tests: xmem commit-on-touch checks read the test's own view, not system commit (TEST-XMEM-COMMIT-CHECK) #1316

Open
github-bot wants to merge 1 commit from github-bot/gh-1316 into main AGit
Owner

@⁠GuilhermeG5 on GitHub · 2026-11-24 21:47 UTC · original
GuilhermeG5:pr/xmem-commit-check → main · +22 −6 · 1 files · 1 commits · open

Requested by Guilherme Correa · project thread

Claimed in the coordination issue as: TEST-XMEM-COMMIT-CHECK

What and why

xmem_test failed intermittently in full CTest runs (about once in a dozen on our machine). The two checks in
test_physical_pages_commit_on_touch that decide whether mapping or touching physical pages charges commit compared
GetPerformanceInfo().CommitTotal before and after. CommitTotal is system-wide: any other process that commits or
frees memory in between moves it. With ctest -R ^xmem$ --repeat until-fail:500 while a build ran, the check failed
on run 20, and with the values printed, on run 55 with -120 MiB where +32 MiB (512 x 64 KiB) was expected. It was
never the shim: when the machine was quiet the growth was 32.6-39.7 MiB.

The checks now count the committed (MEM_COMMIT) 64 KiB pages of the test's own view with VirtualQuery, which is
the state commit_mapped_page itself reads: 0 after mapping, exactly the 512 touched pages after writing. The
system-wide growth is still printed, as information only. "Allocating those pages does not charge them" keeps
CommitTotal: there is no view to query yet, and its bound (1/8 of the allocation) was not hit.

Overlaps: #417 changes the same check differently (it re-measures CommitTotal on two more page windows when the first
measurement misses). This PR stops depending on the system-wide counter instead. Whichever lands first, I will rebase
the other side's leftovers; I am also happy to fold this into #417 if its author prefers.

Tested

  • ctest -R ^xmem$ --repeat until-fail:500 under a concurrent full build: 500/500 (before: failures at runs 20 and
    55); the printed system-wide growth ranged from -236 MiB to +313 MiB meanwhile.
  • On this branch (main abc0bd884 + this commit): xmem passes; --repeat until-fail:100: 100/100.
  • Full CTest on main 6293c1c4f with this and other local changes: 315 registered, 302 passed, 11 skipped, 1 disabled,
    1 failed (d3d12_execute_indirect_validation, which fails the same way on unmodified main on this machine).

GPUs tested: NVIDIA GeForce RTX 2060 SUPER, driver 621.01, Windows 11 10.0.26300 (the test is CPU-only)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

**@⁠GuilhermeG5** on GitHub · 2026-11-24 21:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1316) `GuilhermeG5:pr/xmem-commit-check` → `main` · +22 −6 · 1 files · 1 commits · open <!-- claude-projects-attribution: {"github_login":"GuilhermeG5"} --> _Requested by **Guilherme Correa** · [project thread](https://claude.ai/code/project/chan_013Mx1uQ9UtTn7cwcX32t6xG?thread=cmsg_013Mx1uQ9UtTn7cwcX32t6xGWaMHTZvbN9nhuPiAga22tf)_ Claimed in the coordination issue as: TEST-XMEM-COMMIT-CHECK ### What and why `xmem_test` failed intermittently in full CTest runs (about once in a dozen on our machine). The two checks in `test_physical_pages_commit_on_touch` that decide whether mapping or touching physical pages charges commit compared `GetPerformanceInfo().CommitTotal` before and after. CommitTotal is system-wide: any other process that commits or frees memory in between moves it. With `ctest -R ^xmem$ --repeat until-fail:500` while a build ran, the check failed on run 20, and with the values printed, on run 55 with -120 MiB where +32 MiB (512 x 64 KiB) was expected. It was never the shim: when the machine was quiet the growth was 32.6-39.7 MiB. The checks now count the committed (`MEM_COMMIT`) 64 KiB pages of the test's own view with `VirtualQuery`, which is the state `commit_mapped_page` itself reads: 0 after mapping, exactly the 512 touched pages after writing. The system-wide growth is still printed, as information only. "Allocating those pages does not charge them" keeps CommitTotal: there is no view to query yet, and its bound (1/8 of the allocation) was not hit. Overlaps: #417 changes the same check differently (it re-measures CommitTotal on two more page windows when the first measurement misses). This PR stops depending on the system-wide counter instead. Whichever lands first, I will rebase the other side's leftovers; I am also happy to fold this into #417 if its author prefers. ### Tested - `ctest -R ^xmem$ --repeat until-fail:500` under a concurrent full build: 500/500 (before: failures at runs 20 and 55); the printed system-wide growth ranged from -236 MiB to +313 MiB meanwhile. - On this branch (main abc0bd884 + this commit): `xmem` passes; `--repeat until-fail:100`: 100/100. - Full CTest on main 6293c1c4f with this and other local changes: 315 registered, 302 passed, 11 skipped, 1 disabled, 1 failed (`d3d12_execute_indirect_validation`, which fails the same way on unmodified main on this machine). GPUs tested: NVIDIA GeForce RTX 2060 SUPER, driver 621.01, Windows 11 10.0.26300 (the test is CPU-only) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test_physical_pages_commit_on_touch decided whether mapping or touching
physical pages charges commit by comparing GetPerformanceInfo's
CommitTotal before and after. CommitTotal is system-wide, so another
process that commits or frees memory in between moves it: with
`ctest -R ^xmem$ --repeat until-fail:500` while a build ran, the check
failed at run 20, and with the values printed at run 55, where CommitTotal
moved -120 MiB instead of the expected +32 MiB (512 x 64 KiB). When the
machine was quiet the growth was 32.6-39.7 MiB: the shim was right.

"Mapping them does not charge them" and "writing to 512 of them charges
..." now count the committed (MEM_COMMIT) 64 KiB pages of the test's own
view with VirtualQuery, the state commit_mapped_page reads: 0 after
mapping, exactly the 512 touched pages after writing. The system-wide
growth is printed as information only.

Verified: 500 of 500 repeats under a concurrent full build, while the
printed system-wide growth ranged from -236 MiB to +313 MiB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:47:12 +00:00
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 23:38 UTC · original

Independent verification (AI-assisted, overnight review batch):

  • Checked out e668886; single-commit diff to runtime/test/xmem_test.cpp only (+22/-6).
  • Rebuilt xmem_test (Ninja, MSVC 14.44, RelWithDebInfo) on this head and ran it on this machine (Windows 11, NVIDIA RTX + Radeon; the test is CPU-only): 217/217 checks PASS, including the reworked ones:
    • mapping them does not charge them (no page of the view committed)
    • writing to 512 of them charges exactly those 512 pages (committed in the view)
  • Ran it 3 times: 3/3 OK. The informational line shows system commit growing ~32-36 MiB between samples (other activity on this machine) while the view-based check stays exact — consistent with the flakiness claim.
  • Note: an initial run showed 15 unrelated FAILs ("open the startup trace file") because this shell exports empty TEMP/TMP and GetTempPathW then fails; with TEMP/TMP set the suite is fully green. Environmental, not related to the change.
  • Logic review: committed_pages counts MEM_COMMIT 64 KiB pages via VirtualQuery over the test's own view — the same state commit_mapped_page reads; bounds (==0 after map, ==kTouched after touch, all of first kTouched committed) are stricter than the old CommitTotal band and no longer depend on system-wide noise. CommitTotal is still used for the allocate-does-not-charge check, which has no view yet — reasonable.
  • LGTM.
**@⁠whoalin1** on GitHub · 2026-11-24 23:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1316#issuecomment-7147624704) Independent verification (AI-assisted, overnight review batch): - Checked out e668886; single-commit diff to `runtime/test/xmem_test.cpp` only (+22/-6). - Rebuilt `xmem_test` (Ninja, MSVC 14.44, RelWithDebInfo) on this head and ran it on this machine (Windows 11, NVIDIA RTX + Radeon; the test is CPU-only): **217/217 checks PASS**, including the reworked ones: - `mapping them does not charge them (no page of the view committed)` - `writing to 512 of them charges exactly those 512 pages (committed in the view)` - Ran it 3 times: 3/3 OK. The informational line shows system commit growing ~32-36 MiB between samples (other activity on this machine) while the view-based check stays exact — consistent with the flakiness claim. - Note: an initial run showed 15 unrelated FAILs ("open the startup trace file") because this shell exports empty TEMP/TMP and `GetTempPathW` then fails; with TEMP/TMP set the suite is fully green. Environmental, not related to the change. - Logic review: `committed_pages` counts MEM_COMMIT 64 KiB pages via VirtualQuery over the test's own view — the same state `commit_mapped_page` reads; bounds (==0 after map, ==kTouched after touch, all of first kTouched committed) are stricter than the old CommitTotal band and no longer depend on system-wide noise. CommitTotal is still used for the allocate-does-not-charge check, which has no view yet — reasonable. - LGTM.
Author
Owner

@⁠djrolfes on GitHub · 2026-11-25 06:25 UTC · original

Wine follow-up relevant to this test change: on Wine 11.22, main 42537e7b6 (clang-cl/xwin), xmem / xmem_no_write_watch / xmem_write_watch each fail the touched-page commit-accounting check and two existing read-only-fault checks. The preserved ac7c3449d integration build fails those same checks plus three older VirtualQuery/view checks. No game files involved.

#983 already records that Wine can leave SEC_RESERVE views reporting MEM_RESERVE after writes, so the new view-based count should also be compared with an unshimmed host control on Wine rather than assume the Windows measurements transfer. This is not a request to relax the Windows assertions or skip protection correctness. Detailed source locations and the remaining fault-handler question: #1608 . Happy to retest a Wine-aware version. AI-assisted.

**@⁠djrolfes** on GitHub · 2026-11-25 06:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1316#issuecomment-7154778541) Wine follow-up relevant to this test change: on Wine 11.22, main 42537e7b6 (clang-cl/xwin), xmem / xmem_no_write_watch / xmem_write_watch each fail the touched-page commit-accounting check and two existing read-only-fault checks. The preserved ac7c3449d integration build fails those same checks plus three older VirtualQuery/view checks. No game files involved. #983 already records that Wine can leave SEC_RESERVE views reporting MEM_RESERVE after writes, so the new view-based count should also be compared with an unshimmed host control on Wine rather than assume the Windows measurements transfer. This is not a request to relax the Windows assertions or skip protection correctness. Detailed source locations and the remaining fault-handler question: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 . Happy to retest a Wine-aware version. AI-assisted.
Author
Owner

@⁠djrolfes on GitHub · 2026-11-25 06:29 UTC · original

Reduced the remaining Wine behaviour to an unshimmed handwritten Win32 host control (no Leonida code, game files, or GPU):

  • CreateFileMapping(PAGE_READWRITE | SEC_RESERVE), then two MapViewOfFile aliases.
  • On Wine 11.22, writing through an uncommitted alias raises no first-touch exception. VirtualQuery still reports MEM_RESERVE / protection 0 for both views.
  • VirtualProtect(alias, PAGE_READONLY) then FAILS with ERROR_INVALID_ADDRESS (487). This reproduces why the two existing xmem read-only checks fail: their chained VirtualProtect precondition fails, not evidence that the shim swallowed a protection fault.
  • Explicitly committing the backing first makes the alias report MEM_COMMIT / PAGE_READWRITE; VirtualProtect succeeds, and a guarded write correctly raises an access violation. Explicitly committing the alias after the implicit-write case also makes protection and fault delivery work normally.

The control uses /EHa and a non-inlined SEH write probe (the initial /EHsc optimized control was not a valid exception-catching control, so its result was discarded). No runtime cause claimed.

Possible narrow fixture correction alongside your owned commit-accounting change: establish the “committed read-only page” precondition explicitly with rt::xmem::commit_physical_range on that first page before the protection checks. That would keep the protection assertions meaningful rather than skip them on Wine. I have not changed the owned test or mixed a workaround into the retail probe. Windows first-touch assertions should stay strict. Source locations: runtime/test/xmem_test.cpp:762-769. AI-assisted.

**@⁠djrolfes** on GitHub · 2026-11-25 06:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1316#issuecomment-7154847906) Reduced the remaining Wine behaviour to an unshimmed handwritten Win32 host control (no Leonida code, game files, or GPU): - CreateFileMapping(PAGE_READWRITE | SEC_RESERVE), then two MapViewOfFile aliases. - On Wine 11.22, writing through an uncommitted alias raises no first-touch exception. VirtualQuery still reports MEM_RESERVE / protection 0 for both views. - VirtualProtect(alias, PAGE_READONLY) then FAILS with ERROR_INVALID_ADDRESS (487). This reproduces why the two existing xmem read-only checks fail: their chained VirtualProtect precondition fails, not evidence that the shim swallowed a protection fault. - Explicitly committing the backing first makes the alias report MEM_COMMIT / PAGE_READWRITE; VirtualProtect succeeds, and a guarded write correctly raises an access violation. Explicitly committing the alias after the implicit-write case also makes protection and fault delivery work normally. The control uses /EHa and a non-inlined SEH write probe (the initial /EHsc optimized control was not a valid exception-catching control, so its result was discarded). No runtime cause claimed. Possible narrow fixture correction alongside your owned commit-accounting change: establish the “committed read-only page” precondition explicitly with rt::xmem::commit_physical_range on that first page before the protection checks. That would keep the protection assertions meaningful rather than skip them on Wine. I have not changed the owned test or mixed a workaround into the retail probe. Windows first-touch assertions should stay strict. Source locations: runtime/test/xmem_test.cpp:762-769. AI-assisted.
Author
Owner

@⁠Diegobecker07 on GitHub · 2026-11-25 13:24 UTC · original

Data point for this PR: on main 0d80bc5df (Windows 11 Pro 26300, RTX 5070 Ti, driver 621.24), xmem, xmem_no_write_watch and xmem_write_watch each failed once on writing to 512 of them charges about those 512 pages. Two other runtime builds and ctest runs were going on the same machine at the time. Rerun alone, all three passed 3/3. That is the system-wide CommitTotal case this PR describes.

AI-assisted.

**@⁠Diegobecker07** on GitHub · 2026-11-25 13:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1316#issuecomment-7163742847) Data point for this PR: on main 0d80bc5df (Windows 11 Pro 26300, RTX 5070 Ti, driver 621.24), `xmem`, `xmem_no_write_watch` and `xmem_write_watch` each failed once on `writing to 512 of them charges about those 512 pages`. Two other runtime builds and ctest runs were going on the same machine at the time. Rerun alone, all three passed 3/3. That is the system-wide `CommitTotal` case this PR describes. AI-assisted.
Author
Owner

@⁠ammonium231 on GitHub · 2026-11-26 00:04 UTC · original

Tested e6688869a's change on RTX 3090 (NVIDIA 621.40, Windows 11 26320) at main db1a22d2 (CPU-only test).
On main, ctest -j 4 was 452/453; xmem_write_watch failed once with "writing to 512 of them charges about those 512 pages", then passed 3/3 alone. With this change, ctest -j 4 is 453/453 and ctest -R ^xmem --repeat until-fail:10 passed.

**@⁠ammonium231** on GitHub · 2026-11-26 00:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1316#issuecomment-7178358466) Tested e6688869a's change on RTX 3090 (NVIDIA 621.40, Windows 11 26320) at main db1a22d2 (CPU-only test). On main, ctest -j 4 was 452/453; xmem_write_watch failed once with "writing to 512 of them charges about those 512 pages", then passed 3/3 alone. With this change, ctest -j 4 is 453/453 and `ctest -R ^xmem --repeat until-fail:10` passed.
This pull request has changes conflicting with the target branch.
  • runtime/test/xmem_test.cpp
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 origin '+refs/pull/1316/head:github-bot/gh-1316'
git switch 'github-bot/gh-1316'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1316'
git switch 'github-bot/gh-1316'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1316'
git switch 'github-bot/gh-1316'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1316'
git switch 'main'
git merge --squash 'github-bot/gh-1316'
git switch 'main'
git merge --ff-only 'github-bot/gh-1316'
git switch 'main'
git merge 'github-bot/gh-1316'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.