Least-recently-used (LRU) paging and k-competitiveness #
This file implements the least-recently-used (LRU) online paging rule and proves its
k-competitiveness via a Cslib.DataStructure.Amortized potential certificate, formalizing
Theorem 6
of Sleator and Tarjan, Amortized Efficiency of List Update and Paging Rules, Section 4
("Paging"), p. 207 (proof pp. 207–208) in the equal-capacity
(n_LRU = n_MIN = k) demand-paging model of CslibFrontier.DataStructure.Paging.Basic.
Source statement and mapping #
In [ST85a], Section 4 ("Paging"), pp. 207–208, Theorem 6 (p. 207) bounds the page
faults of LRU with fast-memory capacity n_LRU against any offline paging algorithm with
fast-memory capacity n_MIN ≤ n_LRU by (n_LRU / (n_LRU - n_MIN + 1)) · F_MIN + n_MIN.
Specializing to equal online and offline fast-memory capacity (n_LRU = n_MIN = k, 0 < k):
- Concrete LRU memory is a duplicate-free list
q : List α(q.Nodup ∧ q.length ≤ k) ordered from most recently used (head) to least recently used (last). lruNext k q pmovespto the front on a cache hit (p ∈ q) and prependspwhile truncating to lengthkon a cache miss (p ∉ q), evicting the least recently used page whenq.length = k.lruPotential k s qis the maximum of:maxWeightFrom k s q: the recency weightk - iof the most recent page inqabsent from the offline caches(0ifq ⊆ s), and(s \ q.toFinset).card: the number of offline-cached pages absent fromq(handling partially filled cachesq.length < k).
lruAmortizedpackages the single-step inequalitystepCost + lruPotential k s' q' ≤ k * stepCost_off + lruPotential k s qas aCslib.DataStructure.Amortizedcertificate over(problem α k).offlineSpec.- Telescoping via
DetStrategy.competitive_of_amortizedandDetStrategy.competitiveAnyInit_of_amortizedyields:lruStrategy_isCompetitive:(lruStrategy k hk).IsCompetitive k 0when online and offline caches start from the same valid initial caches₀(sincelruPotential k s₀ (init s₀) = 0), andlruStrategy_isCompetitiveAnyInit:(lruStrategy k hk).IsCompetitiveAnyInit k kwhen online and offline caches start from arbitrary valid initial caches of size at mostk(sincelruPotential k s_off q ≤ k).
Resource augmentation with unequal fast-memory capacities (n_MIN < n_LRU) is left as a separate
extension.
Main definitions #
Cslib.DataStructure.Paging.lruNext,lruStep,lruRun,lruFaults: computable recency-list LRU transitions and fault counter.Cslib.DataStructure.Paging.maxWeightFrom,lruPotential: potential function between an offline caches : Finset αand an LRU recency listq : List α.Cslib.DataStructure.Paging.lruStrategy:Online.DetStrategy (problem α k)realization of LRU.
Main results #
lruAmortized:Cslib.DataStructure.Amortizedcertificate for LRU againstktimes offline step cost.lruFaults_amortized_bound: computable-list telescoping bound for any valid initial recency list and any valid offline schedule.lruStrategy_isCompetitive:(lruStrategy k hk).IsCompetitive k 0from any common initial cache.lruStrategy_isCompetitiveAnyInit:(lruStrategy k hk).IsCompetitiveAnyInit k kacross arbitrary initial caches.
References #
Computable recency-list LRU operations #
Advance the recency-ordered LRU list (most recently used first) of capacity k on page p.
Single-step LRU update returning the new recency list and whether a page fault occurred.
Run lruNext k across a request list from initial recency list q.
Count total page faults incurred by computable recency-list LRU from q on reqs.
lruNext preserves List.Nodup.
For 0 < k, p always resides in lruNext k q p.
Packaging LRU as an Online.DetStrategy #
Deterministic online strategy realizing LRU for demand paging with positive capacity k.
Marked noncomputable solely because init s₀ := s₀.toList selects an initial recency ordering on
pre-loaded cache elements from s₀ : Finset α (canonically [] when s₀ = ∅, as witnessed by
lruStrategy_cost_empty, with lruPotential k s₀ s₀.toList = 0 for every s₀). For an explicit
initial recency list q : List α, lruRun, lruFaults, and lruFaults_amortized_bound are
directly computable.
lruStrategy.runMem agrees with computable lruRun.
lruStrategy.costFrom agrees with computable lruFaults.
From an empty cache ∅, lruStrategy.cost equals computable lruFaults k [] reqs.
Potential function and structural step inequalities #
Recency weight of the most recently used element in q absent from s (0 if all elements of
q belong to s), assigning head weight w and decrementing by 1 at each step toward the LRU
tail.
Potential function between offline cache s and LRU recency list q at capacity k.
maxWeightFrom w s q never exceeds the head weight w.
When every page of q is in s, maxWeightFrom vanishes.
Taking a prefix cannot increase maxWeightFrom.
Removing a resident page p ∈ s from q and decrementing the starting weight does not
increase maxWeightFrom.
Decrementing the starting weight either yields 0 or decreases maxWeightFrom by at least
1.
lruPotential k s q never exceeds k when s.card ≤ k.
lruPotential k s q vanishes whenever q represents the exact same page set as s.
Cslib.DataStructure.Amortized certificate and competitive theorems #
Native Cslib.DataStructure.Amortized potential certificate for lruStrategy k hk against k
times the offline demand-paging step cost.
Computable-list telescoping bound for LRU: for any valid recency list q and any valid offline
schedule (s_off, reqs, offStates), lruFaults k q reqs plus final potential is at most k times
offline faults plus initial potential.
LRU k-competitiveness from a common initial cache ([ST85a], Theorem 6 at
n_LRU = n_MIN = k with identical initial caches): when online and offline algorithms start from
the same valid cache s₀ (including ∅), lruStrategy k hk incurs at most k times the faults
of any valid offline schedule, with zero additive constant.
LRU k-competitiveness across arbitrary initial caches ([ST85a], Theorem 6 at
n_LRU = n_MIN = k): for any valid initial caches s₀ and s_off of size at most k,
lruStrategy k hk incurs at most k * optCost + k faults.