Skip to content

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

Draft
vakaobr wants to merge 1 commit into
xcl-dev:mainfrom
vakaobr:kernelx/private-usage-zero
Draft

vakaobr wants to merge 1 commit into
xcl-dev:mainfrom
vakaobr:kernelx/private-usage-zero

Conversation

@vakaobr

@vakaobr vakaobr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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.
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No concrete code defect found. The VirtualQuery fallback correctly sums committed private regions when K32 PrivateUsage is zero/fails, and opt-in 2s activity sampling keeps cost bounded. Merge readiness still needs the required description/smoke evidence. The 256 MiB process-wide allocation test has parallel flake/resource risk (it permits 64 MiB concurrent freeing); consider a controlled lower-allocation seam or document the cost. An independent Win11 report also notes an intermittent parallel abort worth reproducing.

@Oliwettoo

Copy link
Copy Markdown

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.

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
vakaobr added a commit to vakaobr/xcl that referenced this pull request Nov 26, 2026
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.

5 participants