1 / 20

Review: The Memory Hierarchy

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 ). 8-32 bytes ( block ). 1 to 4 blocks. 1,024+ bytes ( disk sector = page ). Review: The Memory Hierarchy.

dot
Download Presentation

Review: The Memory Hierarchy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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) 8-32 bytes (block) 1 to 4 blocks 1,024+ bytes (disk sector = page) Review: The Memory Hierarchy • 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 Processor Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory (Relative) size of the memory at each level

  2. Virtual Memory • Use main memory as a “cache” for secondary memory • Allows efficient and safe sharing of memory among multiple programs • Provides the ability to easily run programs larger than the size of physical memory • 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 • 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 • During run-time each virtual address must be translated to a physical address (an address in main memory)

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

  4. Recall: Each MIPS program has an address space of size 232 bytes

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

  6. P a g e t a b l e r e g i s t e r V i r t u a l a d d r e s s 3 1 3 0 2 9 2 8 2 7 1 5 1 4 1 3 1 2 1 1 1 0 9 8 3 2 1 0 V i r t u a l p a g e n u m b e r P a g e o f f s e t 2 0 1 2 V a l i d P h y s i c a l p a g e n u m b e r P a g e t a b l e 1 8 I f 0 t h e n p a g e i s n o t p r e s e n t i n m e m o r y 2 9 2 8 2 7 1 5 1 4 1 3 1 2 1 1 1 0 9 8 3 2 1 0 P h y s i c a l p a g e n u m b e r P a g e o f f s e t P h y s i c a l a d d r e s s Page Tables

  7. Address Translation Mechanisms Virtual page # Offset Physical page # Offset Physical page base addr V 1 1 1 1 1 1 0 1 0 1 0 Main memory Page Table (in main memory) Disk storage

  8. miss VA PA Trans- lation Cache Main Memory CPU hit data Virtual Addressing with a Cache • Thus it takes an extra memory access to translate a VA to a PA • 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

  9. Physical page base addr V Tag 1 1 1 0 1 TLB Making Address Translation Fast Virtual page # Physical page base addr V 1 1 1 1 1 1 0 1 0 1 0 Main memory Page Table (in physical memory) Disk storage

  10. 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) • TLBs are typically not more than 128 to 256 entries even on high end machines

  11. hit ¾ t ¼ t miss VA PA TLB Lookup Cache Main Memory CPU miss hit Trans- lation data A TLB in the Memory Hierarchy • A TLB miss – is it a page fault or merely a TLB miss? • 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 • 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

  12. Some Virtual Memory Design Parameters

  13. Two Machines’ Cache Parameters

  14. TLB Event Combinations 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

  15. Reducing Translation Time • Can overlap the cache access with the TLB access • 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 Block offset 2-way Associative Cache Index PA Tag VA Tag Tag Data Tag Data PA Tag TLB Hit = = Cache Hit Desired word

  16. PA VA Trans- lation Main Memory CPU Cache hit data Why Not a Virtually Addressed Cache? • A virtually addressed cache would only require address translation on cache misses but • 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

  17. V i r t u a l a d d r e s s T L B a c c e s s N o Y e s T L B m i s s T L B h i t ? e x c e p t i o n P h y s i c a l a d d r e s s N o Y e s W r i t e ? T r y t o r e a d d a t a Y e s N o f r o m c a c h e W r i t e a c c e s s b i t o n ? W r i t e p r o t e c t i o n W r i t e d a t a i n t o c a c h e , e x c e p t i o n u p d a t e t h e t a g , a n d p u t N o Y e s t h e d a t a a n d t h e a d d r e s s C a c h e m i s s s t a l l C a c h e h i t ? i n t o t h e w r i t e b u f f e r D e l i v e r d a t a t o t h e C P U TLBs and caches

  18. The Hardware/Software Boundary • What parts of the virtual to physical address translation is done by or assisted by the hardware? • 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 • 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 • 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

  19. Summary • The Principle of Locality: • 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 • Where can block be placed? • How is block found? • What block is replaced on miss? • How are writes handled? • Page tables map virtual address to physical address • TLBs are important for fast translation

  20. Some Issues • Processor speeds continue to increase very fast — much faster than either DRAM or disk access times • Design challenge: dealing with this growing disparity • Trends: • synchronous SRAMs (provide a burst of data) • redesign DRAM chips to provide higher bandwidth or processing • restructure code to increase locality • use prefetching (make cache visible to ISA)

More Related