Skip to content

kernelx: keep lazy pages on failed MEM_COMMIT (#467) - #487

Open
Grimkaaah wants to merge 1 commit into
xcl-dev:mainfrom
Grimkaaah:fix/467-lazy-commit-keep-on-fail
Open

Grimkaaah wants to merge 1 commit into
xcl-dev:mainfrom
Grimkaaah:fix/467-lazy-commit-keep-on-fail

Conversation

@Grimkaaah

Copy link
Copy Markdown

Summary

  • Remove a lazy physical page from LAZY only after VirtualAlloc(MEM_COMMIT) succeeds, so a commitment-limit failure can be retried instead of becoming a bare 0xc0000005 on still-reserved memory.
  • Record failed commits in atomics (count, last page, GetLastError) and append fail_summary() to the AV crash line in eh.rs.
  • lazy::ensure now returns bool; DirectStorage writable() fails closed when a destination page cannot be committed.

Fixes #467

Test plan

  • cargo test -p xcl --lib hle::kernelx::lazy:: (3 passed, including failed-commit keeps page lazy)

Only remove a page from LAZY after VirtualAlloc succeeds; record fail count/page/GetLastError for the crash line; ensure returns false so DirectStorage refuses unwritable destinations.

Co-authored-by: Cursor <cursoragent@cursor.com>
mdberkey

This comment was marked as off-topic.

@shdann shdann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lazy::ensure can reject a writable destination when two callers snapshot the same lazy page. The first caller commits it and removes it from LAZY. The second then gets false from commit because the entry is gone. dstorage::writable treats that as a commit failure and rejects the request. Please distinguish an entry that is already gone from a failed VirtualAlloc, and let the existing writability check handle the former. A two-caller test should check that both requests succeed when the page was committed successfully. Static review with OpenAI Codex (GPT-6).

T-Crypt added a commit to T-Crypt/bathyal that referenced this pull request Nov 24, 2026
From xcl-dev/xcl#487 by @Grimkaaah, squashed.
Supersedes xcl-dev/xcl#488 (dropped: its child-process test overflows the stack under the job commit limit instead of hitting the limit, so the crash-line assertion cannot hold).
@brothernog

Copy link
Copy Markdown

Tested bf21bcb on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug. This adds one thing to the comparison on #467, about the dstorage.rs hunk: it does change behaviour, and it can refuse a healthy destination.

ensure takes the lazy pages under the read lock (lazy.rs:129), drops it, then calls commit for each. commit returns false when the page is no longer in LAZY (lazy.rs:67), which is also the case when another thread committed it in between: a second ensure, or the title touching the page and the vectored handler committing it. ensure then reports a failure, and writable (dstorage.rs:728) fails a request whose pages are all committed and writable.

I added a temporary test (removed afterwards): 256 lazy pages, two threads behind a barrier call ensure over the same range. In 5 of 5 runs at least one call returned false (4 runs [false, false], 1 run [true, false]), and every page was committed afterwards.

Dropping the hunk keeps the fix: writable already checks every page with VirtualQuery after ensure, so a page that stayed reserved fails there. If you want the bool kept, commit could tell "not lazy any more" apart from "the commit failed", and ensure could return false only for the second case.

This review was AI-assisted.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of bf21bcba64680fb85a01e4802a86971af03c4e36 on AMD RDNA4. I merged it onto current main 6025201 locally (clean merge).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 705 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 664 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the lazy tests pass, the failed-commit one included.

Review: Removing a lazy page from LAZY only after MEM_COMMIT succeeds is right. Overlap with #512 (open), whose title is about the e2e test output but which also changes kernelx/lazy.rs to keep the page on a failed commit; the two will conflict there, and this PR is the one that is about #467.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@asd3670576

Copy link
Copy Markdown

Built and tested the PR head on a Windows 10 machine that has no Shader Model 6.6 and only a GNU toolchain. Every count below is pasted from the run, not written by hand.

Machine

  • Windows 10 Pro for Workstations 19045.3324 (22H2), Rust/cargo 1.100.0, host toolchain x86_64-pc-windows-gnu (no MSVC, no Windows SDK: cargo build here needs MinGW-w64 on PATH or it dies with error calling dlltool 'dlltool.exe': program not found), Ryzen 9 5950X (32 logical CPUs), 64 GB RAM.
  • GPU: RTX 3080 20 GB, driver 610.88. DXC 1.9.2609.5 at H:\leonida\dxc\bin\x64 (XCL_DXC_DIR). Agility 1.620.2 at H:\leonida\agility\build\native\bin\x64 (XCL_D3D12_DIR) but it cannot load on this OS build (no ID3D12SDKConfiguration1 before KB5029331), so the inbox runtime caps at Shader Model 6.5 and XCL's GPU recompiler path is unavailable here.
  • Release profile throughout. No title run here, so no xcl-smoke block from this machine.

Apply / build

  • git fetch https://github.com/ivall/xcl pull/487/head:pr487 → bf21bcba64680fb85a01e4802a86971af03c4e36, checked out as-is: no rebase, no conflict resolution, git status --porcelain empty before the build and after it. The API reports mergeable: true, mergeable_state: unstable against current main.
  • cargo build --release --workspace → exit code 0:
    Finished `release` profile [optimized] target(s) in 27.75s

Tests

cargo test --release -p xcl --lib -- kernelx::lazy, three runs on the default thread count:

run 1: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.02s
run 2: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.02s
run 3: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.02s

cargo test --release -p xcl --lib -- gpu::recomp::dxc:

test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 644 filtered out; finished in 0.44s

cargo test --release -p xcl --lib -- kernelx::lazy gpu::recomp::dxc (both modules in one process, default threads):

test result: ok. 17 passed; 0 failed; 0 ignored; 0 measured; 641 filtered out; finished in 0.44s

cargo test --release --workspace --no-fail-fast -- --test-threads=4 → exit code 0. 16 test result: lines (one per test binary plus the doc-test run); the xcl lib is:

test result: ok. 637 passed; 0 failed; 21 ignored; 0 measured; 0 filtered out; finished in 5.28s

all 16 are ok; summed over them: 677 passed; 0 failed; 41 ignored. Skips, reported rather than counted as coverage: 86 SKIPPED lines, 84 : no GPU and 2 : no wave64, for example

SKIPPED gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no GPU
SKIPPED gpu::recomp::mesh_dispatch::tests::gpu_dispatch_matches_native_wave64_reference: no GPU

Forcing the requirement shows the SM 6.5 cap directly (XCL_REQUIRE_GPU=mesh cargo test --release -p xcl --lib -- --exact gpu::recomp::tests::gpu_bvh_intersect_ray):

thread 'gpu::recomp::tests::gpu_bvh_intersect_ray' (20752) panicked at crates\xcl\src\gpu\recomp\runner.rs:439:9:
gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU, but XCL_REQUIRE_GPU=mesh

On the dstorage.rs hunk. The code in this head agrees with @brothernog's reading: commit returns false both when the page is no longer in LAZY (another thread committed it) and when VirtualAlloc fails, and ensure maps either one to false. The pre-existing threads_first_touching_one_lazy_page_together_all_go_on drives the pages through the vectored handler rather than through ensure and asserts nothing about a return value, so it cannot catch that case; the new test covers the failed-commit path only. I did not measure the race itself here.

What this machine can and cannot verify. It can verify that the head builds in release with the GNU toolchain, that the three kernelx::lazy tests are stable here (3/3, and 17/17 with the dxc tests in the same process), and that nothing else in the workspace regresses. It cannot verify the case the fix is about: with 64 GB of RAM and a 153 GB commit limit (125 GB of it free) nothing here reaches ERROR_COMMITMENT_LIMIT, so commit's failure branch only runs because the test injects a failing allocator. And because the adapter caps at SM 6.5, no GPU test executed at all — the 84 skips are the whole GPU surface, so this run says nothing about the recompiler paths.

AI use: an agent (DeepSeek Harness, "auto" route - I do not know the underlying model) built the head, ran the tests and pasted the output.

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #488 solves the same problem (for #467) in a different way: #1607, group D13. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of bf21bcba on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: bf21bcba64680fb85a01e4802a86971af03c4e36
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1461)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14765 MB

Against the limits in CONTRIBUTING.md: 90 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kernelx: a lazy physical page whose commit fails leaves the lazy set, silently

8 participants