Chapter 3 : Memory Management, Recent Systems <ul><li>Paged Memory Allocation </li></ul><ul><li>Demand Paging </li></ul><u...
Memory Management <ul><li>Early schemes were limited to storing entire program in memory. </li></ul><ul><ul><li>Fragmentat...
More Recent Memory Management Schemes <ul><li>Paged Memory Allocation </li></ul><ul><li>Demand Paging Memory Allocation </...
Paged Memory Allocation <ul><li>Divides each incoming job into  pages  of equal size. </li></ul><ul><li>Works well if page...
Programs Are Split Into Equal-sized Pages  (Figure 3.1)
Job 1  (Figure 3.1) <ul><li>At compilation time every job is divided into pages: </li></ul><ul><ul><li>Page 0 contains the...
Paging Requires 3 Tables to Track a Job’s Pages <ul><li>1. Job table (JT)  - 2 entries for each active job. </li></ul><ul>...
Job Table Contains 2 Entries for Each Active Job  (Table 3.1)
Job 1 Is 350 Lines Long & Divided Into 4 Pages  (Figure 3.2)
Displacement  (Figure 3.2) <ul><li>Displacement (offset ) of a line --  how far away a line is from the beginning of its p...
To Find the Address of a Given Program Line <ul><li>Divide the line number by the page size, keeping the remainder as an i...
Address Resolution <ul><li>Each time and instruction is executed or a data value is used, the OS or (hardware) must: </li>...
Pros & Cons of Paging <ul><li>Allows jobs to be allocated in non-contiguous memory locations. </li></ul><ul><ul><li>Memory...
Demand Paging <ul><li>Bring a page into memory only when it is needed, so less I/O & memory needed. </li></ul><ul><ul><li>...
Demand Paging - 2 <ul><li>Demand paging made virtual memory widely available . </li></ul><ul><ul><li>Can give appearance o...
Tables in Demand Paging <ul><li>Job Table. </li></ul><ul><li>Page Map Table (with 3 new fields). </li></ul><ul><ul><li>Det...
Page Map Table
Hardware Instruction  Processing Algorithm   <ul><li>Start processing instruction </li></ul><ul><li>Generate data address ...
Page Fault Handler Algorithm <ul><li>If there is no free page frame </li></ul><ul><li>Then Select page to be swapped out u...
Thrashing Is a Problem  With Demand Paging <ul><li>Trashing  – an excessive amount of page swapping back and forth between...
Page Replacement Policies   <ul><li>Policy that selects page to be removed is crucial to system efficiency.  </li></ul><ul...
FIFO policy.  When program calls for Page C, Page A is moved out of 1st page frame to make room for it (solid lines). When...
How each page requested is swapped into 2 available page frames using FIFO. When program is ready to be processed all 4 pa...
FIFO <ul><li>High failure rate shown in previous example caused by: </li></ul><ul><ul><li>limited amount of memory availab...
LRU Policy  For program in Figure 3.8. Throughout the program 11 page requests are issued, but they cause only 8 page inte...
LRU <ul><li>The efficiency of LRU is only slightly better than with FIFO.  </li></ul><ul><li>LRU is a  stack algorithm  re...
Mechanics of Paging : Page Map Table <ul><li>Status bit  indicates if page is currently in memory or not.  </li></ul><ul><...
Four Possible Combinations of Modified and Referenced Bits   Modified Referenced Meaning Case 1 0 0 Not modified AND not r...
Page Replacement : The Working Set   <ul><li>Working set  – set of pages residing in memory that can be accessed directly ...
Pros & Cons of Demand Paging <ul><li>First scheme in which a job was no longer constrained by the size of physical memory ...
Segmented Memory Allocation <ul><li>Based on common practice by programmers of structuring their programs in  modules ( lo...
Segment Map Table (SMT) <ul><li>When a program is compiled, segments are set up according to program’s structural modules....
Tables Used in Segmentation <ul><li>Memory Manager needs to track segments in memory: </li></ul><ul><li>Job Table (JT)  li...
Pros & Cons of Segmentation <ul><li>Compaction. </li></ul><ul><li>External fragmentation. </li></ul><ul><li>Secondary stor...
Segmented/Demand Paged  Memory Allocation   <ul><li>Evolved from combination of segmentation and demand paging. </li></ul>...
4 Tables Are Used in Segmented/Demand Paging <ul><li>Job  Table lists every job in process (one for whole system). </li></...
Pros & Cons of Segment/Demand Paging <ul><li>Overhead required for the extra tables </li></ul><ul><li>Time required to ref...
Virtual Memory (VM) <ul><li>Even though only a portion of each program is stored in memory, virtual memory gives appearanc...
Comparison of VM With Paging and With Segmentation
Advantages of VM  <ul><li>Works well in a multiprogramming environment because most programs spend a lot of time waiting. ...
Disadvantages of VM <ul><li>Increased processor hardware costs . </li></ul><ul><li>Increased overhead for handling paging ...
Key Terms <ul><li>address resolution </li></ul><ul><li>associative memory </li></ul><ul><li>demand paging </li></ul><ul><l...
Key Terms - 2 <ul><li>segmented memory allocation </li></ul><ul><li>segmented/demand paged memory allocation </li></ul><ul...
Upcoming SlideShare
Loading in …5
×

Chapter 3 memory management, recent systems

2,399 views

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,399
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
124
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Chapter 3 memory management, recent systems

  1. 1. Chapter 3 : Memory Management, Recent Systems <ul><li>Paged Memory Allocation </li></ul><ul><li>Demand Paging </li></ul><ul><li>Page Replacement Policies </li></ul><ul><li>Segmented Memory Allocation </li></ul><ul><li>Segmented/Demand Paged Memory Allocation </li></ul><ul><li>Virtual Memory </li></ul>Paged Memory Allocation Segmented Demand Paging Segmented/ Demand Paging
  2. 2. Memory Management <ul><li>Early schemes were limited to storing entire program in memory. </li></ul><ul><ul><li>Fragmentation. </li></ul></ul><ul><ul><li>Overhead due to relocation. </li></ul></ul><ul><li>More sophisticated memory schemes now that: </li></ul><ul><ul><li>Eliminate need to store programs contiguously. </li></ul></ul><ul><ul><li>Eliminate need for entire program to reside in memory during execution. </li></ul></ul>Problems
  3. 3. More Recent Memory Management Schemes <ul><li>Paged Memory Allocation </li></ul><ul><li>Demand Paging Memory Allocation </li></ul><ul><li>Segmented Memory Allocation </li></ul><ul><li>Segmented/Demand Paged Allocation </li></ul>
  4. 4. Paged Memory Allocation <ul><li>Divides each incoming job into pages of equal size. </li></ul><ul><li>Works well if page size = size of memory block size ( page frames ) = size of disk section ( sector, block ). </li></ul><ul><li>Before executing a program, memory manager: </li></ul><ul><li>1. Determines number of pages in program. </li></ul><ul><li>2. Locates enough empty page frames in main memory. </li></ul><ul><li>3. Loads all of the program’s pages into them. </li></ul>
  5. 5. Programs Are Split Into Equal-sized Pages (Figure 3.1)
  6. 6. Job 1 (Figure 3.1) <ul><li>At compilation time every job is divided into pages: </li></ul><ul><ul><li>Page 0 contains the first hundred lines. </li></ul></ul><ul><ul><li>Page 1 contains the second hundred lines. </li></ul></ul><ul><ul><li>Page 2 contains the third hundred lines. </li></ul></ul><ul><ul><li>Page 3 contains the last fifty lines. </li></ul></ul><ul><li>Program has 350 lines. </li></ul><ul><ul><li>Referred to by system as line 0 through line 349. </li></ul></ul>
  7. 7. Paging Requires 3 Tables to Track a Job’s Pages <ul><li>1. Job table (JT) - 2 entries for each active job. </li></ul><ul><ul><li>Size of job & memory location of its page map table. </li></ul></ul><ul><ul><li>Dynamic – grows/shrinks as jobs loaded/completed. </li></ul></ul><ul><li>2. Page map table (PMT) - 1 entry per page. </li></ul><ul><ul><li>Page number & corresponding page frame memory address. </li></ul></ul><ul><ul><li>Page numbers are sequential (Page 0, Page 1 …) </li></ul></ul><ul><li>3. Memory map table (MMT) - 1 entry for each page frame. </li></ul><ul><ul><li>Location & free/busy status. </li></ul></ul>
  8. 8. Job Table Contains 2 Entries for Each Active Job (Table 3.1)
  9. 9. Job 1 Is 350 Lines Long & Divided Into 4 Pages (Figure 3.2)
  10. 10. Displacement (Figure 3.2) <ul><li>Displacement (offset ) of a line -- how far away a line is from the beginning of its page. </li></ul><ul><ul><li>Used to locate that line within its page frame. </li></ul></ul><ul><ul><li>Relative factor. </li></ul></ul><ul><li>For example, lines 0, 100, 200, and 300 are first lines for pages 0, 1, 2, and 3 respectively so each has displacement of zero. </li></ul>
  11. 11. To Find the Address of a Given Program Line <ul><li>Divide the line number by the page size, keeping the remainder as an integer. </li></ul><ul><ul><ul><li> Page number </li></ul></ul></ul><ul><ul><ul><li>Page size line number to be located </li></ul></ul></ul><ul><ul><ul><li> xxx </li></ul></ul></ul><ul><ul><ul><li> xxx </li></ul></ul></ul><ul><ul><ul><li> xxx </li></ul></ul></ul><ul><li> Displacement </li></ul>
  12. 12. Address Resolution <ul><li>Each time and instruction is executed or a data value is used, the OS or (hardware) must: </li></ul><ul><ul><li>Translate the job space address (relative). </li></ul></ul><ul><ul><li>Into a physical address (absolute). </li></ul></ul>
  13. 13. Pros & Cons of Paging <ul><li>Allows jobs to be allocated in non-contiguous memory locations. </li></ul><ul><ul><li>Memory used more efficiently; more jobs can fit. </li></ul></ul><ul><li>Size of page is crucial (not too small, not too large). </li></ul><ul><li>Increased overhead occurs. </li></ul><ul><li>Reduces, but does not eliminate, internal fragmentation. </li></ul>
  14. 14. Demand Paging <ul><li>Bring a page into memory only when it is needed, so less I/O & memory needed. </li></ul><ul><ul><li>Faster response. </li></ul></ul><ul><li>Takes advantage that programs are written sequentially so not all pages are necessary at once. For example: </li></ul><ul><ul><li>User-written error handling modules. </li></ul></ul><ul><ul><li>Mutually exclusive modules. </li></ul></ul><ul><ul><li>Certain program options are either mutually exclusive or not always accessible. </li></ul></ul><ul><ul><li>Many tables assigned fixed amount of address space even though only a fraction of table is actually used. </li></ul></ul>
  15. 15. Demand Paging - 2 <ul><li>Demand paging made virtual memory widely available . </li></ul><ul><ul><li>Can give appearance of an almost-infinite or nonfinite amount of physical memory . </li></ul></ul><ul><li>Requires use of a high-speed direct access storage device that can work directly with CPU . </li></ul><ul><li>How and when the pages are passed (or “swapped”) depends on predefined policies that determine when to make room for needed pages and how to do so . </li></ul>
  16. 16. Tables in Demand Paging <ul><li>Job Table. </li></ul><ul><li>Page Map Table (with 3 new fields). </li></ul><ul><ul><li>Determines if requested page is already in memory. </li></ul></ul><ul><ul><li>Determines if page contents have been modified. </li></ul></ul><ul><ul><li>Determines if the page has been referenced recently. </li></ul></ul><ul><ul><ul><li>Used to determine which pages should remain in main memory and which should be swapped out. </li></ul></ul></ul><ul><li>Memory Map Table. </li></ul>
  17. 17. Page Map Table
  18. 18. Hardware Instruction Processing Algorithm <ul><li>Start processing instruction </li></ul><ul><li>Generate data address </li></ul><ul><li>Compute page number </li></ul><ul><li>If page is in memory </li></ul><ul><li>Then </li></ul><ul><li>get data and finish instruction </li></ul><ul><li>advance to next instruction </li></ul><ul><li>return to step 1 </li></ul><ul><li>Else </li></ul><ul><li>generate page interrupt </li></ul><ul><li>call page fault handler </li></ul>
  19. 19. Page Fault Handler Algorithm <ul><li>If there is no free page frame </li></ul><ul><li>Then Select page to be swapped out using page removal algorithm </li></ul><ul><li> Update job’s page map table </li></ul><ul><li> If content of page had been changed then </li></ul><ul><li> Write page to disk </li></ul><ul><li>End if </li></ul><ul><li>End if </li></ul><ul><li>2. Use page number from step 3 from the hardware instruction processing algorithm to get disk address where the requested page is stored. </li></ul><ul><li>3. Read page into memory. </li></ul><ul><li>4. Update job’s page map table. </li></ul><ul><li>5. Update memory map table. </li></ul><ul><li>6. Restart interrupted instruction. </li></ul>
  20. 20. Thrashing Is a Problem With Demand Paging <ul><li>Trashing – an excessive amount of page swapping back and forth between main memory and secondary storage. </li></ul><ul><ul><li>Operation becomes inefficient . </li></ul></ul><ul><ul><li>Caused when a page is removed from memory but is called back shortly thereafter. </li></ul></ul><ul><ul><li>Can occur across jobs, when a large number of jobs are vying for a relatively few number of free pages. </li></ul></ul><ul><ul><li>Can happen within a job (e.g., in loops that cross page boundaries). </li></ul></ul><ul><li>Page fault – a failure to find a page in memory. </li></ul>
  21. 21. Page Replacement Policies <ul><li>Policy that selects page to be removed is crucial to system efficiency. </li></ul><ul><ul><li>Selection of algorithm is critical. </li></ul></ul><ul><li>First-in first-out (FIFO) policy* – best page to remove is one that has been in memory the longest. </li></ul><ul><li>Least-recently-used (LRU) policy* – chooses pages least recently accessed to be swapped out. </li></ul><ul><li>Most recently used (MRU) policy. </li></ul><ul><li>Least frequently used (LFU) policy. </li></ul>* Most well known policies
  22. 22. FIFO policy. When program calls for Page C, Page A is moved out of 1st page frame to make room for it (solid lines). When Page A is needed again, it replaces Page B in 2nd page frame (dotted lines) .
  23. 23. How each page requested is swapped into 2 available page frames using FIFO. When program is ready to be processed all 4 pages are on secondary storage. Throughout program, 11 page requests are issued. When program calls a page that isn’t already in memory, a page interrupt is issued (shown by *). 9 page interrupts result.
  24. 24. FIFO <ul><li>High failure rate shown in previous example caused by: </li></ul><ul><ul><li>limited amount of memory available. </li></ul></ul><ul><ul><li>order in which pages are requested by program (can’t change). </li></ul></ul><ul><li>There is no guarantee that buying more memory will always result in better performance ( FIFO anomaly or Belady's anomaly ). </li></ul>
  25. 25. LRU Policy For program in Figure 3.8. Throughout the program 11 page requests are issued, but they cause only 8 page interrupts.
  26. 26. LRU <ul><li>The efficiency of LRU is only slightly better than with FIFO. </li></ul><ul><li>LRU is a stack algorithm removal policy – increasing main memory causes either a decrease in or same number of page interrupts. </li></ul><ul><ul><li>LRU doesn’t have same anomaly that FIFO does. </li></ul></ul>
  27. 27. Mechanics of Paging : Page Map Table <ul><li>Status bit indicates if page is currently in memory or not. </li></ul><ul><li>Referenced bit indicates if page has been referenced recently. </li></ul><ul><ul><li>Used by LRU to determine which pages should be swapped out. </li></ul></ul><ul><li>Modified bit indicates if page contents have been altered </li></ul><ul><ul><li>Used to determine if page must be rewritten to secondary storage when it’s swapped out. </li></ul></ul>
  28. 28. Four Possible Combinations of Modified and Referenced Bits   Modified Referenced Meaning Case 1 0 0 Not modified AND not referenced Case 2 0 1 Not modified BUT was referenced Case 3 1 0 Was modified BUT not referenced (impossible?) Case 4 1 1 Was modified AND referenced
  29. 29. Page Replacement : The Working Set <ul><li>Working set – set of pages residing in memory that can be accessed directly without incurring a page fault . </li></ul><ul><ul><li>Improves performance of demand page schemes. </li></ul></ul><ul><li>Locality of reference occurs with well-structured programs. </li></ul><ul><ul><li>During any phase of its execution program references only a small fraction of its pages . </li></ul></ul><ul><li>System must decide: </li></ul><ul><ul><li>How many pages comprise the working set? </li></ul></ul><ul><ul><li>What’s the maximum number of pages the operating system will allow for a working set? </li></ul></ul>
  30. 30. Pros & Cons of Demand Paging <ul><li>First scheme in which a job was no longer constrained by the size of physical memory (virtual memory). </li></ul><ul><li>Uses memory more efficiently than previous schemes because sections of a job used seldom or not at all aren’t loaded into memory unless specifically requested. </li></ul><ul><li>Increased overhead caused by tables and page interrupts . </li></ul>
  31. 31. Segmented Memory Allocation <ul><li>Based on common practice by programmers of structuring their programs in modules ( logical groupings of code ). </li></ul><ul><ul><li>A segment is a logical unit such as: main program, subroutine, procedure, function, local variables, global variables, common block, stack, symbol table, or array. </li></ul></ul><ul><li>Main memory is not divided into page frames because size of each segment is different. </li></ul><ul><ul><li>Memory is allocated dynamically. </li></ul></ul>
  32. 32. Segment Map Table (SMT) <ul><li>When a program is compiled, segments are set up according to program’s structural modules. </li></ul><ul><li>Each segment is numbered and a Segment Map Table (SMT) is generated for each job. </li></ul><ul><ul><li>Contains segment numbers, their lengths, access rights, status, and (when each is loaded into memory) its location in memory . </li></ul></ul>
  33. 33. Tables Used in Segmentation <ul><li>Memory Manager needs to track segments in memory: </li></ul><ul><li>Job Table (JT) lists every job in process (one for whole system). </li></ul><ul><li>Segment Map Table lists details about each segment (one for each job). </li></ul><ul><li>Memory Map Table monitors allocation of main memory (one for whole system). </li></ul>
  34. 34. Pros & Cons of Segmentation <ul><li>Compaction. </li></ul><ul><li>External fragmentation. </li></ul><ul><li>Secondary storage handling. </li></ul><ul><li>Memory is allocated dynamically. </li></ul>
  35. 35. Segmented/Demand Paged Memory Allocation <ul><li>Evolved from combination of segmentation and demand paging. </li></ul><ul><ul><li>Logical benefits of segmentation. </li></ul></ul><ul><ul><li>Physical benefits of paging. </li></ul></ul><ul><li>Subdivides each segment into pages of equal size, smaller than most segments, and more easily manipulated than whole segments. </li></ul><ul><li>Eliminates many problems of segmentation because it uses fixed length pages. </li></ul>
  36. 36. 4 Tables Are Used in Segmented/Demand Paging <ul><li>Job Table lists every job in process (one for whole system). </li></ul><ul><li>Segment Map Table lists details about each segment (one for each job). </li></ul><ul><ul><li>E.g., protection data, access data. </li></ul></ul><ul><li>Page Map Table lists details about every page (one for each segment). </li></ul><ul><ul><li>E.g., status, modified, and referenced bits . </li></ul></ul><ul><li>Memory Map Table monitors allocation of page frames in main memory (one for whole system). </li></ul>
  37. 37. Pros & Cons of Segment/Demand Paging <ul><li>Overhead required for the extra tables </li></ul><ul><li>Time required to reference segment table and page table. </li></ul><ul><li>Logical benefits of segmentation. </li></ul><ul><li>Physical benefits of paging </li></ul><ul><li>To minimize number of references, many systems use associative memory to speed up the process. </li></ul>
  38. 38. Virtual Memory (VM) <ul><li>Even though only a portion of each program is stored in memory, virtual memory gives appearance that programs are being completely loaded in main memory during their entire processing time . </li></ul><ul><li>Shared programs and subroutines are loaded “on demand,” reducing storage requirements of main memory. </li></ul><ul><li>VM is implemented through demand paging and segmentation schemes . </li></ul>
  39. 39. Comparison of VM With Paging and With Segmentation
  40. 40. Advantages of VM <ul><li>Works well in a multiprogramming environment because most programs spend a lot of time waiting. </li></ul><ul><li>Job’s size is no longer restricted to the size of main memory (or the free space within main memory). </li></ul><ul><li>Memory is used more efficiently. </li></ul><ul><li>Allows an unlimited amount of multiprogramming. </li></ul><ul><li>Eliminates external fragmentation when used with paging and eliminates internal fragmentation when used with segmentation. </li></ul><ul><li>Allows a program to be loaded multiple times occupying a different memory location each time. </li></ul><ul><li>Allows the sharing of code and data. </li></ul><ul><li>Facilitates dynamic linking of program segments. </li></ul>
  41. 41. Disadvantages of VM <ul><li>Increased processor hardware costs . </li></ul><ul><li>Increased overhead for handling paging interrupts . </li></ul><ul><li>Increased software complexity to prevent thrashing . </li></ul>
  42. 42. Key Terms <ul><li>address resolution </li></ul><ul><li>associative memory </li></ul><ul><li>demand paging </li></ul><ul><li>displacement </li></ul><ul><li>FIFO anomaly </li></ul><ul><li>first-in first-out (FIFO) policy </li></ul><ul><li>Job Table (JT) </li></ul><ul><li>least-recently-used (LRU) policy </li></ul><ul><li>locality of reference </li></ul><ul><li>Memory Map Table (MMT) </li></ul><ul><li>page </li></ul><ul><li>page fault </li></ul><ul><li>page fault handler </li></ul><ul><li>page frame </li></ul><ul><li>Page Map Table (PMT) </li></ul><ul><li>page replacement policy </li></ul><ul><li>page swap </li></ul><ul><li>paged memory allocation </li></ul><ul><li>reentrant code </li></ul><ul><li>segment </li></ul><ul><li>Segment Map Table (SMT) </li></ul>
  43. 43. Key Terms - 2 <ul><li>segmented memory allocation </li></ul><ul><li>segmented/demand paged memory allocation </li></ul><ul><li>thrashing </li></ul><ul><li>virtual memory </li></ul><ul><li>working set </li></ul>

×