[CLAIM] VSP-03: split large lazy title-memory sections to remove mapping stalls #4

Open
opened 2026-11-30 16:22:18 +00:00 by github-bot · 5 comments
Owner

@⁠FeelsGoodMan2 on GitHub · 2026-11-30 00:13 UTC · original

Roadmap Task ID

VSP-03

Technical Plan & File Scope

This covers one part of VSP-03: title-memory sections in xmem.rs. It does not attempt the "promote the ~62 refused multi-stretch regions" criterion, so please say if you would rather track it under a separate ID.

Files

  • crates/vesper-hle/src/modules/xmem.rs only (including its unit tests)

Problem

Every large lazily committed allocation of title pages is one shared-memory section (CreateFileMappingW without a file). In my run the largest is 6,236 MB. A comment in the source puts the 64 KB single-page views at about 100,000; I have not counted them myself.

A CPU and context-switch trace (24 s of switch data, normal unmodified mapping code) has three gaps longer than 60 ms in the submit thread. An unrelated process of mine used about one core during the recording, and the gaps lie in its first seconds, so I will repeat it.

Gap Title thread waiting for one system thread Waits
168 ms 157 ms 95
90 ms 80 ms 51
367 ms 342 ms 225

The waiting thread is in copy_page_mappings -> map_aliases -> map_alias -> MapViewOfFile3 / UnmapViewOfFile2, 1-4 ms per page, one page at a time. The system thread mostly uses 55-100 % of a core during seconds 0-4.7, when all three gaps occur, and about 1 % afterwards, when there are none.

Its stack reads as large-page rebuilding (MiRebuildLargePages -> MiTradePage -> MiTrimSharedPage -> MiTrimSection -> MiViewMayContainPage). I named these frames by comparing code with a neighbouring kernel build whose symbols I have: some match exactly, the last ones at about 0.6-0.7 similarity. My reading is that it walks all views of a section under the section's lock, while mapping calls wait for that lock.

Plan

  • Cut lazily committed allocations into sections of at most 64 MB. New switch: VESPER_SECTION_MB (0 = one section per allocation, as today).
  • Leave sections committed upfront alone (32-bit heap, pools up to VESPER_INPLACE_HOT_MB), because buffers in place need one stretch of one section. Lazy sections cannot be opened as a host heap today, so no in-place candidate is lost.
  • Page numbers handed to the title stay consecutive.

Relation to the VSP-03 goal: a pool that should later become one heap must be made committed, and so stays whole. Cutting applies only to lazy ones.

State

  • A local implementation exists already, made with an AI coding tool (Claude Code); I will disclose that in the PR. No PR is open.
  • Tests: a new test fails with the cut switched off (16,387 pages in one section) and passes with it, including mapping, aliasing and writes across a cut.
  • On a clean branch with only the xmem.rs change: clippy --workspace --all-targets -- -D warnings clean; cargo test -p xtask 9 passed; workspace 1236 passed, 3 failed, 47 ignored. The 3 failures are in vesper-shader (first_half_values_render_on_hardware_and_warp, rectangles_are_drawn_whole, the_rectangle_stage_is_a_geometry_shader) and fail the same way on an untouched checkout here.
  • In the first run with it (that build also had other local changes of mine, which are not part of this claim), the pools became 98 sections (6,236 MB) and 12 sections (710 MB). In 1.6 minutes of counted play no ~5 s window was below 12 FPS (0 of 20; 17 of 128 in the run before, another scene), and I see no spikes while playing. This is too short to be a benchmark. Average FPS is unchanged.

Verification planned

  • Same PC, same route and duration, VESPER_SECTION_MB=0 against 64: Avg / Med / Settled FPS, Med / p95 ms, GPU busy, peak private RAM, number of slow windows.
  • A second context-switch trace to check that the waits are gone.
  • Visual check of interiors and open world.

Hardware: i5-13600KF, 32 GB RAM, RX 7800 XT 16 GB, 1440p, Windows 11 build 26300.

Possibly related: #3 (stutter on the same GPU and Windows build). I have not checked whether the cause is the same.

Contributor Rules

  • I confirmed no other open Task Claim holds this ID.
  • I will include local clippy + xtask test results and real before/after benchmarks in my PR.
**@⁠FeelsGoodMan2** on GitHub · 2026-11-30 00:13 UTC · [original](https://github.com/monte-alt/vesper/issues/4) ### Roadmap Task ID VSP-03 ### Technical Plan & File Scope This covers one part of VSP-03: title-memory sections in `xmem.rs`. It does not attempt the "promote the ~62 refused multi-stretch regions" criterion, so please say if you would rather track it under a separate ID. **Files** - `crates/vesper-hle/src/modules/xmem.rs` only (including its unit tests) **Problem** Every large lazily committed allocation of title pages is one shared-memory section (`CreateFileMappingW` without a file). In my run the largest is 6,236 MB. A comment in the source puts the 64 KB single-page views at about 100,000; I have not counted them myself. A CPU and context-switch trace (24 s of switch data, normal unmodified mapping code) has three gaps longer than 60 ms in the submit thread. An unrelated process of mine used about one core during the recording, and the gaps lie in its first seconds, so I will repeat it. | Gap | Title thread waiting for one system thread | Waits | |---:|---:|---:| | 168 ms | 157 ms | 95 | | 90 ms | 80 ms | 51 | | 367 ms | 342 ms | 225 | The waiting thread is in `copy_page_mappings` -> `map_aliases` -> `map_alias` -> `MapViewOfFile3` / `UnmapViewOfFile2`, 1-4 ms per page, one page at a time. The system thread mostly uses 55-100 % of a core during seconds 0-4.7, when all three gaps occur, and about 1 % afterwards, when there are none. Its stack reads as large-page rebuilding (`MiRebuildLargePages` -> `MiTradePage` -> `MiTrimSharedPage` -> `MiTrimSection` -> `MiViewMayContainPage`). I named these frames by comparing code with a neighbouring kernel build whose symbols I have: some match exactly, the last ones at about 0.6-0.7 similarity. My reading is that it walks all views of a section under the section's lock, while mapping calls wait for that lock. **Plan** - Cut lazily committed allocations into sections of at most 64 MB. New switch: `VESPER_SECTION_MB` (0 = one section per allocation, as today). - Leave sections committed upfront alone (32-bit heap, pools up to `VESPER_INPLACE_HOT_MB`), because buffers in place need one stretch of one section. Lazy sections cannot be opened as a host heap today, so no in-place candidate is lost. - Page numbers handed to the title stay consecutive. **Relation to the VSP-03 goal:** a pool that should later become one heap must be made committed, and so stays whole. Cutting applies only to lazy ones. **State** - A local implementation exists already, made with an AI coding tool (Claude Code); I will disclose that in the PR. No PR is open. - Tests: a new test fails with the cut switched off (16,387 pages in one section) and passes with it, including mapping, aliasing and writes across a cut. - On a clean branch with only the `xmem.rs` change: `clippy --workspace --all-targets -- -D warnings` clean; `cargo test -p xtask` 9 passed; workspace 1236 passed, 3 failed, 47 ignored. The 3 failures are in `vesper-shader` (`first_half_values_render_on_hardware_and_warp`, `rectangles_are_drawn_whole`, `the_rectangle_stage_is_a_geometry_shader`) and fail the same way on an untouched checkout here. - In the first run with it (that build also had other local changes of mine, which are not part of this claim), the pools became 98 sections (6,236 MB) and 12 sections (710 MB). In 1.6 minutes of counted play no ~5 s window was below 12 FPS (0 of 20; 17 of 128 in the run before, another scene), and I see no spikes while playing. This is too short to be a benchmark. Average FPS is unchanged. **Verification planned** - Same PC, same route and duration, `VESPER_SECTION_MB=0` against 64: Avg / Med / Settled FPS, Med / p95 ms, GPU busy, peak private RAM, number of slow windows. - A second context-switch trace to check that the waits are gone. - Visual check of interiors and open world. Hardware: i5-13600KF, 32 GB RAM, RX 7800 XT 16 GB, 1440p, Windows 11 build 26300. Possibly related: #3 (stutter on the same GPU and Windows build). I have not checked whether the cause is the same. ### Contributor Rules - [X] I confirmed no other open Task Claim holds this ID. - [X] I will include local clippy + xtask test results and real before/after benchmarks in my PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 16:22:18 +00:00
Author
Owner

@⁠thefafu on GitHub · 2026-11-30 00:22 UTC · original

Hi, I filed #8 for VSP-03 without seeing this claim (it was not in the search yet) and have closed it as a duplicate. Two data points that may help your verification, both from an RX 9060 XT 16 GB / 7800X3D / 32 GB on the same Windows build 26300 (details in #5):

  1. A VESPER_TIMELINE trace (diagnostics build, 5 frames at 120/180/240 s, Series X, 4K out + HW RT) showed the title's CopyPageMappings on the frames' chain: 1.7 ms a frame at 120 s and 8.4 ms at 180 s. At 240 s the chain was 77 ms a frame behind a thread of ours that held the views' lock (see 2), which is how we found it.
  2. Our local change, also in xmem.rs only, discards dead streaming-pool pages from the section's lasting view (Section::window): pages shown by no view but the whole-section one are MEM_RESET under the views' lock and VirtualUnlocked after it while free RAM is low. It lets 11-28 GB go per drive with under 0.5 % needed again (working set peak 25.5 GB down to 18-23 GB). In 4 MiB pieces under the lock, spikes over 200 ms went 14 -> 7 a minute and over 500 ms 1.3 -> 0.4.

It adds bits to Section and hooks in window(), change() and unmap(), so it would conflict with your split; I am happy to rebase it on top of yours once it lands and propose it separately. If you share your branch, I can also run it here (same restored save and route, VESPER_SECTION_MB=0 against 64, with the per-frame spike counts) and post the numbers as an independent check.

**@⁠thefafu** on GitHub · 2026-11-30 00:22 UTC · [original](https://github.com/monte-alt/vesper/issues/4#issuecomment-7265209376) Hi, I filed #8 for VSP-03 without seeing this claim (it was not in the search yet) and have closed it as a duplicate. Two data points that may help your verification, both from an RX 9060 XT 16 GB / 7800X3D / 32 GB on the same Windows build 26300 (details in #5): 1. A `VESPER_TIMELINE` trace (diagnostics build, 5 frames at 120/180/240 s, Series X, 4K out + HW RT) showed the title's `CopyPageMappings` on the frames' chain: 1.7 ms a frame at 120 s and 8.4 ms at 180 s. At 240 s the chain was 77 ms a frame behind a thread of ours that held the views' lock (see 2), which is how we found it. 2. Our local change, also in `xmem.rs` only, discards dead streaming-pool pages from the section's lasting view (`Section::window`): pages shown by no view but the whole-section one are MEM_RESET under the views' lock and VirtualUnlocked after it while free RAM is low. It lets 11-28 GB go per drive with under 0.5 % needed again (working set peak 25.5 GB down to 18-23 GB). In 4 MiB pieces under the lock, spikes over 200 ms went 14 -> 7 a minute and over 500 ms 1.3 -> 0.4. It adds bits to `Section` and hooks in `window()`, `change()` and `unmap()`, so it would conflict with your split; I am happy to rebase it on top of yours once it lands and propose it separately. If you share your branch, I can also run it here (same restored save and route, `VESPER_SECTION_MB=0` against 64, with the per-frame spike counts) and post the numbers as an independent check.
Author
Owner

@⁠FeelsGoodMan2 on GitHub · 2026-11-30 00:45 UTC · original

Thanks for the data. The CopyPageMappings / views-lock trace lines up with what I'm seeing. I'll publish the branch on my fork a bit later and ping you here when it's up.

**@⁠FeelsGoodMan2** on GitHub · 2026-11-30 00:45 UTC · [original](https://github.com/monte-alt/vesper/issues/4#issuecomment-7265546868) Thanks for the data. The `CopyPageMappings` / views-lock trace lines up with what I'm seeing. I'll publish the branch on my fork a bit later and ping you here when it's up.
Author
Owner

@⁠monte-alt on GitHub · 2026-11-30 02:49 UTC · original

claim looks good, go for it. killing that MiRebuildLargePages / MiTrimSection 367ms kernel lock stall is definitely worth doing and we arent touching section splitting in our next pass (we're focused on shadow/host/watch right now).

keeping VSP-03 scoped just to splitting lazy sections is totally fine, no need to cram the multi-stretch promotion into the same pr — smaller focused prs are way easier to review and verify. just rebase onto the new main we just pushed (since xmem.rs got contiguous coalescing in phase 1b/1c) and drop your before/after numbers + xtask/clippy results when the pr is up.

**@⁠monte-alt** on GitHub · 2026-11-30 02:49 UTC · [original](https://github.com/monte-alt/vesper/issues/4#issuecomment-7267348623) claim looks good, go for it. killing that `MiRebuildLargePages` / `MiTrimSection` 367ms kernel lock stall is definitely worth doing and we arent touching section splitting in our next pass (we're focused on `shadow`/`host`/`watch` right now). keeping `VSP-03` scoped just to splitting lazy sections is totally fine, no need to cram the multi-stretch promotion into the same pr — smaller focused prs are way easier to review and verify. just rebase onto the new `main` we just pushed (since `xmem.rs` got contiguous coalescing in phase 1b/1c) and drop your before/after numbers + `xtask`/`clippy` results when the pr is up.
Author
Owner

@⁠FeelsGoodMan2 on GitHub · 2026-11-30 10:03 UTC · original

@⁠thefafu the branch is up: section-split on https://github.com/FeelsGoodMan2/vesper (draft PR #17). If you still want to run it, VESPER_SECTION_MB=0 against 64 on the same save and route is the comparison I need. My own numbers are one run each on the same route, but with different free RAM and draws per frame, so an independent check would help a lot.

**@⁠FeelsGoodMan2** on GitHub · 2026-11-30 10:03 UTC · [original](https://github.com/monte-alt/vesper/issues/4#issuecomment-7275050198) @⁠thefafu the branch is up: `section-split` on https://github.com/FeelsGoodMan2/vesper (draft PR #17). If you still want to run it, `VESPER_SECTION_MB=0` against `64` on the same save and route is the comparison I need. My own numbers are one run each on the same route, but with different free RAM and draws per frame, so an independent check would help a lot.
Author
Owner

@⁠thefafu on GitHub · 2026-11-30 18:38 UTC · original · edited 2026-11-30 18:49 UTC

@⁠FeelsGoodMan2 I ran your branch here. One run each, back to back, so not a benchmark, but the difference is large.

Setup: same PC as #5: 7800X3D, 32 GB DDR5-4800, RX 9060 XT 16 GB (driver 32.0.32029.2010), Windows 11 build 26300, inbox D3D12.

  • Build: section-split at 5e5b56c, release, unchanged.
  • scripts\launch.cmd [1] Series X 1440p native with telemetry, otherwise stock. Only VESPER_SECTION_MB was passed through.
  • Note: in this commit an unset VESPER_SECTION_MB means 64, not 0. The 0 run therefore sets 0 explicitly, unlike the claim's "0 = as today, default".
  • Same restored save, same route, ~270 s each. The 0 run was first.

With 64 the log shows mb=6236 sections=98 and mb=710 sections=12, as in your run. With 0 that line does not appear.

Metric (summary.txt) VESPER_SECTION_MB=0 VESPER_SECTION_MB=64
Duration / gameplay frames 270.5 s / 4,301 269.8 s / 4,649
p50 FPS (ms) 18.02 (55.5) 18.61 (53.7)
p95 ms 99.9 87.8
p99 ms / 1% low 197.9 / 5.05 FPS 104.3 / 9.59 FPS
Frames > 100 ms 5.0 % (215) 1.36 % (63)
Longest > 100 ms streak 7 frames 4 frames
GPU busy, mean 83.9 % 86.8 %
Private peak 35,457 MB 35,873 MB

Per minute, from drive_frames.csv (frames with more than 50 draws, so in play). The draws per frame show the load was comparable:

Minute Draws / frame (0 / 64) Avg ms (0 / 64) > 100 ms (0 / 64) > 200 ms (0 / 64)
1 7,217 / 8,129 54.0 / 55.1 7 / 5 4 / 1
2 9,211 / 9,630 59.9 / 60.1 21 / 25 1 / 0
3 10,358 / 10,239 63.9 / 59.4 30 / 1 0 / 0
4 10,486 / 9,937 68.8 / 60.0 87 / 21 15 / 2
All 4,318 / 4,661 frames 215 / 63 42 / 7

Frames over 500 ms are 4 in each run, almost all in the first minute while the world loads.

The gain is not from more free RAM: physical free RAM was lower in the 64 run (minutes 2-4 averaged ~0.7-0.9 GB against ~1.9 GB) and private peak is about the same.

Caveats:

  • One run each.
  • The 64 run came second, so the OS file cache was warmer.
  • No context-switch trace on my side.

Telemetry reports (cleaned): VESPER_SECTION_MB=0: vesper_report_20261130-212504_5e5b56c_clean.zip, VESPER_SECTION_MB=64: vesper_report_20261130-213150_5e5b56c_clean.zip. The launcher's own bundles still carry local paths and names in drive_telemetry.log (details in #23). In these copies every file was scrubbed of paths, machine and user names, the title's folder, executable, id and file names, 64-bit hashes and user ids. Nothing else was changed.

Looks like a clear win on this machine, in the same direction as your numbers.

**@⁠thefafu** on GitHub · 2026-11-30 18:38 UTC · [original](https://github.com/monte-alt/vesper/issues/4#issuecomment-7288145524) · edited 2026-11-30 18:49 UTC @⁠FeelsGoodMan2 I ran your branch here. One run each, back to back, so not a benchmark, but the difference is large. **Setup:** same PC as #5: 7800X3D, 32 GB DDR5-4800, RX 9060 XT 16 GB (driver 32.0.32029.2010), Windows 11 build 26300, inbox D3D12. - Build: `section-split` at `5e5b56c`, release, unchanged. - `scripts\launch.cmd` [1] Series X 1440p native with telemetry, otherwise stock. Only `VESPER_SECTION_MB` was passed through. - Note: in this commit an unset `VESPER_SECTION_MB` means 64, not 0. The 0 run therefore sets 0 explicitly, unlike the claim's "0 = as today, default". - Same restored save, same route, ~270 s each. The 0 run was first. With 64 the log shows `mb=6236 sections=98` and `mb=710 sections=12`, as in your run. With 0 that line does not appear. | Metric (`summary.txt`) | `VESPER_SECTION_MB=0` | `VESPER_SECTION_MB=64` | |---|---:|---:| | Duration / gameplay frames | 270.5 s / 4,301 | 269.8 s / 4,649 | | p50 FPS (ms) | 18.02 (55.5) | 18.61 (53.7) | | p95 ms | 99.9 | 87.8 | | p99 ms / 1% low | 197.9 / 5.05 FPS | 104.3 / 9.59 FPS | | Frames > 100 ms | 5.0 % (215) | 1.36 % (63) | | Longest > 100 ms streak | 7 frames | 4 frames | | GPU busy, mean | 83.9 % | 86.8 % | | Private peak | 35,457 MB | 35,873 MB | Per minute, from `drive_frames.csv` (frames with more than 50 draws, so in play). The draws per frame show the load was comparable: | Minute | Draws / frame (0 / 64) | Avg ms (0 / 64) | > 100 ms (0 / 64) | > 200 ms (0 / 64) | |---|---:|---:|---:|---:| | 1 | 7,217 / 8,129 | 54.0 / 55.1 | 7 / 5 | 4 / 1 | | 2 | 9,211 / 9,630 | 59.9 / 60.1 | 21 / 25 | 1 / 0 | | 3 | 10,358 / 10,239 | 63.9 / 59.4 | 30 / 1 | 0 / 0 | | 4 | 10,486 / 9,937 | 68.8 / 60.0 | 87 / 21 | 15 / 2 | | All | 4,318 / 4,661 frames | | 215 / 63 | 42 / 7 | Frames over 500 ms are 4 in each run, almost all in the first minute while the world loads. **The gain is not from more free RAM:** physical free RAM was *lower* in the 64 run (minutes 2-4 averaged ~0.7-0.9 GB against ~1.9 GB) and private peak is about the same. **Caveats:** - One run each. - The 64 run came second, so the OS file cache was warmer. - No context-switch trace on my side. **Telemetry reports (cleaned):** `VESPER_SECTION_MB=0`: [vesper_report_20261130-212504_5e5b56c_clean.zip](https://github.com/user-attachments/files/35634752/vesper_report_20261130-212504_5e5b56c_clean.zip), `VESPER_SECTION_MB=64`: [vesper_report_20261130-213150_5e5b56c_clean.zip](https://github.com/user-attachments/files/35634770/vesper_report_20261130-213150_5e5b56c_clean.zip). The launcher's own bundles still carry local paths and names in `drive_telemetry.log` (details in #23). In these copies every file was scrubbed of paths, machine and user names, the title's folder, executable, id and file names, 64-bit hashes and user ids. Nothing else was changed. Looks like a clear win on this machine, in the same direction as your numbers.
This discussion has been locked. Commenting is limited to contributors.
No description provided.