1 / 24

ECE232: Hardware Organization and Design

Learn how virtual memory allows programs to be written without memory constraints, exceed the size of main memory, and enable sharing of memory among multiple programs. Explore the addressing and mapping of virtual to physical memory, and discover efficient techniques for address translation.

saral
Download Presentation

ECE232: Hardware Organization and Design

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. ECE232: Hardware Organization and Design Part 16: Virtual Memory Chapter 7 http://www.ecs.umass.edu/ece/ece232/

  2. Disk Processor Control Cache Regs Datapath Virtual Memory - Objectives • Allow program to be written without memory constraints • program can exceed the size of the main memory • Many Programs sharing DRAM Memory so that context switches can occur • Relocation: Parts of the program can be placed at different locations in the memory instead of a big chunk • Virtual Memory: • Main Memory holds many programs running at same time (processes) • use Main Memory as a kind of “cache” for disk Main Memory (DRAM)

  3. Disk Technology in Brief • Disk is mechanical memory tracks R/W arm 3600–4200-5400-7200-10000 RPM rotation speed • Disk Access Time =seek time + rotational delay + transfer time • usually measured in milliseconds • “Miss” to disk is extremely expensive • typical access time = millions of clock cycles • Addressing a sector

  4. Virtual to Physical Memory mapping • Each process has its own private “virtual address space” (e.g., 232 Bytes); CPU actually generates “virtual addresses” • Each computer has a “physical address space” (e.g., 128 MB DRAM); also called “real memory” • Address translation: mapping virtual addresses to physical addresses Virtual Memory • Allows some chunks of virtual memory to be present on disk, not in main memory • Allows multiple programs to use (different chunks of physical) memory at same time Physical Memory virtual address Processor

  5. Heap Mapping Virtual Memory to Physical Memory Virtual Memory • Divide Memory into equal sizedpages (say, 4KB each) • A page of Virtual Memory can be assigned to any page frame of Physical Memory 4GB Stack Physical Memory Single Process 128 MB Heap Static Code 0 0

  6. How to Perform Address Translation? • VM divides memory into equal sized pages • Address translation maps entire pages • offsets within the pages do not change • if page size is a power of two, the virtual address separates into two fields: • like cache index, offset fields virtual address Virtual Page Number Page Offset

  7. Mapping Virtual to Physical Address Virtual Address 31 30 29 28 27 .………………….12 11 10 9 8 ……..……. 3 2 1 0 Virtual Page Number Page Offset 1KB page size Translation Physical Page Number Page Offset 9 8 ……..……. 3 2 1 0 27 ……..………………….12 11 10 Physical Address

  8. Virtual Page No. Page Offset Physical Page No. Page Offset Address Translation • Want fully associative page placement • How to locate the physical page? • Search impractical (too many pages) • A page table is a data structure which contains the mapping of virtual pages to physical pages • There are several different ways, all up to the operating system, to keep and update this data • Each process running in the system has its own page table Virtual Address Hit_time = 70-100 CPU cycles Miss_penalty = 10^6 cycles Miss_rate = 1% CPU Memory Page Table Physical Address Address Mapping

  9. 0 1 A.R. A.R. P. P. N. Address Translation: Page Table Virtual Address (VA): offset virtual page # Page Table ... Page Table Register V A.R. P. P. N. Access Rights Physical Page Number Val -id index into page table Physical Memory Address (PA) ... Page Table is located in physical memory disk Access Rights: None, Read Only, Read/Write, Execute

  10. Page Table

  11. Handling Page Faults • A page fault is like a cache miss • Must find page in lower level of hierarchy • If valid bit is zero, the Physical Page Number points to a page on disk • When OS starts new process, it creates space on disk for all the pages of the process, sets all valid bits in page table to zero, and all Physical Page Numbers to point to disk • called Demand Paging - pages of the process are loaded from disk only as needed

  12. CacheVirtual Memory Block or Line Page Miss Page Fault Block Size: 32-64B Page Size: 4K-16KB Placement: Fully AssociativeDirect Mapped, N-way Set Associative Replacement: Least Recently UsedLRU or Random (LRU) approximation Write Thru or Back Write Back How Managed: Hardware + SoftwareHardware (Operating System) Comparing the 2 hierarchies

  13. Optimizing for Space • Page Table too big! • 4GB Virtual Address Space ÷ 4 KB page • 1 million Page Table Entries • 4 MB just for Page Table of single process! • Variety of solutions to tradeoff Page Table size for slower performance • Multilevel page table, Paging page tables, etc. • (Take O/S Class to learn more)

  14. How to Translate Fast? • Problem: Virtual Memory requires two memory accesses! • one to translate Virtual Address into Physical Address (page table lookup) - Page Table is in physical memory • one to transfer the actual data (hopefully cache hit) • Observation: since there is locality in pages of data, must be locality in virtual addresses of those pages! • Why not create a cache of virtual to physical address translations to make translation fast? (smaller is faster) • For historical reasons, such a “page table cache” is called a Translation Lookaside Buffer, or TLB

  15. Translation-Lookaside Buffer (TLB) Physical Page 0 PhysicalPage 1 of page 1 PhysicalPage N-1 Main Memory H. Stone, “High Performance Computer Architecture,” AW 1993

  16. TLB and Page Table

  17. Typical TLB Format • TLB just a cache of the page table mappings • Dirty: since use write back, need to know whether or not to write page to disk when replaced • Ref: Used to calculate LRU on replacement • Referencebit - set when page accessed; OS periodically sorts and moves the referenced pages to the top & resets all Ref bits • Must provide timer interrupt to update LRUbits • TLB access time comparable to cache (much less than main memory access time) Virtual Physical Valid Ref Dirty Access Page Number Page Number Rights “data” “tag”

  18. Translation Look-Aside Buffers • TLB is usually small, typically 32-512 entries • Like any other cache, the TLB can be fully associative, set associative, or direct mapped data data virtualaddr. physicaladdr. TLB Cache miss Main Memory hit hit Processor miss PageTable Disk Memory OS FaultHandler page fault/protection violation

  19. Steps in Memory Access - Example

  20. DECStation 3100/MIPS R2000 3 1 3 0 2 9 1 5 1 4 1 3 1 2 1 1 1 0 9 8 3 2 1 0 Virtual Address 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 D i r t y P h y s i c a l p a g e n u m b e r T a g TLB T L B h i t 64 entries, fully associative 2 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 Physical Address P h y s i c a l a d d r e s s t a g C a c h e i n d e x B y t e 1 4 2 1 6 o f f s e t T a g D a t a V a l i d Cache 16K entries, direct mapped 3 2 D a t a C a c h e h i t

  21. Address Size: 32 bits (VA, PA) VM Page Size: 4 KB, 4 MB TLB organization: separate i,d TLBs (i-TLB: 32 entries, d-TLB: 64 entries) 4-way set associative LRU approximated hardware handles miss L1 Cache: 8 KB, separate i,d 4-way set associative LRU approximated 32 byte block write back L2 Cache: 256 or 512 KB Real Stuff: Pentium Pro Memory Hierarchy

  22. Intel “Nehalim” quad-core processor 13.519.6 mm die; 731 million transistors; Two 128-bit memory channels Each processor has: private 32-KB instruction and 32-KB data caches and a 512-KB L2 cache. The four cores share an 8-MB L3 cache. Each core also has a two-level TLB.

  23. Comparing Intel’s Nehalim to AMD’s Opteron

  24. Further Comparison

More Related