CS 162
Spring 1996
Homework 6 -- sample solution and discussion
1 Clock Algorithm: pages considered
1.a Minimum
The minimum value of C(f, p), the number of pages considered for replacement while processing f page-faults in a system with p physical pages, occurs when all physical pages are initially free and no pages cleared by the sweeping clock pointer are returned to an active status by system activity. In this case, each such cleared page will be replaced the next time it is considered for replacement. The exact value of Cmin(f, p) is:
f, where f <= p, orthese cases quantify the following process: the first p faults are serviced by considering one page for each; the remaining faults are serviced by sweeping the clock pointer past all p pages (clearing them) before servicing the next p faults by considering one page for each, with the possibility of fewer than p faults being serviced on the final iteration.
p + 2 p (q - 1), where f = p q, or
p + 2 p (q - 1) + p + r, where f = p q + r and p > r > 0.
1.b Maximum
The maximum value of C(f, p) occurs when all physical pages are initially active and every page cleared by the sweeping clock pointer is returned to active status before the next fault is serviced. The exact value of Cmax(f, p) is:
f (p + 1).This formula quanitifies the following process: for each fault serviced, the clock pointer must sweep p pages (clearing them) before the next page considered for replacement is actually replaced, but the system then returns all the other cleared pages to active status before they can be considered for replacement during the next fault.
2 Average VM Latency
The average access latency in a simple single-level paged virtual memory system with hardware-loaded TLB, no cache, probability pt of a TLB miss, probability pp of a page fault given a TLB miss occurs, probability pd that a page is dirty when replaced, time tt to access the TLB, time tm to access memory, and time td to access the disk is:
tt + tm + pt (tt + tm + pp (td + pd td)).this formula quantifies the following: the TLB and memory are always accessed; whenever there is a TLB miss, the TLB and memory are accessed a second time; whenever the TLB miss is a page fault, the disk is accessed; whenever the page fault replaces a dirty page, the disk is accessed a second time.
3 VM Thrashing: LRU vs. MIN vs. clock
For a large array A consisting of pages <A1, A2, ..., An>, a program repeatedly scanning the array (producing a reference string A1 A2...An A1 A2...An...) causes LRU and the clock algorithm to behave pessimally, because LRU selects for replacement the page which will be referenced soonest.