Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS623: Lecture 3 February 10, 2004 © Joel Wein 2003, modified by T. Suel.

Similar presentations


Presentation on theme: "CS623: Lecture 3 February 10, 2004 © Joel Wein 2003, modified by T. Suel."— Presentation transcript:

1 CS623: Lecture 3 February 10, 2004 © Joel Wein 2003, modified by T. Suel

2 Source Material Section 8.2, Stallings. The Working Set Model for Program Behavior. P. Denning. Communications of the ACM, May 1968 The Working Set Model for Program Behavior. WSCLock – A Simple and Effective Algorithm for VMM. R. Carr & J. Hennessy, WSCLock – A Simple and Effective Algorithm for VMM.

3 Denning (1967/68) Assumption: – Dynamic advice regarding resource requirements cannot be obtained successfully from users or from compilers. Goal Advocated: – Minimize page traffic. Minimizes computational overhead for deciding what to move, etc. Traverse time long compared to a memory cycle Schedule another process to run during page I/O

4 Replacement Policy Deals with selection of page in memory to be replaced when a new page needs to be brought in. Three issues that get lumped together. – How many page frames/process. – Whether page frames considered for replacement should be limited to those of the process that caused the page fault or encompass all the page frames in main memory. – Among the set of pages considered, which particular page should be selected for replacement? Call the first two Resident Set Management; third is Replacement Policy.

5 Replacement Policy Frame Locking: Some frames might be locked Basic Algorithms: – Optimal – Random – Least Recently Used (LRU) – FIFO – ATLAS Loop Detection (?)

6 Optimal Algorithm Select for Replacement page for which the time to next replacement is longest Result in fewest page faults. Not implementable Running Example: 3 pages, sequence This is provably the best!

7 LRU Replace page not used for longest time. Principle of locality: this page least likely to be used in the future Does pretty well Hard to implement

8 FIFO Simple to implement Get rid of page in memory the longest Strategy will often be wrong because of locality A good policy should keep some information on when/how often accessed

9 Clock Policy Try to emulate LRU Associate “use bit” with each frame. – When page first loaded into a frame in memory, use bit for that frame set to 1. – When subsequently referenced, set to 1. – Set of pages that are candidates for replacement are a circular buffer with pointer. – When page replaced,pointer placed on the next frame. – When time to replace a frame scan for a use-bit 0 frame. When you encounter a use-bit 1, set to 0. – Like FIFO except skips use-bit 1.

10 Resident Set Management Resident Set Size: How much main memory to give to a particular process? Replacement Scope: What set of potential replacements do you choose from?

11 Resident Set Size Factors: – The smaller the assigned memory, the more processes in main memory. Increases probability that OS will find at least one ready process and avoids swapping. – If a relatively small number of pages of a process are in main memory, then rate of page faults will be high – Beyond a certain size adding more memory not that useful – Miss has two costs: program delay & page traffic – Goldilocks’ Problem: choose just right

12 Resident Set Management Approaches: Resident set size: – Fixed allocation determined at initial load time. – Variable allocation: varies over lifetime of process. Give more frames to processes that are faulting frequently. Replacement scope: – Local replacement policy: choose among resident pages of process that generated the fault. – Global replacement policy: consider all unlocked pages in main memory as candidates to replace.

13 Possible Combinations Fixed Allocation, Local Scope – Drawback: If allocations too large or too small no good way to recover Too small: lots of page faults Too large: processor idle time or lots of swapping Variable Allocation, Global Scope – Easiest to implement, widely adopted – Processes that fault a lot should get helped out? – Hard to get good replacement policy – not easy to figure out which process is best to choose from

14 Combinations Variable Allocation, Local Scope – Try to overcome problems with a global-scope strategy (use local) – But from time to time reevaluate memory allocation to process – The question: How do you determine resident set size for each process and how do you time the changes?

15 Review: Operating System Software Fetch Policy – Demand – Prepaging Replacement Policy – Random, OPT, FIFO, LRU, etc. Resident Set Management – Static/dynamic and local/global scope

16 Working Sets Roughly speaking, – Working Set of pages: minimum set of pages that must be loaded in main memory for a process to operate efficiently without unnecessary page faults “Smallest collection of information that must be present in main memory to assure efficient execution of the program” Process/Working Set: two different manifestations of the same ongoing computational activity

17 Working Set Strategy W(t,D) = set of pages in memory at time t of that process that have been referenced in the last D virtual time units – Virtual time = time that elapses while process in execution measured in instruction steps – Real time = wall clock time Working set size: number of pages in W(t,D)

18 Characteristics of Working Sets Working set size is nondecreasing function of window size D – Obviously: w(t, D+1) >= w(t, D) – But also sublinear in D: w(t, 2D) <= 2 w(t,D) Prediction: Expect intuitively that immediate past page reference behavior constitutes good prediction of immediate future behavior Quantitatively, hopefully: w(t, 2D) << 2 w(t,D) for many ranges of D

19 Detecting/Measuring W(t,D) Hardware mechanism to record if page referenced in last D seconds Software: s ample the page table entries at intervals of D/K Any page that was referenced in these intervals is in working set Of course: how do you select D ? Assume: program will not be run unless there is space in memory for its working set

20 Using the Working Set Concept A strategy for resident set size: – Monitor the working set of each process – Periodically remove from the resident set of a process any pages that are not in its working set – A process may execute only if its working set is in main memory (i.e., if working set in resident set) Exploits principle of locality to achieve a memory management strategy that should minimize page faults Actually, minimizes might be too strong

21 Issues With this Strategy Past does not necessarily predict future. Size and membership of working set change over time (maybe in itself not a problem?) A true measurement of WS for each process is impractical. Need to time stamp every page reference and keep a time-ordered queue (but a solution proposed by Denning) Optimal value of D is unknown and would vary (as we all know from experience)

22 However, let the spirit guide us… Look only at page fault rate, not all page references: – Page fault rate falls as resident set size increases – If page fault rate is below some threshold, give a smaller resident set size – If above some threshold, increase resident set size by some small factor – And maybe keep as it is in the middle – Too hot (tons of misses), too cold, just right …

23 Algorithm: PFF (Page Fault Frequency) Uses a use bit: – Bit set to 1 when page accessed – When page fault occurs, OS notes virtual time since last fault for that process. If < F, add page to resident set of process. If >= F, discard all pages with a use bit of 0 and shrink resident set accordingly. Could use an upper and lower threshhold. – Time between page faults is 1/(page fault rate). Running average would be better but this is a reasonable simple compromise

24 PFF Shortcoming Does not perform well during transient periods, shift to new locality. – No page ever drops out of the resident set before F virtual time units have elapsed since it was last referenced. – In a locality transition the resident set can balloon and cause a lot of overhead


Download ppt "CS623: Lecture 3 February 10, 2004 © Joel Wein 2003, modified by T. Suel."

Similar presentations


Ads by Google