Repository navigation
Memory: map_pages asks VirtualQuery once per run of fresh pages - #556
Conversation
`map_pages` asks `committed_page` for the address and for the home of every page; a page not in the working set (every fresh one) fell through to a VirtualQuery, which walks the whole run of pages in one state. A title that maps 98,304 fresh pages (6 GiB) in one call took ~13 s under Wine (~132 us a page); a scratch run of the same call shape measured 186 us a page for 4096 and 16384 pages, 0.26 us a page now. The loop remembers the run each VirtualQuery returned for the addresses and for the homes and answers the next pages from it. The runs are dropped whenever `unmap_away` commits or decommits (it now says so; a page never used is only unmarked and keeps them, so mapping lazy pages again is covered too) and when `move_home_away` hands homes back (every 4096: it now says so). The rest of a step changes only an address, or a home that is not asked about again: the addresses rise, and a page mapped twice is unmapped first. The one exception is an address that is another page's home (a home in plain memory): the answer for it was wrong before the runs too. Tests: 64 fresh pages with a committed one among them took 127 VirtualQuery calls before, 5 now; the same pages mapped again, 128 and at most 8. Pages written and mapped again in one call, at another address or at the same one, keep their contents (they fail when the run is not dropped after `unmap_away` moved a page home). The counter behind the first two is a `cfg(test)` thread-local in `committed_page_in`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Tested Native Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug, at 38e58e1.
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. |
|
NVIDIA run, since Not tested lists NVIDIA. This is the whole suite on native Windows, both at the head and merged onto current Tested
Not tested
AI use
|
|
Merged (9aec53d). Checked on an RX 9070 (RDNA4) on main 9aec53d together with #532 and #556: |
map_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.xcl.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 onto 508a0c7 (same diff): 674 passed, 6 failed, 41 ignored, 0 SKIPPED. The 6 failures are the same 6 as on main under Wine (origin/main 2b4bb43: 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.move_home_awaygives homes back every 4096 pages and drops the runs: no test reaches it.AI use
🤖 Generated with Claude Code