Virtual Memory October 26, 2000Motivations for Virtual MemoryMotivation #1: DRAM a “Cache” for DiskLevels in Memory HierarchyDRAM vs. SRAM as a “Cache”Impact of These Properties on DesignLocating an Object in a “Cache”Locating an Object in a “Cache” (cont.)A System with Physical Memory OnlyA System with Virtual MemoryPage Faults (Similar to “Cache Misses”)Servicing a Page FaultMotivation #2: Memory ManagementSolution: Separate Virtual Addr. SpacesContrast: Macintosh Memory ModelMacintosh Memory ManagementMac vs. VM-Based Memory MgmtMAC OS XMotivation #3: ProtectionVM Address TranslationSlide 21Page TablesAddress Translation via Page TablePage Table OperationIntegrating VM and CacheSpeeding up Translation with a TLBAddress Translation with a TLBSimple Memory System ExampleSimple Memory System Page TableSimple Memory System TLBSimple Memory System CacheAddress Translation Example #1Address Translation Example #2Address Translation Example #3Multi-Level Page TablesMain ThemesVirtual MemoryOctober 26, 2000Topics•Motivations for VM•Address translation•Accelerating translation with TLBs15-213class18.pptCS 213 F’00– 2 –class18.pptMotivations 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.CS 213 F’00– 3 –class18.pptMotivation #1: DRAM a “Cache” for DiskFull 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) bytesDisk storage is ~156X cheaper than DRAM storage•8 GB of DRAM: ~ $10,000•8 GB of disk: ~ $64To access large amounts of data in a cost-effective manner, the bulk of the data must be stored on disk256 MB: ~$320 8 GB: ~$644 MB: ~$400DiskDRAMSRAMCS 213 F’00– 4 –class18.pptLevels in Memory HierarchyCPUCPUregsregsCacheMemoryMemorydiskdisksize:speed:$/Mbyte:line size:32 B3 ns8 BRegister Cache Memory Disk Memory32 KB-4MB6 ns$100/MB32 B128 MB60 ns$1.25/MB4 KB30 GB8 ms$0.008/MBlarger, slower, cheaper8 B 32 B 4 KBcache virtual memoryCS 213 F’00– 5 –class18.pptDRAM vs. SRAM as a “Cache”DRAM vs. disk is more extreme than SRAM vs. DRAM•Access latencies:–DRAM ~10X slower than SRAM–Disk ~100,000X slower than DRAM•Importance of exploiting spatial locality:–First byte is ~100,000X slower than successive bytes on disk»vs. ~4X improvement for page-mode vs. regular accesses to DRAM•Bottom line: –Design decisions made for DRAM caches driven by enormous cost of missesDRAMSRAMDiskCS 213 F’00– 6 –class18.pptImpact of These Properties on DesignIf DRAM was to be organized similar to an SRAM cache, how would we set the following design parameters?•Line size?–Large, since disk better at transferring large blocks•Associativity?–High, to mimimize miss rate•Write through or write back?–Write back, since can’t afford to perform small writes to diskWhat would the impact of these choices be on:•miss rate–Extremely low. << 1%•hit time–Must match cache/DRAM performance•miss latency–Very high. ~20ms•tag storage overhead–Low, relative to block sizeCS 213 F’00– 7 –class18.pptLocating an Object in a “Cache”SRAM Cache•Tag stored with cache line•Maps from cache block to memory blocks–From cached to uncached form•No tag for block not in cache•Hardware retrieves information–can quickly match against multiple tagsXObject NameTag DataD 243X 17J 105••••••0:1:N-1:= X?“Cache”CS 213 F’00– 8 –class18.pptLocating an Object in a “Cache” (cont.)Data243 17105•••0:1:N-1:XObject NameLocation•••D:J:X: 10On Disk“Cache”Page TableDRAM Cache•Each allocate 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•OS retrieves informationCS 213 F’00– 9 –class18.pptCPU0:1:N-1:MemoryA System with Physical Memory OnlyExamples:•most Cray machines, early PCs, nearly all embedded systems, etc.Addresses generated by the CPU point directly to bytes in physical memoryPhysicalAddressesCS 213 F’00– 10 –class18.pptA System with Virtual MemoryExamples:•workstations, servers, modern PCs, etc.Address Translation: Hardware converts virtual addresses to physical addresses via an OS-managed lookup table (page table)CPU0:1:N-1:Memory0:1:P-1:Page TableDiskVirtualAddressesPhysicalAddressesCS 213 F’00– 11 –class18.pptPage Faults (Similar to “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–current process suspends, others can resume–OS has full control over placement, etc.CPUMemoryPage TableDiskVirtualAddressesPhysicalAddressesCPUMemoryPage TableDiskVirtualAddressesPhysicalAddressesBefore faultAfter faultCS 213 F’00– 12 –class18.pptServicing a Page FaultProcessor Signals Controller•Read block of length P starting at disk address X and store starting at memory address YRead Occurs•Direct Memory Access (DMA)•Under control of I/O controllerI / O Controller Signals Completion•Interrupt processor•OS resumes suspended process diskDiskdiskDiskMemory-I/O busMemory-I/O busProcessorProcessorCacheCacheMemoryMemoryI/OcontrollerI/OcontrollerReg(2) DMA Transfer(1) Initiate Block Read(3) Read DoneCS 213 F’00– 13 –class18.pptMotivation #2: Memory ManagementMultiple processes can reside in physical memory.How do we resolve address conflicts?•what if two processes access something at the same address?kernel virtual memoryMemory mapped region forshared librariesruntime heap (via malloc)program text (.text)initialized data (.data)uninitialized data (.bss)stackforbidden0%espmemory invisible to user codethe “brk” ptrLinux/x86processmemory imageCS 213
View Full Document