Memory: map_pages asks VirtualQuery once per run of fresh pages #556
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!556
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/556/head"
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?
@frozht on GitHub · 2026-11-24 01:44 UTC · original
frozht:frozht/xcl-mappages-stall→main· +173 −11 · 1 files · 1 commits · merged 2026-11-24 09:43 UTCmap_pages(XMemMapPhysicalPages) askedcommitted_pageabout the address and about the home of every page. A fresh page is not in the working set, so each one fell through to a VirtualQuery, which walks the whole run of pages that are in the same state. A retail title maps 98,304 fresh 64 KiB pages (6 GiB) in one call at startup: two VirtualQuery calls per page, a ~13 s stall under Wine (~132 µs a page). #254 only covers pages that are already in the working set.The loop now keeps the run that each VirtualQuery returned, one for the addresses and one for the homes, and answers the next pages from it. Both runs are dropped whenever
unmap_awaycommits or decommits memory and whenevermove_home_awaygives homes back (every 4096 pages). Both functions now return whether they did. Nothing else in a step changes a state that is asked about again. The one exception is an address that is also another page's home (a home in plain memory), and the answer there was already wrong before this change.No issue covers this one. #156 mentions
XMemMapPhysicalPagesScatterbut is about NVIDIA PSO builds.Open #531 and #849 each add a branch to the same loop that moves a page from its old address to the new one, decommitting the old address. That branch has to drop both runs, because the old address can lie in a run that was already answered: if either lands first, I add that here when rebasing; if this lands first, they need it.
What is in it
Memory: map_pages asks VirtualQuery once per run of fresh pages, incrates/xcl/src/hle/kernelx.rs:StateRunandcommitted_page_in(committed_pagenow calls it with an empty run);unmap_awayandmove_home_awayreturn whether they changed memory;map_pagesdrops the runs when they do. Acfg(test)thread-local counts the VirtualQuery calls.mod tests:mapping_fresh_pages_does_not_query_each_page: 64 fresh pages with one committed page among them.mapping_lazy_pages_again_does_not_query_each_pagepages_mapped_again_at_another_address_keep_what_was_writtenpages_mapped_again_at_the_same_address_keep_what_was_writtenTested
x86_64-pc-windows-gnu, release.cargo test ... -p xcl --lib hle::kernelxunder Wine: 28 passed, 0 failed, 1 ignored.unmap_awaymoves a page home.7ebf1b8and on7ebf1b8+ this commit: the first title activity inxcl.logcame at 20.1 s and 18.1 s before, 6.2 s and 6.0 s after; the first present at 24.7 s and 25.0 s before, 8.8 s and 13.5 s after. All four runs exited normally, with no device removal.cargo test --release --target x86_64-pc-windows-gnu --workspace -- --test-threads=4under Wine, on this commit before the rebase onto508a0c7(same diff): 674 passed, 6 failed, 41 ignored, 0 SKIPPED. The 6 failures are the same 6 as on main under Wine (origin/main2b4bb43: 664 passed, 6 failed, 41 ignored):gpu_f64_roots,gpu_f64_math_random,gpu_nonfused_mad_and_mac_prevent_fma_contraction, e2etest_title_runs_and_game_folder_is_untouched,disk_free_space_ex_reports_pls_quota,set_predication_buffer_state_and_kickoff.Regression run
Not run: this was built and tested on Linux under Wine, with no Windows machine available. Could someone on Windows run
scripts/smoke.ps1 -Game <folder>onmainand on this PR's head and paste bothxcl-smokeblocks? The Wine runs of the retail title above are the closest check I have.Not tested
scripts/smoke.ps1.508a0c7(it ran on the same diff ona6f5f7a).move_home_awaygives homes back every 4096 pages and drops the runs: no test reaches it.AI use
🤖 Generated with Claude Code
@thehollowedone on GitHub · 2026-11-24 01:49 UTC · original
Tested
Native Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug, at 38e58e1.
cargo test --offline --locked -p xcl --lib hle::kernelx::tests -- --test-threads=1 --nocapturereported 26 passed, 0 failed and 1 ignored. In a scratch copy I made the new tests require sparse homes instead of returning early and printed their query counts. The runtime code was unchanged.VirtualQuerycalls.Not tested
The 4,096-page eviction boundary, integration with #531, the full workspace, and retail smoke or startup timing.
AI use
Codex with GPT-6.2 Sol added the scratch-only test assertions and counters, ran the tests, and drafted this report.
@fromthemoonx on GitHub · 2026-11-24 09:10 UTC · original
NVIDIA run, since Not tested lists NVIDIA. This is the whole suite on native Windows, both at the head and merged onto current
main.Tested
stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)38e58e1d17c7c99abde4994274fe199c2b5dbc59(on its base508a0c7), clean worktree, debug:cargo build --workspace, thencargo test --workspace -- --test-threads=4: 684 passed, 0 failed, 41 ignored (lib 644 / 0 / 21). All four new tests passed:mapping_fresh_pages_does_not_query_each_page,mapping_lazy_pages_again_does_not_query_each_page,pages_mapped_again_at_the_same_address_keep_what_was_written,pages_mapped_again_at_another_address_keep_what_was_written.main077ce40(git auto-mergedkernelx.rs, no conflict), debug:cargo test --workspace -- --test-threads=4 --skip a_freed_block_is_decommitted_before_its_address_is_reused: 719 passed, 0 failed, 41 ignored, 1 filtered out (lib 678 / 0 / 21). The skip is #913: on this 12 GB card, that test fills video memory and makes unrelated tests fail withE_OUTOFMEMORY.cargo test -p xcl --lib -- --test-threads=4 hle::kernelx::testson the merged tree, 10 runs: 10 of 10 passed (27 passed, 1 ignored each)cargo test --release -p xcl --lib -- --test-threads=4 hle::kernelx::tests: 26 passed, 0 failed, 1 ignoredgpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwareXCL_SAMPLE_*not setNot tested
smoke.ps1) and no timing of a 6 GiBXMemMapPhysicalPagescall, so the ~13 s Wine stall is not measured either way. The new tests check the query count, not time.AI use
@ivall on GitHub · 2026-11-24 09:43 UTC · original
Merged (
9aec53d). Checked on an RX 9070 (RDNA4) on main9aec53dtogether with #532 and #556:cargo test --workspace -- --test-threads=4- 683 unit tests passed, 0 failed; the retail game plays its intro and menus at 30 fps as before and starts loading the world. Conflict with #849 (merged before): itsmove_awaybranch now drops both runs when a page actually moves (Ok(true)), and keeps them for a lazy page that is only unmarked (Ok(false)), whichmapping_lazy_pages_again_does_not_query_each_pagerequires.