Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.

Similar presentations

Presentation on theme: "Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission."— Presentation transcript:

1
Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission. Computer Architecture ECE 201

3
Virtual Memory Virtual memory (VM) allows main memory (DRAM) to act like a cache for secondary storage (magnetic disk). VM address translation a provides a mapping from the virtual address of the processor to the physical address in main memory and secondary storage. VM provides the following benefits –Allows multiple programs to share the same physical memory –Allows programmers to write code (or compilers to generate code) as though they have a very large amount of main memory –Automatically handles bringing in data from disk Cache terms vs. VM terms –Cache block => page –Cache Miss => page fault

4
Cache and Main Memory Parameters

5
4 Qs for Virtual Memory Q1: Where can a block be placed in the upper level? –Miss penalty for virtual memory is very high –Have software determine location of block while accessing disk –Allow blocks to be placed anywhere in memory (fully associative) to reduce miss rate. Q2: How is a block found if it is in the upper level? –Address divided into page number and page offset –Page table and translation buffer used for address translation Q3: Which block should be replaced on a miss? –Want to reduce miss rate & can handle in software –Least Recently Used typically used Q4: What happens on a write? –Writing to disk is very expensive –Use a write-back strategy

7
Address Translation with Page Tables A page table translates a virtual page number into a physical page number. A page table register indicates the start of the page table. The virtual page number is used as an index into the page table that contains –The physical page number –A valid bit that indicates if the page is present in main memory –A dirty bit to indicate if the page has been written –Protection information about the page (read only, read/write, etc.) Since page tables contain a mapping for every virtual page, no tags are required.

8
Page Table Diagram (See Figure 7.22 on page 584)

9
Accessing Main Memory or Disk If the valid bit of the page table is zero, this means that the page is not in main memory. In this case, a page fault occurs, and the missing page is read in from disk.

11
Caching Virtual Addresses Virtual memory seems to be really slow: –Must access memory on load/store -- even cache hits! –Worse, if translation not completely in memory, may need to go to disk before hitting in cache! Solution: Caching! (surprise!) –Keep track of most common translations and place them in a “Translation Lookaside Buffer” (TLB) CPU Trans- lation Cache Main Memory VAPA miss hit data

18
Handling TLB Misses and Page Faults When a TLB miss occurs either –Page is present in memory and update the TLB »occurs if valid bit of page table is set –Page is not present in memory and O.S. gets control to handle a page fault If a page fault occur, the operating system –Access the page table to determine the physical location of the page on disk –Chooses a physical page to replace - if the replaced page is dirty it is written to disk –Reads a page from disk into the chosen physical page in main memory. Since the disk access takes so long, another process is typically allowed to run during a page fault.

19
Virtual Memory Summary Virtual memory (VM) allows main memory (DRAM) to act like a cache for secondary storage (magnetic disk). Page tables and TLBS are used to translate the virtual address to a physical address The large miss penalty of virtual memory leads to different strategies from cache –Fully associative –LRU or LRU approximation –Write-back –Done by software