xmem: 64-page aligned fault-ahead batch commit (XMEM-FAULT-BATCH-COMMIT) #1707

Closed
Tortoche wants to merge 1 commit from upstream-pr/1707 into main
Tortoche commented 2026-11-25 08:56:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tortoche on 2026-11-25T08:56:28Z.


Claim: XMEM-FAULT-BATCH-COMMIT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157581316)

AI-assisted: yes

Summary

  • Implement 64-page-aligned (4 MiB) fault-ahead batch commit in commit_mapped_page (runtime/shims/xmem.cpp), clamped to [0, view.count).
  • Preserve the existing VirtualQuery + info.State == MEM_COMMIT guard so access_allowed continues to enforce PAGE_READONLY and PAGE_GUARD faults.
  • Fall back to single-page VirtualAlloc if a multi-page batch VirtualAlloc fails.
  • Notify leonida::geometry_writes::notify for the committed range and leonida::title_memory_map::changed().
  • Add test_fault_batch_commit in runtime/test/xmem_test.cpp covering 64-page aligned batch commit, view-boundary clamping (< 64 pages), and PAGE_READONLY protection preservation across a committed batch.

Testing

  • python3 -I scripts/check_no_game_data.py runtime/shims/xmem.cpp runtime/test/xmem_test.cpp -> PASS
  • python3 -I tests/test_text_write_line_endings.py -> PASS (Ran 3 tests in 20.988s, OK)
  • Windows (cmake --build runtime/build --config RelWithDebInfo --target xmem_test gta6rt + ctest --test-dir runtime/build -C RelWithDebInfo -R "^xmem" --output-on-failure):
    • 1/3 Test #48: xmem ............................. Passed 3.23 sec
    • 2/3 Test #49: xmem_no_write_watch .............. Passed 3.21 sec
    • 3/3 Test #50: xmem_write_watch ................. Passed 3.21 sec
    • 100% tests passed out of 3 (9.68 sec)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5488178690 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1707). Originally posted by [Tortoche](https://github.com/Tortoche) on 2026-11-25T08:56:28Z. --- Claim: `XMEM-FAULT-BATCH-COMMIT` (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157581316) AI-assisted: yes ## Summary - Implement 64-page-aligned (4 MiB) fault-ahead batch commit in `commit_mapped_page` (`runtime/shims/xmem.cpp`), clamped to `[0, view.count)`. - Preserve the existing `VirtualQuery` + `info.State == MEM_COMMIT` guard so `access_allowed` continues to enforce `PAGE_READONLY` and `PAGE_GUARD` faults. - Fall back to single-page `VirtualAlloc` if a multi-page batch `VirtualAlloc` fails. - Notify `leonida::geometry_writes::notify` for the committed range and `leonida::title_memory_map::changed()`. - Add `test_fault_batch_commit` in `runtime/test/xmem_test.cpp` covering 64-page aligned batch commit, view-boundary clamping (`< 64` pages), and `PAGE_READONLY` protection preservation across a committed batch. ## Testing - `python3 -I scripts/check_no_game_data.py runtime/shims/xmem.cpp runtime/test/xmem_test.cpp` -> PASS - `python3 -I tests/test_text_write_line_endings.py` -> PASS (Ran 3 tests in 20.988s, OK) - Windows (`cmake --build runtime/build --config RelWithDebInfo --target xmem_test gta6rt` + `ctest --test-dir runtime/build -C RelWithDebInfo -R "^xmem" --output-on-failure`): - `1/3 Test #48: xmem ............................. Passed 3.23 sec` - `2/3 Test #49: xmem_no_write_watch .............. Passed 3.21 sec` - `3/3 Test #50: xmem_write_watch ................. Passed 3.21 sec` - `100% tests passed out of 3` (9.68 sec)
PierreEbele commented 2026-11-25 17:44:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T17:44:14Z.


Reviewed a4d8625: xmem_test is Windows/MSVC-only so it was not executed here. cmake+ninja host_cpu_test builds clean on both trees, and a g++ model of the exact batch arithmetic swept ~90k decisions on both trees with 0 violations and the asserted batches as written. Found: git merge-tree reports conflicts against current main in both changed files, and the rebase is not mechanical (sections_committed(), the plant/promote flow, and the ranged changed(from,to), which should receive the batch range). Not verified (no Windows/Wine here): the new test asserts MEM_COMMIT states ungated, whereas this file gates such checks on Wine (touched_view_reported_reserved), so the report-only Wine run may flag it after a rebase.

AI-assisted review.

Recommendation: Fix first

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7169927202 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1707#issuecomment-7169927202). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T17:44:14Z. --- Reviewed a4d8625: xmem_test is Windows/MSVC-only so it was not executed here. cmake+ninja host_cpu_test builds clean on both trees, and a g++ model of the exact batch arithmetic swept ~90k decisions on both trees with 0 violations and the asserted batches as written. Found: `git merge-tree` reports conflicts against current main in both changed files, and the rebase is not mechanical (sections_committed(), the plant/promote flow, and the ranged changed(from,to), which should receive the batch range). Not verified (no Windows/Wine here): the new test asserts MEM_COMMIT states ungated, whereas this file gates such checks on Wine (touched_view_reported_reserved), so the report-only Wine run may flag it after a rebase. AI-assisted review. **Recommendation:** Fix first
zmasi commented 2026-11-28 22:10:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:10:53Z.


Independent Verification Report — 653b631048 + origin/main (c7753ed98a)

Environment: Native Windows 11 (26200), AMD Ryzen 9 5950X, MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8, /O2 /MD, linked with /BASE:0x140000000 /DYNAMICBASE:NO).
Verdict: PASS (Ready to merge — first native Windows 11 + MSVC execution) — clean Git merge with origin/main (6ba4944fabf2) and combined Batch 11 set (6a93c1e1e828).

1. Red -> Green Verification on Native Windows 11

  • Red (origin/main xmem.cpp + #1707 xmem_test.cpp): xmem_test fails (rc = 1, 506 checks, 4 failures) in test_fault_batch_commit:
    • FAIL touching page 5 commits aligned batch [0, 64)
    • FAIL touching page 70 commits aligned batch [64, 128)
    • FAIL touching page 3 commits partial view [0, 10)
    • FAIL PAGE_READONLY protection is preserved on other pages inside a batch-committed view
  • Green (653b631048 + origin/main):
    • xmem_test (default): PASS (506/506 checks)
    • xmem_test --pool-zero-read: PASS (24/24 checks)
    • xmem_test (LEONIDA_WRITE_WATCH=0): PASS (486/486 checks)
    • xmem_test (LEONIDA_WRITE_WATCH=1): PASS (506/506 checks)
  • Source Audit: commit_mapped_page clamps [batch_begin_idx, batch_end_idx) strictly to [0, it->second.count), notifies both geometry_writes::notify and title_memory_map::changed over the exact committed range, preserves per-view PAGE_READONLY mappings, and falls back cleanly to a single-page VirtualAlloc commit if a 4 MiB batch commit fails under memory pressure.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246552986 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1707#issuecomment-7246552986). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:10:53Z. --- ### Independent Verification Report — `653b631048` + `origin/main` (`c7753ed98a`) **Environment:** Native Windows 11 (`26200`), AMD Ryzen 9 5950X, MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8`, `/O2 /MD`, linked with `/BASE:0x140000000 /DYNAMICBASE:NO`). **Verdict:** **PASS (Ready to merge — first native Windows 11 + MSVC execution)** — clean Git merge with `origin/main` (`6ba4944fabf2`) and combined Batch 11 set (`6a93c1e1e828`). #### 1. Red -> Green Verification on Native Windows 11 - **Red (`origin/main` `xmem.cpp` + `#1707` `xmem_test.cpp`):** `xmem_test` fails (`rc = 1`, `506 checks, 4 failures`) in `test_fault_batch_commit`: - `FAIL touching page 5 commits aligned batch [0, 64)` - `FAIL touching page 70 commits aligned batch [64, 128)` - `FAIL touching page 3 commits partial view [0, 10)` - `FAIL PAGE_READONLY protection is preserved on other pages inside a batch-committed view` - **Green (`653b631048` + `origin/main`):** - `xmem_test` (default): **PASS (`506/506` checks)** - `xmem_test --pool-zero-read`: **PASS (`24/24` checks)** - `xmem_test` (`LEONIDA_WRITE_WATCH=0`): **PASS (`486/486` checks)** - `xmem_test` (`LEONIDA_WRITE_WATCH=1`): **PASS (`506/506` checks)** - **Source Audit:** `commit_mapped_page` clamps `[batch_begin_idx, batch_end_idx)` strictly to `[0, it->second.count)`, notifies both `geometry_writes::notify` and `title_memory_map::changed` over the exact committed range, preserves per-view `PAGE_READONLY` mappings, and falls back cleanly to a single-page `VirtualAlloc` commit if a 4 MiB batch commit fails under memory pressure. AI-assisted.
TheGeogeo commented 2026-11-29 06:52:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T06:52:44Z.


Tested 653b63104 merged (no commit) with main ef3299584. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. check_no_game_data.py is clean.

  • Base: xmem, xmem_no_write_watch and xmem_write_watch pass on plain main ef3299584.
  • Green: all three pass on the merge.
  • Red: with runtime/shims/xmem.cpp back to main, all three fail in test_fault_batch_commit:
    • touching page 5 commits aligned batch [0, 64)
    • touching page 70 commits aligned batch [64, 128)
    • touching page 3 commits partial view [0, 10)
    • PAGE_READONLY protection is preserved on other pages inside a batch-committed view
  • No regression: the merge rebuilds 150 executables. Of their 252 other tests, only xbox_present fails, as on plain main here.
  • LINK: gta6rt.exe linked without ws2_32.lib gives main's 26 unresolved Rust-std symbols, nothing new. Its imports are identical to main's.
  • Still open from review, and not checkable on this machine: the new test checks MEM_COMMIT without the file's Wine gate (wine_host() / touched_view_reported_reserved). Under Wine, sections_committed() commits whole sections, so "next batch [64, 128) stays uncommitted" would not hold there.

No blocker from my side. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7252124280 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1707#issuecomment-7252124280). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T06:52:44Z. --- Tested `653b63104` merged (no commit) with `main` `ef3299584`. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. `check_no_game_data.py` is clean. - Base: `xmem`, `xmem_no_write_watch` and `xmem_write_watch` pass on plain `main` `ef3299584`. - Green: all three pass on the merge. - Red: with `runtime/shims/xmem.cpp` back to `main`, all three fail in `test_fault_batch_commit`: - `touching page 5 commits aligned batch [0, 64)` - `touching page 70 commits aligned batch [64, 128)` - `touching page 3 commits partial view [0, 10)` - `PAGE_READONLY protection is preserved on other pages inside a batch-committed view` - No regression: the merge rebuilds 150 executables. Of their 252 other tests, only `xbox_present` fails, as on plain `main` here. - LINK: `gta6rt.exe` linked without `ws2_32.lib` gives `main`'s 26 unresolved Rust-std symbols, nothing new. Its imports are identical to `main`'s. - Still open from review, and not checkable on this machine: the new test checks `MEM_COMMIT` without the file's Wine gate (`wine_host()` / `touched_view_reported_reserved`). Under Wine, `sections_committed()` commits whole sections, so "next batch [64, 128) stays uncommitted" would not hold there. No blocker from my side. AI-assisted (Claude Code).
aslan2142 commented 2026-12-01 16:37:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:37:19Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317909727 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1707#issuecomment-7317909727). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:37:19Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1707
No description provided.