SIGN IN SIGN UP

fix(agent): cap wazuh-agentd's malloc arena count

The HTTPS transport runs several allocating threads, and glibc answers
that by giving each one its own 64 MiB arena. Most of that is reserved
address space rather than committed memory, and it is what takes the
process past 690 MB of virtual size, but each arena also carries its own
top chunk and bins, which is resident memory never handed back.

main() now caps the count with mallopt(M_ARENA_MAX, 2). It has to run
before any thread is created, since extra arenas are only spawned when a
thread finds every existing one locked; allocations already made on this
thread came from the main arena and are unaffected. Two rather than one
leaves a second arena so the transport's threads do not all serialise on
a single allocator lock.

Measured on two packages differing only in this change, alternating runs
of twelve minutes each: 1.05 MB less private memory and virtual size down
from 676 MB to 166 MB. The virtual figure is reservation rather than
consumption, so it frees no usable memory, but it removes a number that
reads as alarming in monitoring.

Compiled in only for glibc.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
N
Nicolai Romero committed
f6fb2cd64b8a74f00c81ec9fb0db91652dcd91c1
Parent: 93a1821