Memory: bound coherent decommits to whole pages in one block #1453

Open
anakatt wants to merge 2 commits from upstream-pr/1463 into main
anakatt commented 2026-11-24 16:29:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by anakatt on 2026-11-24T16:29:21Z.


Stacked on #1357; merge that first. The new change is 215d5eacbf808a4372b69b4843230ce9ff89e4fc on top of 9aa114cda968072c7165578da16313ec0616e646.

I corrected the coherent-memory VirtualFree(MEM_DECOMMIT) path. It cleared only the requested bytes, ignored zero-size decommits, and could overwrite the next allocation.

What is in it

  • Clear whole covered host pages within one live allocation. A zero-size request at the first page clears the whole allocation, matching native Windows after recommit.
  • Reject invalid ranges with Win32 errors before writing, and hold the allocation lock through the clear so free/reuse cannot race it.
  • Keep coherent GPU pages mapped, as before; this does not implement physical decommit or change sparse-memory behavior.
  • Add a native-Windows comparison and update README.

Tested

Windows 11 Pro ARM64 10.0.26100.1742, UTM VM with 4 GiB RAM, x64 Rust 1.100.0 (x86_64-pc-windows-msvc) under Windows emulation. These checks use real virtual memory, not a GPU.

I tested an archive of main 47efa2ecea0a12934719ae69b81930cf02a4b1c3 with #1357's helper and the changed source/test files copied in, then committed those files as the head above. These were not clean-checkout smoke runs.

Before the fix:

cargo test --locked -p xcl --lib hle::kernelx::tests::coherent_decommit_matches_native_page_ranges -- --exact --test-threads=4
0 passed; 1 failed; 0 ignored; 720 filtered out; 0 skipped

The zero-size request left stale data from byte zero, unlike native Windows after recommit.

After the fix:

cargo test --locked -p xcl --lib hle::kernelx::tests::coherent_ -- --test-threads=4
2 passed; 0 failed; 0 ignored; 719 filtered out; 0 skipped

The regression compares return values, failure codes and bytes against native VirtualFree plus recommit: aligned/unaligned first-page zero-size requests, an invalid interior-page zero-size request, a two-page span, and a cross-allocation request. It also verifies that the adjacent allocation stays unchanged and neither allocation is released.

Regression run

Not run. I do not have generated xcl-smoke blocks from clean main and PR-head commits using the same title and duration. This remains a draft until those required runs are available.

Not tested

Full workspace suite, real-title smoke runs, concurrent GPU access and gameplay effects. The tests do not claim physical memory reclamation.

AI use

omp, openai-codex/gpt-6-astra: investigated native Windows behavior, implemented the fix and regression, ran the Windows VM checks, and prepared this PR.

<!-- greyfinch-sync:ivall/xcl:issue:6586532592 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1463). Originally posted by [anakatt](https://github.com/anakatt) on 2026-11-24T16:29:21Z. --- Stacked on #1357; merge that first. The new change is `215d5eacbf808a4372b69b4843230ce9ff89e4fc` on top of `9aa114cda968072c7165578da16313ec0616e646`. I corrected the coherent-memory `VirtualFree(MEM_DECOMMIT)` path. It cleared only the requested bytes, ignored zero-size decommits, and could overwrite the next allocation. ## What is in it - Clear whole covered host pages within one live allocation. A zero-size request at the first page clears the whole allocation, matching native Windows after recommit. - Reject invalid ranges with Win32 errors before writing, and hold the allocation lock through the clear so free/reuse cannot race it. - Keep coherent GPU pages mapped, as before; this does not implement physical decommit or change sparse-memory behavior. - Add a native-Windows comparison and update README. ## Tested Windows 11 Pro ARM64 10.0.26100.1742, UTM VM with 4 GiB RAM, x64 Rust 1.100.0 (`x86_64-pc-windows-msvc`) under Windows emulation. These checks use real virtual memory, not a GPU. I tested an archive of main `47efa2ecea0a12934719ae69b81930cf02a4b1c3` with #1357's helper and the changed source/test files copied in, then committed those files as the head above. These were not clean-checkout smoke runs. Before the fix: ```text cargo test --locked -p xcl --lib hle::kernelx::tests::coherent_decommit_matches_native_page_ranges -- --exact --test-threads=4 0 passed; 1 failed; 0 ignored; 720 filtered out; 0 skipped ``` The zero-size request left stale data from byte zero, unlike native Windows after recommit. After the fix: ```text cargo test --locked -p xcl --lib hle::kernelx::tests::coherent_ -- --test-threads=4 2 passed; 0 failed; 0 ignored; 719 filtered out; 0 skipped ``` The regression compares return values, failure codes and bytes against native `VirtualFree` plus recommit: aligned/unaligned first-page zero-size requests, an invalid interior-page zero-size request, a two-page span, and a cross-allocation request. It also verifies that the adjacent allocation stays unchanged and neither allocation is released. ## Regression run Not run. I do not have generated `xcl-smoke` blocks from clean main and PR-head commits using the same title and duration. This remains a draft until those required runs are available. ## Not tested Full workspace suite, real-title smoke runs, concurrent GPU access and gameplay effects. The tests do not claim physical memory reclamation. ## AI use omp, openai-codex/gpt-6-astra: investigated native Windows behavior, implemented the fix and regression, ran the Windows VM checks, and prepared this PR.
DavidM1911 commented 2026-11-24 19:07:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:58Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141284596 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1463#issuecomment-7141284596). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:52:58Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
CuteBooty commented 2026-11-24 21:09:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CuteBooty on 2026-11-24T21:02:16Z.


Regression run on a retail title for 215d5ea: pass (no device removal, no crash, frames and peak commit within the check's limits).

Tested

  • RTX 3070 8 GB (32-lane waves), NVIDIA 621.24; Ryzen 5 3600, 32 GB; Windows 11 Pro 26200; rustc 1.100.0 MSVC; release build.
  • scripts\smoke.ps1 -Game <folder> -Seconds 60, no input, on this PR's head as it is and on main 47efa2e, the commit it branches from (so with #1357, on which it is stacked, in it), each from a clean checkout. Each build ran twice back to back; the blocks are the second runs. The main block is shared with my reports on other PRs of the same base.

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 1446 (PresentX 1446)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19285 MB

this PR:

xcl-smoke v1
commit: 215d5eacbf808a4372b69b4843230ce9ff89e4fc
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 1490 (PresentX 1490)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18731 MB

Not tested

  • Whether the 60 s reach the code this PR changes, the world load, the test suite, current main merged in, AMD and Intel GPUs.

AI use

  • Claude Code (Claude Opus 5.5) made the runs with me present and wrote this from the script's output.
<!-- greyfinch-sync:ivall/xcl:comment:7144390922 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1463#issuecomment-7144390922). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-24T21:02:16Z. --- Regression run on a retail title for `215d5ea`: **pass** (no device removal, no crash, frames and peak commit within the check's limits). **Tested** - RTX 3070 8 GB (32-lane waves), NVIDIA 621.24; Ryzen 5 3600, 32 GB; Windows 11 Pro 26200; rustc 1.100.0 MSVC; release build. - `scripts\smoke.ps1 -Game <folder> -Seconds 60`, no input, on this PR's head as it is and on `main` `47efa2e`, the commit it branches from (so with #1357, on which it is stacked, in it), each from a clean checkout. Each build ran twice back to back; the blocks are the second runs. The `main` block is shared with my reports on other PRs of the same base. main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 3070 title: game seconds: 60 exit: 0x0 frames shown: 1446 (PresentX 1446) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19285 MB ``` this PR: ``` xcl-smoke v1 commit: 215d5eacbf808a4372b69b4843230ce9ff89e4fc gpu: NVIDIA GeForce RTX 3070 title: game seconds: 60 exit: 0x0 frames shown: 1490 (PresentX 1490) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18731 MB ``` **Not tested** - Whether the 60 s reach the code this PR changes, the world load, the test suite, current `main` merged in, AMD and Intel GPUs. **AI use** - Claude Code (Claude Opus 5.5) made the runs with me present and wrote this from the script's output.
Foniass commented 2026-12-01 05:50:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:50:54Z.


Triage (#1607) – head 215d5ea

Stacked on #1357 (its first commit 9aa114c is #1357); the top commit adds Uma::decommit_coherent (whole pages, bounded to one block). Not a duplicate, and main's coherent VirtualFree still zeroes size bytes unchecked on MEM_DECOMMIT.
Main's MEM_RELEASE path for coherent blocks now also calls forget_title_mappings, mirrors::place_gone/released and sparse::remapped before u.free; coherent_virtual_free's release branch must keep those when this is rebased.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302202147 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1463#issuecomment-7302202147). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:50:54Z. --- **Triage (#1607)** – head 215d5ea Stacked on #1357 (its first commit 9aa114c is #1357); the top commit adds `Uma::decommit_coherent` (whole pages, bounded to one block). Not a duplicate, and main's coherent `VirtualFree` still zeroes `size` bytes unchecked on `MEM_DECOMMIT`. Main's `MEM_RELEASE` path for coherent blocks now also calls `forget_title_mappings`, `mirrors::place_gone`/`released` and `sparse::remapped` before `u.free`; `coherent_virtual_free`'s release branch must keep those when this is rebased. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1463:upstream-pr/1463'
git switch 'upstream-pr/1463'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1463'
git switch 'upstream-pr/1463'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1463'
git switch 'upstream-pr/1463'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1463'
git switch 'main'
git merge --squash 'upstream-pr/1463'
git switch 'main'
git merge --ff-only 'upstream-pr/1463'
git switch 'main'
git merge 'upstream-pr/1463'
git push origin 'main'
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
xcl-dev/xcl!1453
No description provided.