537 beyond physical memory
play

[537] Beyond Physical Memory Chapters 21-22 Tyler Harter 9/29/14 - PowerPoint PPT Presentation

[537] Beyond Physical Memory Chapters 21-22 Tyler Harter 9/29/14 Problem 1: PT Size page directory PFN: 0101 PFN: 0110 PFN:1111 PFN valid PFN valid PFN valid PFN valid 0101 1 0000 1 1001 1


  1. [537] Beyond Physical Memory Chapters 21-22 Tyler Harter 9/29/14

  2. Problem 1: PT Size

  3. page directory PFN: 0101 PFN: 0110 PFN:1111 PFN 
 valid 
 PFN 
 valid 
 PFN 
 valid 
 PFN 
 valid 
 0101 
 1 
 0000 
 1 
 1001 
 1 
 - 
 0 
 1111 
 1 
 1010 
 1 
 - 
 0 
 - 
 0 
 - 
 0 
 - 
 0 
 - 
 0 
 - 
 0 
 0110 1 
 - 
 0 
 - 
 0 
 1011 
 1 
 Problem 2 (worksheet) � assume 12-bit 
 virtual addrs

  4. Virtual Memory code data Program �

  5. Virtual Memory create code code 
 data data Program � heap � � � � � � � � � � � � stack Process 1

  6. Virtual Memory create code code 
 data data Program � heap � � � � � � � � � � � � stack Process 1 what’s in code?

  7. 
 Virtual Memory create � LibA LibB LibA LibB � � LibC Prog � LibC Prog � data data heap Program � � � � � � � � � stack Process 1 many large libraries, some of which are rarely/never used

  8. How to avoid wasting physical pages to back rarely used virtual pages?

  9. 
 Virtual Memory LibA LibB � � LibA LibB LibC Prog � data LibC Prog � heap � data � � � Program � � � � � � Phys Memory stack Process 1 LibC Prog

  10. 
 Virtual Memory LibA LibB � � LibA LibB LibC Prog � data LibC Prog � heap � data � � � Program � � � � � � Phys Memory stack Process 1 LibC Prog

  11. 
 Virtual Memory LibA LibB � � LibA LibB LibC Prog � access LibB data LibC Prog � heap � data � � � Program � � � � � � Phys Memory stack Process 1 LibC Prog

  12. 
 Virtual Memory LibA LibB � copy (or move) � LibA LibB LibC Prog � data to RAM LibC Prog � heap � data � � � Program � � � � � � Phys Memory stack Process 1 LibC Prog LibB

  13. 
 Virtual Memory LibA LibB � called “ swapping ” � LibA LibB LibC Prog � or “ paging ” in data LibC Prog � heap � data � � � Program � � � � � � Phys Memory stack Process 1 LibC Prog LibB

  14. How to know where a page lives?

  15. Present Bit PFN valid prot 10 1 r-x - 0 - 23 1 rw- - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - 28 1 rw- 4 1 rw-

  16. Present Bit PFN valid prot present 10 1 r-x 1 - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - 28 1 rw- 0 4 1 rw- 1

  17. Present Bit Disk PFN valid prot present 10 1 r-x 1 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - 28 1 rw- 0 4 1 rw- 1

  18. Present Bit Disk PFN valid prot present 10 1 r-x 1 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - access 28 1 rw- 0 4 1 rw- 1

  19. Present Bit Disk PFN valid prot present 10 1 r-x 1 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - access 15 1 rw- 1 4 1 rw- 1

  20. What if no RAM is left?

  21. Present Bit Disk PFN valid prot present 10 1 r-x 1 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - FULL - 0 - - 28 1 rw- 0 4 1 rw- 1

  22. Present Bit Disk PFN valid prot present 10 1 r-x 1 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - FULL - 0 - - access 28 1 rw- 0 4 1 rw- 1

  23. Present Bit Disk PFN valid prot present 10 1 r-x 1 evict � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - FULL - 0 - - access 28 1 rw- 0 4 1 rw- 1

  24. Present Bit Disk PFN valid prot present 25 1 r-x 0 evict � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - access 28 1 rw- 0 4 1 rw- 1

  25. Present Bit called “ swapping ” or “ paging ” out Disk PFN valid prot present 25 1 r-x 0 evict � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - access 28 1 rw- 0 4 1 rw- 1

  26. Present Bit Disk PFN valid prot present 25 1 r-x 0 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - access 28 1 rw- 0 4 1 rw- 1

  27. Present Bit Disk PFN valid prot present 25 1 r-x 0 � - 0 - - 23 1 rw- 0 - 0 - - - 0 - - - 0 - - - 0 - - Phys Memory - 0 - - - 0 - - - 0 - - - 0 - - access 10 1 rw- 1 4 1 rw- 1

  28. Why not leave page on disk?

  29. Performance: RAM vs. Disk How long does it take to access a 4-byte int ? RAM: 5ns to 40ns per int (depending on TLB hit) Disk: 15ms per int

  30. Performance: RAM vs. Disk How long does it take to access a 4-byte int ? RAM: 5ns to 40ns per int (depending on TLB hit) Disk: 15ms per int 
 - because of high fixed costs 
 - reading 4KB of ints: 15us per int 
 - reading many megabytes of ints: 30ns per int

  31. Average Memory Access Time (AMAT) Hit % = portion of accesses that go straight to RAM Miss % = portion of accesses that go to disk first T m = time for memory access T d = time for disk access � AMAT = (Hit % * T m ) + (Miss % * T d ) �

  32. Average Memory Access Time (AMAT) Hit % = portion of accesses that go straight to RAM Miss % = portion of accesses that go to disk first T m = time for memory access T d = time for disk access � AMAT = (Hit % * T m ) + (Miss % * T d ) � Problem 3

  33. Who should do swapping? H/W or OS ?

  34. H/W CPU: A A A B Disk: A A 0 20 40 60 80

  35. OS CPU: A B A B A B Disk: A A 0 20 40 60 80

  36. OS CPU: A B A B A B Disk: A A 0 20 40 60 80 context switch to other process while swapping in

  37. 
 Translation Steps H/W: for each mem reference: 
 extract VPN from VA 
 check TLB for VPN 
 TLB hit: 
 build PA from PFN and offset 
 fetch PA from memory 
 TLB miss: 
 fetch PTE 
 if (!valid) : exception [segfault] 
 else if (!present) : exception [page fault, or page miss] 
 else : extract PFN , insert in TLB , retry

  38. 
 Translation Steps H/W: for each mem reference: 
 which steps are extract VPN from VA 
 expensive? check TLB for VPN 
 TLB hit: 
 build PA from PFN and offset 
 fetch PA from memory 
 TLB miss: 
 fetch PTE 
 if (!valid) : exception [segfault] 
 else if (!present) : exception [page fault, or page miss] 
 else : extract PFN , insert in TLB , retry

  39. 
 Translation Steps H/W: for each mem reference: 
 which steps are extract VPN from VA 
 (cheap) expensive? check TLB for VPN 
 (cheap) TLB hit: 
 build PA from PFN and offset 
 (cheap) fetch PA from memory 
 (expensive) TLB miss: 
 fetch PTE 
 (expensive) if (!valid) : exception [segfault] 
 (expensive) else if (!present) : exception [page fault, or page miss] 
 (expensive) else : extract PFN , insert in TLB , retry (cheap)

  40. 
 Translation Steps H/W: for each mem reference: 
 which steps are extract VPN from VA 
 (cheap) expensive? check TLB for VPN 
 (cheap) TLB hit: 
 build PA from PFN and offset 
 (cheap) fetch PA from memory 
 (expensive) TLB miss: 
 fetch PTE 
 (expensive) if (!valid) : exception [segfault] 
 (expensive) else if (!present) : exception [page fault, or page miss] 
 (expensive) else : extract PFN , insert in TLB , retry (cheap)

  41. Page-Fault Handler (OS) PFN = FindFreePage() 
 if ( PFN == -1) 
 PFN = EvictPage() 
 DiskRead( PTE .DiskAddr, PFN ) 
 PTE .present = 1 
 PTE . PFN = PFN 
 retry instruction

  42. Page-Fault Handler (OS) which steps are PFN = FindFreePage() 
 expensive? if ( PFN == -1) 
 PFN = EvictPage() 
 DiskRead( PTE .DiskAddr, PFN ) 
 PTE .present = 1 
 PTE . PFN = PFN 
 retry instruction

  43. Page-Fault Handler (OS) which steps are PFN = FindFreePage() 
 (cheap) expensive? if ( PFN == -1) 
 (cheap) PFN = EvictPage() 
 (depends) DiskRead( PTE .DiskAddr, PFN ) 
 (expensive) PTE .present = 1 
 (cheap) PTE . PFN = PFN 
 (cheap) retry instruction (cheap)

  44. Page-Fault Handler (OS) PFN = FindFreePage() 
 (cheap) if ( PFN == -1) 
 (cheap) PFN = EvictPage() 
 what to evict? 
 (depends) what to read? DiskRead( PTE .DiskAddr, PFN ) 
 (expensive) (policy) PTE .present = 1 
 (cheap) PTE . PFN = PFN 
 (cheap) retry instruction (cheap)

  45. Caching Policy Workload : series of loads/stores to virtual pages Cache : chooses what to prefetch/evict Metric : hit rate, AMAT Cache “algebra”, given 2 variables, find the 3rd: f( W , C ) = M

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend