perf(radv): reuse the cached mapping cursor #217
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!217
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-217"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tommiehansen on GitHub · 2026-12-02 19:07 UTC · original
tommiehansen:perf/radv-shown-cursor→main· +47 −13 · 1 files · 6 commits · openWhy
RADV restarts a red-black tree search after every already-mapped fragment in a range, even when the matched entry is known and read-only.
What changes
Advance to the successor of a matching cached entry; re-search after an attempted update because it can invalidate the saved node. Preserve mapping writes, order, references and bookkeeping. No runtime switch.
Benchmark results
Reproducible CI result · head
52b3ad4f443d· Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm).Baseline
b581f7e. Synthetic model, not actual Mesa driver or GPU measurement; actual alias workload unsupported.Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS.
Historical fully cached 256-fragment walk: 256→1 root searches. Matched patch model 22,080→11,520 lookups, identical alias-state digest. Operation counts, not driver timing; actual alias workload unsupported.
Why this should be merged
Eliminate repeated root searches on fragmented cached spans without changing actual mappings. Scoped model benefit; live driver execution still required.
Validation
C differential harness using Mesa tree implementation, ASan/UBSan, 32,768 randomized operations with failure injection on earlier revision; current pinned audit. Full Mesa/RADV execution not established.
Compatibility and dependencies
Pinned Mesa 26.3.1. #222 independently changes shared patch hunk offsets; regenerate remaining patch after either lands and apply-check. #483 separate memory change.
Previous detailed description, historical measurements and checklist.
a81ec58406tof3dba55015@tommiehansen on GitHub · 2026-12-03 19:59 UTC · original
Eliminated Remaining In-Loop Tree Lookup via
matchReuse (8754a4b)Updated
radv_amdgpu_um_showinpatches/mesa.patchto reuse the already-found future matching node across[at, stop)gap/mismatch fills instead of callingradv_amdgpu_um_tree_firstagain at the bottom of the loop.Why it is sound
match,stop = match->start < to.um->shownintervals are mutually disjoint,radv_amdgpu_um_shown_drop(um, shown, at, stop)stops strictly beforematch(leaving it untouched), andrb_tree_insertinserts[at, stop)beforematch.at = stop; shown = match;takes at most 1 RB-tree lookup perradv_amdgpu_um_showcall (O(log N + K)). When no future match exists (match == NULL),stop == toexits the loop immediately.Standalone C Model Benchmark & Differential Check (
clang -O2 -Wall -Wextra -Werror, A/B/B/A 8 blocks, 16,384-node RB-tree)origin/main8754a4b)show/blanksequences across overlapping, partial, gap-filled, mismatched, and matching BOs verified byte-identical RB-tree intervals,counts[0..1],um_shownrefcounts, and mirror update hashes acrossorigin/main, old #217, and8754a4b(3,578 -> 2,000 total lookups).verify_patch.pyconfirmed all 39 hunks / 0 errors inpatches/mesa.patch;cargo --offline xtask policy --stagedpassed (1 file ok).rb_tree/radv_amdgpu_um_showlogic; full Mesa compilation and live RADV/AMD GPU execution require external Linux hardware.@CorvetteCole on GitHub · 2026-12-04 01:36 UTC · original
Hardware numbers on RDNA3 at native 1440p. I tested this together with #222 (both on top of
45591b0'spatches/mesa.patch), so the result below is for the pair, not this PR alone.Setup
fec8830) built from eachpatches/mesa.patchwith the same options as the pinned build (meson --buildtype release -Db_ndebug=true,-O3,vulkan-drivers=amd, llvm off).45591b0withVKD3D_UNTYPED_VEC_SSBO=1(local, not in this repo), native 1440p (VICTORY_RENDER_SCALE=1.0),VICTORY_SHADER_OPT=63,VICTORY_WARM=0.8754a4band #222 atd20f287, applied on top of45591b0'smesa.patch(this PR's patch plus #222's source delta, no conflicts, 2 files, +21/−7).drops=0on every run. Frame time is the mean of the last 8 samples.Frame time
baf0468)mesa.patch→45591b0mesa.patch45591b0mesa.patch→ + this PR + #22245591b0runs, 36.46 ms)Same scene on every arm; I compared captures from the three Mesa builds and they look identical apart from the animated TV content.
Why it can't move much here (from the "unified memory on the card" counters, final line of each ~80 s run)
1on every run (pinned,45591b0, and with this PR). So the identical-hidden-alias early exit added in3b73abenever fires in this workload.45591b0's own Mesa, the game logs "the driver does not move single pages … each pool stays where it starts".pages_move()inum.rsfails its probe here, so the page-pool path fromd08da1ais not active on this card with Mesa 26.3.1. Someone with a different driver stack may want to check whether it ever succeeds.So on this card I can confirm the patch is safe (no visual or stability difference,
drops=0) but see no frame-time change beyond noise; the effect of the cursor change on CPU time per submit isn't something this frame-time measurement can resolve. If you want a CPU-side number I can add one — say which counter or log line.@Luxuride on GitHub · 2026-12-04 12:02 UTC · original
This is the kind of small, sane mesa change worth landing — it is also unmeasurable as sent, and it is a hand-edited patch file, so it will rot within weeks if it sits.
patches/mesa.patch:268: the hunk header@@ -348,6 +351,1431 @@becomes+1438here and+1437in #222. Both merge cleanly one at a time and cannot both land: the second has to regenerate the patch, and the count must then match exactly, becausesetup.sh:72applies it withgit -C "$dir" apply --index "$patch"and validates hunk counts. A wrong count breaks./setup.shfor everyone.patches/mesa.patch:866shown = match;drops the re-search the old loop did after each drop. That is sound only if nothing atstopsurvivesshown_drop— butshown_drop(:800-812) can create atailstarting atstopwhen an alias spans the boundary, andrb_tree_insertwith an equal key fails, so that tail is silently lost. Narrow, but it is the failure mode (a mapped page the driver has forgotten) that shows up as corruption hours in.The patch already prints
counts[]every 10 s, so one before/after ofcounts[0]plus wall time inradv_amdgpu_winsys_bo_alias_mapwould settle the claim. Regenerate against currentpatches/mesa.patch, add that number, and it is a five-minute merge.@tommiehansen on GitHub · 2026-12-04 12:43 UTC · original
@Luxuride Thanks for checking both the hunk headers and the
shown = match;tail-split invariant! Pushed commit9afefccwith#ifndef NDEBUGinvariant assertions and a regeneratedpatches/mesa.patch:shown = match;invariant proof:um->shownmutation sites inradv_amdgpu_bo.c:&um->shownonly inserts at two sites —radv_amdgpu_um_shown_drop(tailat[end, shown_end)whenshown_end > end) andradv_amdgpu_um_show(madeat[at, stop)after dropping overlaps on[at, stop)) — and shrinks/removes cleanly inshown_dropandbo_destroy. By induction (even under allocation/mirror failure), intervals inum->shownare strictly disjoint (prev->start + prev->size <= cur->start).radv_amdgpu_um_show:match == NULL,stop == to,atadvances toto, and thewhile (at < to)loop terminates without dereferencingshown = NULL. (If a tail is split atto, it lies at[to, shown_end), past the range.)match != NULL,matchis an existing node inum->shownwithat < stop = match->start < to. By disjointness, no nodexwithx->start < stopcan havex->start + x->size > stop(that would overlapmatch), andradv_amdgpu_um_shown_drop(um, shown, at, stop)exits strictly beforematch. Thus notailcan be created atstop,madeoccupies[at, stop)disjointly beforematch, andshown = matchequalsradv_amdgpu_um_tree_first(&um->shown, at, to).#ifndef NDEBUGradv_amdgpu_um_assert_disjoint(&um->shown)and exact assertions verifyingshown == (at < to ? radv_amdgpu_um_tree_first(&um->shown, at, to) : NULL)after cursor updates inradv_amdgpu_um_show(zero overhead under-DNDEBUG/setup.sh-Db_ndebug=true).src/util/rb_tree.c(at-O0,-O2, and-O2 -DNDEBUG, comparing against fulltree_firstre-lookup after every step) covering empty/exact boundaries, adjacent aliases, matching and mismatching BO offsets, split tails before/after matches, simulatedcallocOOMs on bothtailandmade,mirrors_updatefailures, and 50,000 randomized operations (show,blank,bo_destroy): 0 mismatches, 706 hits / 35,490 fills identical.patches/mesa.patchcleanly from pinnedmesa-26.3.1(git diff) and verifiedgit apply --index patches/mesa.patchexits 0 against cleanmesa-26.3.1(all 15 files).#322Standard mapping comparison (45591b0vs9afefcc, CPU patch model only, 4 paired blocks):mapping/radv_shown_cursor_modelreported0.061 → 0.046 ms(−23.65%,p = 0.0062,identicaldigests,tree_lookups:22,080 → 11,520). Livemapping/radv_um_aliasisUnsupportedon macOS, so live Linux RADVcounts[0]and wall-time impact still require hardware testing.(Separate #222 hunk regeneration and clean independent + combined patch application check are being posted on #222 without stacking the PRs.)
Reuse the RADV cached mapping cursorto perf(radv): reuse the cached mapping cursorgithub-bot referenced this pull request2026-12-05 11:35:00 +00:00
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.