Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Memory Management Page Replacement. Thrashing If a process does not have “ enough ” pages, the page-fault rate is very high. This leads to:

Similar presentations


Presentation on theme: "Chapter 4 Memory Management Page Replacement. Thrashing If a process does not have “ enough ” pages, the page-fault rate is very high. This leads to:"— Presentation transcript:

1 Chapter 4 Memory Management Page Replacement

2 Thrashing If a process does not have “ enough ” pages, the page-fault rate is very high. This leads to: –low CPU utilization –OS scheduler thinks that it needs to increase the degree of multiprogramming  new processes are added  even less pages for each process … Thrashing  a process is busy swapping pages in and out –  Spending more time paging than executing.

3 Demand Paging Demand paging: pages are only loaded into memory when they are demanded during execution –Less I/O needed –Less memory needed –Higher degree of multiprogramming –Faster response Pager (lazy swapper) never swaps a page into memory unless that page will be needed. An extreme case: Pure demand paging starts a process with no pages in memory … Transfer of a Paged Memory to Contiguous Disk Space

4 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 over written Better not to choose an often used page will probably need to be brought back in soon

5 Random page replacement Optimal page replacement algorithm Not recently used page replacement First-In, First-Out page replacement Second chance page replacement Clock page replacement Least recently used page replacement Working set page replacement WSClock page replacement Page Replacement Algorithms

6 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

7 Optimal Example 12 references, 7 faults

8 Not Recently Used Page Replacement Algorithm ( NRU ) Each page has Reference bit, Modified bit –bits are set when page is referenced, modified Pages are classified 1. not referenced, not modified 2. not referenced, modified 3. referenced, not modified 4. referenced, modified NRU removes page at random –from lowest numbered non empty class

9 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

10 FIFO 12 references, 9 faults

11 Belady's Anomaly (for FIFO) Same reference string as with 3 frames (9 page faults). 12 references, 10 faults Belady’s Anomaly for FIFO: (Sometimes) as the number of page frames increase, so does the fault rate.

12 Operation of second chance. (a) Pages sorted in FIFO order. (b) Page list if a page fault occurs at time 20 and A has its R bit set. The numbers above the pages are their load times. Second Chance Algorithm

13 Second Chance Example 12 references, 9 faults

14 The clock page replacement algorithm. The Clock Page Replacement Algorithm

15 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

16 LRU using a matrix when pages are referenced in the order 0, 1, 2, 3, 2, 1, 0, 3, 2, 3. LRU Page Replacement Algorithm

17 The aging algorithm simulates LRU in software. Shown are six pages for five clock ticks. The five clock ticks are represented by (a) to (e). Simulating LRU in Software NFU Aging

18 LRU and Anomalies Anomalies cannot occur. 12 references, 8 faults

19 The working set is the set of pages used by the k most recent memory references. The function w(k, t) is the size of the working set at time t. Working Set Page Replacement (1)

20 The working set algorithm. Working Set Page Replacement (2)

21 When the hand comes all the way around to its starting point there are two cases to consider: At least one write has been scheduled. No writes have been scheduled. The WSClock Page Replacement Algorithm (1)

22 Operation of the WSClock algorithm. (a) and (b) give an example of what happens when R = 1. The WSClock Page Replacement Algorithm (2)

23 Operation of the WSClock algorithm. (c) and (d) give an example of R = 0. The WSClock Page Replacement Algorithm (3)

24 Page replacement algorithms discussed in the text. Summary of Page Replacement Algorithms

25 Figure Local versus global page replacement. (a) Original configuration. (b) Local page replacement. (c) Global page replacement. Local versus Global Allocation Policies (1)

26 Page fault rate as a function of the number of page frames assigned. Local versus Global Allocation Policies (2)

27 Modeling Page Replacement Algorithms Belady's Anomaly FIFO with 3 page frames FIFO with 4 page frames P's show which page references show page faults

28 Stack Algorithms State of memory array, M, after each item in reference string is processed

29 Design Issues for Paging Systems Local versus Global Allocation Policies (1) Original configuration Local page replacement Global page replacement

30 Local versus Global Allocation Policies (2) Page fault rate as a function of the number of page frames assigned

31 Load Control Despite good designs, system may still thrash When 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 Page Size (1) 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

33 Page Size (2) Overhead due to page table and internal fragmentation Where s = average process size in bytes p = page size in bytes e = page entry page table space internal fragmentation Optimized when

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 Implementation Issues Operating 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

37 Page Fault Handling (1) Hardware traps to kernel General registers saved OS determines which virtual page needed OS checks validity of address, seeks page frame If selected frame is dirty, write it to disk

38 Page Fault Handling (2) OS brings schedules new page in from disk Page tables updated Faulting instruction backed up to when it began Faulting process scheduled Registers restored Program continues

39 Instruction Backup An instruction causing a page fault

40 Locking Pages in Memory Virtual memory and I/O occasionally interact Proc 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 proc may be chosen to be paged out Need to specify some pages locked exempted from being target pages

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

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

43 作业 P 139 页 12 , 22 , 24 , 26 , 27 , 28


Download ppt "Chapter 4 Memory Management Page Replacement. Thrashing If a process does not have “ enough ” pages, the page-fault rate is very high. This leads to:"

Similar presentations


Ads by Google