Repository navigation
Description
Introduction
While investigating the scaling of a large multithreaded application running on Linux on an AMD EPYC 9655 processor (96 cores, 192 SMTs), I realised that a measurable drop in performance comes from the increase in TLB shootdowns.
Comparing the total throughput of 12 processes (8 cores each, one per CCD/L3 cache) with a single process spanning the full CPU, the latter generates about 1.5× more madvise calls, which translate into 18× more TLB shootdown interrupts, and cause a 0.8% drop in performance per core.
As far as I can tell this makes sense: the TLB interrupts need to be propagated to all the cores that are part of the process, so 1.5× madvise calls times 12× cores gives the 18× increase.
To confirm that the TLB interrupts are the cause of the drop I've repeated the measurements with no memory purging (dirty_decay_ms:-1,muzzy_decay_ms:-1).
With these settings the TLB shootdown interrupts almost disappear, and the single process achieves a higher throughput than the total of the 12 separate processes.
The downside is an increase of about 25% in memory usage, since the dirty pages are never returned to the OS.
To try and recover most of the gains from not releasing the memory to the OS, while keeping the memory increase under control, I've directed Claude to implement a second level of caching for the dirty extents, and to release them back to the OS with a configurable decay. Opus 5.5 failed spectacularly, but as far as I can tell Fable 5.2 managed to do a good job.
I didn't find a commonly used name for this second level of caching, so I picked "warrens", because they connect multiple arenas.
Background
The application whose scaling I am trying to optimise is the High Level Trigger (HLT) of the CMS Experiment, at CERN.
It is based on the CMSSW framework, written in c++, and built on oneTBB for parallelism.
The HLT processes in real time the "events" corresponding to the particle collisions that happen inside the detectors, at a rate of roughly 110'000 events per second, on a small computer farm with over 200 nodes and about 30k EPYC Zen 3/Zen 4c cores.
Until now we have been running with N processes in parallel, each running on 16 cores / 32 SMTs. As the newer generations of CPUs are getting bigger and memory is getting more expensive, I am looking into scaling the application's performance to bigger jobs.
There are three classes of scaling issues I'm trying to tackle:
- from a single core to a single CCD (8 cores) and L3 cache complex;
- from a single CCD to a single socket;
- from a single socket to a full machine.
Scaling from 1 to 8 cores is dominated by the drop in clock frequency and the increase in L3 traffic, and there is little I can do about those.
Scaling from 1 CCD to a full socket is dominated by the increase in TLB shootdowns, and it's what this proposal is about.
Scaling from 1 socket to the full machine requires making the framework NUMA aware, and can also benefit from the phycpu arena settings that were recently fixed (#3029).
Motivation
All the measurements below use one socket of a dual EPYC 9655 machine running Linux 6.8, restricted to 95 of its 96 cores (190 SMTs), so one of the 12 processes has 7 cores instead of 8. Every process runs one thread per SMT, and all together they process around 430 events per second.
| 12 processes, one per CCD | 1 process | |
|---|---|---|
| Throughput, default settings (events/s) | 427.9 ± 0.3 | 424.4 ± 0.6 |
madvise calls per event, default settings |
18.2 | 28.3 |
| TLB shootdown interrupts per event, default settings | 375 | 6651 |
| Throughput, no purging (events/s) | 432.5 ± 0.4 | 435.7 ± 0.6 |
| TLB shootdown interrupts per event, no purging | 15 | 146 |
| Peak RSS, default settings (GiB) | 119–125 | 58 |
| Peak RSS, no purging (GiB) | 145 | 72 |
Table 1. 12 processes against a single process on the same 95 cores, with the jemalloc defaults and with no purging; average ± standard deviation of 4 runs. These are earlier measurements than those in the Results, with a shorter job and an older BIOS, so the absolute values of the two sets are slightly different.
With no purging the single process gains 2.7% over its own default, and is 0.7% faster than the 12 processes.
A call-graph profile shows that the difference between the two cases is all in the kernel: it takes 2.95% of the samples with the 12 processes and 4.81% with the single process, while the user-space code and TBB look the same.
All the madvise calls are MADV_DONTNEED from jemalloc. In the single process 88% of them (24.9 out of 28.3 per event) come from the 10 s dirty decay of the regular arenas, mostly for ranges smaller than 64 KiB. The rest come from the large and oversize extents that are purged as soon as they are freed: they are few calls, but most of the purged memory (23 MiB per event in 1.9 calls for the oversize ones). The thread that pays for the system call is whichever thread frees memory at that moment, and all the other threads pay for the interrupt.
I've tried to recover some of the performance tuning the existing settings. A longer dirty_decay_ms up to 150s reduces the shootdowns, but with a limited improvement to the throughput (see Table 2). The HPA with different values of hpa_dirty_mult, and percpu_arena:phycpu, didn't do better than a longer dirty decay at the same memory usage. Fewer arenas would share the dirty memory among more threads, but they also share the arena locks and lead to an increased contention.
The common limitation of these settings is that every arena is independent from the others, and the only way memory gets recycled across arenas is being returned to the OS and being paged back in the process again by a different arena. A shared cache would let an arena reuse the memory no longer needed by another arena while it's still mapped, returning dirty memory to the OS only when none of the arenas has needed it. The arenas themselves are unchanged, and the sharing happens only on the slow paths: the decay of the dirty extents, and allocations that find nothing in the caches of their own arena.
Implementation
Claude prototyped an implementation in a branch on top of dev (at fc22b8bb).
Groups. experimental_warren selects how the arenas are grouped: disabled (default), global (one warren for the process), numa (one per NUMA node) or llc (one per last-level cache). Each arena belongs to one warren, chosen when the arena is created from the cpu of the thread that creates it. Only the automatic arenas with the default extent hooks take part: a manual arena can be destroyed, so its extents never move to other arenas.
From an arena to a warren. When the dirty decay of an arena selects some extents to purge, they are handed to the warren instead. Moving an extent changes only the allocator metadata: there is no system call, no change to the page tables and no TLB shootdown. Guarded and pinned extents are purged as before, and so is an explicit arena.<i>.purge. Inside a warren the extents coalesce with their neighbours in the same warren, and never with the extents of an arena or of another warren.
From a warren to an arena. When an allocation finds nothing in the dirty and muzzy caches of its arena, it asks the warren of the arena before reusing retained address space or mapping new memory; an in-place expansion looks for the next pages in the warren in the same way.
In llc mode an allocation that finds no fit in its own warren tries the other warrens of the same NUMA node: the per-LLC mode is meant to split the locks of the warrens, not the memory that the arenas share, so an extent freed in one CCD can still be reused by a thread in another one. This was a design choice, and it hasn't been measured how often or how much it helps.
The warren applies the same fit limit as the arenas (lg_extent_max_active_fit), so a small request doesn't split a much larger extent. When an arena does split an extent from a warren, it keeps the unused part in its own dirty cache, so the pieces coalesce again inside one arena and go back to the warren together.
The fit limit and the kept remainders were added after the first version, where a warren could split an extent of any size for a small request, and kept the rest of every split: with warrens that were never purged, about 43 GiB of fragments of about 160 KiB were left unused in them.
Decay of a warren. Warrens have their own decay time, experimental_warren_decay_ms (default -1: never purge). The decay is driven by the deferred work of the arenas, at most once per decay epoch and under a trylock, and purges the oldest extents of the warren. The purged extents stay in the warren as retained address space, and every arena reuses them before mapping new address space, first from its own warren and then from the others.
Oversize allocations. jemalloc handles the allocations of at least oversize_threshold (8 MiB by default) separately: they all come from a dedicated “huge” arena, shared by all the threads, which by default purges its memory as soon as it is freed. As shown above, in this application these are few madvise calls, but most of the purged memory. With warrens the huge arena doesn’t move its extents anywhere: it’s shared by all the threads, so it already works like a warren. It only changes its decay: instead of purging its dirty extents immediately, it keeps them for the decay time of the warrens.
The regular arenas have a similar rule: when the extents freed in an arena coalesce into one of at least oversize_threshold, it’s purged immediately, without waiting for the dirty decay. With warrens such an extent moves to the warren immediately instead, and is purged with the decay of the warren if nobody reuses it.
HPA. An HPA shard that would purge an empty pageslab moves it to a warren instead; a shard that needs a new pageslab takes one from the warren first, and the decay of the warren purges whole pageslabs. This part is much less exercised than the rest, because all measurements used hpa:false.
Statistics. stats.experimental_warren.* reports the number of warrens, the memory they hold, and counters for the pages that are pushed, pulled, purged and reused, and for the lookups and the misses. The mutexes of the warrens are in stats.mutexes.warren, and malloc_stats_print has a "Warrens" block.
Tests. make check passes on a debug build with the warrens disabled. A stress test (32 threads that allocate, reallocate and free blocks of mixed sizes, including aligned and huge ones, and free blocks allocated by other threads) passed 36 runs of 90 s, 30 of them with assertions enabled, in numa and llc mode, with different dirty and warren decay times, and with default and phycpu arenas. All the HLT jobs behind the tables below ran without failures. There are no unit tests for the warrens themselves yet.
Results
The results are for one HLT job on 95 cores / 190 SMTs, measured over 5 minutes (129'000 events) after 2 minutes of warm-up. All the settings use the same build of the prototype, with muzzy_decay_ms:0,hpa:false; the ones without experimental_warren behave like dev. The madvise calls and the remote TLB flushes (tlb:tlb_flush with reason TLB_REMOTE_SHOOTDOWN) are counted with perf stat on the cpus of the job, and divided by the number of events. Every setting was measured 4 times (5 times for PD240 and PW10_10); the tables give the average ± the standard deviation.
The names of the settings are:
D<d>: dirty decay of d seconds, without warrens;D10is the default, andDinfisdirty_decay_ms:-1,muzzy_decay_ms:-1;W<d>_<w>: per-NUMA warrens, with a dirty decay of d seconds and a warren decay of w seconds;L<d>_<w>: the same, with per-LLC warrens;- the prefix
Paddspercpu_arena:phycpu.
| Setting | MALLOC_CONF (plus muzzy_decay_ms:0,hpa:false) |
Throughput (events/s) | madvise / event |
Remote TLB flushes / event | Peak RSS (GiB) |
|---|---|---|---|---|---|
D10 |
dirty_decay_ms:10000 (default) |
429.1 ± 0.3 | 15.75 ± 0.03 | 3688 ± 26 | 77.0 ± 0.5 |
D60 |
dirty_decay_ms:60000 |
432.8 ± 0.3 | 5.90 ± 0.09 | 1088 ± 16 | 80.4 ± 0.6 |
D150 |
dirty_decay_ms:150000 |
434.0 ± 0.6 | 4.41 ± 0.03 | 676 ± 12 | 83.5 ± 0.3 |
D240 |
dirty_decay_ms:240000 |
434.0 ± 0.2 | 4.10 ± 0.02 | 592 ± 10 | 84.2 ± 0.2 |
D300 |
dirty_decay_ms:300000 |
433.9 ± 0.5 | 4.01 ± 0.01 | 568 ± 11 | 84.5 ± 0.3 |
Dinf |
dirty_decay_ms:-1,muzzy_decay_ms:-1 |
438.5 ± 0.4 | 0.02 ± 0.01 | 36 ± 3 | 97.3 ± 0.2 |
W10_10 |
experimental_warren:numa,experimental_warren_decay_ms:10000,dirty_decay_ms:10000 |
436.1 ± 0.3 | 5.38 ± 0.01 | 1094 ± 13 | 84.1 ± 0.5 |
W10_50 |
experimental_warren:numa,experimental_warren_decay_ms:50000,dirty_decay_ms:10000 |
436.2 ± 0.2 | 3.50 ± 0.06 | 720 ± 14 | 85.2 ± 0.5 |
L10_10 |
experimental_warren:llc,experimental_warren_decay_ms:10000,dirty_decay_ms:10000 |
436.3 ± 0.7 | 5.12 ± 0.03 | 1031 ± 20 | 84.3 ± 0.6 |
L10_50 |
experimental_warren:llc,experimental_warren_decay_ms:50000,dirty_decay_ms:10000 |
436.5 ± 0.6 | 2.93 ± 0.03 | 611 ± 12 | 86.5 ± 0.7 |
PD240 |
percpu_arena:phycpu,dirty_decay_ms:240000 |
431.8 ± 0.8 | 4.10 ± 0.05 | 569 ± 5 | 80.0 ± 0.3 |
PW10_10 |
percpu_arena:phycpu + W10_10 |
434.7 ± 1.4 | 4.53 ± 0.08 | 910 ± 12 | 82.3 ± 0.2 |
PL10_10 |
percpu_arena:phycpu + L10_10 |
435.9 ± 0.3 | 4.18 ± 0.07 | 844 ± 17 | 82.4 ± 0.4 |
Table 2. Throughput, purging activity and memory usage for the different settings.
One of the five PW10_10 runs gave 432.2 events/s over its whole length, and I haven't found why; the other four give 435.4 ± 0.2 events/s.
Figure 1. Throughput against peak RSS for the settings of Table 2. The dashed line joins the settings without warrens and with the default arenas; the squares are the settings with percpu_arena:phycpu.
The memory usage of a 240 s dirty decay, with a higher throughput
With the default settings the job gets 3688 remote TLB flushes per event, that is 1.6 million interrupts per second over its 190 SMTs. A longer dirty decay removes most of them, but the throughput levels off at 434 events/s between 150 s and 300 s. The only setting without warrens that is faster is Dinf, with 13 GiB more memory.
W10_10 and L10_10 use the same memory as D240 (84.1 ± 0.5 and 84.3 ± 0.6 GiB, against 84.2 ± 0.2 GiB) and are 0.5% faster (2.1 and 2.3 events/s), which is about half of the way from D240 to Dinf. Compared with the default they are 1.6% faster, with 70% fewer remote TLB flushes and 7 GiB (9%) more memory.
W10_10 has almost twice the remote TLB flushes of D240 (1094 against 592 per event), about as many as D60, and is still faster than both, so the TLB flushes are not the only cost of purging.
The other cost is assumed to be that of the purged memory itself: when it’s used again, the kernel has to handle the page faults and zero the pages. A longer dirty decay doesn’t reduce this much, because most of it comes from the oversize allocations, which are purged immediately. With warrens the oversized allocations also follow a dirty decay, so part of this memory can be reused directly, reducing the number of madvise calls and memory faults handled by the kernel.
Per-NUMA and per-LLC warrens
In this job the two modes give the same throughput and memory usage within the errors. The difference is in the contention on the locks of the warrens: with numa all the arenas of the job share the single warren of their socket, while with llc they are spread over the 12 warrens of its CCDs.
| Setting | Warrens on the socket of the job | Lock operations | Operations that waited | Total wait time (s) |
|---|---|---|---|---|
W10_10 |
1 | 7.55 M | 23.6 k | 14.6 |
L10_10 |
12 | 7.47 M | 12.4 k | 6.0 |
PW10_10 |
1 | 4.92 M | 15.2 k | 6.6 |
PL10_10 |
12 | 5.16 M | 9.1 k | 3.0 |
Table 3. Mutex statistics of the warrens (stats.mutexes.warren, all the warrens of the process together) per job; average of the runs of Table 2.
With a 10 s dirty decay in front of the warrens these numbers are small (the largest is less than 0.02% of the thread time of the job), which is why the throughput is the same. They become the limit when more memory goes through the warrens. An earlier version of the prototype was also measured with dirty_decay_ms:0, where every freed extent goes directly to a warren: with one warren for the socket the job ran at 201–210 events/s, with per-LLC warrens at 428–430 events/s. I haven't repeated this test with the current version, but it suggests that the per-LLC mode is the one to use on machines with more cores per NUMA node, or with a shorter dirty decay. It also keeps the shared memory inside one NUMA node.
Interaction with phycpu arenas
With percpu_arena:phycpu the job uses 95 arenas, one per physical core, instead of about 200. In llc mode each warren then serves the arenas of the 8 cores that share an L3 cache, so the three levels follow the topology of the machine: a cache per thread, an arena per core, and a warren per CCD.
Without warrens, phycpu reduces the memory by 4.2 GiB and the throughput by 2.2 events/s at a 240 s decay (PD240 against D240). With warrens the two work well together: PL10_10 reaches 435.9 ± 0.3 events/s with 82.4 GiB, that is 0.9% (4.1 events/s) more than PD240 for 2.4 GiB more, and the same throughput as L10_10 within the errors with 1.9 GiB less. The gain from the warrens is larger with the phycpu arenas than with the default ones (4.1 against 2.3 events/s over the 240 s decay), and the phycpu arenas reduce the lock operations on the warrens by about a third (Table 3).
Limitations
- The grouping by NUMA node and by last-level cache is implemented only for Linux; on other systems there is a single warren.
- All the measurements here use a single socket, where a job in
numamode uses a single warren, as it would withglobal. - The warrens are decayed by the deferred work of the arenas (or by the background threads on their behalf), so a process that stops allocating doesn't purge its warrens. A version meant for merging should give them their own place in the background threads.
- The warrens hold only dirty extents, and I've always used them with
muzzy_decay_ms:0and the defaultretain:true. - The HPA part is implemented, but not measured.
- The options are
experimental_*, there is no documentation yet, and the tests are a stress test and a demo instead of unit tests. - All the performance numbers come from one application on one type of machine.
Feedback
I'd be grateful for your opinion on the idea before investing in making the code ready for a review. In particular:
- Does a second level of caching for the dirty extents, shared by groups of arenas, fit the direction of jemalloc? Or is there a different mechanism that you would prefer for the same problem, the cost of purging in a process with hundreds of threads?
- Are the NUMA node and the last-level cache reasonable groups, or would you prefer a more general way to assign the arenas to the warrens?
- How should the decay of a warren relate to the existing decay settings, and to the background threads?
- Is the handling of the oversize extents and of the huge arena acceptable as part of this, or should it be a separate change?
If there is interest in reviewing it, I'm happy to rebase the branch on the current dev, split it into a series that can be reviewed, add unit tests and documentation, and open a PR. I can also publish the branch as it is now, if that helps the discussion, or repeat the measurements with other settings that you consider relevant.
Activity
fwyzard commentedon Nov 14, 2026
Update
I've spent more time to understand where the gain from the proposed "warrens" comes from, and I realised that most of the gain comes from a delayed released of the memory from the oversize extents.
To test this hypothesis I've implemented a second prototype that can configure independently
experimental_oversize_dirty_decay_msoptionThe results are summarised in Figures 2 and 3.
Figure 2 Throughput vs RSS for various settings of
dirty_decay_ms,experimental_oversize_dirty_decay_ms,experimental_warren_decay_ms, and the warren options. The error bars show the estimated uncertainty on the average of the repeated measurements, while the ellipses show the two-dimensional standard deviation.Figure 3 _Throughput vs RSS for various settings of
dirty_decay_ms,experimental_oversize_dirty_decay_ms,experimental_warren_decay_ms, and the warren options. Shows the same results as Figure 2, zoomed in to show the region where warrens and oversize extents dirty decay give similar performance. _Notes
For these measurements, increasing the
dirty_decay_msabove about 2 minutes does not provide any improvements to the performance. The measurements last about 300s after a 120s warm up period, so this could be an artifact of the measurement itself.An
experimental_oversize_dirty_decay_msof 10s, combined with differentdirty_decay_mssettings, achieves similar performance (throughout gains and RSS cost) as various warren settings:dirty_decay_ms:60000,experimental_oversize_dirty_decay_ms:10000vsdirty_decay_ms:30000,experimental_warren:numa,experimental_warren_decay_ms:10000;dirty_decay_ms:40000,experimental_oversize_dirty_decay_ms:10000vsdirty_decay_ms:10000,experimental_warren:llc,experimental_warren_decay_ms:10000.Next steps
I'm leaning towards shelving the warrens idea, at least for the moment, and working on a PR for the oversize extent dirty decay: the impact on the performance is very similar, but the implementation is much simpler.
I will also try to run measurements on different systems (AMD EPYC "Turin" 9965, Intel "Sierra Forest" Xeon 6780E, Intel "Emerald Rapids" Xeon Platinum 8592+) before a possible decision.
fwyzard commentedon Nov 15, 2026
Update ][
I've repeated the measurements after addressing some minor issues in the application, and performed a more systematic scan of three settings:
dirty_decay_ms, from 10s to 240sdirty_decay_msfrom 10s to 240sdirty_decay_msfrom 10s to 240sdirty_decay_msfrom 10s to 240sFigure 4 Throughput vs RSS for various settings of dirty_decay_ms, experimental_oversize_dirty_decay_ms, experimental_warren_decay_ms, and no memory release. Each point is the average of four measurements. The error bars show the estimated uncertainty on the average of the repeated measurements, while the ellipses show the two-dimensional standard deviation.
Figure 5 Same as Figure 4, zoomed in.
The oversize arena decay achieves most of the gain from the warren, although the warren remains better in terms of memory usage.
guangli-dai commentedon Nov 18, 2026
Thank you for the report, very valuable data points! A quick question, do you have background thread enabled? Because we have already stoped purging oversize arena eagerly when background threads are enabled in #2466.
Also, current mallctls allow you to set oversize arena's dirty decay time in the following orders:
arenas.lookuparena.<i>.dirty_decay_ms.On a side note, the centralized free memory management is indeed on our roadmap, but not for Page Allocator Classic (PAC). It is prepared for Huge Page Allocator (HPA), which is still experimental for now, but will be formally released soon.