Skip to content

Set MALLOC_ARENA_MAX=2 for bbb-web and bbb-apps-akka - #25309

Merged
TiagoJacobs merged 1 commit into
bigbluebutton:v3.0.x-developfrom
imdt-claudiop:malloc-arena-max-jvm
Jun 22, 2026
Merged

TiagoJacobs merged 1 commit into
bigbluebutton:v3.0.x-developfrom
imdt-claudiop:malloc-arena-max-jvm

Conversation

@imdt-claudiop

Copy link
Copy Markdown
Contributor

What does this PR do?

Ships MALLOC_ARENA_MAX=2 as a systemd drop-in via the bbb-config package for the two JVM services: bbb-web and bbb-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.conf

Each contains:

[Service]
Environment="MALLOC_ARENA_MAX=2"

The build.sh change 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 vCPU on 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-web and bbb-apps-akka are 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):

Host Treatment RSS p95 pre RSS p95 post Delta RSS p95
230001 none (control) 1450 MB 1387 MB -63 MB
230002 NMT only (control) 1625 MB 1588 MB -37 MB
230004 MALLOC_ARENA_MAX=2 1730 MB 1098 MB -632 MB

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 ships MALLOC_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), and bbb-livekit (Go) all use their own allocators, so glibc arenas are not the dominant off-heap source for these.

How to test

  1. Build the bbb-config package from this branch.
  2. Install it on a BBB server.
  3. Verify the drop-in files exist:
    cat /usr/lib/systemd/system/bbb-web.service.d/malloc-arena.conf
    cat /usr/lib/systemd/system/bbb-apps-akka.service.d/malloc-arena.conf
    
  4. Reload systemd and restart the services:
    systemctl daemon-reload
    systemctl restart bbb-web bbb-apps-akka
    
  5. Verify the env var is set in the process:
    systemctl show bbb-web -p Environment
    
    Expected output includes MALLOC_ARENA_MAX=2.
  6. (Optional) Monitor RSS over 24 h and compare against a control host without the change.

Override: Operators who need to restore stock behavior can drop a higher-priority file in /etc/systemd/system/bbb-web.service.d/00-override.conf with Environment="MALLOC_ARENA_MAX=0" (0 = unlimited, glibc default).

More

  • Added/updated documentation — not applicable (package-level default, documented in commit message and PR body)

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_MAX is 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 in bbb-web or bbb-apps-akka. 36 h of production data shows zero latency impact.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3d025754-c153-404a-bb79-b17e6a0bcc0e

📥 Commits

Reviewing files that changed from the base of the PR and between d181b54 and ffc71ae.

📒 Files selected for processing (2)
  • build/packages-template/bbb-config/build.sh
  • build/packages-template/bbb-config/malloc-arena.conf
✅ Files skipped from review due to trivial changes (1)
  • build/packages-template/bbb-config/malloc-arena.conf
🚧 Files skipped from review as they are similar to previous changes (1)
  • build/packages-template/bbb-config/build.sh

Walkthrough

A new systemd drop-in configuration file malloc-arena.conf is added under build/packages-template/bbb-config/. It contains a [Service] section with Environment="MALLOC_ARENA_MAX=2". The build.sh packaging script is updated with a loop over the bbb-web and bbb-apps-akka service names; for each, it creates the corresponding staging/usr/lib/systemd/system/<service>.service.d/ directory and copies malloc-arena.conf into it, embedding the drop-in into both service units during package build.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: setting MALLOC_ARENA_MAX=2 for the two specified JVM services.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the motivation, measured results, testing procedures, and override mechanism.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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]>
@imdt-claudiop
imdt-claudiop force-pushed the malloc-arena-max-jvm branch from d181b54 to ffc71ae Compare June 22, 2026 21:10
@imdt-claudiop
imdt-claudiop marked this pull request as draft June 22, 2026 21:13
@TiagoJacobs

Copy link
Copy Markdown
Member

@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.

@imdt-claudiop

Copy link
Copy Markdown
Contributor Author

On it — bringing up a BBB environment to capture before/after RSS evidence. Will post the results here shortly.

@imdt-claudiop

Copy link
Copy Markdown
Contributor Author

Runtime evidence: MALLOC_ARENA_MAX=2 effect on bbb-web

Measured on a BBB 3.0 container (16 vCPU, 32 GB RAM, imdt/bigbluebutton:3.0.x-develop), 90 seconds after each restart. The systemd drop-in was applied at /etc/systemd/system/bbb-web.service.d/malloc-arena.conf and the service restarted with systemctl daemon-reload && systemctl restart bbb-web.

Before (glibc default: 8 x 16 vCPU = 128 arenas)

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

  1. The env var reaches the Java process. /proc/<pid>/environ shows MALLOC_ARENA_MAX=2 after the drop-in is applied and the service restarted. The systemd Environment= directive sets it in the process environment before the JVM starts.

  2. 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).

  3. 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.

  4. 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.

@TiagoJacobs

Copy link
Copy Markdown
Member

Try what happens when you increase the number to 1024 arenas

@imdt-claudiop

Copy link
Copy Markdown
Contributor Author

MALLOC_ARENA_MAX=1024 measurement

Same methodology as the previous comment: BBB 3.0 container, 16 vCPU, 90s after restart.

Three-way comparison

Config RSS VSZ VmPeak Threads MALLOC_ARENA_MAX in environ
Default (8 x 16 = 128) 863,916 kB (844 MB) 9,413,156 kB (9,195 MB) 9,413,156 kB 104 not set
MALLOC_ARENA_MAX=2 800,216 kB (781 MB) 2,431,520 kB (2,376 MB) 2,557,588 kB 99 2
MALLOC_ARENA_MAX=1024 841,728 kB (822 MB) 9,275,928 kB (9,058 MB) 9,275,928 kB 98 1024

Analysis

1024 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:

Comparison RSS delta VSZ delta
1024 vs default (128) -22 MB (noise) -137 MB (noise)
2 vs default (128) -63 MB -6,819 MB
2 vs 1024 -41 MB -6,682 MB

The VSZ gap (6.8 GB) between =2 and both higher values is the key indicator: each arena reserves up to 64 MB of virtual address space. With 128+ arenas, that is 8+ GB of address space that gradually becomes resident RSS as the process runs. With 2 arenas, the ceiling is ~128 MB.

@github-actions

Copy link
Copy Markdown

🚨 Automated tests failed

@TiagoJacobs
TiagoJacobs marked this pull request as ready for review June 22, 2026 22:15
@TiagoJacobs
TiagoJacobs merged commit 8c416f1 into bigbluebutton:v3.0.x-develop Jun 22, 2026
32 of 33 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@antobinary antobinary added this to the Release 3.0 milestone Jul 6, 2026
ramonlsouza pushed a commit that referenced this pull request Oct 6, 2026
#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants