Expand description
Keep resident memory close to what the process actually uses.
glibc keeps freed heap pages in its arenas, so after a burst (a long history loaded, a big request built, a turn finished) the resident set stays high even though the program no longer needs the memory. This module limits that and gives the pages back:
configure_system_allocatorcaps the number of malloc arenas and pins the mmap threshold, so large transient buffers are mmapped and returned to the OS as soon as they are freed (glibc otherwise raises the threshold dynamically and keeps them in the heap).release_retained_heaprunsmalloc_trim(0).RetentionWatchtrims when memory that is resident but not allocated grows past the lowest level seen since the last trim.
Everything is a no-op outside Linux/glibc.
Structs§
- Retention
Watch - Trims when retained memory grows
thresholdbytes past a baseline. The baseline is the level measured after the last trim and only moves down between trims: glibc’s free-chunk counters do not drop after a trim, so a plain threshold would fire again on every check.
Constants§
- DEFAULT_
ARENA_ MAX - Default cap on glibc malloc arenas (glibc’s own default is 8 × cores).
- DEFAULT_
MMAP_ THRESHOLD - Default mmap threshold: allocations at least this big bypass the arenas.
Functions§
- configure_
system_ allocator - Apply the allocator limits once at startup.
WHYCODES_GLIBC_ARENA_MAXandWHYCODES_GLIBC_MMAP_THRESHOLDoverride the defaults;0keeps glibc’s own behaviour for that setting. - parse_
rss_ anon RssAnon:from a/proc/<pid>/statusbody, in bytes.- release_
retained_ heap - Return freed-but-retained heap pages to the OS.
- release_
retained_ heap_ debounced release_retained_heapunless one already ran withinmin_interval. Returns whether it ran.- retained_
bytes - Resident anonymous memory not held by live allocations: what a trim could
give back.
Nonewhere it cannot be measured. - rss_
anon_ bytes RssAnonof this process in bytes (Linux).