code wiki / (root) / nx_headroom.nx

nx_headroom.nx

buildroot/runtime/nx_headroom.nx

9794 B211 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_headroom.nx -- S4 of the SRE program (seq1295, incident 2026-07-29): the SPAWN-TIME HEADROOM GATE every background producer must consult before forking work. The outage proof: an 8-wide TLS fork pool spooling to tmpfs on a memory-tight box (which had ALREADY refused a build on the MemAvailable floor) co-produced a host-wide starvation + hard crash. /api/build has this gate baked in; this organ EXTRACTS it as the shared, config-driven primitive so no producer derives width from taste again (bounds-derived law). nx_headroom width <cap> <child_cost_mb> [meminfo] [loadavg] [cpuinfo] -> NX-HEADROOM ok width=<n> avail_mb= usable_mb= cores= load1_centi= (exit 0) -> NX-HEADROOM REFUSED reason=mem_floor|load_ceiling ... (exit 5) width = min(cap, cores/2, (MemAvailable-floor)/child_cost), floor 1 -- else REFUSED. nx_headroom gate <need_mb> [meminfo] [loadavg] [cpuinfo] -> ok (exit 0) iff need_mb fits above the floor AND load is under ceiling; else REFUSED exit 5. Conf headroom.conf in CWD: floor_mb= loadceil_centi_per_core= (else derived defaults below). Path override args exist so the GATE can prove exact math on fixture files -- real callers omit them. Read-only; no hw writes (Rule 26). license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_headroom.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main h_puts sys_write h_streq sys_mmap h_read sys_openat_rd sys_read sys_close h_num_after h_slen sys_munmap h_load_centi h_cores h_refuse h_puts ↻ h_putn sys_write ↻ sys_mmap ↻ sys_munmap ↻ h_atoi h_putn ↻

structs

none

consts

18const H_MAGIC_1024: i64 = 1024
19const H_MAGIC_4096: i64 = 4096
20const H_MAGIC_4095: i64 = 4095
22const H_EXIT_USAGE: i64 = 2
23const H_EXIT_REFUSED: i64 = 5
24const H_READCAP: i64 = 131072
25const H_DEF_FLOOR_MB: i64 = 4096 // derived: control plane + page-cache reserve ~11% of the 36GB hub
26const H_DEF_LOADCEIL: i64 = 200 // 2.00 load per core: beyond that the box is already saturated

functions

28func h_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 2: h_refusemain calls 1: sys_write
29func h_putn(v: i64) -> i64
40func h_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: h_num_after
41func h_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
called by 1: main
42func h_atoi(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } return v }
called by 1: main
43func h_read(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
53func h_num_after(buf: *u8, n: i64, key: *u8) -> i64
called by 1: main calls 1: h_slen
82func h_load_centi(buf: *u8, n: i64) -> i64
called by 1: main
108func h_cores(buf: *u8, n: i64) -> i64
called by 1: main
128func h_refuse(reason: *u8, avail: i64, usable: i64, cores: i64, load: i64) -> i64
called by 1: main calls 2: h_putsh_putn
137func main(argc: i64, argv: *i64) -> i64