fix(memory): honor low guest mapping hints #6469
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6469"
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 QRMOE on 2026-10-15T16:30:21Z.
What
Private anonymous
mmapwithoutMAP_FIXEDdrops the caller's address hint, and the guest arena starts at 8 GiB, so a title cannot get guest memory below 2 GiB even when it asks for it. Super Mario Sunshine (PPSA99312) stops with[port] no memory below 2 GiB for the game's stackthis way (report on #5217; bring-up #6468). Its port's public MIT memory probe requests a 64 MiB mapping at hint0x20000000and a 128 MiB pool at hint0x40000000.This change forwards private anonymous hints to the existing placement allocator and extends the Linux and Windows arena down to 64 KiB. Host mappings already in that range stay occupied, and low chunks Linux refuses by address policy are skipped. Null-hint allocations and the fallback for a high hint with no room still start at 8 GiB. macOS and ASan builds keep their current 8 GiB start. There are no title-ID branches, new exports or silent stubs.
The new
guest_low_address_memorytest covers the probe's two low requests, readable and writable endpoints, relocation of an occupied hint, fixed and exclusive replacement, protection and query, unmap and reuse, and the unchanged default allocation start.Not changed here, recorded in the libc and libkernel debt entries:
KUSER_SHARED_DATA, so Wine's shared user data page (Forever Launcher PPSA99030) still cannot be placed there.scePthreadCreatestill ignores a stack address set withpthread_attr_setstack.Rebased onto main
4997726a5. Main moved the arena offset toGuestArena::GuestAddressOffsetand extended the Fixed anonymous mmap debt entry; both are kept. Thanks to @xXPBSXx for the earlier carry branch.Tested
Local, Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON, head
583687317on main4997726a5:libsand all memory test executables build with no warnings in the changed files.ctest -R 'memory|mmap|arena|alloc|mprotect|munmap|madvise|msync|mincore|flexible|heap|stack|ampr|jit|write_watch|patched_libraries' -E '^agc_'), 50 tests, passes serially. With-j8,windows_write_watchandguest_allocator_failurestimed out once and passed when rerun alone.guest_low_address_memory,guest_memoryandguest_mmap_fixed_anonymouspass 5/5 (--repeat until-fail:5). The two mappings land at0x20000000and0x40000000.GuestArena.cppandPosixMemory.cpprestored to main (new tests kept),guest_low_address_memoryfails at line 35 with the mappings at0x200000000and0x204000000, andguest_memoryfails at its arena-base check.python tools/check_conventions.py --base origin/main: 0 errors, one[debt-length]warning on the Fixed anonymous mmap entry, which was already over the limit on main (2053 characters, now 2334).Reports from other contributors in this thread (on earlier heads/carries of the same change):
guest_low_address_memoryandguest_memory10/10; 650-test non-GPU suite same as main.e1b43da): memory family 24/24 ×3. Super Mario Sunshine: main stopped at "no memory below 2 GiB" in 6 of 22 runs; with the change, 0 of 22 did and all 22 reached the port's own "no disc image" stop. No game image was supplied, so gameplay is not verified.sendmsgcontrol data. On Windows it still stops there (see above).e1b43da): low-address test 3/3, memory family 23/23.Not tested: macOS, ASan, gameplay of any title.
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 jotitadev on 2026-10-15T18:09:33Z.
Review: COMMENTED
Linux run, since the description says Linux was not tested locally.
Ubuntu 26.04 (kernel 7.0), i7-8700, gcc 15.2, Release,
BUILD_TESTING=ON, no ASan, full build. Head29a84d07bapplied onmain03c4cb5e7.vm.mmap_min_addris 65536 here, which is the new arena start.GuestLowAddressMemory.cpp, theGuestMemory.cppchange and the test registration, onmain's source):guest_low_address_memoryfails at line 35 withbuffer=0x200000000 stack=0x204000000.guest_memoryfails atGuestMemory.cpp:1138, the new arena-base check.buffer=0x20000000 stack=0x40000000.guest_low_address_memoryandguest_memorypass 10 of 10 runs.-E "^agc|gpu|vulkan|video_out",-j8): same result asmain. Onlyfile_writer_binaryandfile_writer_textfail, onmaintoo (this host's coreutils rejects the command they run).Not run with ASan, and no title run.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T10:31:34Z.
Another title that needs low guest mappings, a fixed one this time: Forever Launcher (PPSA99030, 01.000.012, catalog build) runs Wine. Linux, RTX 4070 Ti,
mainbf20538169, 60 s, 2 runs each. To reach this point I merged the open PRs for its earlier stops locally: #6915, #6028, #6939, #6787 and #7070.virtual_alloc_first_teb("wine: failed to map the shared user data"). It maps that page at the fixed address 0x7ffe0000, below the current 0x200000000 arena start.sendmsg: control data is not supported. I'm working on that separately.So the arena extension also helps fixed mappings, not only hints.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T11:29:42Z.
A Linux data point for Super Mario Sunshine (PPSA99312), the title @0xRickx mentioned on #5217. RTX 4070 Ti,
main984e5d7201with #6220 (its earlierunamesysctl stop) in both builds, 40 s, no disc image in the folder:main+ #6220: afterno disc image in the title's folder, the title exits at once (0 s) and prints nothing more.main+ #6220 + this PR (29a84d07b3): it continues past that line: That is the port's own stop when no game is supplied. Its 64 MiB at 0xc0000000 is below the current arena start.PS5CEMU-HAR (PPSA99360) runs its launcher to the limit with and without this PR here; scripted input doesn't reach the 3DS side where Azahar's JIT reserves memory, so that case isn't covered.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T16:10:44Z.
A Windows run for the Forever Launcher case @milescoviello reported above. Windows 11, RTX 3080, WinLibs GCC 15.2, Release, head
29a84d07bonmaine5f18ea99plus #6915, #6939, #6787 and #7070 (plain merges, no conflicts; this PR and the stack sharePosixMemory.cppand the debt docs in separate hunks):guest_memoryandguest_low_address_memorypass 5/5 (--repeat until-fail:5). No warnings inGuestArena.cpp,PosixMemory.cpp,GuestLowAddressMemory.cpporGuestMemory.cpp.mmap_nid_postfixshows that Wine's shared-user-data request is a hint, not a fixed mapping:mmap(0x7ffe0000, 0x4000, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0)(flags0x1002). Wine's FreeBSDanon_mmap_tryfixedmaps with the hint, then unmaps and fails if the result isn't that address. Onmainthe hint is dropped and the page lands in the arena (0x203164000).0x7fff0000, one 64 KiB block above, because Windows keeps its ownKUSER_SHARED_DATAat0x7ffe0000in every process. Wine then still exits 1 witherr:virtual:virtual_alloc_first_teb wine: failed to map the shared user data: c0000018, as onmain. Elsewhere in the same runs this PR's hints work: Wine's top-down probe is honored exactly at0x8000000000, so its lower probes and its0x10000reservation no longer happen.So on a Windows host this PR fixes the hints but not this title's stop. No guest mapping can sit at
0x7ffe0000there. Could that page be translated to a different host address for the guest, or is this better left as a Windows-only debt entry for now?AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T17:53:04Z.
@babyhuey thanks for running it on Windows. On translating the page: I don't think it can be done here. Relinked guest code dereferences guest addresses as host addresses, and Windows programs (Wine's included) read the shared user data at its absolute address, 0x7ffe0000 plus a field offset, with plain loads. Putting the page anywhere else would mean trapping every load from that page. On an x64 Windows host, 0x7ffe0000 already holds the system's own read-only
KUSER_SHARED_DATAin every process, so the guest can't map there.So a Windows-only debt entry seems right to me: this PR fixes the hints there, and the shared user data mapping stays a known Windows limit. On Linux this PR gets Wine past that stop (my run above). It's @QRMOE's PR, though, so it's their decision.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T04:48:42Z.
@QRMOE this PR now conflicts with
mainincore/libs/prx/libc/src/GuestArena.cpp(mainmovedGuestArenaOffsetto the sharedGuestArena::GuestAddressOffset) and in theFixed anonymous mmapentry ofdocs/dev/debt/libkernel.md(which gained the native-stack replacement text).In case it helps: I rebased your commit onto current
main(7ab4b2e561) without changing your changes to the allocator, keeping you as its author. InGuestArena.cppI keptmain's shared offset and re-applied yourDefaultAllocationStart/ArenaStartlines on top of it. In the debt entry I keptmain's text and swapped in only your replacement for the sentence about where the arena starts. BranchxXPBSXx:carry/6469-low-guest-mapping-hints, heade1b43da6ce. You can take it withgit fetch https://github.com/xXPBSXx/AnyPS5 carry/6469-low-guest-mapping-hintsandgit reset --hard FETCH_HEAD, or rebase yourself; I will not open a second PR for it.Windows 10 19045, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, on that head:ctest -R '^guest_low_address_memory$'passes 3 of 3.-R 'memory|mmap|arena|alloc|mprotect|munmap|madvise|msync|mincore|flexible' -E '^agc_', after building the missing executables).GuestArena.cppandPosixMemory.cpprestored tomain(your tests kept),guest_low_address_memoryandguest_memoryboth fail with exit code0xc0000409.python tools/check_conventions.py --base upstream/mainpasses with two[debt-length]warnings (thelibc.mdandlibkernel.mdentries you changed are over 1000 characters; both were already long onmain).git merge-treeagainst currentmainis clean.Not tested: Linux/macOS, the titles named in the description (PPSA99312, PPSA99030).
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-22T08:50:56Z.
Linux run of @xXPBSXx's rebase of this PR (
carry/6469-low-guest-mapping-hints, e1b43da6c), since that covers Windows only. Merged ontomain7e2ba73e4(clean merge). Ubuntu 24.04 container, GCC 13, Release,BUILD_TESTING=ON. Full build, no warnings inGuestArena.cpporPosixMemory.cpp.-R 'memory|mmap|arena|alloc|mprotect|munmap|madvise|msync|mincore|flexible' -E '^agc_', 24 tests includingguest_low_address_memory) passes 3 of 3 (--repeat until-fail:3).mainits stack request only fails some of the time:[port] no memory below 2 GiB for the game's stackno disc image in the title's foldermain(d6eafa54)My catalog sweeps showed the same intermittent stop on
main(4 of the last 7). So on Linux the hints are honored often enough by chance that a single run can miss it.DisplayWindowVulkan check on both builds (2 runs each).AI-assisted: yes