perf(libc): remember clean pages once per run in Windows write collects #3864
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3864"
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 CnRJay on 2026-10-11T18:10:32Z.
What
WindowsMappings::Collect(the write-watch walk behindGuestMemory::CollectWrites) cost PPSA28416 (STAR WARS: Galactic Racer, UE5) about 16% of its render thread: ~62k collects and ~625 GiB of guest ranges walked per 10 s, mostly image surfaces collected byShaderResources::precollectImagesandPrepareDrawBindings(10-60 MiB each).#5062 has since merged two of the three parts this PR first carried: the in-order view walk and the
collectable()fast path. This rebase keeps only the part #5062 doesn't cover.A resetting
Collectremembered the clean pages of every 16 KiB view separately: onerememberCleancall, an erase and an insert incleanRanges, per page found clean. NowCollectkeeps one pending run of clean pages and remembers it once, when the run breaks or the walk ends, and before every early return (aPAGE_NOACCESSview, a full page buffer, a resident view, private memory). The run covers only pages behind the cursor, so thecleanRangeslookups ahead see the same map as before. NeitherprotectSubpagesnorcollectResidenttouchescleanRanges.The pages reported, the stamps and the clean ranges left behind are the same as before.
Tested
Windows 11, WinLibs GCC 15.2.0, Release, RTX 4080, rebased onto
main5ef619a91.ctest: 1198 of 1198 pass (14 skipped: display, udmabuf and stencil-export tests this machine can't run), includingguest_memory,windows_write_watch,agc_write_tracking,agc_shared_write,agc_shared_write_partial_collectand_two_pass.tools/check_conventions.py --base upstream/mainpasses.APS5_PROFILE_DRAW) was for all three parts together, before #5062. The share of the remaining part on currentmainhas not been measured again.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:17:54Z.
Conflicts with main in
core/libs/prx/libc/include/WindowsMappings.hppsince #3783, which changedCollect; please rebase and repeat the PPSA28416 collect-time measurement on the new base.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-12T13:17:28Z.
A data point on the new base, from another title. I ported this PR's three parts onto
main'sCollectafter #3783 and kept #3783's clean-range memory:views.findper page;collectable().The diff is at the end, in case it saves you the rebase.
Planet of Lana (PPSA19450) on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 3070 Laptop. The base is
maind146ec1b6plus other changes I'm testing (#494 rebased, #2863, #290, #2904, #4320 and two unmerged driver changes), with and without the port. Both runs are the same scene, Lana standing in the first village, withAPS5_PROFILE_DRAW=1and the worker sampler on:readTargetper drawBefore the port,
GuestArena::WindowsMappings::Collectwas 19% of the queue-0 worker's samples: a map lookup and a clean-range insert per 16 KiB page, plus the second walk incollectable(). Lana's direct memory is in shared views, and the resident-target refresh walked about 1,200 pages per lookup, because the collect epoch moves at every submission and wait (about 440 submissions and 1,050 waits per second here). With the port,Collectno longer shows in the profile, and no AnyPS5 function is above ~1.3%.agc_shared_write*,agc_write_trackingandguest_memorypass with the port onmainc36fd0a0e, in the same test stack. The full suite was not run with it.The port, on main
c36fd0a0e(WindowsMappings.hpp)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:11:45Z.
Review: CHANGES_REQUESTED
Thanks for the measurements. This now conflicts with
mainincore/libs/prx/libc/include/WindowsMappings.hpp: #3783 rewroteCollect(it walks withcleanRanges.upper_boundand callsrememberCleanper stretch), so the three changes have to be re-applied on the new loop rather than merged mechanically.mainand port the iterator hint, the singlerememberCleanper clean run (flushed before every early return) and the clean-range skip incollectable()onto the newCollect.We can't build or measure Windows-only code here, so we can't do the rebase for you. Happy to re-review once it's updated.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-13T19:24:34Z.
Overlaps with #5062 in
WindowsMappings.hpp(the in-order view walk and thecollectable()fast path). This PR also remembers clean pages once per run inCollect, which #5062 does not touch. Whichever merges second will rebase and drop what the first already covers.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T19:47:15Z.
Windows cross-test of e5c6bd4a2c900c50c0d07d563f6a8de74e88cafc on our older integration: exact author-preserved one-file port66e97032f4fd375e70d94081da13b9ebda9db53a, https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-write-collect-cross-test . Source/conventions clean.
Restored final6/6 controls pass6.26s: guest_memory, windows_write_watch, shared-write partial collection single/two-pass, write tracking, mocked driver graphics. Windows Release/GCC15.2/RTX5070Ti; native Vulkan required where applicable. Existing failed-collect/write preservation, armed/fresh collection and subpage controls retained. No new fixture for the speed-only transformation. Parent production header with unchanged fixtures also6/6 pass6.91s; not an expected negative for this optimization.
Initial graphics invocation failed its precondition "write-watched arena contained no host exclusion to test"; unchanged restored run passed. Cause is not confirmed and this is not suppressed or counted as a pass. No Linux/macOS/full-suite claim. Starting title cross-test with only libc changed; graphics/Agc/VideoOut remain our verified sparse-run693 cohort, unary shader port remains unstaged. RAM guard has additional bounded working-set trims, same free/private limits, so no clean title FPS A/B claim yet.
AI-assisted: yes (Codex); no title data attached.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:33:48Z.
Review: CHANGES_REQUESTED
This conflicts with
mainagain incore/libs/prx/libc/include/WindowsMappings.hpp(3 hunks). It needs a re-port, not a mechanical rebase:Collectnow has aresidentbranch (collectResident,watchResident) with its ownreturn false/return truepaths. The pending clean run (flushClean) has to be flushed before each of them, as in the other early returns.collectable()was rewritten for resident views (found->second.resident && !watchResidentreturns false); thecleanRangesskip and the iterator hint must be re-applied on top of that.collectable()fast path). Please settle with it which parts remain here (the singlerememberCleanper clean run is the part #5062 doesn't cover) and drop what it already does.Once it is rebased on current
mainand the Windows job is green, this is ready to re-review.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:35:52Z.
Review: APPROVED
Re-checked on the new head: the pending clean run is flushed before the resident,
PAGE_NOACCESS, full-buffer and private-memory returns and at the end ofCollect; skipcontinues leave it pending and the next non-adjacent stretch flushes it. It only covers pages behind the cursor, and nothing insideCollect/collectResident/protectSubpagestouchescleanRanges, so the lookups ahead see the same map. No conflicts with main; libc build and ctest are green on Linux (this code is Windows-only). Merging once the Windows build is green.