CHAPTER 9:VIRTUAL MEMORY
CHAPTER 9: VIRTUAL MEMORY
CHAPTER 9:VIRTUAL MEMORY o Background o Demand Paging o Copy-on-Write o Page Replacement o Allocation of Frames o Thrashing o Memory-Mapped Files o Allocating Kernel Memory o Other Considerations o Operating-System Examples
CHAPTER 9: VIRTUAL MEMORY Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System Examples
OBJECTIVES o To describe the benefits of a virtual memory system o To explain the concepts of demand paging, page-replacement algorithms,and allocation of page frames o To discuss the principle of the working-set model
OBJECTIVES To describe the benefits of a virtual memory system To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames To discuss the principle of the working-set model
BACKGROUND o Virtual memory-separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution Logical address space can therefore be much larger than physical address space Allows address spaces to be shared by several processes Allows for more efficient process creation o Virtual memory can be implemented via: 。Demand paging ·Demand segmentation
BACKGROUND Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution Logical address space can therefore be much larger than physical address space Allows address spaces to be shared by several processes Allows for more efficient process creation Virtual memory can be implemented via: Demand paging Demand segmentation
VIRTUAL MEMORY THAT IS LARGER THAN PHYSICAL MEMORY page 0 page 1 page 2 memory map page v physical memory virtual memory
VIRTUAL MEMORY THAT IS LARGER THAN PHYSICAL MEMORY
VIRTUAL-ADDRESS SPACE Max stack heap data code 0
VIRTUAL-ADDRESS SPACE
SHARED LIBRARY USING VIRTUAL MEMORY stack stack shared shared library pages shared library heap heap data data code code
SHARED LIBRARY USING VIRTUAL MEMORY
DEMAND PAGING o Bring a page into memory only when it is needed ·Less I/O needed ·Less memory needed ·Faster response ·ore users o Page is needed =reference to it 。invalid reference→abort not-in-memory>bring to memory o Lazy swapper-never swaps a page into memory unless page will be needed Swapper that deals with pages is a pager
DEMAND PAGING Bring a page into memory only when it is needed Less I/O needed Less memory needed Faster response More users Page is needed reference to it invalid reference abort not-in-memory bring to memory Lazy swapper – never swaps a page into memory unless page will be needed Swapper that deals with pages is a pager
TRANSFER OF A PAGED MEMORY TO CONTIGUOUS DISK SPACE swap out 0☐1☐2☐3☐ program A 4古5d7 8☐9☐10☐11☐ 12☐13☐14☐15☐ program B swap in 16☐17☐18☐19☐ 20☐21☐22☐23☐ main memory
TRANSFER OF A PAGED MEMORY TO CONTIGUOUS DISK SPACE
VALID-INVALID BIT 0 With each page table entry a valid-invalid bit is associated (w→in-memory,i→not-in-memory) o Initially valid-invalid bit is set to i on all entries o Example of a page table snapshot: Frame valid-invalid bit V i i page table o During address translation,if valid-invalid bit in page table entry isI→page fault
VALID-INVALID BIT With each page table entry a valid–invalid bit is associated (v in-memory, i not-in-memory) Initially valid–invalid bit is set to i on all entries Example of a page table snapshot: During address translation, if valid–invalid bit in page table entry is I page fault v v v v i i i …. Frame # valid-invalid bit page table