1%{ @file cache_miss_fifo_rmf.m
2 % @brief Position-resolved mean-field miss rates
for FIFO(m) caches
4 % @author LINE Development Team
8 % @brief Miss rates
for FIFO(m) replacement via a position-resolved
9 % density-dependent population process (DDPP) mean field.
12 % FIFO(m) and RANDOM(m) share the exact stationary distribution (Gast and Van
13 % Houdt, SIGMETRICS 2015, Thm 1: pi_FIFO(m) = pi_RAND(m)), so their steady-
14 % state hit ratios coincide and SolverFLD serves FIFO steady state from the
15 % cheaper RAND(m) refined mean field (cache_miss_rmf). Their mean-field
16 % TRANSIENTS differ: FIFO evicts the deterministic tail (residence of exactly
17 % m insertions) whereas RANDOM evicts a uniformly random victim (geometric
18 % residence), so H(t) from a cold cache ramps differently even though H(inf)
19 % agrees. This routine provides that dedicated FIFO transient.
21 % FIFO(m) differs from strict FIFO(m) only in the reinsertion position on a
22 % hit: the demoted tail of list i+1 lands at the vacated position j of list i
23 % (in place, no within-list shift), whereas strict FIFO reinserts at position 1.
26 % N. Gast and B. Van Houdt,
"Transient and Steady-state Regime of a Family
27 % of List-based Cache Replacement Algorithms", ACM SIGMETRICS 2015.
31 % [M, MU, MI, pi0] = cache_miss_fifo_rmf(gamma, m, lambda)
34function [M,MU,MI,pi0,tout,pi0_t,MU_t,xtraj] = cache_miss_fifo_rmf(gamma, m, lambda, tspan, x0init, accost) %#ok<INUSL>
35if nargin < 6, accost = []; end
36if nargin < 4, tspan = []; end
37if nargin < 5, x0init = []; end
46 row(~isfinite(row)) = 0;
50if tot > 0, p = lam_i / tot; else, p = ones(1,n)/n; end
52slots = zeros(sum(m), 2);
61sidx = zeros(h, max(m));
63 sidx(slots(s2,1), slots(s2,2)) = s2;
67[~, order] = sort(p, 'descend
');
73 x0((order(pos)-1)*S + s2) = 1.0;
77% A non-default access graph (accost) uses the general position-resolved drift
78% from a COLD (empty) cache so non-admissible items drain; the linear default
79% keeps the pre-filled path.
80G = cache_build_item_graphs(accost, lambda, n, h);
82 drift_h = @(t, x) cache_pos_drift_graph(x, p, G, m, n, h, slots, sidx, S, 'pos
');
83 x0s = zeros(dim,1); % cold start so non-admissible items drain
85 drift_h = @(t, x) fifo_drift(x, p, m, n, h, slots, sidx, S, dim);
88odeopt = odeset('AbsTol
', 1e-10, 'RelTol
', 1e-8);
89[~, xvec] = ode15s(drift_h, [0, 20000], x0s, odeopt);
94 pi0(k) = fifo_out(xss, k, slots, S);
100 row(~isfinite(row)) = 0;
105tout = []; pi0_t = []; MU_t = []; xtraj = [];
107 if isempty(x0init), x0t = x0s;
else, x0t = x0init(:); end
108 [tout, xtraj] = ode15s(drift_h, tspan, x0t, odeopt);
111 pi0_t = zeros(n, nt);
114 pi0_t(k,c) = fifo_out(xtraj(:,c), k, slots, S);
120 row(~isfinite(row)) = 0;
121 MU_t(v,:) = row * pi0_t;
126function o = fifo_out(x, k, slots, S)
130 acc = acc + x((k-1)*S + s);
132o = max(0, min(1, 1 - acc));
135function dX = fifo_drift(x, p, m, n, h, slots, sidx, S, dim)
136% Mean-field drift F(x) for FIFO(m); x is dim x 1 over in-cache slots.
137x = max(0, min(1, x));
138K = @(k,i,j) (k-1)*S + sidx(i,j);
140Hpos = zeros(h, max(m));
143 i = slots(s,1); j = slots(s,2);
146 acc = acc + p(k) * x(K(k,i,j));
153 M = M + p(k) * fifo_out(x, k, slots, S);
156Sfull = zeros(1, h+1);
165 i = slots(s,1); j = slots(s,2);
167 % outflow: full shift toward j+1 (tail leaves); promotion up if i<h
172 dX(K(k,i,j)) = dX(K(k,i,j)) - o;
173 % inflow: full shift from j-1, or front insertion at j==1
175 dX(K(k,i,j)) = dX(K(k,i,j)) + Sfull(i) * x(K(k,i,j-1));
178 dX(K(k,1,1)) = dX(K(k,1,1)) + p(k) * fifo_out(x, k, slots, S);
182 occ = occ + x(K(k,i-1,jprev));
184 dX(K(k,i,1)) = dX(K(k,i,1)) + p(k) * occ;
187 % FIFO demotion: tail of list i+1 lands in place at the same position j
189 dX(K(k,i,j)) = dX(K(k,i,j)) + Hpos(i,j) * x(K(k,i+1,m(i+1)));