Files
app-catalog-felhom.eu/scripts/memfigure.py
T

32 lines
1.9 KiB
Python

"""memfigure — the memory figure an update test judges an app on (one home; upgrade-test.py and box_walk.py import it)."""
def anon_live(stat: dict):
"""R-1338 (2026-10-28 night): the app's anonymous memory WITHOUT the pages it already gave back.
MEASURED (felhom.eu audits/night-2026-10-28/r1338-meili/, bench and 9202): Wanderer's Meilisearch read `anon` at
84-96 % of its 384 MiB limit for ten minutes while it used ~100 MB. An allocator that frees with MADV_FREE leaves
the pages mapped — `anon` keeps counting them — and the kernel moves them to the INACTIVE FILE list and takes them
back first at the limit (thousands of limit hits, 0 kills, no swap). They are no file cache: `file` stayed at ~1 MB
while `inactive_file` held ~280 MB. Two estimates of the anon the app still holds:
(a) anon - max(0, active_file + inactive_file - file) — the file-list pages beyond the file cache are given back;
(b) active_anon + inactive_anon - shmem — the kernel's own anon lists (given-back pages left them).
The LARGER is taken, capped at `anon`, so the figure errs high, never low (the bench measured (b) 10-22 MB above (a);
a reused given-back page can sit on the file list until the next reclaim pass — (b) still counts it). Missing
fields fall back to `anon`. None when `anon` is missing. Pinned by test_memory_live.py."""
try:
anon = int(stat["anon"])
except (KeyError, TypeError, ValueError):
return None
try:
a = anon - max(0, int(stat.get("active_file", 0)) + int(stat.get("inactive_file", 0)) - int(stat.get("file", 0)))
except (TypeError, ValueError):
return anon
if "active_anon" in stat or "inactive_anon" in stat:
try:
b = int(stat.get("active_anon", 0)) + int(stat.get("inactive_anon", 0)) - int(stat.get("shmem", 0))
except (TypeError, ValueError):
b = anon
a = max(a, b)
return max(0, min(anon, a))