WIP: perf(host): filter translated store marks by GPU backing range on Linux #1558

Draft
HumanBean wants to merge 1 commit from HumanBean/Longshot:perf/parked-gpu-store-filter into main
Owner

Type: perf · Risk: high · Tested on: CachyOS Linux, Ryzen 9 7900X, RTX 3090 · Needs: controlled repeat on Linux

TL;DR

Parked experiment. Skipping dirty-page bookkeeping for memory outside GPU mappings improved one scripted Market run, but the next desktop playtest was slower and had more long frames. The switch stays off by default. Please leave this PR WIP.

Breakdown

  • The experiment targets CPU work in Market on Linux.
  • Translated stores normally mark their endpoint pages so the renderer can capture writes.
  • An opt-in filter starts tracking each 64 KiB group when its first GPU mapping is registered.
  • The first mapping publishes earlier contents. Aliases and later mappings retain tracking.
  • The previous renderer work is tracked separately in PR #1553.
  • The default path in the experimental Linux binary still pays an eligibility check.
  • A controlled three-way comparison remains open.

Why

The main thread often waits for worker jobs in Market. CPU write bookkeeping occurs in those jobs. A related store-mark experiment on another machine motivated checking the cost here. Related experiment

What changed

Linux builds support HOS_GPU_DIRTY_FILTER=1. The generated store helper checks endpoint groups. NVN and nvdrv enroll the guest backing of physical and alias mappings, with a process-wide barrier before the first mapping becomes visible. A system without the required Linux membarrier support keeps ordinary tracking.

Measurements

The tested change was 055c6460 on the #1553 series. This PR carries the isolated change on main at b268d901. Each row compares like routes within its own mode.

Market window Previous build Filter enabled
Scripted, 900 settled frames, average FPS 75.0 82.9
Scripted, p99 frame time 17.3 ms 14.5 ms
Desktop, 50 seconds after entry, average FPS 57.0 54.2
Desktop, p99 frame time 27.1 ms 31.7 ms
Desktop, frames over 33.3 ms 8 21

The queue detected an outside build during the filtered desktop run. Manual movement varied. These results leave the desktop benefit unproven.

Testing

Tested locally with the exclusive timing and profile queue. The scripted and desktop runs reached Market and exited cleanly. The mapping regression passes on the isolated PR commit and covers endpoint stores, first mapping, alias and remap, and failed enrollment and retry. The guest libc hook check passed in the experiment workspace.

Must be tested

Repeat the same route with an uninstrumented binary and the same candidate binary with its switch disabled and enabled. Check scene-entry tails, low-memory hardware and first-mapping capture volume. Full suite and in-game verification of the isolated main-based tip are outstanding.

Risk and rollback

Leaving the switch unset keeps ordinary dirty marking. Reverting this commit also removes the eligibility probe from the Linux binary. The first enrollment marks sixteen pages, which can increase capture traffic.

Checklist

  • Source-only change and regression test.
  • AI-assisted development disclosed.
  • Headed improvement reproduced.
  • Ready to merge.
**Type:** perf · **Risk:** high · **Tested on:** CachyOS Linux, Ryzen 9 7900X, RTX 3090 · **Needs:** controlled repeat on Linux ## TL;DR Parked experiment. Skipping dirty-page bookkeeping for memory outside GPU mappings improved one scripted Market run, but the next desktop playtest was slower and had more long frames. The switch stays off by default. Please leave this PR WIP. ## Breakdown - The experiment targets CPU work in Market on Linux. - Translated stores normally mark their endpoint pages so the renderer can capture writes. - An opt-in filter starts tracking each 64 KiB group when its first GPU mapping is registered. - The first mapping publishes earlier contents. Aliases and later mappings retain tracking. - The previous renderer work is tracked separately in [PR #1553](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1553). - The default path in the experimental Linux binary still pays an eligibility check. - A controlled three-way comparison remains open. ## Why The main thread often waits for worker jobs in Market. CPU write bookkeeping occurs in those jobs. A related store-mark experiment on another machine motivated checking the cost here. [Related experiment](https://git.magicbean.dev/ballotstomper/Longshot/commit/72db7c7d99a851935bcdb384eb18d0d77bbc7bff) ## What changed Linux builds support HOS_GPU_DIRTY_FILTER=1. The generated store helper checks endpoint groups. NVN and nvdrv enroll the guest backing of physical and alias mappings, with a process-wide barrier before the first mapping becomes visible. A system without the required Linux membarrier support keeps ordinary tracking. ## Measurements The tested change was 055c6460 on the #1553 series. This PR carries the isolated change on main at b268d901. Each row compares like routes within its own mode. | Market window | Previous build | Filter enabled | |---|---:|---:| | Scripted, 900 settled frames, average FPS | 75.0 | 82.9 | | Scripted, p99 frame time | 17.3 ms | 14.5 ms | | Desktop, 50 seconds after entry, average FPS | 57.0 | 54.2 | | Desktop, p99 frame time | 27.1 ms | 31.7 ms | | Desktop, frames over 33.3 ms | 8 | 21 | The queue detected an outside build during the filtered desktop run. Manual movement varied. These results leave the desktop benefit unproven. ## Testing Tested locally with the exclusive timing and profile queue. The scripted and desktop runs reached Market and exited cleanly. The mapping regression passes on the isolated PR commit and covers endpoint stores, first mapping, alias and remap, and failed enrollment and retry. The guest libc hook check passed in the experiment workspace. ## Must be tested Repeat the same route with an uninstrumented binary and the same candidate binary with its switch disabled and enabled. Check scene-entry tails, low-memory hardware and first-mapping capture volume. Full suite and in-game verification of the isolated main-based tip are outstanding. ## Risk and rollback Leaving the switch unset keeps ordinary dirty marking. Reverting this commit also removes the eligibility probe from the Linux binary. The first enrollment marks sixteen pages, which can increase capture traffic. ## Checklist - [x] Source-only change and regression test. - [x] AI-assisted development disclosed. - [ ] Headed improvement reproduced. - [ ] Ready to merge.
perf(host): filter translated store marks by GPU backing range on Linux
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Successful in 9s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 9s
CI / Workflow lint (actionlint) (pull_request) Successful in 10s
Third-party parts / As their notes say (pull_request) Successful in 11s
b268d90152
Enroll guest backing ranges before publishing GPU mappings. Preserve pre-map contents and cross-group writes, and leave ordinary tracking enabled unless the experiment is selected.

Assisted-by: Codex
Author
Owner

Tested in game: Tested the filter on the #1553 renderer in scripted and headed Market on Linux, RTX 3090. Isolated commit b268d901 passes the mapping regression. Parked after the headed comparison.

Tested in game: Tested the filter on the #1553 renderer in scripted and headed Market on Linux, RTX 3090. Isolated commit b268d901 passes the mapping regression. Parked after the headed comparison.
Author
Owner

I recommend keeping the filter opt-in. I ran the same #1558 binary (b268d90152) twice on Linux with a Ryzen 9 7900X, an RTX 3090 and NVIDIA 620.70.06. The filter ran first enabled and then disabled. Each pass started from a private copy of the same game and driver caches. Both indexed 32,459 pipeline notes, and the host confirmed filter activation in the enabled run. A single high-priority exclusive queue job covered both passes and recorded zero outside builds.

Each pass used a fresh child save and the same inputs in Market. The player went forward for 10 seconds and circled while looking around for 15 seconds. Position samples confirmed movement in Market throughout.

Filter Forward FPS Circling FPS Overall FPS p99 frame time Frames over 33.3 ms Worst frame
On 45.89 46.39 46.19 94.28 ms 72 404.0 ms
Off 55.21 50.87 51.75 47.85 ms 26 1,054.6 ms

With populated notes, enabling the filter lowered average FPS by 10.7% and nearly doubled p99. The disabled run still had the longest individual pause, including about one second of renderer wait. In an earlier pass where the tour set the graphics notes aside, this PR with the filter enabled reached 62.23 FPS versus 55.91 on its direct main base. The sign changed across experiments. One pass per configuration leaves the effect of run order and scene variation unresolved.

The implementation is currently Linux-only and uses membarrier when memory first becomes GPU-visible. Windows also tracks CPU writes in software, so the idea could apply there. A Windows port would need an equivalent, verified first-mapping handoff and independent measurements. I would want interleaved repeats in Market and Field and a second GPU with less VRAM before proposing a default change.

I recommend keeping the filter opt-in. I ran the same #1558 binary (b268d901523b) twice on Linux with a Ryzen 9 7900X, an RTX 3090 and NVIDIA 620.70.06. The filter ran first enabled and then disabled. Each pass started from a private copy of the same game and driver caches. Both indexed 32,459 pipeline notes, and the host confirmed filter activation in the enabled run. A single high-priority exclusive queue job covered both passes and recorded zero outside builds. Each pass used a fresh child save and the same inputs in Market. The player went forward for 10 seconds and circled while looking around for 15 seconds. Position samples confirmed movement in Market throughout. | Filter | Forward FPS | Circling FPS | Overall FPS | p99 frame time | Frames over 33.3 ms | Worst frame | |---|---:|---:|---:|---:|---:|---:| | On | 45.89 | 46.39 | 46.19 | 94.28 ms | 72 | 404.0 ms | | Off | 55.21 | 50.87 | 51.75 | 47.85 ms | 26 | 1,054.6 ms | With populated notes, enabling the filter lowered average FPS by 10.7% and nearly doubled p99. The disabled run still had the longest individual pause, including about one second of renderer wait. In an earlier pass where the tour set the graphics notes aside, this PR with the filter enabled reached 62.23 FPS versus 55.91 on its direct main base. The sign changed across experiments. One pass per configuration leaves the effect of run order and scene variation unresolved. The implementation is currently Linux-only and uses membarrier when memory first becomes GPU-visible. Windows also tracks CPU writes in software, so the idea could apply there. A Windows port would need an equivalent, verified first-mapping handoff and independent measurements. I would want interleaved repeats in Market and Field and a second GPU with less VRAM before proposing a default change.
Contributor

Results from a Steam Deck OLED.

Setup: SteamOS, RADV (Mesa 26.2.0-devel), the built-in 1280×800 display, Minimum preset with a fixed 50% render, frame generation off, 15 W and main's clock policy.

What was compared: the SAME b268d901 build (on its d1a307cb base) with HOS_GPU_DIRTY_FILTER unset vs =1, two reverse-order rounds (U F / F U).

  • The engagement line was in every filtered run and absent with the switch unset.
  • This is a within-build switch comparison, not the PR vs unmodified main: both arms include the experimental eligibility-check code.

Kokiri standing:

  • fps 25.50 unset vs 25.49 filtered (arm medians): no meaningful FPS gain resolved.
  • The logged memory-sync timer averaged about 0.940 vs 0.814 ms a frame.
  • Tails were mixed:
    • p95 rose 44.88 → 45.18 and 44.70 → 45.11 ms;
    • p99 fell 51.05 → 49.57 and 52.73 → 50.43 ms;
    • frames over 50 ms fell 16 → 11 and 15 → 14 (about 20.5 → 14.0 and 19.1 → 18.8 a minute).
  • Sampled process RSS was roughly 0.5 GiB higher in the filtered windows, mainly shared mappings. That isn't a measurement of extra private or unique physical memory, and its cause is unresolved.

Hyrule Field: no admitted comparison pair. One filtered measured window passed and neither control window did. The refusals flag background work and program-census activity, not an identified translation or filter failure.

Safety: the covered safety windows in both switch states had zero flash-detector flags, and the sampled views showed no obvious new artifact. No GPU fault or reset in this block.

These are descriptive two-pair measurements, not a settled estimate of general benefit, and not evidence of equivalence. They don't justify turning the filter on by default, and they don't replace a comparison against unmodified main.

Results from a Steam Deck OLED. **Setup:** SteamOS, RADV (Mesa 26.2.0-devel), the built-in 1280×800 display, Minimum preset with a fixed 50% render, frame generation off, 15 W and main's clock policy. **What was compared:** the SAME `b268d901` build (on its `d1a307cb` base) with `HOS_GPU_DIRTY_FILTER` unset vs `=1`, two reverse-order rounds (U F / F U). - The engagement line was in every filtered run and absent with the switch unset. - This is a within-build switch comparison, not the PR vs unmodified main: both arms include the experimental eligibility-check code. **Kokiri standing:** - fps 25.50 unset vs 25.49 filtered (arm medians): no meaningful FPS gain resolved. - The logged memory-sync timer averaged about 0.940 vs 0.814 ms a frame. - Tails were mixed: - p95 rose 44.88 → 45.18 and 44.70 → 45.11 ms; - p99 fell 51.05 → 49.57 and 52.73 → 50.43 ms; - frames over 50 ms fell 16 → 11 and 15 → 14 (about 20.5 → 14.0 and 19.1 → 18.8 a minute). - Sampled process RSS was roughly 0.5 GiB higher in the filtered windows, mainly shared mappings. That isn't a measurement of extra private or unique physical memory, and its cause is unresolved. **Hyrule Field: no admitted comparison pair.** One filtered measured window passed and neither control window did. The refusals flag background work and program-census activity, not an identified translation or filter failure. **Safety:** the covered safety windows in both switch states had zero flash-detector flags, and the sampled views showed no obvious new artifact. No GPU fault or reset in this block. These are descriptive two-pair measurements, not a settled estimate of general benefit, and not evidence of equivalence. They don't justify turning the filter on by default, and they don't replace a comparison against unmodified main.
Contributor

Follow-up on the Field admission refusals: the recurring “1 jobs queued” pattern aligns with the renderer’s scheduled glibc heap check/trim (mallinfo2/malloc_trim), which also exists on 544229a2; window alignment explains why it was sampled in some runs and not others. It is not evidence of a newly translated Field shader. Our original admission decisions and exclusions are unchanged; separate program-census refusals remain, so there is still no admitted Field comparison pair.

Follow-up on the Field admission refusals: the recurring “1 jobs queued” pattern aligns with the renderer’s scheduled glibc heap check/trim (`mallinfo2`/`malloc_trim`), which also exists on `544229a2`; window alignment explains why it was sampled in some runs and not others. It is not evidence of a newly translated Field shader. Our original admission decisions and exclusions are unchanged; separate program-census refusals remain, so there is still no admitted Field comparison pair.
Contributor

Instrumentation caveat for the Steam Deck numbers: recurring long frames have nearly the same cadence as our /proc memory sampler. We are investigating an observer effect; no sampler-off control has established its size or whether it changes the arm contrasts. The Deck p95/p99, long-frame counts and FPS comparisons in our comment above include that instrumentation and must not yet be treated as unsampled player experience. The raw results and exclusions are unchanged.

Instrumentation caveat for the Steam Deck numbers: recurring long frames have nearly the same cadence as our /proc memory sampler. We are investigating an observer effect; no sampler-off control has established its size or whether it changes the arm contrasts. The Deck p95/p99, long-frame counts and FPS comparisons in our comment above include that instrumentation and must not yet be treated as unsampled player experience. The raw results and exclusions are unchanged.
Contributor

Follow-up to the instrumentation caveat above: a sampler-cadence control on the same Deck moved the recurring long frames with the memory sampler's period (5.8 → 17.8 → 5.8 s), with every Kokiri interval over 100 ms intersecting its smaps_rollup read. That strengthens the observer-effect caveat for our Deck tail numbers; it doesn't estimate unsampled FPS or show that the arm contrasts cancel. Details: #1477 (comment)

Follow-up to the instrumentation caveat above: a sampler-cadence control on the same Deck moved the recurring long frames with the memory sampler's period (5.8 → 17.8 → 5.8 s), with every Kokiri interval over 100 ms intersecting its `smaps_rollup` read. That strengthens the observer-effect caveat for our Deck tail numbers; it doesn't estimate unsampled FPS or show that the arm contrasts cancel. Details: https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1477#issuecomment-49657
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Successful in 9s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 9s
CI / Workflow lint (actionlint) (pull_request) Successful in 10s
Third-party parts / As their notes say (pull_request) Successful in 11s
This pull request has changes conflicting with the target branch.
  • nx2/build.py
  • nx2/rtgen.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/parked-gpu-store-filter:HumanBean-perf/parked-gpu-store-filter'
git switch 'HumanBean-perf/parked-gpu-store-filter'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1558
No description provided.