Memory: serialize sparse commits and decommits with uploads #233
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/236"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by utkarshxdev on 2026-11-23T21:43:51Z.
Serialize sparse CPU page updates with the upload scan. Previously, the scan could read a page while Windows was decommitting it, or a delayed commit record could mark a decommitted page live again.
What is in it
STATE. A sparse release returns the reservation to the allocator after successful decommit.VirtualAllocin sparse windows requiresMEM_COMMITand a range within one live reservation. Non-commit calls, includingMEM_RESETandMEM_RESET_UNDO, return null andERROR_INVALID_ADDRESS. This changes the previous host passthrough.VirtualQuerybefore attempting a read.Tested
cargo check --locked --target x86_64-pc-windows-msvc --offline --all-targetspassed, with one existing deprecation warning.03d4a86merged into0e946cf: Ryzen 5 5600G, RX 7800 XT driver 32.0.32029.2010, Windows 11 26300, Rust 1.100.0 MSVC.cargo test --workspace -- --test-threads=4reported 655 passed, 0 failed, 40 ignored, and no skips.Regression run
Historical A/B runs from the earlier revision. The display adapter is named in the output. XCL ran on the RX 7800 XT.
Main baseline
Earlier PR revision merged locally
Not tested
xcl-smokepair. The historical retail run did not exercise the sparseVirtualAlloccommit path.AI use
Imported from ivall/xcl. Originally posted by srcamarda on 2026-11-23T23:33:15Z.
AMD run of
03d4a86merged ontomain0e946cf(clean merge), with a retail title, plus a few points from reading the diff.Tested
command_list_slots_include_131_and_132,intro_sparse_reservation_matches_the_observed_request,sparse_commit_rejects_invalid_ranges, the early-commit ones)cargo test --workspace -- --test-threads=4: 655 passed, 0 failed, 40 ignored, noSKIPPEDscripts/smoke.ps1, 90 s, six runs of each binary (two batches of three, each starting with a cold translation cache):main738 / 1 100 / 892 / 1 035 / 1 216 / 1 134 frames, this PR 1 052 / 1 026 / 947 / 948 / 1 194 / 976. Mean ~1 020 for both; no crash or device removal; the same peak commit (~17.2 GB).What the title does with it
mainthe same calls already reach the guard's stub (ID3D12GraphicsCommandList10::#131 (not on PC), 4 + 3 calls; #132 4 + 1), which returns 0 as well. So on this title the new handlers change nothing but the log, andmaindoes not crash there. Which title or build showed the null-vtable crash?XCL_TRACE_MEM, the title's reservations in 90 s are these, and none is0x1_3800_0000with plainMEM_RESERVE/PAGE_NOACCESS; every one carries extra flag bits: (plus three 64K-page / coherent-window ones and the placeholders). NoVirtualAlloc (sparse commit)line either, so the reworked commit path is not reached by this title. A different build of the game?Points from reading the diff
VirtualAlloc: onmaina call on an address in a sparse window withoutMEM_COMMIT(e.g.MEM_RESET/MEM_RESET_UNDO) goes on to the normal path. With this PR it now fails withERROR_INVALID_ADDRESS. Intended? It isn't in the description and has no test.xcl-smokeblocks forPR checks.Regression run (
gpu:names a virtual display adapter here, but XCL ran on the RX 7800 XT). The second run of the second batch for each:main:this PR merged onto
main(local merge commit):Not tested
ERROR_INVALID_ADDRESSpath, the PR on its own, NVIDIA.AI use
Imported from ivall/xcl. Originally posted by ryosen0 on 2026-11-23T23:47:39Z.
Test report on our machine with this PR's head (
03d4a86) stacked on current main (db1ddb2) + #300 + #294 + #273 + #304: Ryzen 7 9800X3D, RTX 3060 Ti 8 GB (wave32), driver 32.0.16.1742, Windows 11.XCL_NETWORK=0 XCL_RUN_SECONDS=240 XCL_ACTIVITY=1 xcl run <retail folder>: clean exit at the timer, 3987 frames shown, no crash, no device removal. Intro stretch ~t=60-165 s at 4.9-6.4 fps, then a steady 30.0 fps to the end; the character loading screen is reached. BCPack refusals in the same run: BC5 44, BC7 20 requests (BC1 unpacked). The 41 console-MS-in-AS-slot refusals are unchanged.The same run without this PR (main + #300 + #294 + #273 + #304, 180 s): the same shape - dip 4.4-8.6 fps at t=44-166 s, 29.9 fps after. So on this hardware the PR neither helped nor hurt the intro pace measurably; the slow stretch looks bounded by something else (we see 6.5 GB local + 4.6 GB non-local video memory on the 8 GB card during it).
Not tested: the command-list slots 131/132 paths in isolation; no unit-test run for this report (run-only data point).
AI use: GPT-6.2 Astra (API model selector) ran the builds and runs and wrote this report; the human contributor watched the screen and reviewed it.
Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T23:52:06Z.
Thanks for this, and thanks @srcamarda and @ryosen0 for the runs. Not merged yet - what would get it in, in this PR:
MEM_RESERVE/PAGE_NOACCESSreservation of0x1_3800_0000, so the path never runs; if a real reservation needs to be in the sparse windows, the rule should come from what the reservation is (its flags / protection), not who makes it.mainthese calls already reach the guard's stub, which returns 0 too, so the new handlers only change the log, and no run showed the null-vtable crash they are meant to prevent. Either drop them, or say which title/build crashed there and with what log.STATE.lock()is the part worth having. Two things for it: say in the description (and cover with a test) the behaviour change srcamarda found -VirtualAllocwithoutMEM_COMMIT(MEM_RESET/MEM_RESET_UNDO) on an address in a sparse window now fails withERROR_INVALID_ADDRESSinstead of taking the normal path; and add a test that shows the race it closes (the upload scan reading a page mid-decommit), failing without the change.The two A/B runs above found no difference on a retail title either way, so with 1 and 2 gone and 3 tested this is a small, safe change. Please keep Tested (suite counts) and the
xcl-smokepair in the description.Imported from ivall/xcl. Originally posted by utkarshxdev on 2026-11-24T16:11:38Z.
Hey @ivall, thanks for the guidance!
I've rebased on latest
mainand addressed all three review items:VirtualAllocnon-commit rejection (ERROR_INVALID_ADDRESS), and added the regression test for the upload scan / decommit ordering race.Branch is clean and rebased with zero conflicts. Ready for workflow approval and review whenever you're free!
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T15:19:42Z.
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T01:53:52Z.
Triage note: this no longer merges with current
main(mergeable=false), so it cannot be built or tested as it stands.Why I am asking rather than just noting it: we have run fifteen mergeable candidates on the retail title on an RTX 5070 Ti, and every one still stops presenting at 50–80 s (device removed, surfacing ~88 s later on the next allocation). The PRs whose descriptions actually match that symptom are the ones that no longer apply — this is one of them. A rebase would make it testable again, and we will run it and report the numbers.
If it has been superseded by merged work, saying so is enough and it can be closed.
AI use: an agent posted this triage note.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:01:24Z.
Triage (#1607) – head
4913af0No open PR makes the same change. Main has since added its own protection for decommits racing uploads:
sparse::decommit(a, n, os)with freeing spans (e0bfb7c1), CPU-view holes during decommit, and coordinated upload plans that recheck pages. The sparse/kernelx code this diff edits has changed a lot.Problems:
kernelx.rstestsparse_virtual_alloc_rejects_out_of_bounds_and_resetcalls.expect("sparse UMA"), so it panics on a machine without a GPU or sparse windows (CI). It should skip there.commit_locked/decommit_lockedhold the sparseSTATElock acrossVirtualAlloc/VirtualFreeand, formap_pages, across a 64 KiB copy. Every submit's upload scan waits behind that.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.