Documentation

CslibFrontier.DataStructure.Paging.Marking

The randomized marking algorithm for paging (2 H_k-competitiveness) #

This file formalizes the randomized marking algorithm for demand paging (Paging.problem α k, 0 < k) and proves Theorem 1 of Fiat, Karp, Luby, McGeoch, Sleator, and Young, Competitive Paging Algorithms, Section 3 ("The marking algorithm"), Theorem 1: randomized marking is 2 H_k-competitive against an oblivious adversary, with additive constant 0.

Algorithm #

Controller memory (MarkMem α) stores the resident cache : Finset α together with the subset of currently marked : Finset α pages, initialized to ⟨s₀, s₀⟩ so that all initially cached pages start marked (as in [FKL+91], Section 3). On request p:

Because marking tosses a fresh uniform coin at unboundedly many evictions, it is packaged as an Online.BehavioralStrategy (problem α k) (markingStrategy).

Proof architecture #

  1. Exact stale-subset distribution law (MarkTracker, markLaw, expectedCost_markingStrategy_eq): At every step, the controller memory distribution equals markLaw tr, where tr.marked is the deterministic set of marked pages in the current phase, tr.stale is the deterministic set of unmarked pages from the previous phase not yet requested in the current phase, and the cache is tr.marked ∪ U for U drawn uniformly from tr.stale.powersetCard tr.staleCached. This yields an exact computable rational recursion trackerExpectedCost for expectedCost.
  2. Harmonic potential (trackerPotential, trackerExpectedCost_le_harmonic_mul_cleanCount): With c = tr.stale.card - tr.staleCached clean misses so far in the current phase, the potential c * (harmonic tr.stale.card - harmonic c) absorbs every stale request's c / |stale| fault probability with zero residual charge and charges at most harmonic k per clean request, giving E[MARK] ≤ H_k · #clean across both completed and incomplete phases.
  3. Two-window offline lower bound (cleanCount_le_two_mul_scheduleCost): Direct backward induction over arbitrary (not necessarily lazy) valid offline schedules (problem α k).ValidSchedule s₀ reqs offStates tracks the fault set B since the start of the current phase, proving #clean ≤ 2 · OPT without reducing to lazy schedules.

Main definitions #

Main results #

References #

Controller memory and deterministic tracker types #

Internal controller memory of the randomized marking algorithm: the resident cache together with the subset of pages marked during the current phase.

  • cache : Finset α

    Pages currently held in fast memory.

  • marked : Finset α

    Subset of cached pages marked in the current phase.

@[instance_reducible]
def Cslib.DataStructure.Paging.instDecidableEqMarkMem.decEq {α✝ : Type} [DecidableEq α✝] (x✝ x✝¹ : MarkMem α✝) :
Decidable (x✝ = x✝¹)

Representation invariant of MarkMem: the cache holds at most k pages and every marked page is resident in the cache.

Deterministic phase bookkeeping for the distribution invariant of markingStrategy: marked is the set of pages marked in the current phase, stale is the set of unmarked pages from the previous phase not yet requested in the current phase, and staleCached is the number of stale pages currently retained in the cache.

  • marked : Finset α

    Pages marked in the current phase.

  • stale : Finset α

    Stale pages from the previous phase not yet requested in the current phase.

  • staleCached : ℕ

    Number of stale pages currently held in the cache.

Initial tracker state corresponding to markingStrategy.init s₀: all pages of s₀ are marked and no stale pages exist yet.

Structural invariant of MarkTracker for cache capacity k.

theorem Cslib.DataStructure.Paging.validTracker_init {α : Type} {k : ℕ} {s₀ : Finset α} (hs₀ : ValidCache k s₀) :

Harmonic phase potential c * (H_{|stale|} - H_c) where c = |stale| - staleCached is the number of clean misses incurred so far in the current phase.

Behavioural marking strategy #

noncomputable def Cslib.DataStructure.Paging.markingStep {α : Type} [DecidableEq α] (k : ℕ) (m : MarkMem α) (p : α) :

One-step randomized transition of the marking algorithm for cache capacity k on page p.

@[reducible, inline]
noncomputable abbrev Cslib.DataStructure.Paging.markingStrategy {α : Type} [DecidableEq α] (k : ℕ) (hk : 0 < k) :

The randomized marking online strategy ([FKL+91], Section 3) for Paging.problem α k (0 < k). Marks are initialized to the initial cache s₀; hits mark the requested page; misses into a non-full cache insert and mark without eviction; misses into a full cache unmark all pages when every cached page is marked and evict uniformly among unmarked cached pages.

Single-step expected cost of markingStrategy depends only on whether p is currently cached: 0 on a hit and 1 on a miss.

theorem Cslib.DataStructure.Paging.expectedCost_markingStrategy_le_length {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) (reqs : List α) :
(markingStrategy k hk).expectedCost s₀ reqs ≤ ↑reqs.length

Expected cost of markingStrategy on any valid initial cache and request sequence reqs is at most reqs.length, hence finite (≠ ⊤).

theorem Cslib.DataStructure.Paging.expectedCost_markingStrategy_ne_top {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) (reqs : List α) :

Exact stale-subset distribution law #

Deterministic transition of MarkTracker on page request p.

Run stepTracker across a request list.

Whether request p is clean relative to tracker tr (unmarked, and either starting a new phase/warmup slot when staleCached = 0 or outside tr.stale).

Total number of clean requests encountered from tracker tr along reqs.

Exact rational single-step expected fault cost from tracker tr on request p.

Exact rational expected fault cost from tracker tr across reqs.

theorem Cslib.DataStructure.Paging.validTracker_step {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {tr : MarkTracker α} (htr : ValidTracker k tr) (p : α) :

stepTracker preserves ValidTracker when 0 < k.

noncomputable def Cslib.DataStructure.Paging.markLaw {α : Type} [DecidableEq α] (tr : MarkTracker α) :

Exact memory distribution associated with tracker tr: the cache is tr.marked ∪ U for a uniform tr.staleCached-subset U of tr.stale, and the marked set is tr.marked.

theorem Cslib.DataStructure.Paging.markLaw_of_staleCached_eq_zero {α : Type} [DecidableEq α] {M S : Finset α} :
markLaw { marked := M, stale := S, staleCached := 0 } = PMF.pure { cache := M, marked := M }

Whenever staleCached = 0, markLaw collapses to the point mass at ⟨marked, marked⟩.

theorem Cslib.DataStructure.Paging.markLaw_initTracker {α : Type} [DecidableEq α] (s₀ : Finset α) :
markLaw (initTracker s₀) = PMF.pure { cache := s₀, marked := s₀ }
theorem Cslib.DataStructure.Paging.markLaw_bind_markingStep {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {tr : MarkTracker α} (htr : ValidTracker k tr) (p : α) :
((markLaw tr).bind fun (m : MarkMem α) => markingStep k m p) = markLaw (stepTracker k tr p)

Exact distribution invariant of randomized marking. Stepping markLaw tr by markingStep on any request p produces markLaw (stepTracker k tr p).

theorem Cslib.DataStructure.Paging.stepExpectedCost_markLaw {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {tr : MarkTracker α} (htr : ValidTracker k tr) (p : α) :

Single-step expected fault cost of markingStrategy under markLaw tr equals ENNReal.ofReal (stepTrackerCost tr p).

theorem Cslib.DataStructure.Paging.expectedCostDist_markLaw_eq {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {tr : MarkTracker α} (htr : ValidTracker k tr) (reqs : List α) :

Expected continuation cost of markingStrategy from markLaw tr equals ENNReal.ofReal (trackerExpectedCost k tr reqs).

theorem Cslib.DataStructure.Paging.expectedCost_markingStrategy_eq {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) (reqs : List α) :

Exact rational expected cost of randomized marking. From any valid initial cache s₀, (markingStrategy k hk).expectedCost s₀ reqs equals ENNReal.ofReal (trackerExpectedCost k (initTracker s₀) reqs).

Harmonic potential bound (E[MARK] ≤ H_k · #clean) #

Single-step harmonic potential inequality: each stale request is paid exactly out of trackerPotential, and each clean request increases cost + potential by at most harmonic k.

theorem Cslib.DataStructure.Paging.trackerExpectedCost_add_potential_le {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {tr : MarkTracker α} (htr : ValidTracker k tr) (reqs : List α) :

Telescoped harmonic potential inequality over any request list reqs.

theorem Cslib.DataStructure.Paging.trackerExpectedCost_le_harmonic_mul_cleanCount {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) (reqs : List α) :

Harmonic phase bound (E[MARK] ≤ H_k · #clean). From any valid initial cache s₀, the rational expected cost of markingStrategy is at most harmonic k times the number of clean requests.

FKLMSY two-window offline lower bound (#clean ≤ 2 · OPT) #

theorem Cslib.DataStructure.Paging.cleanCount_le_two_mul_scheduleCost {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) {reqs : List α} {offStates : List (Finset α)} (hv : (problem α k).ValidSchedule s₀ reqs offStates) :
cleanCount k (initTracker s₀) reqs ≤ 2 * (problem α k).scheduleCost s₀ reqs offStates

FKLMSY two-window offline lower bound (#clean ≤ 2 · OPT). Against any valid offline schedule from s₀, the number of clean requests encountered from initTracker s₀ is at most twice the offline fault cost.

Main competitiveness theorems (FKLMSY Theorem 1) #

theorem Cslib.DataStructure.Paging.trackerExpectedCost_le_two_mul_harmonic_mul_scheduleCost {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) {reqs : List α} {offStates : List (Finset α)} (hv : (problem α k).ValidSchedule s₀ reqs offStates) :
trackerExpectedCost k (initTracker s₀) reqs ≤ 2 * harmonic k * ↑((problem α k).scheduleCost s₀ reqs offStates)

Rational expected cost of markingStrategy is at most 2 * harmonic k * scheduleCost.

theorem Cslib.DataStructure.Paging.markingStrategy_expectedCost_le {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) {reqs : List α} {offStates : List (Finset α)} (hv : (problem α k).ValidSchedule s₀ reqs offStates) :
(markingStrategy k hk).expectedCost s₀ reqs ≤ 2 * ENNReal.ofReal ↑(harmonic k) * ↑((problem α k).scheduleCost s₀ reqs offStates)

FKLMSY Theorem 1 (ℝ≥0∞ cost bound) [FKL+91]: for every admissible initial cache s₀ (|s₀| ≤ k), request sequence reqs, and valid offline schedule offStates from s₀, the expected cost of markingStrategy is at most 2 H_k times the offline schedule's cost.

FKLMSY Theorem 1 (BehavioralStrategy.IsCompetitive) [FKL+91]: the randomized marking strategy is (2 * H_k, 0)-competitive for demand paging against an oblivious adversary.

theorem Cslib.DataStructure.Paging.markingStrategy_expectedCost_toReal_le {α : Type} [DecidableEq α] {k : ℕ} (hk : 0 < k) {s₀ : Finset α} (hs₀ : ValidCache k s₀) {reqs : List α} {offStates : List (Finset α)} (hv : (problem α k).ValidSchedule s₀ reqs offStates) :
((markingStrategy k hk).expectedCost s₀ reqs).toReal ≤ 2 * ↑(harmonic k) * ↑((problem α k).scheduleCost s₀ reqs offStates)

Real-valued expectation form of FKLMSY Theorem 1.