code wiki / _hdl_build / nx_memvel.nx
nx_memvel.nx source
↩ module page · 395 lines · 22165 B
1// nx_memvel.nx -- WHICH process is EATING memory, ranked by SUSTAINED growth (seq1365 / seq1376).
2//
3// WHY IT EXISTS: nx_resmon ranks by MAGNITUDE, so a stable 3 GB tenant outranks a 50 MB process
4// doubling every minute and the real leaker hides. Measured 2026-07-30: swap 525->609 permil in 51 min
5// (~2.03 GB, ~40 MB/min) while the worst_committed process grew ~1 MB. LAW: a census that reports a
6// LEVEL cannot find a LEAK.
7//
8// ★★WHY IT IS N-SAMPLE (this organ's own v1 was WRONG -- seq1376): the FIRST version took ONE 5-second
9// window and I published its top row as a unified root cause. The very next run of the same organ put a
10// DIFFERENT process on top (3560 kB/s vs the previous winner's 1597) and demoted the old winner to #3.
11// The top slot ROTATES. A one-shot ranking of a noisy signal is a coin flip dressed as a finding -- the
12// exact ONE-WINDOW-IS-NOT-A-RATE defect (seq1340) committed by the author of that law, using the tool
13// built to prevent it. Knowing a discipline is not obeying it, so the discipline is now STRUCTURAL:
14// this organ CANNOT report a single-window ranking, because it no longer takes one.
15//
16// ★THE DECIDING COLUMN IS grew_in=k/N, NOT the rate. A real leak grows in EVERY window (k=N). A process
17// that tops one window and vanishes from the next is NOISE, and now says so on its own line. Rate alone
18// cannot distinguish them, which is precisely how v1 misled.
19// Rule 15: top-k, pid-join and rate arithmetic imported from nx_ctxtop_lib / nx_procchurn_lib.
20// Exit 0 = sampled; 3 = UNMEASURED (fail-closed).
21// license_tier: ORIGINAL Read-only. No hw writes (Rule 26). expect_exit: 0
22import "nx_ctxtop_lib.nx"
23import "nx_proc_ctl.nx"
24import "nx_ioadmit_lib.nx" // the ONE shared /proc/stat ncpu parser (ioa_ncpu) -- never a baked core count
25
26const MV_MAXP: i64 = 2048
27const MV_TABLE_BYTES: i64 = 16384
28const MV_DIRBUF: i64 = 65536
29const MV_STATBUF: i64 = 4096
30const MV_TOPK: i64 = 8
31const MV_TOPK_BYTES: i64 = 128
32const MV_ROUNDS: i64 = 5
33const MV_WINDOW_MS: i64 = 1200
34const MV_US_PER_MS: i64 = 1000
35const MV_NAMEOFF: i64 = 6
36const MV_EXIT_UNMEASURED: i64 = 3
37const MV_EXIT_REFUSED: i64 = 4
38const MV_ADMIT_DEFAULT: i64 = 800
39const MV_CONFBUF: i64 = 4096
40const MV_STATBUF: i64 = 65536 // whole-file /proc/stat read, sized like BA_READCAP so it cannot short-read
41const MV_LOADBUF: i64 = 128
42// The status file is FIXED-SHAPE: 6 numeric fields, under 48 bytes of labels, and 6 newlines (one field
43// per line -- rm_field is LINE-ANCHORED). An i64 renders in at most 20 digits, so it cannot exceed
44// 6*20 + 48 + 6 = 174 bytes. 256 is therefore a PROVEN bound derived from the widest value the type can
45// hold -- not a guessed ceiling, and it cannot truncate. (Corrected from 168: the first count omitted
46// the newlines, which is exactly the kind of off-by-a-term that makes a "derived" bound a guess again.)
47const MV_STATUSLINE: i64 = 256
48
49// committed = RSS + Swap. Judging on COMMITTED (never VmSize/VmData) is inherited from nx_resmon's own
50// correction: VmData counts reservations never faulted in and once reported 40.6 GiB on a 36.9 GB box.
51func mv_committed(sbuf: *u8, sn: i64) -> i64 {
52 let r: i64 = rm_field(sbuf, sn, "VmRSS:" as *u8)
53 let w: i64 = rm_field(sbuf, sn, "VmSwap:" as *u8)
54 if r < 0 { return 0 - 1 }
55 var t: i64 = r
56 if w > 0 { t = t + w }
57 return t
58}
59
60func mv_scan(pids: *i64, kbs: *i64, dbuf: *u8, path: *u8, sbuf: *u8) -> i64 {
61 var cnt: i64 = 0
62 let fd: i64 = sys_openat_rd("/proc" as *u8)
63 if fd < 0 { return 0 }
64 var run: i64 = 1
65 while run == 1 {
66 let n: i64 = sys_getdents64(fd, dbuf, MV_DIRBUF)
67 if n <= 0 { run = 0 } else {
68 var off: i64 = 0
69 while off < n {
70 let rec: *u8 = ((dbuf as i64) + off) as *u8
71 let reclen: i64 = dirent_reclen(rec)
72 if reclen <= 0 { off = n } else {
73 let nm: *u8 = dirent_name(rec)
74 if nm[0] >= (48 as u8) { if nm[0] <= (57 as u8) { if cnt < MV_MAXP {
75 var p: i64 = 0
76 let pre: *u8 = "/proc/" as *u8
77 var a: i64 = 0
78 while pre[a] != (0 as u8) { path[p] = pre[a]; p = p + 1; a = a + 1 }
79 var pidv: i64 = 0
80 a = 0
81 while nm[a] != (0 as u8) { path[p] = nm[a]; pidv = pidv * 10 + ((nm[a] as i64) - 48); p = p + 1; a = a + 1 }
82 let suf: *u8 = "/status" as *u8
83 a = 0
84 while suf[a] != (0 as u8) { path[p] = suf[a]; p = p + 1; a = a + 1 }
85 path[p] = 0 as u8
86 let sn: i64 = rm_read(path, sbuf, MV_STATBUF)
87 if sn > 0 {
88 let c: i64 = mv_committed(sbuf, sn)
89 if c >= 0 { pids[cnt] = pidv; kbs[cnt] = c; cnt = cnt + 1 }
90 }
91 } } }
92 off = off + reclen
93 }
94 }
95 }
96 }
97 sys_close(fd)
98 return cnt
99}
100
101// Fill <out> with the process name for <pid>, NUL-terminated; returns the length, 0 when the process
102// is gone. EXTRACTED from mv_putname because the status FILE needs the name as DATA, not as stdout.
103// ★★★★★A VALUE THAT EXISTS ONLY AS PRINTED TEXT CANNOT BE PUBLISHED, so every consumer of the status
104// plane learned that something was leaking and had no way to learn WHAT -- the name was computed on
105// every run and thrown away one line later.
106func mv_getname(pid: i64, path: *u8, sbuf: *u8, out: *u8, cap: i64) -> i64 {
107 var p: i64 = 0
108 let pre: *u8 = "/proc/" as *u8
109 var a: i64 = 0
110 while pre[a] != (0 as u8) { path[p] = pre[a]; p = p + 1; a = a + 1 }
111 p = pc_catn(path, p, pid)
112 let suf: *u8 = "/status" as *u8
113 a = 0
114 while suf[a] != (0 as u8) { path[p] = suf[a]; p = p + 1; a = a + 1 }
115 path[p] = 0 as u8
116 let sn: i64 = rm_read(path, sbuf, MV_STATBUF)
117 if sn <= 0 { out[0] = 0 as u8; return 0 }
118 var z: i64 = MV_NAMEOFF
119 var w: i64 = 0
120 while z < sn { if sbuf[z] == (10 as u8) { z = sn } else { if w < cap - 2 { out[w] = sbuf[z]; w = w + 1 } z = z + 1 } }
121 out[w] = 0 as u8
122 return w
123}
124// Unchanged behaviour for every existing caller: same "<gone>" on a vanished pid, same bytes on stdout.
125func mv_putname(pid: i64, path: *u8, sbuf: *u8) -> i64 {
126 let out: *u8 = sys_mmap(64)
127 let w: i64 = mv_getname(pid, path, sbuf, out, 64)
128 if w <= 0 { rm_puts("<gone>" as *u8) } else { rm_puts(out) }
129 sys_munmap(out, 64)
130 return 0
131}
132
133func main() -> i64 {
134 // ADMISSION CONTROL (seq341 / seq1389): 5 rounds x ~450 procs = ~2700 openat+read+close per run.
135 // That is a real load, and this organ exists to measure a box already under pressure -- exactly when
136 // adding to it is worst. ★LAW: A DIAGNOSTIC THAT CANNOT REFUSE TO RUN IS A LOAD GENERATOR WITH GOOD
137 // INTENTIONS. Fail-CLOSED: an unreadable loadavg REFUSES (ct_admit), because not knowing the load is
138 // not permission to add to it.
139 let cbuf: *u8 = sys_mmap(MV_CONFBUF)
140 let cn: i64 = rm_read("knowledge/status/procchurn.conf" as *u8, cbuf, MV_CONFBUF)
141 let maxload: i64 = rm_conf(cbuf, cn, "admit-max-load-centi" as *u8, MV_ADMIT_DEFAULT)
142 let lbuf: *u8 = sys_mmap(MV_LOADBUF)
143 let ln: i64 = rm_read("/proc/loadavg" as *u8, lbuf, MV_LOADBUF)
144 let loadc: i64 = ct_load_centi(lbuf, ln)
145 // RUN-QUEUE ADMISSION (2026-08-21). The deciding axis is CPU headroom, NOT loadavg -- see
146 // ct_admit_runq for the measurement that forced it: this organ was refused CONTINUOUSLY for 7.4 h
147 // while procs_running sat at 1-3 of 8 and swap climbed past its 700 permil bar, because loadavg on
148 // this NAS is dominated by RAID D-state that a procfs walker can neither cause nor deepen. ncpu is
149 // DERIVED by the one shared parser. loadavg is still read and still PRINTED as context in the
150 // refusal -- it simply no longer decides. Fail-CLOSED on an unreadable /proc/stat.
151 let mvsbuf: *u8 = sys_mmap(MV_STATBUF)
152 let mvsn: i64 = rm_read("/proc/stat" as *u8, mvsbuf, MV_STATBUF)
153 var mv_ncpu: i64 = 0
154 var mv_run: i64 = 0 - 1
155 if mvsn > 0 {
156 mv_ncpu = ioa_ncpu(mvsbuf, mvsn)
157 mv_run = rm_field(mvsbuf, mvsn, "procs_running" as *u8)
158 }
159 if ct_admit_runq(mv_run, mv_ncpu) == 0 {
160 rm_puts("NX-MEMVEL verdict=REFUSED procs_running=" as *u8); rm_num(mv_run)
161 rm_puts(" ncpu=" as *u8); rm_num(mv_ncpu)
162 rm_puts(" load_centi=" as *u8); rm_num(loadc)
163 rm_puts(" retired_load_bar=" as *u8); rm_num(maxload)
164 rm_puts(" why=CPU run queue saturated; load is CONTEXT ONLY and no longer decides (it counts D-state disk wait a procfs walker cannot cause); a /proc-walking diagnostic must not add to it (seq341)\n" as *u8)
165 // ★★★★★★A REFUSING RUN AND A MISSING RUN ARE INDISTINGUISHABLE FROM OUTSIDE, AND THAT
166 // INDISTINGUISHABILITY *IS* THE DEFECT. Measured 2026-08-21: memvel.status sat frozen at one
167 // epoch for 7.2 h against a 600 s beat (~43 missed intervals) while swap climbed past its 700
168 // permil bar -- and FOUR lanes reached FOUR different mechanisms for it (a daily producer, a
169 // plumbing mismatch, a cadence-vs-bound error, a dead beat) because from outside there was
170 // nothing to read. The beat was firing the whole time; admission was declining it above; the
171 // organ returned BEFORE any write. A guard that declines to work must STAMP ITS REFUSAL, or it
172 // is silently identical to a dead beat -- and it fails in the FLATTERING direction, so nobody
173 // investigates. Witnessed live at load_centi=1300 vs max=800 with the status file untouched.
174 // ⚠SEPARATE FILE, NEVER memvel.status: a refusal written into the status artifact would make the
175 // leak axis ACQUIT on a measurement that never happened -- strictly worse than the blindness it
176 // fixes. A reader proves LIVENESS from max(status.epoch, refused.epoch) and keeps proving the
177 // MEASUREMENT from status.epoch alone. Purely additive, so every current consumer parses exactly
178 // what it did before (rule 19).
179 // ONE FIELD PER LINE -- rm_field's contract, the same one the status write below documents; a
180 // space-separated line parses only its FIRST field and every later one reads as ABSENT.
181 // Buffer reuses MV_STATUSLINE deliberately: same purpose (a status record this organ writes),
182 // and this record is 3 fields against the status write's 9, so it cannot be the binding one.
183 let rnl: *u8 = sys_mmap(8)
184 rnl[0] = 10 as u8
185 rnl[1] = 0 as u8
186 let rb: *u8 = sys_mmap(MV_STATUSLINE)
187 var ro: i64 = 0
188 ro = rm_lcat(rb, ro, "epoch=" as *u8)
189 ro = rm_lnum(rb, ro, sys_now_realtime_sec())
190 ro = rm_lcat(rb, ro, rnl)
191 ro = rm_lcat(rb, ro, "load_centi=" as *u8)
192 ro = rm_lnum(rb, ro, loadc)
193 ro = rm_lcat(rb, ro, rnl)
194 ro = rm_lcat(rb, ro, "max_centi=" as *u8)
195 ro = rm_lnum(rb, ro, maxload)
196 ro = rm_lcat(rb, ro, rnl)
197 let rfd: i64 = sys_openat_wr("knowledge/status/memvel.refused" as *u8, MODE_0644)
198 var rw: i64 = 0
199 if rfd >= 0 { rw = sys_write(rfd, rb, ro); sys_close(rfd) }
200 sys_munmap(rb, MV_STATUSLINE)
201 sys_munmap(rnl, 8)
202 // THE PUBLISH ANNOUNCES ITSELF, so a silent failure is a number rather than a guess.
203 rm_puts("NX-MEMVEL refusal_publish fd=" as *u8); rm_num(rfd)
204 rm_puts(" wrote=" as *u8); rm_num(rw)
205 rm_puts(" of=" as *u8); rm_num(ro)
206 rm_puts(" path=knowledge/status/memvel.refused\n" as *u8)
207 return MV_EXIT_REFUSED
208 }
209 let pa: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // previous scan pids
210 let ka: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // previous scan committed kB
211 let pb: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // current scan pids
212 let kb: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // current scan committed kB
213 let ap: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // accumulator pids
214 let asum: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // accumulator summed positive delta (kB)
215 let acnt: *i64 = sys_mmap(MV_TABLE_BYTES) as *i64 // accumulator: in how many windows it GREW
216 let dbuf: *u8 = sys_mmap(MV_DIRBUF)
217 let path: *u8 = sys_mmap(256)
218 let sbuf: *u8 = sys_mmap(MV_STATBUF)
219
220 let t0: i64 = sys_now_us()
221 var na: i64 = mv_scan(pa, ka, dbuf, path, sbuf)
222 if na <= 0 { rm_puts("NX-MEMVEL verdict=UNMEASURED why=/proc walk empty\n" as *u8); return MV_EXIT_UNMEASURED }
223 var nacc: i64 = 0
224 var grew_total: i64 = 0
225 var r: i64 = 0
226 var nb: i64 = 0
227 while r < MV_ROUNDS {
228 sys_sleep_ms(MV_WINDOW_MS)
229 nb = mv_scan(pb, kb, dbuf, path, sbuf)
230 var i: i64 = 0
231 while i < nb {
232 let j: i64 = ct_find(pa, na, pb[i])
233 if j >= 0 {
234 let d: i64 = kb[i] - ka[j]
235 if d > 0 {
236 grew_total = grew_total + d
237 var s: i64 = ct_find(ap, nacc, pb[i])
238 if s < 0 { if nacc < MV_MAXP { ap[nacc] = pb[i]; asum[nacc] = 0; acnt[nacc] = 0; s = nacc; nacc = nacc + 1 } }
239 if s >= 0 { asum[s] = asum[s] + d; acnt[s] = acnt[s] + 1 }
240 }
241 }
242 i = i + 1
243 }
244 // current becomes previous (copy, so the next round diffs against THIS scan)
245 var c: i64 = 0
246 while c < nb { pa[c] = pb[c]; ka[c] = kb[c]; c = c + 1 }
247 na = nb
248 r = r + 1
249 }
250 let el: i64 = (sys_now_us() - t0) / MV_US_PER_MS
251 if el <= 0 { rm_puts("NX-MEMVEL verdict=UNMEASURED why=zero-length observation\n" as *u8); return MV_EXIT_UNMEASURED }
252
253 let tp: *i64 = sys_mmap(MV_TOPK_BYTES) as *i64
254 let tr: *i64 = sys_mmap(MV_TOPK_BYTES) as *i64
255 var used: i64 = 0
256 var q: i64 = 0
257 while q < nacc { used = ct_topk_insert(tp, tr, MV_TOPK, used, ap[q], asum[q]); q = q + 1 }
258
259 // ★THE DECIDING COLUMN, AGGREGATED (2026-08-14). acnt[] already held "in how many of the N windows
260 // did this process grow", and the report has always printed it PER ROW -- but a per-row field that
261 // is never totalled is a measurement no caller can branch on. So every consumer fell back to the
262 // LEVEL census in nx_resmon, whose leak axis is a SNAPSHOT relation (VmSize==VmPeak) that cannot
263 // express growth at all and therefore flags arena-once daemons -- the leak-FREE design -- as leaks.
264 // A process that grew in EVERY window (k==N) is the only shape that is a leak rather than a
265 // rotating top slot. That count is what this organ owes its callers, emitted on a canonical LAST
266 // line so the parse anchors BY POSITION and never on prose that happens to use the same word.
267 // THE COUNT IS THE DECISION, so it lives in nx_resmon_lib where its referee can reach it and where
268 // there is exactly ONE definition of "sustained". The rate below is REPORTING, not judgement.
269 let sustained: i64 = rm_sustained_count(acnt, nacc, MV_ROUNDS)
270 var sust_rate: i64 = 0
271 // ★★★★★A COUNT WITHOUT A WORKLIST IS NOT ACTIONABLE. The published status carried sustained=1 and a
272 // rate but never WHICH PROCESS, so resgov, the beat and a human all learned that something was
273 // leaking and none of them could open an investigation. Measured 2026-08-16: two runs reported
274 // sustained=1 at 1027 and 1264 kB/s and the only way to learn the offender was to re-run the organ
275 // by hand and read its stdout -- on a host that REFUSES the scan when it is saturated, which is
276 // exactly when you need the name. Carry the identity with the number that indicts it.
277 // WORST, not first: with several sustained growers the actionable one is the fastest, and "first"
278 // would hand the investigator whichever pid happened to sort earliest.
279 var sust_pid: i64 = 0
280 var sust_worst: i64 = 0
281 var u: i64 = 0
282 while u < nacc {
283 if acnt[u] >= MV_ROUNDS {
284 let r: i64 = pc_rate(asum[u], el)
285 sust_rate = sust_rate + r
286 if r > sust_worst { sust_worst = r; sust_pid = ap[u] }
287 }
288 u = u + 1
289 }
290
291 rm_puts("NX-MEMVEL rounds=" as *u8); rm_num(MV_ROUNDS)
292 rm_puts(" total_ms=" as *u8); rm_num(el)
293 rm_puts(" procs=" as *u8); rm_num(nb)
294 rm_puts(" grew_kb=" as *u8); rm_num(grew_total)
295 rm_puts(" growers=" as *u8); rm_num(nacc); rm_puts("\n" as *u8)
296 var k: i64 = 0
297 while k < used {
298 let s2: i64 = ct_find(ap, nacc, tp[k])
299 rm_puts(" #" as *u8); rm_num(k + 1)
300 rm_puts(" pid=" as *u8); rm_num(tp[k])
301 rm_puts(" kb_per_sec=" as *u8); rm_num(pc_rate(tr[k], el))
302 rm_puts(" grew_in=" as *u8)
303 if s2 >= 0 { rm_num(acnt[s2]) } else { rm_num(0) }
304 rm_puts("/" as *u8); rm_num(MV_ROUNDS)
305 rm_puts(" name=" as *u8)
306 mv_putname(tp[k], path, sbuf)
307 rm_puts("\n" as *u8)
308 k = k + 1
309 }
310 rm_puts("READ grew_in FIRST: k/" as *u8); rm_num(MV_ROUNDS)
311 rm_puts(" = SUSTAINED leak; anything less is a rotating top slot = NOISE, not a finding (seq1376)\n" as *u8)
312 if nb >= MV_MAXP { rm_puts(" WARNING scan CAPPED -- coverage INCOMPLETE, totals are a floor\n" as *u8) }
313 var cov: i64 = 1
314 if nb >= MV_MAXP { cov = 0 }
315 rm_puts("NX-MEMVEL sustained=" as *u8); rm_num(sustained)
316 rm_puts(" sustained_kb_per_sec=" as *u8); rm_num(sust_rate)
317 rm_puts(" rounds=" as *u8); rm_num(MV_ROUNDS)
318 rm_puts(" coverage_complete=" as *u8); rm_num(cov)
319 rm_puts("\n" as *u8)
320
321 // PUBLISH IT. nx_resmon runs on a per-minute beat and must not pay 6 seconds and ~3000 syscalls to
322 // learn this number, so the measurement is published as ONE OVERWRITTEN LINE rather than an append
323 // log: the reader wants CURRENT, and the trend is already carried by resmon.log, which stamps this
324 // value into its own appended row every beat. ★ONE FILE, ONE PURPOSE -- and a log nothing reads is
325 // an unwired artifact, not a feature.
326 // ★★THE EPOCH FIELD IS LOAD-BEARING: without it a reader cannot tell a fresh measurement from a
327 // fossil, and A STALE FIXTURE SILENCES A GATE. Consumers MUST treat absent-or-stale as UNOBSERVABLE,
328 // never as zero -- an unobserved leak axis voting GREEN is exactly the failure this work removed.
329 // ONE FIELD PER LINE -- this is rm_field's CONTRACT, not a formatting preference. Its docstring is
330 // explicit: "first integer on the line that STARTS with key". A space-separated line therefore
331 // parses only its FIRST field and every later one reads as ABSENT. My first cut wrote all six on
332 // one line: epoch= parsed, sustained= returned -1, and nx_resmon reported the axis UNOBSERVABLE
333 // with a perfectly good file sitting right there. ★★★★★READ THE PARSER'S CONTRACT BEFORE CHOOSING
334 // THE PRODUCER'S FORMAT -- the reader was already written, already correct and already documented;
335 // the producer was the half that was wrong, and a format mismatch fails as a CONFIDENT WRONG ANSWER
336 // ("unobservable") rather than as an error.
337 // ⚠The newline is CONSTRUCTED, never a bare literal: a string literal that IS a newline is ambiguous
338 // to the nx lexer and has silently unseparated whole output streams in this estate before.
339 let nlb: *u8 = sys_mmap(8)
340 nlb[0] = 10 as u8
341 nlb[1] = 0 as u8
342 let sb: *u8 = sys_mmap(MV_STATUSLINE)
343 var so: i64 = 0
344 so = rm_lcat(sb, so, "epoch=" as *u8)
345 so = rm_lnum(sb, so, sys_now_realtime_sec())
346 so = rm_lcat(sb, so, nlb)
347 so = rm_lcat(sb, so, "sustained=" as *u8)
348 so = rm_lnum(sb, so, sustained)
349 so = rm_lcat(sb, so, nlb)
350 so = rm_lcat(sb, so, "kbps=" as *u8)
351 so = rm_lnum(sb, so, sust_rate)
352 so = rm_lcat(sb, so, nlb)
353 so = rm_lcat(sb, so, "rounds=" as *u8)
354 so = rm_lnum(sb, so, MV_ROUNDS)
355 so = rm_lcat(sb, so, nlb)
356 so = rm_lcat(sb, so, "procs=" as *u8)
357 so = rm_lnum(sb, so, nb)
358 so = rm_lcat(sb, so, nlb)
359 so = rm_lcat(sb, so, "coverage=" as *u8)
360 so = rm_lnum(sb, so, cov)
361 so = rm_lcat(sb, so, nlb)
362 // THE ACTIONABLE HALF. ONE FIELD PER LINE, per rm_field's contract documented above -- these are
363 // APPENDED after the existing fields, so every current reader keeps parsing exactly what it did
364 // (rule 19: adding a field is safe, moving one is not).
365 // worst_pid=0 / worst_name=none is the HONEST empty state: it says "no sustained grower", which is
366 // a different fact from "I did not look" (that one is the absent-or-stale epoch above).
367 let wn: *u8 = sys_mmap(64)
368 var wl: i64 = 0
369 if sust_pid > 0 { wl = mv_getname(sust_pid, path, sbuf, wn, 64) }
370 if wl <= 0 { wn[0] = 110 as u8; wn[1] = 111 as u8; wn[2] = 110 as u8; wn[3] = 101 as u8; wn[4] = 0 as u8 }
371 so = rm_lcat(sb, so, "worst_pid=" as *u8)
372 so = rm_lnum(sb, so, sust_pid)
373 so = rm_lcat(sb, so, nlb)
374 so = rm_lcat(sb, so, "worst_kbps=" as *u8)
375 so = rm_lnum(sb, so, sust_worst)
376 so = rm_lcat(sb, so, nlb)
377 so = rm_lcat(sb, so, "worst_name=" as *u8)
378 so = rm_lcat(sb, so, wn)
379 so = rm_lcat(sb, so, nlb)
380 sys_munmap(wn, 64)
381 sys_munmap(nlb, 8)
382 let sfd: i64 = sys_openat_wr("knowledge/status/memvel.status" as *u8, MODE_0644)
383 var wrote: i64 = 0
384 if sfd >= 0 { wrote = sys_write(sfd, sb, so); sys_close(sfd) }
385 sys_munmap(sb, MV_STATUSLINE)
386 // ★★★★★★THE FEATURE ANNOUNCES ITSELF, SO ITS ABSENCE IS VISIBLE IN NORMAL OUTPUT. A publish that
387 // fails silently produces a clean build and a green run -- absent code has no failure mode, and the
388 // only symptom is a consumer that quietly never sees the value. Printing the fd/errno turns a silent
389 // no-op into a number, which is the difference between diagnosing this and guessing at it.
390 rm_puts("NX-MEMVEL status_publish fd=" as *u8); rm_num(sfd)
391 rm_puts(" wrote=" as *u8); rm_num(wrote)
392 rm_puts(" of=" as *u8); rm_num(so)
393 rm_puts(" path=knowledge/status/memvel.status\n" as *u8)
394 return 0
395}