code wiki / (root) / nx_heavyio_lib.nx

nx_heavyio_lib.nx

buildroot/runtime/nx_heavyio_lib.nx

19788 B375 linesdepth 7pulls 13 transitivereach 15 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_heavyio_lib.nx -- THE HEAVY-I/O CONCURRENCY BOUND, in the PRIMITIVE layer (runtime/) so every bulk-I/O producer can reach it (the seq1450 layering rule: primitives may not import the organ layer). WHY (measured 2026-09-02): the estate's storm ruler nx_ioadmit_lib is an INSTANTANEOUS, PER-CALLER check. The clock scheduler, nx_compare_regen's fork burst, seg-compact, a daemon restart and a seat-launched job EACH read "not stormed" at their own instant and all proceed -- and the storm is their SUM, which none of them individually caused (a TOCTOU / thundering-herd gap). Operator: "this is not sota or best of breed coordination and discipline for hub spoke resource management". A bound must count what is RUNNING across every surface, not what was true at one caller's instant. IT COMPOSES THE TWO INCUMBENTS, NEVER A THIRD RULER: nx_poolgov.pg_width derives K from THIS box (hw budget, PROPORTIONAL squeeze above the load ceiling, fail-safe to wmin) and pg_count_procs counts the running heavy class across every surface; nx_ioadmit_lib.ioa_spawn_budget stays as the storm witness, a SECOND conjunct. Data (rule 11): knowledge/heavyio.conf -- producer <proc-name-needle> one row per heavy-I/O producer (the class this bound governs) slots_per_cpu <n> floor <n> max_centi <n> wmin <n> wmax <n> size the width (reasoning in the conf) hio_decide() is PURE and gate-driven; hio_admit() is the thin /proc wrapper. Three states, never a guess: HIO_ADMIT 1 | HIO_DEFER 0 | HIO_UNOBSERVABLE (-1): conf or /proc unreadable. THE CALLER OWNS THE UNOBSERVABLE POLICY and must NAME it: a periodic beat announces and proceeds (a missing conf must never silence the estate's publishers -- the clock's own ioadmit dispatch check still guards the storm); an interactive spawner may refuse. license_tier: ORIGINAL Read-only. No hw writes (Rule 26). lib (no main)

dependencies 4 imports · 11 importers

nx_syscalls.nx nx_poolgov.nx nx_ioadmit_lib.nx nx_lease_lib.nx nx_heavyio_lib.nx nx_artifactdrift.nx nx_compare_regen.nx nx_compare_regen_scoped.nx nx_compare_regen_t138.nx nx_eco_graph_build.nx nx_heavyio_gate.nx nx_plan_run.nx nx_seg_compact_cli.nx nx_swcompare_evidence.nx nx_web_crawl_step.nx

diagram shows first 10 each side; +0 more imports, +1 more importers in the complete lists below.

imports: nx_syscalls.nxnx_poolgov.nxnx_ioadmit_lib.nxnx_lease_lib.nx

imported by: nx_artifactdrift.nxnx_compare_regen.nxnx_compare_regen_scoped.nxnx_compare_regen_t138.nxnx_eco_graph_build.nxnx_heavyio_gate.nxnx_plan_run.nxnx_seg_compact_cli.nxnx_swcompare_evidence.nxnx_web_crawl_step.nxnx_web_shard_compact.nx

structs

none

consts

28const HIO_CONF: *u8 = "knowledge/heavyio.conf"
29const HIO_ADMIT: i64 = 1
30const HIO_DEFER: i64 = 0
31const HIO_UNOBSERVABLE: i64 = 0 - 1
32const HIO_MAXP: i64 = 32 // producer rows the conf may carry; the reader announces when it fills
33const HIO_NAMEW: i64 = 64 // one producer needle slot (comm names are 15 bytes; cmdline needles longer)
34const HIO_CONFCAP: i64 = 65536
35const HIO_SPACE: i64 = 32
36const HIO_NL: i64 = 10
37const HIO_HASH: i64 = 35
39const HIO_C_NPROD: i64 = 0
40const HIO_C_SLOTS: i64 = 1
41const HIO_C_FLOOR: i64 = 2
42const HIO_C_MAXC: i64 = 3
43const HIO_C_WMIN: i64 = 4
44const HIO_C_WMAX: i64 = 5
45const HIO_C_FILLED: i64 = 6 // 1 when HIO_MAXP was reached (rows beyond it were NOT read -- announced)
46const HIO_C_TTL: i64 = 7 // slot_ttl <sec>: crash guard for a HUNG-BUT-ALIVE holder (a dead one frees at once)
47const HIO_C_SLOTS_N: i64 = 8
48const HIO_C_BYTES: i64 = 64 // HIO_C_SLOTS_N * 8
51const HIO_O_RUNNING: i64 = 0
52const HIO_O_WIDTH: i64 = 1
53const HIO_O_STORM: i64 = 2
54const HIO_O_SLOT: i64 = 3
55const HIO_OUT_BYTES: i64 = 32
60const HIO_ROOT_A: *u8 = "knowledge/"
61const HIO_ROOT_B: *u8 = "../knowledge/"
62const HIO_CONF_LEAF: *u8 = "heavyio.conf"
63const HIO_LEASE_LEAF: *u8 = "lease/"
64const HIO_SLOT_PFX: *u8 = "heavyio-slot-"
65const HIO_OWNER_PFX: *u8 = "pid"
66const HIO_PROC_PFX: *u8 = "/proc/"
67const HIO_PROC_LEAF: *u8 = "/stat"
68const HIO_PATHCAP: i64 = 256
69const HIO_TTL_DEFAULT: i64 = 900 // used ONLY when the conf carries no slot_ttl row; the conf explains 900
70const HIO_POOL_NONE: i64 = 0 - 1 // every slot held by a LIVE holder -> DEFER
71const HIO_POOL_IO: i64 = 0 - 2 // every slot attempt failed with io (lease root unwritable) -> UNOBSERVABLE, never a stall

functions

73func hio_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
74func hio_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } return p }
75func hio_catn(d: *u8, o: i64, v: i64) -> i64 { let t: *u8 = sys_mmap(28); var m: i64 = v; var p: i64 = o; if m < 0 { d[p] = 45 as u8; p = p + 1; m = 0 - m } var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { d[p] = t[k-1-i]; p = p + 1; i = i + 1 } return p }
76func hio_eol(q: *u8, i: i64, n: i64) -> i64 { var e: i64 = i; var s: i64 = 1; while s == 1 { if e >= n { s = 0 } else { if q[e] == (HIO_NL as u8) { s = 0 } else { e = e + 1 } } } return e }
called by 1: hio_conf_read
77func hio_keyis(q: *u8, s: i64, e: i64, key: *u8) -> i64
called by 1: hio_conf_read
84func hio_atoi(q: *u8, s: i64, e: i64) -> i64
called by 1: hio_conf_read
90func hio_slot(names: *u8, i: i64) -> *u8 { return ((names as i64) + i * HIO_NAMEW) as *u8 }
95func hio_conf_read(path: *u8, cfg: *i64, names: *u8) -> i64
138func hio_decide(running: i64, width: i64, storm_budget: i64) -> i64
called by 1: main
148func hio_width(cfg: *i64) -> i64
165func hio_running(cfg: *i64, names: *u8) -> i64
175func hio_storm_budget() -> i64
190func hio_pid_alive(pid: i64) -> i64
203func hio_owner_pid(owner: *u8) -> i64
called by 1: hio_pool_acquire
221func hio_owner(out: *u8) -> i64
227func hio_slot_name(i: i64, out: *u8) -> i64
234func hio_root(root: *u8) -> i64
249func hio_lease_root(root: *u8, out: *u8) -> i64
257func hio_pool_acquire(lroot: *u8, width: i64, ttl: i64) -> i64
288func hio_pool_release(lroot: *u8, slot: i64) -> i64
298func hio_decide_pool(width: i64, storm_budget: i64, slot: i64) -> i64
309func hio_admit_conf_root(root: *u8, path: *u8, out: *i64) -> i64
327func hio_admit_conf(path: *u8, out: *i64) -> i64 { return hio_admit_conf_root(HIO_ROOT_A, path, out) }
328func hio_admit(out: *i64) -> i64
341func hio_release(out: *i64) -> i64
352func hio_announce(fd: i64, verdict: i64, out: *i64) -> i64
370func hio_ratchet_next(floor: i64, adopters: i64) -> i64
called by 1: main