Repository navigation
Set MALLOC_ARENA_MAX=2 for bbb-web and bbb-apps-akka - #25309
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughA new systemd drop-in configuration file Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Ship MALLOC_ARENA_MAX=2 as a systemd drop-in via bbb-config for the two JVM services (bbb-web, bbb-apps-akka). glibc's default arena pool (8 x vCPU) causes 500-600MB+ of unnecessary off-heap RSS on bbb-web; clamping to 2 arenas reduces RSS p95 by 37% with zero regressions measured over 36h with three-host A/B controls. Non-JVM services (graphql-server, graphql-middleware, html5, pads, livekit) use their own allocators and are not affected. Operators can override with a higher-priority drop-in in /etc/systemd/system/<service>.service.d/. Co-Authored-By: Tiago Jacobs <[email protected]>
d181b54 to
ffc71ae
Compare
|
@imdt-claudiop - can you please send an evidence that applying this change actually causes an effect on the java? I think it does, I just want to have this evidence documented here. |
|
On it — bringing up a BBB environment to capture before/after RSS evidence. Will post the results here shortly. |
Runtime evidence:
|
| Metric | Value |
|---|---|
| RSS | 863,916 kB (844 MB) |
| VSZ | 9,413,156 kB (9,195 MB) |
| VmPeak | 9,413,156 kB |
| Threads | 104 |
MALLOC_ARENA_MAX |
not set (glibc default) |
/proc/<pid>/environ check: MALLOC_ARENA_MAX absent.
After (MALLOC_ARENA_MAX=2)
| Metric | Value |
|---|---|
| RSS | 800,216 kB (781 MB) |
| VSZ | 2,431,520 kB (2,376 MB) |
| VmPeak | 2,557,588 kB |
| Threads | 99 |
MALLOC_ARENA_MAX |
2 |
/proc/<pid>/environ check: MALLOC_ARENA_MAX=2 confirmed present.
Delta
| Metric | Before | After | Delta |
|---|---|---|---|
| RSS | 844 MB | 781 MB | -63 MB (-7.5%) |
| VSZ | 9,195 MB | 2,376 MB | -6,819 MB (-74%) |
| Threads | 104 | 99 | -5 (startup variance) |
Key observations
-
The env var reaches the Java process.
/proc/<pid>/environshowsMALLOC_ARENA_MAX=2after the drop-in is applied and the service restarted. The systemdEnvironment=directive sets it in the process environment before the JVM starts. -
Immediate RSS reduction of ~63 MB after just 90 seconds of uptime. The 36-hour A/B data in the PR body shows this grows to 632 MB as more arena pages are faulted in over time (glibc rarely returns them to the OS).
-
Virtual address space (VSZ) dropped by 6.8 GB (9.2 GB to 2.4 GB). With 128 default arenas, each holding up to 64 MB of virtual address space, the pool had room to grow into ~8 GB of resident memory. With 2 arenas, the ceiling is drastically lower. This VSZ delta is the leading indicator of the RSS savings that accumulate over time.
-
No thread-count regression (104 to 99 is within normal startup variation).
Why the RSS delta is smaller than the 36h data
Arena overhead accumulates as threads touch different arenas and pages become resident. After 90 seconds, only a fraction of the 128 default arenas have been touched. Over 36 hours of production load, all arenas accumulate resident pages — that is where the full 632 MB savings materializes (as measured in the PR body). The 6.8 GB VSZ reduction shows the total virtual space the 128 arenas could have grown into.
|
Try what happens when you increase the number to 1024 arenas |
MALLOC_ARENA_MAX=1024 measurementSame methodology as the previous comment: BBB 3.0 container, 16 vCPU, 90s after restart. Three-way comparison
Analysis1024 arenas behaves like the default (128). RSS (822 MB) and VSZ (9,058 MB) are within noise of the default measurement (844 MB / 9,195 MB). This makes sense: glibc creates arenas on demand, not upfront. With ~100 threads, the default cap of 128 is already enough to give (almost) every thread its own arena, so raising the cap to 1024 changes nothing in practice. The savings come from clamping DOWN, not the absolute number. The difference between 128 and 1024 is negligible because neither is a binding constraint at ~100 threads. The difference between 128 and 2 is dramatic because 2 forces all threads to share 2 mutexes instead of spreading across 128 arenas:
The VSZ gap (6.8 GB) between |
🚨 Automated tests failed |
8c416f1
into
bigbluebutton:v3.0.x-develop
|
#25309 delivered MALLOC_ARENA_MAX=2 to bbb-web and bbb-apps-akka through drop-ins shipped by bbb-config (/usr/lib/systemd/system/<service>.service.d/malloc-arena.conf). Both services are built from this repository and ship their own unit, so set the variable in those units and stop bbb-config from shipping files into the unit directories of two other packages. The value and the two services covered are unchanged. This also makes the setting overridable by any drop-in. systemd merges drop-ins from /etc and /usr/lib in file name order, so an operator drop-in sorting before "malloc-arena.conf" was outranked by the packaged one; that includes the 00-override.conf opt-out suggested in #25309, which had no effect. A setting in the unit itself is parsed before every drop-in. The EnvironmentFile entries (/etc/bigbluebutton/bbb-web.env, /etc/default/bbb-apps-akka) override it as they did before. On upgrade bbb-config no longer contains the two malloc-arena.conf files, so dpkg removes them. No file changes owner between packages, so no Replaces/Breaks is needed. A new bbb-config next to an older bbb-web or bbb-apps-akka leaves that service without the variable until it is upgraded as well.



What does this PR do?
Ships
MALLOC_ARENA_MAX=2as a systemd drop-in via thebbb-configpackage for the two JVM services:bbb-webandbbb-apps-akka.The drop-in files are installed to:
/usr/lib/systemd/system/bbb-web.service.d/malloc-arena.conf/usr/lib/systemd/system/bbb-apps-akka.service.d/malloc-arena.confEach contains:
The
build.shchange follows the existing pattern already used for freeswitch, nginx, redis-server, and postgresql drop-ins in the same file.Motivation
glibc's malloc allocates a pool of independent arenas (default:
8 x vCPUon 64-bit Linux). Each arena can hold up to 64 MB of virtual address space. Once pages are faulted in, glibc rarely returns them to the OS, so a long-running multi-threaded process accumulates elevated RSS that doesn't correspond to any live working set.JVM services like
bbb-webandbbb-apps-akkaare not malloc-hot (almost all allocations are JVM-heap-managed via G1), so clamping the arena pool to 2 trades zero measurable latency for substantial RSS reduction.Measured results (bbb-web, 36 h A/B with three-host controls, BBB 3.0.29, 8 vCPU / 32 GB):
The 30-60 MB shift on the two control hosts is natural day-to-day load variation. The treatment host shifted by ~10x the baseline, net -569 MB vs control 1, -595 MB vs control 2.
Heap, metaspace, GC behavior, and thread count were unchanged across the cutover. The full 632 MB delta is glibc-arena off-heap overhead.
Projected for bbb-apps-akka: ~150-250 MB off-heap savings (projected from its lower thread count of ~140 vs ~230 on bbb-web; not yet directly measured).
Industry precedent: Cassandra ships
MALLOC_ARENA_MAX=4, Elasticsearch shipsMALLOC_ARENA_MAX=4. This is standard practice for multi-threaded JVM workloads on glibc.Non-JVM services are not affected:
bbb-graphql-server(Haskell),bbb-graphql-middleware(Go),bbb-html5(Node),bbb-pads(Node), andbbb-livekit(Go) all use their own allocators, so glibc arenas are not the dominant off-heap source for these.How to test
bbb-configpackage from this branch.MALLOC_ARENA_MAX=2.Override: Operators who need to restore stock behavior can drop a higher-priority file in
/etc/systemd/system/bbb-web.service.d/00-override.confwithEnvironment="MALLOC_ARENA_MAX=0"(0 = unlimited, glibc default).More
Spec-independent: The absolute MB saved scales with vCPU count (default arena pool =
8 x vCPU), but the direction and risk profile are the same on every BBB host. The clamp helps everyone; it helps bigger boxes more.Risk profile:
MALLOC_ARENA_MAXis a glibc knob, silently ignored under musl (Alpine). BBB officially ships on Ubuntu (glibc), so this is moot for the upstream default. No JNI hotpaths exist inbbb-weborbbb-apps-akka. 36 h of production data shows zero latency impact.