Presentation is loading. Please wait.

Presentation is loading. Please wait.

15-447 Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS 15-447: Computer Architecture.

Similar presentations


Presentation on theme: "15-447 Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS 15-447: Computer Architecture."— Presentation transcript:

1 15-447 Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS 15-447: Computer Architecture

2 15-447 Computer ArchitectureFall 2007 © 2 Last Lecture Virtual memory lets the programmer “see” a memory array larger than the DRAM available on a particular computer system. Virtual memory enables multiple programs to share the physical memory without: –Knowing other programs exist (transparency). –Worrying about one program modifying the data contents of another (protection).

3 15-447 Computer ArchitectureFall 2007 © 3 Other VM Functions Page data location –Physical memory, disk, uninitialized data Access permissions –Read only pages for instructions Gathering access information –Identifying dirty pages by tracking stores –Identifying accesses to help determine LRU candidate

4 15-447 Computer ArchitectureFall 2007 © 4 Page Replacement Strategies Page table indirection enables a fully associative mapping between virtual and physical pages. How do we implement LRU? –True LRU is expensive, but LRU is a heuristic anyway, so approximating LRU is fine –Reference bit on page, cleared occasionally by operating system. Then pick any “unreferenced” page to evict.

5 15-447 Computer ArchitectureFall 2007 © 5 Performance of Virtual Memory We must access physical memory to access the page table to make the translation from a virtual address to a physical one Then we access physical memory again to get (or store) the data A load instruction performs at least 2 memory reads A store instruction performs at least 1 read and then a write.

6 15-447 Computer ArchitectureFall 2007 © 6 Translation Lookaside Buffer We fix this performance problem by avoiding memory in the translation from virtual to physical pages. We buffer the common translations in a translation lookaside buffer (TLB)

7 15-447 Computer ArchitectureFall 2007 © 7 TLB Virtual page vtagPhysical page Pg offset

8 15-447 Computer ArchitectureFall 2007 © 8 Where is the TLB Lookup? We put the TLB lookup in the pipeline after the virtual address is calculated and before the memory reference is performed. –This may be before or during the data cache access. –Without a TLB we need to perform the translation during the memory stage of the pipeline.

9 15-447 Computer ArchitectureFall 2007 © 9 Placing Caches in a VM System VM systems give us two different addresses: virtual and physical Which address should we use to access the data cache? –Virtual address (before VM translation) Faster access? More complex? –Physical address (after VM translations) Delayed access?

10 15-447 Computer ArchitectureFall 2007 © 10 Physically-Addressed Caches Perform TLB lookup before cache tag comparison. –Use bits from physical address to index set –Use bits from physical address to compare tag Slower access? –Tag lookup takes place after the TLB lookup. Simplifies some VM management –When switching processes, TLB must be invalidated, but cache OK to stay as is.

11 15-447 Computer ArchitectureFall 2007 © 11 Page offsetVirtual page Picture of Physical Caches Virtual address Set1 tag Set0 tag Set2 tag Tag cmp Tag cmp Cache tagPPN tagPPN tagPPN tagPPN Page offsetPPN tag index Block offset

12 15-447 Computer ArchitectureFall 2007 © 12 Virtually-Addressed Caches Perform the TLB lookup at the same time as the cache tag compare. –Uses bits from the virtual address to index the cache set –Uses bits from the virtual address for tag match. Problems: –Aliasing: Two processes may refer to the same physical location with different virtual addresses. –When switching processes, TLB must be invalidated, and dirty cache blocks must be written back to memory.

13 15-447 Computer ArchitectureFall 2007 © 13 Picture of Virtual Caches tagindex Block offset Virtual address Set1 tag Set0 tag Set2 tag Tag cmp Tag cmp TLB is accessed in parallel with cache lookup Physical address is used to access main memory in case of a cache miss.

14 15-447 Computer ArchitectureFall 2007 © 14 OS Support for Virtual Memory It must be able to modify the page table register, update page table values, etc. –To enable the OS to do this, AND not the user program, we have different execution modes for a process – one which has executive (or supervisor or kernel level) permissions and one that has user level permissions.

15 15-447 Computer ArchitectureFall 2007 © 15 Extended Example: Loading a Program into Memory text2 Istatic text1 Disk Pages2 entry TLB Memory Page Table 0 1 2 3 1000 1001 1002 1003 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs

16 15-447 Computer ArchitectureFall 2007 © 16 Additional Information Page size = 4KB Page table entry size = 4B Page table register points to physical address 0000

17 15-447 Computer ArchitectureFall 2007 © 17 Step 1: Read Executable Header and Initialize Page Table text2 Istatic text1 Disk Pages2 entry TLB reserved Memory Page Table D1000 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs ro

18 15-447 Computer ArchitectureFall 2007 © 18 Step 2: Load PC from Header and Start Execution text2 Istatic text1 Disk Pages2 entry TLB reserved Memory Page Table D1000 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs ro MISS!

19 15-447 Computer ArchitectureFall 2007 © 19 Fetching instr 0000 text2 Istatic text1 Disk Pages2 entry TLB reserved Memory Page Table D1000 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault ro

20 15-447 Computer ArchitectureFall 2007 © 20 Fetching instr 0000 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Memory Page Table M1 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 ro 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault ro

21 15-447 Computer ArchitectureFall 2007 © 21 Fetching instr 0000 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Memory Page Table M1 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 ro 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 ro

22 15-447 Computer ArchitectureFall 2007 © 22 Fetching instr 0004 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Memory Page Table M1 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 ro 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 ro HIT!

23 15-447 Computer ArchitectureFall 2007 © 23 Reference 7FFC text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Memory Page Table M1 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 ro 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 ro MISS!

24 15-447 Computer ArchitectureFall 2007 © 24 Reference 7FFC text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Memory Page Table M1 D1001 D1002 no map 0 1 2 3 1000 1001 1002 1003 ro 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 No map page fault ro

25 15-447 Computer ArchitectureFall 2007 © 25 Reference 7FFC text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Set to 0s Memory M27000 Page Table M1 D1001 D1002 no map M2 0 1 2 3 1000 1001 1002 1003 ro rw 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 No map page fault 2FFC ro

26 15-447 Computer ArchitectureFall 2007 © 26 Fetching instr 0008 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Set to 0s Memory M27000 Page Table M1 D1001 D1002 no map M2 0 1 2 3 1000 1001 1002 1003 ro rw 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 No map page fault 2FFC 1008 ro HIT!

27 15-447 Computer ArchitectureFall 2007 © 27 Reference 2134 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Set to 0s Memory M27000 Page Table M1 D1001 D1002 no map M2 0 1 2 3 1000 1001 1002 1003 ro rw 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 No map page fault 2FFC 1008 ro MISS!

28 15-447 Computer ArchitectureFall 2007 © 28 Reference 2134 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Set to 0s Memory M27000 Page Table M1 D1001 D1002 no map M2 0 1 2 3 1000 1001 1002 1003 ro rw 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 No map page fault 2FFC 1008 Page fault ro

29 15-447 Computer ArchitectureFall 2007 © 29 Reference 2134 text2 Istatic text1 Disk Pages M10000 2 entry TLB reserved text1 Set to 0s Istatic Memory M32000 Page Table M1 D1001 M3 no map M2 0 1 2 3 1000 1001 1002 1003 ro rw 0 1 2 3 4 5 6 7 References 0000 0004 7FFC 0008 2134 Physical Refs 0000 Page fault 1000 1004 No map page fault 2FFC 1008 Page fault 3134 ro

30 15-447 Computer ArchitectureFall 2007 © 30 Multiple Processes Virtual cache support for multiple processes: –Flush the cache between each context switch. –Use processID (a unique number for each processes given by the operating system) as part of the tag

31 15-447 Computer ArchitectureFall 2007 © 31 Multiple Processors Can run two programs at the same time –Each processor has its own cache. Why? May or may not share data –Sharing code is not a problem (read only) Example: shared libraries, DDLs –Sharing data (read/write) is a problem What if it is in one processors cache? –Solution: Snoopy caches


Download ppt "15-447 Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS 15-447: Computer Architecture."

Similar presentations


Ads by Google