LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cache_miss_fifo_rmf.m
1%{ @file cache_miss_fifo_rmf.m
2 % @brief Position-resolved mean-field miss rates for FIFO(m) caches
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Miss rates for FIFO(m) replacement via a position-resolved
9 % density-dependent population process (DDPP) mean field.
10 %
11 % @details
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.
20 %
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.
24 %
25 % Reference:
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.
28 %
29 % @par Syntax:
30 % @code
31 % [M, MU, MI, pi0] = cache_miss_fifo_rmf(gamma, m, lambda)
32 % @endcode
33%}
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
38u = size(lambda,1);
39n = size(lambda,2);
40h = length(m);
41m = m(:)';
42
43lam_i = zeros(1, n);
44for v = 1:u
45 row = lambda(v,:,1);
46 row(~isfinite(row)) = 0;
47 lam_i = lam_i + row;
48end
49tot = sum(lam_i);
50if tot > 0, p = lam_i / tot; else, p = ones(1,n)/n; end
51
52slots = zeros(sum(m), 2);
53s = 0;
54for i = 1:h
55 for j = 1:m(i)
56 s = s + 1;
57 slots(s,:) = [i j];
58 end
59end
60S = s;
61sidx = zeros(h, max(m));
62for s2 = 1:S
63 sidx(slots(s2,1), slots(s2,2)) = s2;
64end
65dim = n * S;
66
67[~, order] = sort(p, 'descend');
68x0 = zeros(dim,1);
69pos = 0;
70for s2 = 1:S
71 pos = pos + 1;
72 if pos <= n
73 x0((order(pos)-1)*S + s2) = 1.0;
74 end
75end
76
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);
81if ~isempty(G)
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
84else
85 drift_h = @(t, x) fifo_drift(x, p, m, n, h, slots, sidx, S, dim);
86 x0s = x0;
87end
88odeopt = odeset('AbsTol', 1e-10, 'RelTol', 1e-8);
89[~, xvec] = ode15s(drift_h, [0, 20000], x0s, odeopt);
90xss = xvec(end, :)';
91
92pi0 = zeros(n,1);
93for k = 1:n
94 pi0(k) = fifo_out(xss, k, slots, S);
95end
96MI = lam_i(:) .* pi0;
97MU = zeros(1, u);
98for v = 1:u
99 row = lambda(v,:,1);
100 row(~isfinite(row)) = 0;
101 MU(v) = row * pi0;
102end
103M = sum(MI);
104
105tout = []; pi0_t = []; MU_t = []; xtraj = [];
106if ~isempty(tspan)
107 if isempty(x0init), x0t = x0s; else, x0t = x0init(:); end
108 [tout, xtraj] = ode15s(drift_h, tspan, x0t, odeopt);
109 xtraj = xtraj';
110 nt = numel(tout);
111 pi0_t = zeros(n, nt);
112 for k = 1:n
113 for c = 1:nt
114 pi0_t(k,c) = fifo_out(xtraj(:,c), k, slots, S);
115 end
116 end
117 MU_t = zeros(u, nt);
118 for v = 1:u
119 row = lambda(v,:,1);
120 row(~isfinite(row)) = 0;
121 MU_t(v,:) = row * pi0_t;
122 end
123end
124end
125
126function o = fifo_out(x, k, slots, S)
127S2 = size(slots,1);
128acc = 0;
129for s = 1:S2
130 acc = acc + x((k-1)*S + s);
131end
132o = max(0, min(1, 1 - acc));
133end
134
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);
139
140Hpos = zeros(h, max(m));
141Hi = zeros(1, h+1);
142for s = 1:S
143 i = slots(s,1); j = slots(s,2);
144 acc = 0;
145 for k = 1:n
146 acc = acc + p(k) * x(K(k,i,j));
147 end
148 Hpos(i,j) = acc;
149 Hi(i) = Hi(i) + acc;
150end
151M = 0;
152for k = 1:n
153 M = M + p(k) * fifo_out(x, k, slots, S);
154end
155
156Sfull = zeros(1, h+1);
157Sfull(1) = M;
158for i = 2:h
159 Sfull(i) = Hi(i-1);
160end
161
162dX = zeros(dim,1);
163for k = 1:n
164 for s = 1:S
165 i = slots(s,1); j = slots(s,2);
166 xk = x(K(k,i,j));
167 % outflow: full shift toward j+1 (tail leaves); promotion up if i<h
168 o = Sfull(i) * xk;
169 if i < h
170 o = o + p(k) * xk;
171 end
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
174 if j >= 2
175 dX(K(k,i,j)) = dX(K(k,i,j)) + Sfull(i) * x(K(k,i,j-1));
176 else
177 if i == 1
178 dX(K(k,1,1)) = dX(K(k,1,1)) + p(k) * fifo_out(x, k, slots, S);
179 else
180 occ = 0;
181 for jprev = 1:m(i-1)
182 occ = occ + x(K(k,i-1,jprev));
183 end
184 dX(K(k,i,1)) = dX(K(k,i,1)) + p(k) * occ;
185 end
186 end
187 % FIFO demotion: tail of list i+1 lands in place at the same position j
188 if i < h
189 dX(K(k,i,j)) = dX(K(k,i,j)) + Hpos(i,j) * x(K(k,i+1,m(i+1)));
190 end
191 end
192end
193end