perf(libc): skip write-watch queries for proven clean resident ranges #7473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7473"
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 Dripl1x on 2026-10-18T08:47:43Z.
What
Item 10 of the graphics/memory performance series. Depends on #7471.
Eligible settled resident runs of at least 256 KiB retain the clean-range proof that skips GetWriteWatch. A first CPU write now restores the logical protection of the entire resident run and leaves that run on native write watching until it is remapped. Repeatedly rewritten buffers therefore do not fault on every 4-KiB page or rearm on every collection.
Windows GPU imports use a separate scoped HostImportAccess guard: it opens protected resident pages and suppresses resident rearming during driver validation/allocation, without marking an aliased shared mapping dirty when nothing was stored. Actual shared writes still invalidate all aliases.
Tested
Rebased onto main
2185dbf92eon 2026-10-21, on top of the rebased #7471 (9d5f8326bf); head7898b5bd3a(the correctiond8b18e7acis now7898b5bd3a; the two metadata-only commits are dropped). Conflicts: test insertion points incore/libs/tests/GuestMemory.cpp(main's two #7448 release tests and this PR's tests both stay) andstruct ViewinWindowsMappings.hpp(main'sviewBytesstays beforehostImports, asMapinitialisesViewpositionally). After the rebaseguest_memory,guest_mmap_fixed_anonymousandagc_driver_host_import_windowspassed 3/3 each and 31 related write-watch, write-tracking, host-import and socket host-write tests 1/1; @screamm's two source controls (arming off; theHostImportAccessbracket removed) fail as expected and pass once restored. Windows 11 build 26300, Ryzen 7 5800H, RTX 3070 Laptop, NVIDIA 617.42, WinLibs GCC 15.2.0 Release. Enabled by default.The standalone topic passed guest_memory, guest_mmap_fixed_anonymous and the real agc_driver_host_import_windows executable. The new cases cover guest read/pread into a settled protected 2-MiB mapping, import access while collecting, 16 complete write/collect rounds with exactly one access violation in total, and repeated no-store import brackets over a 1-MiB pair of shared aliases. Real writes through the aliases are still found. The inherited 64-KiB no-fault test and 128 collector/writer race iterations remain in place. Vulkan repeated imports, GPU fills and neighboring bytes passed on the standalone topic and combined stack.
Write-heavy 2-MiB probe, one store per 4-KiB page followed by a clearing collect and a clean collect, median of five 256-cycle trials:
This is a memory probe, not an FPS measurement. It removes the repeated per-page exception cost; one initial fault remains for an armed run.
Where it helps
Write collection in the SuperTuxKart scene, main against the series (which includes #7471; the counters show the two together):
2185dbf92eWindowsMappings::Collectcalls per frameWindowsMappings::Collectµs per callWindowsMappings::Collectms per frameCounters come from a local probe build that is not part of this PR (
review-probe.patchin the evidence archive): the same counters and timers were inserted into main2185dbf92eand into main with all eleven series PRs merged (#7464 in its rebased form), anchored on function definitions present in both trees. Runs were in the mirrored order main, series with #7464 reduced to its wake only, series, series, reduced series, main, in the scene above withAPS5_PROFILE_DRAW=1; values are medians of two runs over the same 8-second window as the trace, starting 20 s after the first flip, per flip. These runs carry profiling overhead and are not used for FPS. Each optimised function below is changed by this PR only; counters show where the work goes, not an isolated FPS gain.Host I/O contract
The reviewer's unbracketed ReadFile result is reproducible: a native kernel write can fail with ERROR_NOACCESS while a resident clean proof is armed. This raw WinAPI behavior is not claimed to be fixed. Native writes into guest buffers must hold GuestArena::HostWrite, as shared mappings already require. Existing guest read, pread, fread and socket receive destinations already use it; actual guest read/pread into the large protected mapping are now covered explicitly. The requirement is recorded in docs/dev/debt/libc.md. Guest logical permissions are unchanged.
Matched game repeats
SuperTuxKart captures: Windows 11 Pro build 26300, Ryzen 7 5800H, RTX 3070 Laptop GPU, NVIDIA 617.42, WinLibs GCC 15.2.0 r7, Release; SuperTuxKart (PPSA69421) tutorial prompt over the main menu, 1920x1080 internal rendering in a maximized 2560x1369 window, warm shader caches, audio muted, no input;
APS5_TRACE_SECONDS=20:8withAPS5_TRACE_EVENTS=1048576, console output not redirected, no profiling switches; 2026-10-21 on main2185dbf92e, one valid capture per side (two further launches were closed by hand before their window and are excluded), order #7471, this PR.rv21-u1-7471r9d5f8326bf(this PR's dependency)9d5f8326bfc6rv21-u2-74737898b5bd3ab6Single captures in this scene (8.68 FPS against 8.32 for #7471) are within its run-to-run spread; no FPS claim from them.
Summary lines (main first, then this PR)
tools/performance_compare.py(first capture of each side)Performance comparison
9d5f8326bf7898b5bd3aFrame and GPU times (ms)
Top phases (ms per frame)
tools/trace_digest.pyoutput (first capture of each side; all digests are in the evidence archive)rv21-u1-7471rseconds 20:8 from present 25: 67 presents, frame p50 114.1 / p90 125.6 / p99 362.0 / max 362.0 ms, GPU busy 5.6 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
9d5f8326bf, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
rv21-u2-7473seconds 20:8 from present 25: 70 presents, frame p50 108.3 / p90 120.4 / p99 371.4 / max 371.4 ms, GPU busy 5.6 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
7898b5bd3a, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Isolated title A/B by @screamm (Windows 11, RTX 4070, driver 596.21, this PR on main
1d4164552): vkQuake PPSA99010, shareware demo loop at 3840x2160, 90-s runs, six interleaved pairs. This PR was ahead in all six; over the four quiet pairs main averaged 106.34 FPS and this PR 108.38 FPS (+1.9%), about the size of the main-to-main spread in those pairs (1.8%). A small consistent lead, not an established gain. Middle Ages Ping Pong is vsync-bound (59.94 FPS on both).The earlier combined-stack repeats below remain for reference:
Same machine, warm caches, automatically maximized window, matching client dimensions, focus and loaded-module hashes verified. SuperTuxKart uses 1920x1080 internal rendering, a 2560x1369 client and trace seconds 20-28. Other titles use trace seconds 8-16. Game output is unredirected and the games close automatically.
The SuperTuxKart difference is -0.239 FPS. These results measure the correction in the combined stack and do not establish an isolated gain for this PR. The pinned benchmark base is
6447ed1ed7; the combination retains #6658 and #6678 at previously tested revision5f822a5008. This is not a new current-main benchmark. Earlier single-capture +2.09% is superseded as evidence for this correction.UI Lab received the 20-step default navigation sequence. The 17 fresh GPU frame dumps were visually reviewed; artwork, library grids, dialogs and game UI were present in the inspected frames. This is a visual check only: its early seconds 1-6 FPS interval was excluded because the focus guard had not yet established focus at the beginning. It is not included in the FPS table.
Known baseline rendering issue: vkQuake has intermittent flickering/black floor; no rendering repair is claimed here. The combined focused checks and conventions passed; no full-suite CI or console validation is claimed.
Dependencies and overlap
#7471 is required. #6273 widens Windows epoch collections to 64-KiB blocks; this topic avoids native queries for ranges protected by a clean proof. It does not incorporate #6273. #6918 shares the Windows host-import test file and #7448 shares guest-memory test insertion sites; retain both sets of tests when composing. Foreign branches that already conflict with main have not all been composition-tested.
Related series: #7464, #7465, #7466, #7467, #7468, #7469, #7470, #7471, #7472; #7474 is the separate exit-cache correctness fix. The earlier series traces and UI contact sheets remain available in the series evidence release; the table above is the new review-correction repeat, not the earlier release's measurement.
Re-checked on 2026-10-21: rebased on main
2185dbf92e; #7471 is still required and must land first.Reproduction evidence
Update of 2026-10-21: 7473-evidence.zip (traces, summary lines,
trace_digest.pyandperformance_compare.pyoutput, loaded-module hashes), counters where.json and the probe review-probe.patch with probe_window.py.Checklist
main(2185dbf92e, rebased 2026-10-21) on top of the rebased #7471Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T08:58:29Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL65core/libs/prx/libSceAgcDriver/tests/execution/HostImportWindows.cppL126, L138Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/include/GuestArena.hppcore/libs/prx/libc/src/GuestArena.cppcore/libs/tests/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestArena.cppcore/libs/tests/GuestMemory.cppdocs/dev/debt/libc.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/tests/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libc.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/tests/GuestMemory.cppcore/libs/prx/libc/src/GuestArena.cppcore/libs/tests/GuestMemory.cppdocs/dev/debt/libc.mdcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/src/GuestArena.cppcore/libs/tests/GuestMemory.cppcore/libs/prx/libc/include/GuestArena.hppcore/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libc.mdcore/libs/tests/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:32:18Z.
Measured on Windows 11 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release, PR merged onto
main9f25d0bf5, RTX 5070 Ti. I used a probe againstsceKernelMapDirectMemory+GuestArenaCollectWrites, with a resident mapping collected until settled, comparingmainwith this PR:mainraises none. The 64 KiB case stays at 0, and that is the only reasonCheckSingleDirectMappingTracksWritesWithoutFaultsstill passes.ReadFilestraight into the settled mapping, without aGuestArena::HostWritebracket, succeeds onmainwith 65,536 bytes. With this PR it fails withERROR_NOACCESS(998) and writes 0 bytes.So the PR saves about 1.7 µs per clean 2 MiB collect and costs about 2 µs for the first write to each 4 KiB page. Buffers the guest rewrites every frame, such as rings and dynamic vertex or constant buffers, get slower. Every kernel-mode write into resident memory above 256 KiB now needs a
HostWritebracket, which used to be required only for shared views.The new
HostWriteinimportRunAtalso marks the imported range dirty for shared views: a bracket with no store over an aliased 1 MiB mapping makes the next collect report all 256 pages.The single SuperTuxKart capture (+2.09%) doesn't cover write-heavy buffers. A capture from a title that streams into large resident buffers would be needed. Confirmed: reverting the
GuestBufferMemory.cppguard makesagc_driver_host_import_windowsfail. The 462 related tests pass with this PR.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-18T14:22:33Z.
@wachi35676 Thanks for the large-buffer measurements and the no-store import reproducer. Corrected in
d8b18e7ac4e11695dcce3a84e043f7dcb9c6baba:The standalone topic passed guest_memory, guest_mmap_fixed_anonymous and agc_driver_host_import_windows. The 64-KiB no-fault case, 128 collector/writer race iterations, capacity, alias and pin cases remain covered.
The correction was repeated in the same combined SuperTuxKart tutorial/menu scene in A-B-B-A order: 31.438 -> 31.200 FPS (-0.239 FPS), 1920x1080 internal rendering, maximized 2560x1369 client, warm caches, seconds 20-28, verified focus and runtime hashes. vkQuake moving demo: 54.873 -> 59.420 FPS; Syobon: 30.287 -> 30.299; Ping Pong: 59.941 -> 59.939. These are combined-stack checks, not an isolated PR speedup or a claim that every streaming workload is covered.
UI Lab received the 20-step default navigation sequence. The 17 fresh GPU frame dumps were visually reviewed; artwork, library grids, dialogs and game UI were present in the inspected frames. This is a visual check only: its early seconds 1-6 FPS interval was excluded because the focus guard had not yet established focus at the beginning. It is not included in the FPS table.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T23:40:36Z.
Re-checked
39f8a8056(the fix isd8b18e7ac) merged ontomain07377573fwith the same probe (Windows 11 26300, Ryzen 5 9600X, GCC 15.2). This timemainand the PR were measured on the same base. My first comment compared a9f25d0bf5baseline with PR runs on3e3e8b905; its conclusions still held, but those timings weren't from one base.The earlier regressions are gone:
main. At a 4 KiB stride it takes 244–259 µs (main258–287 µs); at a 64 KiB stride 18–23 µs (main20–22 µs).HostImportAccessbracket gives 0 dirty pages for resident and for aliased mappings, where aHostWritebracket gave 256 on aliases. It opens resident runs during the import and re-arms them afterwards.What remains is what the new debt entry says:
ReadFileinto an armed run still fails withERROR_NOACCESS(998). It succeeds once the run has taken its first write.main.The 472-test set passes.
guest_sce_net,guest_select_wait,guest_pthread_startandguest_mutex_contentionflaked under-j4and pass 3/3 when run serially.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T04:52:49Z.
@Dripl1x thanks. The bracketing looks complete: every Windows kernel-mode reader into guest memory that I found holds
HostWrite, and the fault path is serialised. Two things before this can go in. It's a default-on Windows protection change with a documentedERROR_NOACCESSfailure mode, and the micro-probe shows 342.9 vs 339.7 µs, so could you post a workload A/B (a title scene, main vs this PR, interleaved) that shows the gain? Also, it sits on #7471, so that needs to land first.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T09:05:27Z.
Rebase handoff — rebased onto current
main(all six commits, authorship unchanged). One conflict inWindowsMappings.hpp: both struct fields kept (main'sviewBytesand yourhostImports).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
4386c0596.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T16:31:16Z.
Isolated title A/B on Windows NVIDIA for the workload ask, plus tests and controls.
Host: Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 driver 596.21, Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2 r7, Release. PR head
39f8a8056; I built blawesom's handoffrebase/7473at4386c0596(the same six commits, so #7471's commit is included) merged onto main1d4164552. One conflict, incore/libs/tests/GuestMemory.cpp: main's two new release tests andCheckLargeResidentWritesStopFaultingsit at the same spot; I kept both.Tests, x3:
guest_memory,guest_mmap_fixed_anonymous,agc_driver_host_import_windows: 3/3 each. The new resident write/collect, partial-write, collect-during-host-write, import-bracket and resident-import-after-collection cases run inside these; the host-import test is not skipped on this GPU.Controls. The test files don't build on main, so I used two source controls:
&& armResident(first, stop)->&& falseincollectResident):guest_memoryfails atGuestMemory.cpp:1642, which expectsPAGE_READONLYafter two clean collects.HostImportAccessbracket removed fromimportRunAt:agc_driver_host_import_windowsfails withresident memory could not be filled after collecting its writes.Both pass again once restored.
Title A/B, vkQuake PPSA99010. Without data the title exits after about 5 s, so I used the shareware
id1/pak0.pakdemo loop at 3840x2160. Each run is 90 s withAPS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1 APS5_TRACE_SUMMARY_EVERY=10. main and main+this PR came from the same build directory, were relinked for every run, and ran interleaved in one session. FPS is presents over the seven full 10-s summary windows after the first one (the first holds the shader compiles). p50/p90 are the medians of the windows'frame_ms. No trace dropped events, and no run stopped early.Pairs 1-2 ran while other builds loaded the host, so I give the quiet pairs 3-6 separately: main 106.34 FPS (p50 8.79, p90 10.92 ms), this PR 108.38 FPS (p50 8.72, p90 10.59 ms), +1.9%. That is about the size of the main-to-main spread in those pairs (105.44-107.39, 1.8%), but the PR is ahead in all six pairs. The #7464 runs and one stack run were interleaved in the same session and are not shown here.
Middle Ages Ping Pong PPSA28319 (60 s, two runs per side) is vsync-bound: 59.94 FPS and p50 16.683 ms in every run, so no gain and no loss is visible there.
Stack with #7464, no-regression check: vkQuake 111.42 FPS (9249 frames in 90 s), Ping Pong 59.94, Showcase PPSA99005 12.07 FPS (main 11.25; one run each). No stop line or crash; every run hit the timeout. GPU pass on the stack (
-j1 --timeout 300 -R '^agc_driver_', the image-array-window test excluded because it doesn't build on main, #8310): 599 passed, 2 skipped as on main, 2 failed.agc_driver_pass_input_hazardalso fails on main.agc_driver_indirect_arguments_pending_producertimes out and comes from #7464: it passes when only #7464's label hunk is reverted. I report it there.tools/check_conventions.py --base origin/mainpasses on the head, the handoff and the merge, andgit diff --checkis clean.Not checked: the
ERROR_NOACCESScase for an unbracketedReadFile(no title here hits it), #7471 on its own, the GPU pass on main+#7473 without #7464, the full non-GPU suite, Linux, console behaviour.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-20T23:34:31Z.
@oneandonlydean, thanks. @screamm ran the workload A/B you asked for: vkQuake at 3840x2160, six interleaved pairs, this PR ahead in all six, +1.9% over the four quiet pairs, which is about the main-to-main spread there (1.8%). I read that as a small consistent lead, not an established gain, and the description says so. In SuperTuxKart on main
2185dbf92eI have one valid capture per side against #7471 (8.68 against 8.33 FPS), which is inside that scene's run-to-run spread, so no FPS claim from it; the description has the summary lines and the write-collection counters (with #7471 in the same build:GetWriteWatchcalls per frame 1138 -> 271, bytes scanned bycollectResidentper frame about 1.6 GiB -> 79 MiB).Rebased onto main
2185dbf92eon top of the rebased #7471 (9d5f8326bf); head7898b5bd3a. Conflicts: test insertion points inGuestMemory.cpp(main's #7448 tests kept) andstruct View, where main'sviewBytesstays beforehostImportsbecauseMapinitialisesViewpositionally.guest_memory,guest_mmap_fixed_anonymousandagc_driver_host_import_windows3/3; 31 related write-watch, host-import and socket host-write tests pass; @screamm's two source controls fail as expected and pass once restored. #7471 still has to land first. The unbracketedReadFilecase stays documented debt.AI-assisted: yes (Claude Code)