1 / 31

CMT603

CMT603. Lecture 9 Memory Management 2. Recap. Addressing an Address binding Logical and Physical Addressing Memory Management Unit Contiguous Addressing Fixed Partition Variable Partition Non-Contiguous Addressing Paging Segmentation. Contents. Segmentation Why ? How ?

Télécharger la présentation

CMT603

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. CMT603 Lecture 9 Memory Management 2

  2. Recap • Addressing an Address binding • Logical and Physical Addressing • Memory Management Unit • Contiguous Addressing • Fixed Partition • Variable Partition • Non-Contiguous Addressing • Paging • Segmentation

  3. Contents • Segmentation • Why ? • How ? • Virtual Memory • Why? • Implementation • Page Faults

  4. Segmentation • Paging separates user’s view of memory from the actual physical memory • The user views memory as a collection of variable-sized segments, with no necessary ordering among segments • Segmentation supports this user view of memory.

  5. Users view of Memory Main Program Segment 0 Sub 1 Sub 2 Segment 1 Segment 2 Sub 3 Segment 3

  6. Segmentation Hardware Physical memory Segmentation Table s Limit Base CPU s d < + Addressing Error

  7. An Example Physical memory Segmentation Table s 256 3000 CPU 4 212 3000 3212 < + 3256 Addressing Error

  8. A View of the Memory Physical memory 0 OS 1600 2000 Sub 1 Main Program 2400 Segmentation Table Segment 0 3000 Main Program Sub 1 Sub 2 Segment 1 3800 Segment 2 4100 Sub 3 Sub 3 4500 Segment 3 4800 Sub 2 5000

  9. Fragmentation • Segmentation may cause external fragmentation. • When all blocks of free memory are too small to accommodate a segment, the process may simply have to wait until more memory become available. • Solution: • Memory compaction • Page the segments – Segmentation with paging

  10. Segmentation With Paging • Segments are arranged across multiple pages. • A logical memory address is presented as an ordered triple (s, p, d), where s is the segment number, p is the page number, and d is the displacement within the page

  11. Page size = Frame size = 32 bytes Segmentation With Paging Physical memory CPU s p d Segmentation Table s Limit Page Table Base b Page Table < + f d f b+p

  12. Page size = Frame size = 32 bytes Example Physical memory CPU 4 6 28 Physical Address 20*32+28=668 Segmentation Table 4 Page Table 12 24 24 190 25 100 26 34 < + 20 28 27 20 b+p 28 100 29 34 30 20

  13. Fragmentation • It may cause internal fragmentation

  14. Virtual Memory • Previous memory allocation strategies have the same goal: • To keep many processes in memory simultaneously to support multiprogramming. • Requires the entire process to be in memory before its execution.

  15. Virtual Memory • Benefits of the ability to execute a program that is only partially in memory: • A program is no longer constrained by the amount of physical memory that is available. • More programs can be run at the same time.

  16. Virtual Memory • Virtual memory is a technique that allows the execution of processes that may not be completely in memory. • It allows a large virtual memory to be provided for programmers when only a smaller physical memory is available

  17. Implementation:Demand paging scheme • A process is viewed as a set of sequential pages. It resides on secondary memory (disk). • A page is never brought into memory unless it will be needed. • Add valid-invalid bit into page table. • 􀁺 “valid” indicates that the associated page is both legal and in memory. • 􀁺 “invalid” indicates that the associated page is not in memory.

  18. Diagram of Virtual Memory Page Table A B F C G D E Page-fault Trap Logical Memory Hard Disk Physical Memory

  19. Handling Page Faults • Access to a page marked invalid causes a page-fault trap to the OS • 1. Find a free frame. • 2. Read the desired page into the frame. • 3. Reset the page table to indicate that the page is in memory. • 4. Restart the instruction that was interrupted by the page-fault trap. • The process now can access the page as though it had always been in memory

  20. Handling Page Faults C i v 0 A B F C G D E Logical Memory

  21. Need for Page Replacement • Suppose a page fault occurs, and a • desired page that is residing on the • disk is required by a process, but • there is no free frame

  22. Page Replacement Page Table C P A P B F C G D E Logical Memory Hard Disk Physical Memory

  23. Page Replacement • Reduce the overhead by using a “dirty” bit: • A dirty bit is associated with each page • The dirty bit is set whenever there is any modification in the page • When a page is selected for replacement, the page is written to the disk only if its dirty bit is set.

  24. Page-Replacement Algorithms:Evaluation method • The lower the page-fault rate the better. • Evaluation: Run on a string of memory references and count the number of page faults. For example 7, 8, 0, 6, 5, 4, 6, 9, 2, 3, 3 • Each number is a reference to a page. Question What algorithms could we use

  25. First-In First-Out (FIFO) Algorithm • Create a FIFO queue to hold all pages in memory. Always replace the page at the head of the queue, and insert a new page at the tail of the queue. • Assume there are 3 frames in memory. If run on the reference string 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 using FIFO algorithm, how many page faults?

  26. First-In First-Out (FIFO) Algorithm number of page faults = 15 • Bad replacement choices increase the page-fault rate: • The page replaced may be an active page in constant use. • After paging out this page to bring a new one, a page fault may occur immediately.

  27. Optimal Algorithm • Replace the page that will not be used for the longest period of time. • This has the lowest page-fault rate. • Assume there are 3 frames in memory. If run on a reference string 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 using optimal algorithm, how many page faults?

  28. Optimal Algorithm number of page faults = 9 • Optimal algorithm is difficult to implement, because it requires future knowledge of the reference string.

  29. Least Recently Used (LRU) Algorithm • Replace the page that has not been used for the longest period of time. • An approximation to the optimal algorithm. • Assume there are 3 frames in memory. If run on a reference string 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 using LRU algorithm, how many page faults?

  30. Least Recently Used (LRU) Algorithm number of page faults =12 • Better performance at the cost of system overhead

  31. Summary • Segmentation • Why ? • How ? • Virtual Memory • Why? • Implementation • Page Faults

More Related