perf(libkernel): find the next free direct-memory page with memchr #25280
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25280"
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 LeandroLP23 on 2026-11-21T20:50:04Z.
What
std::find, one byte per 16 KiB page. SuperTuxKart (PPSA69421) allocates, maps, unmaps and releases about 1000 64 KiB blocks per second during a race, above a used prefix of about 1.4 GiB, so everysceKernelAllocateDirectMemoryscans about 92,000 flags under the pool lock.PhysicalMemoryPool::_nextFreePagenow finds the flag withmemchrand returns the same page (or the search limit when every flag up to it is set). Astatic_assertpinssizeof(bool) == 1, which the byte scan relies on.MemoryPoolTestgetsalloc_past_a_long_used_run: two 1.5 GiB runs around a one-page hole; a two-page request lands after the second run, the hole is found for a one-page request, and a search end inside the runs (or at the end of the second one for a two-page request) returnsSCE_KERNEL_ERROR_EAGAIN.tools/pr_overlap.py --branch HEAD: no overlap with open pull requests (#24063 also editsMemoryPool.cppand merges cleanly).Tested
Windows 11 (10.0.26300), NVIDIA GeForce RTX 5060 Ti (NVIDIA 621.24), Intel i5-10600K, WinLibs GCC 15.2.0 r7, Release.
MemoryPoolTestonmain8763aeffdc(with the new case added) and with this change: 21 of 21 cases pass on both.Time per call, measured with a temporary
steady_clocktimer around the export (not part of this change) in the same SuperTuxKart race (title_run with a pad timeline, 110 s), two interleaved pairs; this was on a local branch with1a5c95da66eapplied, whichmainalready contains:sceKernelAllocateDirectMemoryper callstd::findmemchrstd::findmemchrThat is about 0.6 ms per frame of the game thread at about 35 allocations per frame. The frame time does not show it within the run-to-run noise: frame p50 37.9 / 38.4 ms with
std::findand 37.7 / 38.9 ms withmemchron that branch.tools/trace_digest.pyon real commits, same race, 10 s window 80 s after the first present (APS5_TRACE_SECONDS=80:10),main8763aeffdcand this branch's headb6de80aed7, alternated twice:No change in frame time beyond noise; the claim is the time per allocation above. Working set and private bytes are unchanged (3.3 / 5.0 GB).
Summary lines of the first pair:
main (
8763aeffdc)this PR (
b6de80aed7)Not run: the whole CTest suite, other titles, Linux and macOS (the change is in shared code with no platform branch). The traces are available on request.
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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T21:53:42Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b6de80aed7:tools/check_conventions.pypassed.MemoryPoolTestbuilt cleanly.MemoryPoolTest):core/libs/prx/libkernel/DirectMemory/MemoryPool.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T18:09:24Z.
Review: APPROVED
Reviewed — looks good
The reviewed change preserves the existing first-fit search behavior while using
memchrto find the next free page flag.What I ran
Read the prepared PR description, commits, manifest, and diff, then read both changed files through the reader pinned to head
b6de80aed7fb20c0b45f4c7da2d8483aeb17c4eb. No executable tests or other commands were run in this environment.Results
MemoryPoolTestNegative control
Not run; no executable test environment was available.
Findings
Blocking
None.
Non-blocking
None.
Sources
MemoryPool.cppat reviewed headMemoryPoolTest.cppat reviewed headNot verified
The author-reported test results and performance measurements were not independently verified. The full CTest suite, other titles, and Linux and macOS behavior were not run. Both changed files listed in the manifest were read; no changed files were excluded.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:55:50Z.
Review: COMMENTED
Built the branch sources against the existing Linux runtime. The memory-pool fixture passed.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:09:04Z.
Review: APPROVED
I read the diff at
b6de80aed7. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged intomainat6c6b29320fetogether with other open PRs (so not an isolated build).MemoryPoolTest: pass on both.Not checked: the timing in the body.
AI-assisted: yes (Claude Code)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.