diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 841f9a5..eeacd22 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -99,6 +99,33 @@ jobs:
- uses: taiki-e/install-action@nextest
- name: Run the tests under Miri
run: just miri
+ coverage:
+ name: Coverage
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Checkout sources
+ uses: actions/checkout@v7
+ - name: Install Rust stable toolchain
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ components: llvm-tools-preview
+ - uses: Swatinem/rust-cache@v2
+ with:
+ cache-on-failure: true
+ - uses: taiki-e/install-action@just
+ - uses: taiki-e/install-action@nextest
+ - uses: taiki-e/install-action@cargo-llvm-cov
+ - name: Measure coverage
+ run: just coverage
+ - name: Upload to Codecov
+ uses: codecov/codecov-action@v5
+ with:
+ files: lcov.info
+ fail_ci_if_error: false
+ env:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
+
loom:
name: Loom
@@ -140,6 +167,22 @@ jobs:
- name: Fuzz the heaps
run: just fuzz heap_ops 60
+ bench-docs:
+ name: Benchmark documents
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ steps:
+ - name: Checkout sources
+ uses: actions/checkout@v7
+ - name: Install Rust stable toolchain
+ uses: dtolnay/rust-toolchain@stable
+ - uses: Swatinem/rust-cache@v2
+ with:
+ cache-on-failure: true
+ - uses: taiki-e/install-action@just
+ - name: Check that the tables and the figure match benchmarks.json
+ run: just bench-check
+
benches:
name: Build benchmarks
runs-on: ubuntu-latest
diff --git a/.gitignore b/.gitignore
index ffb36cd..e9e1264 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
# macOS
.DS_Store
+lcov.info
diff --git a/BENCHMARKS.md b/BENCHMARKS.md
new file mode 100644
index 0000000..736e666
--- /dev/null
+++ b/BENCHMARKS.md
@@ -0,0 +1,673 @@
+# Benchmarks
+
+bcmalloc against the system allocator, mimalloc, jemalloc and snmalloc on three sets of programs. The development suite of 51 synthetic workloads is what the allocator is tuned against. The held-out Rust programs and the C programs of [mimalloc-bench](https://github.com/daanx/mimalloc-bench) are never tuned against, and show whether the gains carry over to code written for other purposes.
+
+
+
+Every number on this page, and the figure, comes from [benchmarks.json](benchmarks.json). The benchmark commands record their results there, and `just bench-render` renders this page's tables, the table in the README and the figure from it. CI fails when they are out of date.
+
+## Method
+
+- **Machines.** An Apple M4 Max, where the system allocator is libmalloc, and a 32-core AMD EPYC 9354P with Ubuntu 24.04 and glibc 2.39. mimalloc-bench ran on a second, idle machine of the same model. Both Linux machines have transparent huge pages set to `madvise`, and the [machines table](#machines) gives the exact systems.
+- **Versions.** The Rust suites use the latest published crates, mimalloc 0.1.52 (mimalloc 3.3.2), tikv-jemallocator 0.7 (jemalloc 5.3.1) and snmalloc-rs 0.7.6. mimalloc-bench pins mimalloc 1.8.2, so it was rebuilt with mimalloc 3.6.1, the latest release, next to jemalloc 5.4.0 and snmalloc 0.7.6. Rust is 1.100.
+- **Runs.** Every Rust workload runs ten times per allocator, in a fresh process each time, with the allocators taking turns in a rotating order. The tables show medians, and bold marks the best median and every median whose 95% bootstrap interval overlaps it. The cold rows are the first pass of each workload and the others the steady state. Each mimalloc-bench program ran three times per allocator, and its table shows the medians of wall time and peak resident memory.
+- **Reproducing.** `just bench`, `just bench-apps` and `just mimalloc-bench` run the three sets. `just bench --save PATH` keeps the raw samples, `just bench --load PATH` prints their report again, and `just bench-compare OLD NEW` compares two of them.
+
+## Summary
+
+
+| Compared with mimalloc | system | bcmalloc | jemalloc | snmalloc |
+| ---------------------------------- | ------ | -------- | -------- | -------- |
+| development suite, macOS, speed | 0.52 | 2.09 | 0.87 | 1.22 |
+| development suite, Linux, speed | 0.63 | 1.73 | 0.88 | 1.14 |
+| Rust programs, macOS, speed | 0.91 | 1.02 | 0.93 | 1.01 |
+| Rust programs, Linux, speed | 0.82 | 1.09 | 1.03 | 1.04 |
+| mimalloc-bench, Linux, speed | - | 1.00 | 0.82 | 0.94 |
+| mimalloc-bench, Linux, peak memory | - | 1.51 | 1.38 | 1.40 |
+
+
+Each figure is mimalloc's time or peak memory divided by the other allocator's, so above 1.00 means faster or smaller. It is the geometric mean over the suite's speed workloads, or over its programs for memory.
+
+bcmalloc is the fastest allocator on both development suites, by a wide margin in most groups, though jemalloc is slightly ahead on the sharing group on Linux. It is the fastest on the Rust programs on both machines. On mimalloc-bench it ties mimalloc for time while holding two thirds of its peak memory, and it is faster than snmalloc and jemalloc. It is not the fastest on every program there. mimalloc is faster on sh6bench and sh8bench, which free thousands of blocks in a row, more than a heap's bins hold, and on alloc-test, glibc-simple, mstress and rocksdb by 3% to 7%. snmalloc is faster on redis, glibc-thread, cfrac and espresso by 1% to 6%, and on xmalloc-test, where jemalloc is faster still. The 0.01 s difference on mleak10 is the resolution of the timer.
+
+## Machines
+
+
+| Suite | Machine | Runs | Date |
+| ------------------------ | ----------------------------------------------------------------- | ---- | ---------- |
+| development suite, macOS | Apple M4 Max, macOS 27.0.1 | 10 | 2026-11-14 |
+| development suite, Linux | AMD EPYC 9354P 32-Core Processor, Ubuntu 24.04.2 LTS, Linux 7.0.0 | 10 | 2026-11-14 |
+| Rust programs, macOS | Apple M4 Max, macOS 27.0.1 | 10 | 2026-11-14 |
+| Rust programs, Linux | AMD EPYC 9354P 32-Core Processor, Ubuntu 24.04.2 LTS, Linux 7.0.0 | 10 | 2026-11-14 |
+| mimalloc-bench, Linux | AMD EPYC 9354P 32-Core Processor, Ubuntu 24.04.2 LTS, Linux 6.8.0 | 3 | 2026-11-14 |
+
+
+## mimalloc-bench
+
+The geometric means, then the wall time in seconds and the peak resident memory in MiB of every program, as `time / memory`, with the best of each in bold. lua is left out, because its sources are not part of the suite as built.
+
+
+| Compared with mimalloc | bcmalloc | mimalloc | snmalloc | jemalloc |
+| ---------------------- | -------- | -------- | -------- | -------- |
+| speed | 1.00 | 1.00 | 0.94 | 0.82 |
+| peak resident memory | 1.51 | 1.00 | 1.40 | 1.38 |
+
+| Program | bcmalloc | mimalloc | snmalloc | jemalloc |
+| -------------- | -------------------- | ------------------ | ------------------- | ------------------ |
+| cfrac | 3.250 / **3.2** | 3.240 / 4.4 | **3.160** / 3.5 | 3.270 / 5.2 |
+| espresso | 3.470 / **3.8** | 3.470 / 10.4 | **3.420** / 4.5 | 3.540 / 6.2 |
+| barnes | **2.170** / 63.5 | 2.210 / 67.5 | 2.260 / **58.2** | 2.250 / 59.5 |
+| redis | 3.319 / 11.2 | 3.420 / 20.1 | **3.120** / **8.0** | 3.740 / 10.0 |
+| larsonN | **1.071** / 342.1 | 1.167 / 306.5 | 1.219 / 415.8 | 1.290 / **260.0** |
+| larsonN-sized | **1.030** / 347.9 | 1.126 / 310.4 | 1.183 / 418.0 | 1.161 / **270.1** |
+| mstressN | 0.670 / 598.2 | **0.630** / 1030.0 | 0.820 / 813.5 | 1.230 / **511.0** |
+| rptestN | **0.199** / 222.8 | 0.237 / 236.0 | 0.215 / 183.0 | 0.511 / **161.0** |
+| gs | **0.220** / 41.8 | 0.230 / 55.3 | 0.240 / **36.0** | 0.240 / 36.8 |
+| alloc-test1 | 2.640 / 14.2 | **2.500** / 16.2 | 2.590 / 13.8 | 2.580 / **12.8** |
+| alloc-testN | 2.460 / **15.8** | **2.300** / 60.3 | 2.310 / 16.2 | 2.330 / 16.2 |
+| sh6benchN | 0.060 / 280.1 | **0.050** / 226.4 | 0.080 / 275.0 | 0.090 / **224.3** |
+| sh8benchN | 0.170 / 251.3 | **0.140** / 510.5 | 0.190 / 205.3 | 0.270 / **168.2** |
+| xmalloc-testN | 0.191 / 103.0 | 0.216 / **66.3** | 0.177 / 128.3 | **0.165** / 141.6 |
+| cache-scratch1 | **1.050** / **4.0** | **1.050** / 6.2 | **1.050** / 4.2 | **1.050** / 4.5 |
+| cache-scratchN | **0.030** / 4.0 | **0.030** / 6.2 | **0.030** / **3.8** | **0.030** / 4.5 |
+| glibc-simple | 1.670 / **2.0** | **1.590** / 4.2 | 1.620 / 2.5 | 1.900 / 4.8 |
+| glibc-thread | 0.203 / **10.8** | 0.199 / 88.5 | **0.192** / 21.2 | 0.205 / 14.8 |
+| rocksdb | 4.270 / 102.7 | **4.130** / 141.9 | 4.350 / 107.3 | 4.350 / **102.5** |
+| leanN | 9.100 / 260.4 | **9.080** / 335.9 | 9.110 / 242.5 | 9.280 / **218.9** |
+| linux | **0.150** / **18.0** | 0.170 / 23.7 | **0.150** / 18.5 | 0.160 / 18.5 |
+| malloc-large | 1.420 / 579.6 | **1.400** / 588.1 | 3.560 / 650.5 | 14.420 / **429.6** |
+| mleak10 | 0.150 / **2.0** | 0.150 / 4.2 | **0.140** / 2.5 | 0.160 / 4.8 |
+| mleak100 | **1.500** / **2.0** | **1.500** / 4.2 | **1.500** / 2.5 | 1.610 / 4.8 |
+| rbstress1 | **2.790** / 118.8 | 2.820 / 139.2 | 2.820 / **117.3** | 2.800 / 119.0 |
+| rbstressN | 3.020 / **163.3** | 3.010 / 192.7 | 3.010 / 209.0 | **2.990** / 201.3 |
+| cache-thrash1 | **1.050** / **4.0** | **1.050** / 6.2 | **1.050** / 4.2 | **1.050** / 4.5 |
+| cache-thrashN | **0.030** / **4.0** | **0.030** / 6.2 | **0.030** / **4.0** | **0.030** / 4.5 |
+
+
+## Rust programs
+
+Each program is a crate written for its own purpose and driven with a fixed input. They are built on serde_json, regex, syn, a hyper server with its clients, and tokio channels.
+
+### macOS
+
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, all workloads | 0.91 | 1.02 | 1.00 | 0.93 | 1.01 |
+| peak resident memory | 1.22 | 0.96 | 1.00 | 1.13 | 1.17 |
+| speed, cold | 0.91 | 1.03 | 1.00 | 0.93 | 1.01 |
+
+
+
+
+Every workload on macOS
+
+Median of 10 runs. Bold marks the best median and every median whose 95% bootstrap interval overlaps it.
+
+### apps
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ------ | ---------- | --------- | --------- | ---------- |
+| json (MB/s) | 252.1 | 291.3 | **306.0** | 248.9 | 298.6 |
+| regex (MB/s) | 1452.0 | **1525.0** | 1515.0 | 1448.0 | **1526.0** |
+| syn (MB/s) | 16.3 | **20.4** | 19.6 | 16.1 | 19.5 |
+| http (kreq/s) | 218.6 | **227.6** | **225.6** | **225.7** | **225.3** |
+| tokio channels (Mmsg/s) | 4.04 | **4.59** | 4.14 | 4.42 | 4.44 |
+
+### apps, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ------ | ---------- | --------- | --------- | ---------- |
+| json (MB/s) | 254.8 | 291.3 | **303.3** | 247.6 | 298.2 |
+| regex (MB/s) | 1442.0 | **1522.0** | 1513.0 | 1445.0 | **1520.0** |
+| syn (MB/s) | 16.0 | **20.4** | 19.5 | 15.9 | 19.3 |
+| http (kreq/s) | 217.3 | **228.1** | **224.0** | **226.7** | **225.8** |
+| tokio channels (Mmsg/s) | 4.04 | **4.58** | 4.13 | 4.46 | 4.48 |
+
+### Summary
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, all workloads | 0.91 | 1.02 | 1.00 | 0.93 | 1.01 |
+| peak resident memory | 1.22 | 0.96 | 1.00 | 1.13 | 1.17 |
+| speed, cold | 0.91 | 1.03 | 1.00 | 0.93 | 1.01 |
+
+
+
+
+### Linux
+
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, all workloads | 0.82 | 1.09 | 1.00 | 1.03 | 1.04 |
+| peak resident memory | 2.23 | 1.75 | 1.00 | 1.70 | 1.68 |
+| speed, cold | 0.81 | 1.09 | 1.00 | 1.02 | 1.02 |
+
+
+
+
+Every workload on Linux
+
+Median of 10 runs. Bold marks the best median and every median whose 95% bootstrap interval overlaps it.
+
+### apps
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ------ | ---------- | -------- | -------- | -------- |
+| json (MB/s) | 131.2 | **193.4** | 188.1 | 171.3 | 182.1 |
+| regex (MB/s) | 986.9 | **1049.0** | 1039.0 | 1034.0 | 1045.0 |
+| syn (MB/s) | 7.17 | **10.6** | 10.0 | 9.12 | 9.67 |
+| http (kreq/s) | 101.2 | **122.6** | 115.6 | 120.6 | 118.1 |
+| tokio channels (Mmsg/s) | 1.22 | 1.88 | 1.41 | **1.93** | 1.75 |
+
+### apps, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ------ | ---------- | -------- | --------- | -------- |
+| json (MB/s) | 127.8 | **192.6** | 185.3 | 166.8 | 177.0 |
+| regex (MB/s) | 978.5 | **1048.0** | 1039.0 | 1025.0 | 1036.0 |
+| syn (MB/s) | 7.02 | **10.6** | 9.98 | 8.88 | 9.43 |
+| http (kreq/s) | 101.1 | **122.2** | 115.6 | **121.6** | 118.2 |
+| tokio channels (Mmsg/s) | 1.23 | 1.88 | 1.42 | **1.93** | 1.75 |
+
+### Summary
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, all workloads | 0.82 | 1.09 | 1.00 | 1.03 | 1.04 |
+| peak resident memory | 2.23 | 1.75 | 1.00 | 1.70 | 1.68 |
+| speed, cold | 0.81 | 1.09 | 1.00 | 1.02 | 1.02 |
+
+
+
+
+## Development suite
+
+Eight groups of synthetic workloads, from single-thread loops to producer and consumer rings, Larson, false sharing, standard collections, resizing, large blocks, latency percentiles and memory after a burst.
+
+### macOS
+
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, pair | 0.56 | 3.75 | 1.00 | 0.55 | 1.71 |
+| speed, bulk | 0.27 | 1.48 | 1.00 | 0.43 | 0.81 |
+| speed, churn | 0.30 | 2.55 | 1.00 | 1.47 | 1.60 |
+| speed, sharing | 0.55 | 3.06 | 1.00 | 2.10 | 1.57 |
+| speed, false sharing | 0.87 | 1.00 | 1.00 | 0.68 | 1.00 |
+| speed, collections | 0.71 | 1.29 | 1.00 | 0.67 | 1.19 |
+| speed, resizing | 1.00 | 1.03 | 1.00 | 0.95 | 0.86 |
+| speed, large | 0.98 | 1.08 | 1.00 | 0.15 | 0.12 |
+| speed, all workloads | 0.52 | 2.09 | 1.00 | 0.87 | 1.22 |
+| memory held afterwards | 2.37 | 3.13 | 1.00 | 0.96 | 3.91 |
+| peak resident memory | 0.99 | 0.98 | 1.00 | 0.99 | 1.09 |
+| speed, mean of groups | 0.59 | 1.68 | 1.00 | 0.68 | 0.90 |
+| speed, cold | 0.52 | 2.05 | 1.00 | 0.87 | 1.23 |
+| latency, p99 | 0.54 | 4.14 | 1.00 | 2.34 | 1.65 |
+
+
+
+
+Every workload on macOS
+
+Median of 10 runs. Bold marks the best median and every median whose 95% bootstrap interval overlaps it.
+
+### pair
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| --------------------- | ------ | --------- | -------- | -------- | -------- |
+| pair 16 B (Mops/s) | 153.5 | **433.4** | 224.3 | 142.8 | 397.0 |
+| pair 64 B (Mops/s) | 137.6 | **405.0** | 219.9 | 142.2 | 386.5 |
+| pair 256 B (Mops/s) | 126.0 | **410.5** | 182.3 | 140.0 | 344.2 |
+| pair 1 KiB (Mops/s) | 54.2 | **409.8** | 150.8 | 133.1 | 282.1 |
+| pair 4 KiB (Mops/s) | 71.7 | **411.3** | 95.6 | 111.8 | 159.8 |
+| pair 16 KiB (Mops/s) | 61.2 | **308.7** | 87.5 | 54.7 | 158.1 |
+| pair 64 KiB (Mops/s) | 14.5 | **309.1** | 87.9 | 11.4 | 161.7 |
+| pair 256 KiB (Mops/s) | 14.3 | **211.5** | 88.6 | 7.75 | 38.9 |
+| pair 1 MiB (Mops/s) | 14.2 | **212.6** | 4.06 | 7.77 | 19.4 |
+
+### pair, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| --------------------- | ------ | --------- | -------- | -------- | -------- |
+| pair 16 B (Mops/s) | 152.6 | **433.0** | 223.8 | 143.0 | 396.2 |
+| pair 64 B (Mops/s) | 137.4 | **405.2** | 219.6 | 142.2 | 386.1 |
+| pair 256 B (Mops/s) | 129.0 | **409.4** | 182.1 | 140.0 | 341.8 |
+| pair 1 KiB (Mops/s) | 54.2 | **409.8** | 149.7 | 133.6 | 280.8 |
+| pair 4 KiB (Mops/s) | 72.7 | **410.8** | 95.0 | 112.0 | 167.5 |
+| pair 16 KiB (Mops/s) | 61.0 | **309.6** | 86.9 | 54.9 | 157.1 |
+| pair 64 KiB (Mops/s) | 14.6 | **308.5** | 88.2 | 11.3 | 162.5 |
+| pair 256 KiB (Mops/s) | 14.3 | **210.1** | 88.6 | 7.54 | 38.9 |
+| pair 1 MiB (Mops/s) | 14.3 | **209.7** | 4.05 | 7.71 | 19.6 |
+
+### bulk
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | ------ | --------- | -------- | -------- | -------- |
+| bulk 32 B in order (Mops/s) | 86.5 | **306.4** | 172.4 | 66.2 | 211.8 |
+| bulk 32 B shuffled (Mops/s) | 39.9 | **191.4** | 169.7 | 60.3 | 160.8 |
+| bulk 512 B shuffled (Mops/s) | 10.8 | **101.6** | 63.0 | 35.5 | 29.1 |
+
+### bulk, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | ------ | --------- | -------- | -------- | -------- |
+| bulk 32 B in order (Mops/s) | 82.1 | **242.3** | 152.9 | 62.7 | 188.1 |
+| bulk 32 B shuffled (Mops/s) | 39.8 | **173.8** | 150.6 | 58.0 | 147.2 |
+| bulk 512 B shuffled (Mops/s) | 10.5 | **55.3** | 43.8 | 25.5 | 25.2 |
+
+### churn
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------------------- | ------ | ---------- | -------- | -------- | -------- |
+| churn small (Mops/s) | 48.4 | **231.8** | 98.1 | 122.8 | 214.4 |
+| churn medium (Mops/s) | 25.9 | **229.2** | 58.5 | 110.2 | 118.6 |
+| churn mixed (Mops/s) | 35.5 | **227.9** | 83.2 | 113.0 | 127.8 |
+| churn skewed (Mops/s) | 48.9 | **185.3** | 155.2 | 127.6 | 174.0 |
+| churn mixed 4 threads (Mops/s) | 38.1 | **885.3** | 289.0 | 442.5 | 436.7 |
+| churn mixed 8 threads (Mops/s) | 66.0 | **1730.0** | 422.5 | 865.3 | 810.1 |
+| churn mixed 16 threads (Mops/s) | 93.2 | **1952.0** | 595.5 | 1071.0 | 1033.0 |
+| churn skewed 8 threads (Mops/s) | 170.0 | **1373.0** | 848.5 | 950.1 | 1239.0 |
+| churn mixed oversubscribed (Mops/s) | 120.5 | **2015.0** | 750.4 | 1104.0 | 1073.0 |
+| churn large set (Mops/s) | 6.14 | **53.8** | 10.0 | 27.5 | 22.3 |
+| churn with work (Mops/s) | 3.15 | **3.42** | 3.38 | 3.36 | 3.40 |
+
+### churn, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------------------- | ------ | ---------- | -------- | -------- | -------- |
+| churn small (Mops/s) | 48.1 | **230.7** | 98.1 | 122.5 | 213.7 |
+| churn medium (Mops/s) | 25.9 | **228.0** | 58.6 | 109.7 | 118.8 |
+| churn mixed (Mops/s) | 35.3 | **226.9** | 82.9 | 113.2 | 127.4 |
+| churn skewed (Mops/s) | 48.1 | **184.2** | 153.1 | 127.5 | 173.3 |
+| churn mixed 4 threads (Mops/s) | 37.3 | **876.9** | 294.4 | 441.9 | 434.4 |
+| churn mixed 8 threads (Mops/s) | 64.9 | **1703.0** | 436.8 | 863.8 | 809.0 |
+| churn mixed 16 threads (Mops/s) | 90.3 | **1900.0** | 614.1 | 1048.0 | 1007.0 |
+| churn skewed 8 threads (Mops/s) | 165.5 | **1404.0** | 842.3 | 966.8 | 1254.0 |
+| churn mixed oversubscribed (Mops/s) | 93.7 | **1938.0** | 786.0 | 1127.0 | 1043.0 |
+| churn large set (Mops/s) | 5.74 | **35.8** | 8.91 | 20.5 | 20.0 |
+| churn with work (Mops/s) | 3.15 | **3.41** | 3.38 | 3.35 | 3.40 |
+
+### sharing
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | ---------- | -------- | --------- | -------- |
+| larson 8 threads (Mops/s) | 36.3 | **1630.0** | 671.1 | 882.0 | 730.3 |
+| ring 4 threads (Mops/s) | 111.1 | **526.5** | 103.2 | 435.0 | 172.2 |
+| ring 8 threads (Mops/s) | 111.4 | **556.5** | 82.2 | **559.4** | 174.0 |
+| channel 1 pair (Mops/s) | 28.9 | **76.2** | 25.6 | 53.4 | 46.8 |
+| channel 4 pairs (Mops/s) | 45.2 | 123.1 | 56.9 | **131.3** | 114.3 |
+| shared table 8 threads (Mops/s) | 22.2 | **94.6** | 39.1 | 88.6 | 35.7 |
+| thread lifecycle (Mops/s) | 36.4 | **196.7** | 102.3 | 44.1 | 190.0 |
+
+### sharing, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | ---------- | -------- | --------- | --------- |
+| larson 8 threads (Mops/s) | 35.6 | **1543.0** | 663.3 | 867.1 | 727.2 |
+| ring 4 threads (Mops/s) | 100.0 | **530.2** | 102.8 | 439.5 | 171.4 |
+| ring 8 threads (Mops/s) | 110.1 | **546.0** | 78.7 | **543.9** | 175.5 |
+| channel 1 pair (Mops/s) | 29.0 | **75.8** | 25.9 | 51.4 | 51.3 |
+| channel 4 pairs (Mops/s) | 45.0 | 121.8 | 56.1 | **135.2** | 112.9 |
+| shared table 8 threads (Mops/s) | 16.9 | **94.2** | 38.9 | **92.8** | 35.1 |
+| thread lifecycle (Mops/s) | 36.2 | **184.7** | 102.1 | 43.8 | **181.9** |
+
+### false sharing
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| -------------------------------- | ------- | ----------- | -------- | -------- | ----------- |
+| cache scratch 8 threads (Mops/s) | 26420.0 | **31070.0** | 30940.0 | 14320.0 | **31000.0** |
+| cache thrash 8 threads (Mops/s) | 27210.0 | **31060.0** | 30910.0 | 30930.0 | 30990.0 |
+
+### false sharing, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| -------------------------------- | ------- | ----------- | -------- | -------- | -------- |
+| cache scratch 8 threads (Mops/s) | 27750.0 | **31050.0** | 30940.0 | 13100.0 | 31020.0 |
+| cache thrash 8 threads (Mops/s) | 27910.0 | **31050.0** | 30950.0 | 30900.0 | 30990.0 |
+
+### collections
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | --------- | -------- | -------- | -------- |
+| hash map (Mops/s) | 7.55 | **14.7** | 11.7 | 13.0 | 13.7 |
+| btree map (Mops/s) | 5.12 | **6.71** | 5.67 | 6.24 | 6.33 |
+| strings (Mops/s) | 7.56 | 8.79 | 8.77 | 7.61 | **8.89** |
+| linked list (Mops/s) | 92.3 | **223.0** | 148.3 | 66.9 | 187.0 |
+| binary trees (Mops/s) | 75.2 | **174.6** | 119.3 | 56.2 | 158.2 |
+| tree rewrite (Mops/s) | 79.7 | **195.1** | 128.0 | 57.7 | 170.9 |
+| binary trees with work (Mops/s) | 54.3 | **91.2** | 75.2 | 43.9 | 85.3 |
+
+### collections, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | --------- | -------- | -------- | -------- |
+| hash map (Mops/s) | 7.40 | **13.9** | 11.2 | 12.7 | 13.6 |
+| btree map (Mops/s) | 5.11 | **6.67** | 5.56 | 6.13 | 6.24 |
+| strings (Mops/s) | 7.55 | 8.75 | 8.76 | 7.60 | **8.90** |
+| linked list (Mops/s) | 89.8 | **212.0** | 143.8 | 65.6 | 178.5 |
+| binary trees (Mops/s) | 74.3 | **171.8** | 117.7 | 55.9 | 153.9 |
+| tree rewrite (Mops/s) | 79.5 | **196.2** | 128.4 | 57.8 | 171.2 |
+| binary trees with work (Mops/s) | 54.4 | **91.7** | 75.1 | 43.8 | 88.6 |
+
+### resizing
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ---------- | --------- | --------- | --------- | -------- |
+| vec growth (Mops/s) | 857.4 | 675.7 | 630.7 | **947.2** | 826.3 |
+| string growth (Mops/s) | **3092.0** | 2984.0 | 3012.0 | 2622.0 | 1806.0 |
+| many vectors (Mops/s) | 288.3 | **305.1** | **302.5** | 296.5 | 299.7 |
+| realloc random (Mops/s) | 9.10 | **12.9** | 12.3 | 7.72 | 8.47 |
+
+### resizing, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ---------- | --------- | --------- | --------- | -------- |
+| vec growth (Mops/s) | 871.8 | 665.8 | 630.5 | **950.4** | 807.9 |
+| string growth (Mops/s) | **3057.0** | 2964.0 | 2988.0 | 2365.0 | 1800.0 |
+| many vectors (Mops/s) | 284.2 | **303.1** | **300.6** | 292.1 | 297.2 |
+| realloc random (Mops/s) | 9.11 | **12.9** | 12.2 | 7.73 | 8.43 |
+
+### large
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| medium blocks (Mops/s) | 1.69 | **2.01** | 1.49 | 1.22 | 0.58 |
+| large blocks (Mops/s) | 0.20 | 0.20 | **0.23** | 0.01 | 0.01 |
+
+### large, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| medium blocks (Mops/s) | 1.65 | **1.95** | 1.45 | 1.16 | 0.58 |
+| large blocks (Mops/s) | 0.16 | 0.16 | **0.19** | 0.01 | 0.01 |
+
+### memory
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| --------------------- | --------- | -------- | --------- | -------- | --------- |
+| burst retention (MiB) | 21.8 | 7.41 | 260.6 | 266.3 | **5.47** |
+| half freed (MiB) | **153.2** | 154.0 | **153.2** | 155.9 | 153.6 |
+| phase churn (MiB) | 132.5 | 169.2 | 148.2 | 163.2 | **118.1** |
+
+### latency
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | ------ | -------- | -------- | -------- | -------- |
+| latency churn 1 thread (ns) | 16.9 | **3.27** | 7.16 | 7.81 | 5.22 |
+| latency churn 8 threads (ns) | 108.1 | **3.91** | 15.6 | 7.81 | 7.17 |
+| latency remote frees (ns) | 118.5 | **37.8** | 304.7 | 43.6 | 204.4 |
+
+### latency, latency (p50 / p99 / p999)
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | -------------------- | ------------------- | -------------------- | ------------------ | -------------------- |
+| latency churn 1 thread (ns) | 13.0 / 16.9 / 19.5 | 1.95 / 3.27 / 5.20 | 4.56 / 7.16 / 9.12 | 3.91 / 7.81 / 9.77 | 3.27 / 5.22 / 8.46 |
+| latency churn 8 threads (ns) | 57.3 / 108.1 / 142.6 | 1.95 / 3.91 / 5.22 | 7.16 / 15.6 / 22.1 | 3.91 / 7.81 / 10.4 | 3.91 / 7.17 / 10.4 |
+| latency remote frees (ns) | 29.3 / 118.5 / 369.8 | 1.31 / 37.8 / 313.2 | 6.51 / 304.7 / 597.0 | 7.81 / 43.6 / 74.2 | 6.50 / 204.4 / 946.0 |
+
+### Summary
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, pair | 0.56 | 3.75 | 1.00 | 0.55 | 1.71 |
+| speed, bulk | 0.27 | 1.48 | 1.00 | 0.43 | 0.81 |
+| speed, churn | 0.30 | 2.55 | 1.00 | 1.47 | 1.60 |
+| speed, sharing | 0.55 | 3.06 | 1.00 | 2.10 | 1.57 |
+| speed, false sharing | 0.87 | 1.00 | 1.00 | 0.68 | 1.00 |
+| speed, collections | 0.71 | 1.29 | 1.00 | 0.67 | 1.19 |
+| speed, resizing | 1.00 | 1.03 | 1.00 | 0.95 | 0.86 |
+| speed, large | 0.98 | 1.08 | 1.00 | 0.15 | 0.12 |
+| speed, all workloads | 0.52 | 2.09 | 1.00 | 0.87 | 1.22 |
+| memory held afterwards | 2.37 | 3.13 | 1.00 | 0.96 | 3.91 |
+| peak resident memory | 0.99 | 0.98 | 1.00 | 0.99 | 1.09 |
+| speed, mean of groups | 0.59 | 1.68 | 1.00 | 0.68 | 0.90 |
+| speed, cold | 0.52 | 2.05 | 1.00 | 0.87 | 1.23 |
+| latency, p99 | 0.54 | 4.14 | 1.00 | 2.34 | 1.65 |
+
+
+
+
+### Linux
+
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, pair | 1.06 | 2.90 | 1.00 | 0.65 | 1.72 |
+| speed, bulk | 0.13 | 1.15 | 1.00 | 0.33 | 0.56 |
+| speed, churn | 0.82 | 2.23 | 1.00 | 1.67 | 1.71 |
+| speed, sharing | 0.33 | 2.02 | 1.00 | 2.17 | 1.09 |
+| speed, false sharing | 0.90 | 1.00 | 1.00 | 1.00 | 1.00 |
+| speed, collections | 0.61 | 1.07 | 1.00 | 0.72 | 0.94 |
+| speed, resizing | 1.02 | 1.09 | 1.00 | 0.60 | 0.90 |
+| speed, large | 0.44 | 1.10 | 1.00 | 0.08 | 0.23 |
+| speed, all workloads | 0.63 | 1.73 | 1.00 | 0.88 | 1.14 |
+| memory held afterwards | 11.88 | 2.89 | 1.00 | 1.06 | 1.10 |
+| peak resident memory | 2.12 | 1.82 | 1.00 | 1.82 | 1.49 |
+| speed, mean of groups | 0.55 | 1.45 | 1.00 | 0.63 | 0.88 |
+| speed, cold | 0.62 | 1.73 | 1.00 | 0.86 | 1.08 |
+| latency, p99 | 0.91 | 2.98 | 1.00 | 1.64 | 1.96 |
+
+
+
+
+Every workload on Linux
+
+Median of 10 runs. Bold marks the best median and every median whose 95% bootstrap interval overlaps it.
+
+### pair
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| --------------------- | ------ | --------- | -------- | -------- | --------- |
+| pair 16 B (Mops/s) | 130.0 | 298.6 | 283.7 | 251.8 | **342.7** |
+| pair 64 B (Mops/s) | 130.6 | 289.3 | 241.1 | 249.6 | **335.8** |
+| pair 256 B (Mops/s) | 130.6 | 284.4 | 211.0 | 241.4 | **303.2** |
+| pair 1 KiB (Mops/s) | 130.0 | **291.6** | 140.6 | 215.1 | **279.2** |
+| pair 4 KiB (Mops/s) | 55.7 | **290.0** | 60.3 | 153.7 | 190.8 |
+| pair 16 KiB (Mops/s) | 54.9 | **185.0** | 55.3 | 54.3 | **186.8** |
+| pair 64 KiB (Mops/s) | 54.1 | **203.9** | 55.3 | 4.04 | 189.6 |
+| pair 256 KiB (Mops/s) | 57.4 | **130.5** | 55.3 | 4.08 | 20.3 |
+| pair 1 MiB (Mops/s) | 57.3 | **130.7** | 4.48 | 4.06 | 9.29 |
+
+### pair, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| --------------------- | ------ | --------- | -------- | -------- | --------- |
+| pair 16 B (Mops/s) | 130.5 | 300.8 | 283.4 | 251.6 | **342.6** |
+| pair 64 B (Mops/s) | 130.6 | 283.8 | 257.0 | 249.5 | **335.4** |
+| pair 256 B (Mops/s) | 130.6 | 293.2 | 211.6 | 241.2 | **303.1** |
+| pair 1 KiB (Mops/s) | 130.6 | **292.8** | 140.5 | 216.1 | **279.2** |
+| pair 4 KiB (Mops/s) | 55.7 | **289.9** | 60.3 | 153.1 | 190.8 |
+| pair 16 KiB (Mops/s) | 54.9 | **185.7** | 55.1 | 54.3 | **186.1** |
+| pair 64 KiB (Mops/s) | 54.1 | **206.2** | 55.3 | 4.06 | 188.4 |
+| pair 256 KiB (Mops/s) | 57.3 | **134.0** | 55.2 | 4.07 | 20.3 |
+| pair 1 MiB (Mops/s) | 56.7 | **132.9** | 4.46 | 4.05 | 9.29 |
+
+### bulk
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | ------ | --------- | --------- | -------- | -------- |
+| bulk 32 B in order (Mops/s) | 22.2 | 172.0 | **190.7** | 52.7 | 125.1 |
+| bulk 32 B shuffled (Mops/s) | 9.07 | **105.1** | 87.2 | 44.2 | 62.7 |
+| bulk 512 B shuffled (Mops/s) | 7.10 | **59.0** | 42.4 | 11.3 | 16.2 |
+
+### bulk, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | ------ | --------- | --------- | -------- | -------- |
+| bulk 32 B in order (Mops/s) | 25.9 | **158.8** | **165.4** | 41.8 | 67.7 |
+| bulk 32 B shuffled (Mops/s) | 9.97 | **99.4** | 80.6 | 37.0 | 43.7 |
+| bulk 512 B shuffled (Mops/s) | 4.82 | **41.4** | 32.1 | 6.38 | 7.62 |
+
+### churn
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------------------- | -------- | ---------- | -------- | -------- | --------- |
+| churn small (Mops/s) | 61.4 | 119.4 | 69.7 | 108.5 | **125.1** |
+| churn medium (Mops/s) | 36.3 | **116.0** | 41.6 | 82.0 | 80.8 |
+| churn mixed (Mops/s) | 38.7 | **118.0** | 58.1 | 86.8 | 87.9 |
+| churn skewed (Mops/s) | 51.6 | **137.8** | 126.2 | 119.8 | 120.8 |
+| churn mixed 4 threads (Mops/s) | 149.4 | **466.1** | 126.0 | 340.6 | 342.8 |
+| churn mixed 8 threads (Mops/s) | 299.2 | **937.0** | 245.2 | 676.3 | 662.2 |
+| churn mixed 16 threads (Mops/s) | 593.0 | **1713.0** | 466.4 | 1333.0 | 1304.0 |
+| churn skewed 8 threads (Mops/s) | 394.2 | **1078.0** | 860.1 | 936.2 | 946.0 |
+| churn mixed oversubscribed (Mops/s) | 1094.0 | **3185.0** | 1216.0 | 2338.0 | 2423.0 |
+| churn large set (Mops/s) | 5.00 | **24.7** | 6.44 | 10.0 | 10.8 |
+| churn with work (Mops/s) | **2.01** | **2.11** | **2.16** | 1.95 | **2.08** |
+
+### churn, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------------------- | ------ | ---------- | -------- | ---------- | --------- |
+| churn small (Mops/s) | 61.1 | 119.6 | 69.9 | 108.3 | **125.1** |
+| churn medium (Mops/s) | 36.1 | **115.1** | 41.6 | 81.1 | 80.3 |
+| churn mixed (Mops/s) | 38.5 | **117.1** | 57.9 | 85.9 | 86.9 |
+| churn skewed (Mops/s) | 50.7 | **136.2** | 125.0 | 118.5 | 119.6 |
+| churn mixed 4 threads (Mops/s) | 147.4 | **457.8** | 128.9 | 338.1 | 337.4 |
+| churn mixed 8 threads (Mops/s) | 290.8 | **913.7** | 248.2 | 671.4 | 656.0 |
+| churn mixed 16 threads (Mops/s) | 558.2 | **1554.0** | 478.4 | **1316.0** | 1251.0 |
+| churn skewed 8 threads (Mops/s) | 390.5 | **1061.0** | 819.6 | 928.9 | 945.6 |
+| churn mixed oversubscribed (Mops/s) | 992.4 | **3182.0** | 1416.0 | 2312.0 | 2406.0 |
+| churn large set (Mops/s) | 3.86 | **20.5** | 6.09 | 6.57 | 6.29 |
+| churn with work (Mops/s) | 1.93 | **2.18** | **2.06** | 1.96 | **2.04** |
+
+### sharing
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | --------- | -------- | --------- | -------- |
+| larson 8 threads (Mops/s) | 145.5 | **817.1** | 405.6 | 635.4 | 555.9 |
+| ring 4 threads (Mops/s) | 9.68 | 76.4 | 24.0 | **120.0** | 34.2 |
+| ring 8 threads (Mops/s) | 17.4 | 152.0 | 47.6 | **234.0** | 68.5 |
+| channel 1 pair (Mops/s) | 1.19 | 8.54 | 5.42 | **9.17** | 4.94 |
+| channel 4 pairs (Mops/s) | 4.58 | 28.1 | 20.3 | **33.4** | 19.0 |
+| shared table 8 threads (Mops/s) | 4.31 | **82.0** | 29.2 | 69.0 | 22.1 |
+| thread lifecycle (Mops/s) | 70.8 | **77.0** | 69.8 | 62.5 | 69.0 |
+
+### sharing, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | --------- | -------- | --------- | -------- |
+| larson 8 threads (Mops/s) | 142.6 | **802.8** | 418.6 | 622.8 | 545.1 |
+| ring 4 threads (Mops/s) | 9.63 | 76.4 | 23.8 | **119.0** | 34.5 |
+| ring 8 threads (Mops/s) | 17.2 | 151.1 | 47.2 | **227.9** | 68.7 |
+| channel 1 pair (Mops/s) | 1.17 | **8.38** | 5.47 | **8.89** | 5.01 |
+| channel 4 pairs (Mops/s) | 4.55 | 28.1 | 20.8 | **32.5** | 19.0 |
+| shared table 8 threads (Mops/s) | 4.29 | **81.2** | 28.9 | 68.3 | 21.9 |
+| thread lifecycle (Mops/s) | 70.3 | **76.7** | 68.2 | 61.3 | 68.4 |
+
+### false sharing
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| -------------------------------- | ------- | -------- | ----------- | -------- | ----------- |
+| cache scratch 8 threads (Mops/s) | 49250.0 | 59790.0 | **59990.0** | 59900.0 | **59970.0** |
+| cache thrash 8 threads (Mops/s) | 59770.0 | 59800.0 | **59990.0** | 59900.0 | **59990.0** |
+
+### false sharing, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| -------------------------------- | ------- | -------- | ----------- | -------- | ----------- |
+| cache scratch 8 threads (Mops/s) | 42410.0 | 59780.0 | **59960.0** | 59690.0 | **59960.0** |
+| cache thrash 8 threads (Mops/s) | 59760.0 | 59790.0 | **59970.0** | 59710.0 | **59960.0** |
+
+### collections
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | -------- | --------- | -------- | --------- |
+| hash map (Mops/s) | 4.08 | **9.48** | 7.89 | 7.06 | 7.56 |
+| btree map (Mops/s) | 2.88 | **5.31** | 4.50 | 4.77 | 4.48 |
+| strings (Mops/s) | 6.04 | **7.25** | 7.18 | 6.01 | **7.21** |
+| linked list (Mops/s) | 85.5 | 161.9 | **164.7** | 78.2 | 129.8 |
+| binary trees (Mops/s) | 62.4 | **96.2** | **96.0** | 58.7 | 90.9 |
+| tree rewrite (Mops/s) | 37.5 | 104.8 | 101.1 | 55.9 | **107.2** |
+| binary trees with work (Mops/s) | 45.2 | **51.5** | 47.7 | 36.1 | 41.9 |
+
+### collections, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ------------------------------- | ------ | --------- | --------- | -------- | --------- |
+| hash map (Mops/s) | 4.47 | **9.30** | 7.49 | 6.38 | 6.05 |
+| btree map (Mops/s) | 3.62 | **5.30** | 4.39 | 4.45 | 4.14 |
+| strings (Mops/s) | 5.72 | **7.24** | 7.17 | 5.91 | 7.07 |
+| linked list (Mops/s) | 72.8 | **154.5** | **149.3** | 68.2 | 101.3 |
+| binary trees (Mops/s) | 57.1 | **92.8** | **95.0** | 56.1 | 85.6 |
+| tree rewrite (Mops/s) | 45.4 | 104.5 | 101.4 | 55.8 | **107.5** |
+| binary trees with work (Mops/s) | 44.4 | **51.4** | 47.6 | 35.9 | 41.2 |
+
+### resizing
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ---------- | -------- | -------- | -------- | -------- |
+| vec growth (Mops/s) | **1820.0** | 1557.0 | 1348.0 | 280.5 | 978.0 |
+| string growth (Mops/s) | **1876.0** | 1794.0 | 1791.0 | 1816.0 | 1689.0 |
+| many vectors (Mops/s) | **332.2** | 277.6 | 279.2 | 272.3 | 294.9 |
+| realloc random (Mops/s) | 5.39 | **10.4** | 8.39 | 5.32 | 7.50 |
+
+### resizing, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ----------------------- | ---------- | ---------- | -------- | -------- | -------- |
+| vec growth (Mops/s) | 1440.0 | **1489.0** | 1310.0 | 273.7 | 793.4 |
+| string growth (Mops/s) | **1813.0** | 1771.0 | 1779.0 | 1763.0 | 1630.0 |
+| many vectors (Mops/s) | **326.0** | 275.1 | 276.1 | 246.1 | 275.5 |
+| realloc random (Mops/s) | 5.39 | **10.3** | 8.39 | 5.30 | 7.45 |
+
+### large
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| medium blocks (Mops/s) | 0.22 | **1.22** | 1.04 | 0.66 | 0.53 |
+| large blocks (Mops/s) | 0.10 | **0.11** | 0.10 | 0.00 | 0.01 |
+
+### large, cold
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| medium blocks (Mops/s) | 0.22 | **1.20** | 1.00 | 0.55 | 0.49 |
+| large blocks (Mops/s) | 0.04 | **0.09** | **0.07** | 0.00 | 0.01 |
+
+### memory
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| --------------------- | --------- | -------- | -------- | -------- | --------- |
+| burst retention (MiB) | **0.20** | 10.7 | 260.1 | 269.1 | 261.3 |
+| half freed (MiB) | 183.2 | 157.4 | 156.0 | 157.0 | **153.4** |
+| phase churn (MiB) | **133.3** | 196.2 | 197.0 | 156.9 | 149.7 |
+
+### latency
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | ------ | -------- | -------- | --------- | -------- |
+| latency churn 1 thread (ns) | 19.2 | **6.72** | 11.4 | 18.2 | 7.50 |
+| latency churn 8 threads (ns) | 19.7 | **6.88** | 31.5 | 18.6 | 8.45 |
+| latency remote frees (ns) | 566.7 | 134.8 | 457.3 | **109.9** | 347.0 |
+
+### latency, latency (p50 / p99 / p999)
+
+| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------------- | --------------------- | -------------------- | --------------------- | -------------------- | -------------------- |
+| latency churn 1 thread (ns) | 11.6 / 19.2 / 64.4 | 3.91 / 6.72 / 9.53 | 7.34 / 11.4 / 17.2 | 4.53 / 18.2 / 23.1 | 5.07 / 7.50 / 15.6 |
+| latency churn 8 threads (ns) | 12.0 / 19.7 / 59.4 | 4.06 / 6.88 / 10.0 | 12.6 / 31.5 / 51.6 | 5.17 / 18.6 / 23.6 | 5.00 / 8.45 / 20.0 |
+| latency remote frees (ns) | 185.9 / 566.7 / 752.2 | 20.2 / 134.8 / 198.0 | 101.3 / 457.3 / 650.0 | 41.2 / 109.9 / 161.3 | 26.6 / 347.0 / 459.9 |
+
+### Summary
+
+| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
+| ---------------------- | ------ | -------- | -------- | -------- | -------- |
+| speed, pair | 1.06 | 2.90 | 1.00 | 0.65 | 1.72 |
+| speed, bulk | 0.13 | 1.15 | 1.00 | 0.33 | 0.56 |
+| speed, churn | 0.82 | 2.23 | 1.00 | 1.67 | 1.71 |
+| speed, sharing | 0.33 | 2.02 | 1.00 | 2.17 | 1.09 |
+| speed, false sharing | 0.90 | 1.00 | 1.00 | 1.00 | 1.00 |
+| speed, collections | 0.61 | 1.07 | 1.00 | 0.72 | 0.94 |
+| speed, resizing | 1.02 | 1.09 | 1.00 | 0.60 | 0.90 |
+| speed, large | 0.44 | 1.10 | 1.00 | 0.08 | 0.23 |
+| speed, all workloads | 0.63 | 1.73 | 1.00 | 0.88 | 1.14 |
+| memory held afterwards | 11.88 | 2.89 | 1.00 | 1.06 | 1.10 |
+| peak resident memory | 2.12 | 1.82 | 1.00 | 1.82 | 1.49 |
+| speed, mean of groups | 0.55 | 1.45 | 1.00 | 0.63 | 0.88 |
+| speed, cold | 0.62 | 1.73 | 1.00 | 0.86 | 1.08 |
+| latency, p99 | 0.91 | 2.98 | 1.00 | 1.64 | 1.96 |
+
+
+
diff --git a/Cargo.lock b/Cargo.lock
index e5e9de3..36c8bd0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -30,6 +30,7 @@ name = "bcmalloc-bench"
version = "0.0.0"
dependencies = [
"bcmalloc",
+ "bcmalloc-bench-data",
"libc",
"mimalloc",
"snmalloc-rs",
@@ -57,6 +58,14 @@ dependencies = [
"tokio",
]
+[[package]]
+name = "bcmalloc-bench-data"
+version = "0.0.0"
+dependencies = [
+ "serde",
+ "serde_json",
+]
+
[[package]]
name = "bcmalloc-cabi"
version = "0.0.0"
diff --git a/DESIGN.md b/DESIGN.md
index 34f9890..0595484 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -1,8 +1,8 @@
# How bcmalloc works
-**Tldr.** bcmalloc is a global allocator for Rust programs that run for a long time, on many threads, and free memory on threads other than the one that allocated it. It reserves one region of address space when the program starts and carves everything out of it. A thread allocates by popping a pointer off a small stack for the size class, and frees by pushing it back, with no atomic instructions and without touching the block. Blocks freed by another thread travel home in batches of pointers, so neither thread walks or writes memory that the other core holds. Idle memory goes back to the operating system on a clock, in whole huge pages on Linux.
+**Tldr.** bcmalloc is a global allocator for Rust programs that run for a long time, on many threads, and free memory on threads other than the one that allocated it. It reserves one region of address space when the program starts and carves everything out of it. A thread allocates by popping a pointer off a small stack for the size class, and frees by pushing it back, with no atomic instructions and without touching the block. Blocks freed by another thread travel home in batches of pointers, so neither thread walks or writes memory that the other core holds, and small blocks that fill whole cache lines are reused where they are freed. Idle memory goes back to the operating system on a clock. On Linux, heaps big enough to fill transparent huge pages get them, and give them back whole.
-This document explains the design, where each idea comes from, and what each choice costs. Benchmark results close the document.
+This document explains the design, where each idea comes from, and what each choice costs. The measurements are in [BENCHMARKS.md](https://github.com/clabby/bcmalloc/blob/main/BENCHMARKS.md).
## 1. Introduction
@@ -19,15 +19,19 @@ bcmalloc is built from techniques that other allocators have proven, put togethe
| One reservation, sized up front, as a hard limit | TigerBeetle's static allocation[^tigerbeetle] |
| Chunks claimed with one atomic change to a bitmap word | LLFree[^llfree] |
| Any empty slab can become any size class | jwmalloc's uniform slab pool[^jwmalloc] |
+| Size classes 8 bytes apart for small values | TCMalloc[^tcmalloc] and mimalloc[^mimalloc] |
+| Large requests served as runs of their own | jemalloc's large extents[^jemalloc] |
| Per-thread caches that are arrays of pointers | jemalloc[^jemalloc] and TCMalloc[^tcmalloc] |
| Caches that grow when a class keeps missing | TCMalloc's per-CPU cache sizing[^tcmalloc] |
| Remote frees sent home to the owning heap in batches | snmalloc[^snmalloc] |
-| Blocks return to their owner unless they share no line | Hoard's ownership rule[^hoard] |
+| Blocks go home unless they are small and own their lines | Hoard's ownership rule[^hoard] |
| Free blocks tracked in a bitmap outside the slab | jemalloc's slab bitmaps[^jemalloc] |
| A map from address to owner and size class | the pagemaps of TCMalloc and snmalloc |
-| Huge pages filled densely and given back whole | Temeraire[^temeraire] and mimalloc[^mimalloc-thp] |
+| Huge pages for heaps that fill them, given back whole | Temeraire[^temeraire] and mimalloc[^mimalloc-thp] |
+| Fresh memory is not cleared again | mimalloc[^mimalloc] and jemalloc[^jemalloc] |
| A realloc that keeps a block that still fits | mimalloc[^mimalloc] |
| One part of the address space per NUMA node | the node-local arenas common to server allocators |
+| Per-thread counters summed on demand | the statistics of TCMalloc and jemalloc |
## 2. Background
@@ -37,7 +41,7 @@ Rust gives a global allocator a small contract[^globalalloc]. A small C library
- The allocator must never unwind, and it must not allocate while it allocates. A lot of the standard library allocates, so the allocator stays on the thread-local storage and atomics that are documented not to.
- Returning null means failure, and the caller decides what to do.
-The allocator is five layers, and each one is small.
+The allocator is built in layers, from the thread down to the reservation.

@@ -47,11 +51,11 @@ The allocator is five layers, and each one is small.
At first use the allocator asks the operating system for one big mapping and never asks again. The mapping is read-write anonymous memory flagged so that the kernel does not charge the whole size against the commit limit. Nothing is backed by a physical page until it is touched, so reserving 64 GiB costs address space and nothing else.
-The mapping holds the allocator's own metadata and the memory it hands out, laid out so that the zero-filled pages the kernel provides are already a valid starting state. Nothing is written at start-up.
+The mapping holds the allocator's own metadata and the memory it hands out, laid out so that the zero-filled pages the kernel provides are already a valid starting state. Beyond the region's header, nothing is written at start-up.

-**Figure 2.** The reservation. Metadata costs about 1% of the managed memory, plus about 110 KiB of bin slots for each heap slot. A pointer finds its chunk map entry with a subtraction and a shift, and its slab descriptor with a mask on top.
+**Figure 2.** The reservation. Metadata costs about 1% of the managed memory, plus about 280 KiB of address space for the bin slots of each heap slot. A pointer finds its chunk map entry with a subtraction and a shift, and its slab descriptor with a mask on top.
Metadata sits next to the memory it describes and never inside a slab. The descriptors, the chunk map and the bitmaps are separate from the blocks the program uses, and the allocator does not keep its own state in the blocks it hands out. Only blocks on their way home to another heap carry allocator data, as section 7 describes.
@@ -62,14 +66,25 @@ A few parts of the OS interface differ between the supported platforms, and the
| Operation | Linux | macOS |
| ------------ | ---------------------------------- | ------------------------------ |
| reserve | mmap with MAP_NORESERVE | mmap with MAP_NORESERVE |
-| huge pages | madvise MADV_HUGEPAGE | none, there is no THP |
+| huge pages | madvise MADV_HUGEPAGE on one zone | none, there is no THP |
| NUMA parts | mbind with a preferred node | none |
| populate | MADV_POPULATE_WRITE, else touch | touch every page |
| lock | mlock | mlock |
| discard | MADV_DONTNEED, reads back zeros | MADV_FREE_REUSABLE, not zeroed |
| reuse | nothing | MADV_FREE_REUSE |
-**Huge pages.** On Linux the region asks for transparent huge pages, as mimalloc does by default there[^mimalloc-thp]. A 2 MiB page needs one TLB entry where 4 KiB pages need 512, so programs whose working set is larger than the TLB covers stop paying for address translation. The cost is that memory is backed, and given back, 2 MiB at a time. Section 9 explains how the allocator keeps that cost down.
+**Huge pages.** On Linux part of the region asks for transparent huge pages. A 2 MiB page needs one TLB entry where 4 KiB pages need 512, so programs whose working set is larger than the TLB covers stop paying for address translation, and a fresh huge page costs one page fault instead of 512. The cost is that memory is backed, and given back, 2 MiB at a time, so a huge page that is touched in one place is resident in all of it. The part of the region of each NUMA node is therefore split into two zones. The lower one uses small pages, and the upper one is a single range advised with `MADV_HUGEPAGE`. Memory goes to the huge-page zone when it will be used densely.
+
+- A heap counts as big once the slabs it has filled and the blocks of whole chunks it holds add up to 1 MiB. It stays big until they fall below 256 KiB, so that a heap whose size swings around the threshold keeps its zone.
+- Single-chunk slabs of a big heap come from the huge-page zone. They fill quickly and pack next to each other.
+- A slab of several chunks holds few large blocks and may stay mostly untouched, so it comes from the huge-page zone only once the heap has filled a slab of its class.
+- A block of whole chunks is usually a buffer or an arena that the program fills. It comes from the huge-page zone when its heap is big, and always when it spans 2 MiB or more.
+
+
+
+**Figure 3.** The two zones. Threads that each use a little memory never hold a huge page they barely touch, and a heap that fills huge pages gets them.
+
+Section 10 explains how huge pages are kept whole once they are in use.
**NUMA.** On a machine with more than one NUMA node, the chunks are split into one contiguous part per node, and each part asks the kernel to prefer its node's memory. A heap takes its slabs from the part of the node its thread was running on when it claimed the heap, and borrows from the other parts only when its own is full. A thread's memory therefore sits on its own node without the allocator ever asking where it runs on the fast path.
@@ -83,9 +98,9 @@ A request for a run of up to 64 chunks fits in one bitmap word. To find a run of

-**Figure 3.** Claiming chunks. The fold finds every run start in a word with a few shifts and ANDs. The claim is one compare-and-swap. A run longer than a word claims whole words one at a time and gives them back if it loses.
+**Figure 4.** Claiming chunks. The fold finds every run start in a word with a few shifts and ANDs. The claim is one compare-and-swap. A run longer than a word claims whole words one at a time and gives them back if it loses.
-Freeing a run is one `fetch_and` per word it touches. Neighbouring free chunks coalesce simply by being neighbours, because there is nothing to merge. Every transaction is a single atomic change to one word, which is the rule LLFree is built on[^llfree]. There is never a moment when a chunk belongs to nothing, so a concurrent search can never be told that the region is full while memory is free.
+Freeing a run is one `fetch_and` per word it touches. Neighbouring free chunks coalesce by being neighbours, because there is nothing to merge. Every transaction is a single atomic change to one word, which is the rule LLFree is built on[^llfree]. There is never a moment when a chunk belongs to nothing, so a concurrent search can never be told that the region is full while memory is free.
Where a run goes matters for memory as much as for speed.
@@ -95,27 +110,28 @@ Where a run goes matters for memory as much as for speed.
## 5. Size classes and slabs
-A request of up to 512 KiB is rounded up to one of 104 size classes. Classes are 16 bytes apart up to 128 bytes. Above that there are eight per doubling, so rounding wastes at most one part in eight.
+A request of up to 64 KiB is rounded up to one of 87 size classes. Classes are 8 bytes apart from 16 to 128 bytes, as in TCMalloc and mimalloc[^tcmalloc][^mimalloc], so the many Rust values of three, five or seven words fill their blocks. Above 128 bytes there are eight classes per doubling, so rounding wastes at most one part in eight.

-**Figure 4.** Rounding waste by request size. Each dot is the worst request for one class. The three shaded bands show which slab size serves which blocks.
+**Figure 5.** Rounding waste by request size. Each dot is the worst request for one class. The two shaded bands show which slab size serves which blocks.
Each class is carved out of slabs, which are runs of chunks aligned to their own size. Bigger blocks get bigger slabs, so every slab holds at least eight blocks and the unusable tail is smaller than one block.
-| Block size | Slab | Blocks per slab |
-| ----------------- | ----------- | --------------- |
-| 16 B to 8 KiB | 64 KiB (1) | 8 to 4096 |
-| 8 KiB to 64 KiB | 512 KiB (8) | 8 to 56 |
-| 64 KiB to 512 KiB | 4 MiB (64) | 8 to 56 |
+| Block size | Slab | Blocks per slab |
+| --------------- | ----------- | --------------- |
+| 16 B to 8 KiB | 64 KiB (1) | 8 to 4096 |
+| 8 KiB to 64 KiB | 512 KiB (8) | 8 to 56 |
+
+Alignment falls out of the geometry. A slab starts on a multiple of its own size and a block on a multiple of its size within the slab, so a block is aligned to the largest power of two that divides its size, and at least to 8 bytes. A request that asks for 16 bytes of alignment, which C's malloc always does, is rounded up to a multiple of 16 first. A request for more alignment is rounded up to a power of two at least that large. The largest alignment supported is one chunk, 64 KiB.
-Alignment falls out of the geometry. Every class size is a multiple of 16 and every slab starts on a multiple of its own size, so every block is 16-byte aligned. A request for more alignment is rounded up to a power of two at least that large, and a block of such a class starts at a multiple of its size. The largest alignment supported is one chunk, 64 KiB. Anything above 512 KiB gets a run of whole chunks to itself.
+Anything above 64 KiB gets a run of whole chunks to itself, as jemalloc gives large requests extents of their own[^jemalloc]. A slab of such blocks would hold so few of them that one partly used slab per class and heap would cost more than rounding up to whole chunks does.
**Free blocks.** A slab's descriptor holds a bitmap with one bit per block, set while the block is free. Taking a block back sets its bit. A refill collects set bits a word at a time, lowest first, and a word whose bits are all set yields 64 blocks without a search. This is how jemalloc tracks the free regions of its slabs[^jemalloc]. Neither operation reads or writes the memory of a block. A list threaded through the free blocks would make a refill read each block to find the next, every read waiting on the one before, and make every free write into a block whose cache line may be cold or held by another core.

-**Figure 5.** Anatomy of a slab. The descriptor lives outside the slab and only the owning heap touches it. Blocks in a heap's bins, in messages on their way home, or in the program's hands all count as in use.
+**Figure 6.** Anatomy of a slab. The descriptor lives outside the slab and only the owning heap touches it. Blocks in a heap's bins, in messages on their way home, or in the program's hands all count as in use.
A block's index in its slab is its offset divided by the block size. The class sizes are not powers of two, so the division is a multiplication by a precomputed reciprocal and a shift, which is exact for every offset in a slab. jemalloc divides by its bin sizes the same way[^jemalloc-div].
@@ -123,7 +139,7 @@ A block's index in its slab is its offset divided by the block size. The class s

-**Figure 6.** Reuse across classes. An allocator that keeps a free list per size class cannot do this, because a freed 64 byte block cannot serve a 4 KiB request. Here the only memory that is ever free for reuse is a whole slab.
+**Figure 7.** Reuse across classes. An allocator that keeps a free list per size class cannot do this, because a freed 64 byte block cannot serve a 4 KiB request. Here the only memory that is ever free for reuse is a whole slab.
Each class keeps one empty slab, so that a loop that allocates and frees one block does not move a slab in and out of the bitmap.
@@ -133,15 +149,15 @@ A heap is a thread's private view of the region. For each size class it keeps a

-**Figure 7.** A heap's bins. Allocating pops the top pointer and freeing pushes one. An empty bin is refilled to half from the front slab's bitmap, and a full bin gives its older half back.
+**Figure 8.** A heap's bins. Allocating pops the top pointer and freeing pushes one. An empty bin is refilled to half from the front slab's bitmap, and a full bin gives its older half back.
-The fast path of an allocation is a table lookup for the class and a pop. The fast path of a free is one load from the chunk map and a push. Neither uses an atomic instruction or touches the block. The bins are the thread caches of jemalloc and the per-CPU arrays of TCMalloc[^jemalloc][^tcmalloc]. Because a bin is a stack, a block that was just freed is the next one handed out, while it is still in the cache.
+The fast path of an allocation is a table lookup for the bin and a pop. The fast path of a free is one load from the chunk map, whose entry names the owning heap and the bin, and a push. Neither uses an atomic instruction or touches the block, and in the C library malloc compiles to 20 instructions and free to 27. The bins are the thread caches of jemalloc and the per-CPU arrays of TCMalloc[^jemalloc][^tcmalloc]. Because a bin is a stack, a block that was just freed is the next one handed out, while it is still in the cache.
-Each bin is a range of pointer slots in the region, with its top pointer kept next to the bin's two limits. Whether the bin is empty or full is a comparison of the low 16 bits of the top pointer with a limit, because a bin spans at most 4 KiB. The thread finds its heap in one thread-local load. On Apple silicon it reads the slot straight from the thread's key table through the thread pointer register, which is the load that the system's own lookup does, without the call. Creating the key stores a marker through the public interface and reads it back through the register, and the key is refused if the two disagree, so a change in the operating system's layout shows up as a failed allocation and not as corruption. Elsewhere the heap pointer sits in an ordinary thread-local.
+Each bin is a range of pointer slots in the region, with its top pointer kept next to the bin's two limits. Whether the bin is empty or full is a comparison of the low 16 bits of the top pointer with a limit, because a bin spans at most 16 KiB. The thread finds its heap in one thread-local load. On Apple silicon it reads the slot straight from the thread's key table through the thread pointer register, which is the load that the system's own lookup does, without the call. Creating the key stores a marker through the public interface and reads it back through the register, and the key is refused if the two disagree, so a change in the operating system's layout shows up as a failed allocation and not as corruption. Elsewhere the heap pointer sits in an ordinary thread-local.
**Refills and flushes.** An empty bin first looks at the heap's inbox, where other threads send blocks home, and then fills half its capacity from the front slab with room. Blocks come out of each slab in address order, and the bin hands them out in the same order, so a run of allocations walks memory upwards. A slab that runs out moves to the full list. A full bin gives back its older half, and blocks that follow each other in one slab go back with one look at the slab and one write per bitmap word.
-**Sizing.** A bin starts with room for about 32 KiB of blocks of its class, at least 8 and at most 128 pointers, and a bin for a class above 8 KiB with room for about 64 KiB, between 1 and 8 pointers. When a class alternates between running dry and overflowing, which is a sign that its bursts are bigger than the bin, the bin doubles, up to a limit and within a budget of 2 MiB for the whole heap. A bin that has not missed for a while is halved again. This is how TCMalloc sizes its per-CPU caches[^tcmalloc]. A program that builds and drops trees of a few thousand nodes then keeps them all in the bin, and a quiet class holds little.
+**Sizing.** A bin starts with room for about 32 KiB of blocks of its class, at least 8 and at most 128 pointers, and a bin for a class above 8 KiB with room for about 64 KiB, between 1 and 8 pointers. When a class alternates between running dry and overflowing, which is a sign that its bursts are bigger than the bin, the bin doubles, up to 2048 pointers for classes of up to 64 bytes and about 128 KiB of blocks for the others, within a budget of 2 MiB for the whole heap. A bin that has not missed for a while is halved again. This is how TCMalloc sizes its per-CPU caches[^tcmalloc]. A program that builds and drops trees of a few thousand nodes then keeps them all in the bin, and a quiet class holds little.
**Heap lifetime.** A heap is a slot in the region and not a property of a thread. When a thread exits, its heap empties its bins and outboxes and goes back to the pool with all its slabs, and the next thread to start takes it. A thread that is about to go quiet can call `Bcmalloc::flush_thread` to hand back what its heap keeps, as jemalloc's thread cache flush does.
@@ -149,33 +165,41 @@ Each bin is a range of pointer slots in the region, with its top pointer kept ne
A free reads the chunk map entry of the block, which names the heap that owns its slab. If that is the calling thread's heap, the block goes into the bin. Otherwise there are two cases.
-**Blocks that share no cache line.** If the class size is a multiple of the cache line, 64 bytes on x86-64 and 128 bytes on Apple silicon, and its slab is a single chunk, the block goes into the freeing thread's own bin and can be handed out again there. The block cannot share a line with any other block, because blocks start at multiples of their size. A thread that reuses it therefore never writes next to a block that its owner still uses, which is the false sharing that Hoard's rule of returning blocks to their owner exists to prevent[^hoard]. jemalloc and TCMalloc reuse any freed block in the freeing thread[^jemalloc][^tcmalloc]. bcmalloc keeps that speed where it is safe and limits a held block to pinning one 64 KiB slab.
+**Small blocks that own their cache lines.** If the class size is a multiple of the cache line, 64 bytes on x86-64 and 128 bytes on Apple silicon, and at most 256 bytes, the block goes into the freeing thread's own bin and can be handed out again there. The block cannot share a line with any other block, because blocks start at multiples of their size. A thread that reuses it therefore never writes next to a block that its owner still uses, which is the false sharing that Hoard's rule of returning blocks to their owner exists to prevent[^hoard]. jemalloc and TCMalloc reuse any freed block in the freeing thread[^jemalloc][^tcmalloc]. bcmalloc does so only for these few lines, because a larger block costs more where it was freed than at home. Its owner wrote it and probably still holds its lines, and a thread on another core that reuses it pulls every line it writes across the interconnect. On a machine with several L3 caches, keeping blocks of up to 8 KiB where they were freed halved the throughput of a benchmark that allocates on one core and frees on another.
-**Every other block goes home.** It is appended to an outbox for its owner. A heap keeps 16 outboxes, chosen by the owner's id, so up to 16 destinations fill messages side by side. A message is a 512-byte block of the sender's own that holds 62 pointers. When it is full, holds 64 KiB of blocks, or must make room for another destination, the sender pushes it onto the owner's inbox with one compare-and-swap. A message with a single block sends the block itself instead, tagged in its link. snmalloc returns remote frees to their owner the same way, as messages batched per destination[^snmalloc].
+**Every other block goes home.** It is appended to an outbox for its owner. A heap keeps 16 outboxes, chosen by the owner's id, so up to 16 destinations fill messages side by side. A message is a 512-byte block of the sender's own that holds 62 pointers. When it is full, holds 64 KiB of blocks, or must make room for another destination, the sender pushes it onto the owner's inbox with one compare-and-swap. A message with a single block sends the block itself instead, tagged in its link. snmalloc returns remote frees to their owner the same way, as messages batched per destination[^snmalloc]. A message itself is kept by the heap that reads it, whatever its size, because that heap has just read its lines and reuses it for messages of its own.
-
+
-**Figure 8.** A remote free. The sender writes only pointers, into memory it owns. The owner reads only the message, and files the pointers into its bins without touching the blocks. A block that travels alone is the one exception: its link is written into the block itself.
+**Figure 9.** A remote free. The sender writes only pointers, into memory it owns. The owner reads only the message, and files the pointers into its bins without touching the blocks. A block that travels alone is the one exception, because its link is written into the block itself.
The messages carry pointers and are not lists threaded through the blocks. A list would make the sender write into each freed block, whose cache line usually sits in the owner's core, and the owner would then read every block in turn to find the next. With messages, the only memory that moves between cores is the message itself, one line per eight blocks.
The inbox is a stack that any thread pushes onto and that only its owner empties, with one swap. Nothing is ever popped by anyone else, so the stack cannot suffer the ABA problem. The owner reads it when a bin runs dry, which is when it needs blocks, and also when a bin overflows and before it starts a message of its own, so that a thread that only frees still gets its messages back. It files each pointer into its bin, or into its slab if the bin is full. The chunk map tells it the class of each block. The message itself is then freed like any other block.
-Two properties make this safe. A block in a message still counts as in use in its slab, so the slab cannot be released and its chunk map entry cannot change while the block is on its way. And a heap slot outlives its threads: a heap whose thread has exited keeps its inbox, and the next thread to claim the slot, or a call to `trim`, reads it.
+Two properties make this safe. A block in a message still counts as in use in its slab, so the slab cannot be released and its chunk map entry cannot change while the block is on its way. And a heap slot outlives its threads. A heap whose thread has exited keeps its inbox, and the next thread to claim the slot, or a call to `trim`, reads it.
## 8. Reallocation
-A small block keeps its place when the new size fits in it and wastes at most half of it, which is the rule mimalloc uses[^mimalloc]. A free takes the class from the chunk map and not from the layout, so a block that a realloc kept is still freed as what it is. A huge block that shrinks gives back the chunks past its new end, and one that grows claims the chunks right after it if they are free. Everything else is a new block and a copy.
+A small block keeps its place when the new size fits in it and wastes at most half of it, which is the rule mimalloc uses[^mimalloc]. A free takes the class from the chunk map and not from the layout, so a block that a realloc kept is still freed as what it is. A block of whole chunks that shrinks gives back the chunks past its new end, and one that grows claims the chunks right after it if they are free. Everything else is a new block and a copy.
+
+A heap keeps up to four freed blocks of whole chunks of at most 8 MiB, still claimed in the chunk bitmap, and hands one out again to the next request of the same size. A program that frees and allocates big buffers in a loop then skips the bitmap's atomics and the purge clock. Blocks nobody asks for go back at the heap's next maintenance steps, and a flush returns them at once.
-A heap keeps up to four freed huge blocks of at most 8 MiB, still claimed in the chunk bitmap, and hands one out again to the next request of the same size. A program that frees and allocates big buffers in a loop then skips the bitmap's atomics and the purge clock. Blocks nobody asks for go back at the heap's next maintenance steps, and a flush returns them at once.
+## 9. Zeroed memory
-## 9. Giving memory back
+`calloc` and `alloc_zeroed` must return zeros, and clearing memory that already reads as zeros writes every byte for nothing. The kernel hands out fresh pages full of zeros, and on Linux pages given back with `MADV_DONTNEED` come back as zeros too, so the allocator keeps track of what it has not used since, as mimalloc and jemalloc do[^mimalloc][^jemalloc].
+
+- A run of chunks reads as zeros if none of its chunks was used since it was fresh or, on Linux, since it was given back. The bitmap of chunks freed since their last purge, which section 10 describes, already says which chunks were used, so a claim reads it before it forgets which chunks were purged.
+- A slab set up on such a run remembers the index from which its blocks have never been handed out. A zeroed request whose bin is empty takes its block straight from the slab, and a block beyond that index needs no clearing.
+- A block in a bin may have been used, so a zeroed request that a bin can serve clears it while it is likely still in the cache. Blocks under 1 KiB are cleared without asking, which costs less than finding out.
+
+## 10. Giving memory back
A program that frees a gigabyte and then runs for a month should not keep the gigabyte. The allocator hands free chunks back to the operating system on a clock, and it needs three small pieces of state to do that safely.
Every bitmap word has a timestamp, which is the latest time that a chunk in it was freed. A second bitmap marks the chunks that were freed since they were last given back. A third marks the chunks whose pages are already gone. The clock runs from paths that are slow anyway, which are refills, slab releases and huge frees. When it is due, and a flag says that some chunk may be waiting, one thread makes a pass over the words. A word whose newest free is at least 10 ms old has its idle chunks claimed with a compare-and-swap on the used word, the same operation that allocation uses, so a chunk in use can never be handed to the kernel. The pass advises the kernel about each claimed run, marks it as given back, and releases it. A program that stays quiet pays nothing, and a busy one pays a clock read now and then.
-With huge pages, a pass only takes a 2 MiB page whose 32 chunks are all free. Giving back part of a huge page would split it into small pages and lose the TLB reach it was there for. Temeraire releases whole huge pages for the same reason[^temeraire], and mimalloc's default on Linux is to purge no less than 2 MiB[^mimalloc-thp]. The placement rule of section 4 is what makes whole pages come free: allocations crowd into pages that are already in use.
+In the huge-page zone, a pass only takes a 2 MiB page whose 32 chunks are all free. Giving back part of a huge page would split it into small pages and lose the TLB reach it was there for. Temeraire releases whole huge pages for the same reason[^temeraire], and mimalloc's default on Linux is to purge no less than 2 MiB[^mimalloc-thp]. The placement rule of section 4 is what makes whole pages come free, because allocations crowd into pages that are already in use. The small-page zone gives chunks back one at a time. In the huge-page zone a word also waits ten times as long, 100 ms, before its pages go back. A huge page that is given back and used again costs a fault that clears 2 MiB, which a program that frees and allocates big blocks in turn would otherwise pay every time. jemalloc lets dirty pages decay over seconds for the same reason[^jemalloc].
The next claim of a purged chunk has to know. Allocation checks the given-back bitmap for the run it just claimed and, on macOS, tells the kernel that the pages are in use again. macOS has two ways to give pages back. The lazy one leaves them in the process's footprint until the system is short of memory. The reusable one takes them out of the footprint at once, and wants a matching call before reuse so that the accounting is right. Linux needs no second call, because discarded pages come back as zeros.
@@ -183,162 +207,65 @@ A pass makes free chunks look allocated while it holds them. If a pass holds eve
`trim` is the explicit version. It empties every heap that no thread holds, then gives back every free chunk, whole huge page or not, because the caller asked for it.
-## 10. How it is checked
+## 11. Metrics
+
+With the `metrics` feature, every heap counts what it does, and `Bcmalloc::metrics` or `Region::metrics` sums the counts into a snapshot. For each size class it has the blocks allocated and freed and the slabs held, from which the live bytes and the share of the class's slabs in use follow. It also counts refills, slabs taken and given back, blocks sent home and the messages that carried them, reads of the inbox, huge blocks and the requests the heap's cache of them served, bins that grew and shrank, zeroed requests served from fresh memory, and the work of the purge clock. The snapshot prints as a report, and the C library prints it at exit when `BCMALLOC_SHOW_METRICS` is set, as mimalloc does with `MIMALLOC_SHOW_STATS`.
-Concurrency bugs hide from tests that pass, so the allocator is checked in five independent ways.
+The counters follow the per-thread statistics of TCMalloc and jemalloc. Only the heap's own thread writes them, with a relaxed load and a relaxed store, which compiles to an ordinary add with no locked instruction and no cache line that another core writes. The allocation and free counts sit next to the bin they count, on a line the fast path touches anyway, and everything else is counted on slow paths. A snapshot reads only the counters, never state that another thread owns, so it can be taken while the program runs. Without the feature none of it is compiled.
+
+## 12. How it is checked
+
+Concurrency bugs hide from tests that pass, so the allocator is checked in several independent ways.
| Tool | What it covers |
| -------------------- | ----------------------------------------------------------------------------------------------------- |
| loom | Every interleaving of the chunk bitmap, a purge pass and its flag, heap claims, and inbox pushes |
| Miri | All unit tests under strict provenance, on the portable thread lookup |
| fuzzing | Random operation sequences against a model, with a validator that checks every structure after a step |
+| unit tests | Every module, including a causal test for each bug found, with line coverage reported to Codecov |
| benchmarks | Sixteen threads starting at once, and a fresh process for every workload |
+| preloaded C programs | mimalloc-bench's programs run with debug assertions on, many times over, to catch rare interleavings |
| independent review | Every change, read-only, by a second model that writes its own reproductions |
-The validator deserves a sentence. After every few operations the test harness walks every slab of every heap and checks that each bitmap agrees with its counter, that every slab is on the list its occupancy calls for, and that every pointer in a bin, an outbox, a message or an inbox is a block of the right class that is not free in its slab and appears nowhere else. A bin may hold another heap's block only if its class allows reuse. Several heaps are driven from one thread, which makes cross-heap frees deterministic, so a failing fuzz input replays as a unit test. The real global allocator is also exercised end to end. The integration test binary runs the standard test harness on top of bcmalloc, with producer and consumer threads and a few thousand short-lived threads.
+After every few operations the test harness walks every slab of every heap and checks that each bitmap agrees with its counter, that every slab is on the list its occupancy calls for, and that every pointer in a bin, an outbox, a message or an inbox is a block of the right class that is not free in its slab and appears nowhere else. A bin may hold another heap's block only if its class allows reuse. Several heaps are driven from one thread, which makes cross-heap frees deterministic, so a failing fuzz input replays as a unit test. The real global allocator is also exercised end to end. The integration test binary runs the standard test harness on top of bcmalloc, with producer and consumer threads and a few thousand short-lived threads.
-Memory ordering is the other thing to state clearly. A chunk claim is an `Acquire` compare-and-swap, and a free is a `Release` `fetch_and`. A purge pass claims with `AcqRel`, so a thread that finds a chunk missing because of a pass also sees the counters of that pass. An inbox push is a `Release` compare-and-swap and the owner's swap is an `Acquire`, which carries the sender's writes, the message and everything the program wrote into the blocks, to the owner. The chunk map is written when a slab starts and read with relaxed loads, because every thread that frees a block got it through some synchronisation of its own that carries the write along.
+As for memory ordering, a chunk claim is an `Acquire` compare-and-swap, and a free is a `Release` `fetch_and`. A purge pass claims with `AcqRel`, so a thread that finds a chunk missing because of a pass also sees the counters of that pass. An inbox push is a `Release` compare-and-swap and the owner's swap is an `Acquire`, which carries the sender's writes, the message and everything the program wrote into the blocks, to the owner. The chunk map is written when a slab starts and read with relaxed loads, because every thread that frees a block got it through some synchronisation of its own that carries the write along.
-## 11. Where it wins, and what it costs
+## 13. Where it wins, and what it costs
-The design spends a little memory and some bookkeeping to keep three things cheap: the common allocation and free, memory that moves between threads, and memory that has to come back.
+The design spends a little memory and some bookkeeping to keep three things cheap, which are the common allocation and free, memory that moves between threads, and memory that has to come back.
**The common path does almost nothing.** An allocation is a table lookup and a pop, and a free is one load from a dense, read-mostly map and a push. Neither uses an atomic instruction, and neither reads or writes the block. A freed block is the next one handed out, so a program that allocates and frees in a loop works in a few cache lines.
-**Memory that moves between threads does not drag cache lines with it.** A block freed on another core in a batch is never written by the freeing thread and never walked by the owner. Only the messages travel, one line for every eight blocks. A block that has to travel alone, because it is large, the outbox holds nothing else for its owner, or the freeing thread has no heap, carries its own link. Blocks of classes that cannot share a line are reused where they are freed, which is what makes a thread pool that passes buffers around about as fast as one that does not.
+**Memory that moves between threads does not drag cache lines with it.** A block freed on another core in a batch is never written by the freeing thread and never walked by the owner. Only the messages travel, one line for every eight blocks. A block that has to travel alone, because it is large, the outbox holds nothing else for its owner, or the freeing thread has no heap, carries its own link. Small blocks that cannot share a line are reused where they are freed, and larger ones go back to the cache that wrote them.
**Scattered frees stay cheap.** A free that lands in a cold part of memory costs a bitmap bit and not a write into the block, and a refill hands out a slab's free blocks in address order whatever order they came back in. Programs that free large structures in random order, and then build new ones, get memory that is laid out for them again.
-**Memory comes back.** Any empty slab can serve any class, idle chunks go back to the system on a clock, and on Linux they go back in whole huge pages that the placement rule keeps whole. The capacity is a hard limit, and with `Commit::Lock` the allocator never takes a page fault at all.
+**Memory comes back.** Any empty slab can serve any class, idle chunks go back to the system on a clock, and in the huge-page zone they go back in whole huge pages that the placement rule keeps whole. The capacity is a hard limit, and with `Commit::Lock` the allocator never takes a page fault at all.
-**Locality is kept without asking.** Huge pages widen the reach of the TLB, and on a machine with several NUMA nodes a heap takes its memory from its own node. Neither costs anything on the fast path.
+**Locality is kept without asking.** Huge pages widen the reach of the TLB for heaps that fill them, blocks that the owner wrote go back to the owner, and on a machine with several NUMA nodes a heap takes its memory from its own node. None of it costs anything on the fast path.
These are the costs.
-- **Metadata.** The free bitmaps make a slab descriptor 640 bytes, so metadata is about 1% of the managed memory instead of a fraction of that, and every heap slot reserves about 110 KiB of bin slots. All of it is address space until it is used, but a small region with the default 4096 heaps reserves more for bins than for blocks, so small regions should set `max_heaps` to what they need.
+- **Metadata.** The free bitmaps make a slab descriptor 640 bytes, so metadata is about 1% of the managed memory instead of a fraction of that, and every heap slot reserves about 280 KiB of address space for bin slots. All of it is address space until it is used, but a small region with the default 4096 heaps reserves more for bins than for blocks, so small regions should set `max_heaps` to what they need.
- **Bursts larger than a bin.** A block that overflows a bin goes back to its slab and comes out again on the next refill, one bitmap operation each way, where a list would move a whole chain at once. Bins that keep overflowing grow to make this rare, within a budget.
-- **Blocks that share lines always go home.** For small classes the freeing thread cannot keep the block, so a producer and a consumer pay one message per batch, and blocks wait in an outbox until it fills, is needed for another destination, or is flushed.
+- **Most remote frees go home.** Except for small blocks that own their lines, the freeing thread cannot keep a block, so a producer and a consumer pay one message per batch, and blocks wait in an outbox until it fills, is needed for another destination, or is flushed.
- **Per-thread caches hold memory.** A heap's bins and outboxes keep blocks that other threads cannot use until the heap flushes them, and a thread that goes quiet keeps them until it exits or calls `flush_thread`.
-- **Huge pages raise the floor.** Memory is backed and returned 2 MiB at a time, so a lightly used region holds more than it would with small pages.
+- **Huge pages raise the floor for big heaps.** In the huge-page zone memory is backed and returned 2 MiB at a time, so a heap past the threshold can hold up to a few huge pages that are partly empty.
-## 12. Limits
+## 14. Limits
- Alignments above 64 KiB are refused.
- A thread that finds every heap taken fails its allocations, which aborts the program. `max_heaps` is a design-time bound, like TigerBeetle's connection limit.
- Allocations over 4 MiB claim several bitmap words and are obstruction-free, not lock-free.
- The capacity is a hard limit. A purge pass or a trim makes some chunks look allocated while it holds them, so a request that needs those chunks waits for the pass to finish. It does not fail.
- A heap holds blocks in its bins and outboxes until it needs them, fills a message, or is flushed. A thread that goes quiet keeps them until it exits or calls `flush_thread`. The bins of one heap hold at most their initial capacity plus 2 MiB.
-- Each heap keeps up to 16 MiB of freed huge blocks for reuse until its maintenance steps or a flush return them. A thread that only allocates huge blocks never runs maintenance, so only a flush or its exit returns them.
-- Memory in a slab that is only partly free is never returned, and with huge pages neither is a huge page that is partly in use, except by `trim`.
-- Fresh pages are zero, but the allocator does not track that, so zeroed allocations always write zeros.
+- Each heap keeps up to 16 MiB of freed blocks of whole chunks for reuse until its maintenance steps or a flush return them. A thread that only allocates such blocks never runs maintenance, so only a flush or its exit returns them.
+- Memory in a slab that is only partly free is never returned, and in the huge-page zone neither is a huge page that is partly in use, except by `trim`.
+- A heap picks its zone from its own size and its classes' use, not from how much of each page it touches, so a big heap can still hold a few huge pages it barely uses.
+- A zeroed request that a bin serves always writes zeros, even when the block happens to be fresh.
- The NUMA parts are fixed when the region is created, and a heap keeps the node of the CPU its thread first ran on.
-## 13. Results
-
-There are two sets of benchmarks. The development suite has 51 synthetic workloads in eight groups, including producer and consumer rings, Larson, false sharing, standard collections, resizing, large blocks, latency percentiles and memory after a burst, and it is what changes are tuned against. The held-out set is never tuned against. It has real Rust programs, built on serde_json, regex, syn, a hyper server and tokio channels, and the C programs of mimalloc-bench run with bcmalloc preloaded through its C interface. Every Rust workload runs ten times per allocator, with the allocators taking turns in a rotating order and each run in a fresh process, and the tables show medians. The cold row measures the first pass of each workload and the others the steady state. `just bench`, `just bench-apps` and `just mimalloc-bench` reproduce everything.
-
-
-
-**Figure 9.** Speed relative to mimalloc, as the geometric mean of each group, on both machines, and the held-out programs.
-
-The development suite on an Apple M4 Max with macOS 26.5, where the system allocator is libmalloc:
-
-| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
-| ---------------------- | ------ | -------- | -------- | -------- | -------- |
-| speed, pair | 0.55 | 3.95 | 1.00 | 0.54 | 1.70 |
-| speed, bulk | 0.27 | 1.50 | 1.00 | 0.43 | 0.79 |
-| speed, churn | 0.29 | 2.42 | 1.00 | 1.46 | 1.60 |
-| speed, sharing | 0.55 | 3.03 | 1.00 | 2.18 | 1.60 |
-| speed, false sharing | 0.86 | 1.00 | 1.00 | 0.77 | 1.00 |
-| speed, collections | 0.71 | 1.24 | 1.00 | 0.67 | 1.20 |
-| speed, resizing | 1.00 | 1.02 | 1.00 | 0.92 | 0.85 |
-| speed, large | 0.98 | 1.06 | 1.00 | 0.14 | 0.11 |
-| speed, all workloads | 0.52 | 2.07 | 1.00 | 0.88 | 1.22 |
-| speed, mean of groups | 0.59 | 1.66 | 1.00 | 0.69 | 0.89 |
-| speed, cold | 0.52 | 2.04 | 1.00 | 0.87 | 1.23 |
-| latency, p99 | 0.53 | 3.21 | 1.00 | 2.38 | 1.66 |
-| memory held afterwards | 2.29 | 3.11 | 1.00 | 0.96 | 3.90 |
-| peak resident memory | 0.98 | 0.99 | 1.00 | 0.99 | 1.09 |
-
-On an AMD EPYC 9354P with 32 cores and Linux 7.0 with transparent huge pages, where the system allocator is glibc 2.39:
-
-| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
-| ---------------------- | ------ | -------- | -------- | -------- | -------- |
-| speed, pair | 1.05 | 3.11 | 1.00 | 0.64 | 1.73 |
-| speed, bulk | 0.13 | 1.15 | 1.00 | 0.33 | 0.57 |
-| speed, churn | 0.82 | 2.21 | 1.00 | 1.65 | 1.70 |
-| speed, sharing | 0.32 | 2.27 | 1.00 | 2.16 | 1.08 |
-| speed, false sharing | 0.89 | 1.00 | 1.00 | 1.00 | 1.00 |
-| speed, collections | 0.61 | 1.01 | 1.00 | 0.72 | 0.94 |
-| speed, resizing | 1.02 | 1.06 | 1.00 | 0.60 | 0.90 |
-| speed, large | 0.44 | 1.09 | 1.00 | 0.08 | 0.23 |
-| speed, all workloads | 0.62 | 1.76 | 1.00 | 0.88 | 1.14 |
-| speed, mean of groups | 0.55 | 1.46 | 1.00 | 0.63 | 0.88 |
-| speed, cold | 0.62 | 1.76 | 1.00 | 0.86 | 1.08 |
-| latency, p99 | 0.94 | 3.04 | 1.00 | 1.67 | 2.00 |
-| memory held afterwards | 11.88 | 3.12 | 1.00 | 1.06 | 1.10 |
-| peak resident memory | 2.20 | 1.11 | 1.00 | 1.86 | 1.50 |
-
-Above 1.00 is better than mimalloc, for speed, latency and memory alike.
-
-The Rust programs on macOS, in megabytes, thousands of requests or millions of messages per second. Bold marks the best median and every median whose 95% bootstrap interval overlaps it.
-
-| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
-| ----------------------- | --------- | ---------- | ---------- | --------- | ---------- |
-| json (MB/s) | 250.7 | **284.1** | **291.9** | 241.3 | **296.9** |
-| regex (MB/s) | 1436.7 | **1502.3** | **1503.1** | 1435.8 | **1511.5** |
-| syn (MB/s) | 15.9 | **20.6** | 19.3 | 15.9 | 18.9 |
-| http (kreq/s) | **207.0** | **223.4** | **223.4** | **215.1** | **210.6** |
-| tokio channels (Mmsg/s) | 3.99 | **4.61** | 4.08 | **4.35** | **4.40** |
-
-The same programs on Linux:
-
-| Workload | system | bcmalloc | mimalloc | jemalloc | snmalloc |
-| ----------------------- | ------ | ---------- | -------- | -------- | ---------- |
-| json (MB/s) | 131.8 | **193.3** | 187.8 | 171.8 | 181.7 |
-| regex (MB/s) | 987.1 | **1043.6** | 1039.3 | 1027.1 | **1046.3** |
-| syn (MB/s) | 7.18 | **10.4** | 9.90 | 9.11 | 9.68 |
-| http (kreq/s) | 101.3 | **123.5** | 115.1 | 120.5 | 118.5 |
-| tokio channels (Mmsg/s) | 1.23 | **2.07** | 1.41 | 1.92 | 1.76 |
-
-mimalloc-bench on Linux, in seconds as the median of three runs, lower is better. tcmalloc is the one from mimalloc-bench's own build. Bold marks the fastest. The last two rows are geometric means of mimalloc's figure over each allocator's, so above 1.00 is better, and the memory row compares peak resident memory.
-
-| Test | system | bcmalloc | mimalloc | jemalloc | snmalloc | tcmalloc |
-| --- | --- | --- | --- | --- | --- | --- |
-| alloc-test1 | 3.27 | 2.72 | 2.55 | 2.59 | 2.59 | **2.54** |
-| alloc-testN | 2.94 | 2.53 | **2.30** | 2.32 | 2.35 | 2.46 |
-| barnes | 2.24 | **2.15** | 2.25 | 2.25 | 2.24 | 2.25 |
-| cache-scratch1 | **1.05** | **1.05** | **1.05** | **1.05** | **1.05** | 1.06 |
-| cache-scratchN | **0.03** | **0.03** | **0.03** | **0.03** | **0.03** | **0.03** |
-| cache-thrash1 | **1.05** | **1.05** | **1.05** | **1.05** | **1.05** | **1.05** |
-| cache-thrashN | **0.03** | **0.03** | **0.03** | **0.03** | **0.03** | **0.03** |
-| cfrac | 3.53 | 3.39 | 3.17 | 3.27 | **3.15** | 3.21 |
-| espresso | 3.91 | 3.53 | 3.47 | 3.54 | **3.43** | 3.45 |
-| glibc-simple | 2.11 | 1.69 | 1.61 | 1.90 | 1.61 | **1.52** |
-| glibc-thread | 0.33 | 0.22 | 0.20 | 0.21 | **0.19** | 0.47 |
-| gs | 0.23 | **0.22** | 0.23 | 0.24 | 0.25 | 0.23 |
-| larsonN | 1.69 | 1.21 | **1.06** | 1.24 | 1.22 | 1.19 |
-| larsonN-sized | 1.68 | 1.18 | **1.05** | 1.13 | 1.20 | 1.13 |
-| leanN | 10.90 | **8.90** | 9.47 | 9.16 | 9.01 | 9.80 |
-| linux | **0.12** | 0.15 | 0.13 | 0.14 | 0.13 | 0.27 |
-| lua | 0.79 | **0.76** | 0.78 | 0.79 | 0.77 | 0.80 |
-| malloc-large | 2.06 | **1.31** | 1.36 | 15.11 | 3.51 | 1.45 |
-| mleak10 | **0.14** | **0.14** | **0.14** | 0.15 | **0.14** | **0.14** |
-| mleak100 | 1.39 | 1.42 | 1.40 | 1.45 | 1.41 | **1.37** |
-| mstressN | 1.28 | **0.54** | 0.74 | 1.07 | 0.76 | 1.01 |
-| rbstress1 | **2.79** | 2.82 | 2.82 | **2.79** | 2.81 | 2.81 |
-| rbstressN | 3.03 | 3.03 | 3.05 | 3.03 | 3.03 | **3.02** |
-| redis | 3.28 | 3.22 | 3.20 | 3.74 | **3.12** | 3.30 |
-| rocksdb | 4.41 | **4.22** | 4.34 | 4.27 | 4.34 | 4.29 |
-| rptestN | 0.99 | 0.38 | 0.28 | 0.44 | **0.23** | 0.65 |
-| sh6benchN | 0.24 | **0.06** | 0.07 | 0.10 | 0.10 | 0.13 |
-| sh8benchN | 0.64 | 0.19 | **0.18** | 0.27 | 0.19 | 6.45 |
-| xmalloc-testN | 0.94 | 0.18 | 0.24 | **0.17** | 0.19 | 60.57 |
-| speed against mimalloc | 0.74 | 0.99 | 1.00 | 0.86 | 0.96 | 0.64 |
-| memory against mimalloc | 1.06 | 0.51 | 1.00 | 0.83 | 0.84 | 0.77 |
-
-The held-out set changes the picture. On the Rust programs bcmalloc is the fastest on both machines, but only by 3% on macOS and 7% on Linux, because real programs spend most of their time outside the allocator. On mimalloc-bench it ties mimalloc for speed and is ahead of jemalloc, snmalloc and tcmalloc, but it holds about twice as much memory at peak as mimalloc. The largest gaps in memory are in programs that start many threads, such as glibc-thread, alloc-test and lean, where every heap keeps its bins, an empty slab per class and its cached huge blocks.
-
[^tigerbeetle]: [A Database Without Dynamic Memory Allocation](https://tigerbeetle.com/blog/2022-10-12-a-database-without-dynamic-memory/) explains why TigerBeetle sizes everything from fixed limits at start-up and what that buys.
[^llfree]: [LLFree, scalable and optionally-persistent page-frame allocation](https://www.usenix.org/conference/atc23/presentation/wrenger) is a lock-free frame allocator whose every transaction is a single atomic change of a single cache line.
[^jwmalloc]: [jwmalloc, a verified memory allocator for mobile devices](https://www.usenix.org/conference/osdi26/presentation/wang-jiawei) uses a uniform slab size with pooling so that an emptied slab is reusable by any size class.
diff --git a/README.md b/README.md
index 02b33f6..e01abe9 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
A global allocator for long-lived, highly concurrent Rust programs. It reserves one region of address space up front and serves small blocks from per-thread stacks of free pointers, without atomic operations and without touching the blocks. Blocks freed by another thread go home in batched messages, one compare-and-swap per batch. Memory freed by one size class is reused by every other, memory that stays idle goes back to the operating system, and the capacity you configure is a hard limit.
-Usage is one line. The region is reserved the first time anything allocates.
+Declare it as the global allocator, and the region is reserved the first time anything allocates.
```rust
use bcmalloc::Bcmalloc;
@@ -59,6 +59,23 @@ numbers.extend(0..1000_u32);
assert_eq!(numbers.iter().sum::(), 499_500);
```
+## Metrics
+
+With the `metrics` feature, every heap counts its allocations and frees by size class, the slabs it holds, and the slow paths it takes, and `Bcmalloc::metrics` sums the counts into a snapshot that prints as a report. Only a heap's own thread writes its counters, with plain adds on cache lines the allocator touches anyway, so the feature costs little enough to leave on in production.
+
+```rust,ignore
+use bcmalloc::Bcmalloc;
+
+#[global_allocator]
+static GLOBAL: Bcmalloc = Bcmalloc::new();
+
+if let Some(metrics) = GLOBAL.metrics() {
+ eprintln!("{metrics}");
+}
+```
+
+The C library prints the same report at exit when it is built with the feature and `BCMALLOC_SHOW_METRICS` is set.
+
## Configuration
| Option | Default | What it does |
@@ -66,63 +83,27 @@ assert_eq!(numbers.iter().sum::(), 499_500);
| `capacity` | 64 GiB | Size of the region. It is address space until memory is touched. |
| `max_heaps` | 4096 | How many threads can allocate at once. |
| `commit` | `Lazy` | `Populate` backs every page now and `Lock` also pins them in RAM. |
-| `huge_pages` | on | Backs the region with transparent huge pages on Linux. macOS has none. |
-| `numa` | on | Splits the region between NUMA nodes on Linux machines with several. |
+| `huge_pages` | on | Huge pages on Linux for big heaps and big blocks. macOS has none. |
+| `numa` | on | Splits the region between NUMA nodes on Linux machines with several. |
If the operating system refuses the default reservation, the global allocator retries with half the capacity down to 256 MiB.
## Benchmarks
-There are two sets of benchmarks. The development suite has 51 synthetic workloads in eight groups, from single-thread loops to producer and consumer rings, and it is what changes are tuned against. The held-out set is never tuned against: real Rust programs built on serde_json, regex, syn, hyper and tokio, and the C programs of [mimalloc-bench](https://github.com/daanx/mimalloc-bench) run with bcmalloc preloaded. Every Rust workload runs ten times per allocator in a rotating order, each run in a fresh process, and the tables show medians relative to mimalloc, so above 1.00 is better for speed and for memory alike. `just bench`, `just bench-apps` and `just mimalloc-bench` reproduce them.
-
-The development suite on an Apple M4 Max with macOS 26.5 and Rust 1.100, where the system allocator is libmalloc:
-
-| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
-| ---------------------- | ------ | -------- | -------- | -------- | -------- |
-| speed, pair | 0.55 | 3.95 | 1.00 | 0.54 | 1.70 |
-| speed, bulk | 0.27 | 1.50 | 1.00 | 0.43 | 0.79 |
-| speed, churn | 0.29 | 2.42 | 1.00 | 1.46 | 1.60 |
-| speed, sharing | 0.55 | 3.03 | 1.00 | 2.18 | 1.60 |
-| speed, false sharing | 0.86 | 1.00 | 1.00 | 0.77 | 1.00 |
-| speed, collections | 0.71 | 1.24 | 1.00 | 0.67 | 1.20 |
-| speed, resizing | 1.00 | 1.02 | 1.00 | 0.92 | 0.85 |
-| speed, large | 0.98 | 1.06 | 1.00 | 0.14 | 0.11 |
-| speed, all workloads | 0.52 | 2.07 | 1.00 | 0.88 | 1.22 |
-| speed, mean of groups | 0.59 | 1.66 | 1.00 | 0.69 | 0.89 |
-| speed, cold | 0.52 | 2.04 | 1.00 | 0.87 | 1.23 |
-| latency, p99 | 0.53 | 3.21 | 1.00 | 2.38 | 1.66 |
-| memory held afterwards | 2.29 | 3.11 | 1.00 | 0.96 | 3.90 |
-| peak resident memory | 0.98 | 0.99 | 1.00 | 0.99 | 1.09 |
-
-On a 32-core AMD EPYC 9354P with Ubuntu 24.04, kernel 7.0 and Rust 1.100, where the system allocator is glibc 2.39:
-
-| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc |
-| ---------------------- | ------ | -------- | -------- | -------- | -------- |
-| speed, pair | 1.05 | 3.11 | 1.00 | 0.64 | 1.73 |
-| speed, bulk | 0.13 | 1.15 | 1.00 | 0.33 | 0.57 |
-| speed, churn | 0.82 | 2.21 | 1.00 | 1.65 | 1.70 |
-| speed, sharing | 0.32 | 2.27 | 1.00 | 2.16 | 1.08 |
-| speed, false sharing | 0.89 | 1.00 | 1.00 | 1.00 | 1.00 |
-| speed, collections | 0.61 | 1.01 | 1.00 | 0.72 | 0.94 |
-| speed, resizing | 1.02 | 1.06 | 1.00 | 0.60 | 0.90 |
-| speed, large | 0.44 | 1.09 | 1.00 | 0.08 | 0.23 |
-| speed, all workloads | 0.62 | 1.76 | 1.00 | 0.88 | 1.14 |
-| speed, mean of groups | 0.55 | 1.46 | 1.00 | 0.63 | 0.88 |
-| speed, cold | 0.62 | 1.76 | 1.00 | 0.86 | 1.08 |
-| latency, p99 | 0.94 | 3.04 | 1.00 | 1.67 | 2.00 |
-| memory held afterwards | 11.88 | 3.12 | 1.00 | 1.06 | 1.10 |
-| peak resident memory | 2.20 | 1.11 | 1.00 | 1.86 | 1.50 |
-
-The held-out programs:
-
-| Compared with mimalloc | system | bcmalloc | mimalloc | jemalloc | snmalloc | tcmalloc |
-| --- | --- | --- | --- | --- | --- | --- |
-| speed, Rust programs, macOS | 0.91 | 1.03 | 1.00 | 0.92 | 1.00 | - |
-| speed, Rust programs, Linux | 0.82 | 1.11 | 1.00 | 1.04 | 1.04 | - |
-| speed, mimalloc-bench, Linux | 0.74 | 0.99 | 1.00 | 0.86 | 0.96 | 0.64 |
-| memory, mimalloc-bench, Linux | 1.06 | 0.51 | 1.00 | 0.83 | 0.84 | 0.77 |
-
-On the synthetic suite bcmalloc leads by a wide margin on both machines. On the held-out programs the margin is small. It is the fastest on the Rust programs on both machines, by 3% over the next allocator on macOS and 7% on Linux, and it ties mimalloc for speed on mimalloc-bench while holding about twice its memory at peak. DESIGN.md has the per-program tables and explains the design.
+
+
+
+| Compared with mimalloc | system | bcmalloc | jemalloc | snmalloc |
+| ---------------------------------- | ------ | -------- | -------- | -------- |
+| development suite, macOS, speed | 0.52 | 2.09 | 0.87 | 1.22 |
+| development suite, Linux, speed | 0.63 | 1.73 | 0.88 | 1.14 |
+| Rust programs, macOS, speed | 0.91 | 1.02 | 0.93 | 1.01 |
+| Rust programs, Linux, speed | 0.82 | 1.09 | 1.03 | 1.04 |
+| mimalloc-bench, Linux, speed | - | 1.00 | 0.82 | 0.94 |
+| mimalloc-bench, Linux, peak memory | - | 1.51 | 1.38 | 1.40 |
+
+
+The development suite has 51 synthetic workloads and is what the allocator is tuned against. The Rust programs, built on serde_json, regex, syn, hyper and tokio, and the C programs of mimalloc-bench are never tuned against. Figures are relative to mimalloc, and above 1.00 is better, faster or less memory. [BENCHMARKS.md](https://github.com/clabby/bcmalloc/blob/main/BENCHMARKS.md) has the method, the machines, every table, and the programs where bcmalloc is not the fastest.
## Limits
@@ -134,7 +115,7 @@ On the synthetic suite bcmalloc leads by a wide margin on both machines. On the
## Testing
-The lock-free code is checked with loom, the unsafe code with Miri under strict provenance, and the allocator and its chunk bitmap with fuzz targets. `just` has a recipe for each, and `just --list` shows them all.
+The lock-free code is checked with loom, the unsafe code with Miri under strict provenance, and the allocator and its chunk bitmap with fuzz targets that compare them against reference models. Line coverage of the unit tests is reported to Codecov. `just` has a recipe for each, and `just --list` shows them all.
## LLM Disclosure
diff --git a/assets/benchmarks.svg b/assets/benchmarks.svg
index 6865e09..1f5e47c 100644
--- a/assets/benchmarks.svg
+++ b/assets/benchmarks.svg
@@ -1,31 +1,10 @@
-
\ No newline at end of file
+.grid{stroke:var(--line);stroke-width:1}.even{stroke:var(--muted);stroke-width:1.5;stroke-dasharray:4 4}
+.dot{fill-opacity:.55;stroke:none}.mean{stroke-width:3;fill:none}
+.c-mimalloc{fill:#8250df;stroke:#8250df}.c-snmalloc{fill:#1a7f37;stroke:#1a7f37}.c-jemalloc{fill:#bc4c00;stroke:#bc4c00}.c-tcmalloc{fill:#9a6700;stroke:#9a6700}.c-system{fill:#6e7781;stroke:#6e7781}
+How bcmalloc compares, workload by workloadEach dot is one workload: bcmalloc's speed divided by the other allocator's, on a log scale. Right of the dashed line,bcmalloc is faster. The bar is the geometric mean. Medians of every run, from benchmarks.json.4× slower2× slowereven2× faster4× faster8× faster16× fasterDevelopment suite, macOS45 workloadsagainst mimalloc2.09× faster on 43 of 45against snmalloc1.71× faster on 43 of 45against jemalloc2.41× faster on 42 of 45against system4.03× faster on 43 of 45Development suite, Linux45 workloadsagainst mimalloc1.73× faster on 39 of 45against snmalloc1.52× faster on 36 of 45against jemalloc1.96× faster on 38 of 45against system2.75× faster on 42 of 45Rust programs, macOS5 workloadsagainst mimalloc1.02× faster on 4 of 5against snmalloc1.01× faster on 3 of 5against jemalloc1.10× faster on 5 of 5against system1.12× faster on 5 of 5Rust programs, Linux5 workloadsagainst mimalloc1.09× faster on 5 of 5against snmalloc1.05× faster on 5 of 5against jemalloc1.06× faster on 4 of 5against system1.34× faster on 5 of 5Mimalloc-bench, Linux28 workloadsagainst mimalloc1.00× faster on 9 of 28against snmalloc1.06× faster on 12 of 28against jemalloc1.22× faster on 20 of 28Dots beyond the ends of the axis sit at the ends. Workloads that measure memory are left out, and so is the latency group.
diff --git a/assets/messages.svg b/assets/messages.svg
index 5043b3d..fe2f7ac 100644
--- a/assets/messages.svg
+++ b/assets/messages.svg
@@ -28,4 +28,4 @@ text{font-family:ui-sans-serif, -apple-system, "Segoe UI", Helvetica, Arial, san
.dash{stroke-dasharray:6 5}
.t-blue{fill:var(--blue)}.t-green{fill:var(--green)}.t-orange{fill:var(--orange)}.t-red{fill:var(--red)}.t-purple{fill:var(--purple)}
.f-ink{fill:var(--ink)}.f-muted{fill:var(--muted)}.f-blue{fill:var(--blue)}.f-green{fill:var(--green)}.f-orange{fill:var(--orange)}.f-purple{fill:var(--purple)}.f-red{fill:var(--red)}.f-gray{fill:var(--gray)}
-A remote freeA consumer frees blocks that the producer’s heap owns. In a batch only pointers move between the threads, never the blocks.consumer thread, heap 71free(p)one load of the chunk map entry of powner 2, class 96 Bnot this heap2append to the outbox for heap 2a 512 B block of heap 7, up to 62 pointerspppppppp…Sixteen outboxes, one per destination heap,fill side by side. The block p is never written.3when full,one CASproducer thread, heap 2, the ownerinboxa stack anyone pushes ontomessageone block, tagged4a bin runs dry: one swap takes allthe chunk map gives each block’s classpppppppppPointers go into the bins, or into their slabif the bin is full. The message is then freedlike any other block.why this wayA list threaded through the freed blocks would make the consumer write into each block, whose line sits in theproducer’s cache, and the producer would then read each block to find the next. Here only the message moves.Blocks that fill whole cache lines skip all of this. The consumer keeps them in its own bin and hands them out again,because they cannot share a line with a block the producer still uses.
\ No newline at end of file
+A remote freeA consumer frees blocks that the producer’s heap owns. In a batch only pointers move between the threads, never the blocks.consumer thread, heap 71free(p)one load of the chunk map entry of powner 2, class 96 Bnot this heap2append to the outbox for heap 2a 512 B block of heap 7, up to 62 pointerspppppppp…Sixteen outboxes, one per destination heap,fill side by side. The block p is never written.3when full,one CASproducer thread, heap 2, the ownerinboxa stack anyone pushes ontomessageone block, tagged4a bin runs dry, and one swap takes allthe chunk map gives each block’s classpppppppppPointers go into the bins, or into their slabif the bin is full. The message is then freedlike any other block.why this wayA list threaded through the freed blocks would make the consumer write into each block, whose line sits in theproducer’s cache, and the producer would then read each block to find the next. Here only the message moves.Blocks of up to 256 bytes that fill whole cache lines skip all of this. The consumer keeps them in its own bin and handsthem out again, because they cannot share a line with a block the producer still uses, and span few lines to pull across.
\ No newline at end of file
diff --git a/assets/region-map.svg b/assets/region-map.svg
index b80c5e8..ba12ce9 100644
--- a/assets/region-map.svg
+++ b/assets/region-map.svg
@@ -28,4 +28,4 @@ text{font-family:ui-sans-serif, -apple-system, "Segoe UI", Helvetica, Arial, san
.dash{stroke-dasharray:6 5}
.t-blue{fill:var(--blue)}.t-green{fill:var(--green)}.t-orange{fill:var(--orange)}.t-red{fill:var(--red)}.t-purple{fill:var(--purple)}
.f-ink{fill:var(--ink)}.f-muted{fill:var(--muted)}.f-blue{fill:var(--blue)}.f-green{fill:var(--green)}.f-orange{fill:var(--orange)}.f-purple{fill:var(--purple)}.f-red{fill:var(--red)}.f-gray{fill:var(--gray)}
-The reservationMetadata sits next to the memory it describes and never inside it. All of it starts out as zeros.Regionheaderheapslotsone perheapbinslots13,600 pointersper heapslabdescriptors640 Bper chunkchunkmap8 Bper chunkbitmaps4 bitsper chunkpadto 4 MiBchunks, the memory that is handed out64 KiB each, aligned to 4 MiBmetadata, about 1% of the regionthe other 99%from a pointer to its metadataNo header is read from the block. A subtraction and a shift find the chunk, and its chunk map entry says who owns it and what it is.pointerbase + 0x2A_3F10chunk index(ptr - base) >> 16= 42chunk map entrymap[42]= heap 3, class 30descriptorslabs[42 & !7]= slabs[40]A free needs only the entry: the owner says whether the block is this heap’s, and the class says which bin it goes to.The descriptor is only read by the owning heap, when blocks go back to their slab. Its slab here spans 8 chunks, and maskingworks because every slab starts at a multiple of its own length in chunks.
\ No newline at end of file
+The reservationMetadata sits next to the memory it describes and never inside it. All of it starts out as zeros.Regionheaderheapslotsone perheapbinslots36,000 pointersper heapslabdescriptors640 Bper chunkchunkmap8 Bper chunkbitmaps4 bitsper chunkpadto 4 MiBchunks, the memory that is handed out64 KiB each, aligned to 4 MiBmetadata, about 1% of the regionthe other 99%from a pointer to its metadataNo header is read from the block. A subtraction and a shift find the chunk, and its chunk map entry says who owns it and what it is.pointerbase + 0x2A_3F10chunk index(ptr - base) >> 16= 42chunk map entrymap[42]= heap 3, class 30descriptorslabs[42 & !7]= slabs[40]A free needs only the entry. The owner says whether the block is this heap’s, and the bin offset next to the class says where it goes.The descriptor is only read by the owning heap, when blocks go back to their slab. Its slab here spans 8 chunks, and maskingworks because every slab starts at a multiple of its own length in chunks.
\ No newline at end of file
diff --git a/assets/size-classes.svg b/assets/size-classes.svg
index 41dc17c..b3632f3 100644
--- a/assets/size-classes.svg
+++ b/assets/size-classes.svg
@@ -1,4 +1,4 @@
-
+64 KiB slabs, 1 chunk512 KiB slabs, 8 chunks0%5%10%128 B256 B512 B1 KiB2 KiB4 KiB8 KiB16 KiB32 KiB64 KiBworst case is 12.5%Rounding waste of a request, by request sizeEight classes per doubling keep the waste under one eighth. Below 128 B the classes are 8 B apart, and above 64 KiB a request gets whole chunks.request sizewaste
\ No newline at end of file
diff --git a/assets/zones.svg b/assets/zones.svg
new file mode 100644
index 0000000..73acd17
--- /dev/null
+++ b/assets/zones.svg
@@ -0,0 +1,31 @@
+
\ No newline at end of file
diff --git a/benchmarks.json b/benchmarks.json
new file mode 100644
index 0000000..ed2440e
--- /dev/null
+++ b/benchmarks.json
@@ -0,0 +1,10000 @@
+{
+ "runs": [
+ {
+ "suite": "dev",
+ "machine": "macos",
+ "description": "Apple M4 Max, macOS 27.0.1",
+ "date": "2026-11-14",
+ "samples": 10,
+ "baseline": "mimalloc",
+ "allocators": [
+ "system",
+ "bcmalloc",
+ "mimalloc",
+ "jemalloc",
+ "snmalloc"
+ ],
+ "workloads": [
+ {
+ "group": "pair",
+ "name": "pair 16 B",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 433.0,
+ "lo": 430.2,
+ "hi": 434.4,
+ "peak_mib": 1.7
+ },
+ "jemalloc": {
+ "median": 143.0,
+ "lo": 142.8,
+ "hi": 143.3,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 223.8,
+ "lo": 223.0,
+ "hi": 224.5,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 396.2,
+ "lo": 392.8,
+ "hi": 397.9,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 152.6,
+ "lo": 146.9,
+ "hi": 158.0,
+ "peak_mib": 1.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 433.4,
+ "lo": 432.7,
+ "hi": 436.8,
+ "peak_mib": 1.7
+ },
+ "jemalloc": {
+ "median": 142.8,
+ "lo": 142.7,
+ "hi": 145.6,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 224.3,
+ "lo": 224.0,
+ "hi": 224.7,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 397.0,
+ "lo": 394.8,
+ "hi": 397.5,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 153.5,
+ "lo": 151.7,
+ "hi": 155.3,
+ "peak_mib": 1.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 64 B",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 405.2,
+ "lo": 392.1,
+ "hi": 410.6,
+ "peak_mib": 1.7
+ },
+ "jemalloc": {
+ "median": 142.2,
+ "lo": 142.1,
+ "hi": 142.4,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 219.6,
+ "lo": 219.1,
+ "hi": 220.1,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 386.1,
+ "lo": 384.6,
+ "hi": 387.0,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 137.4,
+ "lo": 136.1,
+ "hi": 137.9,
+ "peak_mib": 1.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 405.0,
+ "lo": 392.1,
+ "hi": 411.2,
+ "peak_mib": 1.7
+ },
+ "jemalloc": {
+ "median": 142.2,
+ "lo": 142.0,
+ "hi": 143.9,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 219.9,
+ "lo": 219.5,
+ "hi": 220.4,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 386.5,
+ "lo": 385.6,
+ "hi": 387.1,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 137.6,
+ "lo": 136.5,
+ "hi": 138.2,
+ "peak_mib": 1.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 256 B",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 409.4,
+ "lo": 408.0,
+ "hi": 411.0,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 140.0,
+ "lo": 139.9,
+ "hi": 141.2,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 182.1,
+ "lo": 180.7,
+ "hi": 185.7,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 341.8,
+ "lo": 339.6,
+ "hi": 344.1,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 129.0,
+ "lo": 126.9,
+ "hi": 129.9,
+ "peak_mib": 1.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 410.5,
+ "lo": 409.3,
+ "hi": 412.7,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 140.0,
+ "lo": 139.8,
+ "hi": 140.8,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 182.3,
+ "lo": 180.6,
+ "hi": 184.7,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 344.2,
+ "lo": 342.4,
+ "hi": 345.2,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 126.0,
+ "lo": 120.9,
+ "hi": 127.6,
+ "peak_mib": 1.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 1 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 409.8,
+ "lo": 408.5,
+ "hi": 411.5,
+ "peak_mib": 1.7
+ },
+ "jemalloc": {
+ "median": 133.6,
+ "lo": 133.3,
+ "hi": 134.9,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 149.7,
+ "lo": 148.8,
+ "hi": 151.9,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 280.8,
+ "lo": 274.8,
+ "hi": 288.2,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 54.22,
+ "lo": 54.06,
+ "hi": 54.35,
+ "peak_mib": 1.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 409.8,
+ "lo": 404.5,
+ "hi": 411.8,
+ "peak_mib": 1.7
+ },
+ "jemalloc": {
+ "median": 133.1,
+ "lo": 133.1,
+ "hi": 133.4,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 150.8,
+ "lo": 148.8,
+ "hi": 152.2,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 282.1,
+ "lo": 276.1,
+ "hi": 286.1,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 54.21,
+ "lo": 54.12,
+ "hi": 54.43,
+ "peak_mib": 1.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 4 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 410.8,
+ "lo": 408.9,
+ "hi": 422.8,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 112.0,
+ "lo": 111.9,
+ "hi": 112.3,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 94.97,
+ "lo": 94.81,
+ "hi": 97.67,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 167.5,
+ "lo": 156.8,
+ "hi": 169.6,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 72.66,
+ "lo": 72.2,
+ "hi": 73.01,
+ "peak_mib": 1.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 411.3,
+ "lo": 408.8,
+ "hi": 422.9,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 111.8,
+ "lo": 111.2,
+ "hi": 112.1,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 95.59,
+ "lo": 93.7,
+ "hi": 97.51,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 159.8,
+ "lo": 157.0,
+ "hi": 166.0,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 71.73,
+ "lo": 71.55,
+ "hi": 72.11,
+ "peak_mib": 1.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 16 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 309.6,
+ "lo": 308.4,
+ "hi": 322.0,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 54.93,
+ "lo": 53.74,
+ "hi": 55.04,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 86.9,
+ "lo": 86.58,
+ "hi": 88.78,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 157.1,
+ "lo": 154.0,
+ "hi": 160.3,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 60.95,
+ "lo": 60.13,
+ "hi": 61.33,
+ "peak_mib": 1.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 308.7,
+ "lo": 308.3,
+ "hi": 311.8,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 54.73,
+ "lo": 54.05,
+ "hi": 55.12,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 87.54,
+ "lo": 86.88,
+ "hi": 89.9,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 158.1,
+ "lo": 151.5,
+ "hi": 160.8,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 61.16,
+ "lo": 60.17,
+ "hi": 61.37,
+ "peak_mib": 1.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 64 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 308.5,
+ "lo": 307.3,
+ "hi": 332.1,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 11.32,
+ "lo": 11.14,
+ "hi": 11.34,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 88.15,
+ "lo": 86.72,
+ "hi": 90.89,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 162.5,
+ "lo": 157.4,
+ "hi": 168.6,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 14.6,
+ "lo": 14.41,
+ "hi": 14.75,
+ "peak_mib": 1.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 309.1,
+ "lo": 307.9,
+ "hi": 333.4,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 11.42,
+ "lo": 11.21,
+ "hi": 11.46,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 87.9,
+ "lo": 87.09,
+ "hi": 90.6,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 161.7,
+ "lo": 157.5,
+ "hi": 169.3,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 14.51,
+ "lo": 14.4,
+ "hi": 14.72,
+ "peak_mib": 1.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 256 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 210.1,
+ "lo": 208.8,
+ "hi": 210.5,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 7.545,
+ "lo": 7.516,
+ "hi": 7.579,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 88.6,
+ "lo": 87.34,
+ "hi": 90.32,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 38.89,
+ "lo": 38.34,
+ "hi": 39.12,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 14.28,
+ "lo": 14.25,
+ "hi": 14.51,
+ "peak_mib": 1.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 211.5,
+ "lo": 209.5,
+ "hi": 211.8,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 7.755,
+ "lo": 7.427,
+ "hi": 7.785,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 88.62,
+ "lo": 87.22,
+ "hi": 90.81,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 38.93,
+ "lo": 38.41,
+ "hi": 39.67,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 14.28,
+ "lo": 14.24,
+ "hi": 14.45,
+ "peak_mib": 1.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 1 MiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 209.7,
+ "lo": 209.1,
+ "hi": 210.3,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 7.714,
+ "lo": 7.66,
+ "hi": 7.773,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 4.053,
+ "lo": 4.032,
+ "hi": 4.071,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 19.59,
+ "lo": 19.36,
+ "hi": 19.66,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 14.28,
+ "lo": 14.07,
+ "hi": 14.5,
+ "peak_mib": 1.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 212.6,
+ "lo": 211.2,
+ "hi": 212.7,
+ "peak_mib": 1.8
+ },
+ "jemalloc": {
+ "median": 7.768,
+ "lo": 7.688,
+ "hi": 7.792,
+ "peak_mib": 1.7
+ },
+ "mimalloc": {
+ "median": 4.061,
+ "lo": 4.034,
+ "hi": 4.076,
+ "peak_mib": 1.7
+ },
+ "snmalloc": {
+ "median": 19.42,
+ "lo": 19.37,
+ "hi": 19.61,
+ "peak_mib": 1.5
+ },
+ "system": {
+ "median": 14.23,
+ "lo": 14.1,
+ "hi": 14.5,
+ "peak_mib": 1.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "bulk",
+ "name": "bulk 32 B in order",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 242.3,
+ "lo": 218.8,
+ "hi": 252.6,
+ "peak_mib": 49.1
+ },
+ "jemalloc": {
+ "median": 62.67,
+ "lo": 62.3,
+ "hi": 63.58,
+ "peak_mib": 48.4
+ },
+ "mimalloc": {
+ "median": 152.9,
+ "lo": 150.6,
+ "hi": 153.8,
+ "peak_mib": 47.6
+ },
+ "snmalloc": {
+ "median": 188.1,
+ "lo": 187.2,
+ "hi": 192.4,
+ "peak_mib": 49.4
+ },
+ "system": {
+ "median": 82.11,
+ "lo": 80.74,
+ "hi": 84.28,
+ "peak_mib": 62.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 306.4,
+ "lo": 303.3,
+ "hi": 311.3,
+ "peak_mib": 49.1
+ },
+ "jemalloc": {
+ "median": 66.24,
+ "lo": 65.94,
+ "hi": 66.38,
+ "peak_mib": 48.4
+ },
+ "mimalloc": {
+ "median": 172.4,
+ "lo": 172.2,
+ "hi": 173.0,
+ "peak_mib": 47.6
+ },
+ "snmalloc": {
+ "median": 211.8,
+ "lo": 210.0,
+ "hi": 214.9,
+ "peak_mib": 49.4
+ },
+ "system": {
+ "median": 86.54,
+ "lo": 84.97,
+ "hi": 98.51,
+ "peak_mib": 62.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "bulk",
+ "name": "bulk 32 B shuffled",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 173.8,
+ "lo": 172.2,
+ "hi": 176.2,
+ "peak_mib": 48.0
+ },
+ "jemalloc": {
+ "median": 57.96,
+ "lo": 57.48,
+ "hi": 58.73,
+ "peak_mib": 48.4
+ },
+ "mimalloc": {
+ "median": 150.6,
+ "lo": 148.3,
+ "hi": 152.5,
+ "peak_mib": 47.6
+ },
+ "snmalloc": {
+ "median": 147.2,
+ "lo": 144.0,
+ "hi": 150.1,
+ "peak_mib": 49.45
+ },
+ "system": {
+ "median": 39.8,
+ "lo": 38.97,
+ "hi": 40.8,
+ "peak_mib": 62.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 191.4,
+ "lo": 188.7,
+ "hi": 197.4,
+ "peak_mib": 48.0
+ },
+ "jemalloc": {
+ "median": 60.26,
+ "lo": 59.92,
+ "hi": 60.87,
+ "peak_mib": 48.4
+ },
+ "mimalloc": {
+ "median": 169.7,
+ "lo": 166.0,
+ "hi": 171.6,
+ "peak_mib": 47.6
+ },
+ "snmalloc": {
+ "median": 160.8,
+ "lo": 158.8,
+ "hi": 167.0,
+ "peak_mib": 49.45
+ },
+ "system": {
+ "median": 39.91,
+ "lo": 39.11,
+ "hi": 41.93,
+ "peak_mib": 62.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "bulk",
+ "name": "bulk 512 B shuffled",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 55.31,
+ "lo": 54.89,
+ "hi": 57.52,
+ "peak_mib": 268.6
+ },
+ "jemalloc": {
+ "median": 25.54,
+ "lo": 25.4,
+ "hi": 26.12,
+ "peak_mib": 272.2
+ },
+ "mimalloc": {
+ "median": 43.82,
+ "lo": 43.22,
+ "hi": 45.1,
+ "peak_mib": 269.5
+ },
+ "snmalloc": {
+ "median": 25.25,
+ "lo": 24.73,
+ "hi": 26.07,
+ "peak_mib": 267.8
+ },
+ "system": {
+ "median": 10.5,
+ "lo": 10.33,
+ "hi": 10.69,
+ "peak_mib": 285.8
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 101.6,
+ "lo": 100.3,
+ "hi": 102.9,
+ "peak_mib": 268.6
+ },
+ "jemalloc": {
+ "median": 35.53,
+ "lo": 35.21,
+ "hi": 36.23,
+ "peak_mib": 272.2
+ },
+ "mimalloc": {
+ "median": 63.05,
+ "lo": 62.61,
+ "hi": 63.63,
+ "peak_mib": 269.5
+ },
+ "snmalloc": {
+ "median": 29.08,
+ "lo": 28.54,
+ "hi": 30.08,
+ "peak_mib": 267.8
+ },
+ "system": {
+ "median": 10.77,
+ "lo": 10.59,
+ "hi": 11.47,
+ "peak_mib": 285.8
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn small",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 230.7,
+ "lo": 229.7,
+ "hi": 231.0,
+ "peak_mib": 2.2
+ },
+ "jemalloc": {
+ "median": 122.5,
+ "lo": 121.6,
+ "hi": 122.9,
+ "peak_mib": 2.1
+ },
+ "mimalloc": {
+ "median": 98.09,
+ "lo": 97.77,
+ "hi": 98.31,
+ "peak_mib": 2.2
+ },
+ "snmalloc": {
+ "median": 213.7,
+ "lo": 213.5,
+ "hi": 214.8,
+ "peak_mib": 1.9
+ },
+ "system": {
+ "median": 48.12,
+ "lo": 47.81,
+ "hi": 48.22,
+ "peak_mib": 1.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 231.8,
+ "lo": 230.7,
+ "hi": 232.3,
+ "peak_mib": 2.2
+ },
+ "jemalloc": {
+ "median": 122.8,
+ "lo": 122.3,
+ "hi": 124.8,
+ "peak_mib": 2.1
+ },
+ "mimalloc": {
+ "median": 98.06,
+ "lo": 97.94,
+ "hi": 98.65,
+ "peak_mib": 2.2
+ },
+ "snmalloc": {
+ "median": 214.4,
+ "lo": 213.9,
+ "hi": 215.0,
+ "peak_mib": 1.9
+ },
+ "system": {
+ "median": 48.38,
+ "lo": 48.24,
+ "hi": 48.46,
+ "peak_mib": 1.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn medium",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 228.0,
+ "lo": 227.2,
+ "hi": 228.5,
+ "peak_mib": 5.4
+ },
+ "jemalloc": {
+ "median": 109.7,
+ "lo": 109.6,
+ "hi": 111.7,
+ "peak_mib": 5.0
+ },
+ "mimalloc": {
+ "median": 58.57,
+ "lo": 58.35,
+ "hi": 58.73,
+ "peak_mib": 5.3
+ },
+ "snmalloc": {
+ "median": 118.8,
+ "lo": 117.6,
+ "hi": 119.4,
+ "peak_mib": 5.4
+ },
+ "system": {
+ "median": 25.86,
+ "lo": 25.8,
+ "hi": 25.95,
+ "peak_mib": 4.6
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 229.2,
+ "lo": 228.2,
+ "hi": 229.8,
+ "peak_mib": 5.4
+ },
+ "jemalloc": {
+ "median": 110.2,
+ "lo": 109.9,
+ "hi": 112.2,
+ "peak_mib": 5.0
+ },
+ "mimalloc": {
+ "median": 58.55,
+ "lo": 58.44,
+ "hi": 58.72,
+ "peak_mib": 5.3
+ },
+ "snmalloc": {
+ "median": 118.6,
+ "lo": 117.7,
+ "hi": 119.8,
+ "peak_mib": 5.4
+ },
+ "system": {
+ "median": 25.94,
+ "lo": 25.82,
+ "hi": 26.04,
+ "peak_mib": 4.6
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 226.9,
+ "lo": 226.2,
+ "hi": 227.8,
+ "peak_mib": 4.7
+ },
+ "jemalloc": {
+ "median": 113.2,
+ "lo": 112.9,
+ "hi": 115.8,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 82.88,
+ "lo": 82.38,
+ "hi": 82.99,
+ "peak_mib": 4.5
+ },
+ "snmalloc": {
+ "median": 127.4,
+ "lo": 126.1,
+ "hi": 128.8,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 35.32,
+ "lo": 35.17,
+ "hi": 35.38,
+ "peak_mib": 4.2
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 227.9,
+ "lo": 227.3,
+ "hi": 229.0,
+ "peak_mib": 4.7
+ },
+ "jemalloc": {
+ "median": 113.0,
+ "lo": 112.8,
+ "hi": 114.2,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 83.2,
+ "lo": 83.01,
+ "hi": 83.38,
+ "peak_mib": 4.5
+ },
+ "snmalloc": {
+ "median": 127.8,
+ "lo": 127.2,
+ "hi": 128.7,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 35.49,
+ "lo": 35.41,
+ "hi": 35.57,
+ "peak_mib": 4.2
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn skewed",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 184.2,
+ "lo": 183.4,
+ "hi": 184.8,
+ "peak_mib": 5.1
+ },
+ "jemalloc": {
+ "median": 127.5,
+ "lo": 127.2,
+ "hi": 127.9,
+ "peak_mib": 4.8
+ },
+ "mimalloc": {
+ "median": 153.1,
+ "lo": 152.8,
+ "hi": 153.9,
+ "peak_mib": 4.0
+ },
+ "snmalloc": {
+ "median": 173.3,
+ "lo": 173.0,
+ "hi": 174.1,
+ "peak_mib": 4.2
+ },
+ "system": {
+ "median": 48.07,
+ "lo": 47.87,
+ "hi": 48.21,
+ "peak_mib": 4.2
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 185.3,
+ "lo": 184.6,
+ "hi": 186.2,
+ "peak_mib": 5.1
+ },
+ "jemalloc": {
+ "median": 127.6,
+ "lo": 127.0,
+ "hi": 128.1,
+ "peak_mib": 4.8
+ },
+ "mimalloc": {
+ "median": 155.2,
+ "lo": 154.3,
+ "hi": 155.7,
+ "peak_mib": 4.0
+ },
+ "snmalloc": {
+ "median": 174.0,
+ "lo": 173.3,
+ "hi": 174.5,
+ "peak_mib": 4.2
+ },
+ "system": {
+ "median": 48.93,
+ "lo": 48.72,
+ "hi": 49.14,
+ "peak_mib": 4.2
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed 4 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 876.9,
+ "lo": 875.5,
+ "hi": 878.9,
+ "peak_mib": 14.2
+ },
+ "jemalloc": {
+ "median": 441.9,
+ "lo": 440.1,
+ "hi": 443.6,
+ "peak_mib": 13.4
+ },
+ "mimalloc": {
+ "median": 294.4,
+ "lo": 286.2,
+ "hi": 306.1,
+ "peak_mib": 14.2
+ },
+ "snmalloc": {
+ "median": 434.4,
+ "lo": 428.5,
+ "hi": 443.4,
+ "peak_mib": 13.4
+ },
+ "system": {
+ "median": 37.29,
+ "lo": 35.93,
+ "hi": 37.53,
+ "peak_mib": 19.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 885.3,
+ "lo": 883.1,
+ "hi": 886.2,
+ "peak_mib": 14.2
+ },
+ "jemalloc": {
+ "median": 442.5,
+ "lo": 442.1,
+ "hi": 443.1,
+ "peak_mib": 13.4
+ },
+ "mimalloc": {
+ "median": 289.0,
+ "lo": 282.9,
+ "hi": 298.5,
+ "peak_mib": 14.2
+ },
+ "snmalloc": {
+ "median": 436.7,
+ "lo": 434.7,
+ "hi": 442.4,
+ "peak_mib": 13.4
+ },
+ "system": {
+ "median": 38.15,
+ "lo": 36.7,
+ "hi": 42.33,
+ "peak_mib": 19.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1703.0,
+ "lo": 1699.0,
+ "hi": 1709.0,
+ "peak_mib": 26.6
+ },
+ "jemalloc": {
+ "median": 863.8,
+ "lo": 860.8,
+ "hi": 865.2,
+ "peak_mib": 25.2
+ },
+ "mimalloc": {
+ "median": 436.8,
+ "lo": 430.6,
+ "hi": 440.5,
+ "peak_mib": 45.75
+ },
+ "snmalloc": {
+ "median": 809.0,
+ "lo": 805.7,
+ "hi": 812.4,
+ "peak_mib": 25.2
+ },
+ "system": {
+ "median": 64.93,
+ "lo": 64.71,
+ "hi": 67.93,
+ "peak_mib": 27.6
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1730.0,
+ "lo": 1719.0,
+ "hi": 1753.0,
+ "peak_mib": 26.6
+ },
+ "jemalloc": {
+ "median": 865.3,
+ "lo": 861.7,
+ "hi": 867.0,
+ "peak_mib": 25.2
+ },
+ "mimalloc": {
+ "median": 422.5,
+ "lo": 420.5,
+ "hi": 428.9,
+ "peak_mib": 45.75
+ },
+ "snmalloc": {
+ "median": 810.1,
+ "lo": 808.7,
+ "hi": 816.1,
+ "peak_mib": 25.2
+ },
+ "system": {
+ "median": 65.96,
+ "lo": 65.56,
+ "hi": 68.63,
+ "peak_mib": 27.6
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed 16 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1900.0,
+ "lo": 1820.0,
+ "hi": 1952.0,
+ "peak_mib": 51.5
+ },
+ "jemalloc": {
+ "median": 1048.0,
+ "lo": 1010.0,
+ "hi": 1085.0,
+ "peak_mib": 48.6
+ },
+ "mimalloc": {
+ "median": 614.1,
+ "lo": 604.8,
+ "hi": 629.1,
+ "peak_mib": 78.15
+ },
+ "snmalloc": {
+ "median": 1007.0,
+ "lo": 988.8,
+ "hi": 1023.0,
+ "peak_mib": 48.3
+ },
+ "system": {
+ "median": 90.28,
+ "lo": 88.79,
+ "hi": 91.32,
+ "peak_mib": 216.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1952.0,
+ "lo": 1905.0,
+ "hi": 2047.0,
+ "peak_mib": 51.5
+ },
+ "jemalloc": {
+ "median": 1071.0,
+ "lo": 1045.0,
+ "hi": 1088.0,
+ "peak_mib": 48.6
+ },
+ "mimalloc": {
+ "median": 595.5,
+ "lo": 588.7,
+ "hi": 607.0,
+ "peak_mib": 78.15
+ },
+ "snmalloc": {
+ "median": 1033.0,
+ "lo": 1017.0,
+ "hi": 1050.0,
+ "peak_mib": 48.3
+ },
+ "system": {
+ "median": 93.18,
+ "lo": 90.92,
+ "hi": 95.55,
+ "peak_mib": 216.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn skewed 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1404.0,
+ "lo": 1388.0,
+ "hi": 1410.0,
+ "peak_mib": 30.7
+ },
+ "jemalloc": {
+ "median": 966.8,
+ "lo": 959.7,
+ "hi": 971.7,
+ "peak_mib": 25.35
+ },
+ "mimalloc": {
+ "median": 842.3,
+ "lo": 821.4,
+ "hi": 865.6,
+ "peak_mib": 35.1
+ },
+ "snmalloc": {
+ "median": 1254.0,
+ "lo": 1249.0,
+ "hi": 1293.0,
+ "peak_mib": 29.05
+ },
+ "system": {
+ "median": 165.5,
+ "lo": 164.5,
+ "hi": 167.1,
+ "peak_mib": 18.55
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1373.0,
+ "lo": 1361.0,
+ "hi": 1408.0,
+ "peak_mib": 30.7
+ },
+ "jemalloc": {
+ "median": 950.1,
+ "lo": 946.8,
+ "hi": 964.5,
+ "peak_mib": 25.35
+ },
+ "mimalloc": {
+ "median": 848.5,
+ "lo": 811.4,
+ "hi": 895.0,
+ "peak_mib": 35.1
+ },
+ "snmalloc": {
+ "median": 1239.0,
+ "lo": 1230.0,
+ "hi": 1259.0,
+ "peak_mib": 29.05
+ },
+ "system": {
+ "median": 170.0,
+ "lo": 167.5,
+ "hi": 171.3,
+ "peak_mib": 18.55
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed oversubscribed",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1938.0,
+ "lo": 1890.0,
+ "hi": 2143.0,
+ "peak_mib": 183.0
+ },
+ "jemalloc": {
+ "median": 1127.0,
+ "lo": 1061.0,
+ "hi": 1152.0,
+ "peak_mib": 166.8
+ },
+ "mimalloc": {
+ "median": 786.0,
+ "lo": 760.6,
+ "hi": 821.7,
+ "peak_mib": 259.3
+ },
+ "snmalloc": {
+ "median": 1043.0,
+ "lo": 1026.0,
+ "hi": 1060.0,
+ "peak_mib": 168.3
+ },
+ "system": {
+ "median": 93.7,
+ "lo": 91.47,
+ "hi": 114.6,
+ "peak_mib": 977.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 2015.0,
+ "lo": 1962.0,
+ "hi": 2155.0,
+ "peak_mib": 183.0
+ },
+ "jemalloc": {
+ "median": 1104.0,
+ "lo": 1053.0,
+ "hi": 1121.0,
+ "peak_mib": 166.8
+ },
+ "mimalloc": {
+ "median": 750.4,
+ "lo": 733.9,
+ "hi": 763.4,
+ "peak_mib": 259.3
+ },
+ "snmalloc": {
+ "median": 1073.0,
+ "lo": 1063.0,
+ "hi": 1098.0,
+ "peak_mib": 168.3
+ },
+ "system": {
+ "median": 120.5,
+ "lo": 110.7,
+ "hi": 184.5,
+ "peak_mib": 977.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn large set",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 35.78,
+ "lo": 35.0,
+ "hi": 36.04,
+ "peak_mib": 2111.0
+ },
+ "jemalloc": {
+ "median": 20.53,
+ "lo": 20.15,
+ "hi": 20.89,
+ "peak_mib": 2142.0
+ },
+ "mimalloc": {
+ "median": 8.908,
+ "lo": 8.808,
+ "hi": 9.051,
+ "peak_mib": 2561.0
+ },
+ "snmalloc": {
+ "median": 20.03,
+ "lo": 19.69,
+ "hi": 20.23,
+ "peak_mib": 2167.0
+ },
+ "system": {
+ "median": 5.739,
+ "lo": 5.715,
+ "hi": 5.825,
+ "peak_mib": 3663.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 53.79,
+ "lo": 52.19,
+ "hi": 54.29,
+ "peak_mib": 2111.0
+ },
+ "jemalloc": {
+ "median": 27.5,
+ "lo": 26.5,
+ "hi": 27.82,
+ "peak_mib": 2142.0
+ },
+ "mimalloc": {
+ "median": 10.0,
+ "lo": 9.919,
+ "hi": 10.16,
+ "peak_mib": 2561.0
+ },
+ "snmalloc": {
+ "median": 22.26,
+ "lo": 21.87,
+ "hi": 22.49,
+ "peak_mib": 2167.0
+ },
+ "system": {
+ "median": 6.14,
+ "lo": 6.114,
+ "hi": 6.191,
+ "peak_mib": 3663.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn with work",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 3.414,
+ "lo": 3.412,
+ "hi": 3.417,
+ "peak_mib": 4.8
+ },
+ "jemalloc": {
+ "median": 3.354,
+ "lo": 3.353,
+ "hi": 3.358,
+ "peak_mib": 4.4
+ },
+ "mimalloc": {
+ "median": 3.376,
+ "lo": 3.369,
+ "hi": 3.378,
+ "peak_mib": 4.5
+ },
+ "snmalloc": {
+ "median": 3.404,
+ "lo": 3.402,
+ "hi": 3.406,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 3.148,
+ "lo": 3.141,
+ "hi": 3.149,
+ "peak_mib": 4.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 3.415,
+ "lo": 3.412,
+ "hi": 3.418,
+ "peak_mib": 4.8
+ },
+ "jemalloc": {
+ "median": 3.357,
+ "lo": 3.355,
+ "hi": 3.36,
+ "peak_mib": 4.4
+ },
+ "mimalloc": {
+ "median": 3.379,
+ "lo": 3.373,
+ "hi": 3.383,
+ "peak_mib": 4.5
+ },
+ "snmalloc": {
+ "median": 3.405,
+ "lo": 3.403,
+ "hi": 3.407,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 3.151,
+ "lo": 3.144,
+ "hi": 3.154,
+ "peak_mib": 4.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "larson 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1543.0,
+ "lo": 1524.0,
+ "hi": 1551.0,
+ "peak_mib": 16.9
+ },
+ "jemalloc": {
+ "median": 867.1,
+ "lo": 862.8,
+ "hi": 868.6,
+ "peak_mib": 12.3
+ },
+ "mimalloc": {
+ "median": 663.3,
+ "lo": 654.8,
+ "hi": 677.0,
+ "peak_mib": 15.8
+ },
+ "snmalloc": {
+ "median": 727.2,
+ "lo": 720.1,
+ "hi": 730.3,
+ "peak_mib": 17.85
+ },
+ "system": {
+ "median": 35.6,
+ "lo": 35.43,
+ "hi": 36.36,
+ "peak_mib": 12.05
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1630.0,
+ "lo": 1617.0,
+ "hi": 1645.0,
+ "peak_mib": 16.9
+ },
+ "jemalloc": {
+ "median": 882.0,
+ "lo": 881.0,
+ "hi": 884.3,
+ "peak_mib": 12.3
+ },
+ "mimalloc": {
+ "median": 671.1,
+ "lo": 660.7,
+ "hi": 677.3,
+ "peak_mib": 15.8
+ },
+ "snmalloc": {
+ "median": 730.3,
+ "lo": 728.0,
+ "hi": 734.6,
+ "peak_mib": 17.85
+ },
+ "system": {
+ "median": 36.33,
+ "lo": 35.66,
+ "hi": 36.63,
+ "peak_mib": 12.05
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "ring 4 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 530.2,
+ "lo": 512.5,
+ "hi": 534.8,
+ "peak_mib": 7.45
+ },
+ "jemalloc": {
+ "median": 439.5,
+ "lo": 435.1,
+ "hi": 440.7,
+ "peak_mib": 7.15
+ },
+ "mimalloc": {
+ "median": 102.8,
+ "lo": 89.9,
+ "hi": 107.1,
+ "peak_mib": 5.35
+ },
+ "snmalloc": {
+ "median": 171.4,
+ "lo": 166.8,
+ "hi": 175.0,
+ "peak_mib": 4.2
+ },
+ "system": {
+ "median": 99.98,
+ "lo": 92.37,
+ "hi": 105.5,
+ "peak_mib": 3.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 526.5,
+ "lo": 513.6,
+ "hi": 536.1,
+ "peak_mib": 7.45
+ },
+ "jemalloc": {
+ "median": 435.0,
+ "lo": 429.1,
+ "hi": 444.0,
+ "peak_mib": 7.15
+ },
+ "mimalloc": {
+ "median": 103.2,
+ "lo": 93.58,
+ "hi": 110.0,
+ "peak_mib": 5.35
+ },
+ "snmalloc": {
+ "median": 172.2,
+ "lo": 167.9,
+ "hi": 176.3,
+ "peak_mib": 4.2
+ },
+ "system": {
+ "median": 111.1,
+ "lo": 97.59,
+ "hi": 112.2,
+ "peak_mib": 3.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "ring 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 546.0,
+ "lo": 543.3,
+ "hi": 550.2,
+ "peak_mib": 14.75
+ },
+ "jemalloc": {
+ "median": 543.9,
+ "lo": 540.0,
+ "hi": 546.5,
+ "peak_mib": 17.6
+ },
+ "mimalloc": {
+ "median": 78.66,
+ "lo": 77.79,
+ "hi": 80.45,
+ "peak_mib": 9.4
+ },
+ "snmalloc": {
+ "median": 175.5,
+ "lo": 173.6,
+ "hi": 178.2,
+ "peak_mib": 7.0
+ },
+ "system": {
+ "median": 110.1,
+ "lo": 108.2,
+ "hi": 111.7,
+ "peak_mib": 7.05
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 556.5,
+ "lo": 553.6,
+ "hi": 566.6,
+ "peak_mib": 14.75
+ },
+ "jemalloc": {
+ "median": 559.4,
+ "lo": 553.5,
+ "hi": 563.0,
+ "peak_mib": 17.6
+ },
+ "mimalloc": {
+ "median": 82.22,
+ "lo": 79.66,
+ "hi": 83.38,
+ "peak_mib": 9.4
+ },
+ "snmalloc": {
+ "median": 174.0,
+ "lo": 171.6,
+ "hi": 175.6,
+ "peak_mib": 7.0
+ },
+ "system": {
+ "median": 111.4,
+ "lo": 110.5,
+ "hi": 113.1,
+ "peak_mib": 7.05
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "channel 1 pair",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 75.84,
+ "lo": 75.48,
+ "hi": 76.53,
+ "peak_mib": 3.1
+ },
+ "jemalloc": {
+ "median": 51.37,
+ "lo": 51.2,
+ "hi": 51.51,
+ "peak_mib": 3.65
+ },
+ "mimalloc": {
+ "median": 25.91,
+ "lo": 25.68,
+ "hi": 25.99,
+ "peak_mib": 2.3
+ },
+ "snmalloc": {
+ "median": 51.33,
+ "lo": 50.68,
+ "hi": 51.56,
+ "peak_mib": 2.45
+ },
+ "system": {
+ "median": 29.0,
+ "lo": 28.81,
+ "hi": 29.12,
+ "peak_mib": 2.05
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 76.21,
+ "lo": 75.37,
+ "hi": 77.27,
+ "peak_mib": 3.1
+ },
+ "jemalloc": {
+ "median": 53.4,
+ "lo": 53.16,
+ "hi": 54.03,
+ "peak_mib": 3.65
+ },
+ "mimalloc": {
+ "median": 25.58,
+ "lo": 25.5,
+ "hi": 25.8,
+ "peak_mib": 2.3
+ },
+ "snmalloc": {
+ "median": 46.8,
+ "lo": 43.77,
+ "hi": 51.39,
+ "peak_mib": 2.45
+ },
+ "system": {
+ "median": 28.9,
+ "lo": 28.59,
+ "hi": 29.14,
+ "peak_mib": 2.05
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "channel 4 pairs",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 121.8,
+ "lo": 111.8,
+ "hi": 124.8,
+ "peak_mib": 6.6
+ },
+ "jemalloc": {
+ "median": 135.2,
+ "lo": 132.1,
+ "hi": 138.5,
+ "peak_mib": 9.5
+ },
+ "mimalloc": {
+ "median": 56.14,
+ "lo": 54.38,
+ "hi": 60.31,
+ "peak_mib": 4.3
+ },
+ "snmalloc": {
+ "median": 112.9,
+ "lo": 111.3,
+ "hi": 117.3,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 45.02,
+ "lo": 44.34,
+ "hi": 46.0,
+ "peak_mib": 3.5
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 123.1,
+ "lo": 115.6,
+ "hi": 125.8,
+ "peak_mib": 6.6
+ },
+ "jemalloc": {
+ "median": 131.3,
+ "lo": 130.3,
+ "hi": 133.0,
+ "peak_mib": 9.5
+ },
+ "mimalloc": {
+ "median": 56.9,
+ "lo": 53.8,
+ "hi": 61.07,
+ "peak_mib": 4.3
+ },
+ "snmalloc": {
+ "median": 114.3,
+ "lo": 111.4,
+ "hi": 116.3,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 45.24,
+ "lo": 44.81,
+ "hi": 47.9,
+ "peak_mib": 3.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "shared table 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 94.25,
+ "lo": 93.12,
+ "hi": 96.62,
+ "peak_mib": 50.7
+ },
+ "jemalloc": {
+ "median": 92.76,
+ "lo": 90.01,
+ "hi": 93.59,
+ "peak_mib": 44.2
+ },
+ "mimalloc": {
+ "median": 38.92,
+ "lo": 38.76,
+ "hi": 39.24,
+ "peak_mib": 26.45
+ },
+ "snmalloc": {
+ "median": 35.13,
+ "lo": 34.84,
+ "hi": 35.92,
+ "peak_mib": 43.85
+ },
+ "system": {
+ "median": 16.86,
+ "lo": 14.95,
+ "hi": 17.83,
+ "peak_mib": 28.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 94.6,
+ "lo": 93.51,
+ "hi": 95.87,
+ "peak_mib": 50.7
+ },
+ "jemalloc": {
+ "median": 88.6,
+ "lo": 82.23,
+ "hi": 90.96,
+ "peak_mib": 44.2
+ },
+ "mimalloc": {
+ "median": 39.11,
+ "lo": 38.94,
+ "hi": 39.34,
+ "peak_mib": 26.45
+ },
+ "snmalloc": {
+ "median": 35.72,
+ "lo": 35.22,
+ "hi": 36.17,
+ "peak_mib": 43.85
+ },
+ "system": {
+ "median": 22.22,
+ "lo": 21.44,
+ "hi": 23.25,
+ "peak_mib": 28.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "thread lifecycle",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 184.7,
+ "lo": 183.0,
+ "hi": 191.2,
+ "peak_mib": 9.9
+ },
+ "jemalloc": {
+ "median": 43.79,
+ "lo": 41.55,
+ "hi": 46.43,
+ "peak_mib": 6.2
+ },
+ "mimalloc": {
+ "median": 102.1,
+ "lo": 101.2,
+ "hi": 102.3,
+ "peak_mib": 6.8
+ },
+ "snmalloc": {
+ "median": 181.9,
+ "lo": 174.1,
+ "hi": 188.0,
+ "peak_mib": 5.0
+ },
+ "system": {
+ "median": 36.17,
+ "lo": 35.42,
+ "hi": 36.34,
+ "peak_mib": 2.8
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 196.7,
+ "lo": 193.8,
+ "hi": 197.9,
+ "peak_mib": 9.9
+ },
+ "jemalloc": {
+ "median": 44.1,
+ "lo": 41.65,
+ "hi": 46.66,
+ "peak_mib": 6.2
+ },
+ "mimalloc": {
+ "median": 102.3,
+ "lo": 101.6,
+ "hi": 102.8,
+ "peak_mib": 6.8
+ },
+ "snmalloc": {
+ "median": 190.0,
+ "lo": 186.4,
+ "hi": 190.9,
+ "peak_mib": 5.0
+ },
+ "system": {
+ "median": 36.39,
+ "lo": 35.99,
+ "hi": 37.55,
+ "peak_mib": 2.8
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "false sharing",
+ "name": "cache scratch 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 31050.0,
+ "lo": 31040.0,
+ "hi": 31090.0,
+ "peak_mib": 2.7
+ },
+ "jemalloc": {
+ "median": 13100.0,
+ "lo": 12860.0,
+ "hi": 14190.0,
+ "peak_mib": 3.2
+ },
+ "mimalloc": {
+ "median": 30940.0,
+ "lo": 30870.0,
+ "hi": 30970.0,
+ "peak_mib": 2.3
+ },
+ "snmalloc": {
+ "median": 31020.0,
+ "lo": 30990.0,
+ "hi": 31030.0,
+ "peak_mib": 2.1
+ },
+ "system": {
+ "median": 27750.0,
+ "lo": 27180.0,
+ "hi": 28560.0,
+ "peak_mib": 1.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 31070.0,
+ "lo": 30990.0,
+ "hi": 31090.0,
+ "peak_mib": 2.7
+ },
+ "jemalloc": {
+ "median": 14320.0,
+ "lo": 14070.0,
+ "hi": 22710.0,
+ "peak_mib": 3.2
+ },
+ "mimalloc": {
+ "median": 30940.0,
+ "lo": 30760.0,
+ "hi": 30970.0,
+ "peak_mib": 2.3
+ },
+ "snmalloc": {
+ "median": 31000.0,
+ "lo": 30950.0,
+ "hi": 31030.0,
+ "peak_mib": 2.1
+ },
+ "system": {
+ "median": 26420.0,
+ "lo": 26140.0,
+ "hi": 27020.0,
+ "peak_mib": 1.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "false sharing",
+ "name": "cache thrash 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 31050.0,
+ "lo": 31040.0,
+ "hi": 31090.0,
+ "peak_mib": 2.6
+ },
+ "jemalloc": {
+ "median": 30900.0,
+ "lo": 30860.0,
+ "hi": 30930.0,
+ "peak_mib": 3.25
+ },
+ "mimalloc": {
+ "median": 30950.0,
+ "lo": 30940.0,
+ "hi": 30980.0,
+ "peak_mib": 2.2
+ },
+ "snmalloc": {
+ "median": 30990.0,
+ "lo": 30980.0,
+ "hi": 31020.0,
+ "peak_mib": 2.0
+ },
+ "system": {
+ "median": 27910.0,
+ "lo": 27330.0,
+ "hi": 28950.0,
+ "peak_mib": 1.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 31060.0,
+ "lo": 31040.0,
+ "hi": 31090.0,
+ "peak_mib": 2.6
+ },
+ "jemalloc": {
+ "median": 30930.0,
+ "lo": 30860.0,
+ "hi": 30960.0,
+ "peak_mib": 3.25
+ },
+ "mimalloc": {
+ "median": 30910.0,
+ "lo": 30840.0,
+ "hi": 30950.0,
+ "peak_mib": 2.2
+ },
+ "snmalloc": {
+ "median": 30990.0,
+ "lo": 30970.0,
+ "hi": 31010.0,
+ "peak_mib": 2.0
+ },
+ "system": {
+ "median": 27210.0,
+ "lo": 26730.0,
+ "hi": 27850.0,
+ "peak_mib": 1.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "hash map",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 13.91,
+ "lo": 13.88,
+ "hi": 13.96,
+ "peak_mib": 153.6
+ },
+ "jemalloc": {
+ "median": 12.66,
+ "lo": 12.44,
+ "hi": 12.69,
+ "peak_mib": 161.0
+ },
+ "mimalloc": {
+ "median": 11.23,
+ "lo": 11.12,
+ "hi": 11.26,
+ "peak_mib": 162.7
+ },
+ "snmalloc": {
+ "median": 13.56,
+ "lo": 13.46,
+ "hi": 13.65,
+ "peak_mib": 185.8
+ },
+ "system": {
+ "median": 7.398,
+ "lo": 7.381,
+ "hi": 7.422,
+ "peak_mib": 199.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 14.71,
+ "lo": 14.61,
+ "hi": 14.77,
+ "peak_mib": 153.6
+ },
+ "jemalloc": {
+ "median": 12.96,
+ "lo": 12.75,
+ "hi": 13.01,
+ "peak_mib": 161.0
+ },
+ "mimalloc": {
+ "median": 11.66,
+ "lo": 11.61,
+ "hi": 11.7,
+ "peak_mib": 162.7
+ },
+ "snmalloc": {
+ "median": 13.73,
+ "lo": 13.69,
+ "hi": 13.77,
+ "peak_mib": 185.8
+ },
+ "system": {
+ "median": 7.555,
+ "lo": 7.479,
+ "hi": 7.615,
+ "peak_mib": 199.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "btree map",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 6.674,
+ "lo": 6.575,
+ "hi": 6.701,
+ "peak_mib": 35.5
+ },
+ "jemalloc": {
+ "median": 6.133,
+ "lo": 6.083,
+ "hi": 6.172,
+ "peak_mib": 36.65
+ },
+ "mimalloc": {
+ "median": 5.557,
+ "lo": 5.517,
+ "hi": 5.612,
+ "peak_mib": 37.6
+ },
+ "snmalloc": {
+ "median": 6.238,
+ "lo": 6.172,
+ "hi": 6.262,
+ "peak_mib": 37.9
+ },
+ "system": {
+ "median": 5.114,
+ "lo": 5.078,
+ "hi": 5.178,
+ "peak_mib": 35.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 6.715,
+ "lo": 6.687,
+ "hi": 6.771,
+ "peak_mib": 35.5
+ },
+ "jemalloc": {
+ "median": 6.243,
+ "lo": 6.2,
+ "hi": 6.276,
+ "peak_mib": 36.65
+ },
+ "mimalloc": {
+ "median": 5.674,
+ "lo": 5.655,
+ "hi": 5.723,
+ "peak_mib": 37.6
+ },
+ "snmalloc": {
+ "median": 6.325,
+ "lo": 6.286,
+ "hi": 6.393,
+ "peak_mib": 37.9
+ },
+ "system": {
+ "median": 5.116,
+ "lo": 5.066,
+ "hi": 5.184,
+ "peak_mib": 35.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "strings",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 8.752,
+ "lo": 8.725,
+ "hi": 8.799,
+ "peak_mib": 14.5
+ },
+ "jemalloc": {
+ "median": 7.604,
+ "lo": 7.569,
+ "hi": 7.626,
+ "peak_mib": 15.9
+ },
+ "mimalloc": {
+ "median": 8.761,
+ "lo": 8.753,
+ "hi": 8.781,
+ "peak_mib": 15.7
+ },
+ "snmalloc": {
+ "median": 8.9,
+ "lo": 8.861,
+ "hi": 8.941,
+ "peak_mib": 18.0
+ },
+ "system": {
+ "median": 7.553,
+ "lo": 7.53,
+ "hi": 7.583,
+ "peak_mib": 15.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 8.787,
+ "lo": 8.73,
+ "hi": 8.817,
+ "peak_mib": 14.5
+ },
+ "jemalloc": {
+ "median": 7.607,
+ "lo": 7.6,
+ "hi": 7.631,
+ "peak_mib": 15.9
+ },
+ "mimalloc": {
+ "median": 8.766,
+ "lo": 8.755,
+ "hi": 8.782,
+ "peak_mib": 15.7
+ },
+ "snmalloc": {
+ "median": 8.894,
+ "lo": 8.879,
+ "hi": 8.923,
+ "peak_mib": 18.0
+ },
+ "system": {
+ "median": 7.56,
+ "lo": 7.54,
+ "hi": 7.592,
+ "peak_mib": 15.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "linked list",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 212.0,
+ "lo": 205.0,
+ "hi": 213.1,
+ "peak_mib": 25.6
+ },
+ "jemalloc": {
+ "median": 65.61,
+ "lo": 65.29,
+ "hi": 66.11,
+ "peak_mib": 33.0
+ },
+ "mimalloc": {
+ "median": 143.8,
+ "lo": 143.6,
+ "hi": 144.3,
+ "peak_mib": 32.3
+ },
+ "snmalloc": {
+ "median": 178.5,
+ "lo": 176.9,
+ "hi": 180.1,
+ "peak_mib": 33.5
+ },
+ "system": {
+ "median": 89.8,
+ "lo": 89.54,
+ "hi": 90.11,
+ "peak_mib": 32.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 223.0,
+ "lo": 214.3,
+ "hi": 223.6,
+ "peak_mib": 25.6
+ },
+ "jemalloc": {
+ "median": 66.87,
+ "lo": 66.47,
+ "hi": 67.3,
+ "peak_mib": 33.0
+ },
+ "mimalloc": {
+ "median": 148.3,
+ "lo": 147.9,
+ "hi": 148.5,
+ "peak_mib": 32.3
+ },
+ "snmalloc": {
+ "median": 187.0,
+ "lo": 184.2,
+ "hi": 189.0,
+ "peak_mib": 33.5
+ },
+ "system": {
+ "median": 92.29,
+ "lo": 92.12,
+ "hi": 92.55,
+ "peak_mib": 32.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "binary trees",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 171.8,
+ "lo": 171.2,
+ "hi": 172.2,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 55.85,
+ "lo": 55.58,
+ "hi": 56.02,
+ "peak_mib": 3.8
+ },
+ "mimalloc": {
+ "median": 117.7,
+ "lo": 115.2,
+ "hi": 118.7,
+ "peak_mib": 3.7
+ },
+ "snmalloc": {
+ "median": 153.9,
+ "lo": 151.7,
+ "hi": 155.7,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 74.3,
+ "lo": 73.78,
+ "hi": 74.52,
+ "peak_mib": 3.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 174.6,
+ "lo": 173.3,
+ "hi": 175.2,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 56.17,
+ "lo": 55.92,
+ "hi": 56.45,
+ "peak_mib": 3.8
+ },
+ "mimalloc": {
+ "median": 119.3,
+ "lo": 117.9,
+ "hi": 119.8,
+ "peak_mib": 3.7
+ },
+ "snmalloc": {
+ "median": 158.2,
+ "lo": 156.1,
+ "hi": 159.6,
+ "peak_mib": 4.4
+ },
+ "system": {
+ "median": 75.16,
+ "lo": 74.82,
+ "hi": 75.38,
+ "peak_mib": 3.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "tree rewrite",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 196.2,
+ "lo": 194.4,
+ "hi": 197.7,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 57.78,
+ "lo": 57.63,
+ "hi": 58.03,
+ "peak_mib": 3.8
+ },
+ "mimalloc": {
+ "median": 128.4,
+ "lo": 128.0,
+ "hi": 128.6,
+ "peak_mib": 3.8
+ },
+ "snmalloc": {
+ "median": 171.2,
+ "lo": 170.0,
+ "hi": 171.5,
+ "peak_mib": 3.5
+ },
+ "system": {
+ "median": 79.48,
+ "lo": 78.55,
+ "hi": 79.72,
+ "peak_mib": 3.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 195.1,
+ "lo": 193.6,
+ "hi": 196.6,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 57.67,
+ "lo": 57.34,
+ "hi": 57.92,
+ "peak_mib": 3.8
+ },
+ "mimalloc": {
+ "median": 128.0,
+ "lo": 127.6,
+ "hi": 128.3,
+ "peak_mib": 3.8
+ },
+ "snmalloc": {
+ "median": 170.9,
+ "lo": 170.3,
+ "hi": 171.1,
+ "peak_mib": 3.5
+ },
+ "system": {
+ "median": 79.73,
+ "lo": 79.51,
+ "hi": 79.89,
+ "peak_mib": 3.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "binary trees with work",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 91.73,
+ "lo": 91.48,
+ "hi": 91.81,
+ "peak_mib": 4.9
+ },
+ "jemalloc": {
+ "median": 43.81,
+ "lo": 43.77,
+ "hi": 43.93,
+ "peak_mib": 5.8
+ },
+ "mimalloc": {
+ "median": 75.13,
+ "lo": 74.84,
+ "hi": 75.21,
+ "peak_mib": 5.7
+ },
+ "snmalloc": {
+ "median": 88.62,
+ "lo": 88.35,
+ "hi": 88.74,
+ "peak_mib": 7.4
+ },
+ "system": {
+ "median": 54.37,
+ "lo": 54.24,
+ "hi": 54.42,
+ "peak_mib": 5.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 91.15,
+ "lo": 90.95,
+ "hi": 91.69,
+ "peak_mib": 4.9
+ },
+ "jemalloc": {
+ "median": 43.92,
+ "lo": 43.81,
+ "hi": 43.96,
+ "peak_mib": 5.8
+ },
+ "mimalloc": {
+ "median": 75.22,
+ "lo": 75.07,
+ "hi": 75.27,
+ "peak_mib": 5.7
+ },
+ "snmalloc": {
+ "median": 85.26,
+ "lo": 85.02,
+ "hi": 85.43,
+ "peak_mib": 7.4
+ },
+ "system": {
+ "median": 54.32,
+ "lo": 53.87,
+ "hi": 54.4,
+ "peak_mib": 5.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "vec growth",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 665.8,
+ "lo": 662.6,
+ "hi": 678.0,
+ "peak_mib": 12.1
+ },
+ "jemalloc": {
+ "median": 950.4,
+ "lo": 900.6,
+ "hi": 998.8,
+ "peak_mib": 16.8
+ },
+ "mimalloc": {
+ "median": 630.5,
+ "lo": 629.6,
+ "hi": 632.5,
+ "peak_mib": 17.5
+ },
+ "snmalloc": {
+ "median": 807.9,
+ "lo": 771.1,
+ "hi": 822.6,
+ "peak_mib": 14.6
+ },
+ "system": {
+ "median": 871.8,
+ "lo": 832.6,
+ "hi": 887.4,
+ "peak_mib": 501.5
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 675.7,
+ "lo": 664.5,
+ "hi": 683.4,
+ "peak_mib": 12.1
+ },
+ "jemalloc": {
+ "median": 947.2,
+ "lo": 903.3,
+ "hi": 994.0,
+ "peak_mib": 16.8
+ },
+ "mimalloc": {
+ "median": 630.7,
+ "lo": 630.1,
+ "hi": 633.8,
+ "peak_mib": 17.5
+ },
+ "snmalloc": {
+ "median": 826.3,
+ "lo": 763.3,
+ "hi": 855.0,
+ "peak_mib": 14.6
+ },
+ "system": {
+ "median": 857.4,
+ "lo": 848.4,
+ "hi": 889.2,
+ "peak_mib": 501.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "string growth",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 2964.0,
+ "lo": 2944.0,
+ "hi": 2971.0,
+ "peak_mib": 9.9
+ },
+ "jemalloc": {
+ "median": 2365.0,
+ "lo": 2327.0,
+ "hi": 2487.0,
+ "peak_mib": 8.9
+ },
+ "mimalloc": {
+ "median": 2988.0,
+ "lo": 2972.0,
+ "hi": 3005.0,
+ "peak_mib": 9.7
+ },
+ "snmalloc": {
+ "median": 1800.0,
+ "lo": 1798.0,
+ "hi": 1806.0,
+ "peak_mib": 8.8
+ },
+ "system": {
+ "median": 3057.0,
+ "lo": 3043.0,
+ "hi": 3071.0,
+ "peak_mib": 7.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 2984.0,
+ "lo": 2962.0,
+ "hi": 2998.0,
+ "peak_mib": 9.9
+ },
+ "jemalloc": {
+ "median": 2622.0,
+ "lo": 2483.0,
+ "hi": 2821.0,
+ "peak_mib": 8.9
+ },
+ "mimalloc": {
+ "median": 3012.0,
+ "lo": 2987.0,
+ "hi": 3045.0,
+ "peak_mib": 9.7
+ },
+ "snmalloc": {
+ "median": 1806.0,
+ "lo": 1802.0,
+ "hi": 1818.0,
+ "peak_mib": 8.8
+ },
+ "system": {
+ "median": 3092.0,
+ "lo": 3062.0,
+ "hi": 3109.0,
+ "peak_mib": 7.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "many vectors",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 303.1,
+ "lo": 301.2,
+ "hi": 303.9,
+ "peak_mib": 19.3
+ },
+ "jemalloc": {
+ "median": 292.1,
+ "lo": 289.5,
+ "hi": 294.5,
+ "peak_mib": 18.6
+ },
+ "mimalloc": {
+ "median": 300.6,
+ "lo": 299.8,
+ "hi": 304.3,
+ "peak_mib": 18.0
+ },
+ "snmalloc": {
+ "median": 297.2,
+ "lo": 295.9,
+ "hi": 298.3,
+ "peak_mib": 19.3
+ },
+ "system": {
+ "median": 284.2,
+ "lo": 282.3,
+ "hi": 286.3,
+ "peak_mib": 33.5
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 305.1,
+ "lo": 303.2,
+ "hi": 306.2,
+ "peak_mib": 19.3
+ },
+ "jemalloc": {
+ "median": 296.5,
+ "lo": 295.0,
+ "hi": 298.0,
+ "peak_mib": 18.6
+ },
+ "mimalloc": {
+ "median": 302.5,
+ "lo": 301.8,
+ "hi": 306.4,
+ "peak_mib": 18.0
+ },
+ "snmalloc": {
+ "median": 299.7,
+ "lo": 298.1,
+ "hi": 300.2,
+ "peak_mib": 19.3
+ },
+ "system": {
+ "median": 288.3,
+ "lo": 287.2,
+ "hi": 291.3,
+ "peak_mib": 33.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "realloc random",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 12.89,
+ "lo": 12.82,
+ "hi": 13.0,
+ "peak_mib": 20.0
+ },
+ "jemalloc": {
+ "median": 7.729,
+ "lo": 7.663,
+ "hi": 7.781,
+ "peak_mib": 16.2
+ },
+ "mimalloc": {
+ "median": 12.18,
+ "lo": 12.12,
+ "hi": 12.31,
+ "peak_mib": 16.6
+ },
+ "snmalloc": {
+ "median": 8.427,
+ "lo": 8.369,
+ "hi": 8.479,
+ "peak_mib": 13.9
+ },
+ "system": {
+ "median": 9.106,
+ "lo": 9.044,
+ "hi": 9.134,
+ "peak_mib": 15.8
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 12.86,
+ "lo": 12.8,
+ "hi": 12.95,
+ "peak_mib": 20.0
+ },
+ "jemalloc": {
+ "median": 7.721,
+ "lo": 7.692,
+ "hi": 7.773,
+ "peak_mib": 16.2
+ },
+ "mimalloc": {
+ "median": 12.26,
+ "lo": 12.15,
+ "hi": 12.32,
+ "peak_mib": 16.6
+ },
+ "snmalloc": {
+ "median": 8.474,
+ "lo": 8.404,
+ "hi": 8.551,
+ "peak_mib": 13.9
+ },
+ "system": {
+ "median": 9.099,
+ "lo": 9.03,
+ "hi": 9.142,
+ "peak_mib": 15.8
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "large",
+ "name": "medium blocks",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.946,
+ "lo": 1.93,
+ "hi": 1.993,
+ "peak_mib": 61.0
+ },
+ "jemalloc": {
+ "median": 1.159,
+ "lo": 1.146,
+ "hi": 1.183,
+ "peak_mib": 58.0
+ },
+ "mimalloc": {
+ "median": 1.448,
+ "lo": 1.438,
+ "hi": 1.457,
+ "peak_mib": 124.6
+ },
+ "snmalloc": {
+ "median": 0.5755,
+ "lo": 0.564,
+ "hi": 0.581,
+ "peak_mib": 63.4
+ },
+ "system": {
+ "median": 1.648,
+ "lo": 1.626,
+ "hi": 1.662,
+ "peak_mib": 57.6
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.014,
+ "lo": 1.982,
+ "hi": 2.052,
+ "peak_mib": 61.0
+ },
+ "jemalloc": {
+ "median": 1.216,
+ "lo": 1.196,
+ "hi": 1.221,
+ "peak_mib": 58.0
+ },
+ "mimalloc": {
+ "median": 1.493,
+ "lo": 1.486,
+ "hi": 1.504,
+ "peak_mib": 124.6
+ },
+ "snmalloc": {
+ "median": 0.5795,
+ "lo": 0.5685,
+ "hi": 0.587,
+ "peak_mib": 63.4
+ },
+ "system": {
+ "median": 1.689,
+ "lo": 1.683,
+ "hi": 1.695,
+ "peak_mib": 57.6
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "large",
+ "name": "large blocks",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.1615,
+ "lo": 0.159,
+ "hi": 0.169,
+ "peak_mib": 23.2
+ },
+ "jemalloc": {
+ "median": 0.006,
+ "lo": 0.006,
+ "hi": 0.006,
+ "peak_mib": 23.1
+ },
+ "mimalloc": {
+ "median": 0.1935,
+ "lo": 0.189,
+ "hi": 0.196,
+ "peak_mib": 18.0
+ },
+ "snmalloc": {
+ "median": 0.009,
+ "lo": 0.0085,
+ "hi": 0.009,
+ "peak_mib": 18.8
+ },
+ "system": {
+ "median": 0.1625,
+ "lo": 0.159,
+ "hi": 0.166,
+ "peak_mib": 22.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.1985,
+ "lo": 0.1935,
+ "hi": 0.208,
+ "peak_mib": 23.2
+ },
+ "jemalloc": {
+ "median": 0.006,
+ "lo": 0.006,
+ "hi": 0.006,
+ "peak_mib": 23.1
+ },
+ "mimalloc": {
+ "median": 0.231,
+ "lo": 0.227,
+ "hi": 0.236,
+ "peak_mib": 18.0
+ },
+ "snmalloc": {
+ "median": 0.009,
+ "lo": 0.009,
+ "hi": 0.01,
+ "peak_mib": 18.8
+ },
+ "system": {
+ "median": 0.1975,
+ "lo": 0.192,
+ "hi": 0.2015,
+ "peak_mib": 22.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "memory",
+ "name": "burst retention",
+ "lower": true,
+ "size": true,
+ "primary": "value",
+ "metrics": {
+ "value": {
+ "unit": "MiB",
+ "results": {
+ "bcmalloc": {
+ "median": 7.406,
+ "lo": 7.406,
+ "hi": 7.406,
+ "peak_mib": 264.5
+ },
+ "jemalloc": {
+ "median": 266.3,
+ "lo": 266.3,
+ "hi": 266.3,
+ "peak_mib": 268.0
+ },
+ "mimalloc": {
+ "median": 260.6,
+ "lo": 260.6,
+ "hi": 260.6,
+ "peak_mib": 262.3
+ },
+ "snmalloc": {
+ "median": 5.469,
+ "lo": 5.469,
+ "hi": 5.5,
+ "peak_mib": 262.9
+ },
+ "system": {
+ "median": 21.78,
+ "lo": 21.78,
+ "hi": 21.78,
+ "peak_mib": 262.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "memory",
+ "name": "half freed",
+ "lower": true,
+ "size": true,
+ "primary": "value",
+ "metrics": {
+ "value": {
+ "unit": "MiB",
+ "results": {
+ "bcmalloc": {
+ "median": 154.0,
+ "lo": 154.0,
+ "hi": 154.0,
+ "peak_mib": 155.8
+ },
+ "jemalloc": {
+ "median": 155.9,
+ "lo": 155.8,
+ "hi": 155.9,
+ "peak_mib": 157.5
+ },
+ "mimalloc": {
+ "median": 153.2,
+ "lo": 153.2,
+ "hi": 153.2,
+ "peak_mib": 154.9
+ },
+ "snmalloc": {
+ "median": 153.6,
+ "lo": 153.6,
+ "hi": 153.6,
+ "peak_mib": 155.0
+ },
+ "system": {
+ "median": 153.2,
+ "lo": 153.2,
+ "hi": 153.2,
+ "peak_mib": 154.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "memory",
+ "name": "phase churn",
+ "lower": true,
+ "size": true,
+ "primary": "value",
+ "metrics": {
+ "value": {
+ "unit": "MiB",
+ "results": {
+ "bcmalloc": {
+ "median": 169.2,
+ "lo": 169.2,
+ "hi": 169.3,
+ "peak_mib": 281.6
+ },
+ "jemalloc": {
+ "median": 163.2,
+ "lo": 162.0,
+ "hi": 164.7,
+ "peak_mib": 244.4
+ },
+ "mimalloc": {
+ "median": 148.2,
+ "lo": 148.2,
+ "hi": 148.2,
+ "peak_mib": 258.8
+ },
+ "snmalloc": {
+ "median": 118.1,
+ "lo": 118.1,
+ "hi": 118.1,
+ "peak_mib": 198.6
+ },
+ "system": {
+ "median": 132.5,
+ "lo": 132.3,
+ "hi": 134.4,
+ "peak_mib": 269.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "latency",
+ "name": "latency churn 1 thread",
+ "lower": true,
+ "size": false,
+ "primary": "p99",
+ "metrics": {
+ "p50": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 1.953,
+ "lo": 1.312,
+ "hi": 1.953,
+ "peak_mib": 10.75
+ },
+ "jemalloc": {
+ "median": 3.906,
+ "lo": 3.906,
+ "hi": 3.906,
+ "peak_mib": 10.4
+ },
+ "mimalloc": {
+ "median": 4.562,
+ "lo": 4.562,
+ "hi": 4.562,
+ "peak_mib": 10.5
+ },
+ "snmalloc": {
+ "median": 3.266,
+ "lo": 3.266,
+ "hi": 3.266,
+ "peak_mib": 10.35
+ },
+ "system": {
+ "median": 13.02,
+ "lo": 13.02,
+ "hi": 13.02,
+ "peak_mib": 12.4
+ }
+ }
+ },
+ "p99": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 3.266,
+ "lo": 3.266,
+ "hi": 3.266,
+ "peak_mib": 10.75
+ },
+ "jemalloc": {
+ "median": 7.812,
+ "lo": 7.812,
+ "hi": 7.812,
+ "peak_mib": 10.4
+ },
+ "mimalloc": {
+ "median": 7.156,
+ "lo": 7.156,
+ "hi": 7.813,
+ "peak_mib": 10.5
+ },
+ "snmalloc": {
+ "median": 5.219,
+ "lo": 5.219,
+ "hi": 5.86,
+ "peak_mib": 10.35
+ },
+ "system": {
+ "median": 16.92,
+ "lo": 16.92,
+ "hi": 17.9,
+ "peak_mib": 12.4
+ }
+ }
+ },
+ "p999": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 5.203,
+ "lo": 5.203,
+ "hi": 5.531,
+ "peak_mib": 10.75
+ },
+ "jemalloc": {
+ "median": 9.766,
+ "lo": 9.766,
+ "hi": 10.74,
+ "peak_mib": 10.4
+ },
+ "mimalloc": {
+ "median": 9.125,
+ "lo": 9.125,
+ "hi": 10.74,
+ "peak_mib": 10.5
+ },
+ "snmalloc": {
+ "median": 8.461,
+ "lo": 8.453,
+ "hi": 8.789,
+ "peak_mib": 10.35
+ },
+ "system": {
+ "median": 19.53,
+ "lo": 19.53,
+ "hi": 26.04,
+ "peak_mib": 12.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "latency",
+ "name": "latency churn 8 threads",
+ "lower": true,
+ "size": false,
+ "primary": "p99",
+ "metrics": {
+ "p50": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 1.953,
+ "lo": 1.953,
+ "hi": 1.953,
+ "peak_mib": 83.7
+ },
+ "jemalloc": {
+ "median": 3.906,
+ "lo": 3.906,
+ "hi": 3.906,
+ "peak_mib": 61.0
+ },
+ "mimalloc": {
+ "median": 7.156,
+ "lo": 7.156,
+ "hi": 7.164,
+ "peak_mib": 82.4
+ },
+ "snmalloc": {
+ "median": 3.906,
+ "lo": 3.906,
+ "hi": 3.906,
+ "peak_mib": 74.7
+ },
+ "system": {
+ "median": 57.3,
+ "lo": 55.98,
+ "hi": 57.94,
+ "peak_mib": 87.4
+ }
+ }
+ },
+ "p99": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 3.906,
+ "lo": 3.266,
+ "hi": 3.906,
+ "peak_mib": 83.7
+ },
+ "jemalloc": {
+ "median": 7.812,
+ "lo": 7.812,
+ "hi": 7.812,
+ "peak_mib": 61.0
+ },
+ "mimalloc": {
+ "median": 15.63,
+ "lo": 15.3,
+ "hi": 16.27,
+ "peak_mib": 82.4
+ },
+ "snmalloc": {
+ "median": 7.172,
+ "lo": 7.172,
+ "hi": 7.172,
+ "peak_mib": 74.7
+ },
+ "system": {
+ "median": 108.1,
+ "lo": 104.2,
+ "hi": 109.4,
+ "peak_mib": 87.4
+ }
+ }
+ },
+ "p999": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 5.219,
+ "lo": 5.219,
+ "hi": 5.219,
+ "peak_mib": 83.7
+ },
+ "jemalloc": {
+ "median": 10.41,
+ "lo": 9.766,
+ "hi": 10.41,
+ "peak_mib": 61.0
+ },
+ "mimalloc": {
+ "median": 22.14,
+ "lo": 21.48,
+ "hi": 22.46,
+ "peak_mib": 82.4
+ },
+ "snmalloc": {
+ "median": 10.41,
+ "lo": 9.766,
+ "hi": 10.42,
+ "peak_mib": 74.7
+ },
+ "system": {
+ "median": 142.6,
+ "lo": 140.3,
+ "hi": 154.3,
+ "peak_mib": 87.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "latency",
+ "name": "latency remote frees",
+ "lower": true,
+ "size": false,
+ "primary": "p99",
+ "metrics": {
+ "p50": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 1.312,
+ "lo": 1.312,
+ "hi": 1.312,
+ "peak_mib": 54.85
+ },
+ "jemalloc": {
+ "median": 7.812,
+ "lo": 6.531,
+ "hi": 7.812,
+ "peak_mib": 51.05
+ },
+ "mimalloc": {
+ "median": 6.515,
+ "lo": 6.5,
+ "hi": 6.531,
+ "peak_mib": 43.2
+ },
+ "snmalloc": {
+ "median": 6.5,
+ "lo": 5.219,
+ "hi": 6.5,
+ "peak_mib": 47.0
+ },
+ "system": {
+ "median": 29.3,
+ "lo": 27.34,
+ "hi": 31.89,
+ "peak_mib": 66.8
+ }
+ }
+ },
+ "p99": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 37.75,
+ "lo": 36.44,
+ "hi": 39.7,
+ "peak_mib": 54.85
+ },
+ "jemalloc": {
+ "median": 43.61,
+ "lo": 42.97,
+ "hi": 44.27,
+ "peak_mib": 51.05
+ },
+ "mimalloc": {
+ "median": 304.7,
+ "lo": 291.7,
+ "hi": 309.9,
+ "peak_mib": 43.2
+ },
+ "snmalloc": {
+ "median": 204.4,
+ "lo": 186.2,
+ "hi": 218.8,
+ "peak_mib": 47.0
+ },
+ "system": {
+ "median": 118.5,
+ "lo": 114.6,
+ "hi": 141.9,
+ "peak_mib": 66.8
+ }
+ }
+ },
+ "p999": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 313.2,
+ "lo": 311.2,
+ "hi": 315.8,
+ "peak_mib": 54.85
+ },
+ "jemalloc": {
+ "median": 74.22,
+ "lo": 72.92,
+ "hi": 77.47,
+ "peak_mib": 51.05
+ },
+ "mimalloc": {
+ "median": 597.0,
+ "lo": 578.1,
+ "hi": 619.8,
+ "peak_mib": 43.2
+ },
+ "snmalloc": {
+ "median": 946.0,
+ "lo": 920.6,
+ "hi": 993.5,
+ "peak_mib": 47.0
+ },
+ "system": {
+ "median": 369.8,
+ "lo": 333.3,
+ "hi": 475.3,
+ "peak_mib": 66.8
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ {
+ "suite": "dev",
+ "machine": "linux",
+ "description": "AMD EPYC 9354P 32-Core Processor, Ubuntu 24.04.2 LTS, Linux 7.0.0",
+ "date": "2026-11-14",
+ "samples": 10,
+ "baseline": "mimalloc",
+ "allocators": [
+ "system",
+ "bcmalloc",
+ "mimalloc",
+ "jemalloc",
+ "snmalloc"
+ ],
+ "workloads": [
+ {
+ "group": "pair",
+ "name": "pair 16 B",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 300.8,
+ "lo": 286.9,
+ "hi": 304.4,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 251.6,
+ "lo": 251.4,
+ "hi": 251.7,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 283.4,
+ "lo": 282.2,
+ "hi": 284.0,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 342.6,
+ "lo": 341.9,
+ "hi": 342.9,
+ "peak_mib": 4.1
+ },
+ "system": {
+ "median": 130.5,
+ "lo": 130.2,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 298.6,
+ "lo": 293.0,
+ "hi": 301.5,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 251.8,
+ "lo": 251.6,
+ "hi": 251.8,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 283.7,
+ "lo": 282.0,
+ "hi": 284.4,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 342.7,
+ "lo": 341.9,
+ "hi": 343.1,
+ "peak_mib": 4.1
+ },
+ "system": {
+ "median": 130.0,
+ "lo": 125.8,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 64 B",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 283.8,
+ "lo": 276.7,
+ "hi": 298.6,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 249.5,
+ "lo": 248.9,
+ "hi": 249.5,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 257.0,
+ "lo": 241.0,
+ "hi": 257.5,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 335.4,
+ "lo": 334.8,
+ "hi": 335.9,
+ "peak_mib": 4.0
+ },
+ "system": {
+ "median": 130.6,
+ "lo": 128.6,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 289.3,
+ "lo": 278.9,
+ "hi": 298.5,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 249.6,
+ "lo": 249.5,
+ "hi": 249.7,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 241.1,
+ "lo": 240.8,
+ "hi": 241.3,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 335.8,
+ "lo": 335.2,
+ "hi": 336.0,
+ "peak_mib": 4.0
+ },
+ "system": {
+ "median": 130.6,
+ "lo": 122.2,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 256 B",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 293.2,
+ "lo": 287.7,
+ "hi": 300.3,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 241.2,
+ "lo": 240.6,
+ "hi": 241.4,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 211.6,
+ "lo": 210.8,
+ "hi": 217.6,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 303.1,
+ "lo": 302.9,
+ "hi": 303.1,
+ "peak_mib": 3.9
+ },
+ "system": {
+ "median": 130.6,
+ "lo": 130.5,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 284.4,
+ "lo": 281.1,
+ "hi": 290.7,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 241.4,
+ "lo": 241.3,
+ "hi": 241.5,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 211.0,
+ "lo": 210.6,
+ "hi": 211.7,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 303.2,
+ "lo": 303.1,
+ "hi": 303.2,
+ "peak_mib": 3.9
+ },
+ "system": {
+ "median": 130.6,
+ "lo": 128.4,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 1 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 292.8,
+ "lo": 280.7,
+ "hi": 301.1,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 216.1,
+ "lo": 214.8,
+ "hi": 216.3,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 140.5,
+ "lo": 135.1,
+ "hi": 142.3,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 279.2,
+ "lo": 279.1,
+ "hi": 294.4,
+ "peak_mib": 3.9
+ },
+ "system": {
+ "median": 130.6,
+ "lo": 130.2,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 291.6,
+ "lo": 278.2,
+ "hi": 299.7,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 215.1,
+ "lo": 214.4,
+ "hi": 215.5,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 140.6,
+ "lo": 135.1,
+ "hi": 142.4,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 279.2,
+ "lo": 279.0,
+ "hi": 279.3,
+ "peak_mib": 3.9
+ },
+ "system": {
+ "median": 130.0,
+ "lo": 126.3,
+ "hi": 130.6,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 4 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 289.9,
+ "lo": 275.1,
+ "hi": 298.6,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 153.1,
+ "lo": 152.4,
+ "hi": 153.4,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 60.32,
+ "lo": 54.74,
+ "hi": 60.38,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 190.8,
+ "lo": 182.7,
+ "hi": 196.4,
+ "peak_mib": 3.9
+ },
+ "system": {
+ "median": 55.69,
+ "lo": 55.67,
+ "hi": 55.69,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 290.0,
+ "lo": 269.6,
+ "hi": 297.1,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 153.7,
+ "lo": 152.6,
+ "hi": 154.7,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 60.32,
+ "lo": 54.97,
+ "hi": 60.36,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 190.8,
+ "lo": 182.6,
+ "hi": 196.5,
+ "peak_mib": 3.9
+ },
+ "system": {
+ "median": 55.7,
+ "lo": 55.69,
+ "hi": 55.7,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 16 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 185.7,
+ "lo": 178.8,
+ "hi": 192.7,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 54.28,
+ "lo": 53.96,
+ "hi": 54.36,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 55.12,
+ "lo": 54.62,
+ "hi": 55.46,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 186.1,
+ "lo": 181.9,
+ "hi": 192.5,
+ "peak_mib": 3.85
+ },
+ "system": {
+ "median": 54.86,
+ "lo": 54.8,
+ "hi": 54.88,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 185.0,
+ "lo": 179.3,
+ "hi": 186.8,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 54.3,
+ "lo": 54.01,
+ "hi": 54.47,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 55.28,
+ "lo": 54.8,
+ "hi": 55.5,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 186.8,
+ "lo": 182.6,
+ "hi": 192.6,
+ "peak_mib": 3.85
+ },
+ "system": {
+ "median": 54.89,
+ "lo": 54.86,
+ "hi": 54.9,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 64 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 206.2,
+ "lo": 204.3,
+ "hi": 207.5,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 4.058,
+ "lo": 4.037,
+ "hi": 4.074,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 55.26,
+ "lo": 52.73,
+ "hi": 55.46,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 188.4,
+ "lo": 182.7,
+ "hi": 194.0,
+ "peak_mib": 3.85
+ },
+ "system": {
+ "median": 54.07,
+ "lo": 53.88,
+ "hi": 54.09,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 203.9,
+ "lo": 198.3,
+ "hi": 205.7,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 4.037,
+ "lo": 4.002,
+ "hi": 4.065,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 55.28,
+ "lo": 52.79,
+ "hi": 55.56,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 189.6,
+ "lo": 182.8,
+ "hi": 195.0,
+ "peak_mib": 3.85
+ },
+ "system": {
+ "median": 54.1,
+ "lo": 54.08,
+ "hi": 54.11,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 256 KiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 134.0,
+ "lo": 131.2,
+ "hi": 137.0,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 4.072,
+ "lo": 4.024,
+ "hi": 4.085,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 55.2,
+ "lo": 53.87,
+ "hi": 55.29,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 20.27,
+ "lo": 20.22,
+ "hi": 20.35,
+ "peak_mib": 3.95
+ },
+ "system": {
+ "median": 57.26,
+ "lo": 57.23,
+ "hi": 57.3,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 130.5,
+ "lo": 130.3,
+ "hi": 131.1,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 4.076,
+ "lo": 4.033,
+ "hi": 4.096,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 55.27,
+ "lo": 53.86,
+ "hi": 55.44,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 20.27,
+ "lo": 20.22,
+ "hi": 20.38,
+ "peak_mib": 3.95
+ },
+ "system": {
+ "median": 57.37,
+ "lo": 57.34,
+ "hi": 57.38,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "pair",
+ "name": "pair 1 MiB",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 132.9,
+ "lo": 130.3,
+ "hi": 134.9,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 4.051,
+ "lo": 4.022,
+ "hi": 4.088,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 4.463,
+ "lo": 4.436,
+ "hi": 4.487,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 9.288,
+ "lo": 9.192,
+ "hi": 9.31,
+ "peak_mib": 3.85
+ },
+ "system": {
+ "median": 56.71,
+ "lo": 56.39,
+ "hi": 56.86,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 130.7,
+ "lo": 130.1,
+ "hi": 134.8,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 4.058,
+ "lo": 4.008,
+ "hi": 4.094,
+ "peak_mib": 2.8
+ },
+ "mimalloc": {
+ "median": 4.482,
+ "lo": 4.461,
+ "hi": 4.492,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 9.293,
+ "lo": 9.258,
+ "hi": 9.317,
+ "peak_mib": 3.85
+ },
+ "system": {
+ "median": 57.33,
+ "lo": 57.08,
+ "hi": 57.39,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "bulk",
+ "name": "bulk 32 B in order",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 158.8,
+ "lo": 157.8,
+ "hi": 159.2,
+ "peak_mib": 50.7
+ },
+ "jemalloc": {
+ "median": 41.84,
+ "lo": 41.49,
+ "hi": 42.39,
+ "peak_mib": 49.65
+ },
+ "mimalloc": {
+ "median": 165.4,
+ "lo": 140.5,
+ "hi": 172.4,
+ "peak_mib": 52.3
+ },
+ "snmalloc": {
+ "median": 67.73,
+ "lo": 67.03,
+ "hi": 68.83,
+ "peak_mib": 57.3
+ },
+ "system": {
+ "median": 25.9,
+ "lo": 25.83,
+ "hi": 25.97,
+ "peak_mib": 63.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 172.0,
+ "lo": 171.8,
+ "hi": 172.5,
+ "peak_mib": 50.7
+ },
+ "jemalloc": {
+ "median": 52.66,
+ "lo": 52.35,
+ "hi": 52.97,
+ "peak_mib": 49.65
+ },
+ "mimalloc": {
+ "median": 190.7,
+ "lo": 182.8,
+ "hi": 191.1,
+ "peak_mib": 52.3
+ },
+ "snmalloc": {
+ "median": 125.1,
+ "lo": 114.2,
+ "hi": 126.5,
+ "peak_mib": 57.3
+ },
+ "system": {
+ "median": 22.22,
+ "lo": 22.13,
+ "hi": 22.28,
+ "peak_mib": 63.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "bulk",
+ "name": "bulk 32 B shuffled",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 99.43,
+ "lo": 98.75,
+ "hi": 99.76,
+ "peak_mib": 50.7
+ },
+ "jemalloc": {
+ "median": 37.01,
+ "lo": 36.82,
+ "hi": 37.43,
+ "peak_mib": 49.7
+ },
+ "mimalloc": {
+ "median": 80.64,
+ "lo": 77.17,
+ "hi": 82.68,
+ "peak_mib": 52.3
+ },
+ "snmalloc": {
+ "median": 43.67,
+ "lo": 43.41,
+ "hi": 43.85,
+ "peak_mib": 57.1
+ },
+ "system": {
+ "median": 9.967,
+ "lo": 9.815,
+ "hi": 10.05,
+ "peak_mib": 63.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 105.1,
+ "lo": 104.4,
+ "hi": 105.7,
+ "peak_mib": 50.7
+ },
+ "jemalloc": {
+ "median": 44.25,
+ "lo": 39.28,
+ "hi": 44.42,
+ "peak_mib": 49.7
+ },
+ "mimalloc": {
+ "median": 87.24,
+ "lo": 86.46,
+ "hi": 88.95,
+ "peak_mib": 52.3
+ },
+ "snmalloc": {
+ "median": 62.68,
+ "lo": 62.38,
+ "hi": 63.36,
+ "peak_mib": 57.1
+ },
+ "system": {
+ "median": 9.071,
+ "lo": 8.983,
+ "hi": 9.134,
+ "peak_mib": 63.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "bulk",
+ "name": "bulk 512 B shuffled",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 41.43,
+ "lo": 40.82,
+ "hi": 41.89,
+ "peak_mib": 268.8
+ },
+ "jemalloc": {
+ "median": 6.381,
+ "lo": 6.34,
+ "hi": 6.454,
+ "peak_mib": 275.8
+ },
+ "mimalloc": {
+ "median": 32.11,
+ "lo": 31.64,
+ "hi": 32.73,
+ "peak_mib": 272.3
+ },
+ "snmalloc": {
+ "median": 7.621,
+ "lo": 7.441,
+ "hi": 7.669,
+ "peak_mib": 274.1
+ },
+ "system": {
+ "median": 4.824,
+ "lo": 4.783,
+ "hi": 4.889,
+ "peak_mib": 274.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 59.01,
+ "lo": 57.92,
+ "hi": 59.69,
+ "peak_mib": 268.8
+ },
+ "jemalloc": {
+ "median": 11.31,
+ "lo": 9.077,
+ "hi": 11.43,
+ "peak_mib": 275.8
+ },
+ "mimalloc": {
+ "median": 42.36,
+ "lo": 41.74,
+ "hi": 42.57,
+ "peak_mib": 272.3
+ },
+ "snmalloc": {
+ "median": 16.16,
+ "lo": 16.13,
+ "hi": 16.3,
+ "peak_mib": 274.1
+ },
+ "system": {
+ "median": 7.097,
+ "lo": 6.991,
+ "hi": 7.303,
+ "peak_mib": 274.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn small",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 119.6,
+ "lo": 118.3,
+ "hi": 120.3,
+ "peak_mib": 2.75
+ },
+ "jemalloc": {
+ "median": 108.3,
+ "lo": 108.2,
+ "hi": 108.9,
+ "peak_mib": 2.9
+ },
+ "mimalloc": {
+ "median": 69.91,
+ "lo": 69.47,
+ "hi": 70.08,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 125.1,
+ "lo": 124.4,
+ "hi": 126.2,
+ "peak_mib": 4.25
+ },
+ "system": {
+ "median": 61.1,
+ "lo": 60.36,
+ "hi": 61.63,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 119.4,
+ "lo": 117.9,
+ "hi": 120.8,
+ "peak_mib": 2.75
+ },
+ "jemalloc": {
+ "median": 108.5,
+ "lo": 108.3,
+ "hi": 109.0,
+ "peak_mib": 2.9
+ },
+ "mimalloc": {
+ "median": 69.72,
+ "lo": 69.4,
+ "hi": 70.0,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 125.1,
+ "lo": 124.3,
+ "hi": 126.5,
+ "peak_mib": 4.25
+ },
+ "system": {
+ "median": 61.42,
+ "lo": 61.2,
+ "hi": 61.75,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn medium",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 115.1,
+ "lo": 111.3,
+ "hi": 116.1,
+ "peak_mib": 7.55
+ },
+ "jemalloc": {
+ "median": 81.12,
+ "lo": 76.84,
+ "hi": 81.62,
+ "peak_mib": 5.9
+ },
+ "mimalloc": {
+ "median": 41.56,
+ "lo": 41.38,
+ "hi": 41.68,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 80.34,
+ "lo": 79.29,
+ "hi": 80.72,
+ "peak_mib": 7.6
+ },
+ "system": {
+ "median": 36.11,
+ "lo": 36.03,
+ "hi": 36.23,
+ "peak_mib": 4.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 116.0,
+ "lo": 112.2,
+ "hi": 117.4,
+ "peak_mib": 7.55
+ },
+ "jemalloc": {
+ "median": 81.95,
+ "lo": 77.45,
+ "hi": 82.67,
+ "peak_mib": 5.9
+ },
+ "mimalloc": {
+ "median": 41.59,
+ "lo": 41.49,
+ "hi": 41.75,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 80.77,
+ "lo": 78.97,
+ "hi": 81.5,
+ "peak_mib": 7.6
+ },
+ "system": {
+ "median": 36.27,
+ "lo": 36.19,
+ "hi": 36.34,
+ "peak_mib": 4.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 117.1,
+ "lo": 115.7,
+ "hi": 117.4,
+ "peak_mib": 5.5
+ },
+ "jemalloc": {
+ "median": 85.88,
+ "lo": 85.77,
+ "hi": 86.2,
+ "peak_mib": 5.4
+ },
+ "mimalloc": {
+ "median": 57.92,
+ "lo": 57.75,
+ "hi": 58.18,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 86.9,
+ "lo": 86.42,
+ "hi": 87.16,
+ "peak_mib": 6.8
+ },
+ "system": {
+ "median": 38.52,
+ "lo": 38.48,
+ "hi": 38.62,
+ "peak_mib": 4.6
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 118.0,
+ "lo": 116.8,
+ "hi": 118.4,
+ "peak_mib": 5.5
+ },
+ "jemalloc": {
+ "median": 86.82,
+ "lo": 86.63,
+ "hi": 86.88,
+ "peak_mib": 5.4
+ },
+ "mimalloc": {
+ "median": 58.15,
+ "lo": 57.97,
+ "hi": 58.39,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 87.87,
+ "lo": 87.47,
+ "hi": 88.1,
+ "peak_mib": 6.8
+ },
+ "system": {
+ "median": 38.68,
+ "lo": 38.64,
+ "hi": 38.74,
+ "peak_mib": 4.6
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn skewed",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 136.2,
+ "lo": 135.7,
+ "hi": 136.7,
+ "peak_mib": 3.9
+ },
+ "jemalloc": {
+ "median": 118.5,
+ "lo": 117.4,
+ "hi": 119.1,
+ "peak_mib": 4.9
+ },
+ "mimalloc": {
+ "median": 125.0,
+ "lo": 124.6,
+ "hi": 125.4,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 119.6,
+ "lo": 119.0,
+ "hi": 120.2,
+ "peak_mib": 5.5
+ },
+ "system": {
+ "median": 50.69,
+ "lo": 50.59,
+ "hi": 50.78,
+ "peak_mib": 3.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 137.8,
+ "lo": 137.4,
+ "hi": 138.2,
+ "peak_mib": 3.9
+ },
+ "jemalloc": {
+ "median": 119.8,
+ "lo": 119.1,
+ "hi": 120.2,
+ "peak_mib": 4.9
+ },
+ "mimalloc": {
+ "median": 126.2,
+ "lo": 125.5,
+ "hi": 126.5,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 120.8,
+ "lo": 118.5,
+ "hi": 121.6,
+ "peak_mib": 5.5
+ },
+ "system": {
+ "median": 51.63,
+ "lo": 51.36,
+ "hi": 51.72,
+ "peak_mib": 3.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed 4 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 457.8,
+ "lo": 453.2,
+ "hi": 465.3,
+ "peak_mib": 19.9
+ },
+ "jemalloc": {
+ "median": 338.1,
+ "lo": 335.4,
+ "hi": 339.1,
+ "peak_mib": 13.6
+ },
+ "mimalloc": {
+ "median": 128.9,
+ "lo": 127.5,
+ "hi": 132.3,
+ "peak_mib": 26.3
+ },
+ "snmalloc": {
+ "median": 337.4,
+ "lo": 332.3,
+ "hi": 339.4,
+ "peak_mib": 15.1
+ },
+ "system": {
+ "median": 147.4,
+ "lo": 147.1,
+ "hi": 147.8,
+ "peak_mib": 12.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 466.1,
+ "lo": 458.7,
+ "hi": 468.1,
+ "peak_mib": 19.9
+ },
+ "jemalloc": {
+ "median": 340.6,
+ "lo": 334.6,
+ "hi": 341.3,
+ "peak_mib": 13.6
+ },
+ "mimalloc": {
+ "median": 126.0,
+ "lo": 124.9,
+ "hi": 127.4,
+ "peak_mib": 26.3
+ },
+ "snmalloc": {
+ "median": 342.8,
+ "lo": 340.5,
+ "hi": 346.3,
+ "peak_mib": 15.1
+ },
+ "system": {
+ "median": 149.4,
+ "lo": 149.2,
+ "hi": 149.7,
+ "peak_mib": 12.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 913.7,
+ "lo": 908.6,
+ "hi": 918.8,
+ "peak_mib": 35.4
+ },
+ "jemalloc": {
+ "median": 671.4,
+ "lo": 662.6,
+ "hi": 673.0,
+ "peak_mib": 24.6
+ },
+ "mimalloc": {
+ "median": 248.2,
+ "lo": 246.0,
+ "hi": 256.7,
+ "peak_mib": 70.3
+ },
+ "snmalloc": {
+ "median": 656.0,
+ "lo": 647.0,
+ "hi": 667.0,
+ "peak_mib": 29.85
+ },
+ "system": {
+ "median": 290.8,
+ "lo": 289.1,
+ "hi": 291.4,
+ "peak_mib": 22.15
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 937.0,
+ "lo": 930.8,
+ "hi": 942.6,
+ "peak_mib": 35.4
+ },
+ "jemalloc": {
+ "median": 676.3,
+ "lo": 672.5,
+ "hi": 678.8,
+ "peak_mib": 24.6
+ },
+ "mimalloc": {
+ "median": 245.2,
+ "lo": 243.5,
+ "hi": 247.9,
+ "peak_mib": 70.3
+ },
+ "snmalloc": {
+ "median": 662.2,
+ "lo": 654.4,
+ "hi": 673.8,
+ "peak_mib": 29.85
+ },
+ "system": {
+ "median": 299.2,
+ "lo": 298.6,
+ "hi": 299.6,
+ "peak_mib": 22.15
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed 16 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1554.0,
+ "lo": 1308.0,
+ "hi": 1770.0,
+ "peak_mib": 63.8
+ },
+ "jemalloc": {
+ "median": 1316.0,
+ "lo": 1198.0,
+ "hi": 1341.0,
+ "peak_mib": 46.4
+ },
+ "mimalloc": {
+ "median": 478.4,
+ "lo": 476.4,
+ "hi": 480.7,
+ "peak_mib": 119.4
+ },
+ "snmalloc": {
+ "median": 1251.0,
+ "lo": 1156.0,
+ "hi": 1294.0,
+ "peak_mib": 48.8
+ },
+ "system": {
+ "median": 558.2,
+ "lo": 545.3,
+ "hi": 560.9,
+ "peak_mib": 42.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1713.0,
+ "lo": 1442.0,
+ "hi": 1852.0,
+ "peak_mib": 63.8
+ },
+ "jemalloc": {
+ "median": 1333.0,
+ "lo": 1244.0,
+ "hi": 1345.0,
+ "peak_mib": 46.4
+ },
+ "mimalloc": {
+ "median": 466.4,
+ "lo": 464.2,
+ "hi": 477.5,
+ "peak_mib": 119.4
+ },
+ "snmalloc": {
+ "median": 1304.0,
+ "lo": 1234.0,
+ "hi": 1320.0,
+ "peak_mib": 48.8
+ },
+ "system": {
+ "median": 593.0,
+ "lo": 561.9,
+ "hi": 596.6,
+ "peak_mib": 42.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn skewed 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1061.0,
+ "lo": 1054.0,
+ "hi": 1067.0,
+ "peak_mib": 17.7
+ },
+ "jemalloc": {
+ "median": 928.9,
+ "lo": 921.7,
+ "hi": 932.9,
+ "peak_mib": 20.15
+ },
+ "mimalloc": {
+ "median": 819.6,
+ "lo": 781.5,
+ "hi": 843.4,
+ "peak_mib": 112.4
+ },
+ "snmalloc": {
+ "median": 945.6,
+ "lo": 939.4,
+ "hi": 951.1,
+ "peak_mib": 22.25
+ },
+ "system": {
+ "median": 390.5,
+ "lo": 388.8,
+ "hi": 391.3,
+ "peak_mib": 13.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1078.0,
+ "lo": 1071.0,
+ "hi": 1080.0,
+ "peak_mib": 17.7
+ },
+ "jemalloc": {
+ "median": 936.2,
+ "lo": 931.9,
+ "hi": 937.8,
+ "peak_mib": 20.15
+ },
+ "mimalloc": {
+ "median": 860.1,
+ "lo": 799.8,
+ "hi": 892.9,
+ "peak_mib": 112.4
+ },
+ "snmalloc": {
+ "median": 946.0,
+ "lo": 925.6,
+ "hi": 955.4,
+ "peak_mib": 22.25
+ },
+ "system": {
+ "median": 394.2,
+ "lo": 393.3,
+ "hi": 394.9,
+ "peak_mib": 13.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn mixed oversubscribed",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 3182.0,
+ "lo": 3163.0,
+ "hi": 3291.0,
+ "peak_mib": 364.4
+ },
+ "jemalloc": {
+ "median": 2312.0,
+ "lo": 2169.0,
+ "hi": 2426.0,
+ "peak_mib": 311.5
+ },
+ "mimalloc": {
+ "median": 1416.0,
+ "lo": 1353.0,
+ "hi": 1449.0,
+ "peak_mib": 787.1
+ },
+ "snmalloc": {
+ "median": 2406.0,
+ "lo": 2249.0,
+ "hi": 2442.0,
+ "peak_mib": 376.6
+ },
+ "system": {
+ "median": 992.4,
+ "lo": 972.7,
+ "hi": 1018.0,
+ "peak_mib": 328.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 3185.0,
+ "lo": 2914.0,
+ "hi": 3398.0,
+ "peak_mib": 364.4
+ },
+ "jemalloc": {
+ "median": 2338.0,
+ "lo": 2250.0,
+ "hi": 2397.0,
+ "peak_mib": 311.5
+ },
+ "mimalloc": {
+ "median": 1216.0,
+ "lo": 1183.0,
+ "hi": 1236.0,
+ "peak_mib": 787.1
+ },
+ "snmalloc": {
+ "median": 2423.0,
+ "lo": 2338.0,
+ "hi": 2486.0,
+ "peak_mib": 376.6
+ },
+ "system": {
+ "median": 1094.0,
+ "lo": 1072.0,
+ "hi": 1104.0,
+ "peak_mib": 328.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn large set",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 20.52,
+ "lo": 20.24,
+ "hi": 20.66,
+ "peak_mib": 2112.0
+ },
+ "jemalloc": {
+ "median": 6.569,
+ "lo": 6.53,
+ "hi": 6.588,
+ "peak_mib": 2514.0
+ },
+ "mimalloc": {
+ "median": 6.088,
+ "lo": 6.053,
+ "hi": 6.103,
+ "peak_mib": 2587.0
+ },
+ "snmalloc": {
+ "median": 6.291,
+ "lo": 6.235,
+ "hi": 6.368,
+ "peak_mib": 2180.0
+ },
+ "system": {
+ "median": 3.862,
+ "lo": 3.811,
+ "hi": 3.883,
+ "peak_mib": 2129.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 24.7,
+ "lo": 24.36,
+ "hi": 24.83,
+ "peak_mib": 2112.0
+ },
+ "jemalloc": {
+ "median": 10.03,
+ "lo": 9.904,
+ "hi": 10.25,
+ "peak_mib": 2514.0
+ },
+ "mimalloc": {
+ "median": 6.44,
+ "lo": 6.415,
+ "hi": 6.461,
+ "peak_mib": 2587.0
+ },
+ "snmalloc": {
+ "median": 10.84,
+ "lo": 10.79,
+ "hi": 10.93,
+ "peak_mib": 2180.0
+ },
+ "system": {
+ "median": 4.995,
+ "lo": 4.982,
+ "hi": 5.025,
+ "peak_mib": 2129.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "churn",
+ "name": "churn with work",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.177,
+ "lo": 2.094,
+ "hi": 2.201,
+ "peak_mib": 5.5
+ },
+ "jemalloc": {
+ "median": 1.956,
+ "lo": 1.954,
+ "hi": 1.957,
+ "peak_mib": 5.1
+ },
+ "mimalloc": {
+ "median": 2.055,
+ "lo": 2.026,
+ "hi": 2.122,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 2.035,
+ "lo": 1.971,
+ "hi": 2.109,
+ "peak_mib": 6.8
+ },
+ "system": {
+ "median": 1.928,
+ "lo": 1.89,
+ "hi": 2.044,
+ "peak_mib": 4.35
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.111,
+ "lo": 2.096,
+ "hi": 2.144,
+ "peak_mib": 5.5
+ },
+ "jemalloc": {
+ "median": 1.951,
+ "lo": 1.95,
+ "hi": 1.985,
+ "peak_mib": 5.1
+ },
+ "mimalloc": {
+ "median": 2.158,
+ "lo": 2.056,
+ "hi": 2.211,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 2.084,
+ "lo": 1.945,
+ "hi": 2.161,
+ "peak_mib": 6.8
+ },
+ "system": {
+ "median": 2.013,
+ "lo": 1.882,
+ "hi": 2.145,
+ "peak_mib": 4.35
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "larson 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 802.8,
+ "lo": 784.4,
+ "hi": 809.5,
+ "peak_mib": 12.25
+ },
+ "jemalloc": {
+ "median": 622.8,
+ "lo": 616.8,
+ "hi": 624.2,
+ "peak_mib": 9.9
+ },
+ "mimalloc": {
+ "median": 418.6,
+ "lo": 411.9,
+ "hi": 421.8,
+ "peak_mib": 20.6
+ },
+ "snmalloc": {
+ "median": 545.1,
+ "lo": 542.8,
+ "hi": 547.2,
+ "peak_mib": 17.1
+ },
+ "system": {
+ "median": 142.6,
+ "lo": 141.9,
+ "hi": 143.0,
+ "peak_mib": 7.55
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 817.1,
+ "lo": 791.4,
+ "hi": 821.6,
+ "peak_mib": 12.25
+ },
+ "jemalloc": {
+ "median": 635.4,
+ "lo": 630.3,
+ "hi": 639.0,
+ "peak_mib": 9.9
+ },
+ "mimalloc": {
+ "median": 405.6,
+ "lo": 399.0,
+ "hi": 410.8,
+ "peak_mib": 20.6
+ },
+ "snmalloc": {
+ "median": 555.9,
+ "lo": 553.5,
+ "hi": 558.5,
+ "peak_mib": 17.1
+ },
+ "system": {
+ "median": 145.5,
+ "lo": 144.8,
+ "hi": 145.8,
+ "peak_mib": 7.55
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "ring 4 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 76.44,
+ "lo": 75.91,
+ "hi": 76.78,
+ "peak_mib": 5.4
+ },
+ "jemalloc": {
+ "median": 119.0,
+ "lo": 118.7,
+ "hi": 119.4,
+ "peak_mib": 5.8
+ },
+ "mimalloc": {
+ "median": 23.83,
+ "lo": 23.68,
+ "hi": 23.95,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 34.48,
+ "lo": 34.23,
+ "hi": 34.76,
+ "peak_mib": 6.1
+ },
+ "system": {
+ "median": 9.635,
+ "lo": 9.603,
+ "hi": 9.676,
+ "peak_mib": 3.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 76.36,
+ "lo": 76.06,
+ "hi": 76.63,
+ "peak_mib": 5.4
+ },
+ "jemalloc": {
+ "median": 120.0,
+ "lo": 118.9,
+ "hi": 120.4,
+ "peak_mib": 5.8
+ },
+ "mimalloc": {
+ "median": 24.04,
+ "lo": 23.91,
+ "hi": 24.2,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 34.21,
+ "lo": 34.05,
+ "hi": 34.55,
+ "peak_mib": 6.1
+ },
+ "system": {
+ "median": 9.683,
+ "lo": 9.598,
+ "hi": 9.752,
+ "peak_mib": 3.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "ring 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 151.1,
+ "lo": 150.6,
+ "hi": 151.9,
+ "peak_mib": 9.05
+ },
+ "jemalloc": {
+ "median": 227.9,
+ "lo": 225.9,
+ "hi": 229.1,
+ "peak_mib": 10.1
+ },
+ "mimalloc": {
+ "median": 47.22,
+ "lo": 46.95,
+ "hi": 47.56,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 68.7,
+ "lo": 68.25,
+ "hi": 69.7,
+ "peak_mib": 8.2
+ },
+ "system": {
+ "median": 17.21,
+ "lo": 17.15,
+ "hi": 17.34,
+ "peak_mib": 4.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 152.0,
+ "lo": 151.6,
+ "hi": 152.6,
+ "peak_mib": 9.05
+ },
+ "jemalloc": {
+ "median": 234.0,
+ "lo": 232.6,
+ "hi": 234.9,
+ "peak_mib": 10.1
+ },
+ "mimalloc": {
+ "median": 47.63,
+ "lo": 47.27,
+ "hi": 47.99,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 68.52,
+ "lo": 68.04,
+ "hi": 68.75,
+ "peak_mib": 8.2
+ },
+ "system": {
+ "median": 17.43,
+ "lo": 17.32,
+ "hi": 17.62,
+ "peak_mib": 4.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "channel 1 pair",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 8.375,
+ "lo": 7.953,
+ "hi": 8.606,
+ "peak_mib": 2.9
+ },
+ "jemalloc": {
+ "median": 8.89,
+ "lo": 8.496,
+ "hi": 9.467,
+ "peak_mib": 3.6
+ },
+ "mimalloc": {
+ "median": 5.467,
+ "lo": 5.262,
+ "hi": 5.742,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 5.007,
+ "lo": 4.854,
+ "hi": 5.073,
+ "peak_mib": 4.3
+ },
+ "system": {
+ "median": 1.166,
+ "lo": 1.141,
+ "hi": 1.203,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 8.538,
+ "lo": 8.289,
+ "hi": 8.856,
+ "peak_mib": 2.9
+ },
+ "jemalloc": {
+ "median": 9.172,
+ "lo": 8.91,
+ "hi": 9.588,
+ "peak_mib": 3.6
+ },
+ "mimalloc": {
+ "median": 5.418,
+ "lo": 5.331,
+ "hi": 5.587,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 4.937,
+ "lo": 4.784,
+ "hi": 5.11,
+ "peak_mib": 4.3
+ },
+ "system": {
+ "median": 1.193,
+ "lo": 1.168,
+ "hi": 1.215,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "channel 4 pairs",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 28.14,
+ "lo": 27.03,
+ "hi": 29.5,
+ "peak_mib": 4.4
+ },
+ "jemalloc": {
+ "median": 32.48,
+ "lo": 31.47,
+ "hi": 33.15,
+ "peak_mib": 6.7
+ },
+ "mimalloc": {
+ "median": 20.84,
+ "lo": 20.43,
+ "hi": 21.08,
+ "peak_mib": 11.3
+ },
+ "snmalloc": {
+ "median": 19.04,
+ "lo": 18.88,
+ "hi": 19.27,
+ "peak_mib": 5.1
+ },
+ "system": {
+ "median": 4.555,
+ "lo": 4.518,
+ "hi": 4.59,
+ "peak_mib": 2.8
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 28.07,
+ "lo": 27.33,
+ "hi": 29.17,
+ "peak_mib": 4.4
+ },
+ "jemalloc": {
+ "median": 33.41,
+ "lo": 31.39,
+ "hi": 33.65,
+ "peak_mib": 6.7
+ },
+ "mimalloc": {
+ "median": 20.32,
+ "lo": 20.04,
+ "hi": 20.66,
+ "peak_mib": 11.3
+ },
+ "snmalloc": {
+ "median": 18.97,
+ "lo": 18.51,
+ "hi": 19.18,
+ "peak_mib": 5.1
+ },
+ "system": {
+ "median": 4.585,
+ "lo": 4.559,
+ "hi": 4.627,
+ "peak_mib": 2.8
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "shared table 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 81.19,
+ "lo": 80.53,
+ "hi": 81.36,
+ "peak_mib": 44.05
+ },
+ "jemalloc": {
+ "median": 68.31,
+ "lo": 66.54,
+ "hi": 68.72,
+ "peak_mib": 29.1
+ },
+ "mimalloc": {
+ "median": 28.94,
+ "lo": 28.87,
+ "hi": 29.15,
+ "peak_mib": 32.3
+ },
+ "snmalloc": {
+ "median": 21.92,
+ "lo": 21.78,
+ "hi": 22.2,
+ "peak_mib": 40.2
+ },
+ "system": {
+ "median": 4.288,
+ "lo": 4.268,
+ "hi": 4.304,
+ "peak_mib": 27.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 82.01,
+ "lo": 81.67,
+ "hi": 82.44,
+ "peak_mib": 44.05
+ },
+ "jemalloc": {
+ "median": 69.0,
+ "lo": 68.09,
+ "hi": 69.35,
+ "peak_mib": 29.1
+ },
+ "mimalloc": {
+ "median": 29.17,
+ "lo": 29.04,
+ "hi": 29.36,
+ "peak_mib": 32.3
+ },
+ "snmalloc": {
+ "median": 22.07,
+ "lo": 21.98,
+ "hi": 22.18,
+ "peak_mib": 40.2
+ },
+ "system": {
+ "median": 4.312,
+ "lo": 4.299,
+ "hi": 4.32,
+ "peak_mib": 27.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "sharing",
+ "name": "thread lifecycle",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 76.65,
+ "lo": 75.35,
+ "hi": 77.18,
+ "peak_mib": 4.4
+ },
+ "jemalloc": {
+ "median": 61.33,
+ "lo": 61.05,
+ "hi": 62.28,
+ "peak_mib": 6.15
+ },
+ "mimalloc": {
+ "median": 68.19,
+ "lo": 67.26,
+ "hi": 70.1,
+ "peak_mib": 14.3
+ },
+ "snmalloc": {
+ "median": 68.36,
+ "lo": 67.8,
+ "hi": 68.63,
+ "peak_mib": 6.1
+ },
+ "system": {
+ "median": 70.31,
+ "lo": 69.29,
+ "hi": 71.64,
+ "peak_mib": 2.75
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 76.96,
+ "lo": 76.52,
+ "hi": 77.45,
+ "peak_mib": 4.4
+ },
+ "jemalloc": {
+ "median": 62.55,
+ "lo": 61.98,
+ "hi": 63.13,
+ "peak_mib": 6.15
+ },
+ "mimalloc": {
+ "median": 69.8,
+ "lo": 68.38,
+ "hi": 71.05,
+ "peak_mib": 14.3
+ },
+ "snmalloc": {
+ "median": 69.01,
+ "lo": 68.22,
+ "hi": 69.71,
+ "peak_mib": 6.1
+ },
+ "system": {
+ "median": 70.85,
+ "lo": 70.22,
+ "hi": 72.31,
+ "peak_mib": 2.75
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "false sharing",
+ "name": "cache scratch 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 59780.0,
+ "lo": 59640.0,
+ "hi": 59790.0,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 59690.0,
+ "lo": 59660.0,
+ "hi": 59710.0,
+ "peak_mib": 2.85
+ },
+ "mimalloc": {
+ "median": 59960.0,
+ "lo": 59940.0,
+ "hi": 59970.0,
+ "peak_mib": 7.3
+ },
+ "snmalloc": {
+ "median": 59960.0,
+ "lo": 59900.0,
+ "hi": 59970.0,
+ "peak_mib": 4.1
+ },
+ "system": {
+ "median": 42410.0,
+ "lo": 42280.0,
+ "hi": 42560.0,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 59790.0,
+ "lo": 59780.0,
+ "hi": 59800.0,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 59900.0,
+ "lo": 59890.0,
+ "hi": 59920.0,
+ "peak_mib": 2.85
+ },
+ "mimalloc": {
+ "median": 59990.0,
+ "lo": 59940.0,
+ "hi": 60010.0,
+ "peak_mib": 7.3
+ },
+ "snmalloc": {
+ "median": 59970.0,
+ "lo": 59940.0,
+ "hi": 59990.0,
+ "peak_mib": 4.1
+ },
+ "system": {
+ "median": 49250.0,
+ "lo": 45290.0,
+ "hi": 52180.0,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "false sharing",
+ "name": "cache thrash 8 threads",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 59790.0,
+ "lo": 59770.0,
+ "hi": 59800.0,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 59710.0,
+ "lo": 59690.0,
+ "hi": 59710.0,
+ "peak_mib": 2.9
+ },
+ "mimalloc": {
+ "median": 59970.0,
+ "lo": 59960.0,
+ "hi": 59980.0,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 59960.0,
+ "lo": 59940.0,
+ "hi": 59980.0,
+ "peak_mib": 4.05
+ },
+ "system": {
+ "median": 59760.0,
+ "lo": 59750.0,
+ "hi": 59770.0,
+ "peak_mib": 2.65
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 59800.0,
+ "lo": 59790.0,
+ "hi": 59810.0,
+ "peak_mib": 2.65
+ },
+ "jemalloc": {
+ "median": 59900.0,
+ "lo": 59890.0,
+ "hi": 59920.0,
+ "peak_mib": 2.9
+ },
+ "mimalloc": {
+ "median": 59990.0,
+ "lo": 59990.0,
+ "hi": 60010.0,
+ "peak_mib": 6.3
+ },
+ "snmalloc": {
+ "median": 59990.0,
+ "lo": 59960.0,
+ "hi": 60000.0,
+ "peak_mib": 4.05
+ },
+ "system": {
+ "median": 59770.0,
+ "lo": 59750.0,
+ "hi": 59780.0,
+ "peak_mib": 2.65
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "hash map",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 9.305,
+ "lo": 9.238,
+ "hi": 9.352,
+ "peak_mib": 200.0
+ },
+ "jemalloc": {
+ "median": 6.381,
+ "lo": 6.352,
+ "hi": 6.412,
+ "peak_mib": 170.6
+ },
+ "mimalloc": {
+ "median": 7.489,
+ "lo": 7.421,
+ "hi": 7.584,
+ "peak_mib": 199.3
+ },
+ "snmalloc": {
+ "median": 6.048,
+ "lo": 6.032,
+ "hi": 6.196,
+ "peak_mib": 212.2
+ },
+ "system": {
+ "median": 4.466,
+ "lo": 4.445,
+ "hi": 4.491,
+ "peak_mib": 192.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 9.482,
+ "lo": 9.431,
+ "hi": 9.556,
+ "peak_mib": 200.0
+ },
+ "jemalloc": {
+ "median": 7.063,
+ "lo": 7.032,
+ "hi": 7.077,
+ "peak_mib": 170.6
+ },
+ "mimalloc": {
+ "median": 7.892,
+ "lo": 7.813,
+ "hi": 8.048,
+ "peak_mib": 199.3
+ },
+ "snmalloc": {
+ "median": 7.556,
+ "lo": 7.393,
+ "hi": 7.718,
+ "peak_mib": 212.2
+ },
+ "system": {
+ "median": 4.079,
+ "lo": 4.044,
+ "hi": 4.107,
+ "peak_mib": 192.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "btree map",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 5.3,
+ "lo": 5.232,
+ "hi": 5.309,
+ "peak_mib": 37.65
+ },
+ "jemalloc": {
+ "median": 4.447,
+ "lo": 4.428,
+ "hi": 4.476,
+ "peak_mib": 37.2
+ },
+ "mimalloc": {
+ "median": 4.386,
+ "lo": 4.287,
+ "hi": 4.473,
+ "peak_mib": 42.3
+ },
+ "snmalloc": {
+ "median": 4.139,
+ "lo": 4.112,
+ "hi": 4.196,
+ "peak_mib": 40.35
+ },
+ "system": {
+ "median": 3.617,
+ "lo": 3.567,
+ "hi": 3.631,
+ "peak_mib": 44.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 5.312,
+ "lo": 5.241,
+ "hi": 5.336,
+ "peak_mib": 37.65
+ },
+ "jemalloc": {
+ "median": 4.77,
+ "lo": 4.717,
+ "hi": 4.81,
+ "peak_mib": 37.2
+ },
+ "mimalloc": {
+ "median": 4.498,
+ "lo": 4.462,
+ "hi": 4.517,
+ "peak_mib": 42.3
+ },
+ "snmalloc": {
+ "median": 4.476,
+ "lo": 4.446,
+ "hi": 4.5,
+ "peak_mib": 40.35
+ },
+ "system": {
+ "median": 2.882,
+ "lo": 2.865,
+ "hi": 2.887,
+ "peak_mib": 44.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "strings",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 7.243,
+ "lo": 7.217,
+ "hi": 7.254,
+ "peak_mib": 16.4
+ },
+ "jemalloc": {
+ "median": 5.912,
+ "lo": 5.89,
+ "hi": 5.918,
+ "peak_mib": 16.8
+ },
+ "mimalloc": {
+ "median": 7.168,
+ "lo": 7.143,
+ "hi": 7.189,
+ "peak_mib": 20.3
+ },
+ "snmalloc": {
+ "median": 7.068,
+ "lo": 7.017,
+ "hi": 7.087,
+ "peak_mib": 18.85
+ },
+ "system": {
+ "median": 5.723,
+ "lo": 5.695,
+ "hi": 5.73,
+ "peak_mib": 16.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 7.248,
+ "lo": 7.224,
+ "hi": 7.268,
+ "peak_mib": 16.4
+ },
+ "jemalloc": {
+ "median": 6.011,
+ "lo": 6.002,
+ "hi": 6.027,
+ "peak_mib": 16.8
+ },
+ "mimalloc": {
+ "median": 7.185,
+ "lo": 7.152,
+ "hi": 7.195,
+ "peak_mib": 20.3
+ },
+ "snmalloc": {
+ "median": 7.214,
+ "lo": 7.187,
+ "hi": 7.237,
+ "peak_mib": 18.85
+ },
+ "system": {
+ "median": 6.039,
+ "lo": 6.024,
+ "hi": 6.053,
+ "peak_mib": 16.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "linked list",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 154.5,
+ "lo": 153.6,
+ "hi": 154.7,
+ "peak_mib": 27.6
+ },
+ "jemalloc": {
+ "median": 68.22,
+ "lo": 67.87,
+ "hi": 69.01,
+ "peak_mib": 34.2
+ },
+ "mimalloc": {
+ "median": 149.3,
+ "lo": 145.1,
+ "hi": 158.2,
+ "peak_mib": 36.3
+ },
+ "snmalloc": {
+ "median": 101.3,
+ "lo": 100.0,
+ "hi": 103.7,
+ "peak_mib": 49.9
+ },
+ "system": {
+ "median": 72.85,
+ "lo": 71.85,
+ "hi": 73.3,
+ "peak_mib": 32.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 161.9,
+ "lo": 160.1,
+ "hi": 162.3,
+ "peak_mib": 27.6
+ },
+ "jemalloc": {
+ "median": 78.16,
+ "lo": 77.38,
+ "hi": 78.89,
+ "peak_mib": 34.2
+ },
+ "mimalloc": {
+ "median": 164.7,
+ "lo": 164.5,
+ "hi": 165.0,
+ "peak_mib": 36.3
+ },
+ "snmalloc": {
+ "median": 129.8,
+ "lo": 128.0,
+ "hi": 131.5,
+ "peak_mib": 49.9
+ },
+ "system": {
+ "median": 85.48,
+ "lo": 84.2,
+ "hi": 86.35,
+ "peak_mib": 32.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "binary trees",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 92.81,
+ "lo": 90.21,
+ "hi": 93.46,
+ "peak_mib": 5.1
+ },
+ "jemalloc": {
+ "median": 56.07,
+ "lo": 55.74,
+ "hi": 56.38,
+ "peak_mib": 4.6
+ },
+ "mimalloc": {
+ "median": 95.04,
+ "lo": 92.11,
+ "hi": 97.03,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 85.58,
+ "lo": 85.16,
+ "hi": 86.27,
+ "peak_mib": 6.9
+ },
+ "system": {
+ "median": 57.13,
+ "lo": 56.55,
+ "hi": 57.66,
+ "peak_mib": 5.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 96.23,
+ "lo": 95.99,
+ "hi": 97.11,
+ "peak_mib": 5.1
+ },
+ "jemalloc": {
+ "median": 58.71,
+ "lo": 58.33,
+ "hi": 58.98,
+ "peak_mib": 4.6
+ },
+ "mimalloc": {
+ "median": 95.97,
+ "lo": 94.74,
+ "hi": 96.32,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 90.92,
+ "lo": 90.26,
+ "hi": 91.31,
+ "peak_mib": 6.9
+ },
+ "system": {
+ "median": 62.42,
+ "lo": 60.86,
+ "hi": 62.79,
+ "peak_mib": 5.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "tree rewrite",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 104.5,
+ "lo": 104.0,
+ "hi": 104.8,
+ "peak_mib": 5.3
+ },
+ "jemalloc": {
+ "median": 55.75,
+ "lo": 55.67,
+ "hi": 55.87,
+ "peak_mib": 4.65
+ },
+ "mimalloc": {
+ "median": 101.4,
+ "lo": 101.0,
+ "hi": 101.7,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 107.5,
+ "lo": 106.9,
+ "hi": 107.7,
+ "peak_mib": 6.1
+ },
+ "system": {
+ "median": 45.43,
+ "lo": 45.16,
+ "hi": 45.77,
+ "peak_mib": 5.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 104.8,
+ "lo": 104.3,
+ "hi": 105.0,
+ "peak_mib": 5.3
+ },
+ "jemalloc": {
+ "median": 55.86,
+ "lo": 55.8,
+ "hi": 56.04,
+ "peak_mib": 4.65
+ },
+ "mimalloc": {
+ "median": 101.1,
+ "lo": 100.7,
+ "hi": 101.3,
+ "peak_mib": 8.3
+ },
+ "snmalloc": {
+ "median": 107.2,
+ "lo": 106.9,
+ "hi": 107.4,
+ "peak_mib": 6.1
+ },
+ "system": {
+ "median": 37.55,
+ "lo": 37.18,
+ "hi": 37.63,
+ "peak_mib": 5.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "collections",
+ "name": "binary trees with work",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 51.39,
+ "lo": 51.01,
+ "hi": 51.76,
+ "peak_mib": 7.4
+ },
+ "jemalloc": {
+ "median": 35.92,
+ "lo": 33.74,
+ "hi": 38.18,
+ "peak_mib": 6.6
+ },
+ "mimalloc": {
+ "median": 47.64,
+ "lo": 47.3,
+ "hi": 48.3,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 41.23,
+ "lo": 40.3,
+ "hi": 42.19,
+ "peak_mib": 10.0
+ },
+ "system": {
+ "median": 44.42,
+ "lo": 44.16,
+ "hi": 44.65,
+ "peak_mib": 5.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 51.49,
+ "lo": 51.32,
+ "hi": 51.85,
+ "peak_mib": 7.4
+ },
+ "jemalloc": {
+ "median": 36.09,
+ "lo": 33.86,
+ "hi": 38.28,
+ "peak_mib": 6.6
+ },
+ "mimalloc": {
+ "median": 47.66,
+ "lo": 47.43,
+ "hi": 48.29,
+ "peak_mib": 10.3
+ },
+ "snmalloc": {
+ "median": 41.88,
+ "lo": 40.79,
+ "hi": 42.85,
+ "peak_mib": 10.0
+ },
+ "system": {
+ "median": 45.24,
+ "lo": 44.96,
+ "hi": 45.33,
+ "peak_mib": 5.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "vec growth",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1489.0,
+ "lo": 1483.0,
+ "hi": 1490.0,
+ "peak_mib": 12.25
+ },
+ "jemalloc": {
+ "median": 273.7,
+ "lo": 273.0,
+ "hi": 274.3,
+ "peak_mib": 17.4
+ },
+ "mimalloc": {
+ "median": 1310.0,
+ "lo": 1279.0,
+ "hi": 1314.0,
+ "peak_mib": 28.3
+ },
+ "snmalloc": {
+ "median": 793.4,
+ "lo": 784.1,
+ "hi": 809.4,
+ "peak_mib": 24.55
+ },
+ "system": {
+ "median": 1440.0,
+ "lo": 1433.0,
+ "hi": 1448.0,
+ "peak_mib": 9.6
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1557.0,
+ "lo": 1555.0,
+ "hi": 1558.0,
+ "peak_mib": 12.25
+ },
+ "jemalloc": {
+ "median": 280.5,
+ "lo": 280.0,
+ "hi": 280.7,
+ "peak_mib": 17.4
+ },
+ "mimalloc": {
+ "median": 1348.0,
+ "lo": 1348.0,
+ "hi": 1349.0,
+ "peak_mib": 28.3
+ },
+ "snmalloc": {
+ "median": 978.0,
+ "lo": 976.5,
+ "hi": 983.6,
+ "peak_mib": 24.55
+ },
+ "system": {
+ "median": 1820.0,
+ "lo": 1817.0,
+ "hi": 1822.0,
+ "peak_mib": 9.6
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "string growth",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1771.0,
+ "lo": 1769.0,
+ "hi": 1773.0,
+ "peak_mib": 10.4
+ },
+ "jemalloc": {
+ "median": 1763.0,
+ "lo": 1762.0,
+ "hi": 1764.0,
+ "peak_mib": 9.4
+ },
+ "mimalloc": {
+ "median": 1779.0,
+ "lo": 1759.0,
+ "hi": 1781.0,
+ "peak_mib": 20.3
+ },
+ "snmalloc": {
+ "median": 1630.0,
+ "lo": 1625.0,
+ "hi": 1632.0,
+ "peak_mib": 12.1
+ },
+ "system": {
+ "median": 1813.0,
+ "lo": 1808.0,
+ "hi": 1816.0,
+ "peak_mib": 5.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1794.0,
+ "lo": 1793.0,
+ "hi": 1794.0,
+ "peak_mib": 10.4
+ },
+ "jemalloc": {
+ "median": 1816.0,
+ "lo": 1815.0,
+ "hi": 1816.0,
+ "peak_mib": 9.4
+ },
+ "mimalloc": {
+ "median": 1791.0,
+ "lo": 1790.0,
+ "hi": 1791.0,
+ "peak_mib": 20.3
+ },
+ "snmalloc": {
+ "median": 1689.0,
+ "lo": 1688.0,
+ "hi": 1691.0,
+ "peak_mib": 12.1
+ },
+ "system": {
+ "median": 1876.0,
+ "lo": 1874.0,
+ "hi": 1877.0,
+ "peak_mib": 5.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "many vectors",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 275.1,
+ "lo": 273.2,
+ "hi": 277.7,
+ "peak_mib": 21.5
+ },
+ "jemalloc": {
+ "median": 246.1,
+ "lo": 245.4,
+ "hi": 246.8,
+ "peak_mib": 27.3
+ },
+ "mimalloc": {
+ "median": 276.1,
+ "lo": 271.3,
+ "hi": 279.1,
+ "peak_mib": 22.3
+ },
+ "snmalloc": {
+ "median": 275.5,
+ "lo": 274.2,
+ "hi": 276.4,
+ "peak_mib": 23.8
+ },
+ "system": {
+ "median": 326.0,
+ "lo": 324.9,
+ "hi": 327.8,
+ "peak_mib": 18.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 277.6,
+ "lo": 275.6,
+ "hi": 278.9,
+ "peak_mib": 21.5
+ },
+ "jemalloc": {
+ "median": 272.3,
+ "lo": 271.3,
+ "hi": 273.0,
+ "peak_mib": 27.3
+ },
+ "mimalloc": {
+ "median": 279.2,
+ "lo": 274.1,
+ "hi": 282.0,
+ "peak_mib": 22.3
+ },
+ "snmalloc": {
+ "median": 294.9,
+ "lo": 293.6,
+ "hi": 295.7,
+ "peak_mib": 23.8
+ },
+ "system": {
+ "median": 332.2,
+ "lo": 328.2,
+ "hi": 334.4,
+ "peak_mib": 18.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "resizing",
+ "name": "realloc random",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 10.32,
+ "lo": 10.26,
+ "hi": 10.37,
+ "peak_mib": 24.1
+ },
+ "jemalloc": {
+ "median": 5.298,
+ "lo": 5.24,
+ "hi": 5.337,
+ "peak_mib": 16.9
+ },
+ "mimalloc": {
+ "median": 8.389,
+ "lo": 8.315,
+ "hi": 8.47,
+ "peak_mib": 20.3
+ },
+ "snmalloc": {
+ "median": 7.452,
+ "lo": 7.425,
+ "hi": 7.474,
+ "peak_mib": 17.4
+ },
+ "system": {
+ "median": 5.387,
+ "lo": 5.364,
+ "hi": 5.398,
+ "peak_mib": 14.85
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 10.39,
+ "lo": 10.31,
+ "hi": 10.44,
+ "peak_mib": 24.1
+ },
+ "jemalloc": {
+ "median": 5.324,
+ "lo": 5.265,
+ "hi": 5.361,
+ "peak_mib": 16.9
+ },
+ "mimalloc": {
+ "median": 8.386,
+ "lo": 8.311,
+ "hi": 8.494,
+ "peak_mib": 20.3
+ },
+ "snmalloc": {
+ "median": 7.5,
+ "lo": 7.467,
+ "hi": 7.517,
+ "peak_mib": 17.4
+ },
+ "system": {
+ "median": 5.386,
+ "lo": 5.37,
+ "hi": 5.405,
+ "peak_mib": 14.85
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "large",
+ "name": "medium blocks",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.202,
+ "lo": 1.185,
+ "hi": 1.207,
+ "peak_mib": 63.2
+ },
+ "jemalloc": {
+ "median": 0.5505,
+ "lo": 0.5485,
+ "hi": 0.552,
+ "peak_mib": 57.3
+ },
+ "mimalloc": {
+ "median": 1.001,
+ "lo": 0.98,
+ "hi": 1.01,
+ "peak_mib": 130.3
+ },
+ "snmalloc": {
+ "median": 0.492,
+ "lo": 0.489,
+ "hi": 0.494,
+ "peak_mib": 67.75
+ },
+ "system": {
+ "median": 0.2185,
+ "lo": 0.2175,
+ "hi": 0.22,
+ "peak_mib": 52.9
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.223,
+ "lo": 1.206,
+ "hi": 1.226,
+ "peak_mib": 63.2
+ },
+ "jemalloc": {
+ "median": 0.6645,
+ "lo": 0.657,
+ "hi": 0.666,
+ "peak_mib": 57.3
+ },
+ "mimalloc": {
+ "median": 1.041,
+ "lo": 1.023,
+ "hi": 1.051,
+ "peak_mib": 130.3
+ },
+ "snmalloc": {
+ "median": 0.527,
+ "lo": 0.5235,
+ "hi": 0.529,
+ "peak_mib": 67.75
+ },
+ "system": {
+ "median": 0.2175,
+ "lo": 0.216,
+ "hi": 0.2185,
+ "peak_mib": 52.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "large",
+ "name": "large blocks",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.092,
+ "lo": 0.091,
+ "hi": 0.093,
+ "peak_mib": 23.6
+ },
+ "jemalloc": {
+ "median": 0.001,
+ "lo": 0.001,
+ "hi": 0.001,
+ "peak_mib": 24.1
+ },
+ "mimalloc": {
+ "median": 0.075,
+ "lo": 0.0665,
+ "hi": 0.095,
+ "peak_mib": 24.3
+ },
+ "snmalloc": {
+ "median": 0.01,
+ "lo": 0.009,
+ "hi": 0.01,
+ "peak_mib": 25.3
+ },
+ "system": {
+ "median": 0.036,
+ "lo": 0.036,
+ "hi": 0.037,
+ "peak_mib": 18.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mops/s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.1075,
+ "lo": 0.106,
+ "hi": 0.108,
+ "peak_mib": 23.6
+ },
+ "jemalloc": {
+ "median": 0.001,
+ "lo": 0.001,
+ "hi": 0.001,
+ "peak_mib": 24.1
+ },
+ "mimalloc": {
+ "median": 0.104,
+ "lo": 0.103,
+ "hi": 0.104,
+ "peak_mib": 24.3
+ },
+ "snmalloc": {
+ "median": 0.011,
+ "lo": 0.011,
+ "hi": 0.011,
+ "peak_mib": 25.3
+ },
+ "system": {
+ "median": 0.096,
+ "lo": 0.095,
+ "hi": 0.096,
+ "peak_mib": 18.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "memory",
+ "name": "burst retention",
+ "lower": true,
+ "size": true,
+ "primary": "value",
+ "metrics": {
+ "value": {
+ "unit": "MiB",
+ "results": {
+ "bcmalloc": {
+ "median": 10.69,
+ "lo": 10.68,
+ "hi": 10.75,
+ "peak_mib": 264.9
+ },
+ "jemalloc": {
+ "median": 269.1,
+ "lo": 269.0,
+ "hi": 269.1,
+ "peak_mib": 271.9
+ },
+ "mimalloc": {
+ "median": 260.1,
+ "lo": 260.0,
+ "hi": 260.1,
+ "peak_mib": 266.3
+ },
+ "snmalloc": {
+ "median": 261.3,
+ "lo": 261.3,
+ "hi": 261.3,
+ "peak_mib": 265.3
+ },
+ "system": {
+ "median": 0.195,
+ "lo": 0.195,
+ "hi": 0.258,
+ "peak_mib": 265.9
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "memory",
+ "name": "half freed",
+ "lower": true,
+ "size": true,
+ "primary": "value",
+ "metrics": {
+ "value": {
+ "unit": "MiB",
+ "results": {
+ "bcmalloc": {
+ "median": 157.4,
+ "lo": 157.4,
+ "hi": 157.5,
+ "peak_mib": 159.7
+ },
+ "jemalloc": {
+ "median": 157.0,
+ "lo": 157.0,
+ "hi": 157.1,
+ "peak_mib": 159.8
+ },
+ "mimalloc": {
+ "median": 156.0,
+ "lo": 156.0,
+ "hi": 156.1,
+ "peak_mib": 162.3
+ },
+ "snmalloc": {
+ "median": 153.4,
+ "lo": 153.4,
+ "hi": 153.4,
+ "peak_mib": 157.4
+ },
+ "system": {
+ "median": 183.2,
+ "lo": 183.2,
+ "hi": 183.2,
+ "peak_mib": 185.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "memory",
+ "name": "phase churn",
+ "lower": true,
+ "size": true,
+ "primary": "value",
+ "metrics": {
+ "value": {
+ "unit": "MiB",
+ "results": {
+ "bcmalloc": {
+ "median": 196.2,
+ "lo": 196.1,
+ "hi": 196.2,
+ "peak_mib": 284.1
+ },
+ "jemalloc": {
+ "median": 156.9,
+ "lo": 155.4,
+ "hi": 159.2,
+ "peak_mib": 227.7
+ },
+ "mimalloc": {
+ "median": 197.0,
+ "lo": 197.0,
+ "hi": 197.1,
+ "peak_mib": 282.3
+ },
+ "snmalloc": {
+ "median": 149.7,
+ "lo": 149.6,
+ "hi": 149.7,
+ "peak_mib": 201.1
+ },
+ "system": {
+ "median": 133.3,
+ "lo": 133.3,
+ "hi": 133.4,
+ "peak_mib": 179.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "latency",
+ "name": "latency churn 1 thread",
+ "lower": true,
+ "size": false,
+ "primary": "p99",
+ "metrics": {
+ "p50": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 3.906,
+ "lo": 3.906,
+ "hi": 4.062,
+ "peak_mib": 11.6
+ },
+ "jemalloc": {
+ "median": 4.531,
+ "lo": 4.375,
+ "hi": 5.156,
+ "peak_mib": 11.2
+ },
+ "mimalloc": {
+ "median": 7.344,
+ "lo": 7.336,
+ "hi": 7.344,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 5.071,
+ "lo": 5.0,
+ "hi": 5.156,
+ "peak_mib": 12.85
+ },
+ "system": {
+ "median": 11.63,
+ "lo": 11.56,
+ "hi": 11.72,
+ "peak_mib": 10.4
+ }
+ }
+ },
+ "p99": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 6.719,
+ "lo": 6.719,
+ "hi": 6.797,
+ "peak_mib": 11.6
+ },
+ "jemalloc": {
+ "median": 18.2,
+ "lo": 17.97,
+ "hi": 18.44,
+ "peak_mib": 11.2
+ },
+ "mimalloc": {
+ "median": 11.41,
+ "lo": 11.41,
+ "hi": 11.48,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 7.5,
+ "lo": 7.5,
+ "hi": 7.656,
+ "peak_mib": 12.85
+ },
+ "system": {
+ "median": 19.22,
+ "lo": 19.22,
+ "hi": 19.23,
+ "peak_mib": 10.4
+ }
+ }
+ },
+ "p999": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 9.531,
+ "lo": 9.453,
+ "hi": 9.61,
+ "peak_mib": 11.6
+ },
+ "jemalloc": {
+ "median": 23.05,
+ "lo": 22.73,
+ "hi": 23.44,
+ "peak_mib": 11.2
+ },
+ "mimalloc": {
+ "median": 17.19,
+ "lo": 16.95,
+ "hi": 17.33,
+ "peak_mib": 16.3
+ },
+ "snmalloc": {
+ "median": 15.63,
+ "lo": 15.39,
+ "hi": 15.78,
+ "peak_mib": 12.85
+ },
+ "system": {
+ "median": 64.38,
+ "lo": 63.83,
+ "hi": 64.69,
+ "peak_mib": 10.4
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "latency",
+ "name": "latency churn 8 threads",
+ "lower": true,
+ "size": false,
+ "primary": "p99",
+ "metrics": {
+ "p50": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 4.062,
+ "lo": 3.992,
+ "hi": 4.062,
+ "peak_mib": 87.85
+ },
+ "jemalloc": {
+ "median": 5.172,
+ "lo": 5.156,
+ "hi": 5.312,
+ "peak_mib": 61.4
+ },
+ "mimalloc": {
+ "median": 12.58,
+ "lo": 12.19,
+ "hi": 12.97,
+ "peak_mib": 76.75
+ },
+ "snmalloc": {
+ "median": 5.0,
+ "lo": 5.0,
+ "hi": 5.156,
+ "peak_mib": 83.6
+ },
+ "system": {
+ "median": 12.03,
+ "lo": 12.03,
+ "hi": 12.03,
+ "peak_mib": 60.1
+ }
+ }
+ },
+ "p99": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 6.875,
+ "lo": 6.875,
+ "hi": 7.11,
+ "peak_mib": 87.85
+ },
+ "jemalloc": {
+ "median": 18.6,
+ "lo": 18.59,
+ "hi": 18.75,
+ "peak_mib": 61.4
+ },
+ "mimalloc": {
+ "median": 31.48,
+ "lo": 30.63,
+ "hi": 32.5,
+ "peak_mib": 76.75
+ },
+ "snmalloc": {
+ "median": 8.446,
+ "lo": 8.368,
+ "hi": 8.578,
+ "peak_mib": 83.6
+ },
+ "system": {
+ "median": 19.69,
+ "lo": 19.69,
+ "hi": 19.7,
+ "peak_mib": 60.1
+ }
+ }
+ },
+ "p999": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 10.0,
+ "lo": 10.0,
+ "hi": 10.47,
+ "peak_mib": 87.85
+ },
+ "jemalloc": {
+ "median": 23.6,
+ "lo": 23.59,
+ "hi": 23.75,
+ "peak_mib": 61.4
+ },
+ "mimalloc": {
+ "median": 51.64,
+ "lo": 49.53,
+ "hi": 54.14,
+ "peak_mib": 76.75
+ },
+ "snmalloc": {
+ "median": 20.0,
+ "lo": 20.0,
+ "hi": 20.0,
+ "peak_mib": 83.6
+ },
+ "system": {
+ "median": 59.38,
+ "lo": 59.15,
+ "hi": 59.77,
+ "peak_mib": 60.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "latency",
+ "name": "latency remote frees",
+ "lower": true,
+ "size": false,
+ "primary": "p99",
+ "metrics": {
+ "p50": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 20.16,
+ "lo": 19.22,
+ "hi": 20.63,
+ "peak_mib": 72.1
+ },
+ "jemalloc": {
+ "median": 41.25,
+ "lo": 40.16,
+ "hi": 41.56,
+ "peak_mib": 44.25
+ },
+ "mimalloc": {
+ "median": 101.3,
+ "lo": 94.55,
+ "hi": 107.5,
+ "peak_mib": 47.3
+ },
+ "snmalloc": {
+ "median": 26.56,
+ "lo": 26.56,
+ "hi": 26.88,
+ "peak_mib": 44.75
+ },
+ "system": {
+ "median": 185.9,
+ "lo": 122.5,
+ "hi": 190.9,
+ "peak_mib": 41.6
+ }
+ }
+ },
+ "p99": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 134.8,
+ "lo": 124.7,
+ "hi": 142.5,
+ "peak_mib": 72.1
+ },
+ "jemalloc": {
+ "median": 109.9,
+ "lo": 109.4,
+ "hi": 110.2,
+ "peak_mib": 44.25
+ },
+ "mimalloc": {
+ "median": 457.3,
+ "lo": 446.3,
+ "hi": 479.7,
+ "peak_mib": 47.3
+ },
+ "snmalloc": {
+ "median": 347.0,
+ "lo": 342.2,
+ "hi": 350.5,
+ "peak_mib": 44.75
+ },
+ "system": {
+ "median": 566.7,
+ "lo": 544.4,
+ "hi": 574.7,
+ "peak_mib": 41.6
+ }
+ }
+ },
+ "p999": {
+ "unit": "ns",
+ "results": {
+ "bcmalloc": {
+ "median": 198.0,
+ "lo": 187.7,
+ "hi": 204.7,
+ "peak_mib": 72.1
+ },
+ "jemalloc": {
+ "median": 161.3,
+ "lo": 160.3,
+ "hi": 162.0,
+ "peak_mib": 44.25
+ },
+ "mimalloc": {
+ "median": 650.0,
+ "lo": 634.2,
+ "hi": 665.6,
+ "peak_mib": 47.3
+ },
+ "snmalloc": {
+ "median": 459.9,
+ "lo": 456.6,
+ "hi": 464.4,
+ "peak_mib": 44.75
+ },
+ "system": {
+ "median": 752.2,
+ "lo": 732.5,
+ "hi": 760.0,
+ "peak_mib": 41.6
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ {
+ "suite": "apps",
+ "machine": "macos",
+ "description": "Apple M4 Max, macOS 27.0.1",
+ "date": "2026-11-14",
+ "samples": 10,
+ "baseline": "mimalloc",
+ "allocators": [
+ "system",
+ "bcmalloc",
+ "mimalloc",
+ "jemalloc",
+ "snmalloc"
+ ],
+ "workloads": [
+ {
+ "group": "apps",
+ "name": "json",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 291.3,
+ "lo": 284.8,
+ "hi": 292.1,
+ "peak_mib": 55.0
+ },
+ "jemalloc": {
+ "median": 247.6,
+ "lo": 246.5,
+ "hi": 248.3,
+ "peak_mib": 57.65
+ },
+ "mimalloc": {
+ "median": 303.3,
+ "lo": 299.7,
+ "hi": 304.2,
+ "peak_mib": 86.9
+ },
+ "snmalloc": {
+ "median": 298.2,
+ "lo": 295.5,
+ "hi": 298.8,
+ "peak_mib": 57.9
+ },
+ "system": {
+ "median": 254.8,
+ "lo": 253.0,
+ "hi": 255.3,
+ "peak_mib": 54.05
+ }
+ }
+ },
+ "warm": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 291.3,
+ "lo": 285.3,
+ "hi": 292.3,
+ "peak_mib": 55.0
+ },
+ "jemalloc": {
+ "median": 248.9,
+ "lo": 247.8,
+ "hi": 250.5,
+ "peak_mib": 57.65
+ },
+ "mimalloc": {
+ "median": 306.0,
+ "lo": 304.6,
+ "hi": 306.7,
+ "peak_mib": 86.9
+ },
+ "snmalloc": {
+ "median": 298.6,
+ "lo": 297.8,
+ "hi": 299.0,
+ "peak_mib": 57.9
+ },
+ "system": {
+ "median": 252.1,
+ "lo": 250.3,
+ "hi": 253.9,
+ "peak_mib": 54.05
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "regex",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1522.0,
+ "lo": 1520.0,
+ "hi": 1524.0,
+ "peak_mib": 22.6
+ },
+ "jemalloc": {
+ "median": 1445.0,
+ "lo": 1443.0,
+ "hi": 1446.0,
+ "peak_mib": 17.7
+ },
+ "mimalloc": {
+ "median": 1513.0,
+ "lo": 1509.0,
+ "hi": 1514.0,
+ "peak_mib": 18.6
+ },
+ "snmalloc": {
+ "median": 1520.0,
+ "lo": 1518.0,
+ "hi": 1524.0,
+ "peak_mib": 20.9
+ },
+ "system": {
+ "median": 1442.0,
+ "lo": 1439.0,
+ "hi": 1445.0,
+ "peak_mib": 20.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1525.0,
+ "lo": 1524.0,
+ "hi": 1526.0,
+ "peak_mib": 22.6
+ },
+ "jemalloc": {
+ "median": 1448.0,
+ "lo": 1446.0,
+ "hi": 1451.0,
+ "peak_mib": 17.7
+ },
+ "mimalloc": {
+ "median": 1515.0,
+ "lo": 1513.0,
+ "hi": 1516.0,
+ "peak_mib": 18.6
+ },
+ "snmalloc": {
+ "median": 1526.0,
+ "lo": 1524.0,
+ "hi": 1527.0,
+ "peak_mib": 20.9
+ },
+ "system": {
+ "median": 1452.0,
+ "lo": 1452.0,
+ "hi": 1456.0,
+ "peak_mib": 20.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "syn",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 20.45,
+ "lo": 20.2,
+ "hi": 20.49,
+ "peak_mib": 71.0
+ },
+ "jemalloc": {
+ "median": 15.94,
+ "lo": 15.84,
+ "hi": 16.01,
+ "peak_mib": 65.45
+ },
+ "mimalloc": {
+ "median": 19.5,
+ "lo": 19.37,
+ "hi": 19.62,
+ "peak_mib": 92.0
+ },
+ "snmalloc": {
+ "median": 19.26,
+ "lo": 19.21,
+ "hi": 19.31,
+ "peak_mib": 71.2
+ },
+ "system": {
+ "median": 16.0,
+ "lo": 15.84,
+ "hi": 16.06,
+ "peak_mib": 66.6
+ }
+ }
+ },
+ "warm": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 20.44,
+ "lo": 20.35,
+ "hi": 20.53,
+ "peak_mib": 71.0
+ },
+ "jemalloc": {
+ "median": 16.05,
+ "lo": 15.97,
+ "hi": 16.13,
+ "peak_mib": 65.45
+ },
+ "mimalloc": {
+ "median": 19.65,
+ "lo": 19.53,
+ "hi": 19.73,
+ "peak_mib": 92.0
+ },
+ "snmalloc": {
+ "median": 19.47,
+ "lo": 19.37,
+ "hi": 19.49,
+ "peak_mib": 71.2
+ },
+ "system": {
+ "median": 16.31,
+ "lo": 16.11,
+ "hi": 16.33,
+ "peak_mib": 66.6
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "http",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "kreq/s",
+ "results": {
+ "bcmalloc": {
+ "median": 228.1,
+ "lo": 222.8,
+ "hi": 229.3,
+ "peak_mib": 6.55
+ },
+ "jemalloc": {
+ "median": 226.7,
+ "lo": 221.4,
+ "hi": 227.9,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 224.0,
+ "lo": 214.1,
+ "hi": 226.1,
+ "peak_mib": 4.55
+ },
+ "snmalloc": {
+ "median": 225.8,
+ "lo": 220.8,
+ "hi": 227.4,
+ "peak_mib": 4.0
+ },
+ "system": {
+ "median": 217.3,
+ "lo": 212.1,
+ "hi": 218.5,
+ "peak_mib": 4.1
+ }
+ }
+ },
+ "warm": {
+ "unit": "kreq/s",
+ "results": {
+ "bcmalloc": {
+ "median": 227.6,
+ "lo": 226.3,
+ "hi": 228.9,
+ "peak_mib": 6.55
+ },
+ "jemalloc": {
+ "median": 225.7,
+ "lo": 223.3,
+ "hi": 227.3,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 225.6,
+ "lo": 223.7,
+ "hi": 227.7,
+ "peak_mib": 4.55
+ },
+ "snmalloc": {
+ "median": 225.3,
+ "lo": 222.5,
+ "hi": 226.9,
+ "peak_mib": 4.0
+ },
+ "system": {
+ "median": 218.6,
+ "lo": 217.7,
+ "hi": 219.2,
+ "peak_mib": 4.1
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "tokio channels",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mmsg/s",
+ "results": {
+ "bcmalloc": {
+ "median": 4.584,
+ "lo": 4.564,
+ "hi": 4.591,
+ "peak_mib": 5.9
+ },
+ "jemalloc": {
+ "median": 4.456,
+ "lo": 4.438,
+ "hi": 4.468,
+ "peak_mib": 5.15
+ },
+ "mimalloc": {
+ "median": 4.127,
+ "lo": 4.113,
+ "hi": 4.154,
+ "peak_mib": 4.15
+ },
+ "snmalloc": {
+ "median": 4.481,
+ "lo": 4.452,
+ "hi": 4.485,
+ "peak_mib": 3.7
+ },
+ "system": {
+ "median": 4.042,
+ "lo": 4.002,
+ "hi": 4.059,
+ "peak_mib": 3.4
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mmsg/s",
+ "results": {
+ "bcmalloc": {
+ "median": 4.594,
+ "lo": 4.574,
+ "hi": 4.608,
+ "peak_mib": 5.9
+ },
+ "jemalloc": {
+ "median": 4.421,
+ "lo": 4.377,
+ "hi": 4.427,
+ "peak_mib": 5.15
+ },
+ "mimalloc": {
+ "median": 4.142,
+ "lo": 4.135,
+ "hi": 4.169,
+ "peak_mib": 4.15
+ },
+ "snmalloc": {
+ "median": 4.444,
+ "lo": 4.432,
+ "hi": 4.458,
+ "peak_mib": 3.7
+ },
+ "system": {
+ "median": 4.045,
+ "lo": 4.024,
+ "hi": 4.06,
+ "peak_mib": 3.4
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ {
+ "suite": "apps",
+ "machine": "linux",
+ "description": "AMD EPYC 9354P 32-Core Processor, Ubuntu 24.04.2 LTS, Linux 7.0.0",
+ "date": "2026-11-14",
+ "samples": 10,
+ "baseline": "mimalloc",
+ "allocators": [
+ "system",
+ "bcmalloc",
+ "mimalloc",
+ "jemalloc",
+ "snmalloc"
+ ],
+ "workloads": [
+ {
+ "group": "apps",
+ "name": "json",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 192.6,
+ "lo": 192.3,
+ "hi": 193.3,
+ "peak_mib": 60.8
+ },
+ "jemalloc": {
+ "median": 166.8,
+ "lo": 166.6,
+ "hi": 167.5,
+ "peak_mib": 60.0
+ },
+ "mimalloc": {
+ "median": 185.3,
+ "lo": 184.2,
+ "hi": 186.3,
+ "peak_mib": 107.9
+ },
+ "snmalloc": {
+ "median": 177.0,
+ "lo": 176.3,
+ "hi": 177.9,
+ "peak_mib": 61.1
+ },
+ "system": {
+ "median": 127.8,
+ "lo": 127.3,
+ "hi": 128.0,
+ "peak_mib": 58.15
+ }
+ }
+ },
+ "warm": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 193.4,
+ "lo": 193.1,
+ "hi": 193.9,
+ "peak_mib": 60.8
+ },
+ "jemalloc": {
+ "median": 171.3,
+ "lo": 169.9,
+ "hi": 171.7,
+ "peak_mib": 60.0
+ },
+ "mimalloc": {
+ "median": 188.1,
+ "lo": 186.6,
+ "hi": 188.3,
+ "peak_mib": 107.9
+ },
+ "snmalloc": {
+ "median": 182.1,
+ "lo": 181.3,
+ "hi": 183.2,
+ "peak_mib": 61.1
+ },
+ "system": {
+ "median": 131.2,
+ "lo": 130.7,
+ "hi": 131.4,
+ "peak_mib": 58.15
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "regex",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1048.0,
+ "lo": 1047.0,
+ "hi": 1049.0,
+ "peak_mib": 26.75
+ },
+ "jemalloc": {
+ "median": 1025.0,
+ "lo": 1024.0,
+ "hi": 1026.0,
+ "peak_mib": 22.85
+ },
+ "mimalloc": {
+ "median": 1039.0,
+ "lo": 1036.0,
+ "hi": 1043.0,
+ "peak_mib": 36.9
+ },
+ "snmalloc": {
+ "median": 1036.0,
+ "lo": 1035.0,
+ "hi": 1038.0,
+ "peak_mib": 24.1
+ },
+ "system": {
+ "median": 978.5,
+ "lo": 976.6,
+ "hi": 979.2,
+ "peak_mib": 17.7
+ }
+ }
+ },
+ "warm": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1049.0,
+ "lo": 1048.0,
+ "hi": 1050.0,
+ "peak_mib": 26.75
+ },
+ "jemalloc": {
+ "median": 1034.0,
+ "lo": 1033.0,
+ "hi": 1036.0,
+ "peak_mib": 22.85
+ },
+ "mimalloc": {
+ "median": 1039.0,
+ "lo": 1036.0,
+ "hi": 1041.0,
+ "peak_mib": 36.9
+ },
+ "snmalloc": {
+ "median": 1045.0,
+ "lo": 1044.0,
+ "hi": 1047.0,
+ "peak_mib": 24.1
+ },
+ "system": {
+ "median": 986.9,
+ "lo": 985.3,
+ "hi": 988.0,
+ "peak_mib": 17.7
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "syn",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 10.59,
+ "lo": 10.57,
+ "hi": 10.62,
+ "peak_mib": 74.45
+ },
+ "jemalloc": {
+ "median": 8.876,
+ "lo": 8.836,
+ "hi": 8.944,
+ "peak_mib": 94.15
+ },
+ "mimalloc": {
+ "median": 9.976,
+ "lo": 9.886,
+ "hi": 10.06,
+ "peak_mib": 110.4
+ },
+ "snmalloc": {
+ "median": 9.432,
+ "lo": 9.425,
+ "hi": 9.483,
+ "peak_mib": 75.3
+ },
+ "system": {
+ "median": 7.017,
+ "lo": 6.99,
+ "hi": 7.026,
+ "peak_mib": 64.45
+ }
+ }
+ },
+ "warm": {
+ "unit": "MB/s",
+ "results": {
+ "bcmalloc": {
+ "median": 10.62,
+ "lo": 10.58,
+ "hi": 10.65,
+ "peak_mib": 74.45
+ },
+ "jemalloc": {
+ "median": 9.122,
+ "lo": 9.091,
+ "hi": 9.163,
+ "peak_mib": 94.15
+ },
+ "mimalloc": {
+ "median": 10.02,
+ "lo": 9.952,
+ "hi": 10.03,
+ "peak_mib": 110.4
+ },
+ "snmalloc": {
+ "median": 9.673,
+ "lo": 9.665,
+ "hi": 9.732,
+ "peak_mib": 75.3
+ },
+ "system": {
+ "median": 7.165,
+ "lo": 7.146,
+ "hi": 7.176,
+ "peak_mib": 64.45
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "http",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "kreq/s",
+ "results": {
+ "bcmalloc": {
+ "median": 122.2,
+ "lo": 121.4,
+ "hi": 122.9,
+ "peak_mib": 5.5
+ },
+ "jemalloc": {
+ "median": 121.6,
+ "lo": 120.8,
+ "hi": 122.2,
+ "peak_mib": 5.65
+ },
+ "mimalloc": {
+ "median": 115.6,
+ "lo": 115.1,
+ "hi": 116.3,
+ "peak_mib": 14.1
+ },
+ "snmalloc": {
+ "median": 118.2,
+ "lo": 117.7,
+ "hi": 118.7,
+ "peak_mib": 6.8
+ },
+ "system": {
+ "median": 101.1,
+ "lo": 100.8,
+ "hi": 101.8,
+ "peak_mib": 4.0
+ }
+ }
+ },
+ "warm": {
+ "unit": "kreq/s",
+ "results": {
+ "bcmalloc": {
+ "median": 122.6,
+ "lo": 122.1,
+ "hi": 122.9,
+ "peak_mib": 5.5
+ },
+ "jemalloc": {
+ "median": 120.6,
+ "lo": 120.2,
+ "hi": 121.1,
+ "peak_mib": 5.65
+ },
+ "mimalloc": {
+ "median": 115.6,
+ "lo": 115.4,
+ "hi": 115.9,
+ "peak_mib": 14.1
+ },
+ "snmalloc": {
+ "median": 118.1,
+ "lo": 117.7,
+ "hi": 118.4,
+ "peak_mib": 6.8
+ },
+ "system": {
+ "median": 101.2,
+ "lo": 100.8,
+ "hi": 101.7,
+ "peak_mib": 4.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "apps",
+ "name": "tokio channels",
+ "lower": false,
+ "size": false,
+ "primary": "warm",
+ "metrics": {
+ "cold": {
+ "unit": "Mmsg/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.876,
+ "lo": 1.871,
+ "hi": 1.886,
+ "peak_mib": 5.7
+ },
+ "jemalloc": {
+ "median": 1.925,
+ "lo": 1.912,
+ "hi": 1.972,
+ "peak_mib": 6.15
+ },
+ "mimalloc": {
+ "median": 1.424,
+ "lo": 1.402,
+ "hi": 1.442,
+ "peak_mib": 10.15
+ },
+ "snmalloc": {
+ "median": 1.748,
+ "lo": 1.744,
+ "hi": 1.757,
+ "peak_mib": 6.3
+ },
+ "system": {
+ "median": 1.229,
+ "lo": 1.227,
+ "hi": 1.231,
+ "peak_mib": 4.3
+ }
+ }
+ },
+ "warm": {
+ "unit": "Mmsg/s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.883,
+ "lo": 1.875,
+ "hi": 1.9,
+ "peak_mib": 5.7
+ },
+ "jemalloc": {
+ "median": 1.926,
+ "lo": 1.909,
+ "hi": 1.964,
+ "peak_mib": 6.15
+ },
+ "mimalloc": {
+ "median": 1.406,
+ "lo": 1.385,
+ "hi": 1.412,
+ "peak_mib": 10.15
+ },
+ "snmalloc": {
+ "median": 1.753,
+ "lo": 1.743,
+ "hi": 1.771,
+ "peak_mib": 6.3
+ },
+ "system": {
+ "median": 1.223,
+ "lo": 1.222,
+ "hi": 1.227,
+ "peak_mib": 4.3
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ {
+ "suite": "mimalloc-bench",
+ "machine": "linux",
+ "description": "AMD EPYC 9354P 32-Core Processor, Ubuntu 24.04.2 LTS, Linux 6.8.0",
+ "date": "2026-11-14",
+ "samples": 3,
+ "baseline": "mimalloc",
+ "allocators": [
+ "bcmalloc",
+ "mimalloc",
+ "snmalloc",
+ "jemalloc"
+ ],
+ "workloads": [
+ {
+ "group": "mimalloc-bench",
+ "name": "cfrac",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 3.25,
+ "lo": 3.23,
+ "hi": 3.26,
+ "peak_mib": 3.25
+ },
+ "jemalloc": {
+ "median": 3.27,
+ "lo": 3.27,
+ "hi": 3.29,
+ "peak_mib": 5.25
+ },
+ "mimalloc": {
+ "median": 3.24,
+ "lo": 3.24,
+ "hi": 3.24,
+ "peak_mib": 4.418
+ },
+ "snmalloc": {
+ "median": 3.16,
+ "lo": 3.14,
+ "hi": 3.16,
+ "peak_mib": 3.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "espresso",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 3.47,
+ "lo": 3.45,
+ "hi": 3.48,
+ "peak_mib": 3.75
+ },
+ "jemalloc": {
+ "median": 3.54,
+ "lo": 3.54,
+ "hi": 3.54,
+ "peak_mib": 6.25
+ },
+ "mimalloc": {
+ "median": 3.47,
+ "lo": 3.47,
+ "hi": 3.48,
+ "peak_mib": 10.42
+ },
+ "snmalloc": {
+ "median": 3.42,
+ "lo": 3.42,
+ "hi": 3.42,
+ "peak_mib": 4.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "barnes",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.17,
+ "lo": 2.17,
+ "hi": 2.18,
+ "peak_mib": 63.46
+ },
+ "jemalloc": {
+ "median": 2.25,
+ "lo": 2.25,
+ "hi": 2.26,
+ "peak_mib": 59.5
+ },
+ "mimalloc": {
+ "median": 2.21,
+ "lo": 2.21,
+ "hi": 2.21,
+ "peak_mib": 67.53
+ },
+ "snmalloc": {
+ "median": 2.26,
+ "lo": 2.25,
+ "hi": 2.26,
+ "peak_mib": 58.25
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "redis",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 3.319,
+ "lo": 3.2,
+ "hi": 3.339,
+ "peak_mib": 11.16
+ },
+ "jemalloc": {
+ "median": 3.74,
+ "lo": 3.72,
+ "hi": 3.839,
+ "peak_mib": 10.0
+ },
+ "mimalloc": {
+ "median": 3.42,
+ "lo": 3.42,
+ "hi": 3.58,
+ "peak_mib": 20.09
+ },
+ "snmalloc": {
+ "median": 3.12,
+ "lo": 3.099,
+ "hi": 3.379,
+ "peak_mib": 8.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "larsonN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.071,
+ "lo": 1.07,
+ "hi": 1.071,
+ "peak_mib": 342.1
+ },
+ "jemalloc": {
+ "median": 1.29,
+ "lo": 1.271,
+ "hi": 1.291,
+ "peak_mib": 260.0
+ },
+ "mimalloc": {
+ "median": 1.167,
+ "lo": 1.161,
+ "hi": 1.178,
+ "peak_mib": 306.5
+ },
+ "snmalloc": {
+ "median": 1.219,
+ "lo": 1.187,
+ "hi": 1.229,
+ "peak_mib": 415.8
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "larsonN-sized",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.03,
+ "lo": 1.022,
+ "hi": 1.038,
+ "peak_mib": 347.9
+ },
+ "jemalloc": {
+ "median": 1.161,
+ "lo": 1.133,
+ "hi": 1.163,
+ "peak_mib": 270.1
+ },
+ "mimalloc": {
+ "median": 1.126,
+ "lo": 1.113,
+ "hi": 1.138,
+ "peak_mib": 310.4
+ },
+ "snmalloc": {
+ "median": 1.183,
+ "lo": 1.182,
+ "hi": 1.21,
+ "peak_mib": 418.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "mstressN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.67,
+ "lo": 0.67,
+ "hi": 0.68,
+ "peak_mib": 598.2
+ },
+ "jemalloc": {
+ "median": 1.23,
+ "lo": 1.23,
+ "hi": 1.23,
+ "peak_mib": 511.0
+ },
+ "mimalloc": {
+ "median": 0.63,
+ "lo": 0.62,
+ "hi": 0.63,
+ "peak_mib": 1030.0
+ },
+ "snmalloc": {
+ "median": 0.82,
+ "lo": 0.81,
+ "hi": 0.86,
+ "peak_mib": 813.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "rptestN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.199,
+ "lo": 0.197,
+ "hi": 0.2,
+ "peak_mib": 222.8
+ },
+ "jemalloc": {
+ "median": 0.511,
+ "lo": 0.51,
+ "hi": 0.514,
+ "peak_mib": 161.0
+ },
+ "mimalloc": {
+ "median": 0.237,
+ "lo": 0.228,
+ "hi": 0.24,
+ "peak_mib": 236.0
+ },
+ "snmalloc": {
+ "median": 0.215,
+ "lo": 0.208,
+ "hi": 0.22,
+ "peak_mib": 183.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "gs",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.22,
+ "lo": 0.22,
+ "hi": 0.22,
+ "peak_mib": 41.79
+ },
+ "jemalloc": {
+ "median": 0.24,
+ "lo": 0.24,
+ "hi": 0.24,
+ "peak_mib": 36.75
+ },
+ "mimalloc": {
+ "median": 0.23,
+ "lo": 0.23,
+ "hi": 0.23,
+ "peak_mib": 55.29
+ },
+ "snmalloc": {
+ "median": 0.24,
+ "lo": 0.24,
+ "hi": 0.24,
+ "peak_mib": 36.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "alloc-test1",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.64,
+ "lo": 2.64,
+ "hi": 2.67,
+ "peak_mib": 14.16
+ },
+ "jemalloc": {
+ "median": 2.58,
+ "lo": 2.57,
+ "hi": 2.59,
+ "peak_mib": 12.75
+ },
+ "mimalloc": {
+ "median": 2.5,
+ "lo": 2.5,
+ "hi": 2.52,
+ "peak_mib": 16.25
+ },
+ "snmalloc": {
+ "median": 2.59,
+ "lo": 2.58,
+ "hi": 2.59,
+ "peak_mib": 13.75
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "alloc-testN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.46,
+ "lo": 2.44,
+ "hi": 2.47,
+ "peak_mib": 15.75
+ },
+ "jemalloc": {
+ "median": 2.33,
+ "lo": 2.31,
+ "hi": 2.34,
+ "peak_mib": 16.25
+ },
+ "mimalloc": {
+ "median": 2.3,
+ "lo": 2.28,
+ "hi": 2.3,
+ "peak_mib": 60.32
+ },
+ "snmalloc": {
+ "median": 2.31,
+ "lo": 2.29,
+ "hi": 2.35,
+ "peak_mib": 16.25
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "sh6benchN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.06,
+ "lo": 0.06,
+ "hi": 0.06,
+ "peak_mib": 280.1
+ },
+ "jemalloc": {
+ "median": 0.09,
+ "lo": 0.09,
+ "hi": 0.09,
+ "peak_mib": 224.3
+ },
+ "mimalloc": {
+ "median": 0.05,
+ "lo": 0.04,
+ "hi": 0.05,
+ "peak_mib": 226.4
+ },
+ "snmalloc": {
+ "median": 0.08,
+ "lo": 0.08,
+ "hi": 0.09,
+ "peak_mib": 275.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "sh8benchN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.17,
+ "lo": 0.16,
+ "hi": 0.17,
+ "peak_mib": 251.3
+ },
+ "jemalloc": {
+ "median": 0.27,
+ "lo": 0.26,
+ "hi": 0.28,
+ "peak_mib": 168.2
+ },
+ "mimalloc": {
+ "median": 0.14,
+ "lo": 0.14,
+ "hi": 0.15,
+ "peak_mib": 510.5
+ },
+ "snmalloc": {
+ "median": 0.19,
+ "lo": 0.19,
+ "hi": 0.19,
+ "peak_mib": 205.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "xmalloc-testN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.191,
+ "lo": 0.191,
+ "hi": 0.192,
+ "peak_mib": 103.0
+ },
+ "jemalloc": {
+ "median": 0.165,
+ "lo": 0.163,
+ "hi": 0.165,
+ "peak_mib": 141.6
+ },
+ "mimalloc": {
+ "median": 0.216,
+ "lo": 0.213,
+ "hi": 0.217,
+ "peak_mib": 66.33
+ },
+ "snmalloc": {
+ "median": 0.177,
+ "lo": 0.176,
+ "hi": 0.178,
+ "peak_mib": 128.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "cache-scratch1",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 6.246
+ },
+ "snmalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 4.25
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "cache-scratchN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 6.246
+ },
+ "snmalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 3.75
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "glibc-simple",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.67,
+ "lo": 1.66,
+ "hi": 1.7,
+ "peak_mib": 2.0
+ },
+ "jemalloc": {
+ "median": 1.9,
+ "lo": 1.9,
+ "hi": 1.93,
+ "peak_mib": 4.75
+ },
+ "mimalloc": {
+ "median": 1.59,
+ "lo": 1.48,
+ "hi": 1.59,
+ "peak_mib": 4.152
+ },
+ "snmalloc": {
+ "median": 1.62,
+ "lo": 1.52,
+ "hi": 1.62,
+ "peak_mib": 2.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "glibc-thread",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.203,
+ "lo": 0.202,
+ "hi": 0.203,
+ "peak_mib": 10.75
+ },
+ "jemalloc": {
+ "median": 0.205,
+ "lo": 0.201,
+ "hi": 0.209,
+ "peak_mib": 14.75
+ },
+ "mimalloc": {
+ "median": 0.199,
+ "lo": 0.194,
+ "hi": 0.202,
+ "peak_mib": 88.45
+ },
+ "snmalloc": {
+ "median": 0.192,
+ "lo": 0.192,
+ "hi": 0.193,
+ "peak_mib": 21.25
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "rocksdb",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 4.27,
+ "lo": 4.24,
+ "hi": 4.27,
+ "peak_mib": 102.7
+ },
+ "jemalloc": {
+ "median": 4.35,
+ "lo": 4.31,
+ "hi": 4.38,
+ "peak_mib": 102.5
+ },
+ "mimalloc": {
+ "median": 4.13,
+ "lo": 4.13,
+ "hi": 4.2,
+ "peak_mib": 141.9
+ },
+ "snmalloc": {
+ "median": 4.35,
+ "lo": 4.27,
+ "hi": 4.45,
+ "peak_mib": 107.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "leanN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 9.1,
+ "lo": 9.08,
+ "hi": 9.13,
+ "peak_mib": 260.4
+ },
+ "jemalloc": {
+ "median": 9.28,
+ "lo": 9.27,
+ "hi": 9.29,
+ "peak_mib": 218.9
+ },
+ "mimalloc": {
+ "median": 9.08,
+ "lo": 9.06,
+ "hi": 9.12,
+ "peak_mib": 335.9
+ },
+ "snmalloc": {
+ "median": 9.11,
+ "lo": 9.09,
+ "hi": 9.14,
+ "peak_mib": 242.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "linux",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.15,
+ "lo": 0.15,
+ "hi": 0.15,
+ "peak_mib": 18.0
+ },
+ "jemalloc": {
+ "median": 0.16,
+ "lo": 0.16,
+ "hi": 0.16,
+ "peak_mib": 18.5
+ },
+ "mimalloc": {
+ "median": 0.17,
+ "lo": 0.16,
+ "hi": 0.17,
+ "peak_mib": 23.67
+ },
+ "snmalloc": {
+ "median": 0.15,
+ "lo": 0.15,
+ "hi": 0.15,
+ "peak_mib": 18.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "malloc-large",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.42,
+ "lo": 1.38,
+ "hi": 1.42,
+ "peak_mib": 579.6
+ },
+ "jemalloc": {
+ "median": 14.42,
+ "lo": 14.35,
+ "hi": 14.76,
+ "peak_mib": 429.6
+ },
+ "mimalloc": {
+ "median": 1.4,
+ "lo": 1.37,
+ "hi": 1.42,
+ "peak_mib": 588.1
+ },
+ "snmalloc": {
+ "median": 3.56,
+ "lo": 3.55,
+ "hi": 3.57,
+ "peak_mib": 650.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "mleak10",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.15,
+ "lo": 0.14,
+ "hi": 0.15,
+ "peak_mib": 1.992
+ },
+ "jemalloc": {
+ "median": 0.16,
+ "lo": 0.16,
+ "hi": 0.16,
+ "peak_mib": 4.75
+ },
+ "mimalloc": {
+ "median": 0.15,
+ "lo": 0.15,
+ "hi": 0.15,
+ "peak_mib": 4.156
+ },
+ "snmalloc": {
+ "median": 0.14,
+ "lo": 0.14,
+ "hi": 0.15,
+ "peak_mib": 2.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "mleak100",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.5,
+ "lo": 1.46,
+ "hi": 1.5,
+ "peak_mib": 2.0
+ },
+ "jemalloc": {
+ "median": 1.61,
+ "lo": 1.59,
+ "hi": 1.63,
+ "peak_mib": 4.75
+ },
+ "mimalloc": {
+ "median": 1.5,
+ "lo": 1.5,
+ "hi": 1.52,
+ "peak_mib": 4.152
+ },
+ "snmalloc": {
+ "median": 1.5,
+ "lo": 1.5,
+ "hi": 1.52,
+ "peak_mib": 2.5
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "rbstress1",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 2.79,
+ "lo": 2.79,
+ "hi": 2.8,
+ "peak_mib": 118.8
+ },
+ "jemalloc": {
+ "median": 2.8,
+ "lo": 2.78,
+ "hi": 2.82,
+ "peak_mib": 119.0
+ },
+ "mimalloc": {
+ "median": 2.82,
+ "lo": 2.82,
+ "hi": 2.86,
+ "peak_mib": 139.2
+ },
+ "snmalloc": {
+ "median": 2.82,
+ "lo": 2.81,
+ "hi": 2.83,
+ "peak_mib": 117.3
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "rbstressN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 3.02,
+ "lo": 3.02,
+ "hi": 3.04,
+ "peak_mib": 163.3
+ },
+ "jemalloc": {
+ "median": 2.99,
+ "lo": 2.96,
+ "hi": 3.04,
+ "peak_mib": 201.3
+ },
+ "mimalloc": {
+ "median": 3.01,
+ "lo": 2.98,
+ "hi": 3.07,
+ "peak_mib": 192.7
+ },
+ "snmalloc": {
+ "median": 3.01,
+ "lo": 3.0,
+ "hi": 3.14,
+ "peak_mib": 209.0
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "cache-thrash1",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 6.25
+ },
+ "snmalloc": {
+ "median": 1.05,
+ "lo": 1.05,
+ "hi": 1.05,
+ "peak_mib": 4.25
+ }
+ }
+ }
+ }
+ },
+ {
+ "group": "mimalloc-bench",
+ "name": "cache-thrashN",
+ "lower": true,
+ "size": false,
+ "primary": "time",
+ "metrics": {
+ "time": {
+ "unit": "s",
+ "results": {
+ "bcmalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 4.0
+ },
+ "jemalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 4.5
+ },
+ "mimalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 6.246
+ },
+ "snmalloc": {
+ "median": 0.03,
+ "lo": 0.03,
+ "hi": 0.03,
+ "peak_mib": 4.0
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000..4148c27
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,13 @@
+coverage:
+ status:
+ project:
+ default:
+ target: auto
+ threshold: 1%
+ patch:
+ default:
+ target: 80%
+ignore:
+ - "crates/bench"
+ - "crates/bench-apps"
+ - "fuzz"
diff --git a/crates/bcmalloc/Cargo.toml b/crates/bcmalloc/Cargo.toml
index e9f2b3b..bc8cb89 100644
--- a/crates/bcmalloc/Cargo.toml
+++ b/crates/bcmalloc/Cargo.toml
@@ -16,6 +16,9 @@ default = [ "std" ]
std = [ "libc/std" ]
# Exposes the model-checking helpers in `bcmalloc::testing` (used by the fuzz targets).
testing = [ "std" ]
+# Counts allocations, frees, slabs and slow-path events per heap, for `Region::metrics` and
+# `Bcmalloc::metrics`. The fast paths pay one add each on a cache line they already touch.
+metrics = []
[dependencies]
libc.workspace = true
diff --git a/crates/bcmalloc/src/allocator.rs b/crates/bcmalloc/src/allocator.rs
index 314b00d..0d82191 100644
--- a/crates/bcmalloc/src/allocator.rs
+++ b/crates/bcmalloc/src/allocator.rs
@@ -12,11 +12,12 @@
//! * A block is as long as it was asked to be. The allocator may have rounded the size up
//! internally, but the slice it returns is exactly the requested length, so the zeroing and
//! copying rules stay simple.
-//! * Zeroed requests clear the whole block. Memory that was freed or given back to the OS is not
-//! known to be zero, so there is no shortcut.
-//! * Growing and shrinking keep the block in place when the new size falls in the same size class.
-//! Otherwise they move it, and they always move it when the alignment changes, which the
-//! allocator's own resize does not support.
+//! * Zeroed requests read as zeros in the whole block. Fresh memory is not cleared again, and
+//! everything else is.
+//! * Growing and shrinking keep the block in place when the allocator's own resize does, which is
+//! when the new size still fits the block and fills at least half of it, or when a block of whole
+//! chunks can shrink or grow where it is. They always move it when the alignment changes, which
+//! that resize does not support.
use core::{
alloc::{AllocError, Layout},
@@ -24,7 +25,7 @@ use core::{
ptr::{self, NonNull},
};
-/// The three operations that the allocator trait is built from.
+/// The operations that the allocator trait is built from.
pub(crate) trait Backend {
/// Allocates a block, or returns null.
///
@@ -33,6 +34,13 @@ pub(crate) trait Backend {
/// The layout must not be zero sized.
unsafe fn allocate_raw(&self, layout: Layout) -> *mut u8;
+ /// Allocates a zeroed block, or returns null.
+ ///
+ /// # Safety
+ ///
+ /// The layout must not be zero sized.
+ unsafe fn allocate_zeroed_raw(&self, layout: Layout) -> *mut u8;
+
/// Frees a block.
///
/// # Safety
@@ -69,11 +77,9 @@ pub(crate) fn allocate(
return Ok(empty(layout));
}
// SAFETY: the layout is not zero sized.
- let ptr = unsafe { backend.allocate_raw(layout) };
- if zeroed && !ptr.is_null() {
- // SAFETY: the block holds the layout's size in bytes.
- unsafe { ptr.write_bytes(0, layout.size()) };
- }
+ let ptr = unsafe {
+ if zeroed { backend.allocate_zeroed_raw(layout) } else { backend.allocate_raw(layout) }
+ };
block(ptr, layout.size())
}
@@ -187,11 +193,10 @@ pub(crate) use allocator;
#[cfg(all(test, not(loom)))]
mod test {
- use core::alloc::Allocator;
- use std::{boxed::Box, vec::Vec};
-
use super::*;
use crate::testing::{TestRegion, iterations};
+ use core::alloc::Allocator;
+ use std::{boxed::Box, vec::Vec};
fn layout(size: usize, align: usize) -> Layout {
Layout::from_size_align(size, align).unwrap()
@@ -205,7 +210,7 @@ mod test {
#[test]
fn collections_allocate_from_a_heap() {
- // The biggest slabs span 64 chunks, so the region has to have room for more than one.
+ // The biggest slabs span 8 chunks, and the region has room for many of them.
let test = TestRegion::new(160, 1);
let region = test.region();
let heap = region.heap().unwrap();
@@ -249,9 +254,9 @@ mod test {
// SAFETY: the block came from this allocator with this layout and is freed once.
unsafe { heap.deallocate(block.cast(), layout) };
}
- // A slab holds 327 of these blocks, so asking for that many covers every block that was
- // dirtied.
- let clean: Vec<_> = (0..327).map(|_| heap.allocate_zeroed(layout).unwrap()).collect();
+ // Asking for a whole slab of blocks covers every block that was dirtied.
+ let per_slab = crate::size_class::Class::for_size(200).blocks_per_slab();
+ let clean: Vec<_> = (0..per_slab).map(|_| heap.allocate_zeroed(layout).unwrap()).collect();
assert!(clean.iter().all(|block| bytes(*block).iter().all(|&byte| byte == 0)));
assert!(
clean
@@ -284,10 +289,10 @@ mod test {
let heap = region.heap().unwrap();
let block = heap.allocate(layout(20, 8)).unwrap();
// SAFETY: the block is live with the old layout and the new size is larger.
- let grown = unsafe { heap.grow(block.cast(), layout(20, 8), layout(30, 8)) }.unwrap();
+ let grown = unsafe { heap.grow(block.cast(), layout(20, 8), layout(24, 8)) }.unwrap();
assert_eq!(grown.cast::(), block.cast::());
// SAFETY: the block is live with the layout it was grown to, and the new size is smaller.
- let shrunk = unsafe { heap.shrink(grown.cast(), layout(30, 8), layout(18, 8)) }.unwrap();
+ let shrunk = unsafe { heap.shrink(grown.cast(), layout(24, 8), layout(18, 8)) }.unwrap();
assert_eq!(shrunk.cast::(), block.cast::());
}
diff --git a/crates/bcmalloc/src/chunks.rs b/crates/bcmalloc/src/chunks.rs
index 81ca30d..a6ceca2 100644
--- a/crates/bcmalloc/src/chunks.rs
+++ b/crates/bcmalloc/src/chunks.rs
@@ -20,8 +20,8 @@
//!
//! A run of up to 64 chunks fits in one word, so claiming it takes one compare-and-swap. A swap
//! only fails because another thread's swap succeeded, which makes this path lock-free. A run may
-//! be required to start at a multiple of an alignment. That is how slabs of 8 and 64 chunks stay
-//! aligned to their own size.
+//! be required to start at a multiple of an alignment. That is how slabs of 8 chunks stay aligned
+//! to their own size.
//!
//! A run of more than 64 chunks spans several words, and no single atomic covers that. The
//! allocator claims the words in order and rolls back if it loses a race. This path is
@@ -54,10 +54,12 @@
//! caller returns the pages to the OS, and the next claim of a purged chunk learns that it must
//! prepare them for use again.
//!
-//! Pages are given back in granules of a fixed number of chunks. With transparent huge pages a
-//! granule is one 2 MiB page, 32 chunks, and a pass only takes a granule whose every chunk is free.
-//! Returning part of a huge page would split it into small pages, which costs the TLB reach that
-//! huge pages exist for. This is the rule Temeraire follows in TCMalloc.
+//! Pages are given back in granules of a fixed number of chunks. In memory backed by transparent
+//! huge pages a granule is one 2 MiB page, 32 chunks, and a pass only takes a granule whose every
+//! chunk is free. Returning part of a huge page would split it into small pages, which costs the
+//! TLB reach that huge pages exist for. This is the rule Temeraire follows in TCMalloc. The
+//! bitmap can be split into parts of which only every second one is purged in granules, for the
+//! zones of a region.
//!
//! # Placement within a word
//!
@@ -71,9 +73,8 @@
//! and then reused by another. The release on the free and the acquire on the next claim make the
//! first thread's writes visible to the second.
-use core::ops::Range;
-
use crate::sync::{AtomicU64, Ordering};
+use core::ops::Range;
/// log2 of the chunk size.
pub(crate) const CHUNK_SHIFT: usize = 16;
@@ -99,6 +100,14 @@ pub(crate) struct Chunks<'a> {
len: usize,
/// How many chunks are purged together, a power of two of at most 64.
granule: usize,
+ /// If not zero, the words are split into this many parts as [`Region::home`] splits them,
+ /// and only the words of the odd parts are purged in granules. The others go a chunk at a
+ /// time.
+ ///
+ /// [`Region::home`]: crate::region::Region::home
+ coarse_parts: usize,
+ /// How many times the purge delay the words of the odd parts wait.
+ coarse_wait: u64,
}
impl<'a> Chunks<'a> {
@@ -126,7 +135,44 @@ impl<'a> Chunks<'a> {
let (used, rest) = words.split_at(each);
let (dirty, rest) = rest.split_at(each);
let (purged, rest) = rest.split_at(each);
- Self { used, dirty, purged, stamps: &rest[..each], len, granule }
+ Self {
+ used,
+ dirty,
+ purged,
+ stamps: &rest[..each],
+ len,
+ granule,
+ coarse_parts: 0,
+ coarse_wait: 1,
+ }
+ }
+
+ /// These chunks with only the odd ones of `parts` parts purged in granules, and only after
+ /// `wait` times the purge delay. See [`Chunks::coarse_parts`](Self#structfield.coarse_parts).
+ pub(crate) const fn coarse_in_odd_parts(self, parts: usize, wait: u64) -> Self {
+ Self { coarse_parts: parts, coarse_wait: wait, ..self }
+ }
+
+ /// Whether word `w` lies in an odd part, or there are no parts.
+ const fn is_coarse(&self, w: usize) -> bool {
+ let parts = self.coarse_parts;
+ if parts == 0 {
+ return true;
+ }
+ // The part whose words `p * words / parts..(p + 1) * words / parts` hold `w`.
+ let words = Self::words_for(self.len);
+ let part = ((w + 1) * parts).div_ceil(words) - 1;
+ part % 2 == 1
+ }
+
+ /// How many chunks of word `w` are purged together.
+ const fn granule_of(&self, w: usize) -> usize {
+ if self.is_coarse(w) { self.granule } else { 1 }
+ }
+
+ /// How long the chunks of word `w` wait before a purge, for a purge delay of `delay`.
+ const fn delay_of(&self, w: usize, delay: u64) -> u64 {
+ if self.coarse_parts != 0 && self.is_coarse(w) { delay * self.coarse_wait } else { delay }
}
/// The number of chunks tracked.
@@ -320,9 +366,11 @@ impl<'a> Chunks<'a> {
if self.dirty[w].load(Ordering::Relaxed) & valid == 0 {
continue;
}
- if now.saturating_sub(self.stamps[w].load(Ordering::Relaxed)) < delay {
+ if now.saturating_sub(self.stamps[w].load(Ordering::Relaxed)) < self.delay_of(w, delay)
+ {
let free = !self.used[w].load(Ordering::Relaxed) & valid;
- pending |= self.purgeable(free, self.dirty[w].load(Ordering::Relaxed), valid) != 0;
+ let dirty = self.dirty[w].load(Ordering::Relaxed);
+ pending |= self.purgeable(w, free, dirty, valid) != 0;
continue;
}
// Claim the free granules that hold a dirty chunk. A dirty chunk in use was reclaimed
@@ -330,7 +378,7 @@ impl<'a> Chunks<'a> {
let mut seen = self.used[w].load(Ordering::Relaxed);
let claimed = loop {
let want =
- self.purgeable(!seen & valid, self.dirty[w].load(Ordering::Relaxed), valid);
+ self.purgeable(w, !seen & valid, self.dirty[w].load(Ordering::Relaxed), valid);
if want == 0 {
break 0;
}
@@ -360,24 +408,48 @@ impl<'a> Chunks<'a> {
pending
}
- /// The chunks of a word that a purge would take: every granule that is entirely `free` and has
- /// a `dirty` chunk. A granule that runs past the end of the region counts its valid part.
- const fn purgeable(&self, free: u64, dirty: u64, valid: u64) -> u64 {
- if self.granule == 1 {
+ /// The chunks of word `w` that a purge would take: every granule that is entirely `free` and
+ /// has a `dirty` chunk. A granule that runs past the end of the region counts its valid part.
+ const fn purgeable(&self, w: usize, free: u64, dirty: u64, valid: u64) -> u64 {
+ let granule = self.granule_of(w);
+ if granule == 1 {
return dirty & free & valid;
}
let mut want = 0;
let mut offset = 0;
while offset < WORD {
- let mask = run_mask(self.granule, offset) & valid;
+ let mask = run_mask(granule, offset) & valid;
if mask != 0 && free & mask == mask && dirty & mask != 0 {
want |= mask;
}
- offset += self.granule;
+ offset += granule;
}
want
}
+ /// Whether the `n` chunks from `first`, which the caller has just claimed, read as zeros: none
+ /// was used since its pages were last given back, and, unless `purged_reads_zero`, none was
+ /// given back either. Chunks that were never used hold fresh pages, which are zero. Call this
+ /// before [`take_purged`](Self::take_purged), which forgets which chunks were purged.
+ pub(crate) fn is_clean(&self, first: usize, n: usize, purged_reads_zero: bool) -> bool {
+ let end = first + n;
+ let mut chunk = first;
+ while chunk < end {
+ let (word, offset) = (chunk / WORD, chunk % WORD);
+ let take = (WORD - offset).min(end - chunk);
+ let mask = run_mask(take, offset);
+ let mut used = self.dirty[word].load(Ordering::Relaxed);
+ if !purged_reads_zero {
+ used |= self.purged[word].load(Ordering::Relaxed);
+ }
+ if used & mask != 0 {
+ return false;
+ }
+ chunk += take;
+ }
+ true
+ }
+
/// Hands the purged runs among the `n` chunks from `first`, which the caller has just claimed,
/// to `visit`, and records that they are in use again. The caller makes the pages ready for
/// reuse where the system needs that.
@@ -537,10 +609,9 @@ const fn run_starts(free: u64, n: usize, align: usize) -> u64 {
#[cfg(all(test, not(loom)))]
mod test {
- use std::{vec, vec::Vec};
-
use super::*;
use crate::testing::{Bitmap, ChunkModel, Rng, iterations};
+ use std::{vec, vec::Vec};
#[test]
fn single_chunks_fill_the_bitmap_from_the_bottom() {
@@ -794,6 +865,68 @@ mod test {
chunks.purge_pass(200, 10, |run| purged.push(run));
assert_eq!(purged.first(), Some(&(0..32)));
}
+ #[test]
+ fn only_chunks_unused_since_their_last_purge_are_clean() {
+ let bitmap = Bitmap::new(128);
+ let chunks = bitmap.chunks();
+ let first = chunks.alloc(4, 4, 0).unwrap();
+ assert!(chunks.is_clean(first, 4, false), "never used");
+ chunks.free_at(first, 4, 0);
+ let again = chunks.alloc(4, 4, 0).unwrap();
+ assert_eq!(again, first);
+ assert!(!chunks.is_clean(first, 4, true), "used since it was fresh");
+ chunks.free_at(first, 4, 0);
+ chunks.purge_pass(100, 10, |_| ());
+ assert!(chunks.claim_at(first, 4));
+ assert!(chunks.is_clean(first, 4, true), "purged pages that read as zeros");
+ assert!(!chunks.is_clean(first, 4, false), "purged pages that may keep their contents");
+ chunks.take_purged(first, 4, |_| ());
+ }
+
+ #[test]
+ fn only_the_odd_parts_are_purged_in_huge_pages() {
+ // Four words in two parts, so the huge page granule applies from chunk 128 on.
+ let bitmap = Bitmap::with_granule(256, 32);
+ let chunks = bitmap.chunks().coarse_in_odd_parts(2, 1);
+ for first in [0, 128] {
+ assert!(chunks.claim_at(first, 2));
+ chunks.free_at(first + 1, 1, 0);
+ }
+ let mut purged = Vec::new();
+ chunks.purge_pass(100, 10, |run| purged.push(run));
+ assert_eq!(purged, vec![(1..2)], "small pages go one chunk at a time, huge pages whole");
+ }
+ #[test]
+ fn huge_pages_wait_longer_before_they_are_purged() {
+ let bitmap = Bitmap::with_granule(256, 32);
+ let chunks = bitmap.chunks().coarse_in_odd_parts(2, 10);
+ for first in [0, 128] {
+ assert!(chunks.claim_at(first, 32));
+ chunks.free_at(first, 32, 0);
+ }
+ let mut purged = Vec::new();
+ assert!(chunks.purge_pass(20, 10, |run| purged.push(run)), "the huge page still waits");
+ assert_eq!(purged, vec![(0..32)]);
+ purged.clear();
+ assert!(!chunks.purge_pass(100, 10, |run| purged.push(run)));
+ assert_eq!(purged, vec![(128..160)]);
+ }
+
+ #[test]
+ fn the_granule_of_a_word_follows_the_parts_of_the_region() {
+ for words in 1..40 {
+ for parts in (2..=8).step_by(2).filter(|&parts| parts <= words) {
+ let bitmap = Bitmap::with_granule(words * WORD, 32);
+ let chunks = bitmap.chunks().coarse_in_odd_parts(parts, 1);
+ for part in 0..parts {
+ for w in part * words / parts..(part + 1) * words / parts {
+ let want = if part % 2 == 1 { 32 } else { 1 };
+ assert_eq!(chunks.granule_of(w), want, "word {w} of {words} in {parts}");
+ }
+ }
+ }
+ }
+ }
#[test]
fn single_chunks_fill_the_fuller_huge_page_of_a_word_first() {
@@ -812,9 +945,8 @@ mod test {
#[cfg(all(test, loom))]
mod loom_test {
- use loom::{sync::Arc, thread};
-
use crate::testing::Bitmap;
+ use loom::{sync::Arc, thread};
/// Runs `claim` on two threads against one bitmap and returns what each got.
fn race(
diff --git a/crates/bcmalloc/src/config.rs b/crates/bcmalloc/src/config.rs
index 289f8eb..abbcab7 100644
--- a/crates/bcmalloc/src/config.rs
+++ b/crates/bcmalloc/src/config.rs
@@ -59,22 +59,21 @@ impl Config {
/// Sets how many threads can allocate at once.
///
- /// Each running thread holds one heap, and a thread that finds none free fails its allocations.
- /// This bounds concurrency the way TigerBeetle bounds connections, so choose it from the design
- /// of the program instead of guessing.
+ /// Each running thread holds one heap, and a thread that finds none free fails its allocations,
+ /// so set it to the most threads the program runs at once, with some room to spare.
#[must_use]
pub const fn max_heaps(mut self, heaps: usize) -> Self {
self.max_heaps = heaps;
self
}
- /// Asks Linux to back the region with transparent huge pages, which is the default there. Other
- /// platforms ignore it.
+ /// Asks Linux to back part of the region with transparent huge pages, which is the default
+ /// there. Other platforms ignore it.
///
/// Huge pages cut the cost of address translation for programs whose working set is larger
- /// than the TLB covers with small pages. Idle memory then goes back to the system one whole
- /// 2 MiB page at a time, so a region that is lightly used throughout holds more memory than it
- /// would with small pages.
+ /// than the TLB covers with small pages. Only heaps that have grown past a threshold, and
+ /// blocks of 2 MiB or more, take memory from them, and it goes back to the system one whole
+ /// 2 MiB page at a time.
#[must_use]
pub const fn huge_pages(mut self, enabled: bool) -> Self {
self.huge_pages = enabled;
diff --git a/crates/bcmalloc/src/global.rs b/crates/bcmalloc/src/global.rs
index 1fc838d..5115ca8 100644
--- a/crates/bcmalloc/src/global.rs
+++ b/crates/bcmalloc/src/global.rs
@@ -28,19 +28,19 @@
//! happens when the region is full, when the alignment is above [`MAX_ALIGN`](crate::MAX_ALIGN),
//! or when more threads are running than the configuration has heaps for.
-use core::{
- alloc::{AllocError, Allocator, GlobalAlloc, Layout},
- ptr::{self, NonNull},
-};
-
use crate::{
allocator::{Backend, allocator},
config::Config,
heap::{Heap, HeapData},
region::{Error, Mapping, Region, Stats},
+ size_class::{MIN_ALIGN, TABLE_MAX},
sync::{AtomicPtr, AtomicUsize, Ordering},
tls,
};
+use core::{
+ alloc::{AllocError, Allocator, GlobalAlloc, Layout},
+ ptr::{self, NonNull},
+};
/// The smallest region the lazy start-up settles for when the OS refuses a bigger one.
const MIN_CAPACITY: usize = 256 << 20;
@@ -124,6 +124,13 @@ impl Bcmalloc {
self.existing().map(Region::stats)
}
+ /// A snapshot of the allocator's metrics, or `None` if nothing has been allocated yet. See
+ /// [`Region::metrics`].
+ #[cfg(feature = "metrics")]
+ pub fn metrics(&self) -> Option {
+ self.existing().map(Region::metrics)
+ }
+
/// Returns the memory of idle heaps and free chunks to the operating system. See
/// [`Region::trim`] for what that costs.
pub fn trim(&self) {
@@ -143,6 +150,89 @@ impl Bcmalloc {
self.existing()?.block_layout(ptr.as_ptr())
}
+ /// Allocates `size` bytes aligned to 16, as C's `malloc` does, or returns null if there is no
+ /// room. A size of zero gets a block of its own.
+ #[inline]
+ pub fn malloc(&self, size: usize) -> *mut u8 {
+ if size <= TABLE_MAX &&
+ let Some(data) = self.thread_heap()
+ {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, and the table covers
+ // the size.
+ return unsafe { data.alloc_table(size, true) };
+ }
+ self.malloc_general(size)
+ }
+
+ /// Allocates what [`malloc`](Self::malloc) does not take on its fast path.
+ #[inline(never)]
+ fn malloc_general(&self, size: usize) -> *mut u8 {
+ Layout::from_size_align(size.max(1), MIN_ALIGN).map_or(ptr::null_mut(), |layout| {
+ // SAFETY: the layout has a non-zero size.
+ unsafe { GlobalAlloc::alloc(self, layout) }
+ })
+ }
+
+ /// How many bytes the block that `ptr` points to holds, as C's `malloc_usable_size` tells, or
+ /// `None` if `ptr` is not in this allocator's region. The answer is only meaningful when `ptr`
+ /// is the start of a live block from this allocator.
+ #[inline]
+ pub fn usable_size(&self, ptr: NonNull) -> Option {
+ self.thread_heap().map_or_else(
+ || self.block_layout(ptr).map(|layout| layout.size()),
+ |data| data.usable_size(ptr),
+ )
+ }
+
+ /// Resizes the block that `ptr` points to without its layout, as C's `realloc` does, keeping
+ /// an alignment of 16. Returns null, and leaves the block as it was, if there is no room or
+ /// the size is too large, or if `ptr` is not in this allocator's region.
+ ///
+ /// # Safety
+ ///
+ /// `ptr` must be the start of a live block from this allocator, and `new_size` must not be
+ /// zero.
+ pub unsafe fn realloc_unsized(&self, ptr: NonNull, new_size: usize) -> *mut u8 {
+ let Some(size) = self.usable_size(ptr) else { return ptr::null_mut() };
+ if Layout::from_size_align(new_size, MIN_ALIGN).is_err() {
+ return ptr::null_mut();
+ }
+ // SAFETY: the block holds `size` bytes at an alignment of at least 16, which is a layout it
+ // can be freed and resized with, and the new size is valid for that alignment.
+ unsafe {
+ let old = Layout::from_size_align_unchecked(size, MIN_ALIGN);
+ GlobalAlloc::realloc(self, ptr.as_ptr(), old, new_size)
+ }
+ }
+
+ /// Frees the block that `ptr` points to without its layout, as C's `free` does, and ignores
+ /// a pointer outside the region.
+ ///
+ /// # Safety
+ ///
+ /// A pointer inside the region must be the start of a live block from this allocator, and the
+ /// block must not be used again.
+ #[inline]
+ pub unsafe fn free_unsized(&self, ptr: NonNull) {
+ match self.thread_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, its region is this
+ // allocator's, and the caller vouches for the block.
+ Some(data) => unsafe { data.free_unsized(ptr) },
+ // SAFETY: the caller vouches for the block.
+ None => unsafe { self.free_unsized_unbound(ptr) },
+ }
+ }
+
+ /// Frees without a layout for a thread that has no heap yet.
+ #[cold]
+ #[inline(never)]
+ unsafe fn free_unsized_unbound(&self, ptr: NonNull) {
+ if let Some(layout) = self.block_layout(ptr) {
+ // SAFETY: the layout is the one the allocator holds for the block.
+ unsafe { self.dealloc_unbound(ptr, layout) };
+ }
+ }
+
/// Hands back the blocks that the calling thread's heap keeps for reuse: its bins, its
/// outboxes and what other threads sent it, and then its empty slabs.
///
@@ -150,10 +240,8 @@ impl Bcmalloc {
/// held while it sleeps, as jemalloc offers with its thread cache flush. Heaps of exited
/// threads are handed back on their own, and [`trim`](Self::trim) covers heaps nobody holds.
pub fn flush_thread(&self) {
- // SAFETY: a thread's bound heap is claimed by that thread alone, and so is its region.
- if let (Some(data), Some(region)) = (unsafe { self.bound_heap().as_ref() }, self.existing())
- {
- // SAFETY: as above.
+ if let (Some(data), Some(region)) = (self.bound_heap(), self.existing()) {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, and so is its region.
unsafe { data.flush(region) };
}
}
@@ -206,6 +294,11 @@ impl Backend for Bcmalloc {
unsafe { GlobalAlloc::alloc(self, layout) }
}
+ unsafe fn allocate_zeroed_raw(&self, layout: Layout) -> *mut u8 {
+ // SAFETY: forwarded.
+ unsafe { GlobalAlloc::alloc_zeroed(self, layout) }
+ }
+
unsafe fn deallocate_raw(&self, ptr: NonNull, layout: Layout) {
// SAFETY: forwarded.
unsafe { GlobalAlloc::dealloc(self, ptr.as_ptr(), layout) };
@@ -226,15 +319,15 @@ impl Default for Bcmalloc {
}
impl Bcmalloc {
- /// This thread's heap, or null if it has not bound one or the fast lookup cannot tell.
+ /// This thread's heap, or `None` if it has not bound one or the fast lookup cannot tell.
#[inline(always)]
- fn thread_heap(&self) -> *const HeapData {
+ fn thread_heap(&self) -> Option<&'static HeapData> {
tls::get(self.key.load(Ordering::Relaxed))
}
- /// This thread's heap, or null if it has not bound one. This is the slow lookup that settles
+ /// This thread's heap, or `None` if it has not bound one. This is the slow lookup that settles
/// what [`thread_heap`](Self::thread_heap) could not.
- fn bound_heap(&self) -> *const HeapData {
+ fn bound_heap(&self) -> Option<&'static HeapData> {
tls::lookup(self.key.load(Ordering::Relaxed))
}
@@ -287,9 +380,8 @@ impl Bcmalloc {
#[cold]
#[inline(never)]
unsafe fn alloc_unbound(&self, layout: Layout) -> *mut u8 {
- // SAFETY: a thread's bound heap is claimed by that thread alone.
- if let Some(data) = unsafe { self.bound_heap().as_ref() } {
- // SAFETY: as above.
+ if let Some(data) = self.bound_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone.
return unsafe { data.alloc(layout) };
}
let Some(region) = self.region() else { return ptr::null_mut() };
@@ -304,9 +396,9 @@ impl Bcmalloc {
#[cold]
#[inline(never)]
unsafe fn dealloc_unbound(&self, ptr: NonNull, layout: Layout) {
- // SAFETY: a thread's bound heap is claimed by that thread alone.
- if let Some(data) = unsafe { self.bound_heap().as_ref() } {
- // SAFETY: as above, and the caller vouches for the block.
+ if let Some(data) = self.bound_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, and the caller vouches
+ // for the block.
return unsafe { data.dealloc(ptr, layout) };
}
let Some(region) = self.existing() else { return };
@@ -324,9 +416,9 @@ impl Bcmalloc {
#[cold]
#[inline(never)]
unsafe fn realloc_unbound(&self, ptr: NonNull, layout: Layout, new_size: usize) -> *mut u8 {
- // SAFETY: a thread's bound heap is claimed by that thread alone.
- if let Some(data) = unsafe { self.bound_heap().as_ref() } {
- // SAFETY: as above, and the caller vouches for the block and the size.
+ if let Some(data) = self.bound_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, and the caller vouches
+ // for the block and the size.
return unsafe { data.realloc(ptr, layout, new_size) };
}
let Some(region) = self.existing() else { return ptr::null_mut() };
@@ -348,22 +440,36 @@ impl Bcmalloc {
unsafe impl GlobalAlloc for Bcmalloc {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
- // SAFETY: a thread's bound heap is claimed by that thread alone.
- if let Some(data) = unsafe { self.thread_heap().as_ref() } {
- // SAFETY: as above.
+ if let Some(data) = self.thread_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone.
return unsafe { data.alloc(layout) };
}
// SAFETY: forwarded.
unsafe { self.alloc_unbound(layout) }
}
+ #[inline]
+ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
+ if let Some(data) = self.thread_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone.
+ return unsafe { data.alloc_zeroed(layout) };
+ }
+ // SAFETY: forwarded.
+ let block = unsafe { self.alloc_unbound(layout) };
+ if !block.is_null() {
+ // SAFETY: the block holds the layout's size in bytes.
+ unsafe { block.write_bytes(0, layout.size()) };
+ }
+ block
+ }
+
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
// SAFETY: the caller guarantees the block is live, so it is not null.
let ptr = unsafe { NonNull::new_unchecked(ptr) };
- // SAFETY: a thread's bound heap is claimed by that thread alone.
- match unsafe { self.thread_heap().as_ref() } {
- // SAFETY: the caller guarantees the block came from this allocator with this layout.
+ match self.thread_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, and the caller
+ // guarantees the block came from this allocator with this layout.
Some(data) => unsafe { data.dealloc(ptr, layout) },
// SAFETY: as above.
None => unsafe { self.dealloc_unbound(ptr, layout) },
@@ -374,10 +480,10 @@ unsafe impl GlobalAlloc for Bcmalloc {
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
// SAFETY: the caller guarantees the block is live, so it is not null.
let ptr = unsafe { NonNull::new_unchecked(ptr) };
- // SAFETY: a thread's bound heap is claimed by that thread alone.
- if let Some(data) = unsafe { self.thread_heap().as_ref() } {
- // SAFETY: the caller guarantees the block is live with this layout and that the new
- // size is valid for the alignment.
+ if let Some(data) = self.thread_heap() {
+ // SAFETY: a thread's bound heap is claimed by that thread alone, and the caller
+ // guarantees the block is live with this layout and that the new size is valid for
+ // the alignment.
return unsafe { data.realloc(ptr, layout, new_size) };
}
// SAFETY: as above.
@@ -387,11 +493,10 @@ unsafe impl GlobalAlloc for Bcmalloc {
#[cfg(all(test, not(loom), not(miri)))]
mod test {
- use core::alloc::Layout;
- use std::{boxed::Box, vec::Vec};
-
use super::*;
use crate::config::Commit;
+ use core::alloc::Layout;
+ use std::{boxed::Box, vec::Vec};
/// An allocator over a small region, leaked so that it can be used as a static would be.
fn instance() -> &'static Bcmalloc {
@@ -451,6 +556,117 @@ mod test {
let outside = NonNull::from(&0_u64).cast::();
assert_eq!(allocator.block_layout(outside), None, "a pointer outside the region");
}
+ #[test]
+ fn frees_without_a_layout_return_everything_from_any_thread() {
+ let allocator = instance();
+ let sizes = [1, 100, 5000, 300_000, 3 << 20];
+ let blocks: Vec<_> = sizes
+ .iter()
+ .map(|&size| {
+ let layout = Layout::from_size_align(size, 16).unwrap();
+ // SAFETY: the layout has a non-zero size.
+ NonNull::new(unsafe { allocator.alloc(layout) }).unwrap().addr().get()
+ })
+ .collect();
+ let (mine, theirs) = blocks.split_at(2);
+ let theirs = theirs.to_vec();
+ // A fresh thread has no heap, so its first free takes the path that binds one.
+ std::thread::spawn(move || {
+ for &addr in &theirs {
+ // SAFETY: each block is live and freed once.
+ unsafe { allocator.free_unsized(NonNull::new(addr as *mut u8).unwrap()) };
+ }
+ })
+ .join()
+ .unwrap();
+ let mut outside = 0_u8;
+ // SAFETY: as above, and the last pointer is not in the region.
+ unsafe {
+ for &addr in mine {
+ allocator.free_unsized(NonNull::new(addr as *mut u8).unwrap());
+ }
+ allocator.free_unsized(NonNull::from(&mut outside));
+ }
+ allocator.flush_thread();
+ allocator.trim();
+ let stats = allocator.stats().unwrap();
+ assert_eq!(stats.free, stats.capacity, "every block went back");
+ }
+
+ #[test]
+ fn malloc_serves_every_size_aligned_and_refuses_impossible_ones() {
+ let allocator = instance();
+ let sizes = [0, 1, 15, 16, 17, 8191, 8192, 8193, 100_000, 600_000, 5 << 20];
+ let blocks: Vec<_> = sizes.iter().map(|&size| (allocator.malloc(size), size)).collect();
+ for &(block, size) in &blocks {
+ assert!(!block.is_null(), "{size} bytes");
+ assert!(block.addr().is_multiple_of(16), "{size} bytes are aligned to 16");
+ let held = allocator.block_layout(NonNull::new(block).unwrap()).unwrap();
+ assert!(held.size() >= size.max(1), "{size} bytes fit in the block");
+ // SAFETY: the block holds the size in bytes.
+ unsafe { block.write_bytes(0xa5, size) };
+ }
+ let distinct: std::collections::BTreeSet<_> = blocks.iter().map(|&(b, _)| b).collect();
+ assert_eq!(distinct.len(), blocks.len(), "a zero-sized request gets a block of its own");
+ assert!(allocator.malloc(usize::MAX).is_null());
+ assert!(allocator.malloc(usize::MAX / 2).is_null());
+ for (block, _) in blocks {
+ // SAFETY: each block is live and freed once.
+ unsafe { allocator.free_unsized(NonNull::new(block).unwrap()) };
+ }
+ }
+ #[test]
+ fn c_style_resizing_and_sizes_need_no_layout() {
+ let allocator = instance();
+ let block = NonNull::new(allocator.malloc(100)).unwrap();
+ assert_eq!(allocator.usable_size(block), Some(112));
+ // SAFETY: the block holds 100 bytes.
+ unsafe { block.as_ptr().write_bytes(7, 100) };
+ // SAFETY: the block is live and the sizes are not zero.
+ let same = unsafe { allocator.realloc_unsized(block, 60) };
+ assert_eq!(same, block.as_ptr(), "a block that still fits stays");
+ // SAFETY: as above.
+ let grown = NonNull::new(unsafe { allocator.realloc_unsized(block, 300_000) }).unwrap();
+ assert_ne!(grown, block);
+ // SAFETY: the grown block holds the first 60 bytes of the old one.
+ assert!(unsafe { core::slice::from_raw_parts(grown.as_ptr(), 60) }.iter().all(|&b| b == 7));
+ assert_eq!(allocator.usable_size(grown), Some(5 * (64 << 10)));
+ // SAFETY: as above.
+ assert!(unsafe { allocator.realloc_unsized(grown, usize::MAX) }.is_null());
+ let mut outside = 0_u8;
+ assert_eq!(allocator.usable_size(NonNull::from(&mut outside)), None);
+ // SAFETY: the block is live and freed once.
+ unsafe { allocator.free_unsized(grown) };
+ }
+ #[test]
+ fn a_thread_whose_first_call_resizes_or_zeroes_binds_a_heap() {
+ let allocator = instance();
+ let layout = Layout::from_size_align(100, 8).unwrap();
+ // SAFETY: the layout is not zero sized.
+ let block = unsafe { allocator.alloc(layout) }.addr();
+ std::thread::spawn(move || {
+ let block = ptr::with_exposed_provenance_mut::(block);
+ // SAFETY: the block is live with this layout, and the new size is valid.
+ let grown = unsafe { allocator.realloc(block, layout, 5000) };
+ assert!(!grown.is_null());
+ // SAFETY: the grown block is live with the new layout.
+ unsafe { allocator.dealloc(grown, Layout::from_size_align(5000, 8).unwrap()) };
+ })
+ .join()
+ .unwrap();
+ std::thread::spawn(move || {
+ let zeroed = Layout::from_size_align(3000, 16).unwrap();
+ // SAFETY: the layout is not zero sized.
+ let block = unsafe { allocator.alloc_zeroed(zeroed) };
+ // SAFETY: the block holds 3000 bytes.
+ assert!(unsafe { core::slice::from_raw_parts(block, 3000) }.iter().all(|&b| b == 0));
+ // SAFETY: the block is live with this layout.
+ unsafe { allocator.dealloc(block, zeroed) };
+ })
+ .join()
+ .unwrap();
+ assert_eq!(allocator.config().heap_count(), 4);
+ }
#[test]
fn flushing_a_thread_returns_what_its_heap_kept() {
diff --git a/crates/bcmalloc/src/heap.rs b/crates/bcmalloc/src/heap.rs
index cc0b664..93cf376 100644
--- a/crates/bcmalloc/src/heap.rs
+++ b/crates/bcmalloc/src/heap.rs
@@ -35,7 +35,7 @@
//! block's slab belongs to this heap comes from the chunk map, one load from a dense array.
//!
//! ```text
-//! +- own slab, or a class whose blocks share no cache line -> push on the bin
+//! +- own slab, or a small block that owns its cache lines -> push on the bin
//! free(ptr, layout) |
//! +- another heap's slab -> append to the outbox for that heap
//! |
@@ -44,10 +44,11 @@
//! ```
//!
//! A heap may keep a block of another heap's slab in its own bin and hand it out again, as
-//! jemalloc and TCMalloc do, but only for classes whose blocks never share a cache line with other
-//! blocks. Otherwise the reusing thread would write next to a block that the owner still uses,
-//! which is the false sharing that Hoard's rule of returning blocks to their owner prevents. Blocks
-//! of the other classes always go home.
+//! jemalloc and TCMalloc do, but only for classes of at most 256 bytes whose blocks never share a
+//! cache line with other blocks, and for messages. Otherwise the reusing thread would write next to
+//! a block that the owner still uses, which is the false sharing that Hoard's rule of returning
+//! blocks to their owner prevents, or pull across many lines that the owner still holds. Blocks of
+//! the other classes always go home.
//!
//! A bin that fills up gives its oldest half back: blocks of this heap's slabs go to the slab, and
//! the others go to their owners.
@@ -71,6 +72,15 @@
//! empties its bins and outboxes and is released with all its slabs intact, and the next thread to
//! start picks it up. Messages that arrive in between wait in its inbox.
+use crate::{
+ allocator::{Backend, allocator},
+ cache::CacheLine,
+ chunks::CHUNK_SHIFT,
+ region::{Entry, HUGE_PAGE_CHUNKS, Region},
+ size_class::{CLASSES, Class, MAX_SMALL, Request, STEP, TABLE_MAX, TABLE_STEPS, classify},
+ slab::{Block, List, Owned, Returns, Slab},
+ sync::{AtomicBool, AtomicPtr, AtomicU64, Ordering},
+};
use core::{
alloc::{AllocError, Allocator, Layout},
cell::Cell,
@@ -80,16 +90,6 @@ use core::{
ptr::NonNull,
};
-use crate::{
- allocator::{Backend, allocator},
- cache::CacheLine,
- chunks::CHUNK_SHIFT,
- region::{Entry, Region},
- size_class::{CLASSES, Class, MAX_SMALL, Request, classify},
- slab::{Block, List, Owned, Returns, Slab},
- sync::{AtomicBool, AtomicPtr, AtomicU64, Ordering},
-};
-
/// The tag on an inbox link that marks a node as a single block and not a message.
const SINGLE: usize = 0b1;
@@ -124,6 +124,49 @@ const HUGE_CACHE: usize = 4;
const HUGE_CACHE_BLOCK: usize = 8 << 20;
const HUGE_CACHE_BYTES: usize = 16 << 20;
+/// Counts a slow-path event of the heap when metrics are compiled in.
+macro_rules! count {
+ ($heap:expr, $event:ident, $n:expr) => {
+ #[cfg(feature = "metrics")]
+ $heap.private.events.add(crate::metrics::Event::$event, $n as u64);
+ };
+}
+
+/// The smallest block for which a zeroed request asks whether the memory is fresh. Clearing a
+/// smaller block costs less than the slab lookup that would find out.
+const ZERO_CHECK_MIN: usize = 1024;
+
+/// Whether a heap may keep and reuse blocks of `class` that another heap owns. See
+/// [`Class::reusable_anywhere`]. Messages qualify too, whatever their size: the heap that reads
+/// one has its lines in its cache already, and reuses it for messages of its own.
+const fn reusable_anywhere(class: Class) -> bool {
+ class.reusable_anywhere() || class.index() == MESSAGE_CLASS.index()
+}
+
+/// How many blocks a bin that overflows gives back at a time, from a buffer on the stack.
+const FLUSH_BATCH: usize = 512;
+
+/// The size of a bin, which [`Entry`] uses to keep the offset of a class's bin.
+pub(crate) const BIN_SIZE: usize = size_of::();
+
+/// For every size that the class table covers, in steps of [`STEP`], the byte offset of the
+/// bin of its class in a heap's array of bins. The allocation fast path finds its bin with one load
+/// where looking the class up and then the bin would take a load and a multiplication.
+const BIN_OFFSETS: [u16; TABLE_STEPS] = {
+ let mut offsets = [0; TABLE_STEPS];
+ let mut step = 0;
+ while step < offsets.len() {
+ offsets[step] = (Class::from_table(step * STEP).index() * size_of::()) as u16;
+ step += 1;
+ }
+ offsets
+};
+
+/// How many chunks of filled slabs a heap holds before its chunks come from the zone of
+/// transparent huge pages, 1 MiB. See [`Region::part`]. Below it are the threads that use a
+/// little memory each, whose huge pages would be mostly empty.
+const HUGE_ZONE_CHUNKS: usize = 16;
+
/// The last miss of a bin was a refill of an empty bin.
const UNDERFLOW: u8 = 0b01;
@@ -151,7 +194,7 @@ const _: () = assert!(MESSAGE_CLASS.block_size() == MESSAGE_BYTES);
///
/// The stack lives in the heap's slot array and grows down. It is empty when `top` is at the end of
/// its range and full when it is at the start. Both ends fit in 16 bits of address, because a bin
-/// is at most 1 KiB long, so the checks compare the low bits of `top` only and the bin fits in one
+/// is at most 16 KiB long, so the checks compare the low bits of `top` only and the bin fits in one
/// load of 16 bytes.
struct Bin {
top: Cell<*mut *mut Block>,
@@ -163,6 +206,11 @@ struct Bin {
misses: Cell,
/// Whether this bin may hold blocks of other heaps' slabs.
anywhere: Cell,
+ /// Blocks of the class this heap has handed out and freed, on the bin's line.
+ #[cfg(feature = "metrics")]
+ allocs: crate::metrics::Counter,
+ #[cfg(feature = "metrics")]
+ frees: crate::metrics::Counter,
}
/// Blocks of other heaps' slabs that this heap has freed and not posted yet, all for one heap.
@@ -192,6 +240,11 @@ struct Lists {
active: Cell<*const Slab>,
active_last: Cell<*const Slab>,
full: Cell<*const Slab>,
+ /// How many of the class's slabs that the heap holds have been filled once.
+ filled: Cell,
+ /// How many slabs of the class the heap holds.
+ #[cfg(feature = "metrics")]
+ slabs: crate::metrics::Counter,
}
/// What other threads touch in a heap slot, kept on a line of its own.
@@ -216,6 +269,9 @@ struct Private {
/// slot was claimed from, so that the fast paths reach them without loading the region. They
/// are set at every claim and valid while the claim lasts.
base: Cell<*mut u8>,
+ /// The length of the managed memory in bytes, so that a free without a layout can tell a block
+ /// of the region from any other pointer.
+ span: Cell,
map: Cell<*const AtomicU64>,
slabs: Cell<*const Slab>,
region: Cell<*const Region<'static>>,
@@ -223,12 +279,23 @@ struct Private {
/// where single-chunk searches start.
node: Cell,
cursor: Cell,
+ /// How many chunks this heap's slabs that have been filled once take up, which decides whether
+ /// its chunks come from the zone of transparent huge pages. A slab that was never filled may
+ /// have most of its pages untouched, so counting it would move heaps that are small in memory.
+ held: Cell,
+ /// How many chunks the blocks of whole chunks that this heap handed out and did not free take
+ /// up. It counts towards the size of the heap as `held` does.
+ runs: Cell,
+ /// Whether the heap counted as big the last time it was asked. See [`HeapData::is_big`].
+ big: Cell,
bins: [Bin; CLASSES],
/// This heap's bin slots in the region, set at every claim.
slots: Cell<*mut *mut Block>,
outboxes: [Outbox; OUTBOXES],
kept: [Cell; HUGE_CACHE],
classes: [Lists; CLASSES],
+ #[cfg(feature = "metrics")]
+ events: crate::metrics::HeapEvents,
}
/// The state of one heap slot in a region.
@@ -271,11 +338,15 @@ impl HeapData {
draining: Cell::new(false),
grown: Cell::new(0),
base: Cell::new(ptr::null_mut()),
+ span: Cell::new(0),
map: Cell::new(ptr::null()),
slabs: Cell::new(ptr::null()),
region: Cell::new(ptr::null()),
node: Cell::new(0),
cursor: Cell::new(0),
+ held: Cell::new(0),
+ runs: Cell::new(0),
+ big: Cell::new(false),
bins: [const {
Bin {
top: Cell::new(ptr::null_mut()),
@@ -284,6 +355,10 @@ impl HeapData {
capacity: Cell::new(0),
misses: Cell::new(0),
anywhere: Cell::new(false),
+ #[cfg(feature = "metrics")]
+ allocs: crate::metrics::Counter::new(),
+ #[cfg(feature = "metrics")]
+ frees: crate::metrics::Counter::new(),
}
}; CLASSES],
slots: Cell::new(ptr::null_mut()),
@@ -300,12 +375,30 @@ impl HeapData {
active: Cell::new(ptr::null()),
active_last: Cell::new(ptr::null()),
full: Cell::new(ptr::null()),
+ filled: Cell::new(0),
+ #[cfg(feature = "metrics")]
+ slabs: crate::metrics::Counter::new(),
}
}; CLASSES],
+ #[cfg(feature = "metrics")]
+ events: crate::metrics::HeapEvents::new(),
},
}
}
+ /// The allocations, frees and slabs this heap slot has counted for `class`.
+ #[cfg(feature = "metrics")]
+ pub(crate) fn class_counts(&self, class: Class) -> (u64, u64, u64) {
+ let bin = self.bin(class);
+ (bin.allocs.get(), bin.frees.get(), self.lists(class).slabs.get())
+ }
+
+ /// The slow-path counts of this heap slot.
+ #[cfg(feature = "metrics")]
+ pub(crate) const fn events(&self) -> &crate::metrics::HeapEvents {
+ &self.private.events
+ }
+
/// Tries to claim this slot as heap number `id` of the region.
pub(crate) fn claim(&self, id: u32, region: &Region<'_>) -> bool {
let won = !self.shared.claimed.load(Ordering::Relaxed) &&
@@ -318,6 +411,7 @@ impl HeapData {
private.id.set(id);
private.region.set(ptr::from_ref(region).cast());
private.base.set(region.chunk_ptr(0));
+ private.span.set(region.span());
private.slabs.set(region.slabs_ptr());
private.map.set(region.map_ptr());
private.slots.set(region.bin_slots(id));
@@ -329,13 +423,37 @@ impl HeapData {
/// Makes the heap take its chunks from the part of the region of NUMA node `node`.
fn settle_on(&self, region: &Region<'_>, node: usize) {
- let home = region.home(node);
self.private.node.set(node);
+ let home = region.home(self.slab_part(region, Class::from_index(0)));
if !home.contains(&self.private.cursor.get()) {
self.private.cursor.set(home.start);
}
}
+ /// Whether the heap holds enough memory that its chunks come from the zone of transparent huge
+ /// pages. See [`HUGE_ZONE_CHUNKS`]. A heap that became big stays big until it holds less than
+ /// a quarter of that, so that a heap whose size swings around the threshold does not leave
+ /// its new slabs on small pages half of the time.
+ fn is_big(&self) -> bool {
+ let size = self.private.held.get() + self.private.runs.get();
+ let low = if self.private.big.get() { HUGE_ZONE_CHUNKS / 4 } else { HUGE_ZONE_CHUNKS };
+ let big = size >= low;
+ self.private.big.set(big);
+ big
+ }
+
+ /// The part of the region the next slab of `class` comes from. See [`Region::part`].
+ ///
+ /// Slabs of a big heap go to the zone of transparent huge pages when they will be dense. A
+ /// single-chunk slab fills quickly and packs next to others. A slab of several chunks holds
+ /// few blocks and may stay mostly untouched, where a huge page fault would back all of it, so
+ /// it goes there only once the heap holds a slab of its class that it has filled.
+ fn slab_part(&self, region: &Region<'_>, class: Class) -> usize {
+ let dense = class.slab_chunks() == 1 || self.lists(class).filled.get() > 0;
+ let huge = dense && self.is_big();
+ region.part(self.private.node.get(), huge)
+ }
+
/// Points every bin at its range of the slot array, empty and at its initial capacity. A slot
/// that was claimed before has empty bins at the same place.
fn init_bins(&self) {
@@ -348,7 +466,7 @@ impl HeapData {
debug_assert_eq!(bin.top.get(), end, "a released heap left blocks in a bin");
bin.empty.set(end.addr() as u16);
bin.misses.set(0);
- bin.anywhere.set(class.reusable_anywhere());
+ bin.anywhere.set(reusable_anywhere(class));
self.set_capacity(class, class.bin_initial());
}
self.private.grown.set(0);
@@ -362,7 +480,8 @@ impl HeapData {
/// Sets how many blocks the bin of `class` may hold. It must hold no more than that already.
fn set_capacity(&self, class: Class, capacity: usize) {
let bin = self.bin(class);
- debug_assert!(self.bin_len(class) <= capacity && capacity <= class.bin_max());
+ // A bin that held more than its capacity would let pushes run past its start.
+ assert!(self.bin_len(class) <= capacity && capacity <= class.bin_max());
bin.capacity.set(capacity as u16);
bin.full.set(self.bin_end(class).wrapping_sub(capacity).addr() as u16);
}
@@ -385,6 +504,7 @@ impl HeapData {
}
self.private.grown.set(self.private.grown.get() + bytes);
self.set_capacity(class, grown);
+ count!(self, BinsGrown, 1);
true
}
@@ -492,20 +612,37 @@ impl HeapData {
/// Pops a block off the bin of `class`.
#[inline(always)]
fn pop(&self, class: Class) -> Option<*mut Block> {
- let bin = self.bin(class);
+ Self::pop_from(self.bin(class))
+ }
+
+ /// Pops a block off `bin`.
+ #[inline(always)]
+ fn pop_from(bin: &Bin) -> Option<*mut Block> {
let top = bin.top.get();
if top.addr() as u16 == bin.empty.get() {
return None;
}
bin.top.set(top.wrapping_add(1));
- // SAFETY: slots between the top and the end of a bin hold blocks.
- Some(unsafe { *top })
+ #[cfg(feature = "metrics")]
+ bin.allocs.add(1);
+ // SAFETY: slots between the top and the end of a bin hold blocks, which are never null.
+ // Saying so lets callers that turn the block into a nullable pointer skip a check.
+ unsafe {
+ let block = *top;
+ core::hint::assert_unchecked(!block.is_null());
+ Some(block)
+ }
}
/// Pushes a block onto the bin of `class`, or returns false if the bin is full.
#[inline(always)]
fn push(&self, class: Class, block: *mut Block) -> bool {
- let bin = self.bin(class);
+ Self::push_to(self.bin(class), block)
+ }
+
+ /// Pushes a block onto `bin`, or returns false if the bin is full.
+ #[inline(always)]
+ fn push_to(bin: &Bin, block: *mut Block) -> bool {
let top = bin.top.get();
if top.addr() as u16 == bin.full.get() {
return false;
@@ -532,16 +669,35 @@ impl HeapData {
#[inline(always)]
pub(crate) unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
if Class::is_table_request(layout) {
- let class = Class::from_table(layout.size());
- if let Some(block) = self.pop(class) {
- return block.cast();
- }
- // SAFETY: forwarded.
- return unsafe { self.refill(class) }.cast();
+ // SAFETY: forwarded, and the table covers the size.
+ return unsafe { self.alloc_table(layout.size(), layout.align() > STEP) };
}
// SAFETY: forwarded.
unsafe { self.alloc_general(layout) }
}
+ /// Allocates `size` bytes for a size the class table covers, zero included, aligned to 16 if
+ /// `wide` and to 8 otherwise. A wide request rounds the size up to a multiple of 16, whose
+ /// class's blocks are 16-byte aligned.
+ ///
+ /// # Safety
+ ///
+ /// The caller must hold the claim on this slot, and `size` must be at most [`TABLE_MAX`].
+ #[inline(always)]
+ pub(crate) unsafe fn alloc_table(&self, size: usize, wide: bool) -> *mut u8 {
+ debug_assert!(size <= TABLE_MAX);
+ let step = if wide { size.div_ceil(2 * STEP) * 2 } else { size.div_ceil(STEP) };
+ // SAFETY: the size is at most `TABLE_MAX`, a multiple of 16, so its step is in the table,
+ // and every offset in it is that of a bin in the array.
+ let bin = unsafe {
+ let offset = *BIN_OFFSETS.get_unchecked(step);
+ &*self.private.bins.as_ptr().byte_add(usize::from(offset))
+ };
+ if let Some(block) = Self::pop_from(bin) {
+ return block.cast();
+ }
+ // SAFETY: forwarded.
+ unsafe { self.refill(Class::from_table(step * STEP)) }.cast()
+ }
/// Allocates anything that the fast path in [`HeapData::alloc`] does not take.
///
@@ -582,6 +738,7 @@ impl HeapData {
#[cold]
#[inline(never)]
unsafe fn refill(&self, class: Class) -> *mut Block {
+ count!(self, Refills, 1);
// SAFETY: the claim keeps the region alive.
let region = unsafe { self.region() };
// SAFETY: the caller holds the claim.
@@ -640,9 +797,11 @@ impl HeapData {
if bin.misses.get() & MISSED == 0 && capacity > class.bin_initial() {
// A bin that has not missed for a while holds more than it needs.
let shrunk = (capacity / 2).max(class.bin_initial());
- // SAFETY: forwarded.
+ // SAFETY: forwarded. The bin holds no more than the new capacity afterwards,
+ // even when giving blocks back filed mail into it.
unsafe { self.flush_bin(class, shrunk) };
self.set_capacity(class, shrunk);
+ count!(self, BinsShrunk, 1);
let bytes = (capacity - shrunk) * class.block_size();
self.private.grown.set(self.private.grown.get() - bytes);
}
@@ -680,9 +839,7 @@ impl HeapData {
unsafe { *slot = block.cast() };
slot = slot.wrapping_add(1);
});
- if slab.is_exhausted() {
- self.move_to(slab, List::Full);
- }
+ self.after_take(slab, class);
}
let top = end.wrapping_sub(got);
if got < want {
@@ -697,23 +854,142 @@ impl HeapData {
/// active list. Returns false if the region has no room.
unsafe fn add_slab(&self, region: &Region<'_>, class: Class) -> bool {
let chunks = class.slab_chunks();
- let (cursor, node) = (self.private.cursor.get(), self.private.node.get());
- let Some(first) = region.alloc_chunks(chunks, chunks, cursor, node) else {
+ let part = self.slab_part(region, class);
+ let home = region.home(part);
+ let cursor = self.private.cursor.get();
+ let cursor = if home.contains(&cursor) { cursor } else { home.start };
+ let Some((first, zeroed)) = region.alloc_chunks_zeroed(chunks, chunks, cursor, part) else {
return false;
};
+ count!(self, SlabsAdded, 1);
+ #[cfg(feature = "metrics")]
+ self.lists(class).slabs.add(1);
region.set_owner(first, chunks, self.private.id.get(), class);
let slab = region.slab(first);
// SAFETY: the chunks were just allocated to us, so nobody else uses this descriptor.
let owned = unsafe { slab.owned() };
// SAFETY: the chunks are a slab-sized, slab-aligned run that is ours alone.
- unsafe { owned.init(class, region.chunk_ptr(first)) };
+ unsafe { owned.init(class, region.chunk_ptr(first), zeroed) };
self.push_front(owned, List::Active);
- if chunks == 1 && region.home(node).contains(&(first / 64)) {
+ if chunks == 1 && home.contains(&(first / 64)) {
self.private.cursor.set(first / 64);
}
true
}
+ /// Moves a slab that blocks were just taken from to the full list if it has none left.
+ fn after_take(&self, slab: Owned<'_>, class: Class) {
+ if slab.is_exhausted() {
+ self.move_to(slab, List::Full);
+ if slab.mark_filled() {
+ self.private.held.set(self.private.held.get() + class.slab_chunks());
+ let filled = &self.lists(class).filled;
+ filled.set(filled.get() + 1);
+ }
+ }
+ }
+
+ /// Allocates zeroed memory for the layout, returning null if the region is out of room or the
+ /// layout is not supported.
+ ///
+ /// Fresh memory already reads as zeros, so it is not written again, as mimalloc and jemalloc
+ /// skip zeroing pages they know are fresh. A huge block knows from the chunk bitmap. A block
+ /// of a slab is fresh if the slab was set up on zeroed memory and the block lies beyond every
+ /// block the slab has handed out. Blocks in a bin may have been used, so a request that a bin
+ /// can serve takes the block from the bin and clears it, while it is likely still in the cache.
+ /// When the bin is empty the block comes straight from a slab instead, where it may be fresh.
+ /// Small blocks are cleared without asking, which costs less than finding out.
+ ///
+ /// # Safety
+ ///
+ /// The caller must hold the claim on this slot.
+ pub(crate) unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
+ let size = layout.size();
+ match classify(layout) {
+ Some(Request::Small(class)) if class.block_size() >= ZERO_CHECK_MIN => {
+ let (block, zeroed) = self.pop(class).map_or_else(
+ // SAFETY: forwarded.
+ || unsafe { self.take_zeroed(class) },
+ |block| (block.cast::(), false),
+ );
+ if !block.is_null() && !zeroed {
+ // SAFETY: the block holds at least `size` bytes and is ours.
+ unsafe { block.write_bytes(0, size) };
+ }
+ block
+ }
+ Some(Request::Huge { chunks }) => {
+ // SAFETY: the claim keeps the region alive.
+ let region = unsafe { self.region() };
+ let (mut block, mut zeroed) = self.alloc_huge_zeroed(region, chunks);
+ if block.is_null() {
+ // SAFETY: the caller holds the claim.
+ unsafe { self.flush(region) };
+ (block, zeroed) = self.alloc_huge_zeroed(region, chunks);
+ }
+ if !block.is_null() && !zeroed {
+ // SAFETY: as above.
+ unsafe { block.write_bytes(0, size) };
+ }
+ block
+ }
+ _ => {
+ // SAFETY: forwarded.
+ let block = unsafe { self.alloc(layout) };
+ if !block.is_null() {
+ // SAFETY: as above.
+ unsafe { block.write_bytes(0, size) };
+ }
+ block
+ }
+ }
+ }
+
+ /// Takes one block of `class` straight from a slab for a zeroed request whose bin is empty,
+ /// and tells whether it still holds the zeros of fresh memory. Falls back to an ordinary
+ /// refill when the inbox has blocks to take in first.
+ ///
+ /// # Safety
+ ///
+ /// The caller must hold the claim.
+ #[cold]
+ unsafe fn take_zeroed(&self, class: Class) -> (*mut u8, bool) {
+ // SAFETY: the claim keeps the region alive.
+ let region = unsafe { self.region() };
+ if self.has_mail() {
+ // SAFETY: the caller holds the claim.
+ return (unsafe { self.refill(class) }.cast(), false);
+ }
+ // SAFETY: as above.
+ unsafe { self.maintain(region) };
+ if let Some(block) = self.pop(class) {
+ return (block.cast(), false);
+ }
+ loop {
+ // SAFETY: slabs on our lists are ours.
+ if let Some(slab) = unsafe { self.lists(class).active.get().as_ref() } {
+ // SAFETY: as above.
+ let slab = unsafe { slab.owned() };
+ if let Some((block, zeroed)) = slab.take_one() {
+ self.after_take(slab, class);
+ #[cfg(feature = "metrics")]
+ {
+ self.bin(class).allocs.add(1);
+ if zeroed {
+ count!(self, ZeroedFresh, 1);
+ }
+ }
+ return (block, zeroed);
+ }
+ }
+ // SAFETY: as above.
+ if !unsafe { self.add_slab(region, class) } {
+ // SAFETY: as above.
+ return (unsafe { self.refill(class) }.cast(), false);
+ }
+ }
+ }
+
/// Resizes a block, returning null and leaving the block untouched if there is no room.
///
/// # Safety
@@ -740,6 +1016,7 @@ impl HeapData {
let first = region.chunk_index(ptr.as_ptr());
if wants <= had {
if wants < had {
+ count!(self, HugeBytesFreed, (had - wants) << CHUNK_SHIFT);
region.set_huge(first, wants);
region.free_chunks(first + wants, had - wants);
region.purge_if_due();
@@ -747,6 +1024,7 @@ impl HeapData {
return ptr.as_ptr();
}
if region.grow_in_place(first, had, wants) {
+ count!(self, HugeBytesAllocated, (wants - had) << CHUNK_SHIFT);
region.set_huge(first, wants);
return ptr.as_ptr();
}
@@ -800,6 +1078,9 @@ impl HeapData {
return unsafe { region.dealloc(ptr, layout) };
};
let bytes = chunks << CHUNK_SHIFT;
+ self.private.runs.set(self.private.runs.get().saturating_sub(chunks));
+ count!(self, HugeFrees, 1);
+ count!(self, HugeBytesFreed, bytes);
if bytes <= HUGE_CACHE_BLOCK {
let held: usize =
self.private.kept.iter().map(|kept| kept.get().chunks << CHUNK_SHIFT).sum();
@@ -814,8 +1095,8 @@ impl HeapData {
return;
}
}
- // SAFETY: forwarded.
- unsafe { region.dealloc(ptr, layout) };
+ region.free_chunks(region.chunk_index(ptr.as_ptr()), chunks);
+ region.purge_if_due();
}
/// Frees a block of a slab. Its class and its owner both come from one load of the chunk map,
@@ -827,18 +1108,68 @@ impl HeapData {
/// As for [`dealloc`](Self::dealloc).
#[inline(always)]
unsafe fn free_small(&self, block: *mut Block) {
- let entry = self.entry_of(block.cast());
- let class = entry.class();
+ // SAFETY: forwarded.
+ unsafe { self.free_entry(block, self.entry_of(block.cast())) };
+ }
+
+ /// Frees a block without its layout, as C's `free` does, and ignores a pointer outside the
+ /// region. The chunk map tells a slab's block from a huge one, so this takes one load of the
+ /// map where looking the layout up first and then freeing would take two.
+ ///
+ /// # Safety
+ ///
+ /// The caller must hold the claim on this slot, and a pointer inside the region must be the
+ /// start of a live block that is not used again.
+ #[inline(always)]
+ pub(crate) unsafe fn free_unsized(&self, ptr: NonNull) {
+ let Some(entry) = self.entry_in_region(ptr.as_ptr()) else { return };
+ if let Some(chunks) = entry.huge_chunks() {
+ // SAFETY: a huge block of `chunks` chunks has this layout, and the caller gives it up.
+ return unsafe {
+ self.free_huge(ptr, Layout::from_size_align_unchecked(chunks << CHUNK_SHIFT, 16))
+ };
+ }
+ // SAFETY: the caller gives up a block of a slab.
+ unsafe { self.free_entry(ptr.as_ptr().cast(), entry) };
+ }
+
+ /// The chunk map entry of the chunk that holds `ptr`, or `None` if `ptr` is not in the region.
+ #[inline(always)]
+ fn entry_in_region(&self, ptr: *const u8) -> Option {
+ let offset = ptr.addr().wrapping_sub(self.private.base.get().addr());
+ (offset < self.private.span.get()).then(|| self.entry_of(ptr))
+ }
+
+ /// How many bytes the block at `ptr` holds, or `None` if `ptr` is not in the region. The
+ /// answer is only meaningful for the start of a live block.
+ #[cfg(all(feature = "std", not(loom)))]
+ #[inline(always)]
+ pub(crate) fn usable_size(&self, ptr: NonNull) -> Option {
+ let entry = self.entry_in_region(ptr.as_ptr())?;
+ Some(entry.huge_chunks().map_or_else(|| entry.class().block_size(), |n| n << CHUNK_SHIFT))
+ }
+
+ /// Frees a block of a slab whose chunk map entry is `entry`.
+ ///
+ /// # Safety
+ ///
+ /// As for [`dealloc`](Self::dealloc), and `entry` must be the entry of the block's chunk.
+ #[inline(always)]
+ unsafe fn free_entry(&self, block: *mut Block, entry: Entry) {
+ // SAFETY: entries hold the offset of a bin in the array.
+ let bin = unsafe { &*self.private.bins.as_ptr().byte_add(entry.bin_offset()) };
+ #[cfg(feature = "metrics")]
+ bin.frees.add(1);
// Testing the owner first keeps the common case, a block of this heap, on one branch that
// predicts well. Whether the class allows reuse depends on the size, which is as random as
// the program's requests.
- if entry.owner() != self.private.id.get() && !self.bin(class).anywhere.get() {
+ if entry.owner() != self.private.id.get() && !bin.anywhere.get() {
// SAFETY: forwarded.
- return unsafe { self.send(block, class, entry.owner()) };
+ return unsafe { self.send(block, entry.class(), entry.owner()) };
}
- if !self.push(class, block) {
+ if !Self::push_to(bin, block) {
// SAFETY: forwarded.
- unsafe { self.free_full(block, class) };
+ unsafe { self.free_full(block, entry.class()) };
}
}
@@ -881,19 +1212,25 @@ impl HeapData {
if len <= keep {
return;
}
- let gone = len - keep;
// The oldest blocks are at the end of the bin. Move them out first and the rest down, so
- // that the bin is consistent if giving the blocks back allocates or frees again.
- let mut out = [ptr::null_mut::(); 512];
- let top = bin.top.get();
- // SAFETY: the bin holds `len` blocks from `top`, and `out` holds a bin's capacity.
- unsafe {
- ptr::copy_nonoverlapping(top.add(keep), out.as_mut_ptr(), gone);
- ptr::copy(top, top.add(gone), keep);
+ // that the bin is consistent if giving the blocks back allocates or frees again. A bin
+ // can be longer than the buffer, so this goes a buffer at a time.
+ let mut out = [ptr::null_mut::(); FLUSH_BATCH];
+ let mut len = len;
+ while len > keep {
+ let gone = (len - keep).min(FLUSH_BATCH);
+ let top = bin.top.get();
+ // SAFETY: the bin holds `len` blocks from `top`, and `out` holds `gone` of them.
+ unsafe {
+ ptr::copy_nonoverlapping(top.add(len - gone), out.as_mut_ptr(), gone);
+ ptr::copy(top, top.add(gone), len - gone);
+ }
+ bin.top.set(top.wrapping_add(gone));
+ // SAFETY: the blocks were in the bin, so they are in use and ours to give back.
+ unsafe { self.give_back(region, class, &out[..gone], false) };
+ // Giving back may have filed blocks from the inbox into this bin.
+ len = self.bin_len(class);
}
- bin.top.set(top.wrapping_add(gone));
- // SAFETY: the blocks were in the bin, so they are in use and ours to give back.
- unsafe { self.give_back(region, class, &out[..gone], false) };
}
/// Gives blocks of `class` that this heap holds back: blocks of its own slabs to the slab, and
@@ -986,6 +1323,7 @@ impl HeapData {
#[cold]
#[inline(never)]
unsafe fn send(&self, block: *mut Block, class: Class, owner: u32) {
+ count!(self, BlocksSent, 1);
// SAFETY: the claim keeps the region alive.
let region = unsafe { self.region() };
let size = class.block_size();
@@ -1058,6 +1396,7 @@ impl HeapData {
}
}
_ => {
+ count!(self, MessagesPosted, 1);
outbox.message.set(ptr::null_mut());
// SAFETY: the message is a block of ours, given up here.
unsafe { dest.post(message.cast(), message.cast()) };
@@ -1103,6 +1442,9 @@ impl HeapData {
/// The caller must hold the claim.
unsafe fn drain_inbox(&self, region: &Region<'_>) {
let mut node = self.shared.inbox.swap(ptr::null_mut(), Ordering::Acquire);
+ if !node.is_null() {
+ count!(self, MailReads, 1);
+ }
while !node.is_null() {
let raw = node.map_addr(|addr| addr & !SINGLE);
// SAFETY: inbox nodes are blocks given to us, linked through their first words, and the
@@ -1132,6 +1474,7 @@ impl HeapData {
/// The caller must hold the claim, and the block must be an in-use block of one of this heap's
/// slabs, which is given up.
unsafe fn file(&self, region: &Region<'_>, block: *mut Block) {
+ count!(self, BlocksFiled, 1);
let entry = self.entry_of(block.cast());
debug_assert_eq!(
entry.owner(),
@@ -1197,12 +1540,21 @@ impl HeapData {
/// Returns an empty slab's chunks to the chunk allocator.
fn release(&self, region: &Region<'_>, slab: Owned<'_>) {
self.unlink(slab);
+ count!(self, SlabsReleased, 1);
+ #[cfg(feature = "metrics")]
+ self.lists(slab.class()).slabs.sub(1);
let first = region.chunk_index(slab.start());
- region.free_chunks(first, slab.class().slab_chunks());
+ let chunks = slab.class().slab_chunks();
+ if slab.was_filled() {
+ self.private.held.set(self.private.held.get().saturating_sub(chunks));
+ let filled = &self.lists(slab.class()).filled;
+ filled.set(filled.get().saturating_sub(1));
+ }
+ region.free_chunks(first, chunks);
region.purge_if_due();
// Prefer the lowest free word of the home part next time, so slabs stay packed towards the
// bottom of it.
- if region.home(self.private.node.get()).contains(&(first / 64)) {
+ if region.home(self.slab_part(region, Class::from_index(0))).contains(&(first / 64)) {
self.private.cursor.set(self.private.cursor.get().min(first / 64));
}
}
@@ -1234,20 +1586,44 @@ impl HeapData {
/// Allocates a run of `chunks` whole chunks, returning null if there is no room.
pub(crate) fn alloc_huge(&self, region: &Region<'_>, chunks: usize) -> *mut u8 {
+ self.alloc_huge_zeroed(region, chunks).0
+ }
+
+ /// As [`alloc_huge`](Self::alloc_huge), and also tells whether the block reads as zeros.
+ fn alloc_huge_zeroed(&self, region: &Region<'_>, chunks: usize) -> (*mut u8, bool) {
for kept in &self.private.kept {
let block = kept.get();
if block.chunks == chunks {
kept.set(Kept::NONE);
// The next kept block of this size has been asked for, so it stays a while.
self.mark_kept_reused(chunks);
- return region.chunk_ptr(block.first);
+ count!(self, HugeCacheHits, 1);
+ self.note_huge_alloc(chunks);
+ return (region.chunk_ptr(block.first), false);
}
}
- let Some(first) = region.alloc_chunks(chunks, 1, 0, self.private.node.get()) else {
- return ptr::null_mut();
+ // A block of whole chunks is a buffer or an arena that most programs touch all of, and
+ // such blocks pack next to each other, so they use huge pages once the heap is big. One of
+ // a huge page or more is worth it whatever the size of the heap.
+ let huge = chunks >= HUGE_PAGE_CHUNKS || self.is_big();
+ let part = region.part(self.private.node.get(), huge);
+ let Some((first, zeroed)) = region.alloc_chunks_zeroed(chunks, 1, 0, part) else {
+ return (ptr::null_mut(), false);
};
+ self.note_huge_alloc(chunks);
region.set_huge(first, chunks);
- region.chunk_ptr(first)
+ #[cfg(feature = "metrics")]
+ if zeroed {
+ count!(self, ZeroedFresh, 1);
+ }
+ (region.chunk_ptr(first), zeroed)
+ }
+
+ /// Records that a huge block of `chunks` chunks was handed out.
+ fn note_huge_alloc(&self, chunks: usize) {
+ self.private.runs.set(self.private.runs.get() + chunks);
+ count!(self, HugeAllocs, 1);
+ count!(self, HugeBytesAllocated, chunks << CHUNK_SHIFT);
}
/// Marks the kept huge blocks of `chunks` chunks as wanted.
@@ -1522,10 +1898,8 @@ impl<'r> Heap<'r> {
/// As [`alloc`](Self::alloc), but the memory is zeroed.
pub fn alloc_zeroed(&self, layout: Layout) -> Option> {
- let block = self.alloc(layout)?;
- // SAFETY: the block holds at least `layout.size()` bytes and is ours.
- unsafe { block.as_ptr().write_bytes(0, layout.size()) };
- Some(block)
+ // SAFETY: this handle holds the claim.
+ NonNull::new(unsafe { self.data.alloc_zeroed(layout) })
}
/// Frees a block.
@@ -1541,10 +1915,23 @@ impl<'r> Heap<'r> {
unsafe { self.data.dealloc(ptr, layout) };
}
+ /// Frees a block without its layout, and ignores a pointer outside the region.
+ ///
+ /// # Safety
+ ///
+ /// A pointer inside the region must be a live block of it, and must not be used or freed
+ /// again.
+ pub unsafe fn free_unsized(&self, ptr: NonNull) {
+ // SAFETY: this handle holds the claim, and the caller vouches for the block.
+ unsafe { self.data.free_unsized(ptr) };
+ }
+
/// Resizes a block, returning `None` (and leaving the block untouched) if there is no room.
///
- /// A block whose new size falls in the same size class, or the same number of chunks for huge
- /// blocks, is returned as is. Otherwise the contents are copied to a new block.
+ /// A block of a slab stays where it is while the new size fits in it and fills at least half
+ /// of it. A block of whole chunks that shrinks gives back the chunks past its new end, and one
+ /// that grows takes the chunks right after it if they are free. Otherwise the contents are
+ /// copied to a new block.
///
/// # Safety
///
@@ -1604,6 +1991,10 @@ impl Backend for Heap<'_> {
self.alloc(layout).map_or(ptr::null_mut(), NonNull::as_ptr)
}
+ unsafe fn allocate_zeroed_raw(&self, layout: Layout) -> *mut u8 {
+ self.alloc_zeroed(layout).map_or(ptr::null_mut(), NonNull::as_ptr)
+ }
+
unsafe fn deallocate_raw(&self, ptr: NonNull, layout: Layout) {
// SAFETY: forwarded.
unsafe { self.dealloc(ptr, layout) };
@@ -1626,6 +2017,11 @@ impl Drop for Heap<'_> {
#[cfg(all(test, not(loom)))]
mod test {
+ use super::*;
+ use crate::{
+ chunks::CHUNK_SIZE,
+ testing::{Harness, Rng, TestRegion, iterations, random_traffic},
+ };
use core::{
alloc::Layout,
mem::{MaybeUninit, align_of, offset_of, size_of},
@@ -1633,12 +2029,6 @@ mod test {
};
use std::vec::Vec;
- use super::*;
- use crate::{
- chunks::CHUNK_SIZE,
- testing::{Harness, Rng, TestRegion, iterations, random_traffic},
- };
-
fn layout(size: usize, align: usize) -> Layout {
Layout::from_size_align(size, align).unwrap()
}
@@ -1676,7 +2066,7 @@ mod test {
fn the_test_sizes_fall_on_both_sides_of_the_reuse_rule() {
assert!(!Class::for_size(HOMEBOUND).reusable_anywhere());
assert!(Class::for_size(ANYWHERE).reusable_anywhere());
- assert!(MESSAGE_CLASS.reusable_anywhere(), "messages are recycled by whoever reads them");
+ assert!(reusable_anywhere(MESSAGE_CLASS), "messages are recycled by whoever reads them");
}
#[test]
@@ -1949,11 +2339,11 @@ mod test {
unsafe { block.as_ptr().write_bytes(0xAB, 100) };
// SAFETY: the block is live with the layout given.
- let same = unsafe { heap.realloc(block, old, 110) }.unwrap();
- assert_eq!(same, block, "100 and 110 bytes share a size class");
+ let same = unsafe { heap.realloc(block, old, 104) }.unwrap();
+ assert_eq!(same, block, "100 and 104 bytes share a size class");
- // SAFETY: the block is still live, now with the 110-byte layout.
- let grown = unsafe { heap.realloc(same, layout(110, 8), 5000) }.unwrap();
+ // SAFETY: the block is still live, now with the 104-byte layout.
+ let grown = unsafe { heap.realloc(same, layout(104, 8), 5000) }.unwrap();
assert_ne!(grown, block);
// SAFETY: the grown block holds at least 100 initialised bytes.
let copied = unsafe { core::slice::from_raw_parts(grown.as_ptr(), 100) };
@@ -2049,6 +2439,157 @@ mod test {
near.validate();
far.validate();
}
+ #[test]
+ fn frees_without_a_layout_find_small_and_huge_blocks_and_skip_others() {
+ let test = TestRegion::new(256, 2);
+ let region = test.region();
+ let (heap, other) = (region.heap().unwrap(), region.heap().unwrap());
+ let small = alloc_many(&heap, layout(48, 8), 100);
+ let theirs = alloc_many(&other, layout(4000, 8), 10);
+ let huge = heap.alloc(layout(9 * CHUNK_SIZE + 1, 8)).unwrap();
+ let mut outside = 0_u64;
+ // SAFETY: each block is live and freed once, and the last pointer is not in the region.
+ unsafe {
+ for &block in small.iter().chain(&theirs) {
+ heap.free_unsized(block);
+ }
+ heap.free_unsized(huge);
+ heap.free_unsized(NonNull::from(&mut outside).cast());
+ }
+ heap.flush();
+ other.flush();
+ // The other heap frees the messages it was sent, which are this heap's blocks.
+ heap.flush();
+ heap.validate();
+ other.validate();
+ assert_eq!(used(®ion), 0, "every block went back to its slab or the chunk allocator");
+ }
+ #[test]
+ fn shrinking_a_bin_that_takes_in_mail_while_it_shrinks_keeps_it_within_capacity() {
+ // Found by mimalloc-bench's mstress. Shrinking an idle bin gives its oldest blocks back.
+ // Sending another heap's block may read the inbox, and blocks filed from it land in the bin
+ // being shrunk. Setting the smaller capacity after that let pushes run past the bin.
+ let test = TestRegion::new(256, 2);
+ let region = test.region();
+ let (heap, other) = (region.heap().unwrap(), region.heap().unwrap());
+ let class = Class::for_size(ANYWHERE);
+ assert!(class.reusable_anywhere(), "the bin keeps the other heap's blocks");
+ let layout = layout(class.block_size(), 8);
+ let max = class.bin_max();
+ heap.data.set_capacity(class, max);
+ heap.data.private.grown.set((max - class.bin_initial()) * class.block_size());
+ // Blocks of this heap come back through its inbox once the other heap flushes them.
+ let mine = alloc_many(&heap, layout, max);
+ free_all(&other, layout, mine);
+ other.flush();
+ assert!(has_mail(&heap));
+ // The bin fills with the other heap's blocks, which shrinking sends home.
+ let theirs = alloc_many(&other, layout, max);
+ free_all(&heap, layout, theirs);
+ heap.data.bin(class).misses.set(0);
+ heap.data.private.refills.set(MAINTENANCE_INTERVAL - 1);
+ // SAFETY: the handle holds the claim.
+ unsafe { heap.data.maintain(®ion) };
+ let capacity = usize::from(heap.data.bin(class).capacity.get());
+ assert!(capacity < max, "the idle bin shrank");
+ assert!(heap.data.bin_len(class) <= capacity);
+ heap.validate();
+ other.validate();
+ heap.flush();
+ other.flush();
+ heap.flush();
+ assert_eq!(used(®ion), 0);
+ }
+ #[test]
+ fn zeroed_requests_read_as_zeros_whether_memory_is_fresh_reused_or_cached() {
+ let test = TestRegion::new(256, 1);
+ let region = test.region();
+ let heap = region.heap().unwrap();
+ let check = |block: NonNull, size: usize| {
+ // SAFETY: the block holds `size` bytes.
+ let bytes = unsafe { core::slice::from_raw_parts(block.as_ptr(), size) };
+ assert!(bytes.iter().all(|&byte| byte == 0), "a zeroed block of {size} has data");
+ };
+ // Miri checks every byte it writes, so it takes the small sizes only.
+ let sizes: &[usize] = if cfg!(miri) {
+ &[24, 4096]
+ } else {
+ &[24, 2000, 4096, 20 << 10, 9 * CHUNK_SIZE + 5, 3 << 20]
+ };
+ for &size in sizes {
+ let layout = layout(size, 8);
+ for _ in 0..3 {
+ let count = if size > CHUNK_SIZE { 3 } else { 40 };
+ let blocks: Vec<_> =
+ (0..count).map(|_| heap.alloc_zeroed(layout).unwrap()).collect();
+ for &block in &blocks {
+ check(block, size);
+ // SAFETY: the block holds `size` bytes.
+ unsafe { block.as_ptr().write_bytes(0xa5, size) };
+ }
+ free_all(&heap, layout, blocks);
+ // The next round takes the same memory back, from the bin, the slab or the cache
+ // of huge blocks, or after a flush from the chunk bitmap.
+ if size > 4096 {
+ heap.flush();
+ }
+ }
+ }
+ heap.flush();
+ heap.validate();
+ assert_eq!(used(®ion), 0);
+ }
+ #[test]
+ fn blocks_are_as_aligned_as_their_layouts_ask() {
+ let test = TestRegion::new(64, 1);
+ let region = test.region();
+ let heap = region.heap().unwrap();
+ for size in [8, 24, 40, 56, 120, 136] {
+ for align in [8, 16] {
+ let blocks = alloc_many(&heap, layout(size, align), 50);
+ assert!(blocks.iter().all(|block| block.as_ptr().addr() % align == 0));
+ free_all(&heap, layout(size, align), blocks);
+ }
+ }
+ }
+
+ #[test]
+ fn big_heaps_and_big_blocks_take_chunks_from_the_huge_page_zone() {
+ // Four bitmap words: chunks 0 to 127 are the small zone and 128 up the huge one.
+ let test = TestRegion::new(256, 2).with_huge_zone();
+ let region = test.region();
+ let (big, small) = (region.heap().unwrap(), region.heap().unwrap());
+ let chunk = |block: NonNull| region.chunk_index(block.as_ptr());
+ let blocks = layout(8192, 8);
+ let first = alloc_many(&big, blocks, 8 * (HUGE_ZONE_CHUNKS - 4));
+ assert!(first.iter().all(|&block| chunk(block) < 128), "a small heap uses small pages");
+ let later = alloc_many(&big, blocks, 8 * 16);
+ assert!(chunk(*later.last().unwrap()) >= 128, "a big heap moves to the huge page zone");
+ let sparse = big.alloc(layout(20 << 10, 8)).unwrap();
+ assert!(chunk(sparse) < 128, "a slab of several chunks of a big heap uses small pages");
+ let run = big.alloc(layout(9 * CHUNK_SIZE, 8)).unwrap();
+ assert!(chunk(run) >= 128, "a block of whole chunks of a big heap uses huge pages");
+ let medium = small.alloc(layout(9 * CHUNK_SIZE, 8)).unwrap();
+ assert!(chunk(medium) < 128, "and one of a small heap does not");
+ let large = small.alloc(layout(HUGE_PAGE_CHUNKS * CHUNK_SIZE, 8)).unwrap();
+ assert!(chunk(large) >= 128, "a block of a huge page or more uses huge pages");
+ let next = small.alloc(layout(9 * CHUNK_SIZE, 8)).unwrap();
+ assert!(chunk(next) >= 128, "a heap is big once it holds big blocks too");
+ for block in first.into_iter().chain(later) {
+ // SAFETY: allocated above with this layout.
+ unsafe { big.dealloc(block, blocks) };
+ }
+ // SAFETY: as above.
+ unsafe {
+ big.dealloc(sparse, layout(20 << 10, 8));
+ big.dealloc(run, layout(9 * CHUNK_SIZE, 8));
+ }
+ big.flush();
+ let again = big.alloc(blocks).unwrap();
+ assert!(chunk(again) < 128, "a heap that shrank to a quarter goes back to small pages");
+ big.validate();
+ small.validate();
+ }
#[test]
fn a_dropped_heaps_slot_and_slabs_pass_to_the_next_claimant() {
@@ -2209,12 +2750,10 @@ mod test {
#[cfg(all(test, loom))]
mod loom_test {
- use core::mem;
-
- use loom::thread;
-
use super::*;
use crate::testing::TestRegion;
+ use core::mem;
+ use loom::thread;
/// A pointer that may be moved to another thread.
struct SendPtr(NonNull);
diff --git a/crates/bcmalloc/src/lib.rs b/crates/bcmalloc/src/lib.rs
index 6cab2a3..973f82a 100644
--- a/crates/bcmalloc/src/lib.rs
+++ b/crates/bcmalloc/src/lib.rs
@@ -12,6 +12,8 @@ mod config;
#[cfg(all(feature = "std", not(loom)))]
mod global;
mod heap;
+#[cfg(feature = "metrics")]
+mod metrics;
mod region;
mod size_class;
mod slab;
@@ -26,5 +28,7 @@ pub use config::{Commit, Config};
#[cfg(all(feature = "std", not(loom)))]
pub use global::Bcmalloc;
pub use heap::Heap;
+#[cfg(feature = "metrics")]
+pub use metrics::{ClassMetrics, Events, Metrics};
pub use region::{Error, Mapping, Region, Stats};
pub use size_class::{MAX_ALIGN, MAX_SMALL};
diff --git a/crates/bcmalloc/src/metrics.rs b/crates/bcmalloc/src/metrics.rs
new file mode 100644
index 0000000..5288aba
--- /dev/null
+++ b/crates/bcmalloc/src/metrics.rs
@@ -0,0 +1,468 @@
+//! Allocation metrics, compiled in with the `metrics` feature.
+//!
+//! The counters follow the per-thread statistics of TCMalloc and jemalloc: each heap counts its
+//! own events in words that only its thread writes, and a snapshot sums them over every heap slot.
+//! A count is a relaxed load and a relaxed store of the heap's own word, which compiles to an
+//! ordinary add on x86-64 and AArch64, with no locked instruction and no line that another core
+//! writes. The allocation and free counters sit next to the bin they count, on a line the fast path
+//! already touches. Everything else is counted on slow paths.
+//!
+//! Live bytes come from the counts and not from walking slabs, so a snapshot never reads state
+//! that belongs to another thread. A snapshot taken while threads run sums counters that each only
+//! move forward, so it is a consistent view of each counter, not an instant of the whole allocator.
+
+use crate::{
+ chunks::CHUNK_SHIFT,
+ size_class::{CLASSES, Class},
+};
+use core::{
+ fmt::{self, Write},
+ sync::atomic::{AtomicU64, Ordering},
+};
+
+/// A counter that one thread writes and any thread may read.
+#[derive(Debug, Default)]
+pub(crate) struct Counter(AtomicU64);
+
+impl Counter {
+ /// A counter at zero.
+ #[cfg(any(test, feature = "testing"))]
+ pub(crate) const fn new() -> Self {
+ Self(AtomicU64::new(0))
+ }
+
+ /// Adds `n`, wrapping. Only the owning thread may call this.
+ #[inline(always)]
+ pub(crate) fn add(&self, n: u64) {
+ self.0.store(self.0.load(Ordering::Relaxed).wrapping_add(n), Ordering::Relaxed);
+ }
+
+ /// Subtracts `n`, wrapping. Only the owning thread may call this.
+ #[inline(always)]
+ pub(crate) fn sub(&self, n: u64) {
+ self.add(n.wrapping_neg());
+ }
+
+ /// The current value.
+ pub(crate) fn get(&self) -> u64 {
+ self.0.load(Ordering::Relaxed)
+ }
+}
+
+/// A counter that any thread may add to, for the few paths that have no heap of their own.
+#[derive(Debug, Default)]
+pub(crate) struct SharedCounter(AtomicU64);
+
+impl SharedCounter {
+ /// A counter at zero.
+ pub(crate) const fn new() -> Self {
+ Self(AtomicU64::new(0))
+ }
+
+ /// Adds `n`.
+ pub(crate) fn add(&self, n: u64) {
+ self.0.fetch_add(n, Ordering::Relaxed);
+ }
+
+ /// The current value.
+ pub(crate) fn get(&self) -> u64 {
+ self.0.load(Ordering::Relaxed)
+ }
+}
+
+/// The slow-path events a heap counts.
+#[derive(Clone, Copy, Debug)]
+pub(crate) enum Event {
+ Refills,
+ SlabsAdded,
+ SlabsReleased,
+ BlocksSent,
+ MessagesPosted,
+ MailReads,
+ BlocksFiled,
+ HugeAllocs,
+ HugeFrees,
+ HugeBytesAllocated,
+ HugeBytesFreed,
+ HugeCacheHits,
+ BinsGrown,
+ BinsShrunk,
+ ZeroedFresh,
+}
+
+/// How many kinds of [`Event`] there are.
+const EVENTS: usize = Event::ZeroedFresh as usize + 1;
+
+/// The slow-path counters of one heap slot.
+#[derive(Debug)]
+pub(crate) struct HeapEvents([Counter; EVENTS]);
+
+impl HeapEvents {
+ /// Every counter at zero.
+ #[cfg(any(test, feature = "testing"))]
+ pub(crate) const fn new() -> Self {
+ Self([const { Counter::new() }; EVENTS])
+ }
+
+ /// Counts `n` events of a kind. Only the heap's thread may call this.
+ #[inline]
+ pub(crate) fn add(&self, event: Event, n: u64) {
+ self.0[event as usize].add(n);
+ }
+
+ /// The count of a kind.
+ pub(crate) fn get(&self, event: Event) -> u64 {
+ self.0[event as usize].get()
+ }
+}
+
+/// The counters a region keeps for paths that run without a heap, and for the purge clock.
+#[derive(Debug)]
+pub(crate) struct RegionCounters {
+ /// Small blocks freed by threads without a heap, by class.
+ pub(crate) frees: [SharedCounter; CLASSES],
+ pub(crate) huge_frees: SharedCounter,
+ pub(crate) huge_bytes_freed: SharedCounter,
+ pub(crate) purge_passes: SharedCounter,
+ pub(crate) chunks_purged: SharedCounter,
+ pub(crate) chunks_reused: SharedCounter,
+}
+
+impl RegionCounters {
+ /// Every counter at zero.
+ pub(crate) const fn new() -> Self {
+ Self {
+ frees: [const { SharedCounter::new() }; CLASSES],
+ huge_frees: SharedCounter::new(),
+ huge_bytes_freed: SharedCounter::new(),
+ purge_passes: SharedCounter::new(),
+ chunks_purged: SharedCounter::new(),
+ chunks_reused: SharedCounter::new(),
+ }
+ }
+}
+
+/// What a snapshot reports for one size class.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct ClassMetrics {
+ /// The size of every block of the class.
+ pub block_size: usize,
+ /// How many blocks have been handed out, including the allocator's own messages.
+ pub allocs: u64,
+ /// How many blocks have been freed.
+ pub frees: u64,
+ /// How many slabs of the class the heaps hold.
+ pub slabs: u64,
+ /// The bytes those slabs span.
+ pub slab_bytes: u64,
+}
+
+impl ClassMetrics {
+ /// Blocks handed out and not yet freed.
+ pub const fn live_blocks(&self) -> u64 {
+ self.allocs.saturating_sub(self.frees)
+ }
+
+ /// Bytes handed out and not yet freed.
+ pub const fn live_bytes(&self) -> u64 {
+ self.live_blocks() * self.block_size as u64
+ }
+}
+
+/// Counts of the allocator's slow paths, summed over every heap.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct Events {
+ /// Bins refilled from slabs.
+ pub refills: u64,
+ /// Slabs taken from the chunk allocator.
+ pub slabs_added: u64,
+ /// Empty slabs given back to the chunk allocator.
+ pub slabs_released: u64,
+ /// Blocks freed by a heap that does not own them and sent to their owner.
+ pub blocks_sent: u64,
+ /// Messages of several blocks posted to an owner's inbox.
+ pub messages_posted: u64,
+ /// Times a heap read its inbox.
+ pub mail_reads: u64,
+ /// Blocks a heap took in from its inbox.
+ pub blocks_filed: u64,
+ /// Huge blocks allocated.
+ pub huge_allocs: u64,
+ /// Huge blocks freed.
+ pub huge_frees: u64,
+ /// Huge requests served from a heap's cache of freed blocks.
+ pub huge_cache_hits: u64,
+ /// Bins that grew because they kept missing.
+ pub bins_grown: u64,
+ /// Bins that shrank because they stopped missing.
+ pub bins_shrunk: u64,
+ /// Zeroed requests served from fresh memory, which needed no clearing.
+ pub zeroed_fresh: u64,
+ /// Passes of the purge clock.
+ pub purge_passes: u64,
+ /// Chunks the purge clock gave back to the operating system.
+ pub chunks_purged: u64,
+ /// Purged chunks that were used again.
+ pub chunks_reused: u64,
+}
+
+/// A snapshot of the allocator's metrics, from [`Region::metrics`](crate::Region::metrics).
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct Metrics {
+ /// The size of the managed memory.
+ pub capacity: usize,
+ /// Bytes of chunks that belong to a slab or a huge block, or that a heap keeps for reuse.
+ pub chunk_bytes: usize,
+ /// Heap slots that have ever been claimed.
+ pub heaps_claimed: usize,
+ /// Heap slots claimed now.
+ pub heaps_in_use: usize,
+ /// Bytes of huge blocks handed out and not yet freed.
+ pub huge_live_bytes: u64,
+ /// Every size class, in order.
+ pub classes: [ClassMetrics; CLASSES],
+ /// Slow-path counts.
+ pub events: Events,
+}
+
+impl Metrics {
+ /// Bytes of small blocks handed out and not yet freed, including the allocator's messages.
+ pub fn small_live_bytes(&self) -> u64 {
+ self.classes.iter().map(ClassMetrics::live_bytes).sum()
+ }
+
+ /// Bytes spanned by slabs.
+ pub fn slab_bytes(&self) -> u64 {
+ self.classes.iter().map(|class| class.slab_bytes).sum()
+ }
+
+ /// The share of slab bytes that holds live blocks, from 0 to 1. The rest is free blocks in
+ /// slabs, blocks cached in bins and outboxes, and pages that no block has reached yet.
+ pub fn slab_utilization(&self) -> f64 {
+ let slabs = self.slab_bytes();
+ if slabs == 0 { 1.0 } else { self.small_live_bytes() as f64 / slabs as f64 }
+ }
+}
+
+/// Builds the per-class part of a snapshot from the allocations, frees and slabs of each class.
+pub(crate) fn class_metrics(
+ mut counts: impl FnMut(Class) -> (u64, u64, u64),
+) -> [ClassMetrics; CLASSES] {
+ core::array::from_fn(|index| {
+ let class = Class::from_index(index);
+ let (allocs, frees, slabs) = counts(class);
+ ClassMetrics {
+ block_size: class.block_size(),
+ allocs,
+ frees,
+ slabs,
+ slab_bytes: slabs * ((class.slab_chunks() as u64) << CHUNK_SHIFT),
+ }
+ })
+}
+
+/// A size in bytes with a binary unit, padded to the width the formatter asks for.
+struct Bytes(u64);
+
+impl fmt::Display for Bytes {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ const UNITS: [&str; 5] = ["B", "KiB", "MiB", "GiB", "TiB"];
+ let mut value = self.0 as f64;
+ let mut unit = 0;
+ while value >= 1024.0 && unit + 1 < UNITS.len() {
+ value /= 1024.0;
+ unit += 1;
+ }
+ let mut text = Text::default();
+ if unit == 0 {
+ write!(text, "{} B", self.0)?;
+ } else {
+ write!(text, "{value:.1} {}", UNITS[unit])?;
+ }
+ f.pad(text.as_str())
+ }
+}
+
+/// A short string on the stack, so that formatting needs no allocation.
+#[derive(Default)]
+struct Text {
+ bytes: [u8; 32],
+ len: usize,
+}
+
+impl Text {
+ fn as_str(&self) -> &str {
+ core::str::from_utf8(&self.bytes[..self.len]).unwrap_or("")
+ }
+}
+
+impl Write for Text {
+ fn write_str(&mut self, s: &str) -> fmt::Result {
+ let end = self.len + s.len();
+ if end > self.bytes.len() {
+ return Err(fmt::Error);
+ }
+ self.bytes[self.len..end].copy_from_slice(s.as_bytes());
+ self.len = end;
+ Ok(())
+ }
+}
+
+#[cfg(all(test, not(loom)))]
+mod test {
+ use crate::{chunks::CHUNK_SIZE, size_class::Class, testing::TestRegion};
+ use core::{alloc::Layout, ptr::NonNull};
+ use std::{string::ToString, vec::Vec};
+
+ #[test]
+ fn snapshots_count_live_blocks_slabs_and_events() {
+ let test = TestRegion::new(256, 2);
+ let region = test.region();
+ let (heap, other) = (region.heap().unwrap(), region.heap().unwrap());
+ let small = Layout::from_size_align(100, 8).unwrap();
+ let class = Class::for_size(100);
+ let blocks: Vec> = (0..1000).map(|_| heap.alloc(small).unwrap()).collect();
+ let huge = Layout::from_size_align(48 * CHUNK_SIZE, 8).unwrap();
+ let big = heap.alloc(huge).unwrap();
+
+ let metrics = region.metrics();
+ let counted = metrics.classes[class.index()];
+ assert_eq!(counted.block_size, class.block_size());
+ assert_eq!(counted.live_blocks(), 1000);
+ assert!(counted.slabs >= 1 && counted.slab_bytes >= counted.live_bytes());
+ assert_eq!(metrics.huge_live_bytes, huge.size().next_multiple_of(CHUNK_SIZE) as u64);
+ assert_eq!(metrics.events.huge_allocs, 1);
+ assert!(metrics.events.refills > 0 && metrics.events.slabs_added > 0);
+ assert_eq!(metrics.heaps_in_use, 2);
+
+ // Half go back on the owner, half from the other heap, which sends them home.
+ let (mine, theirs) = blocks.split_at(500);
+ // SAFETY: every block is live and freed once with its layout.
+ unsafe {
+ for &block in mine {
+ heap.dealloc(block, small);
+ }
+ for &block in theirs {
+ other.dealloc(block, small);
+ }
+ heap.dealloc(big, huge);
+ }
+ other.flush();
+ heap.flush();
+ other.flush();
+ let metrics = region.metrics();
+ let counted = metrics.classes[class.index()];
+ assert_eq!(counted.live_blocks(), 0, "{counted:?}");
+ assert_eq!(counted.allocs, 1000);
+ assert_eq!(metrics.huge_live_bytes, 0);
+ assert!(metrics.events.blocks_sent >= 500 && metrics.events.blocks_filed > 0);
+ assert!(metrics.events.slabs_released > 0);
+ assert!(metrics.small_live_bytes() == 0 && metrics.slab_utilization() <= 1.0);
+ let report = metrics.to_string();
+ assert!(report.starts_with("bcmalloc metrics"));
+ assert!(report.contains(&std::format!("{:>8}", class.block_size())));
+ }
+
+ #[test]
+ fn frees_by_threads_without_a_heap_are_counted_by_the_region() {
+ let test = TestRegion::new(64, 1);
+ let region = test.region();
+ let heap = region.heap().unwrap();
+ let layout = Layout::from_size_align(48, 8).unwrap();
+ let block = heap.alloc(layout).unwrap();
+ // SAFETY: the block is live and freed once.
+ unsafe { region.dealloc(block, layout) };
+ let counted = region.metrics().classes[Class::for_size(48).index()];
+ assert_eq!((counted.allocs, counted.frees), (1, 1));
+ }
+
+ #[test]
+ fn zeroed_requests_from_fresh_memory_are_not_cleared() {
+ let test = TestRegion::new(256, 1);
+ let region = test.region();
+ let heap = region.heap().unwrap();
+ let fresh = heap.alloc_zeroed(Layout::from_size_align(4096, 8).unwrap()).unwrap();
+ let huge = heap.alloc_zeroed(Layout::from_size_align(20 * CHUNK_SIZE, 8).unwrap()).unwrap();
+ assert_eq!(region.metrics().events.zeroed_fresh, 2);
+ // SAFETY: both blocks are live and freed once.
+ unsafe {
+ heap.dealloc(fresh, Layout::from_size_align(4096, 8).unwrap());
+ heap.dealloc(huge, Layout::from_size_align(20 * CHUNK_SIZE, 8).unwrap());
+ }
+ // The huge block comes back from the heap's cache, which is not fresh.
+ let again = heap.alloc_zeroed(Layout::from_size_align(20 * CHUNK_SIZE, 8).unwrap());
+ assert!(again.is_some());
+ assert_eq!(region.metrics().events.zeroed_fresh, 2);
+ }
+}
+
+impl fmt::Display for Metrics {
+ /// A report in the manner of mimalloc's statistics: totals, then every class in use.
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let events = &self.events;
+ writeln!(f, "bcmalloc metrics")?;
+ writeln!(
+ f,
+ " heaps: {} in use, {} claimed; chunks: {} of {}",
+ self.heaps_in_use,
+ self.heaps_claimed,
+ Bytes(self.chunk_bytes as u64),
+ Bytes(self.capacity as u64)
+ )?;
+ writeln!(
+ f,
+ " small: {} live in {} of slabs ({:.0}% used); huge: {} live",
+ Bytes(self.small_live_bytes()),
+ Bytes(self.slab_bytes()),
+ self.slab_utilization() * 100.0,
+ Bytes(self.huge_live_bytes)
+ )?;
+ writeln!(
+ f,
+ " refills {}, slabs +{} -{}, sent {} blocks in {} messages, mail read {} times for {} blocks",
+ events.refills,
+ events.slabs_added,
+ events.slabs_released,
+ events.blocks_sent,
+ events.messages_posted,
+ events.mail_reads,
+ events.blocks_filed
+ )?;
+ writeln!(
+ f,
+ " huge +{} -{} ({} cached), bins grown {} shrunk {}, fresh zeroed {}, purges {} gave back {} reused {}",
+ events.huge_allocs,
+ events.huge_frees,
+ events.huge_cache_hits,
+ events.bins_grown,
+ events.bins_shrunk,
+ events.zeroed_fresh,
+ events.purge_passes,
+ Bytes(events.chunks_purged << CHUNK_SHIFT),
+ Bytes(events.chunks_reused << CHUNK_SHIFT)
+ )?;
+ writeln!(
+ f,
+ " {:>8} {:>14} {:>14} {:>11} {:>11} {:>5}",
+ "size", "allocs", "frees", "live", "slabs", "used"
+ )?;
+ for class in self.classes.iter().filter(|class| class.allocs != 0 || class.slabs != 0) {
+ let used = if class.slab_bytes == 0 {
+ 0.0
+ } else {
+ class.live_bytes() as f64 * 100.0 / class.slab_bytes as f64
+ };
+ writeln!(
+ f,
+ " {:>8} {:>14} {:>14} {:>11} {:>11} {:>4.0}%",
+ class.block_size,
+ class.allocs,
+ class.frees,
+ Bytes(class.live_bytes()),
+ Bytes(class.slab_bytes),
+ used
+ )?;
+ }
+ Ok(())
+ }
+}
diff --git a/crates/bcmalloc/src/region.rs b/crates/bcmalloc/src/region.rs
index 0d95f52..a46df8b 100644
--- a/crates/bcmalloc/src/region.rs
+++ b/crates/bcmalloc/src/region.rs
@@ -2,8 +2,9 @@
//! byte it hands out.
//!
//! Everything lives in a single mapping, laid out so that the zero-filled pages the kernel provides
-//! are a valid initial state for all of it. Nothing is written at start-up, so creating a region of
-//! any size is instant and costs nothing until it is used.
+//! are a valid initial state for all of it. Creating a region writes its header and, unless the
+//! configuration asks to populate the memory up front, nothing else, so a region of any size costs
+//! address space until it is used.
//!
//! ```text
//! +--------+-------+-----------+-------------+-----------+---------+-----+-------------------+
@@ -23,14 +24,6 @@
//! A [`Region`] is the shared, thread-safe half of the allocator. Threads take a [`Heap`] from it
//! to allocate. A [`Mapping`] owns the memory behind a region and unmaps it on drop.
-use core::{
- alloc::Layout,
- fmt, mem,
- ops::Range,
- ptr::{self, NonNull},
- slice,
-};
-
use crate::{
chunks::{CHUNK_SHIFT, CHUNK_SIZE, Chunks},
config::{Commit, Config},
@@ -40,17 +33,31 @@ use crate::{
sync::{AtomicBool, AtomicU64, AtomicUsize, Ordering, fence},
sys,
};
+use core::{
+ alloc::Layout,
+ fmt, mem,
+ ops::Range,
+ ptr::{self, NonNull},
+ slice,
+};
/// How often the purge clock ticks, in milliseconds, and how long free chunks must have gone
/// unused before they go back to the OS.
const PURGE_INTERVAL_MS: u64 = 10;
-/// The alignment of the managed memory, which is the size of the largest slab.
+/// The alignment of the managed memory: one bitmap word of 64 chunks, 4 MiB. Every word then covers
+/// two whole huge pages, and every slab, which is at most 8 chunks, starts on a multiple of its
+/// size.
const SLAB_ALIGN: usize = 64 * CHUNK_SIZE;
-/// The chunks in one transparent huge page of 2 MiB, which is the unit the purge clock gives back
-/// when the region asks for huge pages.
-const HUGE_PAGE_CHUNKS: usize = (2 << 20) / CHUNK_SIZE;
+/// How many times longer free chunks of the zone of transparent huge pages wait before they are
+/// given back. A huge page that is given back and then used again costs a fault that clears 2 MiB,
+/// and big blocks that a program frees and allocates in turn would pay it every time, so idle huge
+/// pages wait 100 ms, as jemalloc lets dirty pages decay instead of returning them at once.
+const HUGE_PURGE_WAIT: u64 = 10;
+
+/// The chunks in one transparent huge page of 2 MiB.
+pub(crate) const HUGE_PAGE_CHUNKS: usize = (2 << 20) / CHUNK_SIZE;
/// Why a region could not be created.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -101,8 +108,10 @@ pub struct Region<'a> {
heaps: &'a [HeapData],
/// The bin slots of every heap, [`BIN_SLOTS`] for each, owned by whoever claims the heap.
bin_slots: *mut *mut Block,
- /// How many NUMA nodes the region is split between, and how many bitmap words there are.
+ /// How many NUMA nodes the region is split between, into how many zones the part of each node
+ /// is split, and how many bitmap words there are. See [`Region::part`].
nodes: usize,
+ zones: usize,
words: usize,
/// How many heap slots may have been claimed. Slots at or beyond it are untouched, so the
/// operations that visit every slot stop here.
@@ -116,6 +125,8 @@ pub struct Region<'a> {
purges_active: AtomicUsize,
/// How many purge passes and trims have finished.
purges_done: AtomicUsize,
+ #[cfg(feature = "metrics")]
+ counters: crate::metrics::RegionCounters,
}
// SAFETY: the raw pointer is an address into memory the region owns, and every shared structure
@@ -133,8 +144,6 @@ unsafe impl Sync for Region<'_> {}
/// slots.
/// * `bin_slots` must point to [`BIN_SLOTS`] writable pointers for each heap slot, valid for as
/// long as `'a` and used by nothing else.
-/// * `purge_granule` is how many chunks the purge clock gives back together, a power of two of at
-/// most 64 that `base` is aligned to in chunks.
pub(crate) struct Parts<'a> {
pub(crate) base: *mut u8,
pub(crate) words: &'a [AtomicU64],
@@ -143,9 +152,10 @@ pub(crate) struct Parts<'a> {
pub(crate) map: &'a [AtomicU64],
pub(crate) heaps: &'a [HeapData],
pub(crate) bin_slots: *mut *mut Block,
- pub(crate) purge_granule: usize,
/// How many NUMA nodes to split the chunks between, at least 1.
pub(crate) nodes: usize,
+ /// Whether the part of each node has a zone for transparent huge pages. See [`Region::part`].
+ pub(crate) huge_zone: bool,
}
impl<'a> Region<'a> {
@@ -159,22 +169,34 @@ impl<'a> Region<'a> {
debug_assert_eq!(parts.map.len(), parts.chunk_count);
let words = Chunks::words_for(parts.chunk_count);
// A region too small to give every node a word of its own is not split at all, because
- // the parts are numbered by physical node.
+ // the parts are numbered by physical node. Zones are given up first, since they only
+ // decide placement.
let nodes = if parts.nodes <= words { parts.nodes.max(1) } else { 1 };
+ let zones = if parts.huge_zone && 2 * nodes <= words { 2 } else { 1 };
+ // Huge pages go back whole, and small pages one chunk at a time.
+ let chunks = if zones > 1 {
+ Chunks::with_granule(parts.words, parts.chunk_count, HUGE_PAGE_CHUNKS)
+ .coarse_in_odd_parts(nodes * zones, HUGE_PURGE_WAIT)
+ } else {
+ Chunks::with_granule(parts.words, parts.chunk_count, 1)
+ };
Self {
base: parts.base,
- chunks: Chunks::with_granule(parts.words, parts.chunk_count, parts.purge_granule),
+ chunks,
slabs: parts.slabs,
map: parts.map,
heaps: parts.heaps,
bin_slots: parts.bin_slots,
nodes,
+ zones,
words,
claimed_mark: AtomicUsize::new(0),
next_purge: AtomicU64::new(0),
aging: AtomicBool::new(false),
purges_active: AtomicUsize::new(0),
purges_done: AtomicUsize::new(0),
+ #[cfg(feature = "metrics")]
+ counters: crate::metrics::RegionCounters::new(),
}
}
@@ -205,11 +227,19 @@ impl<'a> Region<'a> {
pub unsafe fn dealloc(&self, ptr: NonNull, layout: Layout) {
match classify(layout) {
Some(Request::Small(_)) => {
- let owner = self.entry(self.chunk_index(ptr.as_ptr())).owner();
+ let entry = self.entry(self.chunk_index(ptr.as_ptr()));
+ #[cfg(feature = "metrics")]
+ self.counters.frees[entry.class().index()].add(1);
+ let owner = entry.owner();
// SAFETY: the caller gives the block up, and the chunk map names its owner.
unsafe { self.heap_slot(owner).post_block(ptr.as_ptr().cast()) };
}
Some(Request::Huge { chunks }) => {
+ #[cfg(feature = "metrics")]
+ {
+ self.counters.huge_frees.add(1);
+ self.counters.huge_bytes_freed.add((chunks << CHUNK_SHIFT) as u64);
+ }
self.free_chunks(self.chunk_index(ptr.as_ptr()), chunks);
self.purge_if_due();
}
@@ -262,27 +292,99 @@ impl<'a> Region<'a> {
}
}
+ /// A snapshot of the allocator's metrics, summed over every heap slot that has been claimed.
+ /// It costs a pass over those slots and the chunk bitmap, so call it now and then, not on a
+ /// hot path. See [`Metrics`](crate::Metrics).
+ #[cfg(feature = "metrics")]
+ pub fn metrics(&self) -> crate::Metrics {
+ use crate::metrics::Event;
+ let claimed = self.claimed_mark.load(Ordering::Acquire);
+ let heaps = &self.heaps[..claimed];
+ let counters = &self.counters;
+ let classes = crate::metrics::class_metrics(|class| {
+ let unbound = counters.frees[class.index()].get();
+ heaps
+ .iter()
+ .map(|heap| heap.class_counts(class))
+ .fold((0, unbound, 0), |(allocs, frees, slabs), (a, f, s)| {
+ (allocs + a, frees + f, slabs.wrapping_add(s))
+ })
+ });
+ let sum = |event| heaps.iter().map(|heap| heap.events().get(event)).sum::();
+ let huge_allocated = sum(Event::HugeBytesAllocated);
+ let huge_freed = sum(Event::HugeBytesFreed) + counters.huge_bytes_freed.get();
+ let stats = self.stats();
+ crate::Metrics {
+ capacity: stats.capacity,
+ chunk_bytes: stats.capacity - stats.free,
+ heaps_claimed: claimed,
+ heaps_in_use: stats.heaps_in_use,
+ huge_live_bytes: huge_allocated.saturating_sub(huge_freed),
+ classes,
+ events: crate::metrics::Events {
+ refills: sum(Event::Refills),
+ slabs_added: sum(Event::SlabsAdded),
+ slabs_released: sum(Event::SlabsReleased),
+ blocks_sent: sum(Event::BlocksSent),
+ messages_posted: sum(Event::MessagesPosted),
+ mail_reads: sum(Event::MailReads),
+ blocks_filed: sum(Event::BlocksFiled),
+ huge_allocs: sum(Event::HugeAllocs),
+ huge_frees: sum(Event::HugeFrees) + counters.huge_frees.get(),
+ huge_cache_hits: sum(Event::HugeCacheHits),
+ bins_grown: sum(Event::BinsGrown),
+ bins_shrunk: sum(Event::BinsShrunk),
+ zeroed_fresh: sum(Event::ZeroedFresh),
+ purge_passes: counters.purge_passes.get(),
+ chunks_purged: counters.chunks_purged.get(),
+ chunks_reused: counters.chunks_reused.get(),
+ },
+ }
+ }
+
/// Whether `ptr` points into this region's managed memory.
pub fn contains(&self, ptr: *const u8) -> bool {
let offset = ptr.addr().wrapping_sub(self.base.addr());
- offset < self.chunks.len() << CHUNK_SHIFT
+ offset < self.span()
}
- /// Claims `n` chunks as `Chunks`::alloc does, and makes the pages of any that were given back
- /// to the OS ready for use.
+ /// The length of the managed memory in bytes.
+ pub(crate) const fn span(&self) -> usize {
+ self.chunks.len() << CHUNK_SHIFT
+ }
+
+ /// As [`alloc_chunks_zeroed`](Self::alloc_chunks_zeroed), without telling whether the chunks
+ /// read as zeros.
+ #[cfg(test)]
pub(crate) fn alloc_chunks(
&self,
n: usize,
align: usize,
hint: usize,
- node: usize,
+ part: usize,
) -> Option {
- let home = self.home(node);
+ self.alloc_chunks_zeroed(n, align, hint, part).map(|(first, _)| first)
+ }
+
+ /// Claims `n` chunks as `Chunks`::alloc does, preferring part `part` (see [`Region::part`]),
+ /// makes the pages of any that were given back to the OS ready for use, and tells whether the
+ /// chunks read as zeros.
+ pub(crate) fn alloc_chunks_zeroed(
+ &self,
+ n: usize,
+ align: usize,
+ hint: usize,
+ part: usize,
+ ) -> Option<(usize, bool)> {
+ let home = self.home(part);
let first = match self.chunks.alloc_near(n, align, hint, home.clone()) {
Some(first) => first,
None => self.alloc_chunks_after_purge(n, align, hint, home)?,
};
+ let zeroed = self.chunks.is_clean(first, n, sys::DISCARD_ZEROES);
self.chunks.take_purged(first, n, |run| {
+ #[cfg(feature = "metrics")]
+ self.counters.chunks_reused.add(run.len() as u64);
// SAFETY: the run is inside the region and belongs to us since the claim above.
unsafe {
sys::reuse(
@@ -291,13 +393,31 @@ impl<'a> Region<'a> {
);
}
});
- Some(first)
+ Some((first, zeroed))
}
- /// The bitmap words of the part of the region that belongs to NUMA node `node`.
- pub(crate) const fn home(&self, node: usize) -> Range {
+ /// The part of the region that the chunks of NUMA node `node` come from, in its zone for
+ /// transparent huge pages if `huge`.
+ ///
+ /// The part of each node is split in two. The upper zone is backed by huge pages and holds the
+ /// chunks of heaps that have grown past a threshold, and of blocks of a huge page or more, so
+ /// that a thread that uses little memory never holds a 2 MiB page it barely touches. Each zone
+ /// is one range of addresses, so the advice is given once.
+ pub(crate) const fn part(&self, node: usize, huge: bool) -> usize {
+ (node % self.nodes) * self.zones + (huge && self.zones > 1) as usize
+ }
+
+ /// The bitmap words of part `part`. The parts of a node are next to each other.
+ pub(crate) const fn home(&self, part: usize) -> Range {
+ let parts = self.nodes * self.zones;
+ let part = part % parts;
+ part * self.words / parts..(part + 1) * self.words / parts
+ }
+
+ /// The bitmap words of all the parts of NUMA node `node`.
+ pub(crate) const fn node_words(&self, node: usize) -> Range {
let node = node % self.nodes;
- node * self.words / self.nodes..(node + 1) * self.words / self.nodes
+ self.home(self.part(node, false)).start..self.home(self.part(node, true)).end
}
/// The NUMA node of the CPU the calling thread runs on, as the region numbers its parts.
@@ -330,6 +450,8 @@ impl<'a> Region<'a> {
core::hint::spin_loop();
}
self.chunks.take_purged(start, more, |run| {
+ #[cfg(feature = "metrics")]
+ self.counters.chunks_reused.add(run.len() as u64);
// SAFETY: the run is inside the region and belongs to us since the claim above.
unsafe {
sys::reuse(
@@ -414,7 +536,11 @@ impl<'a> Region<'a> {
// acquires the bits of every free that set it.
self.aging.swap(false, Ordering::Acquire);
self.purges_active.fetch_add(1, Ordering::Release);
+ #[cfg(feature = "metrics")]
+ self.counters.purge_passes.add(1);
let pending = self.chunks.purge_pass(now, PURGE_INTERVAL_MS, |run| {
+ #[cfg(feature = "metrics")]
+ self.counters.chunks_purged.add(run.len() as u64);
// SAFETY: the pass holds the run, so no allocation overlaps it.
unsafe {
sys::discard(
@@ -533,9 +659,11 @@ impl<'a> Region<'a> {
pub(crate) struct Entry(pub(crate) u64);
impl Entry {
- /// The entry for a slab of `class` owned by heap `owner`.
+ /// The entry for a slab of `class` owned by heap `owner`. Next to the class it keeps the byte
+ /// offset of the class's bin in a heap, so that a free finds the bin without arithmetic.
pub(crate) const fn new(owner: u32, class: Class) -> Self {
- Self(owner as u64 | (class.index() as u64) << 32)
+ let offset = (class.index() * crate::heap::BIN_SIZE) as u64;
+ Self(owner as u64 | (class.index() as u64) << 32 | offset << 40)
}
/// The bit that marks the entry of the first chunk of a huge block.
@@ -547,9 +675,13 @@ impl Entry {
}
/// The number of chunks of a huge block, or None if the entry is a slab's.
- #[cfg(all(feature = "std", not(loom)))]
pub(crate) const fn huge_chunks(self) -> Option {
- if self.0 & Self::HUGE != 0 { Some((self.0 & !Self::HUGE) as usize) } else { None }
+ if self.is_huge() { Some((self.0 & !Self::HUGE) as usize) } else { None }
+ }
+
+ /// Whether the entry is that of the first chunk of a huge block.
+ pub(crate) const fn is_huge(self) -> bool {
+ self.0 & Self::HUGE != 0
}
/// The id of the heap that owns the slab.
@@ -557,6 +689,11 @@ impl Entry {
self.0 as u32
}
+ /// The byte offset of the bin of the slab's class in a heap.
+ pub(crate) const fn bin_offset(self) -> usize {
+ (self.0 >> 40) as usize
+ }
+
/// The size class of the slab.
pub(crate) const fn class(self) -> Class {
// SAFETY: entries are only ever written by [`Entry::new`] from a class.
@@ -662,13 +799,7 @@ impl Mapping {
at(geometry.words).cast::(),
Chunks::storage_words(chunks),
);
- // With huge pages, giving back less than a whole one would split it.
let nodes = if config.wants_numa() { sys::numa_nodes() } else { 1 };
- let granule = if config.wants_huge_pages() && cfg!(target_os = "linux") {
- HUGE_PAGE_CHUNKS
- } else {
- 1
- };
let region = Region::from_parts(Parts {
base: at(geometry.data),
words,
@@ -677,8 +808,8 @@ impl Mapping {
map,
heaps: heap_slots,
bin_slots: at(geometry.bins).cast::<*mut Block>(),
- purge_granule: granule,
nodes,
+ huge_zone: config.wants_huge_pages() && cfg!(target_os = "linux"),
});
ptr::write(base.as_ptr().cast::>(), region);
}
@@ -707,25 +838,33 @@ impl Mapping {
let data_len = config.capacity_bytes();
// SAFETY: the data range is inside the reservation.
let data = unsafe { NonNull::new_unchecked(self.base.as_ptr().add(geometry.data)) };
- if config.wants_huge_pages() {
- // SAFETY: as above.
- unsafe { sys::advise_huge(data, data_len) };
- }
let region = self.region();
for node in 0..region.nodes {
- let words = region.home(node);
- let start = (words.start * 64).min(region.chunks.len());
- let end = (words.end * 64).min(region.chunks.len());
- if region.nodes > 1 && start < end {
+ let chunks = |words: Range| {
+ (words.start * 64).min(region.chunks.len())..
+ (words.end * 64).min(region.chunks.len())
+ };
+ let all = chunks(region.node_words(node));
+ if region.nodes > 1 && !all.is_empty() {
// SAFETY: the range is inside the data range.
unsafe {
sys::prefer_node(
- NonNull::new_unchecked(region.chunk_ptr(start)),
- (end - start) << CHUNK_SHIFT,
+ NonNull::new_unchecked(region.chunk_ptr(all.start)),
+ all.len() << CHUNK_SHIFT,
node,
);
}
}
+ let huge = chunks(region.home(region.part(node, true)));
+ if region.zones > 1 && !huge.is_empty() {
+ // SAFETY: as above.
+ unsafe {
+ sys::advise_huge(
+ NonNull::new_unchecked(region.chunk_ptr(huge.start)),
+ huge.len() << CHUNK_SHIFT,
+ );
+ }
+ }
}
match config.commit_mode() {
Commit::Lazy => {}
@@ -779,6 +918,35 @@ mod test {
let tiny = crate::testing::TestRegion::with_nodes(64, 1, 4);
assert_eq!(tiny.region().home(3), 0..1, "a region smaller than the nodes is not split");
}
+ #[test]
+ fn print_geometry_tmp() {
+ let g = Geometry::new(1 << 20, 4096).unwrap();
+ std::println!(
+ "GEOM heaps {} bins {} slabs {} map {} words {} data {} heapdata {} slab {}",
+ g.heaps >> 20,
+ g.bins >> 20,
+ g.slabs >> 20,
+ g.map >> 20,
+ g.words >> 20,
+ g.data >> 20,
+ mem::size_of::(),
+ mem::size_of::()
+ );
+ }
+
+ #[test]
+ fn every_node_gets_a_small_and_a_huge_page_zone_side_by_side() {
+ let test = crate::testing::TestRegion::with_nodes(512, 1, 2).with_huge_zone();
+ let region = test.region();
+ let parts = [(0, false), (0, true), (1, false), (1, true)]
+ .map(|(node, huge)| region.home(region.part(node, huge)));
+ assert_eq!(parts, [0..2, 2..4, 4..6, 6..8], "the zones of a node are next to each other");
+ assert_eq!(region.node_words(1), 4..8);
+ let one = crate::testing::TestRegion::new(64, 1).with_huge_zone();
+ let region = one.region();
+ assert_eq!(region.part(0, true), region.part(0, false), "one word is not split");
+ assert_eq!(region.node_words(0), 0..1);
+ }
#[test]
fn growing_in_place_waits_out_a_purge_that_holds_the_next_chunks() {
@@ -824,17 +992,16 @@ mod test {
fn slabs_start_on_multiples_of_their_size() {
let mapping = Mapping::new(&config(64 * MIB)).unwrap();
let heap = mapping.region().heap().unwrap();
- // The largest class lives in 4 MiB slabs, and its blocks are 512 KiB apart.
- let layout = Layout::from_size_align(512 << 10, 64 << 10).unwrap();
+ // The largest class lives in 512 KiB slabs, and its blocks are 64 KiB apart.
+ let layout = Layout::from_size_align(64 << 10, 64 << 10).unwrap();
let blocks: std::vec::Vec<_> = (0..4).map(|_| heap.alloc(layout).unwrap()).collect();
- assert!(blocks.iter().all(|block| block.as_ptr().addr() % (512 << 10) == 0));
+ assert!(blocks.iter().all(|block| block.as_ptr().addr() % (64 << 10) == 0));
}
#[test]
fn a_retry_does_not_wait_for_a_purge_pass_while_other_chunks_are_free() {
- use std::{sync::mpsc, time::Duration};
-
use crate::testing::TestRegion;
+ use std::{sync::mpsc, time::Duration};
let test = TestRegion::new(2, 1);
let region = test.region();
@@ -940,10 +1107,9 @@ mod test {
#[cfg(all(test, loom))]
mod loom_test {
- use loom::thread;
-
use super::*;
use crate::testing::TestRegion;
+ use loom::thread;
#[test]
fn a_free_racing_a_purge_pass_never_strands_a_dirty_chunk() {
diff --git a/crates/bcmalloc/src/size_class.rs b/crates/bcmalloc/src/size_class.rs
index 6b547b5..59d329e 100644
--- a/crates/bcmalloc/src/size_class.rs
+++ b/crates/bcmalloc/src/size_class.rs
@@ -1,57 +1,76 @@
//! Size classes and slab geometry.
//!
-//! A request of up to 512 KiB is rounded up to one of 104 size classes. Classes are 16 bytes apart
-//! up to 128 bytes. Above that there are eight classes per doubling, so rounding wastes at most one
-//! part in eight.
+//! A request of up to 64 KiB is rounded up to one of 87 size classes. Classes are 8 bytes apart
+//! from 16 up to 128 bytes, as in TCMalloc and mimalloc, so the many Rust values of three, five or
+//! seven words fill their blocks. Above that there are eight classes per doubling, so rounding
+//! wastes at most one part in eight.
//!
//! ```text
-//! 16 32 48 64 80 96 112 128 | 144 160 176 192 208 224 240 256 | 288 320 352 ... 512K
-//! <---- 8 classes, +16 ----> <------- 8 classes, +16 -------> <--- +32 ---> ...
-//! <-------- one doubling -------->
+//! 16 24 32 ... 112 120 128 | 144 160 176 192 208 224 240 256 | 288 320 352 ... 64K
+//! <---- 15 classes, +8 ----> <------- 8 classes, +16 -------> <--- +32 ---> ...
+//! <-------- one doubling -------->
//! ```
//!
//! Each class is carved out of slabs. A slab is a run of chunks aligned to its own size, so the
//! first chunk of a slab is found by masking a chunk index. Bigger blocks get bigger slabs. That
//! keeps at least eight blocks in every slab and the unusable tail of a slab under an eighth of it.
//!
-//! | Block size | Slab | Blocks per slab |
-//! | ----------------- | ----------- | --------------- |
-//! | 16 B to 8 KiB | 64 KiB (1) | 8 to 4096 |
-//! | 8 KiB to 64 KiB | 512 KiB (8) | 8 to 56 |
-//! | 64 KiB to 512 KiB | 4 MiB (64) | 8 to 56 |
+//! | Block size | Slab | Blocks per slab |
+//! | --------------- | ----------- | --------------- |
+//! | 16 B to 8 KiB | 64 KiB (1) | 8 to 4096 |
+//! | 8 KiB to 64 KiB | 512 KiB (8) | 8 to 56 |
//!
-//! Anything larger than 512 KiB is a huge request, which gets a run of whole chunks of its own.
+//! Anything larger than 64 KiB is a huge request, which gets a run of whole chunks of its own,
+//! as jemalloc gives large requests extents of their own. A slab of bigger blocks would hold so
+//! few of them that one partly used slab per class and heap would cost more than rounding up to
+//! whole chunks does.
//!
//! # Alignment
//!
-//! Every class size is a multiple of 16 and a slab starts on a multiple of its own size, so every
-//! block is 16-byte aligned for free. A request for more alignment is rounded up to a power of two
-//! that is at least as large as the alignment. A block of such a class starts at a multiple of its
-//! size, which is therefore a multiple of the alignment. Huge allocations start on a chunk
-//! boundary, so the largest supported alignment is one chunk.
-
-use core::alloc::Layout;
+//! A slab starts on a multiple of its own size and a block on a multiple of its size within the
+//! slab, so a block is aligned to the largest power of two that divides its size. Every class is a
+//! multiple of 8, so every block is 8-byte aligned. A request that asks for 16, which C's malloc
+//! always does, is rounded up to a multiple of 16 first. A request for more alignment is rounded
+//! up to a power of two that is at least as large as the alignment. Huge allocations start on a
+//! chunk boundary, so the largest supported alignment is one chunk.
use crate::chunks::CHUNK_SIZE;
+use core::alloc::Layout;
-/// The alignment every block has regardless of its class.
+/// The alignment that C's malloc promises, which a request gets unless its layout asks for less.
pub(crate) const MIN_ALIGN: usize = 16;
+/// How far apart the classes up to [`LINEAR_LIMIT`] are, which is also the alignment every block
+/// has.
+pub(crate) const STEP: usize = 8;
+
/// The largest alignment the allocator supports, which is one chunk.
pub const MAX_ALIGN: usize = CHUNK_SIZE;
/// The largest block served from a slab. Bigger requests are huge allocations.
-pub const MAX_SMALL: usize = 512 << 10;
+pub const MAX_SMALL: usize = 64 << 10;
+
+/// The largest block that a heap may reuse when another heap owns it. See
+/// [`Class::reusable_anywhere`].
+const ANYWHERE_MAX: usize = 256;
/// Requests of up to this many bytes are classified by a table lookup.
pub(crate) const TABLE_MAX: usize = 8192;
-/// The number of size classes.
-pub(crate) const CLASSES: usize = 104;
+/// The number of size classes: fifteen up to 128 bytes, and eight per doubling up to
+/// [`MAX_SMALL`].
+pub(crate) const CLASSES: usize =
+ LINEAR_CLASSES + 8 * (MAX_SMALL.ilog2() - LINEAR_LIMIT.ilog2()) as usize;
-/// Classes up to this many bytes advance in steps of 16.
+/// Classes up to this many bytes advance in steps of [`STEP`].
const LINEAR_LIMIT: usize = 128;
+/// The smallest class. A slab's bitmap has room for the blocks of a single chunk of it.
+const SMALLEST: usize = 16;
+
+/// How many classes there are up to [`LINEAR_LIMIT`].
+const LINEAR_CLASSES: usize = (LINEAR_LIMIT - SMALLEST) / STEP + 1;
+
/// A size class, which is an index into the table of block sizes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct Class(u8);
@@ -67,10 +86,10 @@ pub(crate) enum Request {
/// The block size of class index `i`.
const fn block_size_of(i: usize) -> usize {
- if i < LINEAR_LIMIT / MIN_ALIGN {
- return (i + 1) * MIN_ALIGN;
+ if i < LINEAR_CLASSES {
+ return SMALLEST + i * STEP;
}
- let (doubling, step) = ((i - 8) / 8, (i - 8) % 8);
+ let (doubling, step) = ((i - LINEAR_CLASSES) / 8, (i - LINEAR_CLASSES) % 8);
let top_bit = doubling + 7;
(1 << top_bit) + (step + 1) * (1 << (top_bit - 3))
}
@@ -90,8 +109,8 @@ const BLOCK_SIZES: [u32; CLASSES] = {
const LINE: usize = if cfg!(target_arch = "aarch64") { 128 } else { 64 };
/// How many block pointers a heap's bin of class index `i` starts out holding at most. Small blocks
-/// get many and big blocks few, so that a full bin of a small class holds about 32 KiB and one of a
-/// class above 8 KiB about 64 KiB.
+/// get many and big blocks few, so that a full bin holds up to 32 KiB of blocks, but at least 8 and
+/// at most 128 of them, and one of a class above 8 KiB up to 64 KiB, between 1 and 8 of them.
const fn bin_initial_of(i: usize) -> usize {
let size = block_size_of(i);
if size <= TABLE_MAX {
@@ -102,12 +121,12 @@ const fn bin_initial_of(i: usize) -> usize {
}
/// How many block pointers the bin of class index `i` may grow to hold. A bin grows when the
-/// program alternates between emptying it and filling it, so that bursts of a few hundred blocks
+/// program alternates between emptying it and filling it, so that bursts of a few thousand blocks
/// stay in the bin, as TCMalloc grows its per-CPU caches.
const fn bin_max_of(i: usize) -> usize {
let size = block_size_of(i);
if size <= TABLE_MAX {
- clamp((128 << 10) / size, 8, 512)
+ clamp((128 << 10) / size, 8, 2048)
} else {
clamp((128 << 10) / size, 1, 16)
}
@@ -166,22 +185,27 @@ const RECIPROCALS: [u64; CLASSES] = {
table
};
-/// The class of every size up to [`TABLE_MAX`], indexed by the size in 16-byte steps rounded up.
-const TABLE: [u8; TABLE_MAX / MIN_ALIGN + 1] = {
- let mut table = [0; TABLE_MAX / MIN_ALIGN + 1];
+/// How many entries the class table has: one for every [`STEP`] up to [`TABLE_MAX`].
+pub(crate) const TABLE_STEPS: usize = TABLE_MAX / STEP + 1;
+
+/// The class of every size up to [`TABLE_MAX`], indexed by the size in steps of [`STEP`] rounded
+/// up.
+const TABLE: [u8; TABLE_STEPS] = {
+ let mut table = [0; TABLE_STEPS];
let mut step = 0;
while step < table.len() {
- table[step] = Class::for_size(step * MIN_ALIGN).0;
+ table[step] = Class::for_size(step * STEP).0;
step += 1;
}
table
};
impl Class {
- /// The class of a request that [`Class`::is_table_request] accepts.
+ /// The class of a size of at most [`TABLE_MAX`], for a request that needs no more than 8 bytes
+ /// of alignment, or for one that needs 16 once the size is rounded up to a multiple of 16.
#[inline(always)]
pub(crate) const fn from_table(size: usize) -> Self {
- Self(TABLE[size.div_ceil(MIN_ALIGN)])
+ Self(TABLE[size.div_ceil(STEP)])
}
/// Whether the layout is small and aligned loosely enough to be classified by the table,
@@ -211,12 +235,12 @@ impl Class {
pub(crate) const fn for_size(size: usize) -> Self {
debug_assert!(size <= MAX_SMALL);
if size <= LINEAR_LIMIT {
- return Self(size.saturating_sub(1).div_euclid(MIN_ALIGN) as u8);
+ return Self(size.saturating_sub(SMALLEST).div_ceil(STEP) as u8);
}
let below = size - 1;
let top_bit = (usize::BITS - 1 - below.leading_zeros()) as usize;
let step = (below >> (top_bit - 3)) & 7;
- Self((8 + (top_bit - 7) * 8 + step) as u8)
+ Self((LINEAR_CLASSES + (top_bit - 7) * 8 + step) as u8)
}
/// How many block pointers the bin of this class holds when a heap starts.
@@ -240,11 +264,13 @@ impl Class {
/// That needs two things. A block must not share a cache line with any other block, or the
/// thread that reuses it would write next to a block that its owner still uses, which is the
/// false sharing that Hoard's ownership rule exists to prevent. Blocks start at multiples of
- /// their size, so a size that is a multiple of the line width is enough. And a block must not
- /// pin much memory while a foreign heap holds it, so only classes with one-chunk slabs qualify.
+ /// their size, so a size that is a multiple of the line width is enough. And the block must
+ /// span few lines. Its lines are likely still in the cache of the owner, which wrote them, and
+ /// a thread on another core that reuses the block pulls each line it writes across, where the
+ /// owner would find them at hand. For a few lines that costs less than sending the block home.
pub(crate) const fn reusable_anywhere(self) -> bool {
let size = self.block_size();
- size.is_multiple_of(LINE) && size <= TABLE_MAX
+ size.is_multiple_of(LINE) && size <= ANYWHERE_MAX
}
/// The position of this class in per-heap tables.
@@ -263,17 +289,10 @@ impl Class {
((offset as u64 * RECIPROCALS[self.0 as usize]) >> 32) as usize
}
- /// How many chunks one slab of this class spans, which is 1, 8 or 64. Slabs are aligned to this
+ /// How many chunks one slab of this class spans, which is 1 or 8. Slabs are aligned to this
/// many chunks.
pub(crate) const fn slab_chunks(self) -> usize {
- let size = self.block_size();
- if size <= 8192 {
- 1
- } else if size <= 65536 {
- 8
- } else {
- 64
- }
+ if self.block_size() <= TABLE_MAX { 1 } else { 8 }
}
/// How many blocks fit in one slab.
@@ -292,8 +311,10 @@ pub(crate) const fn classify(layout: Layout) -> Option {
return Some(Request::Huge { chunks: size.div_ceil(CHUNK_SIZE) });
}
// Over-aligned blocks come from power-of-two classes, as the module documentation explains.
- let size = if align <= MIN_ALIGN {
+ let size = if align <= STEP {
size
+ } else if align == MIN_ALIGN {
+ size.next_multiple_of(MIN_ALIGN)
} else {
let rounded = size.next_power_of_two();
if rounded > align { rounded } else { align }
@@ -313,14 +334,15 @@ mod test {
fn the_table_is_strictly_increasing_and_spans_the_range() {
let sizes: std::vec::Vec<_> =
(0..CLASSES).map(|i| Class::from_index(i).block_size()).collect();
- assert_eq!((sizes[0], sizes[CLASSES - 1]), (MIN_ALIGN, MAX_SMALL));
+ assert_eq!((sizes[0], sizes[CLASSES - 1]), (SMALLEST, MAX_SMALL));
assert!(sizes.windows(2).all(|pair| pair[0] < pair[1]));
- assert!(sizes.iter().all(|size| size % MIN_ALIGN == 0));
+ assert!(sizes.iter().all(|size| size % STEP == 0));
+ assert!(sizes[LINEAR_CLASSES..].iter().all(|size| size % MIN_ALIGN == 0));
}
#[test]
fn for_size_picks_the_smallest_class_that_fits() {
- // Every size below 512 KiB is cheap to check, and Miri takes a sample.
+ // Every small size is cheap to check, and Miri takes a sample.
let step = if cfg!(miri) { 997 } else { 1 };
for size in (1..=MAX_SMALL).step_by(step) {
let class = Class::for_size(size);
@@ -401,6 +423,18 @@ mod test {
}
}
}
+ #[test]
+ fn requests_for_sixteen_bytes_of_alignment_get_classes_that_keep_it() {
+ for size in 1..=TABLE_MAX {
+ let Some(Request::Small(class)) = classify(layout(size, MIN_ALIGN)) else { panic!() };
+ assert_eq!(class.block_size() % MIN_ALIGN, 0, "{size}");
+ assert_eq!(Class::from_table(size.next_multiple_of(MIN_ALIGN)), class);
+ let Some(Request::Small(loose)) = classify(layout(size, STEP)) else { panic!() };
+ assert!(loose.block_size() <= class.block_size());
+ assert_eq!(Class::from_table(size), loose);
+ }
+ assert_eq!(Class::for_size(24).block_size(), 24, "three words fill their block");
+ }
#[test]
fn the_small_and_huge_boundary_is_exact() {
@@ -408,7 +442,7 @@ mod test {
classify(layout(MAX_SMALL, 1)),
Some(Request::Small(Class::from_index(CLASSES - 1)))
);
- assert_eq!(classify(layout(MAX_SMALL + 1, 1)), Some(Request::Huge { chunks: 9 }));
+ assert_eq!(classify(layout(MAX_SMALL + 1, 1)), Some(Request::Huge { chunks: 2 }));
assert_eq!(
classify(layout(CHUNK_SIZE, 1)),
Some(Request::Small(Class::for_size(CHUNK_SIZE)))
diff --git a/crates/bcmalloc/src/slab.rs b/crates/bcmalloc/src/slab.rs
index 431c223..f03d8f1 100644
--- a/crates/bcmalloc/src/slab.rs
+++ b/crates/bcmalloc/src/slab.rs
@@ -32,9 +32,8 @@
//! bins or in a message on the way back, so a slab is only released when every block has really
//! come home.
-use core::{cell::Cell, ptr};
-
use crate::{cache::CacheLine, size_class::Class};
+use core::{cell::Cell, ptr};
/// A free block seen as a link, which is how a single block travels to its owner's inbox. Blocks
/// are at least 16 bytes.
@@ -75,8 +74,14 @@ pub(crate) struct Slab {
capacity: Cell,
/// No word of the bitmap below this one has a bit set.
cursor: Cell,
+ /// Blocks from this index on have never been handed out since the slab was set up on memory
+ /// that read as zeros, so they still hold zeros. It is the capacity if the memory was not
+ /// zero.
+ zero_from: Cell,
class: Cell,
list: Cell,
+ /// Whether every block has been handed out once since the slab was set up.
+ filled: Cell,
bits: [Cell; BITMAP_WORDS],
}
@@ -103,8 +108,10 @@ impl Slab {
free_len: Cell::new(0),
capacity: Cell::new(0),
cursor: Cell::new(0),
+ zero_from: Cell::new(0),
class: Cell::new(0),
list: Cell::new(List::None),
+ filled: Cell::new(false),
bits: [const { Cell::new(0) }; BITMAP_WORDS],
}
}
@@ -131,12 +138,13 @@ impl<'a> Owned<'a> {
}
/// Prepares an unused descriptor for a fresh slab of `class` whose first block is at `start`,
- /// with every block free.
+ /// with every block free. `zeroed` says that the slab's memory reads as zeros.
///
/// # Safety
///
- /// `start` must point to a slab-sized, suitably aligned region that nothing else uses.
- pub(crate) unsafe fn init(self, class: Class, start: *mut u8) {
+ /// `start` must point to a slab-sized, suitably aligned region that nothing else uses, and
+ /// that is all zeros if `zeroed`.
+ pub(crate) unsafe fn init(self, class: Class, start: *mut u8, zeroed: bool) {
let slab = self.0;
let capacity = class.blocks_per_slab();
debug_assert!(capacity <= MAX_BLOCKS);
@@ -146,8 +154,10 @@ impl<'a> Owned<'a> {
slab.free_len.set(capacity as u32);
slab.capacity.set(capacity as u32);
slab.cursor.set(0);
+ slab.zero_from.set(if zeroed { 0 } else { capacity as u16 });
slab.class.set(class.index() as u8);
slab.list.set(List::None);
+ slab.filled.set(false);
for (index, word) in slab.bits.iter().enumerate() {
let below = capacity.saturating_sub(index * 64);
word.set(if below >= 64 { u64::MAX } else { (1 << below) - 1 });
@@ -174,6 +184,17 @@ impl<'a> Owned<'a> {
self.0.free_len.get() == 0
}
+ /// Records that every block has been handed out, and returns whether this is the first time
+ /// since the slab was set up.
+ pub(crate) const fn mark_filled(self) -> bool {
+ !self.0.filled.replace(true)
+ }
+
+ /// Whether every block has been handed out at some point since the slab was set up.
+ pub(crate) const fn was_filled(self) -> bool {
+ self.0.filled.get()
+ }
+
/// The list this slab is on.
pub(crate) const fn list(self) -> List {
self.0.list.get()
@@ -224,6 +245,7 @@ impl<'a> Owned<'a> {
let (start, size) = (slab.start.get(), self.class().block_size());
let mut word = usize::from(slab.cursor.get());
let mut taken = 0;
+ let mut last = 0;
while taken < want {
let mut bits = slab.bits[word].get();
if bits == u64::MAX && want - taken >= 64 {
@@ -236,6 +258,7 @@ impl<'a> Owned<'a> {
}
slab.bits[word].set(0);
taken += 64;
+ last = word * 64 + 63;
word += 1;
continue;
}
@@ -245,6 +268,7 @@ impl<'a> Owned<'a> {
out(unsafe { start.add(index * size) });
bits &= bits - 1;
taken += 1;
+ last = index;
}
slab.bits[word].set(bits);
if bits == 0 {
@@ -253,9 +277,23 @@ impl<'a> Owned<'a> {
}
slab.cursor.set(word.min(BITMAP_WORDS - 1) as u16);
slab.free_len.set(slab.free_len.get() - taken as u32);
+ if taken != 0 {
+ // Blocks come out lowest first, so everything handed out lies below the last one.
+ slab.zero_from.set(slab.zero_from.get().max(last as u16 + 1));
+ }
taken
}
+ /// Hands out the lowest free block, and whether it still holds the zeros of fresh memory.
+ pub(crate) fn take_one(self) -> Option<(*mut u8, bool)> {
+ let zero_from = usize::from(self.0.zero_from.get());
+ let mut block = None;
+ self.take(1, |taken| block = Some(taken));
+ let block = block?;
+ let index = (block.addr() - self.start().addr()) / self.class().block_size();
+ Some((block, index >= zero_from))
+ }
+
/// Checks that the bitmap agrees with the counters and has no bit set below the cursor or
/// past the last block, and returns how many blocks are free.
#[cfg(any(test, feature = "testing"))]
@@ -364,12 +402,10 @@ impl<'a> Returns<'a> {
#[cfg(all(test, not(loom)))]
mod test {
- use std::vec::Vec;
-
- use core::mem::{align_of, size_of};
-
use super::*;
use crate::testing::Buffer;
+ use core::mem::{align_of, size_of};
+ use std::vec::Vec;
#[test]
fn a_descriptor_fills_whole_cache_lines() {
@@ -397,7 +433,7 @@ mod test {
let memory = Buffer::new(class.slab_chunks() << crate::chunks::CHUNK_SHIFT);
let slab = Slab::new();
// SAFETY: the buffer is slab sized and aligned, and ours alone.
- unsafe { slab.owned().init(class, memory.as_ptr()) };
+ unsafe { slab.owned().init(class, memory.as_ptr(), true) };
Self { slab, _memory: memory }
}
@@ -415,7 +451,7 @@ mod test {
#[test]
fn a_fresh_slab_yields_every_block_once_in_address_order() {
- for size in [16, 48, 1024, 3000, 100_000] {
+ for size in [16, 48, 1024, 3000, 60_000] {
let fixture = Fixture::new(size);
let capacity = Class::for_size(size).blocks_per_slab();
let blocks = fixture.take(usize::MAX);
diff --git a/crates/bcmalloc/src/sync.rs b/crates/bcmalloc/src/sync.rs
index 8f99912..c467cc6 100644
--- a/crates/bcmalloc/src/sync.rs
+++ b/crates/bcmalloc/src/sync.rs
@@ -4,12 +4,11 @@
//! instrumented versions, so the model checker can explore every interleaving of the lock-free
//! code without that code knowing the difference.
-#[cfg(loom)]
-pub(crate) use loom::sync::atomic::{
- AtomicBool, AtomicPtr, AtomicU64, AtomicUsize, Ordering, fence,
-};
-
#[cfg(not(loom))]
pub(crate) use core::sync::atomic::{
AtomicBool, AtomicPtr, AtomicU64, AtomicUsize, Ordering, fence,
};
+#[cfg(loom)]
+pub(crate) use loom::sync::atomic::{
+ AtomicBool, AtomicPtr, AtomicU64, AtomicUsize, Ordering, fence,
+};
diff --git a/crates/bcmalloc/src/sys.rs b/crates/bcmalloc/src/sys.rs
index e805145..5e3d8cd 100644
--- a/crates/bcmalloc/src/sys.rs
+++ b/crates/bcmalloc/src/sys.rs
@@ -120,6 +120,9 @@ pub(crate) unsafe fn lock(ptr: NonNull, len: usize) -> bool {
}
}
+/// Whether pages that [`discard`] gave back read as zeros when next touched.
+pub(crate) const DISCARD_ZEROES: bool = cfg!(all(target_os = "linux", not(miri)));
+
/// Tells the kernel the contents of the range are no longer needed, so it may reclaim the physical
/// pages. The range stays mapped and usable. Reading it afterwards returns zeros on Linux and
/// either the old contents or zeros on macOS.
diff --git a/crates/bcmalloc/src/testing.rs b/crates/bcmalloc/src/testing.rs
index 41311e5..9bbeba8 100644
--- a/crates/bcmalloc/src/testing.rs
+++ b/crates/bcmalloc/src/testing.rs
@@ -3,14 +3,6 @@
//! This module only exists in test builds and behind the `testing` feature, so none of it is part
//! of the allocator.
-use core::{alloc::Layout, cell::Cell, ptr, ptr::NonNull};
-use std::{
- alloc::{alloc, dealloc},
- boxed::Box,
- collections::BTreeMap,
- vec::Vec,
-};
-
use crate::{
chunks::{CHUNK_SHIFT, Chunks},
heap::{Heap, HeapData},
@@ -19,6 +11,13 @@ use crate::{
slab::{Block, Slab},
sync::AtomicU64,
};
+use core::{alloc::Layout, cell::Cell, ptr, ptr::NonNull};
+use std::{
+ alloc::{alloc_zeroed, dealloc},
+ boxed::Box,
+ collections::BTreeMap,
+ vec::Vec,
+};
/// A small, fast, deterministic random number generator (xorshift64*).
///
@@ -93,7 +92,7 @@ pub(crate) struct Buffer {
layout: Layout,
}
-/// The alignment of the largest slab, which is 64 chunks of 64 KiB.
+/// The alignment of the managed memory, one bitmap word of 64 chunks of 64 KiB.
pub(crate) const SLAB_ALIGN: usize = 4 << 20;
impl Buffer {
@@ -101,7 +100,7 @@ impl Buffer {
pub(crate) fn new(size: usize) -> Self {
let layout = Layout::from_size_align(size, SLAB_ALIGN).expect("valid test layout");
// SAFETY: the layout has a non-zero size.
- let ptr = NonNull::new(unsafe { alloc(layout) }).expect("test allocation failed");
+ let ptr = NonNull::new(unsafe { alloc_zeroed(layout) }).expect("test allocation failed");
Self { ptr, layout }
}
@@ -135,6 +134,7 @@ pub struct TestRegion {
memory: Buffer,
chunks: usize,
nodes: usize,
+ huge_zone: bool,
}
impl TestRegion {
@@ -157,6 +157,7 @@ impl TestRegion {
memory: Buffer::new(chunks << CHUNK_SHIFT),
chunks,
nodes: 1,
+ huge_zone: false,
}
}
}
@@ -167,6 +168,13 @@ impl TestRegion {
Self { nodes, ..Self::new(chunks, heaps) }
}
+ /// This region with the part of every node split into a zone for small pages and one for
+ /// transparent huge pages, as on Linux.
+ #[must_use]
+ pub fn with_huge_zone(self) -> Self {
+ Self { huge_zone: true, ..self }
+ }
+
/// The region over this storage.
pub fn region(&self) -> Region<'_> {
// SAFETY: the buffer is 4 MiB aligned and `chunks` chunks long, and everything else was
@@ -180,8 +188,8 @@ impl TestRegion {
map: &self.map,
heaps: &self.heaps,
bin_slots: self.bins.as_ptr().cast::<*mut Block>().cast_mut(),
- purge_granule: 1,
nodes: self.nodes,
+ huge_zone: self.huge_zone,
})
}
}
@@ -245,11 +253,29 @@ impl<'r> Harness<'r> {
/// Allocates through heap number `heap` (wrapping) and returns whether it succeeded.
pub fn alloc(&mut self, heap: usize, size: usize, align: usize) -> bool {
+ self.alloc_with(heap, size, align, false)
+ }
+
+ /// As [`alloc`](Self::alloc), but asks for zeroed memory and checks that it is.
+ pub fn alloc_zeroed(&mut self, heap: usize, size: usize, align: usize) -> bool {
+ self.alloc_with(heap, size, align, true)
+ }
+
+ fn alloc_with(&mut self, heap: usize, size: usize, align: usize, zeroed: bool) -> bool {
let layout = Layout::from_size_align(size, align).expect("valid layout");
let heap = heap % self.heaps.len();
- let Some(ptr) = self.heaps[heap].alloc(layout) else { return false };
+ let heap = &self.heaps[heap];
+ let Some(ptr) = (if zeroed { heap.alloc_zeroed(layout) } else { heap.alloc(layout) })
+ else {
+ return false;
+ };
assert_eq!(ptr.as_ptr().addr() % align, 0, "misaligned block for {layout:?}");
assert!(self.region.contains(ptr.as_ptr()), "block outside the region");
+ if zeroed {
+ // SAFETY: the block is ours and holds `size` bytes.
+ let bytes = unsafe { core::slice::from_raw_parts(ptr.as_ptr(), size) };
+ assert!(bytes.iter().all(|&byte| byte == 0), "a zeroed block of {size} bytes has data");
+ }
self.stamp = self.stamp.wrapping_add(1);
self.track(ptr, size);
// SAFETY: the block is ours and holds `size` bytes.
@@ -273,6 +299,19 @@ impl<'r> Harness<'r> {
true
}
+ /// As [`free`](Self::free), but without the layout, as C's `free` does.
+ pub fn free_unsized(&mut self, heap: usize, victim: usize) -> bool {
+ if self.live.is_empty() {
+ return false;
+ }
+ let block = self.live.swap_remove(victim % self.live.len());
+ Self::verify(&block, block.layout.size());
+ self.spans.remove(&block.ptr.as_ptr().addr());
+ // SAFETY: as in `free`.
+ unsafe { self.heaps[heap % self.heaps.len()].free_unsized(block.ptr) };
+ true
+ }
+
/// Reallocates a live block to `new_size` through heap `heap`. Returns false if nothing is
/// live.
pub fn realloc(&mut self, heap: usize, victim: usize, new_size: usize) -> bool {
@@ -416,11 +455,15 @@ pub fn random_traffic(region: &Region<'_>, seed: u64, steps: usize) {
let mut harness = Harness::new(region, 3);
for step in 0..steps {
let heap = rng.below(3);
- match rng.below(21) {
+ match rng.below(23) {
0..=9 => {
let widest = if rng.below(8) == 0 { 17 } else { 5 };
let align = 1 << rng.below(widest);
- harness.alloc(heap, random_size(&mut rng), align);
+ if rng.below(4) == 0 {
+ harness.alloc_zeroed(heap, random_size(&mut rng), align);
+ } else {
+ harness.alloc(heap, random_size(&mut rng), align);
+ }
}
10..=16 => {
harness.free(heap, rng.below(1 << 20));
@@ -428,7 +471,10 @@ pub fn random_traffic(region: &Region<'_>, seed: u64, steps: usize) {
17..=18 => {
harness.realloc(heap, rng.below(1 << 20), random_size(&mut rng));
}
- 19 => harness.flush(heap),
+ 19..=20 => {
+ harness.free_unsized(heap, rng.below(1 << 20));
+ }
+ 21 => harness.flush(heap),
_ => harness.recycle(heap),
}
// The check walks every list, which Miri does slowly, so it samples there.
@@ -462,11 +508,19 @@ fn interpret(harness: &mut Harness<'_>, bytes: &mut impl Iterator- )
0..=7 => {
let limit = [256, 4 << 10, 600 << 10, 6 << 20][bytes.next()? % 4];
let size = (bytes.next()? | bytes.next()? << 8 | bytes.next()? << 16) % limit + 1;
- harness.alloc(heap, size, 1 << (bytes.next()? % 18));
+ let align = 1 << (bytes.next()? % 18);
+ if op % 16 < 6 {
+ harness.alloc(heap, size, align);
+ } else {
+ harness.alloc_zeroed(heap, size, align);
+ }
}
- 8..=11 => {
+ 8..=10 => {
harness.free(heap, bytes.next()? | bytes.next()? << 8);
}
+ 11 => {
+ harness.free_unsized(heap, bytes.next()? | bytes.next()? << 8);
+ }
12..=13 => {
let size =
(bytes.next()? | bytes.next()? << 8 | bytes.next()? << 16) % (1 << 20) + 1;
diff --git a/crates/bcmalloc/src/tls.rs b/crates/bcmalloc/src/tls.rs
index 1cf9832..0a3cbbb 100644
--- a/crates/bcmalloc/src/tls.rs
+++ b/crates/bcmalloc/src/tls.rs
@@ -30,9 +30,8 @@
//! free. The slot is empty by then, and binding a new heap would hand a claim to a thread that will
//! never release it. [`exiting`] tells the slow path to use a temporary heap instead.
-use core::{cell::Cell, ffi::c_void, ptr};
-
use crate::heap::HeapData;
+use core::{cell::Cell, ffi::c_void, ptr};
/// A POSIX thread-specific key.
pub(crate) type Key = usize;
@@ -86,15 +85,15 @@ pub(crate) fn delete_key(key: Key) {
unsafe { libc::pthread_key_delete(key as _) };
}
-/// The heap that this thread bound under the key, or null.
+/// The heap that this thread bound under the key.
#[inline(always)]
-pub(crate) fn get(key: Key) -> *const HeapData {
+pub(crate) fn get(key: Key) -> Option<&'static HeapData> {
slot::get(key)
}
/// As [`get`], but where the fast lookup cannot tell, it asks pthread. The fast paths call [`get`]
/// and come here only when that returns null, so they make no call of their own.
-pub(crate) fn lookup(key: Key) -> *const HeapData {
+pub(crate) fn lookup(key: Key) -> Option<&'static HeapData> {
slot::lookup(key)
}
@@ -127,10 +126,9 @@ unsafe extern "C" fn release_heap(value: *mut c_void) {
not(bcmalloc_portable_tls)
))]
mod slot {
- use core::{arch::asm, ptr};
-
use super::Key;
use crate::heap::HeapData;
+ use core::{arch::asm, ptr};
/// The table of this thread's key slots.
#[inline(always)]
@@ -148,8 +146,9 @@ mod slot {
ptr::with_exposed_provenance(register & !7)
}
+ /// The value in the key's slot of the table, which may be null.
#[inline(always)]
- pub(super) fn get(key: Key) -> *const HeapData {
+ fn read(key: Key) -> *const HeapData {
if key == super::NO_KEY {
return ptr::null();
}
@@ -158,7 +157,14 @@ mod slot {
unsafe { *table().add(key) }
}
- pub(super) fn lookup(key: Key) -> *const HeapData {
+ #[inline(always)]
+ pub(super) fn get(key: Key) -> Option<&'static HeapData> {
+ // SAFETY: only bind stores values under a key, and they are heap slots of regions that
+ // live for the rest of the program.
+ unsafe { read(key).as_ref() }
+ }
+
+ pub(super) fn lookup(key: Key) -> Option<&'static HeapData> {
get(key)
}
@@ -172,7 +178,7 @@ mod slot {
let marker: *const u8 = &raw const MARKER;
// SAFETY: the key is fresh, so nothing else uses its slot on this thread.
unsafe { libc::pthread_setspecific(key as _, marker.cast()) };
- let found = get(key).cast::() == marker;
+ let found = read(key).cast::() == marker;
// SAFETY: as above. Clearing the slot keeps the destructor from running on the marker.
unsafe { libc::pthread_setspecific(key as _, ptr::null()) };
found
@@ -186,34 +192,40 @@ mod slot {
not(bcmalloc_portable_tls)
)))]
mod slot {
- use core::{cell::Cell, ptr};
-
use super::Key;
use crate::heap::HeapData;
+ use core::{cell::Cell, ptr};
+
+ /// The key of an empty slot, which no allocator has. Pthread keys are small, and an allocator
+ /// without one has [`NO_KEY`](super::NO_KEY).
+ const EMPTY: Key = super::NO_KEY - 1;
thread_local! {
/// The key and heap this thread used last. A thread that serves several allocators keeps
- /// only the latest here, and pthread remembers the others.
- static CURRENT: Cell<(Key, *const HeapData)> = const { Cell::new((0, ptr::null())) };
+ /// only the latest here, and pthread remembers the others. A slot whose key matches always
+ /// holds a heap.
+ static CURRENT: Cell<(Key, *const HeapData)> = const { Cell::new((EMPTY, ptr::null())) };
}
#[inline(always)]
- pub(super) fn get(key: Key) -> *const HeapData {
+ pub(super) fn get(key: Key) -> Option<&'static HeapData> {
let (bound, data) = CURRENT.with(Cell::get);
- if bound == key { data } else { ptr::null() }
+ // SAFETY: only `set` stores a key that an allocator has, and it stores a heap slot of a
+ // region that lives for the rest of the program with it. A matching key thus needs no null
+ // check of its own.
+ (bound == key).then(|| unsafe { &*data })
}
/// Looks the heap up through pthread and makes it the latest.
- pub(super) fn lookup(key: Key) -> *const HeapData {
+ pub(super) fn lookup(key: Key) -> Option<&'static HeapData> {
if key == super::NO_KEY {
- return ptr::null();
- }
- // SAFETY: the key was created by create_key.
- let data = unsafe { libc::pthread_getspecific(key as _) }.cast::().cast_const();
- if !data.is_null() {
- CURRENT.with(|current| current.set((key, data)));
+ return None;
}
- data
+ // SAFETY: the key was created by create_key, and only bind stores values under it, which
+ // are heap slots of regions that live for the rest of the program.
+ let data = unsafe { libc::pthread_getspecific(key as _).cast::().as_ref() }?;
+ CURRENT.with(|current| current.set((key, ptr::from_ref(data))));
+ Some(data)
}
pub(super) fn set(key: Key, data: &HeapData) {
@@ -221,7 +233,7 @@ mod slot {
}
pub(super) fn clear() {
- CURRENT.with(|current| current.set((0, ptr::null())));
+ CURRENT.with(|current| current.set((EMPTY, ptr::null())));
}
pub(super) const fn probe(_key: Key) -> bool {
@@ -231,24 +243,23 @@ mod slot {
#[cfg(all(test, not(loom)))]
mod test {
- use std::thread;
-
use super::*;
use crate::testing::TestRegion;
+ use std::thread;
#[test]
fn a_thread_finds_the_heap_it_bound_and_others_do_not() {
let test = TestRegion::new(8, 2);
let region = test.region();
let key = create_key().expect("a key");
- assert!(get(key).is_null());
+ assert!(get(key).is_none());
let data = region.heap().expect("a free heap").leak();
// SAFETY: the test keeps the region alive for as long as the heap is bound.
assert!(bind(key, unsafe { &*ptr::from_ref(data) }));
- assert_eq!(get(key), ptr::from_ref(data));
+ assert_eq!(get(key).map(ptr::from_ref), Some(ptr::from_ref(data)));
thread::scope(|scope| {
- scope.spawn(|| assert!(get(key).is_null()));
+ scope.spawn(|| assert!(get(key).is_none()));
});
// Unbind without running the destructor on this long-lived thread.
@@ -277,7 +288,7 @@ mod test {
assert!(!exiting());
// SAFETY: the test keeps the region alive until the thread has been joined.
assert!(bind(key, unsafe { &*handoff.0 }));
- assert_eq!(get(key), handoff.0);
+ assert_eq!(get(key).map(ptr::from_ref), Some(handoff.0));
})
.join()
.unwrap();
diff --git a/crates/bcmalloc/tests/global.rs b/crates/bcmalloc/tests/global.rs
index d98e8a0..8a9b99e 100644
--- a/crates/bcmalloc/tests/global.rs
+++ b/crates/bcmalloc/tests/global.rs
@@ -3,14 +3,13 @@
#![cfg(not(miri))]
+use bcmalloc::{Bcmalloc, Commit, Config};
use std::{
collections::{BTreeMap, HashMap},
sync::mpsc,
thread,
};
-use bcmalloc::{Bcmalloc, Commit, Config};
-
#[global_allocator]
static GLOBAL: Bcmalloc =
Bcmalloc::with_config(Config::new().capacity(16 << 30).max_heaps(256).commit(Commit::Lazy));
diff --git a/crates/bench-apps/benches/common/channels.rs b/crates/bench-apps/benches/common/channels.rs
index 9f0a4a3..6430a76 100644
--- a/crates/bench-apps/benches/common/channels.rs
+++ b/crates/bench-apps/benches/common/channels.rs
@@ -5,12 +5,10 @@
//! runtime moves tasks between its worker threads, so most messages are freed on a different thread
//! than the one that allocated them, as they are in a pipeline of async services.
+use super::{Pass, Scale, text::Rng, twice};
use std::time::Instant;
-
use tokio::{sync::mpsc, task::JoinSet};
-use super::{Pass, Scale, text::Rng, twice};
-
const WORKERS: usize = 4;
const SOURCES: usize = 4;
const SINKS: usize = 4;
diff --git a/crates/bench-apps/benches/common/http.rs b/crates/bench-apps/benches/common/http.rs
index 084a0db..8a3e99d 100644
--- a/crates/bench-apps/benches/common/http.rs
+++ b/crates/bench-apps/benches/common/http.rs
@@ -6,8 +6,11 @@
//! client parses that too. Every pass starts its own runtime and server and shuts both down, and
//! the clock covers only the requests.
-use std::{convert::Infallible, net::SocketAddr, time::Instant};
-
+use super::{
+ Pass, Scale,
+ text::{Rng, WORDS},
+ twice,
+};
use http_body_util::{BodyExt, Full};
use hyper::{
Request, Response,
@@ -18,18 +21,13 @@ use hyper::{
};
use hyper_util::rt::TokioIo;
use serde::{Deserialize, Serialize};
+use std::{convert::Infallible, net::SocketAddr, time::Instant};
use tokio::{
net::{TcpListener, TcpStream},
sync::watch,
task::JoinSet,
};
-use super::{
- Pass, Scale,
- text::{Rng, WORDS},
- twice,
-};
-
const WORKERS: usize = 4;
const CONNECTIONS: usize = 8;
diff --git a/crates/bench-apps/benches/common/json.rs b/crates/bench-apps/benches/common/json.rs
index ab1d0a8..4a6e011 100644
--- a/crates/bench-apps/benches/common/json.rs
+++ b/crates/bench-apps/benches/common/json.rs
@@ -5,16 +5,14 @@
//! result, and then does the same through derived structs. Like a service that reshapes documents,
//! it keeps the previous iteration's output alive while it builds the next one.
-use std::{fmt::Write, time::Instant};
-
-use serde::{Deserialize, Serialize};
-use serde_json::{Map, Value, json};
-
use super::{
Pass, Scale,
text::{Rng, WORDS, capitalized, push_words},
twice,
};
+use serde::{Deserialize, Serialize};
+use serde_json::{Map, Value, json};
+use std::{fmt::Write, time::Instant};
#[derive(Serialize, Deserialize)]
struct Geo {
diff --git a/crates/bench-apps/benches/common/mod.rs b/crates/bench-apps/benches/common/mod.rs
index 0c83965..5dd7784 100644
--- a/crates/bench-apps/benches/common/mod.rs
+++ b/crates/bench-apps/benches/common/mod.rs
@@ -1,9 +1,9 @@
//! The application workloads shared by every allocator benchmark.
//!
-//! These are real programs, not allocation loops: a JSON pipeline, a regex engine, a Rust parser,
-//! an HTTP server with its clients and a graph of async tasks. They exist as a held-out set. The
-//! allocator is never tuned against them, so a result here shows whether a gain on the synthetic
-//! workloads of the main crate carries over to code that was written for another purpose.
+//! The workloads are programs written for their own purpose: a JSON pipeline, a regex engine, a
+//! Rust parser, an HTTP server with its clients and a graph of async tasks. The allocator is never
+//! tuned against them, so a result here shows whether a gain on the synthetic workloads of the main
+//! crate carries over to ordinary code.
//!
//! A program has exactly one global allocator, so each allocator gets its own benchmark binary
//! that installs it and calls [`run`]. A binary runs one workload per invocation, which keeps the
diff --git a/crates/bench-apps/benches/common/pattern.rs b/crates/bench-apps/benches/common/pattern.rs
index cca59c3..0239b4c 100644
--- a/crates/bench-apps/benches/common/pattern.rs
+++ b/crates/bench-apps/benches/common/pattern.rs
@@ -5,15 +5,13 @@
//! with captures or replacement, and collects owned strings from the matches the way a log tool
//! does.
-use std::{collections::HashMap, fmt::Write, time::Instant};
-
-use regex::{Regex, RegexSet};
-
use super::{
Pass, Scale,
text::{Rng, WORDS, capitalized, push_words},
twice,
};
+use regex::{Regex, RegexSet};
+use std::{collections::HashMap, fmt::Write, time::Instant};
const LEVELS: [&str; 5] = ["ERROR", "WARN", "INFO", "DEBUG", "TRACE"];
const MODULES: [&str; 6] =
diff --git a/crates/bench-apps/benches/common/source.rs b/crates/bench-apps/benches/common/source.rs
index fccfa88..e335207 100644
--- a/crates/bench-apps/benches/common/source.rs
+++ b/crates/bench-apps/benches/common/source.rs
@@ -5,16 +5,14 @@
//! walks them, and then turns each tree back into a token stream and a string, which is what a
//! procedural macro does with its input.
-use std::{collections::HashMap, fmt::Write, time::Instant};
-
-use quote::ToTokens;
-use syn::{File, Ident, Lit, visit::Visit};
-
use super::{
Pass, Scale,
text::{Rng, WORDS},
twice,
};
+use quote::ToTokens;
+use std::{collections::HashMap, fmt::Write, time::Instant};
+use syn::{File, Ident, Lit, visit::Visit};
const MODULES: usize = 6;
diff --git a/crates/bench-data/Cargo.toml b/crates/bench-data/Cargo.toml
new file mode 100644
index 0000000..086928e
--- /dev/null
+++ b/crates/bench-data/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "bcmalloc-bench-data"
+version = "0.0.0"
+edition.workspace = true
+rust-version.workspace = true
+license.workspace = true
+publish = false
+description = "The benchmark results of bcmalloc in benchmarks.json, and the tables and figure rendered from them."
+
+[dependencies]
+serde = { version = "1", features = ["derive"] }
+serde_json = "1"
+
+[lints]
+workspace = true
+
+
+[[bin]]
+name = "bench-data"
+path = "src/main.rs"
diff --git a/crates/bench-data/src/docs.rs b/crates/bench-data/src/docs.rs
new file mode 100644
index 0000000..2fd56f1
--- /dev/null
+++ b/crates/bench-data/src/docs.rs
@@ -0,0 +1,82 @@
+//! The documents rendered from the results: the generated parts of `BENCHMARKS.md` and
+//! `README.md`, and `assets/benchmarks.svg`.
+//!
+//! A generated part of a Markdown file sits between `` and
+//! ``, and everything outside those markers is written by hand.
+
+use crate::{
+ markdown::{machine_name, machines, mimalloc_bench, overview, report, summary},
+ model::Data,
+ svg,
+};
+use std::{fs, io, path::Path};
+
+/// The part of a document called `name`, for the results in `data`.
+fn part(data: &Data, name: &str) -> Option {
+ match name {
+ "overview" => Some(overview(data)),
+ "machines" => Some(machines(data)),
+ _ => {
+ let (suite, rest) = name.split_once(':')?;
+ let (machine, view) = rest.split_once(':').unwrap_or((rest, "report"));
+ let run = data.run(suite, machine)?;
+ Some(match (suite, view) {
+ ("mimalloc-bench", _) => mimalloc_bench(run),
+ (_, "summary") => summary(run),
+ (_, _) => format!(
+ "
\nEvery workload on {}
\n\n{}\n \n",
+ machine_name(machine),
+ report(run)
+ ),
+ })
+ }
+ }
+}
+
+/// Replaces every generated part of `text`.
+pub fn fill(data: &Data, text: &str) -> String {
+ let mut out = String::new();
+ let mut rest = text;
+ while let Some(start) = rest.find("").map_or(rest.len() - start, |at| at + 3);
+ let name = rest[start + "");
+ let Some(close_at) = rest[open_end..].find(&close).map(|at| at + open_end) else { break };
+ out += &rest[..open_end];
+ out += "\n";
+ out += &part(data, &name).unwrap_or_else(|| "No results yet.\n".to_string());
+ out += &close;
+ rest = &rest[close_at + close.len()..];
+ }
+ out + rest
+}
+
+/// The files that are rendered from the results, with their new contents.
+pub fn render(root: &Path, data: &Data) -> io::Result> {
+ let mut files = Vec::new();
+ for name in ["BENCHMARKS.md", "README.md"] {
+ let path = root.join(name);
+ files.push((path.clone(), fill(data, &fs::read_to_string(&path)?)));
+ }
+ files.push((root.join("assets/benchmarks.svg"), svg::render(data)));
+ Ok(files)
+}
+
+/// Writes every rendered file that changed.
+pub fn write(root: &Path, data: &Data) -> io::Result<()> {
+ for (path, text) in render(root, data)? {
+ if fs::read_to_string(&path).ok().as_deref() != Some(text.as_str()) {
+ fs::write(&path, text)?;
+ }
+ }
+ Ok(())
+}
+
+/// The rendered files whose contents differ from what the results give.
+pub fn stale(root: &Path, data: &Data) -> io::Result> {
+ Ok(render(root, data)?
+ .into_iter()
+ .filter(|(path, text)| fs::read_to_string(path).ok().as_deref() != Some(text.as_str()))
+ .map(|(path, _)| path)
+ .collect())
+}
diff --git a/crates/bench-data/src/lib.rs b/crates/bench-data/src/lib.rs
new file mode 100644
index 0000000..d6f6e5c
--- /dev/null
+++ b/crates/bench-data/src/lib.rs
@@ -0,0 +1,16 @@
+//! The benchmark results of bcmalloc, kept in `benchmarks.json` at the root of the repository,
+//! and everything that is rendered from them.
+//!
+//! The benchmark commands record their results here: `just bench` and `just bench-apps` through
+//! the report driver, and `just mimalloc-bench` through `bench-data import-mimalloc-bench`. Each
+//! records one run per suite and machine, replacing the previous one. The Markdown tables in
+//! `BENCHMARKS.md` and `README.md` and the figure in `assets/benchmarks.svg` are rendered from
+//! the file, and `bench-data check` fails if they are out of date.
+
+pub mod docs;
+pub mod machine;
+pub mod markdown;
+pub mod model;
+pub mod svg;
+
+pub use model::{Data, Metric, Run, Stat, Workload};
diff --git a/crates/bench-data/src/machine.rs b/crates/bench-data/src/machine.rs
new file mode 100644
index 0000000..5d6d1ff
--- /dev/null
+++ b/crates/bench-data/src/machine.rs
@@ -0,0 +1,63 @@
+//! What machine a run happened on.
+
+use std::{fs, process::Command};
+
+/// The key of the operating system: `macos` or `linux`.
+pub const fn key() -> &'static str {
+ std::env::consts::OS
+}
+
+/// The processor and operating system, for instance "AMD EPYC 9354P 32-Core Processor, Ubuntu
+/// 24.04.2 LTS, Linux 6.8".
+pub fn describe() -> String {
+ let output = |program: &str, args: &[&str]| {
+ Command::new(program)
+ .args(args)
+ .output()
+ .ok()
+ .map(|out| String::from_utf8_lossy(&out.stdout).trim().to_string())
+ .filter(|text| !text.is_empty())
+ };
+ if cfg!(target_os = "macos") {
+ let cpu = output("sysctl", &["-n", "machdep.cpu.brand_string"]).unwrap_or_default();
+ let os = output("sw_vers", &["-productVersion"]).unwrap_or_default();
+ format!("{cpu}, macOS {os}")
+ } else {
+ let cpuinfo = fs::read_to_string("/proc/cpuinfo").unwrap_or_default();
+ let cpu = cpuinfo
+ .lines()
+ .find_map(|line| line.strip_prefix("model name"))
+ .and_then(|rest| rest.split(':').nth(1))
+ .unwrap_or("")
+ .trim()
+ .to_string();
+ let release = fs::read_to_string("/etc/os-release").unwrap_or_default();
+ let os = release
+ .lines()
+ .find_map(|line| line.strip_prefix("PRETTY_NAME="))
+ .unwrap_or("Linux")
+ .trim_matches('"')
+ .to_string();
+ let kernel = output("uname", &["-r"]).unwrap_or_default();
+ let kernel = kernel.split('-').next().unwrap_or("");
+ format!("{cpu}, {os}, Linux {kernel}")
+ }
+}
+
+/// Today's date as YYYY-MM-DD, in UTC.
+pub fn today() -> String {
+ let days = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map_or(0, |since| since.as_secs() / 86_400) as i64;
+ // Days to a civil date, after Howard Hinnant's algorithm.
+ let z = days + 719_468;
+ let era = z.div_euclid(146_097);
+ let doe = z - era * 146_097;
+ let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365;
+ let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
+ let mp = (5 * doy + 2) / 153;
+ let day = doy - (153 * mp + 2) / 5 + 1;
+ let month = if mp < 10 { mp + 3 } else { mp - 9 };
+ let year = yoe + era * 400 + i64::from(month <= 2);
+ format!("{year:04}-{month:02}-{day:02}")
+}
diff --git a/crates/bench-data/src/main.rs b/crates/bench-data/src/main.rs
new file mode 100644
index 0000000..9fff7e4
--- /dev/null
+++ b/crates/bench-data/src/main.rs
@@ -0,0 +1,158 @@
+//! Renders the benchmark documents from `benchmarks.json`, checks that they are up to date, and
+//! imports the results of mimalloc-bench.
+//!
+//! ```text
+//! bench-data render write BENCHMARKS.md, README.md and the figure
+//! bench-data check fail if any of them is out of date
+//! bench-data import-mimalloc-bench CSV record a mimalloc-bench run from its benchres.csv
+//! ```
+
+use bcmalloc_bench_data::{Data, Metric, Run, Stat, Workload, docs, machine, model::round};
+use std::{collections::BTreeMap, path::PathBuf, process::ExitCode};
+
+/// The root of the repository, two levels above this crate.
+fn root() -> PathBuf {
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..")
+}
+
+/// The names of the allocators as mimalloc-bench abbreviates them.
+fn allocator_name(short: &str) -> String {
+ match short {
+ "bc" => "bcmalloc",
+ "mi" => "mimalloc",
+ "sn" => "snmalloc",
+ "je" => "jemalloc",
+ "tc" => "tcmalloc",
+ "sys" => "system",
+ other => other,
+ }
+ .to_string()
+}
+
+/// Parses a time as mimalloc-bench writes it, in seconds or as minutes:seconds.
+fn seconds(text: &str) -> Option {
+ match text.split_once(':') {
+ Some((minutes, rest)) => {
+ Some(minutes.parse::().ok()? * 60.0 + rest.parse::().ok()?)
+ }
+ None => text.parse().ok(),
+ }
+}
+
+fn median(values: &mut [f64]) -> f64 {
+ values.sort_by(f64::total_cmp);
+ let n = values.len();
+ if n % 2 == 1 { values[n / 2] } else { (values[n / 2 - 1] + values[n / 2]) / 2.0 }
+}
+
+/// Reads a benchres.csv: one line per program, allocator and run, with the time in seconds and
+/// the peak resident memory in KiB. The interval of a median is the range of the runs.
+fn import(csv: &str) -> Run {
+ let mut samples: BTreeMap<(String, String), Vec<(f64, f64)>> = BTreeMap::new();
+ let mut programs: Vec = Vec::new();
+ let mut allocators: Vec = Vec::new();
+ for line in csv.lines() {
+ let fields: Vec<&str> = line.split_whitespace().collect();
+ let [program, allocator, time, rss, ..] = fields[..] else { continue };
+ let (Some(time), Ok(rss)) = (seconds(time), rss.parse::()) else { continue };
+ let allocator = allocator_name(allocator);
+ if !programs.iter().any(|p| p == program) {
+ programs.push(program.to_string());
+ }
+ if !allocators.contains(&allocator) {
+ allocators.push(allocator.clone());
+ }
+ samples.entry((program.to_string(), allocator)).or_default().push((time, rss / 1024.0));
+ }
+ let order = ["bcmalloc", "mimalloc", "snmalloc", "jemalloc", "tcmalloc", "system"];
+ allocators.sort_by_key(|a| order.iter().position(|o| o == a).unwrap_or(order.len()));
+ let mut runs = 0;
+ let workloads = programs
+ .iter()
+ .map(|program| {
+ let mut results = BTreeMap::new();
+ for allocator in &allocators {
+ let Some(found) = samples.get(&(program.clone(), allocator.clone())) else {
+ continue
+ };
+ runs = runs.max(found.len());
+ let mut times: Vec = found.iter().map(|s| s.0).collect();
+ let mut peaks: Vec = found.iter().map(|s| s.1).collect();
+ let lo = times.iter().copied().fold(f64::INFINITY, f64::min);
+ let hi = times.iter().copied().fold(0.0, f64::max);
+ let stat = Stat {
+ median: round(median(&mut times)),
+ lo: round(lo),
+ hi: round(hi),
+ peak_mib: round(median(&mut peaks)),
+ };
+ results.insert(allocator.clone(), stat);
+ }
+ let metric = Metric { unit: "s".to_string(), results };
+ Workload {
+ group: "mimalloc-bench".to_string(),
+ name: program.clone(),
+ lower: true,
+ size: false,
+ primary: "time".to_string(),
+ metrics: BTreeMap::from([("time".to_string(), metric)]),
+ }
+ })
+ .collect();
+ Run {
+ suite: "mimalloc-bench".to_string(),
+ machine: machine::key().to_string(),
+ description: machine::describe(),
+ date: machine::today(),
+ samples: runs,
+ baseline: "mimalloc".to_string(),
+ allocators,
+ workloads,
+ }
+}
+
+fn main() -> ExitCode {
+ let args: Vec = std::env::args().skip(1).collect();
+ let root = root();
+ let path = root.join("benchmarks.json");
+ let fail = |message: String| {
+ eprintln!("{message}");
+ ExitCode::FAILURE
+ };
+ let mut data = match Data::load(&path) {
+ Ok(data) => data,
+ Err(error) => return fail(format!("cannot read {}: {error}", path.display())),
+ };
+ match args.first().map(String::as_str) {
+ Some("render") => {}
+ Some("check") => {
+ return match docs::stale(&root, &data) {
+ Ok(stale) if stale.is_empty() => ExitCode::SUCCESS,
+ Ok(stale) => {
+ for path in stale {
+ eprintln!("{} is out of date, run: just bench-render", path.display());
+ }
+ ExitCode::FAILURE
+ }
+ Err(error) => fail(format!("cannot render: {error}")),
+ };
+ }
+ Some("import-mimalloc-bench") => {
+ let Some(csv) = args.get(1) else { return fail("which benchres.csv?".to_string()) };
+ match std::fs::read_to_string(csv) {
+ Ok(text) => data.record(import(&text)),
+ Err(error) => return fail(format!("cannot read {csv}: {error}")),
+ }
+ if let Err(error) = data.save(&path) {
+ return fail(format!("cannot write {}: {error}", path.display()));
+ }
+ }
+ _ => {
+ return fail("usage: bench-data render | check | import-mimalloc-bench CSV".to_string())
+ }
+ }
+ match docs::write(&root, &data) {
+ Ok(()) => ExitCode::SUCCESS,
+ Err(error) => fail(format!("cannot render: {error}")),
+ }
+}
diff --git a/crates/bench-data/src/markdown.rs b/crates/bench-data/src/markdown.rs
new file mode 100644
index 0000000..a46f7e5
--- /dev/null
+++ b/crates/bench-data/src/markdown.rs
@@ -0,0 +1,334 @@
+//! The Markdown tables: the report of a run, the overview of every run, and the table of
+//! mimalloc-bench.
+
+use crate::model::{Data, LATENCY, Run, Workload};
+
+/// Formats a value with three significant digits or one decimal, as the tables show it.
+pub fn fmt_value(value: f64) -> String {
+ if value.abs() >= 10.0 { format!("{value:.1}") } else { format!("{value:.2}") }
+}
+
+/// Lays out rows as a Markdown table with aligned columns. The first row is the header.
+pub fn table(rows: &[Vec]) -> String {
+ let widths: Vec = (0..rows[0].len())
+ .map(|i| rows.iter().map(|row| row[i].chars().count()).max().unwrap_or(0))
+ .collect();
+ let line = |row: &Vec| {
+ let cells: Vec =
+ row.iter().zip(&widths).map(|(cell, width)| format!("{cell: = widths.iter().map(|width| "-".repeat(*width)).collect();
+ out += &format!("| {} |\n", rule.join(" | "));
+ rows[1..].iter().for_each(|row| out += &line(row));
+ out
+}
+
+/// Which cells hold the best median or one whose interval overlaps the best one's interval.
+pub fn leaders(cells: &[Option<(f64, f64, f64)>], lower: bool) -> Vec {
+ let better = |a: f64, b: f64| if lower { a < b } else { a > b };
+ let mut best: Option<(f64, f64, f64)> = None;
+ for cell in cells.iter().flatten() {
+ if best.is_none_or(|(median, ..)| better(cell.0, median)) {
+ best = Some(*cell);
+ }
+ }
+ cells
+ .iter()
+ .map(|cell| match (cell, best) {
+ (Some((_, lo, hi)), Some((_, best_lo, best_hi))) => *lo <= best_hi && best_lo <= *hi,
+ _ => false,
+ })
+ .collect()
+}
+
+/// The groups of a run, in the order they first appear.
+fn groups(run: &Run) -> Vec<&str> {
+ let mut groups: Vec<&str> = Vec::new();
+ for workload in &run.workloads {
+ if !groups.contains(&workload.group.as_str()) {
+ groups.push(&workload.group);
+ }
+ }
+ groups
+}
+
+fn header(first: &str, allocators: &[String]) -> Vec {
+ std::iter::once(first.to_string()).chain(allocators.iter().cloned()).collect()
+}
+
+/// A table of one metric of some workloads, with the leaders in bold.
+fn metric_table(run: &Run, members: &[&Workload], metric: &dyn Fn(&Workload) -> String) -> String {
+ let mut rows = vec![header("Workload", &run.allocators)];
+ for workload in members {
+ let metric = metric(workload);
+ let cells: Vec<_> = run
+ .allocators
+ .iter()
+ .map(|a| workload.stat(&metric, a).map(|s| (s.median, s.lo, s.hi)))
+ .collect();
+ let bold = leaders(&cells, workload.lower_is_better(&metric));
+ let mut row = vec![format!("{} ({})", workload.name, workload.unit(&metric))];
+ for (cell, bold) in cells.iter().zip(bold) {
+ row.push(cell.map_or("-".to_string(), |(median, ..)| {
+ let text = fmt_value(median);
+ if bold { format!("**{text}**") } else { text }
+ }));
+ }
+ rows.push(row);
+ }
+ table(&rows)
+}
+
+/// The tables of every group of a run: the primary metric, the cold pass and the latencies.
+pub fn groups_report(run: &Run) -> String {
+ let mut out = String::new();
+ for group in groups(run) {
+ let members: Vec<&Workload> = run.workloads.iter().filter(|w| w.group == group).collect();
+ out += &format!("### {group}\n\n{}\n", metric_table(run, &members, &|w| w.primary.clone()));
+ let has = |w: &Workload, metric: &str| w.metrics.contains_key(metric);
+ let cold: Vec<&Workload> = members.iter().copied().filter(|w| has(w, "cold")).collect();
+ if !cold.is_empty() {
+ let cold_table = metric_table(run, &cold, &|_| "cold".to_string());
+ out += &format!("### {group}, cold\n\n{cold_table}\n");
+ }
+ let latency: Vec<&Workload> = members.iter().copied().filter(|w| has(w, "p99")).collect();
+ if !latency.is_empty() {
+ let mut rows = vec![header("Workload", &run.allocators)];
+ for workload in latency {
+ let mut row = vec![format!("{} ({})", workload.name, workload.unit("p99"))];
+ for allocator in &run.allocators {
+ let cells: Vec = LATENCY
+ .iter()
+ .map(|metric| {
+ workload
+ .stat(metric, allocator)
+ .map_or("-".to_string(), |stat| fmt_value(stat.median))
+ })
+ .collect();
+ row.push(cells.join(" / "));
+ }
+ rows.push(row);
+ }
+ out += &format!("### {group}, latency (p50 / p99 / p999)\n\n{}\n", table(&rows));
+ }
+ }
+ out
+}
+
+/// How `allocator` compares with the baseline on a metric of a workload, as a ratio of medians
+/// where above 1 is better. With `peak` it compares the peak resident memory instead.
+pub fn ratio(
+ run: &Run,
+ workload: &Workload,
+ metric: &str,
+ allocator: &str,
+ peak: bool,
+) -> Option {
+ let get = |a: &str| {
+ let stat = workload.stat(metric, a)?;
+ Some(if peak { stat.peak_mib } else { stat.median })
+ };
+ let (mine, base) = (get(allocator)?, get(&run.baseline)?);
+ if mine <= 0.0 || base <= 0.0 {
+ return None;
+ }
+ Some(if peak || workload.lower_is_better(metric) { base / mine } else { mine / base })
+}
+
+/// The geometric mean of some values, or `None` if there are none.
+pub fn geomean(values: impl IntoIterator- ) -> Option {
+ let logs: Vec = values.into_iter().map(f64::ln).collect();
+ (!logs.is_empty()).then(|| (logs.iter().sum::() / logs.len() as f64).exp())
+}
+
+/// The geometric mean of how `allocator` compares with the baseline on the speed workloads.
+pub fn speed(run: &Run, allocator: &str) -> Option {
+ geomean(
+ run.workloads
+ .iter()
+ .filter(|w| w.is_speed())
+ .filter_map(|w| ratio(run, w, &w.primary, allocator, false)),
+ )
+}
+
+/// The geometric mean of how the peak resident memory of `allocator` compares with the
+/// baseline's on the speed workloads, where above 1 means less memory.
+pub fn memory(run: &Run, allocator: &str) -> Option {
+ geomean(
+ run.workloads
+ .iter()
+ .filter(|w| w.is_speed())
+ .filter_map(|w| ratio(run, w, &w.primary, allocator, true)),
+ )
+}
+
+/// The summary of a run: per group and overall, the geometric mean of how each allocator compares
+/// with the baseline. A figure above 1.00 means better for speed, latency and memory alike.
+pub fn summary(run: &Run) -> String {
+ type Pick<'a> = &'a dyn Fn(&Workload) -> Option<(String, bool)>;
+ let mean = |allocator: &str, pick: Pick<'_>| {
+ geomean(run.workloads.iter().filter_map(|w| {
+ let (metric, peak) = pick(w)?;
+ ratio(run, w, &metric, allocator, peak)
+ }))
+ };
+ let row = |label: String, pick: Pick<'_>| {
+ let mut row = vec![label];
+ row.extend(
+ run.allocators
+ .iter()
+ .map(|a| mean(a, pick).map_or("-".to_string(), |g| format!("{g:.2}"))),
+ );
+ row
+ };
+ let speed = |w: &Workload| w.is_speed().then(|| (w.primary.clone(), false));
+ let held = |w: &Workload| (w.size && w.primary != "p99").then(|| (w.primary.clone(), false));
+
+ let mut rows = vec![header(&format!("Compared with {}", run.baseline), &run.allocators)];
+ let mut per_group: Vec> = vec![Vec::new(); run.allocators.len()];
+ let groups = groups(run);
+ let multiple = groups.len() > 1;
+ for group in &groups {
+ if !multiple || !run.workloads.iter().any(|w| w.group == *group && w.is_speed()) {
+ continue;
+ }
+ let pick = |w: &Workload| if w.group == *group { speed(w) } else { None };
+ rows.push(row(format!("speed, {group}"), &pick));
+ for (at, allocator) in run.allocators.iter().enumerate() {
+ per_group[at].extend(mean(allocator, &pick));
+ }
+ }
+ rows.push(row("speed, all workloads".to_string(), &speed));
+ if run.workloads.iter().any(|w| w.size) {
+ rows.push(row("memory held afterwards".to_string(), &held));
+ }
+ rows.push(row("peak resident memory".to_string(), &|w| {
+ speed(w).map(|(metric, _)| (metric, true))
+ }));
+ if multiple {
+ let mut mean_row = vec!["speed, mean of groups".to_string()];
+ mean_row.extend(per_group.iter().map(|means| {
+ geomean(means.iter().copied()).map_or("-".to_string(), |g| format!("{g:.2}"))
+ }));
+ rows.push(mean_row);
+ }
+ let has = |w: &Workload, metric: &str| w.metrics.contains_key(metric);
+ if run.workloads.iter().any(|w| has(w, "cold")) {
+ rows.push(row("speed, cold".to_string(), &|w| {
+ (has(w, "cold") && !w.lower).then(|| ("cold".to_string(), false))
+ }));
+ }
+ if run.workloads.iter().any(|w| has(w, "p99")) {
+ rows.push(row("latency, p99".to_string(), &|w| {
+ has(w, "p99").then(|| ("p99".to_string(), false))
+ }));
+ }
+ table(&rows)
+}
+
+/// The full report of a run, as the report driver prints it.
+pub fn report(run: &Run) -> String {
+ format!(
+ "Median of {} runs. Bold marks the best median and every median whose 95% bootstrap \
+ interval overlaps it.\n\n{}### Summary\n\n{}",
+ run.samples,
+ groups_report(run),
+ summary(run)
+ )
+}
+
+/// The table of a mimalloc-bench run: wall time and peak memory of every program, with the best
+/// of each in bold.
+pub fn mimalloc_bench(run: &Run) -> String {
+ let mut rows = vec![header("Program", &run.allocators)];
+ for workload in &run.workloads {
+ let stats: Vec<_> = run.allocators.iter().map(|a| workload.stat("time", a)).collect();
+ let best_time = stats.iter().flatten().map(|s| s.median).fold(f64::INFINITY, f64::min);
+ let best_peak = stats.iter().flatten().map(|s| s.peak_mib).fold(f64::INFINITY, f64::min);
+ let mut row = vec![workload.name.clone()];
+ for stat in stats {
+ row.push(stat.map_or("-".to_string(), |stat| {
+ let bold =
+ |text: String, best: bool| if best { format!("**{text}**") } else { text };
+ format!(
+ "{} / {}",
+ bold(format!("{:.3}", stat.median), stat.median <= best_time),
+ bold(format!("{:.1}", stat.peak_mib), stat.peak_mib <= best_peak)
+ )
+ }));
+ }
+ rows.push(row);
+ }
+ let mut means = vec![header(&format!("Compared with {}", run.baseline), &run.allocators)];
+ let cell = |value: Option| value.map_or("-".to_string(), |v| format!("{v:.2}"));
+ let speed_row = run.allocators.iter().map(|a| cell(speed(run, a)));
+ means.push(std::iter::once("speed".to_string()).chain(speed_row).collect());
+ let memory_row = run.allocators.iter().map(|a| cell(memory(run, a)));
+ means.push(std::iter::once("peak resident memory".to_string()).chain(memory_row).collect());
+ format!("{}\n{}", table(&means), table(&rows))
+}
+
+/// The display name of a suite.
+pub fn suite_name(suite: &str) -> &str {
+ match suite {
+ "dev" => "development suite",
+ "apps" => "Rust programs",
+ other => other,
+ }
+}
+
+/// The display name of a machine key.
+pub fn machine_name(machine: &str) -> &str {
+ match machine {
+ "macos" => "macOS",
+ "linux" => "Linux",
+ other => other,
+ }
+}
+
+/// The overview of every run: the speed of each allocator against the baseline, and the peak
+/// memory where the suite is about memory as much as speed.
+pub fn overview(data: &Data) -> String {
+ let mut columns: Vec = Vec::new();
+ for run in &data.runs {
+ for allocator in &run.allocators {
+ if *allocator != run.baseline && !columns.contains(allocator) {
+ columns.push(allocator.clone());
+ }
+ }
+ }
+ let baseline = data.runs.first().map_or("mimalloc", |run| run.baseline.as_str());
+ let mut rows = vec![header(&format!("Compared with {baseline}"), &columns)];
+ let cell = |value: Option| value.map_or("-".to_string(), |v| format!("{v:.2}"));
+ for run in &data.runs {
+ let label = format!("{}, {}", suite_name(&run.suite), machine_name(&run.machine));
+ let speeds = columns.iter().map(|a| cell(speed(run, a)));
+ rows.push(std::iter::once(format!("{label}, speed")).chain(speeds).collect());
+ if run.suite == "mimalloc-bench" {
+ let memory = columns.iter().map(|a| cell(memory(run, a)));
+ rows.push(std::iter::once(format!("{label}, peak memory")).chain(memory).collect());
+ }
+ }
+ table(&rows)
+}
+
+/// The machines, with the day of their runs.
+pub fn machines(data: &Data) -> String {
+ let mut rows = vec![vec![
+ "Suite".to_string(),
+ "Machine".to_string(),
+ "Runs".to_string(),
+ "Date".to_string(),
+ ]];
+ for run in &data.runs {
+ rows.push(vec![
+ format!("{}, {}", suite_name(&run.suite), machine_name(&run.machine)),
+ run.description.clone(),
+ run.samples.to_string(),
+ run.date.clone(),
+ ]);
+ }
+ table(&rows)
+}
diff --git a/crates/bench-data/src/model.rs b/crates/bench-data/src/model.rs
new file mode 100644
index 0000000..6163d4f
--- /dev/null
+++ b/crates/bench-data/src/model.rs
@@ -0,0 +1,149 @@
+//! The shape of `benchmarks.json`.
+
+use serde::{Deserialize, Serialize};
+use std::{collections::BTreeMap, fs, io, path::Path};
+
+/// Every recorded run, one per suite and machine.
+#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
+pub struct Data {
+ /// The runs, in the order the documents show them.
+ pub runs: Vec,
+}
+
+/// The results of one suite on one machine.
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Run {
+ /// `dev`, `apps` or `mimalloc-bench`.
+ pub suite: String,
+ /// `macos` or `linux`.
+ pub machine: String,
+ /// The hardware and operating system, as people read it.
+ pub description: String,
+ /// The day the run finished, as YYYY-MM-DD.
+ pub date: String,
+ /// How many times every workload ran under every allocator.
+ pub samples: usize,
+ /// The allocator that comparisons are relative to.
+ pub baseline: String,
+ /// The allocators, in the order of the table columns.
+ pub allocators: Vec,
+ /// The workloads, in the order of the table rows.
+ pub workloads: Vec,
+}
+
+/// One workload and its results.
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Workload {
+ /// The group the workload belongs to.
+ pub group: String,
+ /// The name of the workload.
+ pub name: String,
+ /// Whether a lower value of the warm, value and cold metrics is better.
+ pub lower: bool,
+ /// Whether the primary metric is an amount of memory.
+ pub size: bool,
+ /// The metric the tables and the summary use: warm, value, p99 or time.
+ pub primary: String,
+ /// The results by metric.
+ pub metrics: BTreeMap,
+}
+
+/// The results of every allocator on one metric of a workload.
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Metric {
+ /// The unit of the values.
+ pub unit: String,
+ /// The results by allocator.
+ pub results: BTreeMap,
+}
+
+/// The summary of the samples of one allocator on one metric.
+#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Stat {
+ /// The median value.
+ pub median: f64,
+ /// The bounds of a 95% interval of the median.
+ pub lo: f64,
+ /// See [`lo`](Self::lo).
+ pub hi: f64,
+ /// The median of the peak resident memory of the runs, in MiB.
+ pub peak_mib: f64,
+}
+
+/// The metrics where lower is better whatever the workload.
+pub const LATENCY: [&str; 3] = ["p50", "p99", "p999"];
+
+impl Workload {
+ /// Whether a lower value of `metric` is better.
+ pub fn lower_is_better(&self, metric: &str) -> bool {
+ LATENCY.contains(&metric) || self.lower
+ }
+
+ /// The result of `allocator` on `metric`.
+ pub fn stat(&self, metric: &str, allocator: &str) -> Option<&Stat> {
+ self.metrics.get(metric)?.results.get(allocator)
+ }
+
+ /// The unit of `metric`, or of the primary metric if the workload has no such metric.
+ pub fn unit(&self, metric: &str) -> &str {
+ self.metrics.get(metric).or_else(|| self.metrics.get(&self.primary)).map_or("", |m| &m.unit)
+ }
+
+ /// Whether the workload measures speed, which is what the speed summary takes.
+ pub fn is_speed(&self) -> bool {
+ !self.size && self.primary != "p99"
+ }
+}
+
+impl Run {
+ /// The key that identifies the run in the file.
+ pub fn key(&self) -> (&str, &str) {
+ (&self.suite, &self.machine)
+ }
+}
+
+/// The order in which suites and machines are shown.
+fn rank(run: &Run) -> (usize, usize) {
+ let suite = ["dev", "apps", "mimalloc-bench"].iter().position(|s| *s == run.suite);
+ let machine = ["macos", "linux"].iter().position(|m| *m == run.machine);
+ (suite.unwrap_or(9), machine.unwrap_or(9))
+}
+
+impl Data {
+ /// Reads the file, or returns no runs if there is none.
+ pub fn load(path: &Path) -> io::Result {
+ match fs::read_to_string(path) {
+ Ok(text) => serde_json::from_str(&text).map_err(io::Error::other),
+ Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(Self::default()),
+ Err(error) => Err(error),
+ }
+ }
+
+ /// Writes the file.
+ pub fn save(&self, path: &Path) -> io::Result<()> {
+ let mut text = serde_json::to_string_pretty(self).map_err(io::Error::other)?;
+ text.push('\n');
+ fs::write(path, text)
+ }
+
+ /// Adds a run, replacing the one of the same suite and machine.
+ pub fn record(&mut self, run: Run) {
+ self.runs.retain(|old| old.key() != run.key());
+ self.runs.push(run);
+ self.runs.sort_by_key(rank);
+ }
+
+ /// The run of a suite on a machine.
+ pub fn run(&self, suite: &str, machine: &str) -> Option<&Run> {
+ self.runs.iter().find(|run| run.key() == (suite, machine))
+ }
+}
+
+/// Rounds a value to four significant digits, which keeps the file small and its diffs readable.
+pub fn round(value: f64) -> f64 {
+ if value == 0.0 || !value.is_finite() {
+ return value;
+ }
+ let scale = 10_f64.powi(3 - value.abs().log10().floor() as i32);
+ (value * scale).round() / scale
+}
diff --git a/crates/bench-data/src/svg.rs b/crates/bench-data/src/svg.rs
new file mode 100644
index 0000000..de1e3e4
--- /dev/null
+++ b/crates/bench-data/src/svg.rs
@@ -0,0 +1,188 @@
+//! The figure of `assets/benchmarks.svg`: for every run and every other allocator, one dot per
+//! workload for how much faster or slower bcmalloc is.
+
+use crate::{
+ markdown::{geomean, machine_name, ratio, suite_name},
+ model::{Data, Run},
+};
+use std::fmt::Write;
+
+/// The allocator the figure is about.
+const SUBJECT: &str = "bcmalloc";
+
+/// The colours, light and dark, that the figure gives to the other allocators, in this order.
+const COLORS: [(&str, &str, &str); 5] = [
+ ("mimalloc", "#8250df", "#bc8cff"),
+ ("snmalloc", "#1a7f37", "#3fb950"),
+ ("jemalloc", "#bc4c00", "#f0883e"),
+ ("tcmalloc", "#9a6700", "#d29922"),
+ ("system", "#6e7781", "#8b949e"),
+];
+
+const WIDTH: f64 = 980.0;
+const LEFT: f64 = 240.0;
+const RIGHT: f64 = 760.0;
+/// The range of the axis, as powers of two: from a quarter to sixteen times.
+const LOW: f64 = -2.0;
+const HIGH: f64 = 4.0;
+const ROW: f64 = 24.0;
+const SECTION: f64 = 34.0;
+
+fn x_of(ratio: f64) -> f64 {
+ let at = ratio.log2().clamp(LOW, HIGH);
+ LEFT + (at - LOW) / (HIGH - LOW) * (RIGHT - LEFT)
+}
+
+fn escape(text: &str) -> String {
+ text.replace('&', "&").replace('<', "<").replace('>', ">")
+}
+
+/// How bcmalloc's speed compares with `other`'s on every speed workload of a run, above 1 when
+/// bcmalloc is faster.
+pub fn ratios(run: &Run, other: &str) -> Vec {
+ run.workloads
+ .iter()
+ .filter(|w| w.is_speed())
+ .filter_map(|w| {
+ Some(
+ ratio(run, w, &w.primary, SUBJECT, false)? /
+ ratio(run, w, &w.primary, other, false)?,
+ )
+ })
+ .collect()
+}
+
+/// The other allocators of a run, in the order of [`COLORS`].
+fn others(run: &Run) -> Vec<&str> {
+ let mut others: Vec<&str> =
+ run.allocators.iter().map(String::as_str).filter(|a| *a != SUBJECT).collect();
+ others.sort_by_key(|a| COLORS.iter().position(|(name, ..)| name == a).unwrap_or(COLORS.len()));
+ others
+}
+
+fn class(allocator: &str) -> String {
+ format!("c-{}", allocator.replace(|c: char| !c.is_ascii_alphanumeric(), ""))
+}
+
+/// Renders the figure.
+pub fn render(data: &Data) -> String {
+ let runs: Vec<&Run> =
+ data.runs.iter().filter(|run| run.allocators.iter().any(|a| a == SUBJECT)).collect();
+ let rows: usize = runs.iter().map(|run| others(run).len()).sum();
+ let top = 118.0;
+ let height = top + runs.len() as f64 * SECTION + rows as f64 * ROW + 56.0;
+
+ let mut light = String::new();
+ let mut dark = String::new();
+ for (name, color, night) in COLORS {
+ let _ = write!(light, ".{}{{fill:{color};stroke:{color}}}", class(name));
+ let _ = write!(dark, ".{}{{fill:{night};stroke:{night}}}", class(name));
+ }
+ let mut s = String::new();
+ let _ = write!(
+ s,
+ r#"\n";
+ s
+}
diff --git a/crates/bench/Cargo.toml b/crates/bench/Cargo.toml
index a99a0b9..39d4233 100644
--- a/crates/bench/Cargo.toml
+++ b/crates/bench/Cargo.toml
@@ -8,6 +8,7 @@ publish = false
description = "The synthetic benchmark suite of bcmalloc and the driver that runs it and the bench apps."
[dependencies]
+bcmalloc-bench-data = { path = "../bench-data" }
bcmalloc = { workspace = true, features = ["std"] }
libc = { workspace = true, features = ["std"] }
mimalloc.workspace = true
diff --git a/crates/bench/benches/common/churn.rs b/crates/bench/benches/common/churn.rs
index 8c91f10..f14af7b 100644
--- a/crates/bench/benches/common/churn.rs
+++ b/crates/bench/benches/common/churn.rs
@@ -1,9 +1,8 @@
//! Workloads where blocks live for a while and die out of order, the way they do in most
//! programs.
-use std::{hint::black_box, thread};
-
use super::harness::{Block, Outcome, Rng, Scale, empty_slots, parallel, timed};
+use std::{hint::black_box, thread};
/// How a churn workload picks request sizes.
#[derive(Clone, Copy)]
diff --git a/crates/bench/benches/common/concurrent.rs b/crates/bench/benches/common/concurrent.rs
index 6fe286f..a5e0d8e 100644
--- a/crates/bench/benches/common/concurrent.rs
+++ b/crates/bench/benches/common/concurrent.rs
@@ -1,6 +1,7 @@
//! Workloads where several threads share memory, free each other's blocks or live next to each
//! other in the address space.
+use super::harness::{Block, Outcome, Rng, Scale, empty_slots, parallel, raw_alloc, raw_free};
use std::{
hint::black_box,
sync::{
@@ -12,8 +13,6 @@ use std::{
time::Instant,
};
-use super::harness::{Block, Outcome, Rng, Scale, empty_slots, parallel, raw_alloc, raw_free};
-
/// The server simulation from the Larson benchmark. Each thread owns a table of blocks,
/// and every generation its table passes to a brand new thread, which frees blocks that another
/// thread allocated. This is the pattern of a thread pool that keeps replacing its workers.
diff --git a/crates/bench/benches/common/latency.rs b/crates/bench/benches/common/latency.rs
index 22a6cb7..543dccf 100644
--- a/crates/bench/benches/common/latency.rs
+++ b/crates/bench/benches/common/latency.rs
@@ -5,14 +5,13 @@
//! calls and reports the median, the 99th and the 99.9th percentile of the batches in nanoseconds.
//! Nothing is timed while the live set is built or while blocks are handed to other threads.
-use std::sync::{Mutex, mpsc};
-
use super::{
churn::MIXED,
harness::{
BATCH, Block, Outcome, Rng, Scale, empty_slots, latency, parallel_collect, time_batch,
},
};
+use std::sync::{Mutex, mpsc};
/// Replaces random blocks of a live set of 4096 and times batches of steps. A step is an
/// allocation and the free of the block it replaces, so a batch makes two calls per step.
diff --git a/crates/bench/benches/common/memory.rs b/crates/bench/benches/common/memory.rs
index 65aa195..acc1685 100644
--- a/crates/bench/benches/common/memory.rs
+++ b/crates/bench/benches/common/memory.rs
@@ -1,12 +1,11 @@
//! Workloads that report how much memory the process holds afterwards and not how fast it got
//! there.
-use std::{thread, time::Duration};
-
use super::{
churn::{MEDIUM, MIXED, SMALL, Sizes},
harness::{Block, Outcome, Rng, Scale, empty_slots, resident_mib},
};
+use std::{thread, time::Duration};
/// How long to wait after freeing before looking, so that allocators that return memory on a
/// timer have had their turn.
diff --git a/crates/bench/benches/common/micro.rs b/crates/bench/benches/common/micro.rs
index b353c9c..e4ff697 100644
--- a/crates/bench/benches/common/micro.rs
+++ b/crates/bench/benches/common/micro.rs
@@ -1,8 +1,7 @@
//! Single-thread microbenchmarks that isolate the cost of one allocation path.
-use std::hint::black_box;
-
use super::harness::{Block, Outcome, Rng, Scale, layout, raw_alloc, raw_free, timed};
+use std::hint::black_box;
/// Allocates and frees one block of `SIZE` bytes over and over. This is the hot path in its purest
/// form, with the block coming straight back from the free list it was just pushed on.
diff --git a/crates/bench/benches/common/resize.rs b/crates/bench/benches/common/resize.rs
index 8a32cfe..b32b124 100644
--- a/crates/bench/benches/common/resize.rs
+++ b/crates/bench/benches/common/resize.rs
@@ -1,8 +1,7 @@
//! Workloads that grow collections one element at a time, which is a long chain of reallocations.
-use std::hint::black_box;
-
use super::harness::{Outcome, Scale, timed};
+use std::hint::black_box;
/// Pushes a million numbers onto an empty vector.
pub(crate) fn vec_growth(scale: Scale) -> Outcome {
diff --git a/crates/bench/benches/common/structures.rs b/crates/bench/benches/common/structures.rs
index d8e95fe..f7f4d3b 100644
--- a/crates/bench/benches/common/structures.rs
+++ b/crates/bench/benches/common/structures.rs
@@ -1,13 +1,12 @@
//! Workloads built from ordinary Rust collections and trees, where the allocator is a means
//! to an end.
+use super::harness::{Outcome, Rng, Scale, timed};
use std::{
collections::{BTreeMap, HashMap, LinkedList},
hint::black_box,
};
-use super::harness::{Outcome, Rng, Scale, timed};
-
/// A hash map that keeps replacing random entries with new ones of other sizes.
pub(crate) fn hash_map(scale: Scale) -> Outcome {
let steps = scale.ops(2_000_000);
diff --git a/crates/bench/benches/report.rs b/crates/bench/benches/report.rs
index 96ddd9a..fa97e29 100644
--- a/crates/bench/benches/report.rs
+++ b/crates/bench/benches/report.rs
@@ -15,6 +15,7 @@
//! | --manifest PATH | Build and drive the benches of another Cargo.toml than this crate's. |
//! | --save PATH | Also copy the raw samples to PATH. |
//! | --compare OLD NEW | Compare two saved sample files. Runs no benchmarks. Shows bcmalloc. |
+//! | --load PATH | Print the report of a saved sample file instead of running. |
//! | --self-test | Check the statistics helpers and exit. |
//!
//! Each run is a fresh process, so no workload sees the heap that an earlier one left behind. The
@@ -43,6 +44,7 @@
//! resident MiB. Version 1 lines have no metric and no better. They count as the metric warm,
//! and lower is better only for the unit MiB.
+use bcmalloc_bench_data::{self as data, Data, Run, docs, machine, markdown, model::round};
use std::{
collections::BTreeMap,
fs,
@@ -91,13 +93,6 @@ struct Workload {
primary: String,
}
-impl Workload {
- /// Whether a lower value is better for this metric. Latencies always are.
- fn lower_is_better(&self, metric: &str) -> bool {
- LATENCY.contains(&metric) || self.lower
- }
-}
-
/// One result line of a benchmark binary.
#[derive(Debug, PartialEq)]
struct Line {
@@ -177,8 +172,12 @@ fn main() {
}
let mut workloads = list(&binaries[&allocators[0]], filter.as_deref());
- let mut results = Results::new();
- for run in 0..runs {
+ let loaded = value_of("--load");
+ let mut results = loaded.as_deref().map_or_else(Results::new, read_tsv);
+ let saved_runs =
+ results.values().flat_map(|series| series.runs.iter()).max().map(|run| run + 1);
+ let runs = if loaded.is_some() { saved_runs.unwrap_or(0) } else { runs };
+ for run in (0..runs).filter(|_| loaded.is_none()) {
for workload in &workloads {
for turn in 0..allocators.len() {
let allocator = &allocators[(turn + run) % allocators.len()];
@@ -213,12 +212,86 @@ fn main() {
eprintln!("cannot save to {path}: {error}");
}
- println!(
- "Median of {runs} runs. Bold marks the best median and every median whose 95% bootstrap \
- interval overlaps it.\n"
- );
- print_groups(&allocators, &workloads, &results);
- print_summary(&allocators, &workloads, &results, &baseline);
+ let run = to_run(&workloads, &allocators, &results, runs, &baseline);
+ print!("{}", markdown::report(&run));
+
+ // A run of every workload under every allocator is the record of this machine. A partial or
+ // quick run is not.
+ let complete = filter.is_none() && only.is_none() && !driver.quick && !has("--no-record");
+ if complete {
+ let manifest = value_of("--manifest");
+ let suite = if manifest.is_some_and(|m| m.contains("bench-apps")) { "apps" } else { "dev" };
+ if let Err(error) = record(suite, run) {
+ eprintln!("cannot record the results in benchmarks.json: {error}");
+ }
+ }
+}
+
+/// Turns the samples into a run of benchmarks.json, with the median and its interval of every
+/// series.
+fn to_run(
+ workloads: &[Workload],
+ allocators: &[String],
+ results: &Results,
+ samples: usize,
+ baseline: &str,
+) -> Run {
+ let workloads = workloads
+ .iter()
+ .map(|workload| {
+ let mut metrics: BTreeMap = BTreeMap::new();
+ for ((allocator, name, metric), series) in results {
+ if *name != workload.name || series.values.is_empty() {
+ continue;
+ }
+ let (lo, hi) = median_interval(&series.values);
+ let stat = data::Stat {
+ median: round(median(&series.values)),
+ lo: round(lo),
+ hi: round(hi),
+ peak_mib: round(median(&series.peaks)),
+ };
+ metrics
+ .entry(metric.clone())
+ .or_insert_with(|| data::Metric {
+ unit: series.unit.clone(),
+ results: BTreeMap::new(),
+ })
+ .results
+ .insert(allocator.clone(), stat);
+ }
+ data::Workload {
+ group: workload.group.clone(),
+ name: workload.name.clone(),
+ lower: workload.lower,
+ size: workload.lower && workload.primary != "p99",
+ primary: workload.primary.clone(),
+ metrics,
+ }
+ })
+ .collect();
+ Run {
+ suite: String::new(),
+ machine: machine::key().to_string(),
+ description: machine::describe(),
+ date: machine::today(),
+ samples,
+ baseline: baseline.to_string(),
+ allocators: allocators.to_vec(),
+ workloads,
+ }
+}
+
+/// Records a run in benchmarks.json and renders the documents from it again.
+fn record(suite: &str, mut run: Run) -> std::io::Result<()> {
+ run.suite = suite.to_string();
+ let path = workspace().join("benchmarks.json");
+ let mut data = Data::load(&path)?;
+ data.record(run);
+ data.save(&path)?;
+ docs::write(&workspace(), &data)?;
+ eprintln!("recorded in benchmarks.json, and rendered BENCHMARKS.md, README.md and the figure");
+ Ok(())
}
// ---- Running the benchmarks ----
@@ -528,241 +601,6 @@ fn ratio_interval(old: &[f64], new: &[f64]) -> Option<(f64, f64)> {
central_95(&ratios)
}
-/// Which of the medians are bold: the best, and every one whose interval overlaps the best's.
-/// Each entry is a median with its interval, or None when there is no sample.
-fn leaders(cells: &[Option<(f64, f64, f64)>], lower: bool) -> Vec {
- let better = |a: f64, b: f64| if lower { a < b } else { a > b };
- let mut best: Option<(f64, f64, f64)> = None;
- for cell in cells.iter().flatten() {
- if best.is_none_or(|(median, ..)| better(cell.0, median)) {
- best = Some(*cell);
- }
- }
- cells
- .iter()
- .map(|cell| match (cell, best) {
- (Some((_, lo, hi)), Some((_, best_lo, best_hi))) => *lo <= best_hi && best_lo <= *hi,
- _ => false,
- })
- .collect()
-}
-
-// ---- Tables ----
-
-/// The medians and intervals of the samples, if there are any.
-fn summarize(series: Option<&Series>) -> Option<(f64, f64, f64)> {
- let values = &series?.values;
- let (lo, hi) = median_interval(values);
- Some((median(values), lo, hi))
-}
-
-fn fmt_value(value: f64) -> String {
- if value.abs() >= 10.0 { format!("{value:.1}") } else { format!("{value:.2}") }
-}
-
-fn groups_of(workloads: &[Workload]) -> Vec<&str> {
- let mut groups: Vec<&str> = Vec::new();
- for workload in workloads {
- if !groups.contains(&workload.group.as_str()) {
- groups.push(&workload.group);
- }
- }
- groups
-}
-
-fn header(first: &str, allocators: &[String]) -> Vec {
- std::iter::once(first.to_string()).chain(allocators.iter().cloned()).collect()
-}
-
-fn print_groups(allocators: &[String], workloads: &[Workload], results: &Results) {
- let get = |allocator: &str, workload: &Workload, metric: &str| {
- results.get(&(allocator.to_string(), workload.name.clone(), metric.to_string()))
- };
- // A table of one metric, with the leaders in bold.
- let table = |members: &[&Workload], metric: &dyn Fn(&Workload) -> String| {
- let mut rows = vec![header("Workload", allocators)];
- for workload in members {
- let metric = metric(workload);
- let cells: Vec<_> =
- allocators.iter().map(|a| summarize(get(a, workload, &metric))).collect();
- let bold = leaders(&cells, workload.lower_is_better(&metric));
- let unit = get_unit(results, workload, &metric);
- let mut row = vec![format!("{} ({unit})", workload.name)];
- for (cell, bold) in cells.iter().zip(bold) {
- row.push(cell.map_or("-".to_string(), |(median, ..)| {
- let text = fmt_value(median);
- if bold { format!("**{text}**") } else { text }
- }));
- }
- rows.push(row);
- }
- print_table(&rows);
- println!();
- };
-
- for group in groups_of(workloads) {
- let members: Vec<&Workload> = workloads.iter().filter(|w| w.group == group).collect();
- println!("### {group}\n");
- table(&members, &|w| w.primary.clone());
-
- let cold: Vec<&Workload> = members
- .iter()
- .copied()
- .filter(|w| allocators.iter().any(|a| get(a, w, "cold").is_some()))
- .collect();
- if !cold.is_empty() {
- println!("### {group}, cold\n");
- table(&cold, &|_| "cold".to_string());
- }
-
- let latency: Vec<&Workload> = members
- .iter()
- .copied()
- .filter(|w| allocators.iter().any(|a| get(a, w, "p99").is_some()))
- .collect();
- if !latency.is_empty() {
- println!("### {group}, latency (p50 / p99 / p999)\n");
- let mut rows = vec![header("Workload", allocators)];
- for workload in latency {
- let unit = get_unit(results, workload, "p99");
- let mut row = vec![format!("{} ({unit})", workload.name)];
- for allocator in allocators {
- let cells: Vec = LATENCY
- .iter()
- .map(|metric| {
- get(allocator, workload, metric)
- .map_or("-".to_string(), |s| fmt_value(median(&s.values)))
- })
- .collect();
- row.push(cells.join(" / "));
- }
- rows.push(row);
- }
- print_table(&rows);
- println!();
- }
- }
-}
-
-/// The unit that any allocator reported for a metric of a workload.
-fn get_unit(results: &Results, workload: &Workload, metric: &str) -> String {
- results
- .iter()
- .find_map(|((_, name, found), series)| {
- (*name == workload.name && found == metric).then(|| series.unit.clone())
- })
- .unwrap_or_else(|| workload.unit.clone())
-}
-
-/// Which metric of a workload a summary row looks at.
-#[derive(Clone, Copy)]
-enum Which {
- Primary,
- Cold,
- P99,
-}
-
-/// Prints the geometric mean, per group and overall, of how each allocator compares with the
-/// baseline, computed from the medians. A figure above 1.00 means better than the baseline for
-/// speed, latency and memory alike.
-fn print_summary(allocators: &[String], workloads: &[Workload], results: &Results, baseline: &str) {
- // A row picks a metric of a workload, and says whether it wants the peak resident memory.
- type Pick<'a> = &'a dyn Fn(&Workload) -> Option<(Which, bool)>;
-
- let has = |workload: &Workload, metric: &str| {
- results.keys().any(|(_, name, found)| *name == workload.name && found == metric)
- };
- let ratio = |allocator: &str, workload: &Workload, (which, peak): (Which, bool)| {
- let metric = match which {
- Which::Primary => workload.primary.as_str(),
- Which::Cold => "cold",
- Which::P99 => "p99",
- };
- let get = |a: &str| {
- let series =
- results.get(&(a.to_string(), workload.name.clone(), metric.to_string()))?;
- Some(median(if peak { &series.peaks } else { &series.values }))
- };
- let (mine, base) = (get(allocator)?, get(baseline)?);
- if mine <= 0.0 || base <= 0.0 {
- return None;
- }
- // Lower is better for memory and latency, so invert to keep "above 1.00 is better".
- Some(if peak || workload.lower_is_better(metric) { base / mine } else { mine / base })
- };
- let geomean = |allocator: &str, pick: Pick<'_>| {
- let logs: Vec =
- workloads.iter().filter_map(|w| Some(ratio(allocator, w, pick(w)?)?.ln())).collect();
- (!logs.is_empty()).then(|| (logs.iter().sum::() / logs.len() as f64).exp())
- };
- let row = |label: String, pick: Pick<'_>| {
- let mut row = vec![label];
- row.extend(
- allocators
- .iter()
- .map(|a| geomean(a, pick).map_or("-".to_string(), |g| format!("{g:.2}"))),
- );
- row
- };
- // The speed rows take the workloads whose primary metric is a rate, and the memory row those
- // whose primary metric is a size. Latency has a row of its own.
- let speed = |w: &Workload| (w.primary != "p99" && !w.lower).then_some((Which::Primary, false));
- let held = |w: &Workload| (w.primary != "p99" && w.lower).then_some((Which::Primary, false));
-
- let mut rows = vec![header(&format!("Compared with {baseline}"), allocators)];
- let mut per_group: Vec> = vec![Vec::new(); allocators.len()];
- for group in groups_of(workloads) {
- if !workloads.iter().any(|w| w.group == group && speed(w).is_some()) {
- continue;
- }
- let pick = |w: &Workload| if w.group == group { speed(w) } else { None };
- rows.push(row(format!("speed, {group}"), &pick));
- for (at, allocator) in allocators.iter().enumerate() {
- per_group[at].extend(geomean(allocator, &pick));
- }
- }
- rows.push(row("speed, all workloads".to_string(), &speed));
- rows.push(row("memory held afterwards".to_string(), &held));
- rows.push(row("peak resident memory".to_string(), &|w| {
- speed(w).map(|(which, _)| (which, true))
- }));
- // Every group counts once, so a group with many workloads does not dominate.
- let mut mean_row = vec!["speed, mean of groups".to_string()];
- mean_row.extend(per_group.iter().map(|means| {
- if means.is_empty() {
- return "-".to_string();
- }
- let mean = (means.iter().map(|m| m.ln()).sum::() / means.len() as f64).exp();
- format!("{mean:.2}")
- }));
- rows.push(mean_row);
- if workloads.iter().any(|w| has(w, "cold")) {
- rows.push(row("speed, cold".to_string(), &|w| {
- (has(w, "cold") && !w.lower).then_some((Which::Cold, false))
- }));
- }
- if workloads.iter().any(|w| has(w, "p99")) {
- rows.push(row("latency, p99".to_string(), &|w| {
- has(w, "p99").then_some((Which::P99, false))
- }));
- }
- println!("### Summary\n");
- print_table(&rows);
-}
-
-fn print_table(rows: &[Vec]) {
- let widths: Vec =
- (0..rows[0].len()).map(|i| rows.iter().map(|r| r[i].len()).max().unwrap()).collect();
- let line = |row: &Vec| {
- let cells: Vec<_> =
- row.iter().zip(&widths).map(|(cell, width)| format!("{cell:>().join(" | "));
- rows[1..].iter().for_each(line);
-}
-
// ---- Comparing two sample files ----
/// Prints the change of the median from the old file to the new one for every allocator,
@@ -809,8 +647,8 @@ fn compare(old: &str, new: &str, only: &str, filter: Option<&str>) {
allocator.clone(),
workload.clone(),
metric.clone(),
- format!("{} ({})", fmt_value(old_median), old_series.values.len()),
- format!("{} ({})", fmt_value(new_median), new_series.values.len()),
+ format!("{} ({})", markdown::fmt_value(old_median), old_series.values.len()),
+ format!("{} ({})", markdown::fmt_value(new_median), new_series.values.len()),
change,
interval,
verdict.to_string(),
@@ -822,7 +660,7 @@ fn compare(old: &str, new: &str, only: &str, filter: Option<&str>) {
}
println!("Median change from the old file to the new one, with the sample count in brackets.");
println!("A verdict means the 95% bootstrap interval of the ratio of medians excludes zero.\n");
- print_table(&rows);
+ print!("{}", markdown::table(&rows));
}
// ---- Self-check ----
@@ -849,10 +687,10 @@ fn self_test() {
assert!(ratio_interval(&[0.0; 4], &noisy).is_none());
let cells = [Some((10.0, 9.0, 11.0)), Some((10.5, 10.0, 12.0)), Some((20.0, 19.0, 21.0)), None];
- assert_eq!(leaders(&cells, false), [false, false, true, false]);
- assert_eq!(leaders(&cells, true), [true, true, false, false]);
+ assert_eq!(markdown::leaders(&cells, false), [false, false, true, false]);
+ assert_eq!(markdown::leaders(&cells, true), [true, true, false, false]);
let tied = [Some((20.0, 10.5, 21.0)), Some((20.5, 19.0, 21.0)), Some((9.0, 8.0, 10.0))];
- assert_eq!(leaders(&tied, false), [true, true, false]);
+ assert_eq!(markdown::leaders(&tied, false), [true, true, false]);
let (v1, v2) = (parse_result("a\tw\t1.5\tMops/s\t3.0"), parse_result("a\tw\tp99\t80\tns\t4.5"));
assert_eq!(v1.unwrap().metric, "warm");
diff --git a/crates/cabi/Cargo.toml b/crates/cabi/Cargo.toml
index 9e29ad7..88b6fc5 100644
--- a/crates/cabi/Cargo.toml
+++ b/crates/cabi/Cargo.toml
@@ -11,6 +11,10 @@ description = "The C allocation interface of bcmalloc, as a library to preload."
name = "bcmalloc_c"
crate-type = ["cdylib"]
+[features]
+# Counts allocations and slow-path events, and prints them at exit when BCMALLOC_SHOW_METRICS is set.
+metrics = [ "bcmalloc/metrics" ]
+
[dependencies]
bcmalloc = { workspace = true, features = ["std"] }
libc = { workspace = true, features = ["std"] }
diff --git a/crates/cabi/src/lib.rs b/crates/cabi/src/lib.rs
index ee0551a..8e1b1ef 100644
--- a/crates/cabi/src/lib.rs
+++ b/crates/cabi/src/lib.rs
@@ -8,7 +8,8 @@
//! ```
//!
//! Every function forwards to one [`Bcmalloc`] with its default configuration. C frees carry no
-//! size, so `free` and `realloc` ask the allocator for the layout of the block from its chunk map.
+//! size, so `free`, `realloc` and `malloc_usable_size` read what the block is from the chunk map
+//! through the calling thread's heap.
//! Pointers that the allocator does not own are ignored by `free`, which can happen with memory a
//! program got before the library was loaded.
//!
@@ -17,14 +18,13 @@
#![allow(unsafe_code)]
+use bcmalloc::Bcmalloc;
use core::{
alloc::{GlobalAlloc, Layout},
ffi::{c_int, c_void},
ptr::{self, NonNull},
};
-use bcmalloc::Bcmalloc;
-
/// The allocator behind every function, and behind Rust's own allocations in this library.
#[global_allocator]
static ALLOCATOR: Bcmalloc = Bcmalloc::new();
@@ -83,9 +83,13 @@ fn allocate(size: usize, align: usize) -> *mut c_void {
/// # Safety
///
/// Callable from C with the usual contract.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void {
- allocate(size, MIN_ALIGN)
+ let block = ALLOCATOR.malloc(size);
+ if block.is_null() {
+ set_errno(libc::ENOMEM);
+ }
+ block.cast()
}
/// C `free`.
@@ -93,13 +97,11 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void {
/// # Safety
///
/// `ptr` must be null or a live block from this library's allocation functions.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn free(ptr: *mut c_void) {
let Some(block) = NonNull::new(ptr.cast::()) else { return };
- if let Some(layout) = ALLOCATOR.block_layout(block) {
- // SAFETY: the caller frees a live block, and the layout is the one the allocator holds.
- unsafe { ALLOCATOR.dealloc(block.as_ptr(), layout) };
- }
+ // SAFETY: the caller frees a live block, and pointers from elsewhere are ignored.
+ unsafe { ALLOCATOR.free_unsized(block) };
}
/// C `calloc`.
@@ -107,18 +109,22 @@ pub unsafe extern "C" fn free(ptr: *mut c_void) {
/// # Safety
///
/// Callable from C with the usual contract.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn calloc(count: usize, size: usize) -> *mut c_void {
let Some(bytes) = count.checked_mul(size) else {
set_errno(libc::ENOMEM);
return ptr::null_mut();
};
- let block = allocate(bytes, MIN_ALIGN);
- if !block.is_null() {
- // SAFETY: the block holds at least `bytes` bytes.
- unsafe { block.cast::().write_bytes(0, bytes) };
+ let Some(layout) = layout(bytes, MIN_ALIGN) else {
+ set_errno(libc::ENOMEM);
+ return ptr::null_mut();
+ };
+ // SAFETY: the layout has a non-zero size.
+ let block = unsafe { ALLOCATOR.alloc_zeroed(layout) };
+ if block.is_null() {
+ set_errno(libc::ENOMEM);
}
- block
+ block.cast()
}
/// C `realloc`. A size of zero frees the block and returns null, as glibc does.
@@ -126,7 +132,7 @@ pub unsafe extern "C" fn calloc(count: usize, size: usize) -> *mut c_void {
/// # Safety
///
/// `ptr` must be null or a live block from this library's allocation functions.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
let Some(block) = NonNull::new(ptr.cast::()) else {
return allocate(size, MIN_ALIGN);
@@ -136,17 +142,8 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
unsafe { free(ptr) };
return ptr::null_mut();
}
- let Some(old) = ALLOCATOR.block_layout(block) else {
- set_errno(libc::ENOMEM);
- return ptr::null_mut();
- };
- if layout(size, MIN_ALIGN).is_none() {
- set_errno(libc::ENOMEM);
- return ptr::null_mut();
- }
- // SAFETY: the block is live with the layout the allocator holds, and the size is non-zero and
- // valid for the alignment.
- let moved = unsafe { ALLOCATOR.realloc(block.as_ptr(), old, size) };
+ // SAFETY: the caller passes a live block, and the size is not zero.
+ let moved = unsafe { ALLOCATOR.realloc_unsized(block, size) };
if moved.is_null() {
set_errno(libc::ENOMEM);
}
@@ -158,7 +155,7 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
/// # Safety
///
/// Callable from C with the usual contract.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn aligned_alloc(align: usize, size: usize) -> *mut c_void {
if !align.is_power_of_two() {
set_errno(libc::EINVAL);
@@ -172,7 +169,7 @@ pub unsafe extern "C" fn aligned_alloc(align: usize, size: usize) -> *mut c_void
/// # Safety
///
/// Callable from C with the usual contract.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn memalign(align: usize, size: usize) -> *mut c_void {
// SAFETY: forwarded.
unsafe { aligned_alloc(align, size) }
@@ -183,7 +180,7 @@ pub unsafe extern "C" fn memalign(align: usize, size: usize) -> *mut c_void {
/// # Safety
///
/// `out` must be valid for a write of a pointer.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn posix_memalign(out: *mut *mut c_void, align: usize, size: usize) -> c_int {
if !align.is_power_of_two() || !align.is_multiple_of(size_of::<*mut c_void>()) {
return libc::EINVAL;
@@ -206,7 +203,7 @@ pub unsafe extern "C" fn posix_memalign(out: *mut *mut c_void, align: usize, siz
/// # Safety
///
/// Callable from C with the usual contract.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn valloc(size: usize) -> *mut c_void {
allocate(size, page_size())
}
@@ -216,7 +213,7 @@ pub unsafe extern "C" fn valloc(size: usize) -> *mut c_void {
/// # Safety
///
/// Callable from C with the usual contract.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn pvalloc(size: usize) -> *mut c_void {
let page = page_size();
let Some(rounded) = size.max(1).checked_next_multiple_of(page) else {
@@ -231,9 +228,123 @@ pub unsafe extern "C" fn pvalloc(size: usize) -> *mut c_void {
/// # Safety
///
/// `ptr` must be null or a live block from this library's allocation functions.
-#[unsafe(no_mangle)]
+#[cfg_attr(not(test), unsafe(no_mangle))]
pub unsafe extern "C" fn malloc_usable_size(ptr: *mut c_void) -> usize {
- NonNull::new(ptr.cast::())
- .and_then(|block| ALLOCATOR.block_layout(block))
- .map_or(0, |layout| layout.size())
+ NonNull::new(ptr.cast::()).and_then(|block| ALLOCATOR.usable_size(block)).unwrap_or(0)
+}
+
+/// Writes the allocator's metrics to standard error. Built with the `metrics` feature.
+#[cfg(feature = "metrics")]
+#[cfg_attr(not(test), unsafe(no_mangle))]
+pub extern "C" fn bcmalloc_print_metrics() {
+ if let Some(metrics) = ALLOCATOR.metrics() {
+ let report = std::format!("{metrics}");
+ // SAFETY: the buffer is valid for its length, and a short write only loses the report.
+ unsafe { libc::write(2, report.as_ptr().cast(), report.len()) };
+ }
+}
+
+/// Prints the metrics at exit when `BCMALLOC_SHOW_METRICS` is set, as `MIMALLOC_SHOW_STATS` does.
+#[cfg(all(feature = "metrics", target_os = "linux"))]
+extern "C" fn print_metrics_at_exit() {
+ // SAFETY: the name is a valid C string, and the environment is not changing at exit.
+ if !unsafe { libc::getenv(c"BCMALLOC_SHOW_METRICS".as_ptr()) }.is_null() {
+ bcmalloc_print_metrics();
+ }
+}
+
+/// Runs [`print_metrics_at_exit`] among the library's destructors.
+#[cfg(all(feature = "metrics", target_os = "linux"))]
+#[used]
+#[unsafe(link_section = ".fini_array")]
+static PRINT_METRICS_AT_EXIT: extern "C" fn() = print_metrics_at_exit;
+
+#[cfg(test)]
+mod test {
+ //! The C functions are built under their Rust names here, so the test binary keeps the system
+ //! allocator's symbols and calls these directly.
+
+ use super::*;
+
+ fn errno() -> c_int {
+ // SAFETY: the errno location is valid for the calling thread.
+ unsafe { *errno_location() }
+ }
+
+ #[test]
+ fn calloc_refuses_a_size_that_overflows_and_zeroes_what_it_returns() {
+ set_errno(0);
+ // SAFETY: the C contract.
+ assert!(unsafe { calloc(usize::MAX, 2) }.is_null());
+ assert_eq!(errno(), libc::ENOMEM);
+ // SAFETY: as above.
+ let block = unsafe { calloc(100, 3) }.cast::();
+ // SAFETY: the block holds 300 bytes.
+ assert!(unsafe { core::slice::from_raw_parts(block, 300) }.iter().all(|&byte| byte == 0));
+ // SAFETY: the block is live and freed once.
+ unsafe { free(block.cast()) };
+ }
+
+ #[test]
+ fn realloc_follows_the_c_rules_for_null_zero_and_failure() {
+ // SAFETY: the C contract, for each call.
+ unsafe {
+ let block = realloc(ptr::null_mut(), 40).cast::();
+ assert!(!block.is_null(), "a null pointer allocates");
+ block.write_bytes(9, 40);
+ set_errno(0);
+ assert!(realloc(block.cast(), usize::MAX).is_null());
+ assert_eq!(errno(), libc::ENOMEM);
+ assert!(core::slice::from_raw_parts(block, 40).iter().all(|&b| b == 9), "kept");
+ let grown = realloc(block.cast(), 5000).cast::();
+ assert!(core::slice::from_raw_parts(grown, 40).iter().all(|&b| b == 9));
+ assert!(malloc_usable_size(grown.cast()) >= 5000);
+ assert!(realloc(grown.cast(), 0).is_null(), "a size of zero frees");
+ }
+ }
+
+ #[test]
+ fn aligned_allocations_check_their_alignment_and_keep_errno_where_posix_says() {
+ // SAFETY: the C contract, for each call.
+ unsafe {
+ set_errno(0);
+ assert!(aligned_alloc(24, 100).is_null());
+ assert_eq!(errno(), libc::EINVAL);
+ let mut out = ptr::dangling_mut::();
+ set_errno(7);
+ assert_eq!(posix_memalign(&raw mut out, 4, 100), libc::EINVAL);
+ assert_eq!(posix_memalign(&raw mut out, 1 << 20, 100), libc::ENOMEM);
+ assert_eq!(out, ptr::dangling_mut(), "a failed call leaves the output alone");
+ assert_eq!(errno(), 7, "and errno too");
+ assert_eq!(posix_memalign(&raw mut out, 4096, 100), 0);
+ assert!(out.addr().is_multiple_of(4096));
+ free(out);
+ let page = page_size();
+ let block = pvalloc(1);
+ assert!(block.addr().is_multiple_of(page) && malloc_usable_size(block) >= page);
+ free(block);
+ assert!(pvalloc(usize::MAX).is_null());
+ assert_eq!(errno(), libc::ENOMEM);
+ let block = memalign(256, 10);
+ assert!(block.addr().is_multiple_of(256));
+ free(block);
+ }
+ }
+
+ #[test]
+ fn small_requests_are_sixteen_byte_aligned_and_null_is_harmless() {
+ // SAFETY: the C contract, for each call.
+ unsafe {
+ for size in [0, 1, 8, 24, 40, 100, 8192, 100_000] {
+ let block = malloc(size);
+ assert!(!block.is_null() && block.addr().is_multiple_of(MIN_ALIGN), "{size}");
+ assert!(malloc_usable_size(block) >= size);
+ free(block);
+ }
+ free(ptr::null_mut());
+ assert_eq!(malloc_usable_size(ptr::null_mut()), 0);
+ let mut outside = 0_u64;
+ free((&raw mut outside).cast());
+ }
+ }
}
diff --git a/justfile b/justfile
index 6ade3b2..aef4e30 100644
--- a/justfile
+++ b/justfile
@@ -34,7 +34,7 @@ test-docs:
# Run the unit tests, the integration tests and the doctests.
test *args:
- cargo nextest run -p bcmalloc --all-features "$@"
+ cargo nextest run -p bcmalloc -p bcmalloc-cabi --all-features "$@"
cargo test -p bcmalloc --doc --all-features
# Check the library under every feature combination. The tests and benchmarks need `std`.
@@ -45,6 +45,11 @@ hack *args:
miri *args:
MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri nextest run -p bcmalloc --all-features --lib "$@"
+# Measure the line coverage of the library's tests, with every feature, into lcov.info. Needs
+# cargo-llvm-cov and the llvm-tools-preview component.
+coverage *args:
+ cargo llvm-cov nextest -p bcmalloc -p bcmalloc-cabi --all-features --lcov --output-path lcov.info "$@"
+
# Model check the lock-free code with loom.
loom *args:
RUSTFLAGS="--cfg loom" cargo nextest run -p bcmalloc --release --lib loom_test "$@"
@@ -60,8 +65,9 @@ bench-build:
# Run every workload under every allocator and print the comparison with medians and bootstrap
# intervals. Options are --quick, --runs N (default 10), --filter TEXT, --only A,B, --baseline
# ALLOCATOR, --cpus LIST (taskset, Linux), --manifest PATH (the benches of another crate), --save
-# PATH and --perf, which counts hardware events with perf stat on Linux. Every sample goes to
-# target/bench.tsv.
+# PATH, --load PATH (report a saved file instead of running) and --perf, which counts hardware
+# events with perf stat on Linux. Every sample goes to target/bench.tsv, and a complete run is
+# recorded in benchmarks.json, which renders BENCHMARKS.md, README.md and the figure again.
bench *args:
cargo bench -p bcmalloc-bench --bench report -- "$@"
@@ -87,3 +93,13 @@ cabi:
mimalloc-bench dir args: cabi
echo "bc $PWD/target/cabi/release/libbcmalloc_c.$(if [ "$(uname)" = Darwin ]; then echo dylib; else echo so; fi)" > target/bcmalloc-external.txt
cd "$1/out/bench" && ../../bench.sh --external="$OLDPWD/target/bcmalloc-external.txt" $2
+ cargo run -q -p bcmalloc-bench-data -- import-mimalloc-bench "$1/out/bench/benchres.csv"
+
+# Render the tables of BENCHMARKS.md and README.md and assets/benchmarks.svg from benchmarks.json.
+# The benchmark recipes do this after they record their results.
+bench-render:
+ cargo run -q -p bcmalloc-bench-data -- render
+
+# Fail if the rendered tables or figure differ from what benchmarks.json gives.
+bench-check:
+ cargo run -q -p bcmalloc-bench-data -- check
diff --git a/rustfmt.toml b/rustfmt.toml
index 68c3c93..8cc3faa 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -9,3 +9,4 @@ trailing_semicolon = false
use_field_init_shorthand = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 100
+group_imports = "One"