The demand-paging action and cost model #
This file instantiates Cslib.DataStructure.Online.Problem for the classical unweighted
demand-paging (cache replacement) problem of
Sleator and Tarjan, Amortized Efficiency of List Update and Paging Rules, Section 4 ("Paging"),
pp. 207–208 and Cormen, Leiserson, Rivest, and Stein, Introduction to
Algorithms, third edition, Problem 16-5 ("Off-line caching").
Over a page universe α ([DecidableEq α]) and cache capacity k : Nat:
- An observable cache configuration is a finite set
s : Finset αsatisfyingValidCache k s(s.card ≤ k). - On request
p : α:- Cache hit (
p ∈ s):pis already resident; no fault is charged (stepCost = 0) and the cache remains unchanged (s' = s). - Cache miss (
p ∉ s):pmust be loaded into the new cache (p ∈ s',s'.card ≤ k) while retaining only pages frominsert p s(s' ⊆ insert p s, retaining any subset ofinsert p sof size at mostk— in particular single-page replacement whens.card = kand non-evicting insertion whens.card < k), incurring one page fault (stepCost = 1).
- Cache hit (
Both online paging strategies (Online.DetStrategy (problem α k)) and offline reference schedules
((problem α k).ValidSchedule) share this exact transition and fault-counting specification,
including initial cache configurations.
Main definitions #
Cslib.DataStructure.Paging.ValidCache: capacity bounds.card ≤ k.Cslib.DataStructure.Paging.ValidStep: valid demand-paging transitions ↦ s'on requestp.Cslib.DataStructure.Paging.stepCost: unit fault cost (0on hit,1on miss).Cslib.DataStructure.Paging.problem: theOnline.Probleminstance for demand paging.
Main results #
validStep_hit,validStep_insert,validStep_replace: constructors for cache hits, non-full insertions, and single-page evictions.scheduleCost_le_length: total page faults over any trajectory never exceed the number of requests.validSchedule_replicate_of_forall_mem,scheduleCost_replicate_of_forall_mem: serving a sequence of resident pages keeps the cache constant at zero fault cost.
References #
Valid single-request demand-paging transition s ↦ s' on page p: both caches hold at most
k pages, p resides in s', cache hits preserve s' = s, and cache misses satisfy
s' ⊆ insert p s.
Standard paging cost: 0 on a cache hit (p ∈ s) and 1 on a cache miss (p ∉ s).
The demand-paging Online.Problem over page type α and cache capacity k.
Every single-step paging transition charges at most one fault.
A cache hit keeps s unchanged as a valid transition.
Every valid transition on a resident page p ∈ s leaves the cache unchanged.
Every valid transition on a missing page p ∉ s satisfies s' ⊆ insert p s.
Loading a missing page into a non-full cache (s.card < k) without eviction is valid.
Total faults along any schedule are at most the number of requests.
Serving a request sequence whose pages are all already in s keeps s unchanged.
Serving a request sequence whose pages are all already in s incurs zero faults.
Repeating s along any list ends in s.
Every valid demand-paging schedule starting from a valid cache ends in a valid cache.