hw3.2.3.9

advertisement
Problem 3.2 Paging Algorithms-Time & Space Requirements
Problem:What are the space and time requirements of
LIFO, LFU, and LED?
LRU:(least-recently-used): when eviction is necessary,
replace the page whose most recent request was earliest.
LIFO(last-in/first-out):replace the page most recently
moved to the fast memory.
LFU(least-frequently-used): replace the page that has
been requested the least since entering the fast memory.
LFD(longest-forward-distance): replace the page whose
next request is latest.
Problem 3.2 Paging Algorithms-Time & Space Requirements
k is the fast memory size, and l is the length of request sequence
• LRU Replacement
• LFU Replacement
LRU Block
New
reference
LFU Block
New
reference
heap
MRU Block
MFU Block
T: O(1) complexity
T: O(log k) complexity
Total: O(l), l is the length of
request sequence.
Total: O(llogk), l is the length of
O(n) complexity
request sequence.
S: O(klogk)
S: O(klog(n))
Problem 3.2 Paging Algorithms-Time & Space Requirements
• LIFO Replacement
• LFD Replacement
Shortest forward distance
Latest page id
Longest forward distance
T: O(1) complexity
T: O(k+l+logk) complexity
Total: O(l), l is the length of
request sequence.
Total: O(l+k+logk)l, l is the
length of request sequence.
S: O(logk)
S: O(klogn)
Problem: 3.9
Problem: Show that FWF is not a conservative
algorithm.
• FWF: Whenever there is page fault and there is no
space left in the cache, evict all pages current in
the cashe.
• A page algorithm ALG is conservative if it
satisfies the following condition:
On any consecutive input subsequence containing k
or fewer distinct page references, ALG will incur
k or fewer page faults.
Problem: 3.9 (Cont.)
• For this exercise assume that the cache is of size k ( k
>1). Otherwise the claim is not true: for example, suppose
that we have a cache of size 1, and the following sequences:
1; 2; 1;2;
Then, in that sequence of 4 requests there are only 2 distinct
requests, yet with a cache of size 1, there would be 4 faults,
for any page-replacement algorithm.
Problem: 3.9 (Cont.)
The main idea to prove FWF is not a conservative algorithm if we can
find a subsequence with k distinct pages and FWF incurs more
than k page faults.
• For FIFO, LRU, each distinct page request can only cause one fault.
Same goes for FIFO. Thus, they are both conservative algorithms.
However, It is possible that half-way through the consecutive
subsequence, the cache of FWF is going to get full, and FWF is
going to evict everybody. Hence, FWF may have more than one page
fault on the same page during this consecutive subsequence. Therefore,
FWF is not a conservative algorithm.
• For example, k = 3;
1; 2; 3; 4;2;3;4
• Subsequence: 2;3;4;2 ( 3 distinct requests, 4 faults)
Download