kernelx: the process's commit from VirtualQuery when PrivateUsage is 0 #2362

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

@⁠vakaobr on GitHub · 2026-11-25 16:40 UTC · original
vakaobr:kernelx/private-usage-zero → main · +44 −15 · 2 files · 1 commits · draft

Under Wine, XCL tells a title how much memory it uses from the wrong counter. Wine's K32GetProcessMemoryInfo leaves PrivateUsage 0, and process_private_bytes() then falls back to PagefileUsage, which under CrossOver on macOS is the process's virtual size (~41 GiB) and does not move when memory is committed. TitleMemoryStatus and XMemGetWorkingSetStatistics clamp that to the title memory budget, so a title on a Mac is told it has no memory available, and the activity log's commit figure (which reads PrivateUsage itself) is 0. When PrivateUsage is 0, the commit is now the sum of the process's MEM_COMMIT + MEM_PRIVATE regions from VirtualQuery. Windows, where PrivateUsage is filled, is unchanged.

Part of #258. It touches the same lines in host.rs as #1097, which changes only the activity log and leaves the title-memory functions on PagefileUsage. On Wine under Linux this uses the VirtualQuery sum too, where #1097 keeps PagefileUsage.

What is in it

  • crates/xcl/src/hle/kernelx.rs: process_private_bytes() falls back to a new committed_private_bytes() (a VirtualQuery walk of the address space) instead of PagefileUsage; new test process_private_bytes_counts_a_commit checks that a 256 MB commit shows in both.
  • crates/xcl/src/host.rs: the activity log's "committed by the process" figure uses process_private_bytes().

Tested

  • MacBook Pro M5 Pro, macOS 27.2.1, CrossOver 26.3.0, D3DMetal 3.0. Rust 1.100.0 x86_64-pc-windows-gnu, debug, on main 65fc114.
  • cargo test -p xcl --lib --target x86_64-pc-windows-gnu --no-run, then each test of hle::kernelx::tests in its own process in the CrossOver bottle (--exact <test> --test-threads=1): 42 tests, 41 passed, 0 failed, 1 ignored (scatter_timing), 0 SKIPPED. physical_home_without_sparse_windows_uses_coherent_window passed but its process did not exit within 120 s once; three reruns passed and exited normally.
  • With the fix taken out (test kept), process_private_bytes_counts_a_commit fails: commit 44183973888 -> 44183977984 (+4 KiB on a 256 MB commit). With the fix it passes.

Regression run

  • None: I have no title of my own to run scripts/smoke.ps1 on.

Not tested

  • Windows (native), and Wine on Linux.
  • The whole suite: only the hle::kernelx::tests module ran.
  • Any title: whether a title on a Mac now sizes its pools or streaming differently was not checked.
  • Cost of the VirtualQuery walk when a title calls TitleMemoryStatus / XMemGetWorkingSetStatistics often (not measured).

AI use

  • Claude Code with Claude Opus 5.5 ported the commit from my Mac branch to main, checked open PRs for overlap, built the tests, ran the kernelx tests and the check with the fix taken out under CrossOver, and drafted the commit message and this description.
**@⁠vakaobr** on GitHub · 2026-11-25 16:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/2362) `vakaobr:kernelx/private-usage-zero` → `main` · +44 −15 · 2 files · 1 commits · draft Under Wine, XCL tells a title how much memory it uses from the wrong counter. Wine's `K32GetProcessMemoryInfo` leaves `PrivateUsage` 0, and `process_private_bytes()` then falls back to `PagefileUsage`, which under CrossOver on macOS is the process's virtual size (~41 GiB) and does not move when memory is committed. `TitleMemoryStatus` and `XMemGetWorkingSetStatistics` clamp that to the title memory budget, so a title on a Mac is told it has no memory available, and the activity log's commit figure (which reads `PrivateUsage` itself) is 0. When `PrivateUsage` is 0, the commit is now the sum of the process's `MEM_COMMIT` + `MEM_PRIVATE` regions from `VirtualQuery`. Windows, where `PrivateUsage` is filled, is unchanged. Part of #258. It touches the same lines in `host.rs` as #1097, which changes only the activity log and leaves the title-memory functions on `PagefileUsage`. On Wine under Linux this uses the `VirtualQuery` sum too, where #1097 keeps `PagefileUsage`. **What is in it** - `crates/xcl/src/hle/kernelx.rs`: `process_private_bytes()` falls back to a new `committed_private_bytes()` (a `VirtualQuery` walk of the address space) instead of `PagefileUsage`; new test `process_private_bytes_counts_a_commit` checks that a 256 MB commit shows in both. - `crates/xcl/src/host.rs`: the activity log's "committed by the process" figure uses `process_private_bytes()`. **Tested** - MacBook Pro M5 Pro, macOS 27.2.1, CrossOver 26.3.0, D3DMetal 3.0. Rust 1.100.0 `x86_64-pc-windows-gnu`, debug, on `main` `65fc114`. - `cargo test -p xcl --lib --target x86_64-pc-windows-gnu --no-run`, then each test of `hle::kernelx::tests` in its own process in the CrossOver bottle (`--exact <test> --test-threads=1`): 42 tests, 41 passed, 0 failed, 1 ignored (`scatter_timing`), 0 SKIPPED. `physical_home_without_sparse_windows_uses_coherent_window` passed but its process did not exit within 120 s once; three reruns passed and exited normally. - With the fix taken out (test kept), `process_private_bytes_counts_a_commit` fails: `commit 44183973888 -> 44183977984` (+4 KiB on a 256 MB commit). With the fix it passes. **Regression run** - None: I have no title of my own to run `scripts/smoke.ps1` on. **Not tested** - Windows (native), and Wine on Linux. - The whole suite: only the `hle::kernelx::tests` module ran. - Any title: whether a title on a Mac now sizes its pools or streaming differently was not checked. - Cost of the `VirtualQuery` walk when a title calls `TitleMemoryStatus` / `XMemGetWorkingSetStatistics` often (not measured). **AI use** - Claude Code with Claude Opus 5.5 ported the commit from my Mac branch to `main`, checked open PRs for overlap, built the tests, ran the `kernelx` tests and the check with the fix taken out under CrossOver, and drafted the commit message and this description.
Wine's K32GetProcessMemoryInfo leaves PrivateUsage 0, and its
PagefileUsage is not the commit: on macOS it is the Mach task's virtual
size (~41 GiB, which a commit does not change). process_private_bytes()
took PagefileUsage then, so TitleMemoryStatus and
XMemGetWorkingSetStatistics clamped "used" to the title memory budget
and told the title it had no memory available, and the activity log's
commit figure (which read PrivateUsage itself) was 0.

process_private_bytes() now falls back to the sum of the MEM_COMMIT +
MEM_PRIVATE regions of the address space (VirtualQuery), and host.rs's
activity log uses it instead of reading PrivateUsage itself. Windows,
where PrivateUsage is filled, is unchanged.

Measured under CrossOver 26.3 on macOS: with the old fallback, a 256 MB
commit moved PagefileUsage from 44,183,973,888 to 44,183,977,984 bytes
(+4 KiB). New test process_private_bytes_counts_a_commit: a 256 MB
commit shows in both the counter and the region sum.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:28:56 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 18:50 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 18:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7171468854) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-25 22:44 UTC · original

Read from the diff at 619cbb2 (not run). The fix is right for the counter, but on Wine process_private_bytes() now walks the whole address space with VirtualQuery on every call, and its callers are title-facing: TitleMemoryStatus and XMemGetWorkingSetStatistics, which engines can poll often to size pools and texture streaming. A title with many small regions (a 24 GB reservation of 64 KiB pages, committed piecemeal) has thousands of regions to visit each time. Caching the sum for a short interval (e.g. 250 ms, or refreshed from the 2 s activity tick) would keep a polling title off that walk. Worth a timing under Wine on a retail title before merging.

**@⁠Oliwettoo** on GitHub · 2026-11-25 22:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7176741337) Read from the diff at 619cbb2 (not run). The fix is right for the counter, but on Wine `process_private_bytes()` now walks the whole address space with `VirtualQuery` on every call, and its callers are title-facing: `TitleMemoryStatus` and `XMemGetWorkingSetStatistics`, which engines can poll often to size pools and texture streaming. A title with many small regions (a 24 GB reservation of 64 KiB pages, committed piecemeal) has thousands of regions to visit each time. Caching the sum for a short interval (e.g. 250 ms, or refreshed from the 2 s activity tick) would keep a polling title off that walk. Worth a timing under Wine on a retail title before merging.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2362/head:github-bot/gh-2362'
git switch 'github-bot/gh-2362'

Merge

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