code wiki / (root) / nx_ioae_wiring_v2_20260907.nx

nx_ioae_wiring_v2_20260907.nx source

↩ module page · 130 lines · 6260 B

1// TEST ONLY: actual hio budget-entry body; census, width, pool and root boundaries replaced. 2// This verifies budget plumbing and root arguments, not /proc accuracy or lease durability. 3import "nx_ioae_lib_test_20260907.nx" 4const HIO_ADMIT: i64 = 1 5const HIO_DEFER: i64 = 0 6const HIO_UNOBSERVABLE: i64 = 0-1 7const HIO_C_BYTES: i64 = 64 8const HIO_MAXP: i64 = 32 9const HIO_NAMEW: i64 = 64 10const HIO_PATHCAP: i64 = 256 11const HIO_C_TTL: i64 = 7 12const HIO_TTL_DEFAULT: i64 = 900 13const HIO_O_RUNNING: i64 = 0 14const HIO_O_WIDTH: i64 = 1 15const HIO_O_STORM: i64 = 2 16const HIO_O_SLOT: i64 = 3 17const HIO_POOL_NONE: i64 = 0-1 18const HIO_POOL_IO: i64 = 0-2 19const HIO_CONF_LEAF: *u8 = "heavyio.conf" 20const HIO_ADMISSION_BYTES: i64 = HIO_C_BYTES + HIO_MAXP*HIO_NAMEW + HIO_PATHCAP 21const HIO_BUDGET_PATH_BYTES: i64 = HIO_PATHCAP*2 22static eg_live_work: i64 23static eg_allocations: i64 24static eg_releases: i64 25static eg_lifecycle_error: i64 26func hio_admission_alloc() -> *u8 { 27 if eg_live_work != 0 { eg_lifecycle_error = 1 } 28 let p: *u8 = sys_mmap(HIO_ADMISSION_BYTES) 29 eg_live_work = p as i64; eg_allocations = eg_allocations+1; return p 30} 31func hio_admission_free(p: *u8) -> i64 { 32 if eg_live_work != (p as i64) { eg_lifecycle_error = 1 } 33 eg_live_work = 0; eg_releases = eg_releases+1 34 let rc: i64 = sys_munmap(p,HIO_ADMISSION_BYTES) 35 if rc != 0 { eg_lifecycle_error = 1 }; return rc 36} 37static eg_pool_calls: i64 38static eg_pool_result: i64 39static eg_width: i64 40static eg_root_ok: i64 41static eg_path_ok: i64 42static eg_root_mode: i64 43static eg_instant_calls: i64 44func hio_storm_budget() -> i64 { eg_instant_calls = eg_instant_calls+1; return 0 } 45func hio_conf_read(path: *u8, cfg: *i64, names: *u8) -> i64 { 46 eg_path_ok = ioae_eqspan(path,0,ioa_slen(path),"../knowledge/heavyio.conf" as *u8) 47 cfg[HIO_C_TTL] = 900; return 1 48} 49func hio_running(cfg: *i64, names: *u8) -> i64 { return 0 } 50func hio_width(cfg: *i64) -> i64 { return eg_width } 51func hio_lease_root(root: *u8, out: *u8) -> i64 { return ioae_join(root,"lease/" as *u8,out) } 52func hio_pool_acquire(root: *u8, width: i64, ttl: i64) -> i64 { 53 eg_pool_calls = eg_pool_calls+1 54 eg_root_ok = ioae_eqspan(root,0,ioa_slen(root),"../knowledge/lease/" as *u8) 55 return eg_pool_result 56} 57func hio_root(root: *u8) -> i64 { 58 if eg_root_mode == 0 { return 0 } 59 ioae_join("../knowledge/" as *u8,"" as *u8,root); return 2 60} 61func hio_decide_pool(width: i64, storm_budget: i64, slot: i64) -> i64 { 62 if width < 0 { return HIO_UNOBSERVABLE } 63 if storm_budget < 0 { return HIO_UNOBSERVABLE } 64 if storm_budget == 0 { return HIO_DEFER } 65 if slot == HIO_POOL_IO { return HIO_UNOBSERVABLE } 66 if slot < 0 { return HIO_DEFER } 67 return HIO_ADMIT 68} 69func hio_admit_conf_root_budget(root: *u8, path: *u8, selected_budget: i64, out: *i64) -> i64 { 70 let work: *u8 = hio_admission_alloc() 71 let cfg: *i64 = work as *i64 72 let names: *u8 = ((work as i64)+HIO_C_BYTES) as *u8 73 let lroot: *u8 = ((work as i64)+HIO_C_BYTES+HIO_MAXP*HIO_NAMEW) as *u8 74 out[HIO_O_RUNNING] = 0-1; out[HIO_O_WIDTH] = 0-1 75 out[HIO_O_STORM] = selected_budget; out[HIO_O_SLOT] = 0-1 76 var rc: i64 = HIO_UNOBSERVABLE 77 if hio_conf_read(path,cfg,names) == 1 { 78 out[HIO_O_RUNNING] = hio_running(cfg,names) 79 out[HIO_O_WIDTH] = hio_width(cfg) 80 if out[HIO_O_WIDTH] >= 0 { if selected_budget >= 0 { 81 if selected_budget == 0 { rc = HIO_DEFER } else { 82 var ttl: i64 = cfg[HIO_C_TTL] 83 if ttl < 0 { ttl = HIO_TTL_DEFAULT } 84 hio_lease_root(root,lroot) 85 out[HIO_O_SLOT] = hio_pool_acquire(lroot,out[HIO_O_WIDTH],ttl) 86 rc = hio_decide_pool(out[HIO_O_WIDTH],selected_budget,out[HIO_O_SLOT]) 87 } 88 } } 89 } 90 // The held lease is represented by out[slot]; it does not depend on temporary workspace bytes. 91 hio_admission_free(work) 92 return rc 93} 94func hio_admit_budget(selected_budget: i64, out: *i64) -> i64 { 95 let root: *u8 = sys_mmap(HIO_BUDGET_PATH_BYTES) 96 if hio_root(root) == 0 { 97 out[HIO_O_RUNNING] = 0 - 1; out[HIO_O_WIDTH] = 0 - 1 98 out[HIO_O_STORM] = selected_budget; out[HIO_O_SLOT] = 0 - 1 99 sys_munmap(root,HIO_BUDGET_PATH_BYTES); return HIO_UNOBSERVABLE 100 } 101 let path: *u8 = ((root as i64)+HIO_PATHCAP) as *u8 102 let n: i64 = ioae_join(root,HIO_CONF_LEAF,path) 103 var rc: i64 = HIO_UNOBSERVABLE 104 if n >= 0 { rc = hio_admit_conf_root_budget(root,path,selected_budget,out) } 105 sys_munmap(root,HIO_BUDGET_PATH_BYTES) 106 return rc 107} 108 109const BA_EXIT_DENY: i64 = 3 110const BA_EXIT_QUEUE: i64 = 4 111const BA_HARD_FACTOR: i64 = 2 112func ba_verdict(avail_mb: i64, floor_mb: i64, load1: i64, max_load: i64, procs_run: i64, ncpu: i64, procs_blk: i64, blocked_max: i64) -> i64 { 113 if avail_mb < floor_mb { return BA_EXIT_DENY } 114 // I/O-STORM WITNESS (2026-08-17): a run-queue's worth of processes stuck in uninterruptible I/O means 115 // the ARRAY is the bottleneck, and a compiler fork (549KB + arena + thousands of source reads) can only 116 // deepen it. Checked BEFORE the load ceiling because both wired lanes pass an unreachable max_centiload 117 // (runner 1000000, mgmt 100000) -- placed after it, the disabled ceiling would GRANT first and this 118 // witness could never testify on the lanes that actually run. procs_blk < 0 = unreadable -> ABSTAIN. 119 if procs_blk >= 0 { if blocked_max > 0 { if procs_blk >= blocked_max { return BA_EXIT_QUEUE } } } 120 if load1 <= max_load { return 0 } 121 // STORM CEILING (2026-08-17): the run-queue excuse below is only valid for MILD overshoot. load1 122 // counts R and D, so an I/O or swap storm reads as huge load with a near-empty run queue -- exactly 123 // the shape the unbounded excuse kept admitting (measured 2026-08-16: load 4.4 x ncpu, procs_running=2, 124 // workers in D-state on a swapping RAID -> GRANT). Above BA_HARD_FACTOR x max_load the box is 125 // pathologically loaded SOMEWHERE, and a compiler fork (549KB + arena + thousands of source reads) 126 // can only deepen the pileup: QUEUE, regardless of what the run queue says. 127 if load1 > max_load * BA_HARD_FACTOR { return BA_EXIT_QUEUE } 128 if procs_run >= 0 { if procs_run < ncpu { return 0 } } 129 return BA_EXIT_QUEUE 130}