Remediation Hub (9)
Enable jemalloc LD_PRELOAD in Synapse Docker & Systemd
Injecting libjemalloc.so.2 cuts post-burst Python Synapse memory retention by 30-45% with zero application code changes.
RSS Reduction: -30% to -45% post-burst | Env: SYNAPSE_USE_JEMALLOC
Step 1: Set LD_PRELOAD or Official Docker Flag
On official matrixdotorg/synapse images, verify whether libjemalloc.so.2 is pre-installed and inject LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 (or /usr/lib/aarch64-linux-gnu/libjemalloc.so.2 on ARM64) inside docker-compose.yml environment.
Step 2: Tune MALLOC_CONF Background Decay
Pair LD_PRELOAD with MALLOC_CONF="background_thread:true,dirty_decay_ms:5000,muzzy_decay_ms:5000" so freed Python arena pages return to the Linux kernel within five seconds instead of sitting idle.
Measured Thresholds & Configuration
| Runtime Setup | Env Variable | Kernel Page Return |
|---|---|---|
| Docker Official Image (x86_64) | LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 | 5s decay with MALLOC_CONF |
| Debian / Ubuntu Systemd Unit | Environment="LD_PRELOAD=..." | Immediate drop in peak RSS |
| Continuwuity Rust Binary | Built-in Rust allocator / jemalloc | Native zero-config return |