perf(libkernel): find direct-memory aliases through the physical index #7468
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7468"
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:11Z.
What
This PR is part of a series of graphics and memory-management performance improvements for AnyPS5, with SuperTuxKart as the main profiling workload. This is item 05/10; the UI Lab startup/cache fix follows as a separate eleventh PR. Each topic's measurements are distinguished from the combined result.
Use the existing physical-span index to select direct-memory aliases that must be unpinned before a mapping changes. Collect overlapping virtual mappings under the existing lock and wait for their leases outside that lock.
Tested
Pinned benchmark base:
6447ed1ed7fd11c7eef60df336e8d66fac271188. Tested topic snapshot:d2ca227e8f3230cb0b733608ab3fd84cdd9336a9. Windows 11 Pro build 26300, Ryzen 7 5800H, RTX 3070 Laptop, NVIDIA 617.42. Frozen runtime module hashes and raw traces were verified. No opt-in optimization flags are required.2/2 targeted memory cases passed. Coverage includes a live lease delaying physical alias creation, coherence of overlapping aliases, partial removal, release across 48 reverse-ordered pieces and concurrent access while resident runs split.
SuperTuxKart captures for the bot's before/after requirement: 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-18, two captures per side, order main, PR, main, PR.required1018-main-64476447ed1ed7fd6447ed1ed7fdrequired1018-main-6447-awake-r26447ed1ed7fd6447ed1ed7fdrequired1018-7468709520ddabberequired1018-7468-awake-r2709520ddabbeThe FPS difference is within the run-to-run spread of main; this PR claims no FPS change. What it saves is shown under Where it helps.
Summary lines (main first, then this PR)
tools/performance_compare.py(first capture of each side)Performance comparison
6447ed1ed7709520ddabConfiguration differences
Frame 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)required1018-main-6447seconds 20:8 from present 42: 77 presents, frame p50 103.2 / p90 111.2 / p99 116.8 / max 116.8 ms, GPU busy 5.3 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
6447ed1ed7, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
required1018-7468seconds 20:8 from present 47: 70 presents, frame p50 101.3 / p90 162.0 / p99 256.7 / max 256.7 ms, GPU busy 5.4 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 1920x1080, commit
709520ddab, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Where it helps
The title allocates, maps and releases about 48 direct-memory blocks per frame; every release asks
RequireAliasesUnpinnedfor the aliases of the physical range. On main that scans every direct mapping; with this PR it walks the physical index.2185dbf92eRequireAliasesUnpinnedcalls per frameRequireAliasesUnpinnedµs per callRequireAliasesUnpinnedms 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.Other homebrew checks
UI Lab: the 21 default concepts were rendered and visually reviewed in a navigation cycle for this topic. Artwork was present; this covers default navigation, not all themes or every widget interaction.
Known baseline rendering issue: vkQuake still has intermittent flickering and an intermittently black floor on main and the tested performance branches. These changes do not fix it. Yamagi Quake II gameplay stops at unsupported last-provoking-vertex flat interpolation, and UZDoom at unsupported clip/cull-distance handling on the baseline; neither supplies a valid gameplay FPS comparison.
Dependencies, series and overlap
#7448 changes release ordering to unmap views before returning physical pages. This topic only selects aliases through the physical index; it does not fix that separate lifetime race.
The project overlap scan compared the local topics against 785 open PRs and checked merges into main
e5c2b3c325e485ba7fd417c47c46f48aa2c89115. This topic merges cleanly in that snapshot. Some other PRs already conflict with main, so the tool cannot compare all their shared-file hunks; the full report is retained with the common series evidence package. No exact duplicate was identified in the inspected implementations. This is not a certification that every conflicting foreign branch is composition-tested.Conventions and whitespace checks passed for the tested topic range. The benchmark base remains pinned for comparability; this is not a fresh-current-main build/test claim. Measurements and focused tests refer to the pinned source revisions above; no full-suite CI run is claimed.
Re-checked on 2026-10-21: this head still merges cleanly into main
2185dbf92e. #6658, which the earlier combined runs carried, merged into main on 2026-10-20.Combined series result
Re-measured on 2026-10-21 on current main
2185dbf92e(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). Runs in the order A-B-C-D-D-C-B-A, two per configuration; FPS is presents over the 8-s window.2185dbf92e#7464 and #7465 make the largest step together: the title's per-frame host imports disappear (see their PRs). With #7464 reduced to its CPU-label wake only, the whole series measured 10.07 / 9.01 FPS against main 9.24 / 9.30 in a separate block of the same session. Combined numbers are not the gain of any single PR. The combined builds are local merges of the published (#7465-#7470, #7472, #7474) and rebased (#7464, #7471, #7473) heads into main
2185dbf92e; the commits in their summary lines are those merges, not pushed. Summary lines, traces and digests: series-evidence.zip.Checklist
6447ed1ed7fd; merges cleanly into current main2185dbf92e(git merge-tree, 2026-10-21); related overlaps are listed aboveNotImplemented_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)The published head adds publication metadata only; its complete source tree is identical to the tested snapshot above.
Series index
These are the ten performance topics from the same profiling effort, followed by a separate UI Lab cache-preservation fix. Membership in the series does not imply a dependency.
Reproduction evidence
Series traces, summary lines, module hashes, focused-test logs and UI contact sheets. Game measurements use the pinned base and source revisions described above; assets contain no game binaries.
Update of 2026-10-21: 7468-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.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T08:58:23Z.
Some 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/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T12:32:20Z.
Differential check: I put
main'sg_directMappingsand physical-span code in one harness, with random inserts, virtual erases and physical erases. Comparing the old full scan with the new indexedRequireAliasesUnpinnedselection over 3 × 400k operations gives 0 mismatches in about 360k alias queries (about 320k non-empty), in the same order.With 20,000 mappings, a lookup takes 128–147 µs with the old code and 0.22–0.24 µs with the new. The 462
guest_/libkernel/libctests pass on Windows (GCC 15.2).AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-18T13:05:51Z.
@wachi35676 Thanks for the independent differential test and the Windows coverage. The zero-mismatch result across the alias queries, including their order, is useful confirmation of the indexed selection. I will keep the lookup microbenchmark separate from any whole-game FPS claim.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T21:44:41Z.
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 Dripl1x on 2026-10-20T23:34:19Z.
Updated the description: before/after summary lines from the same machine and SuperTuxKart scene (main
6447ed1ed7fd9.58 / 9.53 FPS, this PR709520ddabbe8.70 / 9.86 FPS, so no FPS claim),trace_digest.pyandperformance_compare.pyoutput, and probe counters that show where this change saves work in that scene:RequireAliasesUnpinnedruns about 49 times per frame (every direct-memory release) and takes 54.2 µs per call on main against 0.21 µs with this PR (2.63 -> 0.01 ms per frame). Traces, digests and the probe patch are in the evidence release. The head is unchanged and still merges cleanly into current main.AI-assisted: yes (Claude Code)