w12-one-virtual memory

w12-one-virtual memory - Virtual Memory Topics Motivations...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Virtual Memory Topics Motivations for VM Address translation Motivations for Virtual Memory Use Physical DRAM as a Cache for the Disk Address space of a process can exceed physical memory size Sum of address spaces of multiple processes can exceed physical memory Simplify Memory Management Multiple processes resident in main memory. Each process with its own address space Only "active" code and data is actually in memory Allocate more memory to process as needed. Provide Protection One process can't interfere with another. because they operate in different address spaces. User process cannot access privileged information different sections of address spaces have different permissions. Motivation #1: DRAM a "Cache" for Disk Full address space is quite large: 32-bit addresses: ~4,000,000,000 (4 billion) bytes 64-bit addresses: ~16,000,000,000,000,000,000 (16 quintillion) bytes Disk storage is ~300X cheaper than DRAM storage 80 GB of DRAM: ~ $33,000 80 GB of disk: ~ $110 To access large amounts of data in a cost-effective manner, the bulk of the data must be stored on disk 1GB: ~$200 4 MB: ~$500 SRAM DRAM 80 GB: ~$110 Disk A System with Physical Memory Only Examples: most Cray machines, early PCs, nearly all embedded systems, etc. Memory Physical Addresses 0: 1: CPU N-1: Addresses generated by the CPU correspond directly to bytes in physical memory Locating an Object in a "Cache" SRAM Cache (L1 & L2) Tag stored with cache line Maps from cache block to memory blocks From cached to uncached form Save a few bits by only storing tag No tag for block not in cache Hardware retrieves information can quickly match against multiple tags "Cache" Data 243 17 105 Tag Object Name X 0: D X J = X? 1: N-1: Locating an Object in "Cache" (cont.) DRAM Cache (i.e. Main Memory) Each allocated page of virtual memory has entry in page table Mapping from virtual pages to physical pages From uncached form to cached form Page table entry even if page not in memory Specifies disk address Only way to indicate where to find page OS retrieves information Page Table Location Object Name X D: J: X: 0 On Disk "Cache" Data 0: 1: N-1: 243 17 105 1 A System with Virtual Memory Examples: workstations, servers, modern PCs, etc. Page Table Virtual Addresses 0: 1: Physical Addresses Memory 0: 1: CPU P-1: N-1: Disk Address Translation: Hardware converts virtual addresses to physical addresses via OS-managed lookup table (page table) Page Faults (like "Cache Misses") What if an object is on disk rather than in memory? Page table entry indicates virtual address not in memory OS exception handler invoked to move data from disk into memory (Page Fault) current process suspends, others can resume OS has full control over placement, etc. Before fault Page Table Virtual Physical Addresses Addresses CPU Memory After fault Memory Page Table Virtual Addresses CPU Physical Addresses Disk Disk Servicing a Page Fault (1) Initiate Block Read Processor Signals Controller Read block of length P starting at disk address X and store starting at memory address Y Processor Processor Reg (3) Read Done Cache Cache Read Occurs Direct Memory Access (DMA) Under control of I/O controller Memory-I/O bus Memory-I/O bus (2) DMA Transfer I/O I/O controller controller Memory Memory disk Disk disk Disk I / O Controller Signals Completion Interrupt processor OS resumes suspended process Motivation #2: Memory Management Multiple processes can reside in physical memory. How do we resolve address conflicts? what if two processes access something at the same address? %esp kernel virtual memory stack memory invisible to user code Linux/x86 process memory image 0 Memory mapped region forshared libraries the "brk" ptr runtime heap (via malloc) uninitialized data (.bss) initialized data (.data) program text (.text) forbidden Solution: Separate Virt. Addr. Spaces Virtual and physical address spaces divided into equal-sized blocks blocks are called "pages" (both virtual and physical) Each process has its own virtual address space operating system controls how virtual pages as assigned to physical memory 0 Address Translation VP 1 VP 2 PP 2 Virtual Address Space for Process 1: 0 ... Physical Address Space (DRAM) (e.g., read/only library code) N-1 PP 7 Virtual Address Space for Process 2: 0 VP 1 VP 2 ... PP 10 M-1 N-1 Motivation #3: Protection Page table entry contains access rights information hardware enforces this protection (trap into OS if violation occurs) Page Tables Read? Write? No VP 0: Yes Physical Addr PP 9 PP 4 XXXXXXX Memory 0: 1: Process i: VP 1: Yes VP 2: No Yes No Physical Addr PP 6 PP 9 XXXXXXX Read? Write? VP 0: Yes Yes Process j: VP 1: Yes VP 2: No No No N-1: VM Address Translation Virtual Address Space V = {0, 1, ..., N1} Physical Address Space P = {0, 1, ..., M1} M<N Address Translation MAP: V P U {} For virtual address a: MAP(a) = a' if data at virtual address a at physical address a' in P MAP(a) = if data at virtual address a not in physical memory Either invalid or stored on disk VM Address Translation: Hit Processor Hardware Addr Trans Mechanism Main Memory a' a virtual address part of the physical address on-chip memory mgmt unit (MMU) VM Address Translation: Miss page fault Processor Hardware Addr Trans Mechanism a' OS performs this transfer (only if miss) fault handler Main Memory Secondary memory a virtual address part of the physical address on-chip memory mgmt unit (MMU) VM Address Translation Parameters P = 2p = page size (bytes). N = 2n = Virtual address limit M = 2m = Physical address limit n1 virtual page number p p1 page offset 0 virtual address address translation m1 p p1 physical page number page offset 0 physical address Page offset bits don't change as a result of translation Page Tables Virtual Page Number Memory resident page table (physical page Valid or disk address) 1 1 0 1 1 1 0 1 0 1 Physical Memory Disk Storage (swap file or regular file system file) Address Translation via Page Table page table base register VPN acts as table index virtual address n1 p p1 virtual page number (VPN) page offset valid access physical page number (PPN) 0 if valid=0 then page not in memory m1 p p1 physical page number (PPN) page offset physical address 0 Page Table Operation Translation Separate (set of) page table(s) per process VPN forms index into page table (points to a page table entry) page table base register VPN acts as table index virtual address n1 p p1 virtual page number (VPN) page offset valid access physical page number (PPN) 0 if valid=0 then page not in memory m1 p p1 physical page number (PPN) page offset physical address 0 Page Table Operation Computing Physical Address Page Table Entry (PTE) provides information about page if (valid bit = 1) then the page is in memory. Use physical page number (PPN) to construct address if (valid bit = 0) then the page is on disk Page fault page table base register VPN acts as table index virtual address n1 p p1 virtual page number (VPN) page offset valid access physical page number (PPN) 0 if valid=0 then page not in memory m1 p p1 physical page number (PPN) page offset physical address 0 Page Table Operation Checking Protection Access rights field indicate allowable access e.g., read-only, read-write, execute-only typically support multiple protection modes (e.g., kernel vs. user) Protection violation fault if user doesn't have necessary permission page table base register VPN acts as table index virtual address n1 p p1 virtual page number (VPN) page offset valid access physical page number (PPN) 0 if valid=0 then page not in memory m1 p p1 physical page number (PPN) page offset physical address 0 ...
View Full Document

Ask a homework question - tutors are online