virtual memory vm
play

Virtual memory (VM) Overview and mo-va-on VM as - PowerPoint PPT Presentation

University of Washington Virtual memory (VM) Overview and mo-va-on VM as tool for caching VM as tool for memory management VM as


  1. University ¡of ¡Washington ¡ ¢ Virtual ¡memory ¡(VM) ¡ § Overview ¡and ¡mo-va-on ¡ § VM ¡as ¡tool ¡for ¡caching ¡ § VM ¡as ¡tool ¡for ¡memory ¡management ¡ § VM ¡as ¡tool ¡for ¡memory ¡protec-on ¡ § Address ¡transla-on ¡ 1 ¡

  2. University ¡of ¡Washington ¡ Processes ¡ ¢ Defini=on: ¡A ¡ process ¡is ¡an ¡instance ¡of ¡a ¡running ¡program ¡ § One ¡of ¡the ¡most ¡important ¡ideas ¡in ¡computer ¡science ¡ § Not ¡the ¡same ¡as ¡“program” ¡or ¡“processor” ¡ ¢ Process ¡provides ¡each ¡program ¡with ¡two ¡key ¡abstrac=ons: ¡ § Logical ¡control ¡flow ¡ § Each ¡program ¡seems ¡to ¡have ¡exclusive ¡use ¡of ¡the ¡CPU ¡ § Private ¡virtual ¡address ¡space ¡ § Each ¡program ¡seems ¡to ¡have ¡exclusive ¡use ¡of ¡main ¡memory ¡ ¢ How ¡are ¡these ¡Illusions ¡maintained? ¡ § Process ¡execu-ons ¡interleaved ¡(mul--­‑tasking) ¡ § Address ¡spaces ¡managed ¡by ¡virtual ¡memory ¡system ¡ 2 ¡

  3. University ¡of ¡Washington ¡ Concurrent ¡Processes ¡ ¢ Two ¡processes ¡ run ¡concurrently ¡(are ¡concurrent) ¡if ¡their ¡ instruc=on ¡execu=ons ¡(flows) ¡overlap ¡in ¡=me ¡ ¢ Otherwise, ¡they ¡are ¡ sequen.al ¡ ¢ Examples: ¡ § Concurrent: ¡A ¡& ¡B, ¡A ¡& ¡C ¡ § Sequen-al: ¡B ¡& ¡C ¡ Process ¡A ¡ Process ¡B ¡ Process ¡C ¡ =me ¡ 3 ¡

  4. University ¡of ¡Washington ¡ User ¡View ¡of ¡Concurrent ¡Processes ¡ ¢ Control ¡flows ¡for ¡concurrent ¡processes ¡are ¡physically ¡ disjoint ¡in ¡=me ¡ ¢ However, ¡we ¡can ¡think ¡of ¡concurrent ¡processes ¡as ¡ execu=ng ¡in ¡parallel ¡(only ¡an ¡illusion?) ¡ Process ¡A ¡ Process ¡B ¡ Process ¡C ¡ =me ¡ 4 ¡

  5. University ¡of ¡Washington ¡ Context ¡Switching ¡ ¢ Processes ¡are ¡managed ¡by ¡a ¡shared ¡chunk ¡of ¡OS ¡code ¡ ¡ called ¡the ¡ kernel ¡ § Important: ¡the ¡kernel ¡is ¡not ¡a ¡separate ¡process, ¡but ¡rather ¡runs ¡as ¡part ¡ of ¡a ¡user ¡process ¡ ¢ Control ¡flow ¡passes ¡from ¡one ¡process ¡to ¡another ¡via ¡a ¡ context ¡switch… ¡ (how?) ¡ Process ¡A ¡ Process ¡B ¡ user ¡code ¡ context ¡switch ¡ kernel ¡code ¡ =me ¡ user ¡code ¡ context ¡switch ¡ kernel ¡code ¡ user ¡code ¡ 5 ¡

  6. University ¡of ¡Washington ¡ Virtual ¡Memory ¡(Previous ¡Lectures) ¡ ¢ Programs ¡refer ¡to ¡virtual ¡memory ¡addresses ¡ 00·√·√·√·√·√·√0 ¡ § movl (%ecx),%eax ¡ § Conceptually ¡very ¡large ¡array ¡of ¡bytes ¡ § Each ¡byte ¡has ¡its ¡own ¡address ¡ § Actually ¡implemented ¡with ¡hierarchy ¡of ¡different ¡ memory ¡types ¡ § System ¡provides ¡address ¡space ¡private ¡to ¡par-cular ¡ “process” ¡ ¢ Alloca=on: ¡Compiler ¡and ¡run-­‑=me ¡system ¡ § Where ¡different ¡program ¡objects ¡should ¡be ¡stored ¡ § All ¡alloca-on ¡within ¡single ¡virtual ¡address ¡space ¡ ¢ But ¡why ¡virtual ¡memory? ¡ ¡ FF·√·√·√·√·√·√F ¡ ¢ Why ¡not ¡physical ¡memory? ¡ 6 ¡

  7. University ¡of ¡Washington ¡ Problem ¡1: ¡How ¡Does ¡Everything ¡Fit? ¡ 64-­‑bit ¡addresses: ¡ Physical ¡main ¡memory: ¡ 16 ¡Exabyte ¡ Few ¡Gigabytes ¡ ? And ¡there ¡are ¡many ¡processes ¡…. ¡ 7 ¡

  8. University ¡of ¡Washington ¡ Problem ¡2: ¡Memory ¡Management ¡ Physical ¡main ¡memory ¡ Process ¡1 ¡ stack ¡ Process ¡2 ¡ x ¡ heap ¡ What goes Process ¡3 ¡ where? .text … ¡ .data Process ¡n ¡ … ¡ 8 ¡

  9. University ¡of ¡Washington ¡ Problem ¡3: ¡How ¡To ¡Protect ¡ Physical ¡main ¡memory ¡ Process ¡i ¡ Process ¡j ¡ 9 ¡

  10. University ¡of ¡Washington ¡ Problem ¡3: ¡How ¡To ¡Protect ¡ Physical ¡main ¡memory ¡ Process ¡i ¡ Process ¡j ¡ Problem ¡4: ¡How ¡To ¡Share? ¡ Physical ¡main ¡memory ¡ Process ¡i ¡ Process ¡j ¡ 10 ¡

  11. University ¡of ¡Washington ¡ Solu=on: ¡Level ¡Of ¡Indirec=on ¡ Virtual ¡memory ¡ Process ¡1 ¡ Physical ¡memory ¡ mapping Virtual ¡memory ¡ Process ¡n ¡ ¢ Each ¡process ¡gets ¡its ¡own ¡private ¡memory ¡space ¡ ¢ Solves ¡the ¡previous ¡problems ¡ 11 ¡

  12. University ¡of ¡Washington ¡ Address ¡Spaces ¡ ¢ Virtual ¡address ¡space: ¡ Set ¡of ¡N ¡= ¡2 n ¡virtual ¡addresses ¡ ¡ ¡{0, ¡1, ¡2, ¡3, ¡…, ¡N-­‑1} ¡ ¢ Physical ¡address ¡space: ¡ Set ¡of ¡M ¡= ¡2 m ¡physical ¡addresses ¡( ¡n ¡>> ¡m ¡) ¡ ¡ ¡{0, ¡1, ¡2, ¡3, ¡…, ¡M-­‑1} ¡ ¢ Every ¡byte ¡in ¡main ¡memory: ¡ ¡ one ¡physical ¡address, ¡one ¡(or ¡more) ¡virtual ¡addresses ¡ 12 ¡

  13. University ¡of ¡Washington ¡ A ¡System ¡Using ¡Physical ¡Addressing ¡ Main ¡memory ¡ 0: ¡ 1: ¡ 2: ¡ Physical ¡address ¡ 3: ¡ (PA) ¡ 4: ¡ CPU ¡ 5: ¡ 6: ¡ 7: ¡ 8: ¡ ... ¡ M-­‑1: ¡ Data ¡word ¡ ¢ Used ¡in ¡“simple” ¡systems ¡like ¡embedded ¡microcontrollers ¡in ¡ devices ¡like ¡cars, ¡elevators, ¡and ¡digital ¡picture ¡frames ¡ 13 ¡

  14. University ¡of ¡Washington ¡ A ¡System ¡Using ¡Virtual ¡Addressing ¡ Main ¡memory ¡ 0: ¡ CPU ¡Chip ¡ 1: ¡ 2: ¡ Virtual ¡address ¡ Physical ¡address ¡ 3: ¡ (VA) ¡ (PA) ¡ 4: ¡ CPU ¡ MMU ¡ 5: ¡ 6: ¡ 7: ¡ 8: ¡ ... ¡ M-­‑1: ¡ Data ¡word ¡ ¢ Used ¡in ¡all ¡modern ¡desktops, ¡laptops, ¡worksta=ons ¡ ¢ One ¡of ¡the ¡great ¡ideas ¡in ¡computer ¡science ¡ ¡ 14 ¡

  15. University ¡of ¡Washington ¡ Why ¡Virtual ¡Memory ¡(VM)? ¡ ¢ Efficient ¡use ¡of ¡limited ¡main ¡memory ¡(RAM) ¡ § Use ¡RAM ¡as ¡a ¡cache ¡for ¡the ¡parts ¡of ¡a ¡virtual ¡address ¡space ¡ § some ¡non-­‑cached ¡parts ¡stored ¡on ¡disk ¡ § some ¡(unallocated) ¡non-­‑cached ¡parts ¡stored ¡nowhere ¡ § Keep ¡only ¡ac-ve ¡areas ¡of ¡virtual ¡address ¡space ¡in ¡memory ¡ § transfer ¡data ¡back ¡and ¡forth ¡as ¡needed ¡ ¡ ¢ Simplifies ¡memory ¡management ¡for ¡programmers ¡ § Each ¡process ¡gets ¡the ¡same ¡full, ¡private ¡linear ¡address ¡space ¡ ¢ Isolates ¡address ¡spaces ¡ § One ¡process ¡can’t ¡interfere ¡with ¡another’s ¡memory ¡ ¡ § because ¡they ¡operate ¡in ¡different ¡address ¡spaces ¡ § User ¡process ¡cannot ¡access ¡privileged ¡informa-on ¡ § different ¡sec-ons ¡of ¡address ¡spaces ¡have ¡different ¡permissions ¡ 15 ¡

  16. University ¡of ¡Washington ¡ VM ¡as ¡a ¡Tool ¡for ¡Caching ¡ ¢ Virtual ¡memory: ¡ array ¡of ¡N ¡= ¡2 n ¡con=guous ¡bytes ¡ § think ¡of ¡the ¡array ¡(allocated ¡part) ¡as ¡being ¡stored ¡on ¡disk ¡ ¢ Physical ¡main ¡memory ¡(DRAM) ¡= ¡cache ¡for ¡allocated ¡virtual ¡memory ¡ ¢ Blocks ¡are ¡called ¡pages; ¡size ¡= ¡2 p ¡ Virtual ¡memory ¡ Physical ¡memory ¡ 0 ¡ VP ¡0 ¡ Unallocated ¡ 0 ¡ VP ¡1 ¡ Cached ¡ Empty ¡ PP ¡0 ¡ Uncached ¡ PP ¡1 ¡ Unallocated ¡ Empty ¡ Cached ¡ Disk Uncached ¡ Empty ¡ Cached ¡ PP ¡2 m-­‑p -­‑1 ¡ 2 m -­‑1 ¡ VP ¡2 n-­‑p -­‑1 ¡ Uncached ¡ 2 n -­‑1 ¡ Virtual ¡pages ¡(VP's) ¡ ¡ Physical ¡pages ¡(PP's) ¡ ¡ stored ¡on ¡disk ¡ cached ¡in ¡DRAM ¡ 16 ¡

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