Chapter 10
Chapter 10
1
d. Second-chance replacement 3. Suffers from Belady’s.
b. FIFO replacement 2. Suffers from Belady’s.
You will have to trust my assertions about Belady’s anomaly.
Bonus question: Can you think of a page-replacement algorithm that
would generate the worst possible page-fault rate for any reference
string?
10.5 Consider the page table for ...
• 0EF
• 211
• D00 (page fault, page 7 placed in frame D)
• EFF (page fault, page 0 placed in frame E)
2
B What is the copy-on-write feature, and under what circumstances is its
use beneficial?
D Assume that you are monitoring the rate at which the pointer in the
second-chance victim selection algorithm moves. (The pointer
indicates the candidate page that the algorithm is considering for
replacement.) What can you say about the system if you notice that
the pointer is moving fast? If the pointer is moving slowly?
3
F What is the cause of thrashing? How does the system detect thrashing?
What can the kernel do to eliminate thrashing, once it has been
detected?
A If the system is using pure demand paging, the page fault rate will be
very high when the process first starts, because none of the pages that
the process needs will be in memory.
If the paging algorithm is successful in capturing the working set of
the process in memory, the page fault rate will be 0%.
C If p is the page fault rate and ma is the memory access time, then the
effective access time is defined as
EAT = (1 − p) · ma + p · page fault service time
In this example, the page fault service time is
PFST = 8 msecs · 0.3 + 20 msecs · 0.7
4
Converting to nanoseconds gives
EAT = (1 − p) · 100nsecs + p · (8000000 nsecs · 0.3 + 20000000 nsecs · 0.7)
Set EAT to 200 nsecs and solve for p, giving p ≤ 6.098 · 10−6 .
D If the pointer is moving fast, then the page replacement algorithm must
be running frequently. The page replacement algorithm only runs
when there are no free frames. Thus, the system must be running
under memory over-commit, and page faults must be happening
frequently.
If the pointer is moving slow, then the page replacement algorithm
must be running infrequently. Again, the system must be running
under memory over-commit, since the clock hand would not be
moving at all if there was no contention for memory. However, in this
case, page faults are infrequent, which indicates that the system has
successfully captured in memory most of the pages that processes are
referencing.
5
CPU, and thus finish. Once those processes finish, memory will
be freed up, and the kernel can begin gradually swapping
processes back in.
• Install more main memory.
Likely to improve CPU utilization. More memory would allow us
to allocate more frames to each process, hopefully capturing
more of each process’s locality in memory, thus reducing its
page-fault rate.
• Install a faster paging disk.
May slightly improve CPU utilization. A faster disk may reduce
page-fault service time, leading to a decrease in effective access
time and higher CPU throughput.
• Replace the paging algorithm with one that pre-pages more of
the process.
Prepaging is unlikely to increase CPU utilization. The problem
with this system is that too many pages are fighting over too few
frames. Bringing more pages into memory won’t solve the
problem.
• Increase the page size.
If data and code are accessed sequentially, a large page size
might capture more of a process’s locality in memory, reducing
the page fault rate and thus increasing the CPU utilization.
However, if the process does not access memory sequentially, a
larger page size is unlikely to improve CPU utilization. A larger
page size would tend to capture more code and data than is
contained in the process’s current locality, meaning code and
data which are not being used are stored in memory, wasting
memory and increasing the page fault rate. For example,
imagine a process that is traversing a massive tree in a
breadth-first manner from root to leaves. Parent and child nodes
of this tree are unlikely to reside on the same page. To the
kernel, the process will appear to be accessing memory in a
non-linear fashion.
6
frequent page faults. Thrashing occurs when the sum of all the
memory needs of all the processes on the ready queue is greater than
the amount of physical memory; processes can only execute a few
instructions before they fault for a page.
Since there are no unused frames, a frame must be stolen from
another process, causing that process to fault. Another page is stolen,
causing another process to fault, and so on, in a domino effect. Since
no process has the correct page set in memory to execute for more
than a few instructions, the system is spending all its time servicing
page faults, and little real work is being accomplished.
Thrashing can be detected by monitoring CPU utilization and the
system page-fault rate. A high page-fault rate coupled with a low
CPU utilization indicates thrashing.
Thrashing can be eliminated by swapping out entire processes until
the page-fault rate returns to normal.
t ∆=3 ∆=5
t0 {1} {1}
t1 {1, 2} {1.2}
t2 {1, 2, 3} {1, 2, 3}
t3 {2, 3, 4} {1, 2, 3, 4}
t4 {3, 4, 5} {1, 2, 3, 4, 5}
t5 {1, 4, 5} {1, 2, 3, 4, 5}
t {1, 5, 6} {1, 3, 4, 5, 6}
G 6
t7 {1, 6, 7} {1, 4, 5, 6, 7}
t8 {2, 6, 7} {1, 2, 5, 6, 7}
t9 {2, 6, 7} {1, 2, 6, 7}
t10 {2, 6, 7} {2, 6, 7}
t11 {1, 6, 7} {1, 2, 6, 7}
t12 {1, 5, 7} {1, 2, 5, 6, 7}
t13 {1, 5} {1, 5, 6, 7}
t14 {1, 2, 5} {1, 2, 5, 7}