Title: Outline of Lecture 12
1Outline of Lecture 12
Processing Cost of Page Faults Extension
Problem Working Set Policy and Its Approximations
An Example of Working Set (WS) Policy Assignment
2 (due Lectures 13-14)
2Stack and Priority List Updating OPT Replacement
w123 Stlt3,1,2gt s13 s21 s32 d12
d23 d31
w 1 2 3 4 1 2 3 2
3 1 St 1 2 3 4 1 2 3
2 3 1 - 1 1 1 4
1 2 3 2 2 - - 2 2
2 4 1 1 1 3 - -
- 3 3 3 4 4 4
4 Lt 1 1 1 1 2 3 2 3
1 1 - 2 2 2 3 2
3 1 2 2 - - 3 3 1
1 1 2 3 3 - - -
4 4 4 4 4 4 4
priority
Stack can be implemented by keeping page table as
a double linked list and bringing page referenced
to the top of the stack requires 6 pointer
changes for each reference! Arrows show the
reason for priority, lines show level of
competition. First stack is computed, then
priorities are computed at each column.
3Processing Cost
- The cost of processing C(m,w)
Where n is the number of distinct pages in w, is
the number of times a new page was referenced,
and ck denotes number of times that a page p
moved from k-th position to the first.
4Calculating Cost Function
w 1 2 3 4 1 2 3 2
3 1
dp 2 3 4
2 2 3 C(m,w) c1 0 0 0 0
0 0 0 0 0 0 10 c2 0
0 0 0 1 1 1 2 3
3 7 c3 0 0 0 0 0 1 1
1 1 2 5 c4 0 0 0 0
0 0 1 1 1 1 4 1 2
3 4 4 4 4 4 4 4
-
w 1 2 3 4 1 2 3 2 3 1, algorithm is OPT
5Extension Problem
- Predict performance with larger memory of mk
frames - with the information recorded at the time of a
page fault with m frames. - Solution possible only for stack algorithms.
- (pi, qi) for i-th fault, where pi is the page
which caused the page fault, and qi is the
removed page. Record priority list at each fault
and recreate the stack for frames below the frame
m and the level of the page brought in. This is
possible because the stack at this level is
unchanged between page faults (according to the
update rules).
6Extension Problem Fault Occurs in Larger Memory
...
...
...
Page pi is brought in from the level below of mk
7Extension Problem No Fault in Larger Memory
Page pi is brought in from the level between m1
and mk
8Extension Problem Solution
1 2 3 4 1 2
3
- (pi, qi) (1,-) (2,-) (3,-) (4,3) (3,4)
- Li-1 - 1 1 1 3
- - - 2 2 2
- - - - 3 1
- - - - 3 4
Si
This is for the string w1,2,3,4,1,2,3,2,3,1
and OPT policy considered previously.
m3 after processing string 1,2,3,4 references
to 1,2 will not cause the page fault but
reference to 3 will replacing page 4 with page 3
9Working Set
- W(t,D) is the set of pages that have been
referenced in the last D time units (time
window), at time t. - D is a fixed number of page references
Process executes only if its working set is
resident in memory. If
then page is not removable.
10Working Set continued
- Pre-paging is often used after deactivation of
the process. - If D too small, W will not encompass needed
pages,but too large D will encompass several
localities, resulting in resident pages not
necessary for execution at this point.
11Page Reference Trace
... 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3
4 4 1 3 2 3 ...
D
D
t1
t2
W(t1, D) 1,2,5,6,7
W(t2, D) 3,4
If sum of working sets of all programs gt memory,
working set rule cannot be obeyed. To avoid that,
OS will suspend one of the active processes.
12Working Set of a Process as Defined by Window
Size
Sequence of Page References
Removable Pages
Window Size
2
3
4
5
2 3 4 5
24
- - - -
24
24
24
24
15
15 24
15 24
15 24
15 24
- - - -
18
18 15 24
18 15 24
18 15
18 15 24
24 - - -
23
23 18 15 24
23 18
23 18 15
23 18 15 24
15 24 - -
24
.
24 23
24 23 18
.
18 15 - -
17
17 24 23
17 24 23 18 15
17 24
17 24 23 18
23 18 15 -
13Keeping Track of the Working Set
Working set may change every memory reference
too costly to keep exact record (need to keep
time of reference for each page, sort them).
Approximation fixed interval timer, reference
bit in registers for each page, and a n-bit
structure in memory for each page Procedure 1.
Timer interrupts after every D/n time units (D
is time window) 2. Whenever a page is referenced,
its register reference bit is set to one 3. When
a timer interrupts, for each page - shift
bits in the n-bit structure to the left -
copy to the rightmost bit of n-bit structure and
clear the value of a register reference bit
- if n-bit structure is not zero, the page is
in the working set Not exact, real time window
varies in the range D, D D /n) (why?).
Compare accuracy and overhead with n2 to n10.
14Typical Graph of True Working Set Size
Working Set Size
execution time
15Example of WS Policy
- Assume w 1 (2)n (32)n (432)n 1
- w 6n 2 n gtgt 1
- D 1, 2, 3, 4, 5
length 1 n 2n 3n 1 1 (2)n (32)n (432)n 1
P(D) 1/F D 1 1 1 2n 3n 1 5n3
1.2 2 1 1 1 3n 1 3n4 2
3 1 1 1 1 1 5 1.2n 4 1 1 1 1 1 5
. . . .
. . . 5
. 6n1 1 1 1 1 4 .
Number of page faults
16Working Set Size in WS Policy
length 1 n-3 2n-4
3n-3 1 1 2 2 2 (2)n-3 3 2 3 2 (32)n-2 4 3 2
(432)n 1 W(D) D 1 1 1 1 1 1 11 1 1 1
1 1 1 1 1 1 2 1 2 1 1 1 2 2 2
2 2 2 2 2 2 2 11/61.8 3 1
2 2 1 1 2 2 2 2 2 3 3 3 3 3
14/62.3 4 1 2 2 2 1 2 2 2 2 2 3 3
3 3 4 14/6
Working set size for different substrings
17Knee in WS Policy Lifetime Curve
1/F
knee
1.2n
2
2
D size
3
1.2
Working set size
1
1.8
2.3
18Assignment 2Due Lecture 13(p. 1) and 14(p. 2-5,
bonus)
- Consider the following high-level code segment
- for (i0iltni)
- Biin
- Aiim
- CiBii
-
- for (i0iltni)
- for (jijltnj)
- CjAim
- CjAjBi
-
- BiCn-1
-
19Assignment 2, Tasks
- Using registers (denoted as Ri), create the
machine language translation of this program
loaded into the virtual address space (with the
page size equal to 1024 words). Assume that the
program starts in page 1 at the address 993 (each
page ends at the address 1023). The constants
(like 0,1 etc.) are in page 0 (at the addresses
starting at 0), the static data (for example, m,
n) in page 3, and each of the arrays A, B, C in
its own page (pages 4, 5 and 6, respectively).
Write an expression that represents the string of
page references generated during execution of
this code segment (use the parameters n, i and
notation (str)n to denote n repetitions of the
string str. Represent n-th page by a single
decimal digit n-1). - Assume n12. Write a program to analyze the
run-time behavior of this code segment under the
working set memory policy. In particular, your
program should print a table with rows for
different values of D (the window size) and
columns providing (for D ranging from 1 to 64) - P(D), the total number of page faults,
- W(D), the average working set size,
- F(D) P(D)/w, the average page fault
rate.
20Assignment 2, Plots
- Plot also the following curves
- X axis D, Y-axis P(D), W(D) and 1/F(D)
- for D ranging from 1 to 64.
- Hint A good solution should use the stack
property of the working set policy - If a page fault occurs at D, then it also occurs
at D -1, - If the working set is W for D, then it is at
least W for D1. - From the last plot (D vs. 1/F(D), explain the
cause of the major (at least the largest three)
knees in terms of a reference string features. - A knee in a piecewise linear curve is a
point at which the slope to the immediate left of
it is larger than to the immediate right of it. - In a strict implementation of the working set
policy, a page that drops out of the window is
removed from the memory immediately.
21Assignment 2, Page Removal
- Show that in such a case, that for large w, the
average page fault rate F(D) is nearly equal to
the derivative of the average working set size
W(D). In other words, show that F(D)
W(D1)-W(D) for w gtgt D 1. - In practice, there is a delay between marking
the page as out of the working set and the time
the memory system replaces it with a new page.
Assume that this delay is short for clean pages,
so they cause a page fault immediately when
referenced after dropping from the working set,
and longer for dirty pages, so they will cause a
page fault only when referenced first after a
page fault caused by some other page reference.
Lets call the working set policy with such a
delay a practical working set policy. - Compute the page fault rates F(D) with the
practical working set policy for D1..256 and
plot it together with F(D) for the regular
working set policy. Explain the difference. - Bonus (5pts) For each D and n such that
nfloor(W(D)1/2) find the fault rate under n
frames and OPT policy for the string from (a).
Plot this rate together with corresponding F(D)
with practical working set policy and discuss the
difference.
22Example of A Program
- Consider the program
- for (i0iltni) Aii
- and its machine code
- 1000 (R0)lt-ZERO
- 1001 (R1)lt-n
- 1002 compare R0,R1
- 1003 branch_greaterequal5
- 1004 A(R0)lt-(R0)
- 1005 (R2)lt-ONE
- 1006 (R0)lt-(R0)(R2)
- 1007 branch-5
- ....
- 2000 ONE
- 2001 ZERO
- 2002 n
- 3000 A
23Reference String Created by this Program
- Assuming pages of 1000 bytes, for ngt0 the
reference string would be - 1 2 1 2 (1 1 1 3 1 2 1 1 )n 1 1
- Why ? simple, the execution start with fetching
the statement at address 1000 (so it accesses
page 1). This instruction fetches ZERO from page
2, then the next instruction 1001 is fetched and
it fetches n from page 2. Then, execution enters
the loop beginning in lines 1002-1003 and then
the loop body in lines 1004-1007 which repeats n
times and fetches four instructions out of which
only 1004 and 1005 fetch data from page 3 and 2,
respectively. After the last loop body
execution, two control statements of the loop are
executed. - The same way you can create a string (composed of
page numbers fetched by the program) for the
program from the assignment. - You do not need to execute the program (meaning
what it computes), you just need to establish
what pages it accesses bringing in to processor
instructions and data...