code wiki / (root) / nx_memfloor.nx

nx_memfloor.nx

buildroot/runtime/nx_memfloor.nx

6430 B138 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_memfloor.nx -- ADMISSION CONTROL FOR A LARGE ALLOCATION, as a shared library. WHY THIS EXISTS (2026-07-30 incident, second of its class): nx_skullsdf.elf held 27.7 GB of a 36 GB host inside 2m48s, drove swap to 98% and load to 41, and the mgmt API began refusing builds ("host below the memory floor"). Its grid resolution comes straight from argv with no upper bound, and the allocation is O(g^3): G=1500 -> 1501^3*8 = 27.06 GB, which is exactly what was observed. seq1547 was the same shape in nx_ssdf (28 GB in 227s), and that one took mgmt, the tools daemon and sshd down with it. THE POINT: the ecosystem ALREADY knew how to do this. nx_build_admit refuses to fork the compiler below a memory floor, and nx_headroom exposes the floor + load ceiling as a CLI. Neither was reachable from inside an organ about to allocate, so every heavy organ re-decided the question -- and the ones that never asked are the ones that ate the host. This is the adoption gap, not a missing primitive: MIGRATE THE CHOKEPOINT, NOT THE LEAF. CONTRACT: call mf_admit_bytes() with the EXACT byte count you are about to map, BEFORE you map it. Returns 1 = admit, 0 = refuse. On refuse the caller must fail fast and say so -- never allocate anyway, and never silently shrink the request (a caller that asked for a 1500-cell grid and quietly got 160 would emit a wrong answer, which is worse than an honest refusal). Lives in runtime/ so _hdl_build/ organs can import it; the reverse never resolves. license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_memfloor.nx nx_skullsdf.nx

imports: nx_syscalls.nx

imported by: nx_skullsdf.nx

structs

none

consts

29const MF_DEF_FLOOR_MB: i64 = 2048
30const MF_CONF: *u8 = "knowledge/memfloor.conf" as *u8
31const MF_MEMINFO: *u8 = "/proc/meminfo" as *u8
32const MF_READCAP: i64 = 8192
33const MF_KB_PER_MB: i64 = 1024

functions

35func mf_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: mf_putsmf_num_after
36func mf_puts(s: *u8) -> i64 { let n: i64 = mf_slen(s); sys_write(2, s, n); return 0 }
called by 1: mf_admit_bytes calls 2: mf_slensys_write
37func mf_putn(v: i64) -> i64
called by 1: mf_admit_bytes calls 2: sys_mmapsys_write
57func mf_read(path: *u8, buf: *u8, cap: i64) -> i64
68func mf_num_after(buf: *u8, n: i64, key: *u8) -> i64
called by 2: mf_avail_kbmf_floor_mb calls 1: mf_slen
98func mf_avail_kb() -> i64
106func mf_floor_mb() -> i64
121func mf_admit_bytes(what: *u8, need_bytes: i64, floor_mb: i64) -> i64
called by 1: mf_admit calls 3: mf_avail_kbmf_putsmf_putn
138func mf_admit(what: *u8, need_bytes: i64) -> i64 { return mf_admit_bytes(what, need_bytes, mf_floor_mb()) }
called by 1: main calls 2: mf_admit_bytesmf_floor_mb