Skip to content

perf(malloc): advise huge pages for large MPool mappings - #32815

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aunjgr:perf/large-buffer-hugepages
Nov 16, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aunjgr:perf/large-buffer-hugepages

Conversation

@aunjgr

@aunjgr aunjgr commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32813

What this PR does / why we need it:

Advise fresh Linux MPool mappings of at least 2 MiB with MADV_HUGEPAGE before
handing the allocation to callers. Under defer+madvise, this permits compaction
for large query buffers whose first touches would otherwise fall back to many
small-page faults when contiguous blocks are scarce.

Treat advice as optional and preserve successful allocation if the hint is
unavailable. Keep exact allocation sizes, zeroing, memory accounting, bounded
reuse and cleanup. Reused mappings retain their policy without another syscall.
Small allocations, the file-service cache allocator and Darwin retain their
existing behavior.

Validation

Focused SimpleCAllocator tests and the owning malloc/MPool packages pass,
including the 2 MiB boundary cases. Convention checks and configured static
checks for the changed package pass with repository-pinned tools.

Actual-allocator controls measure available and fragmented backing with serial and
32-worker first touches. The local SF100 disk comparison covers all 22 queries
with one process per arm, one excluded cold suite and five profiled warm suites,
using identical cache and memory thresholds with spilling and swap disallowed.
Per-query results, Q11 I/O tracing, binary/source provenance and measurement
limitations are posted in a separate comment. The full repository pre-push gate
is run with repository-pinned tools in the default CI build mode.

@aunjgr
aunjgr requested a review from XuPeng-SH as a code owner November 16, 2026 12:01
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

aunjgr commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Performance and root-cause evidence

This change addresses the confirmed fragmented-backing cost of large native query
buffers. It leaves global THP settings enabled. The measured workstation uses
enabled=always, defrag=defer+madvise and proactive compaction 0. Ordinary
unadvised mappings can fail to obtain contiguous huge pages despite abundant
free RAM. In a separate 6 GiB ordinary/advised/ordinary probe, excess faults were
exactly 285 * (512 - 1) = 145,635; the identical ordinary code recovered after
compacted blocks became available.

Actual-allocator controls

All controls use MO's real allocator with the same bytes and touch work. Each
allocates approximately 8 GiB in (256 MiB + 48 B) mappings; the fragmented control
also holds a separate owned 16 GiB anonymous working set. Processes are bounded,
with swap disabled. These are mechanism controls, not independent-process query
confidence intervals.

Control Main faults Trial faults Main wall s Trial wall s Main system CPU s Trial system CPU s
Resident 16 GiB, 1 worker 1,850,894 19,971 2.08659 0.50592 1.53650 0.33906
Resident 16 GiB, 32 workers 792,721 10,393 0.34317 0.29177 6.19888 4.84185

The trial includes direct-compaction costs: 2,476 stalls/zero failures in the
serial control and 1,056 stalls/52 failures in the concurrent control. With
available contiguous memory, both arms had zero fallbacks and essentially flat
elapsed time. These controls establish a backing-sensitive improvement; they do
not imply that every query benefits or that compaction is cost-free.

SF100 conclusion and slower-signal review

The full all22 screen observes Total wall -1.06%, total system CPU -5.21%, minor
faults -18.99%, and host huge-page fallbacks -93.57%. Q18 wall is -6.66%, total CPU
-7.59%, system CPU -19.23% and faults -34.00%, with nearly unchanged user
instructions. Observed whole-warm peak is 30.852 GiB main versus 30.487 GiB trial.
This primarily removes kernel work; it does not claim a broad reduction of
foreground SQL instructions or an intrinsic allocation-size reduction.

The original Q11 +1.49% wall and Q17 +1.17% median remain visible below.
Q11's non-GC instruction estimate decreases, process system CPU decreases and
there is no direct compaction in any of its five full-suite invocations. A bounded
Q11-only runtime-traced follow-up (different cache history, unscored, never pooled
with the all22 data) did not reproduce a stable slowdown: five-call warm median
+0.31%, mean -0.86%. Approximately 95% of accumulated syscall delay in both traces
is pread; the new advice helper totals only 46.4 microseconds across the entire
trial trace. I/O-pressure intervals are substantial in both arms. This supports
I/O timing variability rather than added hint/compaction work for that signal;
it does not reconstruct the exact historical I/O wait of the original calls.

Q17's full-suite wall samples are main [4.99407, 3.56009, 3.59253, 4.73790, 3.59052], trial [4.86210, 3.56414, 3.58576, 3.67171, 3.63442]; the median has a
small positive delta while the mean decreases. User instructions are nearly
unchanged. No stable introduced work/regression was confirmed in these controls.
Small timing differences remain conditional measurement uncertainty, not formal
population equivalence. No threshold, spill rule or original sample was removed
to make this conclusion.

Software provenance

Both measured service binaries were built from current main
b815a4cfb5b2eee24b620f7c078dab6f42b12537, Go 1.27.1, SIMD/v3, matching native
artifacts and identical release metadata. The baseline overlay restores the four
changed files to that exact main; the trial uses the subsequently committed
20-line allocator/test diff. Build metadata records an uncommitted workspace;
exact overlay contents, patch digest and ELF digests pin the measured production
source rather than claiming the ELF was built from a different clean commit.

Arm ELF SHA-256 Bytes
main 64643ac48a13d654ac5014416e08291dbaea1609a307056a118153fbfd5740c2 300597880
hugepage-advice 2c9e8c79070fcd1e57698e078fae5210b86b306502ada7b58fab3697914c000d 300598160

All 22 queries and resource counters

One process per arm, one excluded cold Q1–Q22 suite and five profiled warm suites. Medians below; Total sums the per-query medians. Wall time includes GC and profiling. No fabricated GC subtraction or independent-process confidence claims. THP remains enabled, cache 16 GiB, application and spill thresholds 48 GiB. Spill/swap/OOM invalidate the configuration.

Query Main wall s Trial wall s Wall Δ Main CPU s Trial CPU s Main instructions G Trial instructions G Instruction Δ
1 5.66062 5.55124 -1.93% 91.0058 91.1225 1037.4760 1033.7074 -0.36%
2 0.46560 0.46568 +0.02% 5.0275 5.2649 36.4713 36.5114 +0.11%
3 3.16010 3.14981 -0.33% 39.5891 39.2021 203.0444 201.6828 -0.67%
4 2.84813 2.83431 -0.48% 34.3913 34.8801 220.2072 221.7641 +0.71%
5 3.46549 3.47452 +0.26% 38.1184 38.0661 184.8725 185.4733 +0.32%
6 2.09907 2.10405 +0.24% 15.8673 16.2677 116.2058 114.4709 -1.49%
7 3.61519 3.62607 +0.30% 35.9777 36.1837 178.1879 177.9915 -0.11%
8 3.93880 3.95756 +0.48% 35.1479 35.4267 204.4362 204.4337 -0.00%
9 5.92162 5.86656 -0.93% 81.7234 81.5247 522.9198 523.1583 +0.05%
10 4.65262 4.65508 +0.05% 70.0267 69.8423 479.2004 479.0655 -0.03%
11 0.55807 0.56641 +1.49% 5.2230 5.2803 34.5242 34.9368 +1.20%
12 4.03637 4.02615 -0.25% 47.0071 46.6182 369.2813 369.9741 +0.19%
13 3.02102 2.98950 -1.04% 77.7743 77.7199 497.9005 497.9744 +0.01%
14 2.53208 2.52541 -0.26% 22.1148 22.0885 136.8526 135.0722 -1.30%
15 4.93568 4.76223 -3.51% 40.8391 41.1889 229.7323 229.7940 +0.03%
16 0.58919 0.56180 -4.65% 10.1163 10.2149 61.2675 61.3176 +0.08%
17 3.59253 3.63442 +1.17% 33.0951 33.3383 224.8018 225.0252 +0.10%
18 5.63909 5.26377 -6.66% 87.9277 81.2561 373.7342 372.9516 -0.21%
19 4.65562 4.64603 -0.21% 60.6390 60.4644 573.9235 573.8054 -0.02%
20 3.82756 3.78839 -1.02% 49.6777 49.2414 223.4019 223.2006 -0.09%
21 9.29379 9.22499 -0.74% 119.9813 119.7738 910.5593 910.7759 +0.02%
22 0.47628 0.47094 -1.12% 9.6725 9.7161 73.2272 73.1947 -0.04%
Total 78.98452 78.14493 -1.06% 1010.9429 1004.6815 6892.2276 6886.2814 -0.09%
Query Main system CPU s Trial system CPU s Main minor faults Trial minor faults Main Go MB Trial Go MB Main GC CPU s Trial GC CPU s
1 9.9196 9.8501 70467 63179 949.086 942.917 0.3911 0.4065
2 0.9076 0.9436 53397 54693 177.869 181.916 0.0000 0.0000
3 6.2156 6.1719 80336 70752 649.156 645.024 0.4055 0.0000
4 5.1607 5.1164 37402 40298 616.727 627.876 0.0000 0.3215
5 6.0669 6.1279 40656 39141 708.759 715.798 0.3867 0.3972
6 4.2730 4.2602 3237 3136 575.170 577.534 0.3526 0.0000
7 7.3418 7.2390 126773 127205 830.357 837.370 0.3817 0.4208
8 7.3637 7.3469 115435 106980 1176.951 1190.594 0.4028 0.4253
9 12.1413 10.6809 644248 485466 1836.254 1842.877 0.7250 0.7677
10 9.3272 9.1571 609758 582929 835.016 845.049 0.3879 0.3872
11 0.9852 0.9182 27544 27110 258.389 260.468 0.0000 0.0000
12 7.5841 7.5448 30167 30531 855.897 857.072 0.4012 0.3827
13 4.3638 4.0299 502051 422919 8483.813 8477.942 3.3022 3.3860
14 4.9235 4.8590 65474 67502 657.851 660.304 0.3033 0.0000
15 10.3033 10.2271 130155 127352 1008.945 1018.569 0.3808 0.4063
16 1.2525 1.1528 231119 218872 225.888 221.589 0.0000 0.0000
17 6.9535 6.9913 22333 27278 959.177 969.737 0.3672 0.3839
18 29.8009 24.0691 2413352 1592886 921.495 922.863 0.4278 0.4122
19 8.8786 8.7927 41271 48425 1070.039 1079.247 0.3872 0.3827
20 13.5328 12.8359 758614 653313 1387.845 1392.806 0.4162 0.4351
21 17.6354 17.4633 373572 369132 1707.993 1732.817 0.7332 0.7913
22 0.4874 0.4993 32954 33906 89.254 84.994 0.0000 0.0000
Total 175.4184 166.2777 6410315 5193005 25981.930 26085.363 10.1522 9.7066
Query Main THP allocations Trial THP allocations Main THP fallbacks Trial THP fallbacks Main compaction stalls Trial compaction stalls Trial compaction failures
1 4 5 0 0 0 0 0
2 12 12 0 0 0 0 0
3 375 382 0 0 0 0 0
4 0 0 0 0 0 0 0
5 80 83 0 0 0 0 0
6 3 2 0 0 0 0 0
7 299 303 0 0 0 0 0
8 142 161 0 0 0 0 0
9 891 1180 263 0 0 0 0
10 675 742 0 0 0 0 0
11 6 6 0 0 0 0 0
12 2 1 0 0 0 0 0
13 524 636 50 0 0 0 0
14 160 154 0 0 0 0 0
15 14 26 0 0 0 0 0
16 603 619 20 0 0 0 0
17 0 0 0 0 0 0 0
18 1054 2555 1462 128 0 629 101
19 4 4 0 0 0 0 0
20 1136 1344 196 0 0 0 0
21 360 365 0 0 0 0 0
22 31 31 0 0 0 0 0
Total 6375 8611 1991 128 0 629 101

THP/compaction counters are host-wide supporting evidence. Minor-fault and CPU counters belong to the measured application. Go counters include common scrape/background work. Native allocation counters publish asynchronously and are retained raw; their per-query deltas are not exact. No globally exact application copy-byte counter exists. Compaction can copy kernel pages; do not describe this hint as eliminating all memory copies.

main: warm window 427.843s, external cores 0.000, interrupt cores 0.544, whole-warm peak 30.852 GiB; suite totals [84.490246269, 78.69148378, 83.044915567, 80.261724821, 79.456732364].
hugepage-advice: warm window 421.178s, external cores 0.000, interrupt cores 0.527, whole-warm peak 30.487 GiB; suite totals [82.375025943, 79.197036395, 80.928657708, 78.699968877, 77.798044691].

GC-attributed instruction estimates

Raw hardware instructions remain in the preceding table. These are period-weighted stack-sampling estimates; generic allocation/copy functions are attributed to GC only when a GC-specific root appears in the stack. The Go 1.27 classifier includes its GC scanner and gcWork queue roots. No GC-subtracted wall time or exact foreground-counter claim is made.

Query Main estimated non-GC instructions G Trial estimated non-GC instructions G Δ
1 1033.8388 1032.2285 -0.16%
2 36.4713 36.5114 +0.11%
3 201.2503 201.2100 -0.02%
4 219.3221 219.9149 +0.27%
5 183.4924 183.6276 +0.07%
6 114.2945 114.3290 +0.03%
7 176.2782 176.2670 -0.01%
8 202.3216 202.4228 +0.05%
9 520.6438 520.8161 +0.03%
10 477.3014 476.9869 -0.07%
11 34.2076 33.9565 -0.73%
12 367.8253 367.8064 -0.01%
13 473.5241 473.6312 +0.02%
14 134.9931 135.0722 +0.06%
15 227.9342 228.0910 +0.07%
16 61.2675 60.9947 -0.45%
17 222.7954 223.0999 +0.14%
18 371.6475 371.3027 -0.09%
19 571.7922 572.1299 +0.06%
20 220.7898 220.3747 -0.19%
21 906.3215 906.5595 +0.03%
22 73.2272 73.1947 -0.04%
Total 6831.5398 6830.5278 -0.01%
All five raw warm wall times for every query
Query Main wall seconds, suites 1–5 Trial wall seconds, suites 1–5
1 5.57885, 5.56433, 6.57305, 5.66062, 6.41756 5.55010, 6.25340, 6.80803, 5.55124, 5.52372
2 0.45291, 0.47494, 0.50785, 0.42191, 0.46560 0.46568, 0.57114, 0.51943, 0.43549, 0.41569
3 3.19065, 3.16010, 3.14555, 3.16194, 3.13131 3.16266, 3.15530, 3.14981, 3.14863, 3.11958
4 2.84813, 2.85347, 2.85771, 2.81425, 2.80273 2.86297, 2.83901, 2.82595, 2.83431, 2.83349
5 3.48996, 3.46549, 3.47511, 3.45080, 3.44149 3.46884, 3.49819, 3.48789, 3.47452, 3.46962
6 2.09907, 2.09179, 3.29113, 2.74995, 2.07536 2.10130, 2.34762, 3.31312, 2.10405, 2.09681
7 3.65819, 3.61519, 3.68975, 3.58107, 3.58228 3.63921, 3.62607, 3.70052, 3.58889, 3.58440
8 3.93668, 3.94944, 3.97243, 3.93880, 3.91840 3.93636, 3.95168, 4.09538, 3.95756, 3.96858
9 5.99982, 5.92162, 5.93836, 5.89508, 5.82961 5.81219, 5.84875, 5.89883, 5.90571, 5.86656
10 4.69945, 4.62713, 4.65676, 4.65262, 4.63727 4.63123, 4.63778, 4.65508, 4.67035, 4.65963
11 0.57415, 0.57028, 0.55807, 0.53460, 0.52109 0.58966, 0.58728, 0.56438, 0.56641, 0.53171
12 4.06281, 4.03637, 3.99390, 4.04006, 4.00077 4.05164, 4.04120, 4.02615, 3.98444, 4.00397
13 3.13780, 3.02102, 3.04006, 2.98116, 2.96413 3.04909, 2.98950, 2.99486, 2.93407, 2.95435
14 2.53208, 2.52166, 2.53380, 2.53503, 2.51795 2.54626, 2.54700, 2.52541, 2.52342, 2.52074
15 6.50159, 4.79449, 4.75551, 4.93568, 5.16883 6.00064, 4.76223, 4.76160, 5.44808, 4.75012
16 0.69341, 0.62421, 0.58919, 0.56007, 0.56445 0.58790, 0.56180, 0.61026, 0.55491, 0.53868
17 4.99407, 3.56009, 3.59253, 4.73790, 3.59052 4.86210, 3.56414, 3.58576, 3.67171, 3.63442
18 5.87964, 5.63909, 5.66563, 5.58182, 5.43810 5.48954, 5.29259, 5.25913, 5.22896, 5.26377
19 5.73049, 4.65562, 4.65583, 4.65117, 4.63909 5.23841, 4.63898, 4.65735, 4.63768, 4.64603
20 4.63196, 3.82756, 3.80905, 3.73836, 3.98784 4.44784, 3.78029, 3.80814, 3.78839, 3.73692
21 9.32266, 9.23810, 11.09702, 9.16254, 9.29379 9.40457, 9.22887, 9.21064, 9.22499, 9.21174
22 0.47589, 0.47952, 0.64661, 0.47628, 0.46857 0.47684, 0.47419, 0.47094, 0.46617, 0.46753

@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🛑 Queue command cancelled

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 23e0e834c0ba3e73de299c1aadd0340e3883fec2

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 23e0e834c0ba3e73de299c1aadd0340e3883fec2

Assessment: approve

The optional hint preserves allocation sizes, zeroing, accounting, reuse and cleanup. Reported gains with fragmented memory justify the small addition within the existing allocator, without new state or configuration. No actionable defect remains.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all four changed files, five discussion entries, linked issue #32813 and affected allocator, MPool and file-service consumers.

  • Reused successful frozen-head build, UT/coverage, ARM SCA and PROXY/PESSIMISTIC BVT statuses, plus attributed author reports of allocator/MPool tests and performance controls.

  • Source, formatting, discussion coverage and reported benchmark arithmetic audit passed: review-audit.json, review-audit.stdout.log and checks/1794835666277389301-2.json. Receipt reconciliation is retained in validation-manifest.json.

Limitations:

  • No fresh allocator or benchmark execution; raw author/CI artifacts were unavailable. Arithmetic checks do not independently reproduce performance.

  • Measurements use one host and THP configuration with profiled single-process query runs. Q11/Q17 timing uncertainty and counter-attribution limits remain; no population equivalence or umbrella acceptance completion is claimed. Pending, skipped and neutral checks are excluded from passes.

@mergify

mergify Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

queue

🛑 Pull request from fork cannot be queued

Details

This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request.

@mergify mergify Bot added the queued label Nov 16, 2026
@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

1 h 45 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 16 Nov, 13:44 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 15:29 · 367ed0a

Reason

Pull request #32815 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

aunjgr commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio refresh

Maintainer edits are enabled and verified through GitHub's REST API. Please reevaluate the existing queue rules.

@mergify

mergify Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

@XuPeng-SH

XuPeng-SH commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 23e0e834c0ba3e73de299c1aadd0340e3883fec2

New discussion was assessed; the previous review remains unchanged.

This branch was successfully deployed

No deployments
ci — 367ed0ae Deployed Nov 16, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/enhancement size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants