Docsity

Understanding Memory Management: Page Replacement, Thrashing, and Working Sets, Slides of Advanced Operating Systems

Partial preview of the text

Download Understanding Memory Management: Page Replacement, Thrashing, and Working Sets and more Slides Advanced Operating Systems in PDF only on Docsity!

Lecture No.

Overview of today’s lecture

 Page replacement

 Thrashing

 Working set model

 Page fault frequency

 Copy on write

 Sharing

 Memory mapped files

 Per-process  each process has a separate pool of pages

 a page fault in one process can only replace one of this process’s frames  isolates process and therefore relieves interference from other processes

 but, isolates process and therefore prevents process from using other’s (comparatively) idle resources  efficient memory usage requires a mechanism for (slowly) changing the allocations to each pool  Qs: What is “slowly”? How big a pool? When to migrate?

Per-process page replacement

P1 P

pool barrier

Thrashing

 Thrashing is when the system spends most

of its time servicing page faults, little time

doing useful work

 could be that there is enough memory but a bad replacement algorithm (one incompatible with program behavior)

 could be that memory is over-committed

 too many active processes

Making the best of a bad situation

 Single process thrashing?  If process does not fit or does not reuse memory, OS can do nothing except contain damage.  System thrashing?  If thrashing arises because of the sum of several processes then adapt:  figure out how much memory each process needs  change scheduling priorities to run processes in groups whose memory needs can be satisfied (shedding load)  if new processes try to start, can refuse (admission control)  Careful: example of technical vs social.  OS not only way to solve this problem (and others).  solution: go and buy more memory.

The working set model of program behavior

 The working set of a process is used to model the dynamic locality of its memory usage  working set = set of pages process currently “needs”  formally defined by Peter Denning in the 1960’s  Definition:  a page is in the working set (WS) only if it was referenced in the last w references  obviously the working set (the particular pages) varies over the life of the program  so does the working set size (the number of pages in the WS)

Hypothetical Working Set algorithm

 Estimate for a process
 Allow that process to start only if you can allocate it that many
page frames
 Use a local replacement algorithm (e.g. LRU Clock) make sure
that “the right pages” (the working set) are occupying the
process’s frames
 Track each process’s working set size, and re-allocate page
frames among processes dynamically
 How do we choose w?

How to implement working set?

 Associate an idle time with each page frame

 idle time = amount of CPU time received by process since last access to page  page’s idle time > T? page not part of working set

 How to calculate?

 Scan all resident pages of a process  reference bit on? clear page’s idle time, clear use bit  reference bit off? add process CPU time (since last scan) to idle time  Unix:  scan happens every few seconds  T on order of a minute or more

Some problems

 T is magic
 what if T too small? Too large?
 How did we pick it? Usually “try and see”
 Fortunately, system’s aren’t too sensitive
 What processes should be in the balance set?
 Large ones so that they exit faster?
 Small ones since more can run at once?
 How do we compute working set for shared pages?

Working sets of real programs

 Typical programs have phases:

Working set size

transition, stable

Page Fault Frequency (PFF)

 PFF is a variable-space algorithm that uses a more ad hoc
approach
 Attempt to equalize the fault rate among all processes, and to
have a “tolerable” system-wide fault rate
 monitor the fault rate for each process
 if fault rate is above a given threshold, give it more memory
 so that it faults less
 if the fault rate is below threshold, take away memory
 should fault more, allowing someone else to fault less

Fault resumption. lets us lie about many

things

 Emulate reference bits:

 Set page permissions to “invalid”.  On any access will get a fault: Mark as referenced

 Emulate non-existent instructions:

 Give inst an illegal opcode. When executed will cause “illegal instruction” fault. Handler checks opcode: if for fake inst, do, otherwise kill.  Run OS on top of another OS!

 Make OS into normal process  When it does something “privileged” the real OS will get woken up with a fault.  If op allowed, do it, otherwise kill.  User-mode Linux, vmware.com

linux linux win

linux

privileged