code wiki / _hdl_build / nx_leakscan_gate.nx
nx_leakscan_gate.nx
buildroot/runtime/_hdl_build/nx_leakscan_gate.nx
about
nx_leakscan_gate.nx -- STANDING DETECTOR for the allocate-without-free class.
WHY THIS EXISTS (2026-08-01): two INDEPENDENT runaways collapsed the host in one night --
nx_docportal_admin_daemon (16.5 GB resident in 10 SECONDS, 842 GB of address space over 49h) and
nx_ts_lumadiff (28.4 GB, OOM-killed 7 times). Both were found BY HAND, mid-outage, after the control
plane had already died and three other instruments reported healthy. Nothing was watching the one signal
that named them both instantly.
THE SIGNAL: an organ that only ever grows has VmPeak == VmSize. A healthy process that allocates and frees
has VmPeak > VmSize, because its peak was higher than where it sits now. That single comparison separated
the four real leakers from jellyfin (VmPeak > VmSize, normal churn) on the first pass, with no tuning.
★ IT REPORTS ADDRESS SPACE **AND** RESIDENT, AND RANKS ON RESIDENT.
VmSize alone cries wolf: a 842 GB VmSize with 602 MB RSS hurts Committed_AS but not the page cache,
while 28 GB RESIDENT is what actually drives swap to zero and puts 78 processes into D state. A count
without its classification cries wolf; report both, rank by the one that hurts.
EXIT CONTRACT: 0 = no process over the resident budget. 1 = at least one OVER (a fix list, loudly named).
2 = the scan could not measure (refuses to report GREEN when it did not look -- absence of findings and
absence of measurement must never render identically).
nx_leakscan_gate [rss_budget_mb] default budget 4096 MB
expect_exit: 0 license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_gate_verdict.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 26 | const LS_PID_MAX: i64 = 65536 // from /proc/sys/kernel/pid_max class, never a round guess |
| 27 | const LS_DEFAULT_BUDGET_MB: i64 = 4096 |
functions
| 29 | func ls_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 30 | func ls_n(v: i64) -> i64 { |
| 39 | func ls_read(path: *u8, buf: *u8, cap: i64) -> i64 { |
| 57 | func ls_field(buf: *u8, n: i64, key: *u8) -> i64 {
called by 1: main |
| 110 | func ls_atoi(s: *u8) -> i64 {
called by 1: main |
| 116 | func main(argc: i64, argv: *i64) -> i64 { |