feat(gpu): observe physical-page access and rank eligible VRAM promotions #303
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!303
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-303"
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-03 09:51 UTC · original
tommiehansen:perf/t02-observe-page-access→main· +993 −33 · 7 files · 12 commits · openStandard benchmark — 2026-12-05
Reproducible CI result · head
0d36619b720a· Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm).Same head;
VICTORY_POOL_ACCESS_RANK=0→1. Ranking overhead is roughly 10 µs on this synthetic workload; benefit from physical residency decisions remains unmeasured. Migration workloads unsupported.Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS.
What this does
Observe physical-page access and rank eligible VRAM promotions.
Checks
tied_weights_preserve_contiguous_runs_without_splitting, seven portable production tests previously passed; final-head rerun and explicit fail-before pending.cargo xtask policyon the final revision; no new game assets or build output intended.Verified
Current review head:
5ae52b37add8cdd52e3a0fdc965dd23d92c232ac. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.Cost
Ranking has CPU cost; prior trace changed scores but not selected set, drift high. No live promotion-return/FPS benefit proven.
Detailed implementation and historical validation
Problem
GPU heat alone does not distinguish an allocation the CPU repeatedly accesses from a hot page that can stay on the card. These pages can compete for scarce promotion slots and trigger repeated movement and readback stalls.
Implementation and correctness
Source and dependencies
The ranking extends this PR's physical-pool instrumentation and incorporates the one-commit follow-up reviewed in fork PR #1. ReVIctory's allocation observations motivate measuring how the CPU uses allocations. Their results describe a different Windows implementation. This PR can land independently of the adaptive VRAM-budget experiment and does not require the RayQuery stack.
Evidence from related implementations
These are separate external reports. ReVIctory uses explicit allocation classification and readback elimination; this PR does neither. It changes only ranking among already eligible pages when promotion capacity is scarce, without assuming that unobserved accesses cannot occur.
Comparison with the existing approach
Why this should be merged
The observation layer makes the memory-placement hypothesis testable, and the optional ranking can be compared without changing decisions in shadow mode. It complements rather than replaces #255's strike policy and is independently selectable from the budget controller. Start with shadow data and promotion/return rates before enabling ranking in production.
Validation
Previously passed standard and diagnostics Windows-target checks for
victory-gpu. The extracted portable observation test checked that repeated aliases do not count a physical page twice. The portable ranking test covered aging, repeated observations and saturating weights. The combined Phase 2 branch also passed 293 portable shader tests, with two ignored, and both Windows-target modes. These results were reused for this publication update.Limits and testing
Hardware benchmarking was unavailable. Please compare the same RT-enabled route on RX 9060 XT 16 GB at native 1080p and RX 9070 XT at native 1440p with frame generation disabled. Track quick returns, readback bytes, GPU-hot resident bytes, policy cost and P99. Observed-access coverage, behavior under alias remapping and net frame-time impact remain unverified.
Use
VICTORY_POOL_ACCESS=1in a diagnostics build to report observation cohorts. UseVICTORY_POOL_ACCESS_RANK=shadowto compare proposed rankings or1to apply them. Unset the ranking switch to use the original order.Pass 2B — ranking cost versus residency outcomes
The earlier CPU comparison measures the histogram rewrite against the previous ranking implementation. This comparison measures the cost of enabling CPU-access weighting at the same revision,
719a6e1.Apple M5, Standard profile, four interleaved A/B/B/A blocks. Baseline drift was −16.2%, so treat the magnitude as fixture-specific. CPU access lowered 5,462 scores without changing the selected set on this trace. The revised fixture checks both selected sets against a sort-based oracle and hashes complete run identities. Seven portable production tests passed, including a separate contested example where recent CPU access does change the chosen pages. The fixture times production run selection, excluding physical migration, telemetry and shadow outcome tracking.
RX 6700 XT community results used an older revision, RT off and a locally lowered title cap. They also showed little change in selection despite a substantial wait queue. When the live set fills the title cap, physical headroom is sufficient, and ordinary cold retirement frees nothing, the promotion limit can be zero. Reordering candidates cannot create a slot. Lucalocastro’s title-cap experiment addresses that separate condition by retiring a bounded number of residents and rechecking the budget on the next wave. It should be evaluated separately for quick returns, migration volume and P99, especially as workload and RT pressure change. Lucalocastro’s shadow outcome tracking is already included as
c20157c.Final-head CI update
At
5ae52b37add8cdd52e3a0fdc965dd23d92c232ac, Windows MSVCcargo check --locked -p victory-gpu --all-targets --features diagnosticsand 7 targeted tests (residency_ranking::tests) passed, with zero test failures (audit). The upstream merge snapshot also passed asset policy; with the independent repository-wide policy fix #528 applied, all four switch tests pass (verification). No dependency on #528 for runtime behavior. Hardware/gameplay verification and any remaining checklist items are still open for review. Ready for review does not imply those are completed.Queue refresh — 2026-12-05
Merged upstream main
b581f7e0a8086158953a64068ba29305d5450d68into the existing branch without rewriting history. New head:3c37855f09d97ba752c115110f4702dfc18d0efa. The follow-up in the fork remains separate; live promotion outcomes still need the planned hardware run.Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.
Review follow-up
Commit
0d36619fixes the missing residency metadata at both demotion call sites. Windows-target Cargo check with diagnostics and tests enabled passed locally using a check-only allocator shim. Native execution is tracked on the fork’s audit/pr303-diagnostics workflow.um: observe CPU and GPU hints by physical pool generationto residency: observe physical-page access and rank eligible VRAM promotionsgithub-bot referenced this pull request2026-12-03 16:15:24 +00:00
@El-Biiscuit on GitHub · 2026-12-03 18:08 UTC · original
Hardware data from an RX 6700 XT 12 GB (gfx1031, resizable BAR), in case it helps.
Setup: this PR merged on
842767a(no conflicts), diagnostics build,VICTORY_POOL_ACCESS=1,VICTORY_LOG=info,victory_gpu::um::residency=debug. Built-in benchmark mode (VICTORY_BENCH=nort: Series X, FSR 4 Quality 1440p → 3840x2160), 4 min per run with the last 3 min measured (MangoHud). The scene is a city save on foot with the camera turning for the whole run (VICTORY_KEYS). Order A B B A, same save restored before each run.VICTORY_POOL_ACCESS_RANK=shadowVICTORY_POOL_ACCESS_RANK=1On this card
842767agives the titlecard_mb_for_title=1024.Observation cohorts (last report of each run, all four runs look the same):
98 % of the CPU-touched pages are in one pool, and almost all of them are CPU-only. The pools the GPU uses are barely touched by the CPU.
Movement:
0 down for room,0 pages wait for room.Shadow ranking:
plan_usabout 100 µs.Frame times (2 runs per arm, so only indicative):
Since the ranking changes almost nothing here, I would not attribute this difference to the PR. Run-to-run variation between sessions on this scene is about the same size.
Reading: in this scene promotion room is never short, and quick returns are rare after the strike policy (#255), so the ranking has nothing to act on. I have not tested a case where room is actually scarce, for example a larger
VICTORY_CARD_KEPT_MBor a heavier scene. I can run one if you tell me which setting you want.@tommiehansen on GitHub · 2026-12-03 18:22 UTC · original
Thanks for the detailed testing, @El-Biiscuit!
Could you repeat the same A/B/B/A test with a higher
VICTORY_CARD_KEPT_MB, aiming to reduce the reportedcard_mb_for_titlefrom 1024 to around 512 MB? The goal is to see whether the optimization helps when VRAM space is limited (pages wait for roomabove zero).RT would also be interesting if it runs well on your card, but keeping RT off is absolutely fine.
@lucalocastro on GitHub · 2026-12-03 18:36 UTC · original
@El-Biiscuit, thanks for posting the four RX 6700 XT runs and flagging how rarely the ranking changed a decision. Would you be willing to try draft PR #4 on the same card with a scene that puts VRAM under pressure? RT off is fine. The draft build (
f0f259b) uses a fixed reserve, so the best check is whether the log actually showspages wait for roomabove zero.page ranking outcomesline withdeferred_quick,deferred_promoted,kept_quickandkept_promoted, pluscard_mb_for_titleand the waiting count? That lets us compare how often pages in each group returned to RAM within two seconds. A zero count is worth reporting too.VICTORY_POOL_ACCESS_RANK=0/1/1/0) and share the median and P99 in milliseconds for each run? That would let us compare the effect with the variation between repeats.The tester guide has the exact commands. If you only have time for the shadow run, those counters alone would already help. Thanks!
github-bot referenced this pull request2026-12-03 19:34:12 +00:00
@El-Biiscuit on GitHub · 2026-12-03 19:40 UTC · original
@tommiehansen Here is the 512 MB run, plus a correction to my earlier comment.
Correction. "
0 pages wait for room" came from the last residency report of each run only. The full series shows that room was short for a while at 1024 MB too. In all four runs, from about 30 s to about 2 min 30 s into the run, 1,900–3,150 pages were waiting and promotions stalled at ~2,970. After that the queue emptied. Most of the shadow passes I reported happened in that phase, and the ranking would still have changed only 3 pages.512 MB.
VICTORY_CARD_KEPT_MBdoesn't exist on main or on this branch (it comes from #267). The title room also has a 1 GiB floor,CARD_FOR_TITLE_AT_LEAST. So I built this PR (21ab7edon842767a, diagnostics build) with that one constant lowered to512 << 20. The logs showcard_mb_for_title=512in every run.Same harness as before:
VICTORY_POOL_ACCESS=1, city save on foot with the camera turning, 4 min per run, last 3 min measured, RT off. Order A B B A A B B A; all 8 runs valid, 0 kernel faults.VICTORY_POOL_ACCESS_RANK=shadowVICTORY_POOL_ACCESS_RANK=1down for roomPer run (A, B, B, A, A, B, B, A):
At 512 MB the title room fills about 30 s in (~368 MB of paged title memory on the card). From then until the end of the run, 4,300–5,350 pages wait, and promotions almost stop: run 2 went from 6,132 to 6,142 over the last 3 min. Nothing frees room for them:
0 down for roomand only 56–244 cold demotions per run. So the ranking rarely has a slot to hand out. When room is this short, the bottleneck seems to be that no on-card page gets evicted, not the order of the candidates. Frame times are the same within run-to-run variation.One thing I can't explain. With ranking on, quick returns (demoted on CPU touch within 2 s) were higher in both scarce-room tests:
VICTORY_PAGE_MOVE_MB=4at 1024 MB: A 7–12, B 10–21. That follow-up run has the same harness, and B's peak queue there was ~2,900–3,000 pages.The shadow arm says the ranking changes almost no decision, so I'm not attributing this to the PR. The numbers are small, but you may know whether
RANK=1does anything beyond reordering.RT: not tried on this card yet.
@lucalocastro Thanks. I'll look at the tester guide for your draft and come back if I can run the shadow counters on this setup.
@tommiehansen on GitHub · 2026-12-03 19:43 UTC · original
CPU Ranking & Shadow-Mode Overhead Optimization (
3905d33)Extracted the pure-Rust ranking, selection, run-coalescing, and shadow-diff logic into
crates/victory-gpu/src/um/residency_ranking.rsand wired it intocrates/victory-gpu/src/um/residency.rswithout alteringVICTORY_POOL_ACCESS/VICTORY_POOL_ACCESS_RANKbehavior or duplicating Fork PR #4's outcome tracking (shadow.rsremains separate pending hardware feedback).Technical changes
select_runs,select_ranked_runs): Replacessort_unstable_by+Vec<Move>shadow clone with a single-passu8weight histogram + sortedness check (skipping the(id, index)sort when candidates arrive ordered fromactive()), and preserves(id, index)locality on tied cutoff weights to coalesce adjacent pages cleanly.diff_run_counts): Replaces the two temporaryBTreeSet<(usize, usize)>allocations with anO(R1 + R2)two-pointer sorted interval sweep while keepingoriginal/rankedrun lists intact for downstream instrumentation.last_cpuslice across contiguous candidates intick()instead of repeatingby_id(m.id)per page, and adds an unlockedlast[index] < nowcheck inPaged::note_cpu_accessbefore scanning page views.last_cpulookups completely whenmoves.len() <= limitorlimit == 0.macOS ARM64 CPU Benchmark Results (
rustc -O, A/B/B/A 8-block median, direct productionresidency_ranking.rs)3905d33)N=8192,limit=512)N=8192,limit=512)N=8192,limit=512)um.placeruns)N=256,limit=512)N=4096,limit=64)Verification & Reproduction
rustc --edition 2024 --test crates/victory-gpu/src/um/residency_ranking.rs -o /tmp/test_ranking && /tmp/test_ranking(7 passed, 0 failed, including a 256-case randomized differential check verifyingdiff_run_countsmatchesBTreeSet::differenceexactly).cargo check -p victory-gpu --lib --target x86_64-pc-windows-msvc --features blake3/pureand--features blake3/pure,diagnostics(0 errors, 0 warnings, using the check-onlylibmimalloc-sysshim), pluscargo --offline xtask policy --staged(3 files ok).VICTORY_POOL_ACCESS_RANK=1/shadowtelemetry under real gameplay, and AMD GPU FPS / frame-time validation require external AMD hardware testing.@tommiehansen on GitHub · 2026-12-03 20:06 UTC · original
Thank you for the thorough 512 MB and
VICTORY_PAGE_MOVE_MB=4RX 6700 XT runs, @El-Biiscuit, and thank you to @lucalocastro for the outcome-tracking work in Fork PR #4. Here is whatcrates/victory-gpu/src/um/residency.rsshows for each point in your report, along with the integrated shadow-outcome update (719a6e1):1. Why promotion capacity stays exhausted at 512 MB (
0 down for room, ~5,200 waiting)tick(),pressed = free < LOW || live > roomremainsfalsewheneverlive == roomand physicalfree >= LOW(384 MiB), soDOWN_ROOMnever runs to evict warm on-card pages.space = room.saturating_sub(live)drops to0, leavingDOWN_COLDas the only source of room—andDOWN_COLDonly demotes pages whose GPUage >= COLD(150busy ticks, ~30+ seconds without GPU hits). While turning the camera in the city scene, only 56–244 pages go cold per run, somoststays near0once the title pool fills.#303only reordersupwhenlimit = most.min(remaining) > 0 && up.len() > limit.2. Why ranking changes only 0–1 pages in those runs
limit == 0gating when room is full, non-write-combined CPU-touched pages are already filtered beforeupbytouched_by_processorandPROBATION/SETTLEDstrikes, while ~98% of CPU-touched pages sit in pool 15 rather than the hot GPU-sampled pools.3. About quick returns (
A: 1–4vsB: 4–26at 512 MB;A: 7–12vsB: 10–21atMOVE_MB=4)VICTORY_POOL_ACCESS_RANK=1has no side effects anywhere outsidem.weightreordering beforeruns(up, limit)(whereasshadowcomputesrankedon a side path).21ab7edbuild,runs()usedsort_unstable_by(|a, b| b.weight.cmp(&a.weight)), whose quicksort tie-breaking across equal-weight warm pages can select different tied pages even when only a few candidates change weight. Commit3905d33replaces this with deterministic histogram bucket selection preserving(id, index)order so untouched tied weights stay invariant.um.placerun returning on a CPU touch accounts for +16 out of ~6,000 promotions (~0.27%).4. Fork PR #4 Outcome Tracking Integrated (
c20157c,71492b0,719a6e1)f0f259band746e29e, preserving original authorship) directly ontoperf/t02-observe-page-access, adaptingshadow.rsin719a6e1to classify outcomes viaruns_contain_page(O(log R)binary search over sorted runs, avoidingBTreeSetallocation per contested pass).VICTORY_POOL_ACCESS_RANK=shadowon #303 now logspage ranking outcomes(kept_promoted,kept_quick,deferred_promoted,deferred_quick) with 0 newxtask -- switcheserrors and clean Windowsx86_64-pc-windows-msvcstandard +diagnosticsbuilds.@lucalocastro on GitHub · 2026-12-03 20:07 UTC · original
@tommiehansen, thanks for integrating the shadow outcome tracking. I have a question about a separate experiment prompted by El-Biiscuit’s 512 MiB run. In run 2, only ten more pages were promoted in the final three minutes, with thousands still waiting.
Looking at
3905d33, I found one condition that could explain that plateau: at the title cap, a hot page can have no promotion slot even while the device has ample free VRAM. If no resident page meets the ordinary cold threshold, the queue can persist. I'd be interested to hear whether that matches your reading of the trace.I tried a local, opt-in prototype. Under those conditions, it can demote up to 16 previously used pages (1 MiB) that have gone at least 16 busy ticks without a GPU heat hint. The next pass rechecks the budget before promoting anything. In a synthetic replay with 5,000 fixed requests and enough eligible residents, it served 3,600 requests in 450 passes versus zero with the option off. With only 64 eligible residents, it served 64. The driver responses were simulated; the effect on RX 6700 XT frame times is still open.
Are you already working on eviction at the title cap, or would a separate draft PR for this experiment be useful? Happy to coordinate with whatever you have planned.
github-bot referenced this pull request2026-12-03 23:57:20 +00:00
@tommiehansen on GitHub · 2026-12-04 00:03 UTC · original
Thanks @lucalocastro — your diagnosis matches what
residency.rsshows under tight card/promotion headroom: when promotion room stays saturated and quick returns recycle within the same pool budget, page ranking alone plateaus and can slightly shift churn toward those quick returns.I agree with keeping title-cap / eviction policy experiments separate from #303 so each change stays isolated and measurable. Happy to review or run companion checks alongside your draft PR (and see how it interacts with #356 once ready).
@lucalocastro on GitHub · 2026-12-04 00:16 UTC · original
Thanks, @tommiehansen! I opened draft PR #398 to test the eviction change separately, as you suggested. In the local replay it freed slots for waiting pages. The open question is whether the extra transfers reduce stutter on the RX 6700 XT.
The draft proposes eight runs of the same city scene at the same 512 MiB title budget, alternating exchange off and on in ABBAABBA order. We'd compare P99 frame time and frames over 200 ms per minute alongside promotions and quick returns. Does that look like a fair first test before we look at the interaction with #356?
@tommiehansen on GitHub · 2026-12-04 00:57 UTC · original
@lucalocastro Yes, that looks like a sensible first experiment. Keeping the title budget fixed at 512 MiB and using the same binary with an ABBAABBA sequence should isolate the exchange policy nicely.
I'd also track migration volume and time alongside successful promotions, quick returns and refused moves. A shorter waiting queue is useful, but the important question is whether the newly promoted pages remain useful long enough to justify the additional transfers.
If the results show improved P99 and fewer long frames without excessive churn, I'd suggest a follow-up at the normal title budget with RT enabled.
We could then evaluate the interaction with #303 and #356 separately. I think these three approaches are complementary: better page selection, adaptive capacity, and controlled replacement when capacity is saturated.
Thanks for pursuing this independently!
@Luxuride on GitHub · 2026-12-04 12:09 UTC · original
The best-engineered thing in this batch, and also 988 lines of machinery for a hypothesis nobody has measured yet.
What I verified:
crates/victory-gpu/src/pull.rs:431→observe_pull, which returns immediately. So nobody gets faster until someone runs the A/B indocs/DIAGNOSTICS.md:75-135and reports back. That is a fine thing to land — if you are the someone.docs/DIAGNOSTICS.md:75says "This experimental branch builds on …/pull/303" — inside the PR that is 303. Self-reference; point at the branch it was cut from, or say "this branch".crates/victory-gpu/src/um/residency_ranking.rs:22-33: the penalty ladder (4/2/1 heat for a CPU touch within 1 s / 2.5 s / 5 s) is invented, not fitted. Fine for an experiment, but the docs read like it is a result. Say in the PR that these are the numbers the shadow mode exists to test.VICTORY_POOL_ACCESSandVICTORY_POOL_ACCESS_RANKare indocs/SETTINGS.mdbut not inrun.conf.default, whereVICTORY_LATE_FENCEandVICTORY_BAKE_SOURCES_ONLYboth live.To make it landable: rebase (56 behind), add the two switches to
run.conf.default, and bring one number — how many of the pages both policies would promote come back to RAM within 2 s, from the shadow mode. Then it is an On or Off decision instead of a review.The ranking module itself is the right shape: top-k over 256 buckets, run coalescing, allocation-free symmetric difference, differential and property tests, and a shadow mode that reports instead of guessing.
@lucalocastro on GitHub · 2026-12-04 12:25 UTC · original
@Luxuride @tommiehansen I opened a follow-up against the #303 branch for the two menu switches and the test guide. The 4/2/1 penalties and their time windows are trial values. The shadow run is intended to test whether those values identify promotions that return to RAM quickly. I also prepared a squashed rebase on upstream main at
0fd7614on my fork.I’m away for work for the next one to two weeks and don’t have access to my test machine. When I’m back, I’ll run shadow mode and report how many pages selected by both policies returned to RAM on a CPU touch within two seconds (
kept_quickout ofkept_promoted, plus the percentage if there’s a sample). I’ll run the A/B comparison on the same save and build for frame timing.residency: observe physical-page access and rank eligible VRAM promotionsto feat(gpu): observe physical-page access and rank eligible VRAM promotions@tommiehansen on GitHub · 2026-12-05 10:21 UTC · original
Thanks for the residency feedback and hardware experiments. 0d36619 fixes missing residency metadata at both demotion call sites; MSVC compilation and 17 targeted tests passed. The new Standard CPU result records roughly 10 µs extra ranking cost per synthetic sample. The menu/documentation feedback and hardware benefit are still open.
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.