feat(libkernel): count committed ranges in sceKernelGetPageTableStats #4725
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4725"
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 akkadbakkad89 on 2026-10-12T19:48:31Z.
What
Builds on the
sceKernelGetPageTableStatsimplementation merged in #4101 (issue #4067) by adding the usage counting it explicitly deferred:GuestPageTableUsageiterates the recorded protection ranges, charges one page-table entry per 2 MiB granule a range spans to the gpu pool when the range has GPU-access protection bits (0x30) and to the cpu pool otherwise, and follows changes through map/protect/unmap — soavailablereflects committed usage instead of staying at 2048. Totals, EFAULT-on-null and the KytyPS5 model (4 GiB pool / 2 MiB granules / 2048 entries) are unchanged from #4101.Unverified constants remain recorded in
docs/dev/debt/libkernel.mdper conventions.Tested
WSL Ubuntu 24.04, llvmpipe, on current
mainincluding #4101.guest_page_table_statscovers: EFAULT for each null argument, cpu accounting of a flexible mapping and its restore on unmap, cpu/gpu reclassification throughsceKernelMprotect, and gpu accounting of a direct mapping.guest_memory(which now contains #4101'sCheckPageTableStats),guest_memory_pool_stats,guest_addresses,guest_mlock,guest_msyncall pass;check_conventions.py --base upstream/mainclean. No console run — budget constants unverified on hardware.Checklist
main; layered on the implementation merged in #4101NotImplemented_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 akkadbakkad89 on 2026-10-12T19:51:38Z.
Overlap note: #4101 implements the same function and predates this PR — my open-PR search missed it when I picked up #4067, apologies.
The difference between the two: #4101 reports the 2048/2048 totals statically ("KytyPS5 additionally counts the 2 MiB entries of the committed ranges as used; this PR does not"). This PR does that counting —
GuestPageTableUsageiterates the recorded protection ranges, charges each 2 MiB granule a range spans to the gpu pool when it has GPU-access protection bits and to the cpu pool otherwise, and follows protection changes throughmprotect, soavailablereflects actual committed usage rather than staying at 2048.Same signature, constants, sources and EFAULT behavior otherwise. Happy to defer to whichever approach maintainers prefer.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:57:55Z.
The live-range accounting is a useful distinction from #4101’s fixed available count, and the added mapping/protection tests exercise that behavior. I checked the exact PR branch against current main: it is nine commits ahead and includes two merge commits carrying unrelated discussion-template and shader/AGC changes (the page-table implementation itself is a focused commit). Please rebase/cherry-pick the page-table work onto current main before merge, then coordinate with #4101 on which implementation should proceed; the two PRs modify the same export, and the dynamic accounting here is the more complete behavior if its assumptions/tests are validated. No pressure on merge order—maintainers can choose the path.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:15:20Z.
Review: CHANGES_REQUESTED
#4101 is merged now, so this conflicts with
maininDirectMemory/Export.cppanddocs/dev/debt/libkernel.md. Please rebase onto currentmain(and drop the two unrelated merge commits MarcZX100 mentioned) so the diff is just the accounting change on top of the merged function.Points to fix, since the PR says it follows KytyPS5's
CountPageTableEntries:DirectMemory.cpp:1124: Kyty charges a range to the CPU pool when it has any CPU access bit and to the GPU pool when it has GPU access bits, so a range with both counts in both. Here a range with0x30is charged to GPU only.DirectMemory.cpp:1121: Kyty only counts committed range types;g_protectionsrecords every guest mapping, including ones that are not committed memory. Say which ranges are meant to count and filter accordingly.DirectMemory.cpp:1123: entries are summed per range, so contiguous ranges smaller than 2 MiB that share a granule (any partialmprotectsplits a range) each charge it again. Count each granule once per pool, or state that the double count matches Kyty and pin it in the test.Export.cpp:399: with unverified constants,availablecan now drop to 0 wheremainreports 2048. Please show the numbers a typical start-up produces (e.g. the values printed at the call in PPSA30601) so we know the dynamic count doesn't starve a title that the static answer lets through.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-13T05:38:00Z.
Rebased onto current
main(88107b7de, which includes the merged #4101) as requested — single focused commit, no merge commits, and the conflict with #4101'ssceKernelGetPageTableStatsis resolved by layering the live counting on top of it. TheirCheckPageTableStatsinguest_memorystays valid and passes under the counting implementation.Since #4101 merged first, this PR's diff now reads as: static totals kept,
availablenow computed from committed protection ranges. Rebuilt and retested on this base (WSL):guest_page_table_stats,guest_memory,guest_memory_pool_stats,guest_addresses,guest_mlock,guest_msyncpass;check_conventions.py --base upstream/mainclean.AI-assisted (Devin).
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-13T06:50:41Z.
All five points addressed in 08774c0e1:
Dual-access ranges — fixed:
prot & 0x7now charges the cpu pool andprot & GuestProtGpuReadWrite(0x30) the gpu pool, independently, so a0x33range counts in both like Kyty. The direct-mapping test (prot 0x33) now asserts both pools drop, which caught the earlier either/or mistake.Which ranges count —
g_protectionsholds committed mappings only:DoReserveVirtualrecords into the separateg_reservationsmap and callsRecordProtection(addr, len, -1), so reservations are never recorded here. Within the map, each range is charged to each pool whose access bits it carries; a range with no cpu or gpu access bits (e.g. PROT_NONE or ACP-only protections) charges neither, matching Kyty's committed-range access classes. The debt entry now says this explicitly.Shared granules — kept Kyty's per-range sum (each range charges the granules it covers, so split neighbours in one granule charge it once each) rather than deduplicating, and pinned it in the new
CheckSharedGranule: two adjacent 16 KiB maps inside one 2 MiB granule dropcpu_availableby 2, not 1.Startup numbers — measured in
guest_page_table_statson this branch (WSL): a fresh process reportscpu 2048/2048, gpu 2048/2048(guest image segments aren't recorded, so baseline use is 0); after a 6 MiB flexible map2045/2048; a 2 MiB0x33map2047/2047; two 16 KiB neighbours2046/2048.availablereaches 0 only past 4 GiB of committed coverage on a side — the same ceiling the constants imply on console — and reservations cannot inflate usage since they are not recorded.Tests — added
CheckDualAccessMapping(0x33 charges both pools, restore on unmap) andCheckSharedGranule(the Kyty per-range double charge above), both with expected values derived from Kyty's rules.guest_page_table_stats,guest_memory,guest_memory_pool_stats,guest_addresses,guest_mlock,guest_msyncpass;check_conventions.pyclean.AI-assisted (Devin).
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:36:10Z.
Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto
main7e181fcc3together with #4725, #4719, #4585 and #4582 (no conflicts):guest_page_table_statspasses. With this PR's source change reverted (test kept), it fails on Linux, so the check guards the change on Linux too.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-13T10:55:56Z.
Verified on WSL Ubuntu 24.04 as well —
guest_page_table_statsand the neighboringguest_memory*tests pass here too.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:26:58Z.
Review: APPROVED
Checked the counting against KytyPS5's
CountPageTableEntries(per committed range, cpu and gpu pools independent, no-access ranges skipped, clamped at 2048): same results. The five earlier points are addressed. The only conflict was thesceKernelGetPageTableStatsline indocs/dev/debt/libkernel.mdnext toclock_settime; rebased ontomain, kept your entry. Scoped build and ctest 150/150, andguest_page_table_statsfails without the change. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-13T19:05:47Z.
Rebased onto current
main(dacd78525): single commit, the only conflict was thesceKernelGetPageTableStatsentry indocs/dev/debt/libkernel.md(kept this entry next to the newpthread_atfork/clock_settimeones). Rebuilt on this base:guest_page_table_stats,guest_memory,guest_memory_pool_stats,guest_addresses,guest_mlock,guest_msyncpass;check_conventions.py --base upstream/mainclean.AI-assisted (Devin).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-13T19:25:49Z.
Rebase handoff — rebased onto current
main(docs-only conflict, both entries kept), authorship unchanged.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727)To pick it up:
Head is
f9cc81d86.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-13T19:29:42Z.
f9cc81d86 is the current head — already rebased onto
dacd78525, so nothing to pick up on this side. Thanks for the RADV run and the suite verification.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:43:38Z.
Rebuilt on current
main: scoped build and ctest green,guest_page_table_statsfails without the change and passes with it; the counting matches KytyPS5'sCountPageTableEntries(cpu and gpu pools independent, clamped at 2048). Merging once the full Build is green.