chapter 10 virtual memory questions
play

Chapter 10: Virtual Memory Questions? What is virtual memory and - PDF document

Chapter 10: Virtual Memory Questions? What is virtual memory and when is it useful? CSCI [4|6] 730 What is demand paging? Operating Systems When should pages in memory be replaced? When should pages be put on disk?


  1. Chapter 10: Virtual Memory Questions? � � What is virtual memory and when is it useful? CSCI [4|6] 730 � � What is demand paging? Operating Systems � � When should pages in memory be replaced? � � When should pages be put on disk? Virtual Memory � � What is the working set model? 2 Maria Hybinette, UGA Maria Hybinette, UGA Operating System’s Goals The Illusion: “ Virtual ” Memory � � OS provides an illusion of � � Support processes when there is not enough more memory than is physical memory physically available: » � Single process with very large address space » � Large logical space but really » � Multiple processes with combined address spaces » � small physical memory � � User code should be independent of amount � � Why does this work? of physical memory » � Only part of the program » � Correctness, if not performance needs to be in memory (at a particular time) for execution » � Relies on key properties of user processes (workload) and machine architecture (hardware) 3 4 Maria Hybinette, UGA Maria Hybinette, UGA The Million Dollar Question? � � How do the OS decide what is in “main” memory and what is on disk? � � How can we decide? » � Memory Access Patterns? 5 Maria Hybinette, UGA

  2. Observations: Memory Access Patterns Approach: Demand Paging � � Sequential memory accesses of a process are � � Bring in pages into predictable and tend to have locality of reference : memory only when needed » � Spatial: reference memory addresses near previously » � Less memory referenced addresses (in memory) » � Less I/O » � Temporal: reference memory addresses that have » � Faster response time? referenced in the past � � Process viewed as a � � Processes spend majority of time in small portion sequence of pages rather of code than contiguous address » � Estimate: 90% of time in 10% of code space � � Implication: » � Pager (whole process) » � Process only uses small amount of address space at any » � Swapper (portion of a moment process) » � Only small amount of address space must be resident in physical memory 7 8 Maria Hybinette, UGA Maria Hybinette, UGA Virtual Memory Approach: Virtual Address Space Intuition Mechanisms � � Each page in virtual address space maps to one of three � � Idea : OS keeps unreferenced pages on disk locations: » � Slower, cheaper backing store than memory » � Physical main memory: Small, fast, expensive � � Process can run when not all pages are loaded into » � Disk (backing store): Large, slow, cheap main memory » � Nothing (error): Free � � OS and hardware cooperate to provide illusion of large disk as fast as main memory Smaller, faster » � Same behavior as if all of address space in main memory and more Leverage memory » � Hopefully have similar performance registers expensive hierarchy of machine � � Requirements: architecture cache » � OS must have mechanism to identify location of each Each layer acts as “backing store” for the page in address space in memory or on disk Bigger, smaller main memory and cheaper layer above » � OS must have policy for determining which pages live in memory and which on disk Disk Storage 9 10 Maria Hybinette, UGA Maria Hybinette, UGA Virtual Address Space Mechanisms Virtual Memory Mechanisms (cont) Frame # � valid-invalid bit � Extend page tables with an extra bit The TLB factor: Hardware and OS cooperate to translate addresses 1 � to indicate whether it is in memory 1 � � � First, hardware checks TLB for virtual address 1 � or on disk (a resident bit): 1 � » � TLB hit: Address translation is done; page in physical memory 0 � � � valid (or invalid) � � � » � TLB miss: � � Page in memory: valid bit set in page 0 � table entry (PTE) – � Hardware or OS walk page tables 0 � page table � � � Page out to disk: valid bit cleared – � If PTE designates page is valid, then page in physical memory ( invalid ) � � Main Memory Miss: Not in main memory: Page fault (i.e., – � PTE points to block on disk invalid ) – � Causes trap into OS when page is » � Trap into OS (not handled by hardware) referenced – � Trap: page fault » � OS selects victim page in memory to replace – � Write victim page out to disk if modified (add dirty bit to PTE) » � OS reads referenced page from disk into memory » � Page table is updated, valid bit is set » � Process continues execution 11 12 Maria Hybinette, UGA Maria Hybinette, UGA

  3. Flow of “Paging” Operations Virtual Memory Policies PTE in TLB? CPU checks TLB � � OS needs to decide on policies on page faults concerning: Yes PTE in TLB? » � Page selection (When to bring in) No Access page table – � When should a page (or pages) on disk be brought into memory? Page fault routine – � Two cases OS Instructs CPU No Page in MM? to read the page � � When process starts, code pages begin on disk from disk Yes � � As process runs, code and data pages may be moved to disk CPU activates Update TLB I/O hardware » � Page replacement (What to replace) Page transferred – � Which resident page (or pages) in memory should be thrown out from disk to CPU generates main memory physical address to disk? � � Goal: Minimize number of page faults Yes Memory Full? » � Page faults require milliseconds to handle (reading from disk) No Page replacement » � Implication: Plenty of time for OS to make good decision Page tables updated 14 Maria Hybinette, UGA The When : Page Selection Page Selection Continued � � When should a page be brought from disk into memory? � � Prepaging (anticipatory, prefetching): OS loads page into memory before page is referenced � � Request paging: User specifies which pages are needed for process » � OS predicts future accesses (oracle) and brings pages into memory ahead of time » � Problems: – � How? – � Manage memory by hand – � Works well for some access patterns (e.g., sequential) – � Users do not always know future references » � Advantages: May avoid page faults – � Users are not impartial » � Problems? : � � Demand paging: Load page only when page fault occurs � � Hints: Combine demand or prepaging with user- » � Intuition: Wait until page must absolutely be in memory supplied hints about page references » � When process starts: No pages are loaded in memory » � User specifies: may need page in future, don’t need this » � Advantage: Less work for user page anymore, or sequential access pattern, ... » � Disadvantage: Pay cost of page fault for every newly » � Example: madvise() in Unix (1994 4.4 BSD UNIX) accessed page 15 16 Maria Hybinette, UGA Maria Hybinette, UGA What happens if there is no free Virtual Page Optimizations frame? � � Page replacement � � Copy-on-Write: on process creation allow » � find some page in memory, but not really in use, parent and child to share the same page in swap it out memory until one modifies the page. � � Observation: Same page may be brought into memory several times copy page C 17 18 Maria Hybinette, UGA Maria Hybinette, UGA

Recommend


More recommend