1%{ @file cache_miss_sfifo_rmf.m
2 % @brief Position-resolved mean-field miss rates
for strict FIFO(m) caches
4 % @author LINE Development Team
8 % @brief Miss rates
for strict FIFO(m) replacement via a position-resolved
9 % density-dependent population process (DDPP) mean field.
12 % Strict FIFO(m)
is NOT equivalent to RANDOM(m)/FIFO(m). Gast and Van Houdt
13 % (SIGMETRICS 2015) prove pi_FIFO(m) = pi_RAND(m) exactly but show strict
14 % FIFO(m) differs and give it no mean-field model (only trace simulation).
15 % The difference
is the within-list age ordering: on a hit in list i < h the
16 % demoted tail of list i+1
is reinserted at position 1 of list i (positions
17 % 1..j-1 shift back), which the per-item per-list occupancy of RANDOM(m)
18 % cannot express. This routine tracks x[k,i,j] =
P(item k in position j of
19 % list i) with deterministic (age-based) demotion/eviction and returns the
20 % plain mean-field fixed point; it reduces to the RANDOM(m)/FIFO(m) result
21 % when m_1 = ... = m_{h-1} = 1 (the strict-FIFO == FIFO degeneracy).
23 % Strict FIFO(m) dynamics (aggregate IRM stream):
24 % - miss: insert missed item at position 1 of list 1; list 1 shifts back;
25 % tail (position m_1)
is evicted.
26 % - hit at position j of list i < h: promote that item to position 1 of
27 % list i+1 (list i+1 shifts back, tail demoted); demoted tail enters
28 % position 1 of list i and positions 1..j-1 of list i shift back.
29 % - hit in the top list h: no change.
32 % N. Gast and B. Van Houdt,
"Transient and Steady-state Regime of a Family
33 % of List-based Cache Replacement Algorithms", ACM SIGMETRICS 2015.
37 % [M, MU, MI, pi0] = cache_miss_sfifo_rmf(gamma, m, lambda)
40function [M,MU,MI,pi0,tout,pi0_t,MU_t,xtraj] = cache_miss_sfifo_rmf(gamma, m, lambda, tspan, x0init, accost) %#ok<INUSL>
41if nargin < 6, accost = []; end
42if nargin < 4, tspan = []; end
43if nargin < 5, x0init = []; end
49% aggregate per-item request rates over users
53 row(~isfinite(row)) = 0;
57if tot > 0, p = lam_i / tot; else, p = ones(1,n)/n; end
59% slot map: (list i, position j) -> flat slot index; item k occupies k*S+s
60slots = zeros(sum(m), 2);
69sidx = zeros(h, max(m));
71 sidx(slots(s2,1), slots(s2,2)) = s2;
75% popularity-ordered warm start
76[~, order] = sort(p, 'descend
');
82 x0((order(pos)-1)*S + s2) = 1.0;
86% A non-default access graph (accost) uses the general position-resolved drift
87% from a COLD (empty) cache so non-admissible items drain; the linear default
88% keeps the pre-filled path.
89G = cache_build_item_graphs(accost, lambda, n, h);
91 drift_h = @(t, x) cache_pos_drift_graph(x, p, G, m, n, h, slots, sidx, S, 'head
');
92 x0s = zeros(dim,1); % cold start so non-admissible items drain
94 drift_h = @(t, x) sfifo_drift(x, p, m, n, h, slots, sidx, S, dim);
97odeopt = odeset('AbsTol
', 1e-10, 'RelTol
', 1e-8);
98[~, xvec] = ode15s(drift_h, [0, 20000], x0s, odeopt);
103 pi0(k) = sfifo_out(xss, k, slots, S);
109 row(~isfinite(row)) = 0;
114tout = []; pi0_t = []; MU_t = []; xtraj = [];
116 if isempty(x0init), x0t = x0s;
else, x0t = x0init(:); end
117 [tout, xtraj] = ode15s(drift_h, tspan, x0t, odeopt);
120 pi0_t = zeros(n, nt);
123 pi0_t(k,c) = sfifo_out(xtraj(:,c), k, slots, S);
129 row(~isfinite(row)) = 0;
130 MU_t(v,:) = row * pi0_t;
135function o = sfifo_out(x, k, slots, S)
136% Out-of-cache occupancy of item k (1 minus its total in-cache occupancy)
140 acc = acc + x((k-1)*S + s);
142o = max(0, min(1, 1 - acc));
145function dX = sfifo_drift(x, p, m, n, h, slots, sidx, S, dim)
146% Mean-field drift F(x) for strict FIFO(m); x is dim x 1 over in-cache slots.
147x = max(0, min(1, x));
148K = @(k,i,j) (k-1)*S + sidx(i,j);
150% per-position and per-list hit rates, and the miss rate
151Hpos = zeros(h, max(m));
154 i = slots(s,1); j = slots(s,2);
157 acc = acc + p(k) * x(K(k,i,j));
164 M = M + p(k) * sfifo_out(x, k, slots, S);
167% full-shift rate of each list
168Sfull = zeros(1, h+1);
177 i = slots(s,1); j = slots(s,2);
179 % outflow: shift toward j+1 (or leave list at tail); promotion up if i<h
180 o = (Sfull(i) + sfifo_gi(i,j,Hpos,m,h)) * xk;
184 dX(K(k,i,j)) = dX(K(k,i,j)) - o;
187 dX(K(k,i,j)) = dX(K(k,i,j)) + (Sfull(i) + sfifo_gi(i,j-1,Hpos,m,h)) * x(K(k,i,j-1));
190 dX(K(k,1,1)) = dX(K(k,1,1)) + p(k) * sfifo_out(x, k, slots, S);
194 occ = occ + x(K(k,i-1,jprev));
196 dX(K(k,i,1)) = dX(K(k,i,1)) + p(k) * occ;
199 dX(K(k,i,1)) = dX(K(k,i,1)) + Hi(i) * x(K(k,i+1,m(i+1)));
206function g = sfifo_gi(i, jp, Hpos, m, h)
207% Partial-shift rate of a slot at position jp of list i: aggregate hit rate at
208% deeper positions of list i. The top list h never moves on a hit.