refactor(libc): map a run of shared guest pages as one view on Windows #9505
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9505"
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?
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T23:43:56Z.
What
On Windows,
WindowsMappings::Mapmaps shared guest memory one 16 KiB page at a time. That covers direct memory while shared imports are attached,shm_openmemory and JIT shared memory. Each page costs a placeholder split, a view, a protect and threeVirtualQuerycalls: two to find the placeholder the page splits from, one to see whether its section page still needs a commit. All of it runs under the mappings mutex. A 1 GiB map places 65,536 views.This ports two of fable-void's commits from his fork (
wip/new-gpu-path, 027bff5198 and 3d695fbba6), with his authorship. On top of them are our two adjustments formain's file mappings, a bench, and a change after review:6c1f63674e(bench):windows_shared_map_costmaps 4 MiB, 256 MiB and 1 GiB of shared memory throughWindowsMappings::Map, then releases it, five times each. It prints the median map and release times and the number of views. It only measures and always passes.312fb247a9(fable-void): a page-by-page mapping commits its section range once, through one window. Each page then splits off the placeholder the previous page left, whose extent is already known. A page now costs a placeholder split, its view and its protection.a16262ba76(adapts 027bff5198): only mappings that pass no section size, i.e. direct and shared memory, commit the range up front. A file mapping passes the bytes its file still has. A read-write window over it can run past the end of a short file, and a read-only file section refuses one, so file mappings keep committing each view as before.bdf9bfe14a(fable-void): each run of shared pages that need a view becomes one view: one placeholder split, one map at read-write-execute (the cap later guest protections need) and one protect per run. Per-page protections and write tracking still change 4 KiB subpages inside the view. A view splits only where a release or a remap cuts it, and the split restores every 4 KiB protection. An alias of a page elsewhere, or a per-page protection, leaves the view whole.1f19ce0f2a(adapts 3d695fbba6): a run view needs a read-write-execute section and the whole run committed, which a file mapping can't give. File mappings take the per-page path they took before: one view per page at the file's view protection, with the last page cut at the end of the file.a2e0bf19e6(after MarcZX10's review): theVirtualQuerycounter that312fb247a9adds forwindows_write_watchis compiled only into that test, throughAPS5_COUNT_MAPPING_QUERIES, so the runtime'squery()does no atomic update per query.mainhas had the same counter since #10070, which took it from this PR so that whichever landed second would drop its copy, so after the merge withmainthe PR's diff no longer carries it.fable-void's message on
312fb247a9listsagc_private_collectamong the tests he ran. That test comes with his private-collect commit (2760ad8089 on his branch), which isn't part of this PR.Measured on GitHub's Windows runner, three runs each:
mainwith the bench (6c1f63674e, run) against this PR (run).main: map median (views)main→ this PROn his machine, fable-void measured the 1 GiB shared map and import in
agc_driver_committed_importsat 190–196 ms on the mapping thread, against 418–427 ms before.These measure the mapping itself. A Resident Evil Village (PPSA01556) pair (under Tested) shows no measurable change in a 40 s window of its load, so this PR makes no frame-rate claim.
Overlap: checked with
git merge-treeagainst every open PR touching these files, onmaina6dcea9279. Two of ours overlap, on adjacent added lines only:git merge-tree) it conflicts on a test registration incore/libs/CMakeLists.txt, on the query counter inWindowsMappings.hpp(its accessor and the count inquery(), which this PR now guards withAPS5_COUNT_MAPPING_QUERIES), and on a test function beforemain()inWindowsWriteWatch.cpp.main0ea0f25e1btakes it in: itsaliasDemotedreset andunreportedmarks are in both of this PR's loops, and both sides' cases run inWindowsWriteWatch.cpp(see Tested).Both are mine. Merge order: #9098 goes after this PR, lists it under Depends on, and resolves these conflicts when it rebases.
The eight PRs that conflict with
mainthemselves were checked by their diffs: none changesWindowsMappings.hpp. #6044, #7201, #7275, #8285, #8650 and #9224 add root library test registrations incore/libs/CMakeLists.txtnext to this PR'swindows_shared_map_costand thewindows_write_watch_testsdefinition. Whichever PR rebases keeps every registration, and checks after resolving thatctest -Nstill lists all of them.Tested
1f19ce0f2a(run):windows_shared_map_cost,windows_write_watch,guest_memory,guest_jit_shared_memory,guest_shm_openandguest_raise_exceptionpass ×3;main's code doesn't buildwindows_write_watchthere, because fable-void's two new cases use the query counter312fb247a9adds. His messages give their reds: "775 queries for 256 pages" and "a shared gibibyte was mapped as 65536 views instead of one".a2e0bf19e6on GitHub's Windows runner (run):windows_shared_map_costandwindows_write_watchpass 5 runs in a row, and the libc suite passes (142). In both attempts of that run, libkernel'sguest_raise_in_system_calltimed out after 30 s near the end of the suite. Run alone 20 times in a row, it andguest_raise_exceptionpass ata2e0bf19e6(run) and at1f19ce0f2a(run), whilemain'sa6dcea9279times outguest_raise_exceptionwithin its 20 (run).5fd76aff60, merged withmain1e20650e84(run). The one conflict was the list of cases inWindowsWriteWatch.cpp'smain(), wheremainadded three private-commit cases next to this PR's two; all five run.mainnow has the sameAPS5_COUNT_MAPPING_QUERIESquery counter (from #10070), so after the merge this PR no longer changes those lines. Its other added and removed lines are unchanged.windows_write_watch,windows_shared_map_cost,guest_memory,guest_shm_open,guest_jit_shared_memoryandguest_raise_exceptionpass ×10: 6 run, 6 pass, 0 skip, 0 fail;guest_memory,guest_shm_open,guest_jit_shared_memoryandguest_raise_exceptionpass ×10: 4 run, 4 pass, 0 skip, 0 fail;APS5_SKIP_TIMING_TESTS=1.fbf50df422, merged withmain0ea0f25e1b(run). Both conflicts come from #9159, whichmainhas taken since:WindowsMappings.hpp, #9159 added two lines to the per-page loop this PR replaces: thealiasDemoted = falsereset after a resident alias is demoted, and theunreported = allSubpagesmark on a new view of compared shared memory. The merge carries both into this PR's per-page loop and into its run loop, where each run view takes the mark from its shared page. The PR's other added and removed lines are unchanged;WindowsWriteWatch.cpp'smain(), the list of cases keeps this PR's two and #9159's four;windows_write_watch,windows_shared_map_cost, the write-tracking tests (#9159'sagc_rewatched_direct_shared,agc_import_alias_sharedandagc_compared_shared_generationsamong them),guest_memory,guest_shm_open,guest_jit_shared_memoryandguest_raise_exceptionpass ×10: 14 run, 13 pass, 1 skip (agc_driver_compared_shared_snapshot, no Vulkan device), 0 fail. Withmain's implementation,windows_write_watchfails: "a shared mapping queried the address space for every page: 775 queries for 256 pages";agc_write_tracking,agc_write_watch_coverage,guest_memory,guest_shm_open,guest_jit_shared_memoryandguest_raise_exceptionpass ×10: 6 run, 6 pass, 0 skip, 0 fail;^agcsweep, once (run): Linux 987 run, 923 pass, 64 skip, 0 fail. Windows 1,017 run, 287 pass, 726 skip, 4 fail:agc_submit_progress,agc_submit_progress_no_timeline,agc_driver_pipelined_metadata_passandagc_driver_pipelined_metadata_pass_draw_pipelinestop atvkCreateInstance(-9) on GitHub's runner, which has no Vulkan device, and fail the same way onmainc9b2660d56alone (run);APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.guest_memory's regular file mapping case. Those runs were on an earlier branch of this port that also carried his private-collect commit, which doesn't touch file mappings.a16262ba76(run), a read-only shared map of a read-only file fails: "Guest memory check failed at core/libs/tests/GuestMemory.cpp:2922".1f19ce0f2a(run), a shared map of a two-page file fails: "Guest memory check failed at core/libs/tests/GuestMemory.cpp:2899".guest_jit_shared_memoryandguest_shm_openfail there too.guest_raise_exceptiontimed out once (30 s) in an earlier run of the port. It passed in a recheck (run) and in all three runs above. This PR doesn't touch libkernel.WindowsMappings.hppis Windows-only, so Linux builds unchanged code.guest_memory,guest_jit_shared_memory,guest_shm_openandguest_raise_exceptionpass ×3, and libkernel's suite passes (197). libc's suite has one failure,precise_wait, a timing test that flakes on that runner.a2e0bf19e6merged intomaind9c99c9ba4.windows_shared_map_cost(not onmain),windows_write_watch,guest_memory,guest_jit_shared_memoryandguest_shm_openpass 3 of 3, and libc's suite passes (142).guest_raise_exceptiontimes out there with and without this PR, asguest_raise_in_host_codedoes once onmain; JJenkx's breakdown of that time is #9610.check_conventions.pypasses, with no comment lines added.main1ff5c8ac5cplus four local AGC driver commits, none in libc. D is A with this PR's six commits on top (ca13192259, the same diff as this PR).APS5_LAZY_SHADER_PREPARE=1,APS5_NO_GPL=1,APS5_HOST_IMPORT_MIB=6400,APS5_TRACE_SECONDS=900:40), the same route and a warm shader cache;aps5-summary.jsonlline andtools/trace_digest.pyoutput.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)core/libs/prx/libc/include/WindowsMappings.hpp): this PR first, then #11152 rebases onto itImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T23:44:08Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:43:22Z.
Review: CHANGES_REQUESTED
The implementation has substantial Windows coverage: the PR reports successful shared-view, write-watch, guest-memory, JIT, shm, libc/libkernel and relinker runs, plus repeated same-runner map/release measurements. Eligibility, conventions, intake, labels, report and the reported matrix checks pass. I did not run Windows tests locally.
I’m requesting changes for these items:
The required performance report is still missing. The
perflabel bot correctly asks for theaps5-summary.jsonllines for main and this change, traces for both, andtools/trace_digest.pyoutput. CONTRIBUTING.md requires that evidence for a speed claim. The customwindows_shared_map_costtiming table is useful, but it does not provide those report artifacts. Please attach them for the same workload and machine, or revise the performance claim and checklist to match the evidence available.Please complete overlap coordination for #9098 and #9159. The live overlap scan reports shared edits in
WindowsMappings.hppandWindowsWriteWatch.cpp(and the CMake test registration for #9098). The PR description says the changes compose, but does not record agreement with those authors about merge order. Please confirm the order with them; addDepends onif this PR must follow either one, then rebase/recheck the resulting combined diff.The test query counter adds an unconditional atomic operation to production.
WindowsMappings::query()now performsqueries.fetch_add()for everyVirtualQuery, even in the runtime library where the counter is not read. Please compile the counter only into the test target (or otherwise keep it out of production), so a performance change does not add a global atomic RMW to this hot path.The measured view-count and map-time improvements are promising; these requests concern the required report, merge-order process, and the production cost of the new instrumentation.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:20:02Z.
Review: CHANGES_REQUESTED
The performance evidence and hosted product checks are now present and green, so I withdraw the earlier performance-report concern. I verified the current heads directly with
git merge-tree: #9505 and #9098 conflict incore/libs/CMakeLists.txt,core/libs/prx/libc/include/WindowsMappings.hpp, andcore/libs/tests/WindowsWriteWatch.cpp. In particular the sharedAPS5_COUNT_MAPPING_QUERIESaccessor/counter hunks inWindowsMappings.hppconflict, so the PR description’s statement that these parts merge cleanly is stale. #9505 and #9159 also conflict inWindowsWriteWatch.cpp. The contribution rule requires author-agreed order for actual shared-line overlaps andDepends onfor prerequisites. Please coordinate with #9098 and #9159 authors, update this PR’s overlap account/checklist, and rerun the merge-tree/overlap check after any rebase. The content-level work appears distinct; I’m requesting changes for the inaccurate overlap/order record only. Hosted eligibility, conventions, relinker matrix, ASan and write-watch checks pass; full Linux/Windows product jobs are skipped. I did not run local Windows tests.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T01:38:00Z.
Thanks, @MarcZX10, on both reviews.
a2e0bf19e6compiles theVirtualQuerycounter only intowindows_write_watch_tests, throughAPS5_COUNT_MAPPING_QUERIES, so the runtime'sWindowsMappings::queryno longer updates it (run).CMakeLists.txt,WindowsMappings.hppandWindowsWriteWatch.cpphunks when it rebases. This PR and #9159 don't wait on each other, and whichever lands second rebases. The Overlap section now says so, and no longer says the counter parts merge cleanly with #9098.trace_digest.pyoutput. I'll post it here when it's in.The description also gains the
GPUs testedline it was missing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:07:40Z.
Thanks for documenting #9098 as a dependent rebase and #9159 as independent. I checked the remaining overlap warnings: #5021 does not change
core/libs/CMakeLists.txt; #6044, #7201, #7275, #8285, #8650 and #9224 do add root library test registrations, so the shared CMake insertions need to be preserved on rebase even if the changes are otherwise independent. Please note that plan and verify all registrations remain after resolving the CMake conflicts. One separate repository rule remains: this PR still has titleperf(...)and labelperf, while its benchmark is a test-only mapping microbenchmark rather than the prescribed same-title/same-scene warm-cache capture with summary lines, attached traces and digests. The Resident Evil Village pair is still described as running. Please add the required report artifacts if retaining the perf title/label, or change the title/scope so it no longer claims a performance change. I did not run tests locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:07:42Z.
Review: CHANGES_REQUESTED
The Windows mapping change is supported by broad author-reported regression coverage and a dedicated mapping benchmark. I am requesting changes for repository policy/evidence: the
perf(...)title/label requires valid same-title, same-scene, same-machine warm-cache summary lines, attached base/change traces andtools/trace_digest.pyoutput. The current mapping benchmark does not meet that title-scene report requirement, and the described Resident Evil Village pair has not been posted yet. Please attach the compliant capture report or remove the performance claim/perf labeling. Also preserve the documented #9098/#9159 order and root test registrations during rebases. I did not run tests locally; hosted product build jobs are skipped.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:19:37Z.
Thanks, @MarcZX10. The
perftitle stays for now. A Resident Evil Village (PPSA01556) capture pair is queued on this PC in a matched rotation: the same base with and without this PR, a warm cache, and the same machine and scene. I'll attach both summary lines, a trace for each arm and thetrace_digest.pyoutput here. If it shows no measurable effect in that title, the description will cut the claim to the mapping bench, and the title will dropperf. The CMake registrations are in the Overlap section now.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:23:06Z.
Review: DISMISSED
The #9098/#9159 ordering is now documented, the runtime query counter is test-only, and the CMake registration conflicts are accounted for. I am withdrawing the earlier overlap coordination request. One repository requirement remains: this PR still has a
perf(...)title andperflabel, but its body still says the PPSA01556 capture pair is queued and includes no summary lines, attached traces ortrace_digest.pyoutput. The mapping benchmark does not replace the prescribed same-title, same-scene, same-machine warm-cache report. Please attach that complete capture pair or remove theperftitle/claim and revise the description accordingly. No local Windows/title tests were run by me.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T04:23:14Z.
Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release,
BUILD_TESTING=ON. I comparedmaind9c99c9ba4with a local merge of your heada2e0bf19e6into it (c66a5dbc72, no conflicts).Focused tests, 3 runs each:
mainwindows_shared_map_costmainwindows_write_watch,guest_memory,guest_jit_shared_memory,guest_shm_openguest_raise_exceptionSuites:
mainguest_raise_exceptionandguest_raise_in_host_codetime outguest_raise_in_host_codetimes outThe libkernel timeouts aren't from this PR:
mainshows them too, and this PR doesn't touch libkernel. Run outside ctest,guest_raise_exceptionpasses but takes 35.6 s and 37.4 s on this machine. I filed the breakdown as #9610: 14.8 s of it is raises on a thread looping insceKernelSyncOnAddressWake.Not tested: a title, or a performance pair.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T05:39:32Z.
@JJenkx thanks for the Windows run on the 5950X, and for tracking
guest_raise_exception's time down in #9610. It's in Tested now.