Documente Academic
Documente Profesional
Documente Cultură
Consider the management of a cache over T time periods given advance knowledge of requests 0 , 1 , . . . , T 1 from a set of items stored in slower memory.
Let St denote the set of items stored in the cache just before t is requested.
If t St then St+1 = St . Otherwise, a decision must be made to evict one item
from theP
cache, which is replaced by t . The objective is to maximize the number
1
of hits: Tt=0
1(t St ).
The MIN algorithm chooses to evict an item in the cache whose next request
occurs furthest in the future. If there are multiple items that will never again be
requested one of them is chosen arbitrarily. Mattson, Gecsei, Slutz, and Traiger [2]
establish that this algorithm is optimal.1 However, their proof is somewhat long
and complicated. The textbook Randomized Algorithms [3] offers an excellent account of several cache replacement algorithms and their analyses. In the case of the
MIN algorithm, the authors cite the optimality result of [2] without providing the
proof, which they mention to be nontrivial. Here we offer a short and elementary
proof based on a dynamic programming argument.
Proof of Optimality
Recall that, when a requested item is not in St , one item must be evicted. Another
way of thinking about the decision to be made at time t is in terms of what the next
1 In [2], this algorithm is referred to as the OPT algorithm. In that work, the term MIN identifies another
algorithm originally proposed in [1].
cache state St+1 will be. In particular, the set of feasible decisions can be written
as
Ut (St ) = {S St t : t S, |S| = |St |}.
Note that, if t S then Ut (St ) = {St }. Otherwise, Ut (St ) is the set of cache
states that can be arrived at by replacing an existing item with the newly requested
item t .
Let Jt (St ) denote the maximum over feasible sequences of cache states of the
number of future hits starting with the tth request. The functions J0 , . . . , JT can
be computed via a dynamic programming recursion:
JT (ST )
Jt (St )
1(t St ) +
max
St+1 Ut (St )
Jt+1 (St+1 ),
min
hmatchings
dht (S, S 0 ).
The MIN algorithm evicts the item to be requested furthest in the future.
Hence, if St+1 is chosen by the MIN algorithm and Z Ut (St ) is some other
feasible choice then dt+1 (St+1 , S 0 ) dt+1 (Z, S 0 ) for any cache state S 0 . In
other words, St+1 argminZUt (St ) dt+1 (Z, S 0 ) for all S 0 .
The following lemma shows how dt can be used to bound differences among
values of cache states.
Lemma 1. Jt (S 0 ) Jt (S) dt (S, S 0 ) for all t T and S, S 0 with
|S| = |S 0 |.
Proof: Since JT (S) = JT (S 0 ) = 0 and dT (S, S 0 ) = 0, the result holds for
t = T . We proceed by weak induction. Fix t < T and assume Jt+1 (S 0 )
Jt+1 (S) dt+1 (S, S 0 ) for all S, S 0 with |S| = |S 0 |.
0
Let St = S and St0 = S 0 . Let St+1
Ut (St0 ) be chosen by an optimal
strategy. Let St+1 Ut (St ) be chosen by the MIN algorithm, and note that this
0
implies St+1 argminZUt (St ) dt+1 (Z, St+1
). We study the relationship be0
0
tween dt (St , St ) and dt+1 (St+1 , St+1 ) in four cases:
0
Case 1: Both St and St0 are hit by t . Neither cache state changes, so dt+1 (St+1 , St+1
)=
0
dt (St , St ).
Case 2: Neither St nor St0 are hit by t . If St0 evicts an item, St can evict the same
0
item. It follows that dt+1 (St+1 , St+1
) dt (St , St0 ).
Case 3: Only St is hit by t . St0 evicts an item and at best this improves its relative
0
standing by 1; that is, dt+1 (St+1 , St+1
) dt (St , St0 ) + 1.
0
Case 4: Only St is hit by t . St was previously disadvantaged relative to St0 by
not holding t but now by replacing the item to be requested furthest in the future
0
with t , this disadvantage vanishes. Hence, dt+1 (St+1 , St+1
) dt (St , St0 ) 1.
These four relations together imply that
0
dt+1 (St+1 , St+1
) dt (St , St0 ) + 1(t St ) 1(t St0 ).
Using this relation, the dynamic programming recursion, and our inductive hypothesis, we obtain
Jt (St0 )
0
1(t St0 ) + Jt+1 (St+1
)
0
1(t St0 ) + dt+1 (St+1 , St+1
) + Jt+1 (St+1 )
1(t St ) +
max
ZUt (St )
2
Given St , let St+1 be a successive cache state selected by the MIN algo0
rithm and let St+1
be a successive cache state selected by an optimal strategy.
0
0
Since St+1 minimizes dt+1 (St+1 , St+1
) over the set Ut (St ) which contains St+1
,
0
0
dt+1 (St+1 , St+1
) = 0. By the optimality of St+1
and Lemma 1,
0
0
0 Jt+1 (St+1
) Jt+1 (St+1 ) dt+1 (St+1 , St+1
).
0
It follows that Jt+1 (St+1
) = Jt+1 (St+1 ), and therefore, a decision made by the
MIN algorithm is optimal.
Acknowledgments
Balaji Prabhakar introduced the author to the MIN algorithm, its history, and the
interest in obtaining a simpler proof of optimality.
References
[1] L. A. Belady. A study of replacement algorithms for virtual storage computers.
IBM Systems Journal, 5(2):78101, 1966.
[2] R. L. Mattson, J. Gecsei, D. R. Slutz, and I. L. Traiger. Evaluation techniques
for storage hierarchies. IBM Systems Journal, 9(2):78117, 1970.
[3] R. Motwani and P. Raghavan. Randomized Algorithms. Cambridge University
Press, 1995.