LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cache_ttl_hlru.m
1%{ @file cache_ttl_hlru.m
2 % @brief TTL (characteristic-time) approximation for h-LRU / LRU(m) caches
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Steady-state list occupancy probabilities for an h-LRU cache
9 %
10 % @details
11 % Computes the characteristic-time (TTL) approximation of the list-based
12 % h-LRU (LRU(m)) replacement policy: h LRU lists of capacities m(1..h), a
13 % miss inserts the item at the head of list 1, a hit in list l exchanges
14 % the item with the tail of list l+1 (Gast and Van Houdt, SIGMETRICS 2015).
15 % Under the approximation each list l has a characteristic time T(l); the
16 % level process of an item with request rate lam is a birth-death chain
17 % with up-probability 1-e(l) and down-probability e(l), e(l)=exp(-lam*T(l)),
18 % giving pi(l) proportional to prod_{s<=l} (1-e(s))/e(s). For h=1 this
19 % reduces exactly to the Che approximation for LRU.
20 %
21 % @par Syntax:
22 % @code
23 % pij = cache_ttl_hlru(lambda, m)
24 % @endcode
25 %
26 % @par Parameters:
27 % <table>
28 % <tr><th>Name<th>Description
29 % <tr><td>lambda<td>(u x n x h+1) per-class per-item request rates (as built
30 % by solver_mva_cache_analyzer; identical across lists)
31 % <tr><td>m<td>(1 x h) list capacities
32 % </table>
33 %
34 % @par Returns:
35 % <table>
36 % <tr><th>Name<th>Description
37 % <tr><td>pij<td>(n x h+1) probabilities; column 1 = not cached, column
38 % 1+l = in list l
39 % </table>
40%}
41function pij = cache_ttl_hlru(lambda, m)
42% aggregate the request rate of each item over the user classes; the
43% analyzer replicates the same rate on every list slice, so read slice 2
44lam = zeros(size(lambda,2),1);
45for v = 1:size(lambda,1)
46 lam = lam + reshape(lambda(v,:,min(2,size(lambda,3))), [], 1);
47end
48n = length(lam);
49h = length(m);
50m = m(:)';
51
52% characteristic times solved by per-list bisection (Gauss-Seidel sweeps):
53% sum_k pi_l(k; T) = m(l), with sum_k pi_l increasing in T(l)
54T = ones(1,h) / max(mean(lam), GlobalConstants.FineTol);
55maxSweeps = 200;
56for sweep = 1:maxSweeps
57 Told = T;
58 for l = 1:h
59 lo = 0;
60 hi = max(T(l), 1/max(mean(lam), GlobalConstants.FineTol));
61 % grow hi until the list-l occupancy reaches its capacity
62 while cache_hlru_occ(lam, T, l, hi, h) < m(l) && hi < 1e12
63 hi = 2*hi;
64 end
65 for it = 1:100
66 mid = (lo+hi)/2;
67 if cache_hlru_occ(lam, T, l, mid, h) < m(l)
68 lo = mid;
69 else
70 hi = mid;
71 end
72 end
73 T(l) = (lo+hi)/2;
74 end
75 if max(abs(T-Told)./max(Told,GlobalConstants.Zero)) < GlobalConstants.FineTol
76 break
77 end
78end
79
80pij = cache_hlru_levelprobs(lam, T, h); % (n x h+1): [pi_0, pi_1..pi_h]
81end
82
83function occ = cache_hlru_occ(lam, T, l, Tl, h)
84% total occupancy of list l when its characteristic time is Tl
85T(l) = Tl;
86P = cache_hlru_levelprobs(lam, T, h);
87occ = sum(P(:,1+l));
88end
89
90function P = cache_hlru_levelprobs(lam, T, h)
91% birth-death level probabilities: pi_l ~ prod_{s<=l} (1-e_s)/e_s
92n = length(lam);
93P = zeros(n, h+1);
94for k = 1:n
95 w = zeros(1, h+1);
96 w(1) = 1;
97 for l = 1:h
98 e = exp(-lam(k)*T(l));
99 w(1+l) = w(l) * (1-e)/max(e, GlobalConstants.Zero);
100 end
101 P(k,:) = w / sum(w);
102end
103end
Definition Station.m:245