fix(libSceNKWebKit): take WTF::ramSize from the guest sysconf #20100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20100"
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 MatteoSid on 2026-11-14T16:10:00Z.
What
WTF::ramSize()in libSceNKWebKit (_ZN3WTF7ramSizeEv, NIDL+f444MZShU) returned the host's physical memory on every call. It usedGlobalMemoryStatusExon Windows and the hostsysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE)elsewhere, and threw when the host could not answer. The PS5 11.x WebKit tree does something else:USE_SYSTEM_MALLOCoff (WebKitFeatures.cmake), and the PlayStation port links bmalloc statically (PlatformPlayStation.cmake).bmalloc::api::availableMemory()and keeps it in acall_oncestatic.computeAvailableMemorytakes theBOS(FREEBSD)branch, which__FreeBSD__selects (BPlatform.h). It returnssysinfo'stotalram * mem_unit, oravailableMemoryGuess(512 MB) whensysinfofails. TheBOS(UNIX)branch below it multipliessysconf(_SC_PHYS_PAGES)bysysconf(_SC_PAGE_SIZE)and falls back to the same guess when either returns -1. It never throws.WebKit c55364d53f97 has the same
BOS(FREEBSD)andBOS(UNIX)branches.Changes:
ramSize()now asks guest libkernelsysconf(121)(_SC_PHYS_PAGES) andsysconf(47)(_SC_PAGESIZE), the queries #19993 and #20053 use forpageSize()andnumberOfProcessorCores(). It multiplies them once, caches the result, and returns 512 MB when either query is -1, where it used to throw. libSceNKWebKit already links libkernel.src/WtfRamSize.cpp. It starts with aDerived fromline and the RAMSize.cpp and AvailableMemory.cpp notices copied verbatim, likeWtfNumberOfCores.cpp.WtfSystem.cpponly changes the export's body and declares the helper. Its includes stay as they are, because #19380 and #19823 edit the lines around them.ramSizecomes out of the "WTF host services" entry and gets its own entry next toWTF::numberOfProcessorCores:sysinfois not called. On the console,sysinfocomes from libScePosixForWebKit (9Vqxt-qBPB4), and its prototype is unknown (libScePosixForWebKit.md). So this PR follows theBOS(UNIX)branch of the same function, which gives the same value wheneversysinforeports_SC_PHYS_PAGESpages of_SC_PAGESIZEbytes.sysconf(121)still reports the host's memory in 16 KiB pages, not the 139888 pages a PS5 payload read. The libkernelsysconfentry already records that gap.Reachability:
ramSize()takes no arguments and needs no object, so any module that imports it from libSceNKWebKit reaches it directly. In the pinned PS5 tree, a web view calls it on these paths:JSC::Heap::Heapstores it inm_ramSizefor every VM, including the one a web page's scripts run in.minHeapSizeandproportionalHeapSizescale the GC heap by it. Those functions, and the critical-memory threshold at L423, decide when the collector runs.WebKit::calculateMemoryCacheSizessizes the memory cache and the back/forward cache from it.MemoryPressureHandler::Configurationuses it for its base threshold, and the kill thresholds at L107-L126 read it too. The PlayStation port builds it withunix/MemoryPressureHandlerUnix.cpp.BufferMemoryManager::memoryLimit, is three times this value.Which console modules import this NID has not been checked against a dump.
Tested
Linux (Ubuntu 24.04 container, GCC 13.3), Release,
-DBUILD_TESTING=ON, on head498463a545based onmain3e63c9f68f. BuiltlibSceNKWebKit, the patchedcore/libs/libs/libSceNKWebKit.prxand every libSceNKWebKit test target.ctest -R 'nkwebkit|^public_headers$'passes 81 of 81.nkwebkit_wtfdrives the export throughRamSizeSysconfForTest_nid_no_patch, which followsNumberOfProcessorCoresSysconfForTest_nid_no_patchfrom #20053. It replaces the sysconf query and drops the cached size, andnullptrrestores guestsysconf_nid_postfix. The test checks:sysconf_nid_postfix(121) * sysconf_nid_postfix(47), is at least 1 GiB and is stable.No test needs timing.
Negative controls on
498463a545, one at a time, in the Docker build. Each makesnkwebkit_wtffail (no build failures), and the restored tree passes:WtfSystem.cppexport body (hostsysconf, throws on failure);sysconf(58)instead of 121 for the pages;sysconf(46)instead of 47 for the page size;g_ramSizeComputednever set);nm -Don the patchedlibSceNKWebKit.prxlistsL+f444MZShUat the address of_ZN3WTF7ramSizeEv(0x26d0c0), and the hook keeps its_nid_no_patchname.tools/check_conventions.py --base origin/main --head HEADpasses, andgit diff --check origin/mainis clean.Overlap: no open PR mentions
ramSize,RAMSizeor the NID.tools/pr_overlap.py --branchfound no overlap; it could not compare 19 PRs (debt file, andtests/Wtf.cppfor #19103 and #19106), which I checked by hand:WTF::pageSizeorWTF::numberOfProcessorCoresentries, orramSize;tests/Wtf.cppat lines 6, 562-573, 1132 and 1424, far fromTestSystem(line 308).No title tested.
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-14T16:34:37Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
498463a545:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtf_testsbuilt cleanly.nkwebkit_wtf):core/libs/prx/libSceNKWebKit/src/WtfSystem.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me