1 / 65

Memory Management Review of Designs and Issues

Memory Management Review of Designs and Issues. Basic memory management Swapping Virtual memory Page replacement algorithms Design issues for paging systems Implementation issues Segmentation. Memory Management . Ideally programmers want memory that is large fast non volatile

Download Presentation

Memory Management Review of Designs and Issues

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. Memory ManagementReview of Designs and Issues Basic memory management Swapping Virtual memory Page replacement algorithms Design issues for paging systems Implementation issues Segmentation

  2. Memory Management • Ideally programmers want memory that is • large • fast • non volatile • Memory hierarchy • small amount of fast, expensive memory – cache • some medium-speed, medium price main memory • gigabytes of slow, cheap disk storage • Memory manager handles the memory hierarchy

  3. Multiprogramming with Fixed Partitions • Fixed memory partitions • separate input queues for each partition • single input queue

  4. Modeling Multiprogramming CPU utilization as a function of number of processes in memory Degree of multiprogramming

  5. Analysis of Multiprogramming System Performance • Arrival and work requirements of 4 jobs • CPU utilization for 1 – 4 jobs with 80% I/O wait • Sequence of events as jobs arrive and finish • note numbers show amout of CPU time jobs get in each interval

  6. Relocation and Protection • Cannot be sure where program will be loaded in memory • address locations of variables, code routines cannot be absolute • must keep a program out of other processes’ partitions • Use base and limit values • address locations added to base value to map to physical addr • address locations larger than limit value is an error

  7. Swapping (1) Memory allocation changes as • processes come into memory • leave memory Shaded regions are unused memory

  8. Swapping (2) • Allocating space for growing data segment • Allocating space for growing stack & data segment

  9. Memory Management with Bit Maps • Part of memory with 5 processes, 3 holes • tick marks show allocation units • shaded regions are free • Corresponding bit map • Same information as a list

  10. Memory Management with Linked Lists Four neighbor combinations for the terminating process X

  11. Virtual MemoryPaging (1) The position and function of the MMU

  12. Paging (2) The relation betweenvirtual addressesand physical memory addres-ses given bypage table

  13. Page Tables (1) Internal operation of MMU with 16 4 KB pages

  14. Page Tables (2) Second-level page tables • 32 bit address with 2 page table fields • Two-level page tables Top-level page table

  15. Page Tables (3) Typical page table entry

  16. TLBs – Translation Lookaside Buffers A TLB to speed up paging

  17. Inverted Page Tables Comparison of a traditional page table with an inverted page table

  18. Page Replacement Algorithms • Page fault forces choice • which page must be removed • make room for incoming page • Modified page must first be saved • unmodified just overwritten • Better not to choose an often used page • will probably need to be brought back in soon

  19. Optimal Page Replacement Algorithm • Replace page needed at the farthest point in future • Optimal but unrealizable • Estimate by … • logging page use on previous runs of process • although this is impractical

  20. Not Recently Used Page Replacement Algorithm • Each page has Reference bit, Modified bit • bits are set when page is referenced, modified • Pages are classified • not referenced, not modified • not referenced, modified • referenced, not modified • referenced, modified • NRU removes page at random • from lowest numbered non empty class

  21. FIFO Page Replacement Algorithm • Maintain a linked list of all pages • in order they came into memory • Page at beginning of list replaced • Disadvantage • page in memory the longest may be often used

  22. Second Chance Page Replacement Algorithm • Operation of a second chance • pages sorted in FIFO order • Page list if fault occurs at time 20, A has R bit set(numbers above pages are loading times)

  23. The Clock Page Replacement Algorithm

  24. Least Recently Used (LRU) • Assume pages used recently will used again soon • throw out page that has been unused for longest time • Must keep a linked list of pages • most recently used at front, least at rear • update this list every memory reference !! • Alternatively keep counter in each page table entry • choose page with lowest value counter • periodically zero the counter

  25. Review of Page Replacement Algorithms

  26. Replacement Scope • Scope of replacement policy can be: • Local replacement policy – chooses only among the resident pages of the process that generated page fault in selecting a page to replace • Global replacement policy – considers all unlocked pages in main memory as candidates for replacement, regardless of which process owns a particular page • Global policies are more attractive because of the simplicity of implementation and minimal overhead

  27. Replacement Scope • Fixed Allocation, Local Replacement Scope • Number of frames allocated to a process is fixed in advance • Too small: leads to thrashing • Too big: wastes memory • Reduces the available number of processes that can be in memory • Operating system is choosing the page to be replaced among the frames allocated to that process • Global replacement scope is not possible

  28. Replacement scope (3) • Variable Allocation, Global Replacement Scope • This combination is the easiest to implement and is a common technique in operating systems • When a page fault occurs, a free frame is added to the resident set of the process who experiences a page fault and the page is brought up in that frame • Harder to determine who should lose a page; the selection is made among all the frames in the memory (except the locked ones), there is no discipline to determine which process should loose a page from its resident set • May remove a page from a process that needs it

  29. Replacement Scope • Variable Allocation, Local Replacement Scope • Concept • When loading a process, allocate it a set of page frames • After a page fault, replace one of those pages • Periodically reevaluate set size, adjust it to improve performance • For this method, it is important to determine the resident set size and timing of changes. • working set strategy – one method to deal with those aspects

  30. Load Control • Determines the number of processes that will be resident in main memory • referenced as multiprogramming level • Too few processes, many occasions when all processes will be blocked and much time will be spent in swapping • Too many processes will lead to thrashing (page fault rate will be very high)

  31. Load Control • Despite good designs, system may still thrash • When Page Fault Function algorithm indicates • some processes need more memory • but no processes need less • Solution :Reduce number of processes competing for memory • swap one or more to disk, divide up pages they held • reconsider degree of multiprogramming

  32. Multiprogramming Level • Solutions: • Having a page fault frequency algorithm implicitly incorporates load control (only those processes which have a sufficiently large resident set are allowed to execute); • In providing the required resident set size for each active process, the replacement policy automatically and dynamically determines the number of active processes • Adjust dynamically the multiprogramming level so that the mean time between page faults equals the mean time required to process a page fault; • studies show that this is the point where the processor utilization is attained a maximum

  33. Page Size Small page size • Advantages • less internal fragmentation • better fit for various data structures, code sections • less unused program in memory • Disadvantages • programs need many pages, larger page tables

  34. Separate Instruction and Data Spaces • One address space • Separate I and D spaces

  35. Shared Pages Two processes sharing same program sharing its page table

  36. Cleaning Policy • Need for a background process, paging daemon • periodically inspects state of memory • When too few frames are free • selects pages to evict using a replacement algorithm • It can use same circular list • as regular page replacement algorithm but with different pointer

  37. Cleaning Policy • Demand cleaning • A page is written out only when it has been selected for replacement • Pre-cleaning • Writes modified pages before their associated frames are needed so that pages can be written out in batches • Best approach uses page buffering • Replaced pages are placed in two lists • Modified and unmodified • Pages in the modified list are periodically written out in batches • Pages in the unmodified list are either reclaimed if referenced again or lost when its frame is assigned to another page

  38. Implementation IssuesOperating System Involvement with Paging Four times when OS involved with paging • Process creation • determine program size • create page table • Process execution • MMU reset for new process • TLB flushed • Page fault time • determine virtual address causing fault • swap target page out, needed page in • Process termination time • release page table, pages

  39. Locking Pages in Memory • Virtual memory and I/O occasionally interact • Process issues call for read from device into buffer • while waiting for I/O, another processes starts up • has a page fault • buffer for the first procoss may be chosen to be paged out • Need to specify some pages locked • exempted from being target pages

  40. Backing Store (a) Paging to static swap area (b) Backing up pages dynamically

  41. Separation of Policy and Mechanism Page fault handling with an external pager

  42. Segmentation (1) • One-dimensional address space with growing tables • One table may bump into another

  43. Segmentation (2) Allows each table to grow or shrink, independently

  44. Segmentation (3) Comparison of paging and segmentation

  45. Implementation of Pure Segmentation (a)-(d) Development of checker boarding (e) Removal of the checker boarding by compaction

  46. Segmentation with Paging • Descriptor segment points to page tables • Segment descriptor – numbers are field lengths

  47. Segmentation with Paging A 34-bit virtual address

  48. Segmentation with Paging Protection Level

  49. Segmentation Summary • A process is divided into a number of segments that don’t need to be equal in size • When a process is brought into the main memory, then all of its segments are usually brought into main memory and a process segment table is setup. • Advantages: • The virtual address space of a process is divided into logically distinct units which correspond to constituent parts of a process • Segments are the natural units of access control; the process may have different access rights for different segments • Segments are the natural units for sharing code and data objects with other processes • Disadvantages: • Inconvenient for operating system to manage storage allocation for variable-sized segments because each segment that is held in physical memory must be contiguous; after the system has been running for a while, the free memory available can be fragmented • This is known as external fragmentation, because though the total free memory might be far greater than the size of some segment that must be loaded, still there is no single area large enough to load it • External fragmentation might be solved by moving segments that are not needed out to the disk and moving them back when they are needed. This is called swapping.

  50. Paging Summary • Advantages – by using fixed size pages in virtual address space and fixed size pages in physical address space, it addresses some of the problems with segmentation: • External fragmentation is no longer a problem (all frames in physical memory are same size) • Transfers to/from disks can be performed at granularity of individual pages • Disadvantages • The page size is a choose made by CPU or OS designer • It may not fit the size of program data structures and lead to internal fragmentation in which storage allocation request must be rounded to an integral number of pages • There may be no correspondence between page protection settings and application data structures • If two process are to share data structures, they may do so at the level of sharing entire pages • Requiring per process page tables, it is likely that the OS require more storage for its internal data structures

More Related