Skip to main content

Module client_diet

Module client_diet 

Source
Expand description

Client diet (PLAN-phase4 §4): the allocator knobs and purge points that make the thin client’s RssAnon equal its live heap instead of its high-water mark.

  • tune_allocator() — called from main() on the attach path before the runtime or any thread exists: jemalloc background threads off (so none are spawned for the arenas the render/crossterm threads touch; 8 → 4 threads), dirty_decay_ms=0/muzzy_decay_ms=0 (a freed run goes back to the OS on the next decay tick instead of ≤ 10 s later).

  • purge_arenas(stage) — explicit arena.<all>.purge + a ladder line.

  • IdlePurge — the run_loop arm: purge N s after the client goes idle (turn/compaction finished), plus the syntect idle-eviction hook.

  • PR_SET_THP_DISABLE first: with THP=always (bella, most desktops) every touched thread stack, the .bss and each arena chunk is a 2 MiB page — the A1 ladder showed +4 MB at render_thread for 128 KB of allocations. SYNAPS_CLIENT_THP=1 keeps huge pages.

Flags: SYNAPS_CLIENT_MALLOC=off / SYNAPS_CLIENT_ALLOC=default skip the mallctls; SYNAPS_CLIENT_TCACHE=0 disables the main thread’s tcache; SYNAPS_CLIENT_PURGE_SECS / SYNAPS_CLIENT_PURGE_IDLE_SECS (default 10, 0 = never); SYNAPS_MEMPROF_PURGE=1 purges on every idle immediately.

Structs§

IdlePurge
The run_loop idle arm’s state machine. Busy = streaming or compacting. On the busy→idle edge the first fire is scheduled delay later (ladder idle+N → purge → purged); afterwards every [IDLE_TICK] while still idle (syntect eviction + a silent purge). Purging is Socket-only; the eviction check runs in both modes (same code, same render output).

Functions§

allocator_tuning_disabled
Mallctls skipped? (SYNAPS_CLIENT_MALLOC=off or SYNAPS_CLIENT_ALLOC=default).
purge_arenas
arena.<all>.purge and one ladder line at stage.
purge_delay
Idle purge delay: SYNAPS_CLIENT_PURGE_SECS (alias SYNAPS_CLIENT_PURGE_IDLE_SECS), default 10; None = disabled (0). SYNAPS_MEMPROF_PURGE=1 → immediate.
tune_allocator
§4.1–4.3 in order, each result recorded on the alloc ladder line; never fatal (risk #9). Must run before any thread is spawned.