1 / 42

Virtual Caches

Virtual Caches. กรกฎ คชฤทธิ์ 4422005. Virtual Address. Virtual Address. Physical Address. MMU. Main Memory. Virtual Cache. CPU. Data. Data. Virtual Caches. Virtual Caches. Problems with Virtual Caches Ambiguities Aliases. Physical Address. 0 x0000. 1234. * *. 0 x5000.

mahsa
Télécharger la présentation

Virtual Caches

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. Virtual Caches กรกฎ คชฤทธิ์ 4422005

  2. Virtual Address Virtual Address Physical Address MMU Main Memory Virtual Cache CPU Data Data Virtual Caches

  3. Virtual Caches • Problems with Virtual Caches • Ambiguities • Aliases

  4. Physical Address 0x0000 1234 * * 0x5000 5678 * Ambiguities

  5. Ambiguities Virtual Address 0x1000 Physical Address 0x5000 Maps to Virtual Cache Tag Data * 0x1000 5678 *

  6. Ambiguities Virtual Address 0x1000 Physical Address 0x0000 Maps to Virtual Cache Tag Data * 0x1000 5678 *

  7. Virtual Address Space Physical Address Space 0x0000 0x0000 0x1000 0x1000 0x2000 0x2000 0x3000 0x3000 0x4000 0x4000 0x5000 0x5000 Aliases

  8. Managing a Virtual Cache • Context Switch • Process may use the same virtual address to refer to different physical address before and after context switch • Kernel must flush everything the old process had cached • Flushing a virtual cache can be a time-consuming operation

  9. Managing a Virtual Cache • Fork • the child receive a complete copy of the parent’s address space • Flushing during each context switch eliminates most inconsistencies between parent’s and child’s data • But must consider about during the copy operations

  10. Managing a Virtual Cache • Fork (without copy-on-write) Parent’s Virtual Address Space Data Copied to Child’s Pages Mapping to Parent’s Physical Pages * * * * * * * * * * * * Kernel Virtual Space Temporary Mapping to Child’s Physical Pages for Copy Operation

  11. Managing a Virtual Cache • Fork • If write-through caching is used, No special flushing is needed during fork since at least one context switch must occur before the child executes • If write-back caching is used, Main memory must be validated before temporary mapping is removed

  12. Managing a Virtual Cache • Fork • if fork is implemented with copy-on-write • if write-through, no flushing is needed at fork time • if write-back, main memory must be validated

  13. Managing a Virtual Cache • Exec • Discards the process’s current address space and replaces it with a new one for the new program the process will run • Possible to occur ambiguities • Kernel must invalidated all user data from cache before execution begins

  14. Managing a Virtual Cache • Exit • Address space of process is discarded • Last step of exit is to perform context switch that flushed the cache

  15. Managing a Virtual Cache • Brk and Sbrk • use to grow and shrink the process’s bss segment • growing bss causes no cache problems • shrink bss, kernel must invalidates data from cache

  16. Managing a Virtual Cache • Shared Memory and Mapped Files • no special cache management is needed since the cache is flushed at each context switch • if single process attaches shared memory segment at different address ?

  17. Virtual Address Physical Address Virtual Address Physical Address MMU Main Memory Virtual Cache CPU I/O Data Data Data Managing a Virtual Cache • I/O

  18. Managing a Virtual Cache • I/O • Some problem occurs when using DMA • when write to device, kernel must validate main memory with cache data before DMA starts • when read from device, cache must be flushed

  19. Managing a Virtual Cache • User-Kernel Data Ambiguities • to prevent cached kernel data from user process, cache must be flushed • Apollo DN-4000, add bit indicate user or kernel mode

  20. Virtual Cacheswith Keys กรกฎ คชฤทธิ์ 4422005

  21. Current Process Key Virtual Address Virtual Address Physical Address MMU Main Memory Virtual Cache CPU Data Data Virtual Caches with Keys

  22. Managing a Virtual Cache with Keys • Context Switch • Normally no need to flush the cache as long as enough keys that unique can be assigned to each processes • when reassigning key, all entries tagged with affected key must be flushed

  23. Key Key Tag Tag Data Data 1 2 0x100000 0x100000 1011970 1011970 Managing a Virtual Cache with Keys • Fork • No need to Flush • Some problem

  24. Key Tag Data 1 0x100000 1011970 - - - Key Tag Data 1 0x100000 1011970 2 0x100000 1011970 Managing a Virtual Cache with Keys • Fork • Some problem

  25. Managing a Virtual Cache with Keys • Exec • A unique key must be chosen for new address space • if reassigning key, all entries tagged with affected key must be flushed

  26. Managing a Virtual Cache with Keys • Exit • not necessary to invalidate cache at exit time • cache is flushed during context switch

  27. Managing a Virtual Cache with Keys • Brk and Sbrk • Same as pure virtual cache

  28. Key Key Mod Mod Tag Tag Data Data 2 1 - M 0x100000 0x100000 1011970 1011970 Managing a Virtual Cache with Keys • Shared Memory and Mapped Files • Can not share data within cache

  29. Managing a Virtual Cache with Keys • I/O • Same as pure virtual cache

  30. Managing a Virtual Cache with Keys • User-Kernel Data Ambiguities • Kernel process have special key • User process can not access kernel data • Kernel process can not share user data

  31. Virtual Cache Usage in MMUs • Special-purpose cache, Translation Lookside Buffer (TLB) or Address translation Cache (ATC) • caching most recently used page mapping • speed up virtual-to-physical address translation process • must be flush on each context switch

  32. Virtual Cacheswith Physical Address Tags กรกฎ คชฤทธิ์ 4422005

  33. MMU Physical Address Virtual Address Main Memory Virtual Cache with Physical Tags CPU Data Data Virtual Caches with Physical Tags

  34. Managing a Virtual Cache with Physical Tags • Context Switch • Normally no need to flush the cache • No keys to mange as virtual cache with keys

  35. Managing a Virtual Cache with Physical Tags • Fork • No cache flushing is required for fork • Data can be shared in cache • No aliases can occur

  36. Managing a Virtual Cache with Physical Tags • Exec • Address space not be use by any process • exec deallocates pages, must be ensure that stale data is removed prior to allocating page to new process

  37. Managing a Virtual Cache with Physical Tags • Exit • Can be either flushed at system call or postponed until physical page are reuse

  38. Managing a Virtual Cache with Physical Tags • Brk and Sbrk • Like exec and exit • Can be either flushed at system call or postponed until physical page are reuse

  39. Managing a Virtual Cache with Physical Tags • Shared Memory and Mapped Files • Can share data in cache • Better hit ratio for shared memory

  40. Managing a Virtual Cache with Physical Tags • I/O • Same as pure virtual cache

  41. Managing a Virtual Cache with Physical Tags • User-Kernel Data Ambiguities • No ambiguities between user and kernel data • Kernel can reference cached user data directly

  42. The End

More Related