~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/cgroup/memcg_protection.m

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 % SPDX-License-Identifier: GPL-2.0
  2 %
  3 % run as: octave-cli memcg_protection.m
  4 %
  5 % This script simulates reclaim protection behavior on a single level of memcg
  6 % hierarchy to illustrate how overcommitted protection spreads among siblings
  7 % (as it depends also on their current consumption).
  8 %
  9 % Simulation assumes siblings consumed the initial amount of memory (w/out
 10 % reclaim) and then the reclaim starts, all memory is reclaimable, i.e. treated
 11 % same. It simulates only non-low reclaim and assumes all memory.min = 0.
 12 %
 13 % Input configurations
 14 % --------------------
 15 % E number      parent effective protection
 16 % n vector      nominal protection of siblings set at the given level (memory.low)
 17 % c vector      current consumption -,,- (memory.current)
 18 
 19 % example from testcase (values in GB)
 20 E = 50 / 1024;
 21 n = [75 25 0 500 ] / 1024;
 22 c = [50 50 50 0] / 1024;
 23 
 24 % Reclaim parameters
 25 % ------------------
 26 
 27 % Minimal reclaim amount (GB)
 28 cluster = 32*4 / 2**20;
 29 
 30 % Reclaim coefficient (think as 0.5^sc->priority)
 31 alpha = .1
 32 
 33 % Simulation parameters
 34 % ---------------------
 35 epsilon = 1e-7;
 36 timeout = 1000;
 37 
 38 % Simulation loop
 39 % ---------------
 40 
 41 ch = [];
 42 eh = [];
 43 rh = [];
 44 
 45 for t = 1:timeout
 46         % low_usage
 47         u = min(c, n);
 48         siblings = sum(u);
 49 
 50         % effective_protection()
 51         protected = min(n, c);                % start with nominal
 52         e = protected * min(1, E / siblings); % normalize overcommit
 53 
 54         % recursive protection
 55         unclaimed = max(0, E - siblings);
 56         parent_overuse = sum(c) - siblings;
 57         if (unclaimed > 0 && parent_overuse > 0)
 58                 overuse = max(0, c - protected);
 59                 e += unclaimed * (overuse / parent_overuse);
 60         endif
 61 
 62         % get_scan_count()
 63         r = alpha * c;             % assume all memory is in a single LRU list
 64 
 65         % commit 1bc63fb1272b ("mm, memcg: make scan aggression always exclude protection")
 66         sz = max(e, c);
 67         r .*= (1 - (e+epsilon) ./ (sz+epsilon));
 68 
 69         % uncomment to debug prints
 70         % e, c, r
 71 
 72         % nothing to reclaim, reached equilibrium
 73         if max(r) < epsilon
 74                 break;
 75         endif
 76 
 77         % SWAP_CLUSTER_MAX roundup
 78         r = max(r, (r > epsilon) .* cluster);
 79         % XXX here I do parallel reclaim of all siblings
 80         % in reality reclaim is serialized and each sibling recalculates own residual
 81         c = max(c - r, 0);
 82 
 83         ch = [ch ; c];
 84         eh = [eh ; e];
 85         rh = [rh ; r];
 86 endfor
 87 
 88 t
 89 c, e

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php