Skip to main content

Module memstat

Module memstat 

Source
Expand description

Process memory instrumentation (§3.7): the numbers mem.sh reads from /proc, available in-process and via synaps status --memory — no root, no smem.

Linux only. Every entry point degrades to Unsupported / zeroed fields on other platforms so callers never need their own cfg.

Structs§

MemTotals
Totals over a set of ProcMem rows.
ProcMem
One process’ memory, straight from smaps_rollup + status.
SelfMem
In-process snapshot: kernel view + jemalloc’s own accounting (zeros when the build does not link jemalloc-ctl).

Enums§

ProcRole
What a process in a session tree is, classified from its cmdline.

Functions§

background_threads_enabled
Current background_thread setting (None without jemalloc).
classify
Classify a process from its cmdline (argv joined by spaces) and, when known, the engine binary’s own name.
disable_thp
prctl(PR_SET_THP_DISABLE) — no transparent huge pages for this process from now on. With THP=always every touched thread stack, the .bss and each jemalloc chunk costs a 2 MiB page; the thin client wants 4 KiB granularity. Inherited by threads created afterwards. Linux only.
ladder
Boot-ladder stage (PLAN-phase4 §7.1): appends one line to the trace file — not tracing (the attach client has no subscriber) and not stderr (it is the TUI). No-op (one atomic load) unless SYNAPS_MEM_TRACE=1.
log_turn_memory
One agent_core::memstat info line (“turn memory”) — called at SessionEvent::Done so synaps.log carries a greppable per-turn memory trace. No-op (one atomic load) unless SYNAPS_MEM_TRACE=1.
mem_trace_enabled
SYNAPS_MEM_TRACE=1 turns on the per-turn memory trace and the broker install log line. Read once; one atomic load per call afterwards.
process
Memory of exactly one process (no descendants).
purge_arenas
Ask jemalloc to purge every arena’s dirty/muzzy pages back to the OS — the manual malloc_trim equivalent. No-op on builds without jemalloc.
redact_cmdline
Scrub credentials out of a space-joined argv before it leaves the process. Redacted: the value of any --flag value / --flag=value whose flag name mentions key/token/secret/password/bearer/auth/credential, any KEY=value env-style arg with such a key, and any bare arg that looks like a key (sk-…, ghp_…, xox…, Bearer …, or ≥ 32 chars of base64/hex with no path separator).
self_snapshot
Kernel + allocator view of the calling process. Never fails; fields are zero where unavailable.
set_background_threads
background_thread on/off. Turning it off joins every jemalloc_bg_thd (PLAN-phase4 §4.1) — call before spawning threads so none are created for the arenas they touch. No-op Ok without jemalloc.
set_decay_ms
Decay times for existing arenas (arena.<ALL>.*_decay_ms) and the default for future ones (arenas.*_decay_ms). 0 = purge a freed run on the next decay tick; -1 = never. §4.2.
set_thread_tcache
thread.tcache.enabled for the calling thread (§4.3 fallback).
thp_disabled
prctl(PR_GET_THP_DISABLE) — is THP already off for this process (inherited across execve, so a re-exec’d client sees Some(true))?
thp_sysfs_always
Kernel THP mode: Some(true) when /sys/kernel/mm/transparent_hugepage/enabled is [always], Some(false) for [madvise]/[never], None when unreadable (non-Linux, no sysfs).
tree
Walk pid and every descendant (via /proc/*/stat ppid), reading smaps_rollup and status for each. Root first, then children in discovery order. Processes that vanish mid-walk are skipped.

Type Aliases§

MallctlResult
Outcome of one mallctl write, for the ladder line (never fatal).