code wiki / (root) / nx_resgov_core.nx

nx_resgov_core.nx

buildroot/runtime/nx_resgov_core.nx

8871 B171 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_resgov_core.nx -- PURE DECISION CORE of the unified resource-governance regime (nx_resgov). WHY THIS SUPERSEDES THE VSZ WATCHDOG (operator 2026-08-04: "resource management should be proactive, intelligent and SOTA, not watching the hardware get hammered"; debt 1785863639). The incumbent breaker had three structural defects, each fixed here BY CONSTRUCTION: 1. WRONG INSTRUMENT. It thresholded on VSZ. VSZ is reserved ADDRESS SPACE -- nx_wiki_gw sits at 47.4GB VSZ on 355MB resident and is perfectly healthy; a naive VSZ rule kills it. The pressure that actually degraded the estate on 08-04 was RESIDENT memory + SWAP. We meter VmRSS + VmSwap. 2. COVERAGE BY ALLOW-LIST. Rows named 7 remembered processes; every grower nobody listed was invisible (a transient 4GB nx_web_shard_co appeared and exited mid-session -- the population is dynamic and unlistable by hand). Here the policy is INVERTED: a DEFAULT cap covers EVERY process and exemptions are the explicit, auditable rows. ★A DETECTOR'S COVERAGE IS TWO SETS -- WHAT IT MATCHES AND WHERE IT LOOKS; a default-deny breaker has no blind names. 3. REACTIVE ONLY. It fired after a ceiling was crossed -- i.e. after the hardware was already being hammered. Here the primary signal is PREDICTIVE: growth VELOCITY from persisted samples gives an ETA to the ceiling, and the ladder engages while headroom still exists. ★ESCALATION, NEVER A BINARY KILL (rule 14, graceful degradation). Levels: OK -> WATCH (measured, logged) -> WARN (predicted to breach inside the horizon) -> RENICE (deprioritise, let it finish) -> TERM (polite, guard respawns fresh) -> KILL (last resort). A breaker whose only verb is SIGKILL cannot be trusted to run every minute, so it gets disabled -- which is exactly how the incumbent came to be unwired. ★SYSTEM PRESSURE GATES ACTION. A 3GB process on an idle box is not a problem; the same process at 95% memory is. Every destructive level requires BOTH a per-process finding AND real system scarcity, so a healthy fleet is never disturbed. FAIL-SAFE BY CONSTRUCTION: unknown/unreadable measurement -> level OK (never act on ignorance); exempt -> capped at OK; cap<1 -> inert row; cooldown suppresses storms; the CLI never touches pid<=300 or itself. Decisions live here (gate-locked, pure); the /proc walk, state and signals live in the CLI. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_resgov_core.nx nx_resgov.nx nx_resgov_gate.nx

imports: nx_syscalls.nx

imported by: nx_resgov.nxnx_resgov_gate.nx

structs

none

consts

32const RG_MAGIC_1048576: i64 = 1048576
35const RG_OK: i64 = 0
36const RG_WATCH: i64 = 1
37const RG_WARN: i64 = 2
38const RG_RENICE: i64 = 3
39const RG_TERM: i64 = 4
40const RG_KILL: i64 = 5

functions

44func rg_headroom_permil(avail_kb: i64, total_kb: i64) -> i64
called by 2: mainmain
50func rg_swap_permil(used_kb: i64, total_kb: i64) -> i64
called by 1: main
57func rg_system_pressured(headroom_permil: i64, swap_permil: i64, head_floor: i64, swap_ceil: i64) -> i64
called by 2: mainmain
67func rg_velocity_kb_s(prev_kb: i64, prev_t: i64, now_kb: i64, now_t: i64) -> i64
called by 2: mainmain
76func rg_eta_s(now_kb: i64, ceil_kb: i64, vel_kb_s: i64) -> i64
called by 3: mainrg_levelmain
85func rg_footprint_kb(rss_kb: i64, swap_kb: i64) -> i64
called by 3: mainrg_levelmain
100func rg_level(exempt: i64, cap_gb: i64, rss_kb: i64, swap_kb: i64, vel_kb_s: i64,
called by 2: mainmain calls 2: rg_footprint_kbrg_eta_s
124func rg_cooldown_ok(last_action_s: i64, now_s: i64, cooldown_s: i64) -> i64
called by 2: mainmain
131func rg_level_name(l: i64) -> *u8
called by 1: main
141func rg_is_destructive(l: i64) -> i64
called by 1: main
149func rg_meminfo_kb(buf: *u8, n: i64, pat: *u8) -> i64
called by 1: main