1 / 14

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Background Demand Paging. Objectives. To describe the benefits of a virtual memory system To explain the concepts of demand paging. Background. The instructions being executed must be in physical memory.

sona
Télécharger la présentation

Chapter 9: Virtual Memory

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. Chapter 9: Virtual Memory

  2. Chapter 9: Virtual Memory • Background • Demand Paging

  3. Objectives • To describe the benefits of a virtual memory system • To explain the concepts of demand paging

  4. Background • The instructions being executed must be in physical memory. • An examination of real programs shows us that, in many cases, the entire program (in memory) is not needed. • Programs often have code to handle unusual error conditions (seldom used). • Arrays, lists, and tables are often allocated more memory than they actually need. • Certain options and features of a program may be used rarely. • The ability to execute a program that is only partially in memory would offer many benefits: • A program would no longer be constrained by the amount of physical memory that is available (simplifying the programming task). • Because each user program could take less physical memory, more programs could be run at the same time, with a corresponding increase in CPU utilization and throughput.. • Less I/O would be needed to load or swap each user program into memory, so each user program would run faster.

  5. Background • Virtual memory– separation of user logical memory from physical memory This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available (see Fig. 9.1). • 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 • More programs running concurrently • Less I/O needed to load or swap processes • Virtual memory can be implemented via: • Demand paging • Demand segmentation

  6. Virtual Memory That is Larger Than Physical Memory( fig 9.1)

  7. Demand Paging • Consider how an executable program might be loaded from disk into memory. • One option is to load the entire program in physical memory at program execution time. However, a problem with this approach is that we may not initially need the entire program in memory. • An alternative strategy is to initially load pages only as they are needed. This technique is known as demand paging and is commonly used in virtual memory systems. • A demand-paging system is similar to a paging system with swapping (see Fig. 9.4) where processes reside in secondary memory (usually a disk). • Lazy swapper– never swaps a page into memory unless page will be needed • This is termed a lazy swapper, although a pager is a more accurate term.

  8. Transfer of a Paged Memory to Contiguous Disk Space (fig 9.4)

  9. Demand Paging • When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again. • It avoids reading into memory pages that will not be used anyway, decreasing the swap time and the amount of physical memory needed. • Some form of hardware support is needed to distinguish between the pages that are in memory and the pages that are on the disk. • The valid -invalid bit scheme can be used for this purpose. • This time however, when this bit is set to ``valid'', the associated page is both legal and in memory. • If the bit is set to ``invalid'', the page either is not valid (that is, not in the logical address space of the process) or is valid but is currently on the disk. • The page-table entry for a page that is brought into memory is set as usual, • but the page-table entry for a page that is not currently in memory is either simply marked invalid or contains the address of the page on disk (see Fig. 9.5). • While the process executes and accesses pages that are memory resident, execution proceeds normally. • But what happens if the process tries to access a page that was not brought into memory? Access to a page marked invalid causes a page-fault trap. • The paging hardware, in translating the address through the page table, will notice that the invalid bit is set, causing a trap to the OS.

  10. Valid-Invalid Bit • With each page table entry a valid–invalid bit is associated(v in-memory – memory resident,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 Frame # valid-invalid bit v v v v i …. i i page table

  11. Page Table When Some Pages Are Not in Main Memory (fig9.5)

  12. Page Fault • The procedure for handling this page fault is straightforward (see Fig. 9.6). • If there is a reference to a page, first reference to that page will trap to operating system: page fault • Operating system looks at another table to decide: • Invalid reference  abort • Valid  Just not in memory • Get empty frame • We schedule a disk operation to read the desired page into the newly allocated frame. • Reset tables to indicate page now in memorySet validation bit = v • Restart the instruction that caused the page fault

  13. Steps in Handling a Page Fault (fig9.6)

  14. End of Chapter 9

More Related