pub fn cap_malloc_arenas()Expand description
Cap glibc’s per-thread malloc arenas at process start to bound RSS on many-core hosts.
glibc defaults to 8 × ncpu arenas on 64-bit. Under a many-threaded proxy doing bursty
per-request allocations, freed memory lingers in each thread’s arena instead of returning to the
OS, inflating RSS (measured ~2.5× at 1 MB bodies × 50 conns — docs/servey body-tax). This is a
defensive complement to the real fix (not buffering a body no filter reads); routes that
legitimately buffer still allocate, and this bounds their arena fragmentation.
M_ARENA_MAX only gates creation of NEW arenas and never reclaims existing ones, so this MUST
run before the runtime spawns its worker threads (call it first in main). Default cap 4 — a
portable, contention-safe value used across multithreaded services, chosen over the value that
minimised RSS on one host (1) precisely because Plecto is self-hosted on varied machines.
Override with PLECTO_MALLOC_ARENA_MAX (0 leaves glibc’s default in place). No-op off glibc.