VM Implementation - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

VM Implementation

Description:

... memory frames are equivalent (unless page coloring a physical cache. ... The clock scan will fail to find a free page when overcommited. Load phase control ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 26
Provided by: kevinelp
Category:

less

Transcript and Presenter's Notes

Title: VM Implementation


1
VM Implementation
2
Aim Show how standard VM techniques relate to
our OS
  • Fetch Policy
  • Placement Policy
  • Replacement Policy
  • Clock, working set, WSclock
  • Cleaning Policy
  • Resident set size policy
  • Load control

3
Virtual Memory
Fetch Policy
Determines when a page should be swapped in.
2 main policies are used Demand paging swaps in
pages only when a reference is made to that page
? many page faults will arise when a task star
ts, but that number should decrease as more pages
are swapped in Pre-Paging swaps in more pages tha
n the demanded one ? locality of references may s
uggest that it is efficient to swap in some pages
residing contiguously on the disk
However, efficiency not definitely established
at least some pre-paged pages may never be
referenced at all pre-paging is speculative with
all its risks
4
Virtual Memory
Placement Policy
Determines where in real memory a swapped-in page
should reside For pure segmentation systems f
irst-fit, next fit... are possible choices
(a real issue, this can be a quite complicated
task) For paging the chosen frame location i
s irrelevant since all memory frames are
equivalent (unless page coloring a physical
cache.)
5
Virtual Memory
Replacement Policy
Deals with the selection of an appropriate page
in main memory to be replaced when a new page has
to be moved in. This occurs whenever main memory
is full (no free frames available)
Occurs often in some commercial systems since
their OS tries to activate as many tasks as
possible hoping that an increased
multiprogramming level increases also system
performance (e.g. early versions of BS 2000 al
ways over estimated system capacity resulting in
a very poor system performance)
6
Virtual Memory
Replacement Policy
Not all page frames in main memory can be
selected for replacement Some frames are locked (
cannot be paged out) much of the kernel is held
on locked frames as well as key control
structures and I/O buffers (some DMA may access
physical addresses, only) a real time task may ha
ve to pin pages otherwise it cannot guarantee
deadlines The OS might decide that the set of pa
ges considered for the next replacement should
be limited to those frames of that task having i
nitiated the page fault unlimited, i.e. the set o
f all frames in unlocked frames
7
Virtual Memory
Replacement Policy
The decision for the set of pages to be
considered for replacement is related to the
resident set management strategy
How many page frames are to be allocated to each
task? No matter what is the set of page frames c
onsidered for replacement, the replacement policy
deals with algorithms that will choose the
most promising page frame within that set
However, what is the most promising page frame w
ithin a set of page frames?
8
Virtual Memory
OPT Replacement Algorithm
  • The optimal policy (often named Belady-Algorithm)
    selects that page frame out of a set of
    replaceable page frames for which the time to the
    next reference is the longest (e.g. never
    referenced again)
  • produces the fewest number of page faults
  • impossible to implement (need to know the
    future) but serves
  • as a standard to compare with implemental
    algorithms

First-in, first-out (FIFO) Least recently used (L
RU) Clock (second chance) Least frequently used
(LFU)

9
Virtual Memory
Replacement Algorithms
We have to observe the past to predict the
future Observe the reference string and try to
predict Very recently referenced pages will
also be referenced in the near future
time
ri
current reference
Problem 1. What can we observe easily?
2. Which information can we maintain
efficiently?
10
Virtual Memory
The Clock Policy
The set of page frame candidates for replacement
is considered as a circular buffer (so you can
use it globally or locally) Whenever a page fram
e is replaced, a pointer is set to point to the
next page frame in the buffer A referenced (use)
bit for each frame is set to 1 whenever the
corresponding page is referenced (i.e. also upon
loading in demand pg) When it is time to replace
a page, the first frame encountered with the
referenced (used) bit set to 0 is replaced.
During search for replacement, in all controlled
page frames a R-bit with value 1 is changed to
0, indicating that this page gets a second chance
to be referenced again before the next
replacement step
11
Virtual Memory
The Clock Policy
1. A page fault occurs, because page 727 is
currently not in main memory.
2. Look for a candidate to be replaced
3. In the previous replacement step page 45
on page frame 2 has been replaced
12
Virtual Memory
The Clock Policy
13
Pros and Cons
  • Pros
  • Good approximation of LRU
  • Cons
  • Always succeeds
  • Need addition feedback mechanism (e.g monitoring
    page fault rate) to
  • Control load
  • Avoid thrashing

14
Problem Reference and Dirty Bits
  • We dont have access to reference and dirty bits
    inside microkernel
  • However, we can simulate them
  • Assuming they are initially unset, modify the
    pager to
  • Set the reference bit on first read fault to
    page
  • Set dirty (and maybe reference bit) on first
    write access to page
  • If the OS resets the bits it must
  • l4_unmap the page so it is read-only to clear
    dirty bit
  • l4_unmap the page completely to clear the
    reference bit
  • Similar to approaches used on architectures
    without referenced bits (VAX, MIPS)
  • Ozalp Babaoglu, William Joy. Converting a
    Swap-based system to paging in an architecture
    lacking page-referenced bits SOSP 1981

15
Virtual Memory
The Working Set Policy
Is a variable-allocation method with local scope
based on the assumption of locality of
references Notion The working set for a task at
time t W(D, t), is the set of pages that have
been referenced in the last D virtual time units
virtual time time elapsed while the task was in
execution (e.g number of instructions executed)
D is a window of time For any fixed t, W(D,
t) is a non decreasing function of D
W(D, t) is an approximation of the programs
locality
16
Virtual Memory
The Working Set Policy
The working set of a task first grows when it
starts executing and then tends to stabilize due
to the principle of locality It may grow again
when the task enters a new locality
(transition period, e.g. calls a procedure)
up to a point where the working set contains
pages from two localities. It then decreases agai
n spending some time in the new locality.
17
Virtual Memory
The Working Set Policy
The working set concept suggest the following
policy to determine the size of the resident
set Monitor the working set for each task Perio
dically remove from the resident set of a task
those pages that are no longer in its working
set When the resident set of a task is smaller th
an its working set, allocate more frames to it
If not enough free frames are available, suspend
the task (until more frames are available)
i.e. a task may execute only if its working set
fits into the main memory
18
Pros
  • Has load control
  • If sum of all active pages is greater than
    physical memory, we are overloaded
  • If sum of all active pages is less than physical
    memory, we can admit a ready task

19
Virtual Memory
The Working Set Policy
  • Practical problems with the working set policy
  • measurement of the working set for each task is
    impractical
  • necessary to time stamp the referenced page
  • at every memory reference
  • necessary to maintain a time-ordered queue
  • of referenced pages for each task
  • the optimal value for D is unknown and time
    varying due to
  • transient and stable execution phases

20
WSclock Working Set Clock
  • Richard Carr and John Hennessy. WSClock A
    simple and effective algorithm for virtual memory
    management, SOSP 1981
  • Combines advantages of clock and working set
    model
  • Prevents thrashing, provides for task isolation
  • Eliminates
  • WS scan, per-page time stamps

21
(No Transcript)
22
Load control
  • Can determine an approx to active working set
    (resident active working set)
  • Use this to determine undercommitment
  • The clock scan will fail to find a free page when
    overcommited

23
Load phase control
  • Problem
  • Starting task goes through start phase and
    running phase
  • Frequent starting task
  • Cause many fault
  • Compete with each other for bandwidth to disk
  • Indirectly result in running tasks getting more
    CPU
  • Running tasks complete fast
  • More tasks are started

24
Load phase control
  • Limit number of starting tasks to k for the
    startup phase
  • Startup phase is some predefined time constant t
  • K is related to number of disk for paging

25
See paper for results
  • Wsclock with load control performs as well as
    working set policy, but is an easy to implement
    as clock.
Write a Comment
User Comments (0)
About PowerShow.com