Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available.

Similar presentations


Presentation on theme: "CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available."— Presentation transcript:

1 CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available by Dr Mary Jane Irwin, Penn State University.

2 Memory: Virtual Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of the memory at each level Inclusive– what is in L1$ is a subset of what is in L2$ is a subset of what is in MM that is a subset of is in SM 4-8 bytes (word) 1 to 4 blocks 1,024+ bytes (disk sector = page) 8-32 bytes (block)  Take advantage of the principle of locality to present the user with as much memory as is available in the cheapest technology at the speed offered by the fastest technology CS210_305_13/2

3 Memory: Virtual Virtual Memory  Use main memory as a “cache” for secondary memory l Allows efficient and safe sharing of memory among multiple programs l Provides the ability to easily run programs larger than the size of physical memory l Simplifies loading a program for execution by providing for code relocation (i.e., the code can be loaded anywhere in main memory)  What makes it work? – again the Principle of Locality l A program is likely to access a relatively small portion of its address space during any period of time  Each program is compiled into its own address space – a “virtual” address space l During run-time each virtual address must be translated to a physical address (an address in main memory) CS210_305_13/3

4 Memory: Virtual Two Programs Sharing Physical Memory Program 1 virtual address space main memory  A program’s address space is divided into pages (all one fixed size) or segments (variable sizes) l The starting location of each page (either in main memory or in secondary memory) is contained in the program’s page table Program 2 virtual address space CS210_305_13/4

5 Memory: Virtual Address Translation Virtual Address (VA) Page offsetVirtual page number 31 30... 12 11... 0 Page offsetPhysical page number Physical Address (PA) 29... 12 11 0 Translation  So each memory request first requires an address translation from the virtual space to the physical space l A virtual memory miss (i.e., when the page is not in physical memory) is called a page fault  A virtual address is translated to a physical address by a combination of hardware and software: CS210_305_13/5

6 Memory: Virtual Address Translation Mechanisms Physical page base addr Main memory Disk storage Virtual page # V 1111110101011111101010 Page Table (in main memory) Offset Physical page # Offset CS210_305_13/6

7 Memory: Virtual Virtual Addressing with a Cache  Thus it takes an extra memory access to translate a VA to a PA CPU Trans- lation Cache Main Memory VAPA miss hit data  This makes memory (cache) accesses very expensive (if every access was really two accesses)  The hardware fix is to use a Translation Lookaside Buffer (TLB) – a small cache that keeps track of recently used address mappings to avoid having to do a page table lookup CS210_305_13/7

8 Memory: Virtual Making Address Translation Fast Physical page base addr Main memory Disk storage Virtual page # V 1111110101011111101010 1110111101 Tag Physical page base addr V TLB Page Table (in physical memory) CS210_305_13/8

9 Memory: Virtual Translation Lookaside Buffers (TLBs)  Just like any other cache, the TLB can be organized as fully associative, set associative, or direct mapped V Virtual Page # Physical Page # Dirty Ref Access  TLB access time is typically smaller than cache access time (because TLBs are much smaller than caches) l TLBs are typically not more than 128 to 256 entries even on high end machines CS210_305_13/9

10 Memory: Virtual A TLB in the Memory Hierarchy  A TLB miss – is it a page fault or merely a TLB miss? l If the page is loaded into main memory, then the TLB miss can be handled (in hardware or software) by loading the translation information from the page table into the TLB -Takes 10’s of cycles to find and load the translation info into the TLB l If the page is not in main memory, then it’s a true page fault -Takes 1,000,000’s of cycles to service a page fault  TLB misses are much more frequent than true page faults CPU TLB Lookup Cache Main Memory VAPA miss hit data Trans- lation hit miss ¾ t ¼ t CS210_305_13/10

11 Memory: Virtual Some Virtual Memory Design Parameters Paged VMTLBs Total size16,000 to 250,000 words 16 to 512 entries Total size (KB)250,000 to 1,000,000,000 0.25 to 16 Block size (B)4000 to 64,0004 to 32 Miss penalty (clocks)10,000,000 to 100,000,000 10 to 1000 Miss rates0.00001% to 0.0001% 0.01% to 2% CS210_305_13/11

12 Memory: Virtual Two Machines’ Cache Parameters Intel P4AMD Opteron TLB organization1 TLB for instructions and 1TLB for data Both 4-way set associative Both use ~LRU replacement Both have 128 entries TLB misses handled in hardware 2 TLBs for instructions and 2 TLBs for data Both L1 TLBs fully associative with ~LRU replacement Both L2 TLBs are 4-way set associative with round-robin LRU Both L1 TLBs have 40 entries Both L2 TLBs have 512 entries TBL misses handled in hardware CS210_305_13/12

13 Memory: Virtual TLB Event Combinations TLBPage Table CachePossible? Under what circumstances? Hit Miss Hit MissHitMiss HitMissMiss/ Hit Miss Hit CS210_305_12/13

14 Memory: Virtual TLB Event Combinations TLBPage Table CachePossible? Under what circumstances? Hit Miss Hit MissHitMiss HitMissMiss/ Hit Miss Hit Yes – what we want! Yes – although the page table is not checked if the TLB hits Yes – TLB miss, PA in page table Yes – TLB miss, PA in page table, but data not in cache Yes – page fault Impossible – TLB translation not possible if page is not present in memory Impossible – data not allowed in cache if page is not in memory CS210_305_12/14

15 Memory: Virtual Reducing Translation Time  Can overlap the cache access with the TLB access l Works when the high order bits of the VA are used to access the TLB while the low order bits are used as index into cache TagData = TagData = Cache HitDesired word VA Tag PA Tag TLB Hit 2-way Associative Cache Index PA Tag Block offset CS210_305_13/15

16 Memory: Virtual Why Not a Virtually Addressed Cache?  A virtually addressed cache would only require address translation on cache misses data CPU Trans- lation Cache Main Memory VA hit PA but l Two different virtual addresses can map to the same physical address (when processes are sharing data), i.e., two different cache entries hold data for the same physical address – synonyms -Must update all cache entries with the same physical address or the memory becomes inconsistent CS210_305_13/16

17 Memory: Virtual The Hardware/Software Boundary  What parts of the virtual to physical address translation is done by or assisted by the hardware? l Translation Lookaside Buffer (TLB) that caches the recent translations -TLB access time is part of the cache hit time -May allot an extra stage in the pipeline for TLB access l Page table storage, fault detection and updating -Page faults result in interrupts (precise) that are then handled by the OS -Hardware must support (i.e., update appropriately) Dirty and Reference bits (e.g., ~LRU) in the Page Tables l Disk placement -Bootstrap (e.g., out of disk sector 0) so the system can service a limited number of page faults before the OS is even loaded CS210_305_13/17

18 Memory: Virtual Summary  The Principle of Locality: l Program likely to access a relatively small portion of the address space at any instant of time. -Temporal Locality: Locality in Time -Spatial Locality: Locality in Space  Caches, TLBs, Virtual Memory all understood by examining how they deal with the four questions 1. Where can block be placed? 2. How is block found? 3. What block is replaced on miss? 4. How are writes handled?  Page tables map virtual address to physical address l TLBs are important for fast translation CS210_305_13/18

19 Memory: Virtual Fallacies and Pitfalls  Pitfall: Ignoring memory system behaviour when writing programs or when generating code in a compiler. l Here's a prime example of loops that perform extremely poorly… for ( col = 0 ; col < 512 ; col++ ) { for ( row = 0 ; row < 512 ; row++ ) { dst[row][col] = src[row][col]; } /* end...row... */ } /* end...col... */ l …and which can be improved very easily (an exercise left to the reader) CodeInstruction Count (thousands) CPU Cycles (thousands) L2 Cache Misses (Data) (thousands) original 131466504467 improved 1052267715 CS210_305_13/19

20 Memory: Virtual Fallacies and Pitfalls  Fallacy: Programmers can ignore memory hierarchy when writing code. l See last example!  Pitfall: Extending an address space by adding segments on top of an unsegmented address space. l Intel's 8086 16-bit processor with a 20-bit address address space. -Still enshrined in IA-32 for the sake of backwards compatibility. CS210_305_13/20


Download ppt "CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available."

Similar presentations


Ads by Google