COS 318: Operating Systems. Virtual Memory and Address Translation



Similar documents
Lecture 17: Virtual Memory II. Goals of virtual memory

Virtual Memory Paging

CS5460: Operating Systems

W4118: segmentation and paging. Instructor: Junfeng Yang

Virtual vs Physical Addresses

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

Board Notes on Virtual Memory

A Deduplication File System & Course Review

Virtual Machines. COMP 3361: Operating Systems I Winter

Memory Management CS 217. Two programs can t control all of memory simultaneously

Operating Systems, 6 th ed. Test Bank Chapter 7

COS 318: Operating Systems

COS 318: Operating Systems. Virtual Machine Monitors

The Classical Architecture. Storage 1 / 36

Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

Addendum Intel Architecture Software Developer s Manual

361 Computer Architecture Lecture 14: Cache Memory

Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

OPERATING SYSTEMS MEMORY MANAGEMENT

How To Write A Page Table

W4118 Operating Systems. Instructor: Junfeng Yang

Outline: Operating Systems

The Xen of Virtualization

VIRTUAL MEMORY IN CONTEMPORARY MICROPROCESSORS

We r e going to play Final (exam) Jeopardy! "Answers:" "Questions:" - 1 -

Virtualization. Explain how today s virtualization movement is actually a reinvention

1 Storage Devices Summary

Virtualization Technology. Zhiming Shen

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

COS 318: Operating Systems. Storage Devices. Kai Li Computer Science Department Princeton University. (

OPERATING SYSTEM - VIRTUAL MEMORY

RAMCloud and the Low- Latency Datacenter. John Ousterhout Stanford University

WHITE PAPER. AMD-V Nested Paging. AMD-V Nested Paging. Issue Date: July, 2008 Revision: 1.0. Advanced Micro Devices, Inc.

This Unit: Virtual Memory. CIS 501 Computer Architecture. Readings. A Computer System: Hardware

IOMMU: A Detailed view

COS 318: Operating Systems. File Layout and Directories. Topics. File System Components. Steps to Open A File

The Quest for Speed - Memory. Cache Memory. A Solution: Memory Hierarchy. Memory Hierarchy

Exploiting Address Space Contiguity to Accelerate TLB Miss Handling

Lecture 16: Storage Devices

Hypervisor: Requirement Document (Version 3)

Topics in Computer System Performance and Reliability: Storage Systems!

Operating Systems CSE 410, Spring File Management. Stephen Wagner Michigan State University

Computer Architecture

Intel s Virtualization Extensions (VT-x) So you want to build a hypervisor?

Providing Safe, User Space Access to Fast, Solid State Disks. Adrian Caulfield, Todor Mollov, Louis Eisner, Arup De, Joel Coburn, Steven Swanson

Full and Para Virtualization

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

System Virtual Machines

OpenSPARC T1 Processor

Virtual Memory. Virtual Memory. Paging. CSE 380 Computer Operating Systems. Paging (1)

@ )nventor; Radin Qeorge 26 Franklin Piermont New York 10968{US)

6. Storage and File Structures

Computer Organization and Architecture. Characteristics of Memory Systems. Chapter 4 Cache Memory. Location CPU Registers and control unit memory

COS 318: Operating Systems

Caching Mechanisms for Mobile and IOT Devices

CS 695 Topics in Virtualization and Cloud Computing. More Introduction + Processor Virtualization

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

RAID. RAID 0 No redundancy ( AID?) Just stripe data over multiple disks But it does improve performance. Chapter 6 Storage and Other I/O Topics 29

Memory Management under Linux: Issues in Linux VM development

Secondary Storage. Any modern computer system will incorporate (at least) two levels of storage: magnetic disk/optical devices/tape systems

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

OSes. Arvind Seshadri Mark Luk Ning Qu Adrian Perrig SOSP2007. CyLab of CMU. SecVisor: A Tiny Hypervisor to Provide

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

CS161: Operating Systems

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Input / Ouput devices. I/O Chapter 8. Goals & Constraints. Measures of Performance. Anatomy of a Disk Drive. Introduction - 8.1

In-Memory Databases Algorithms and Data Structures on Modern Hardware. Martin Faust David Schwalb Jens Krüger Jürgen Müller

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

Hardware Based Virtualization Technologies. Elsie Wahlig Platform Software Architect

COS 318: Operating Systems. Virtual Machine Monitors

Operating Systems. Virtual Memory

Hybrid Virtualization The Next Generation of XenLinux

Main Memory. Memories. Hauptspeicher. SIMM: single inline memory module 72 Pins. DIMM: dual inline memory module 168 Pins

Price/performance Modern Memory Hierarchy

PERFORMANCE TUNING ORACLE RAC ON LINUX

Virtual machines and operating systems

An Implementation Of Multiprocessor Linux

Operating System Structures

Xen and the Art of. Virtualization. Ian Pratt

CS/COE1541: Introduction to Computer Architecture. Memory hierarchy. Sangyeun Cho. Computer Science Department University of Pittsburgh

Memory management. Chapter 4: Memory Management. Memory hierarchy. In an ideal world. Basic memory management. Fixed partitions: multiple programs

Chapter 7: Distributed Systems: Warehouse-Scale Computing. Fall 2011 Jussi Kangasharju

Chapter 7 Memory Management

1. Computer System Structure and Components

COS 318: Operating Systems. Storage Devices. Kai Li and Andy Bavier Computer Science Department Princeton University

Intel Virtualization Technology Overview Yu Ke

WHITE PAPER Optimizing Virtual Platform Disk Performance

Agenda. Enterprise Application Performance Factors. Current form of Enterprise Applications. Factors to Application Performance.

CS 6290 I/O and Storage. Milos Prvulovic

Virtualization in Linux KVM + QEMU

CS5460: Operating Systems. Lecture: Virtualization 2. Anton Burtsev March, 2013

Virtual Shared Memory (VSM)

x86 Virtualization Hardware Support Pla$orm Virtualiza.on

Virtualization. Clothing the Wolf in Wool. Wednesday, April 17, 13

Operating System Overview. Otto J. Anshus

File-System Implementation

AMD Opteron Quad-Core

Chapter 11: File System Implementation. Operating System Concepts with Java 8 th Edition

Transcription:

COS 318: Operating Systems Virtual Memory and Address Translation

Today s Topics Midterm Results Virtual Memory Virtualization Protection Address Translation Base and bound Segmentation Paging Translation look-ahead buffer Repair working groups 2

Midterm Results (Avg = 31.18) 45 40 35 30 25 20 15 10 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 3

Midterm Grading Problem 1 (Lars Bonge) Main issue: Need to know OS overheads better Problem 2 (Shi Li) Main issue: A few students do not know about calculation Problem 3 (Kai Li) Main issue: Spooling does not eliminate deadlocks of shared data Problem 4 (Nick Johnson) Main issue: A few students do not remember the idioms of Mesa-style monitor! All graders are outside 105 from 2:50pm to 3:00pm 4

The Big Picture DRAM is fast, but relatively expensive $25/GB 20-30ns latency 10-80GB s/sec Disk is inexpensive, but slow $0.2-1/GB (100 less expensive) 5-10ms latency (200K-400K times slower) 40-80MB/sec per disk (1,000 times less) Our goals Run programs as efficiently as possible Make the system as safe as possible CPU Memory Disk 5

Issues Many processes The more processes a system can handle, the better Address space size Many small processes whose total size may exceed memory Even one process may exceed the physical memory size Protection A user process should not crash the system A user process should not do bad things to other processes 6

Consider A Simple System Only physical memory Applications use physical memory directly Run three processes emacs, pine, gcc What if gcc has an address error? emacs writes at x7050? pine needs to expand? emacs needs more memory than is on the machine? OS pine emacs gcc Free x9000 x7000 x5000 x2500 x0000 7

Protection Issue Errors in one process should not affect others For each process, check each load and store instruction to allow only legal memory references gcc CPU address error Check Physical memory data 8

Expansion or Transparency Issue A process should be able to run regardless of its physical location or the physical memory size Give each process a large, static fake address space As a process runs, relocate each load and store to its actual memory pine CPU address Check & relocate Physical memory data 9

Virtual Memory Flexible Processes can move in memory as they execute, partially in memory and partially on disk Simple Make applications very simple in terms of memory accesses Efficient 20/80 rule: 20% of memory gets 80% of references Keep the 20% in physical memory Design issues How is protection enforced? How are processes relocated? How is memory partitioned? 10

Address Mapping and Granularity Must have some mapping mechanism Virtual addresses map to DRAM physical addresses or disk addresses Mapping must have some granularity Granularity determines flexibility Finer granularity requires more mapping information Extremes Any byte to any byte: mapping equals program size Map whole segments: larger segments problematic 11

Generic Address Translation Memory Management Unit (MMU) translates virtual address into physical address for each load and store Software (privileged) controls the translation CPU view Virtual addresses Each process has its own memory space [0, high] Address space Memory or I/O device view Physical addresses CPU MMU Physical memory Virtual address Physical address I/O device 12

Goals of Translation Implicit translation for each memory reference A hit should be very fast Trigger an exception on a miss Protected from user s faults Registers L1 2-3x L2-L3 10-20x Memory 100-300x Paging Disk 20M-30Mx 13

Base and Bound Built in Cray-1 Each process has a pair (base, bound) Protection A process can only access physical memory in [base, base+bound] On a context switch Save/restore base, bound registers Pros Simple Flat and no paging Cons Fragmentation Hard to share Difficult to use disks virtual address + physical address bound > base error 14

Segmentation Each process has a table of (seg, size) Treats (seg, size) has a fine-grained (base, bound) Protection Each entry has (nil, read, write, exec) On a context switch Pros Cons Save/restore the table and a pointer to the table in kernel memory Efficient Easy to share Complex management Fragmentation within a segment Virtual address segment offset seg size. + physical address > error 15

Paging Use a fixed size unit called page instead of segment Use a page table to translate Various bits in each entry Context switch Similar to segmentation What should page size be? Pros Cons Simple allocation Easy to share Big table How to deal with holes? Virtual address VPage # offset Page table PPage#....... PPage#... PPage # offset Physical address page table size error > 16

How Many PTEs Do We Need? Assume 4KB page Equals low order 12 bits Worst case for 32-bit address machine # of processes 2 20 2 20 PTEs per page table (~4Mbytes), but there might be 10K processes. They won t fit in memory together What about 64-bit address machine? # of processes 2 52 A page table cannot fit in a disk (2 52 PTEs = 16PBytes)! 17

Segmentation with Paging Virtual address Vseg # VPage # offset seg. size Page table PPage#....... PPage#... > PPage # offset error Physical address 18

Multiple-Level Page Tables Virtual address dir table offset pte. Directory... What does this buy us? 19

Inverted Page Tables Main idea One PTE for each physical page frame Hash (Vpage, pid) to Ppage# Pros Small page table for large address space Cons Lookup is difficult Overhead of managing hash chains, etc Virtual address pid vpage offset pid vpage 0 k n-1 Inverted page table Physical address k offset 20

Virtual-To-Physical Lookups Programs only know virtual addresses Each program or process starts from 0 to high address Each virtual address must be translated May involve walking through the hierarchical page table Since the page table stored in memory, a program memory access may requires several actual memory accesses Solution Cache active part of page table in a very fast memory 21

Translation Look-aside Buffer (TLB) Virtual address VPage # offset VPage# VPage# VPage# PPage#... PPage#.... PPage#... TLB Hit PPage # offset Miss Real page table Physical address 22

Bits in a TLB Entry Common (necessary) bits Virtual page number: match with the virtual address Physical page number: translated address Valid Access bits: kernel and user (nil, read, write) Optional (useful) bits Process tag Reference Modify Cacheable 23

Hardware-Controlled TLB On a TLB miss Hardware loads the PTE into the TLB Write back and replace an entry if there is no free entry Generate a fault if the page containing the PTE is invalid VM software performs fault handling Restart the CPU On a TLB hit, hardware checks the valid bit If valid, pointer to page frame in memory If invalid, the hardware generates a page fault Perform page fault handling Restart the faulting instruction 24

Software-Controlled TLB On a miss in TLB Write back if there is no free entry Check if the page containing the PTE is in memory If not, perform page fault handling Load the PTE into the TLB Restart the faulting instruction On a hit in TLB, the hardware checks valid bit If valid, pointer to page frame in memory If invalid, the hardware generates a page fault Perform page fault handling Restart the faulting instruction 25

Hardware vs. Software Controlled Hardware approach Efficient Inflexible Need more space for page table Software approach Flexible Software can do mappings by hashing PP# (Pid, VP#) (Pid, VP#) PP# Can deal with large virtual address space 26

Cache vs. TLB Address Data Vpage # offset Cache Hit TLB Hit Miss Miss ppage # offset Memory Memory Similarities Cache a portion of memory Write back on a miss Differences Associativity Consistency 27

TLB Related Issues What TLB entry to be replaced? Random Pseudo LRU What happens on a context switch? Process tag: change TLB registers and process register No process tag: Invalidate the entire TLB contents What happens when changing a page table entry? Change the entry in memory Invalidate the TLB entry 28

Consistency Issues Snoopy cache protocols (hardware) Maintain consistency with DRAM, even when DMA happens Consistency between DRAM and TLBs (software) You need to flush related TLBs whenever changing a page table entry in memory TLB shoot-down On multiprocessors, when you modify a page table entry, you need to flush all related TLB entries on all processors, why? 29

Summary Virtual Memory Virtualization makes software development easier and enables memory resource utilization better Separate address spaces provide protection and isolate faults Address translation Base and bound: very simple but limited Segmentation: useful but complex Paging TLB: fast translation for paging VM needs to take care of TLB consistency issues Regroup NOW 30