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

Open
vakaobr wants to merge 1 commit from upstream-pr/2362 into main
vakaobr commented 2026-11-25 16:40:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-25T16:40:39Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5495304953 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362). Originally posted by [vakaobr](https://github.com/vakaobr) on 2026-11-25T16:40:39Z. --- 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.
DavidM1911 commented 2026-11-25 19:09:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T18:50:15Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7171468854 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7171468854). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T18:50:15Z. --- 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!
bmjask commented 2026-11-25 20:55:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:55:16Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6064858906 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#pullrequestreview-6064858906). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T20:55:16Z. **Review:** COMMENTED --- 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.
upstream-sync closed this pull request 2026-11-25 23:08:16 +00:00
Oliwettoo commented 2026-11-25 23:09:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Oliwettoo on 2026-11-25T22:44:56Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7176741337 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7176741337). Originally posted by [Oliwettoo](https://github.com/Oliwettoo) on 2026-11-25T22:44:56Z. --- 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 commented 2026-11-25 23:09:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:45:05Z.


This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

<!-- greyfinch-sync:ivall/xcl:comment:7176744163 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7176744163). Originally posted by [CalvyPZ](https://github.com/CalvyPZ) on 2026-11-25T22:45:05Z. --- This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.
upstream-sync reopened this pull request 2026-11-26 00:04:59 +00:00
github-actions[bot] commented 2026-11-29 20:44:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:44:48Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7262324821 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7262324821). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:44:48Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:55:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:55:48Z.


Triage (#1607) – head 064347f

#1097 fixes the same Wine problem (PrivateUsage is 0) another way. It keeps PagefileUsage for the guest title-memory APIs and uses it for the activity log on Linux Wine only. This PR replaces the PagefileUsage fallback everywhere with a sum of the MEM_COMMIT + MEM_PRIVATE regions from VirtualQuery, which is also correct on a Mac.
Under Wine, committed_private_bytes walks the whole address space on every call. TitleMemoryStatus, the stats write at kernelx.rs:1642 and memory_report all call it, so a title that polls these often pays a full walk each time. The cost is not measured in the PR.
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:7304659123 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7304659123). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:55:48Z. --- **Triage (#1607)** – head 064347f #1097 fixes the same Wine problem (PrivateUsage is 0) another way. It keeps PagefileUsage for the guest title-memory APIs and uses it for the activity log on Linux Wine only. This PR replaces the PagefileUsage fallback everywhere with a sum of the MEM_COMMIT + MEM_PRIVATE regions from VirtualQuery, which is also correct on a Mac. Under Wine, `committed_private_bytes` walks the whole address space on every call. `TitleMemoryStatus`, the stats write at kernelx.rs:1642 and `memory_report` all call it, so a title that polls these often pays a full walk each time. The cost is not measured in the PR. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
mokkamokacaffe commented 2026-12-01 13:14:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-12-01T13:14:08Z.


Independent D103 review at 064347f. One edge case that distinguishes this from #1097 is a failed process-counter query: this PR still walks committed private regions and supplies that result to guest title-memory queries. The added 256 MiB allocation test checks an actual increase in both measurements. It does not measure the cost of repeated guest polling, so that question remains open.

Group D103 review on #1607. AI use: OpenAI Codex (GPT-6) read and compared both diffs. No builds or tests were run for this review.

<!-- greyfinch-sync:ivall/xcl:comment:7312306625 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2362#issuecomment-7312306625). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-12-01T13:14:08Z. --- Independent D103 review at `064347f`. One edge case that distinguishes this from #1097 is a failed process-counter query: this PR still walks committed private regions and supplies that result to guest title-memory queries. The added 256 MiB allocation test checks an actual increase in both measurements. It does not measure the cost of repeated guest polling, so that question remains open. [Group D103 review on #1607](https://github.com/xcl-dev/xcl/issues/1607#issuecomment-7181731426). AI use: OpenAI Codex (GPT-6) read and compared both diffs. No builds or tests were run for this review.
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/2362:upstream-pr/2362'
git switch 'upstream-pr/2362'

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/2362'
git switch 'upstream-pr/2362'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2362'
git switch 'upstream-pr/2362'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2362'
git switch 'main'
git merge --squash 'upstream-pr/2362'
git switch 'main'
git merge --ff-only 'upstream-pr/2362'
git switch 'main'
git merge 'upstream-pr/2362'
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!2352
No description provided.