1 / 103

Understanding Operating Systems Fifth Edition

Understanding Operating Systems Fifth Edition. Chapter 3 Memory Management: Virtual Memory. Learning Objectives. After completing this chapter, you should be able to describe:

guido
Télécharger la présentation

Understanding Operating Systems Fifth Edition

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. Understanding Operating SystemsFifth Edition Chapter 3Memory Management:Virtual Memory

  2. Learning Objectives After completing this chapter, you should be able to describe: • The basic functionality of the memory allocation methods covered in this chapter: paged, demand paging, segmented, and segmented/demand paged memory allocation • The influence that these page allocation methods have had on virtual memory Understanding Operating Systems, Sixth Edition

  3. Learning Objectives (cont'd.) • The difference between a first-in first-out page replacement policy, a least-recently-used page replacement policy, and a clock page replacement policy • The mechanics of paging and how a memory allocation scheme determines which pages should be swapped out of memory Understanding Operating Systems, Sixth Edition

  4. Learning Objectives (cont'd.) • The concept of the working set and how it is used in memory allocation schemes • The impact that virtual memory had on multiprogramming • Cache memory and its role in improving system response time Understanding Operating Systems, Sixth Edition

  5. Introduction • Evolution of virtual memory • Paged, demand paging, segmented, segmented/demand paging • Foundation for current virtual memory methods • Improvement areas • Need for continuous program storage • Need for placement of entire program in memory during execution • Fragmentation • Overhead due to relocation Understanding Operating Systems, Sixth Edition

  6. Introduction (cont'd.) • Page replacement policies • First-In First-Out • Least Recently Used • Clock replacement and bit-shifting • Mechanics of paging • The working set • Virtual memory • Concepts and advantages • Cache memory • Concepts and advantages Understanding Operating Systems, Sixth Edition

  7. Introduction (cont'd.) • The evolution of virtual memory involves four memory allocation schemes • Paged Memory Allocation • Demand Paging • Segmented Memory Allocation • Segmented/Demand Paging Allocation Understanding Operating Systems, Sixth Edition

  8. Paged Memory Allocation • Before a job is loaded into memory, it is divided into parts called pages that will be loaded into memory locations called page frames. • Paged Memory Allocation is based on the concept of dividing each incoming job into pages of equal size. • Some OS choose a page size that is the same as the memory block size and that is also the same size as the sections of disk on which the job is stored. Understanding Operating Systems, Sixth Edition

  9. Paged Memory Allocation • Before executing a program, the Memory Manager prepares it by: • Determining the number of pages in program; • Locating enough empty page frames in main memory; • Loading all the program’s pages into page frames. • When the program is initially prepared for loading, its pages are in logical sequence. • The program pages, however, do not have to be loaded in adjacent memory. • Each page can be stored in any available page frame anywhere in main memory. Understanding Operating Systems, Sixth Edition

  10. Paged Memory Allocation • The primary advantage of storing programs in noncontiguous locations is that main memory is used more efficiently because an empty page frame can be used by any page of any job. • Because a job’s pages can be located anywhere in main memory, the Memory Manager now needs a mechanism to keep track of them. • This enlarges the size and complexity of the OS which increases overhead. • Figure 3.1 shows how the Memory Manager keeps track of a program that is four pages long. • The page size has been arbitrarily set at 100 bytes. Understanding Operating Systems, Sixth Edition

  11. Paged Memory Allocation • Job 1 is 350 bytes long and is being readied for execution. Understanding Operating Systems, Sixth Edition

  12. Paged Memory Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  13. Paged Memory Allocation • In Figure 3.1 (with seven free page frames), the OS can accommodate jobs that vary in size from 1 to 700 bytes because they can be stored in the seven empty page frames. • But, a job that is larger than 700 bytes can’t be accommodated until Job 1 ends its execution and releases the four page frames it occupies. • A job that is larger than 1100 bytes will never fit into the memory of this tiny system. • Therefore, although paged memory allocation offers the advantage of noncontiguous storage, it still requires that the entire job be stored in memory during its execution. Understanding Operating Systems, Sixth Edition

  14. Paged Memory Allocation (cont'd.) • The Memory Manager use three tables for tracking program pages. • All three tables reside in the part of main memory that is reserved for the OS. • Job Table (JT) • Contains two values for each active job • Size of job • The memory location where its PMT is stored • The Job Table is a dynamic list that grows as jobs are loaded into the system and shrinks as they are later completed. Understanding Operating Systems, Sixth Edition

  15. Paged Memory Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  16. Paged Memory Allocation (cont'd.) • Page Map Table (PMT) • Each active job has its own PMT. • Contains the vital information for each page: • The page number • Sequential (Page 0, Page 1, Page 2, through the last page). • Its corresponding page frame memory address • Memory Map Table (MMT) • Has one entry for each page frame listing: • Its Locationfor each page frame • Free/busy status Understanding Operating Systems, Sixth Edition

  17. Paged Memory Allocation (cont'd.) • At compilation time, every job is divided into pages. • Using Job 1 (Figure 3.1): • Page 0 contains the first hundred bytes; • Page 1 contains the second hundred bytes; • Page 2 contains the third hundred bytes; • Page 3 contains the last 50 bytes. Understanding Operating Systems, Sixth Edition

  18. Paged Memory Allocation (cont'd.) • Displacement (offset) of a byte (how far away a byte is from the beginning of its page) is the factor used to locate that byte within its page frame. • It is a relative value. • Using Figure 3.2: • Bytes 0, 100, 200, and 300 are the first bytes for pages 0, 1, 2, and 3. • Each has a displacement of zero. • If the OS needs to access byte 214, it can first go to the page 2 and then go to byte 14. Understanding Operating Systems, Sixth Edition

  19. Paged Memory Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  20. Paged Memory Allocation (cont'd.) • To find the address of a given program instruction, the byte number is divided by the page size, keeping the remainder as an integer. • The resulting quotient is the page number, and the remainder is the displacement within that page. • This procedure gives the location of an instruction with respect to the job’s pages. • Pages are only relative. • Each page is actually stored in a page frame that can be located anywhere in available memory. Understanding Operating Systems, Sixth Edition

  21. Paged Memory Allocation (cont'd.) • To find the exact location of a line in memory: • Perform the arithmetic computation to determine the page number and displacement of the requested byte. • Page Number = the integer quotient from the division of the job space address by the page size (2). • Displacement = the remainder from the page number division (14). • Refer to the job’s PMT to determine which page frame contains the required page. • Page 2 is located in Page Frame 5. Understanding Operating Systems, Sixth Edition

  22. Paged Memory Allocation (cont'd.) • Obtain the address of the beginning of the page frame by multiplying page frame number (5) by the page frame size (100). • 500 • Add the displacement (calculated in first step) to the starting address ofthe page frame to compute the precise location in memory of the instruction. • 500 + 14 Understanding Operating Systems, Sixth Edition

  23. Paged Memory Allocation (cont'd.) Understanding Operating Systems, Sixth Edition

  24. Paged Memory Allocation (cont'd.) • Every time an instruction is executed, or a data value is used, the OS (or the hardware) must translate the job space address (relative) into its physical address (absolute) • Address Resolution • Address Translation • All of this processing is overhead which takes processing capability away from the jobs waiting to be completed. Understanding Operating Systems, Sixth Edition

  25. Paged Memory Allocation (cont'd.) • Advantages of a paging scheme • It allows jobs to be allocated in noncontiguous memory locations so that memory is used more efficiently; • More jobs can fit into main memory. • Disadvantages • Overhead is increased and internal fragmentation is still a problem on the last page of each job. • Must store entire job in memory location Understanding Operating Systems, Sixth Edition

  26. Paged Memory Allocation (cont'd.) • Disadvantages • Page size selection is crucial • A page size that is too small will generate very long PMTs; • A page size that is too large will result in excessive internal fragmentation. • The best size depends on the actual job environment, the nature of the jobs being processed, and the constraints placed on the system, Understanding Operating Systems, Sixth Edition

  27. Demand Paging • Demand Paging introduced the concept of loading only a part of the program into memory for processing. • Removed the restriction of having the entire job in memory from the beginning to the end of its processing. • Jobs are still divided into equally sized pages that initially reside in secondary storage. • When the job begins to run, its pages are brought into memory only as they are needed. Understanding Operating Systems, Sixth Edition

  28. Demand Paging • Takes advantage of the fact that programs are written sequentially. • While one section (module) is processed all of the other modules are idle. • User-written error handling modules are processed only when a specific error is detected during execution. • If no error occurs, these instructions are never processed and never need to be loaded into memory. Understanding Operating Systems, Sixth Edition

  29. Demand Paging • Many modules are mutually exclusive. • If the input module is active, the processing module is inactive. • If the processing module is active, the output module is idle. Understanding Operating Systems, Sixth Edition

  30. Demand Paging (cont'd.) • Made virtual memory feasible. • Demand Paging allows the user to run jobs with less main memory than is required. • Demand Paging provides the appearance of an almost-infinite or nonfinite amount of physical memory. • Requires high-speed direct access storage device that can work directly with the CPU. • Pages must be passed quickly from secondary storage to main memory and back again. • Swapping: how and when pages passed in memory • Depends on predefined policies Understanding Operating Systems, Sixth Edition

  31. Demand Paging (cont'd.) • Memory Manager requires three tables • Job Table • Memory Map Table • Page Map Table: three new fields for each page in the PMT: • If page has been referenced recently • If the page contains contents that have been modified • If the page has been referenced recently • Used to determine which pages show the most processing activity. • Determines which pages should remain in main memory and which should be swapped out when the system needs to make room for other pages being requested. Understanding Operating Systems, Sixth Edition

  32. Demand Paging (cont'd.) Understanding Operating Systems, Sixth Edition

  33. Demand Paging (cont'd.) • Swapping Process • Job 4 requests that Page 3 be brought into memory even though there are no more empty page frames available • A resident page must be swapped back into secondary storage. • This includes copying the resident page to the disk (if it was modified), and writing the new page into the empty page frame. • The hardware components generate the address of the required page, find the page number. And determine whether it is already in memory. Understanding Operating Systems, Sixth Edition

  34. Demand Paging (cont'd.) • Swapping Process • If the page is in secondary storage but not in memory, the OS software takes over. • The Page Fault Handler determines whether there are empty page frames in memory so the requested page can be immediately copied from secondary storage. • If all page frames are busy, the Page Fault Handler must decide which page will be swapped out. • This decision is directly dependent on the predefined policy for page removal. • The swap is made. Understanding Operating Systems, Sixth Edition

  35. Demand Paging (cont'd.) • Swapping Process • Three tables are updated: • The PMT for both jobs (The PMT with the page that was swapped out and the PMT with the page that was swapped in). • The MMT is updated • The instruction that was interrupted is resumed and processing continues. Understanding Operating Systems, Sixth Edition

  36. Demand Paging (cont'd.) • Thrashing • When there is an excessive amount of page swapping between main memory and secondary storage, the operation becomes inefficient. • It uses a great deal of the computer’s energy but accomplishes very little. • It is caused when a page is removed from memory but is called back shortly thereafter. • Can occur across jobs when a large number of jobs are competing for a relatively few number of free pages. • Can occurs within a job in loops crossing pageboundaries. Understanding Operating Systems, Sixth Edition

  37. Demand Paging (cont'd.) • Advantages • Job is no longer constrained by the size of physical memory • Concept of virtual memory • Utilizes memory more efficiently than previous schemes • Faster response • Disadvantages • Increased overhead caused by tables and page interrupts Understanding Operating Systems, Sixth Edition

  38. Page Replacement Policies and Concepts • The Page Replacement Policy is crucial to the efficiency of the system. • Two of the most well-known Page replacement polices are: • First-In First-Out (FIFO)Policy: • Will remove the pages that have been in memory the longest. • FIFO anomaly • More memory does not lead to better performance • Least Recently Used (LRU)Policy: • Swaps out the pages that show the least amount of activity. Understanding Operating Systems, Sixth Edition

  39. Page Replacement Policies and Concepts • A variation of the LRU page replacement algorithm is known as the Clock Page Replacement Policy. • Implemented with a circular queue and uses a pointer to step through the reference bits of the active pages, simulating a clockwise motion. • The algorithm is paced according to the computer’s clock cycle. • The time span between two ticks in its system clock. • The algorithm checks the reference bit for each page. • If the bit is one (indicating that it was recently referenced) the bit is reset to zero and the bit for the next page is checked. Understanding Operating Systems, Sixth Edition

  40. Page Replacement Policies and Concepts • If the reference bit is zero (indicating that the page has not recently been referenced) that page is targeted for removal. • If all the reference bits are set to one, then the pointer must cycle through the entire circular queue again giving each page a second and perhaps a third or fourth chance. Understanding Operating Systems, Sixth Edition

  41. Page Replacement Policies and Concepts • A second variation of LRU uses an 8-bit reference byte and a bit-shifting technique to track the usage of each page currently in memory. • When the page is first copied into memory, the leftmost bit of its reference byte is set to 1 and all bits to the right of the one are set to zero. • At specific time intervals of the clock cycle, the Memory Manager shifts each page’s reference bytes to the right by one bit, dropping their rightmost bit. • Each time a page is referenced, the leftmost bit of its reference byte is set to 1. Understanding Operating Systems, Sixth Edition

  42. Page Replacement Policies and Concepts • When a page fault occurs, the LRU policy selects the page with the smallest value in its reference bytes because that would be the page least recently used. • Other page removal algorithms: • MRU – most recently used • LFU – least frequently used. Understanding Operating Systems, Sixth Edition

  43. First-In First-Out (cont'd.) Understanding Operating Systems, Sixth Edition

  44. First-In First-Out (cont'd.) Understanding Operating Systems, Sixth Edition

  45. Least Recently Used • Removes pageleastrecently accessed • Efficiency • Causes either decrease in or same number of interrupts • Slightly better (compared to FIFO): 8/11 or 73% • LRU is a stack algorithm removal policy • Increasing main memory will cause either a decrease in or the same number of page interrupts • Does not experience FIFO anomaly Understanding Operating Systems, Sixth Edition

  46. Least Recently Used (cont'd.) Understanding Operating Systems, Sixth Edition

  47. The Mechanics of Paging • Before the Memory manager can determine which pages will be swapped out, it needs specific information about each page in memory • Information included in the Page Map Tables • Status Bit • Referenced Bit • Modified Bit Understanding Operating Systems, Sixth Edition

  48. The Mechanics of Paging (cont'd.) • Status bit • Indicates whether the page is currently in memory. • Referenced bit • Indicates whether the page has been referenced recently. • Used by LRU algorithm to determine which pages should be swapped out. • Modified bit • Whether the contents of the page contents have been altered. • If so, the page must be rewritten to secondary storagewhen it is swapped out before its page frame is released. Understanding Operating Systems, Sixth Edition

  49. The Mechanics of Paging (cont'd.) Understanding Operating Systems, Sixth Edition

  50. The Mechanics of Paging (cont'd.) • Four possible combinations of the referenced and modified bits • A page must be in memory before it can be swapped out so all the candidates for swapping have a 1 in this column. • The other two bits can be either 0 or 1 Understanding Operating Systems, Sixth Edition

More Related