feat(libs): let relinked Linux games opt into mimalloc #14264
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14264"
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 Astronaut10 on 2026-11-01T05:17:20Z.
What
Relinked Linux games can opt into mimalloc with
APS5_MIMALLOC, as Windows games can since #6067 and macOS games since #11130. Without the variable nothing changes, and titles do not need a new relink.libmimalloc.sobeside the libraries as a regular file. It is built from the existing submodule with the options Windows and macOS use (MI_OVERRIDE,MI_FREE_IS_CHECKED=SHARED) and linked--as-needed, which drops an unusedlibatomic.so.1dependency, so it loads wherever the libraries do. The Linux release archives ship it, andpackage_release.pyrequires it as it requires the Windows DLLs.ANYPS5_ENABLE_ASAN,ANYPS5_ENABLE_TSAN) do not build it. With mimalloc preloaded, an ASan program stops with "ASan runtime does not come first in initial library list" and a TSan one crashes.MimallocMacOs.cpp) becomes one implementation with platform pieces,MimallocRestart.cpp. WhenAPS5_MIMALLOCis set and mimalloc is not loaded, libkernel puts thelibmimalloc.sobeside it first inLD_PRELOAD, setsAPS5_MIMALLOC_RESTARTEDand runs the executable again withexecv(same arguments, same process ID). The restarted process removes the marker; if the dynamic linker ignored the variable (secure-execution mode), it prints one line and keeps the system allocator instead of restarting again. The macOS messages are unchanged./proc/self/exe, not/proc/self/exeitself. The kernel names a process after the path it was started from, so that would rename the title toexe. The arguments come from/proc/self/cmdline, so a title started asld.so app.elfstarts that way again.ANYPS5_LOG_FILE. libc's log-file copy moves the standard streams into a pipe when libc loads, before libkernel's constructor runs;execvcloses the pipe's reader, and the restarted process was killed bySIGPIPEat its first write. libkernel now gives the streams back beforeexecv, as LoadExec does. The macOS side of the shared file was compiled against stub headers only, not run on macOS.debt/libkernel.md: when thatexecvfails, the title goes on with the system allocator, but the log-file copy stays stopped, since libc cannot take the streams again.Why: in this scene the frame is bound by the CPU chain of the queue worker, the draw committer and the draw finisher, which allocate on every draw; with mimalloc each of them spends 4-6 % less CPU per frame (below). The cost is memory: in the same scene about 0.9 GiB less host memory was available with mimalloc (below).
Tested
CachyOS (Linux 7.3), Ryzen 7 5700X3D, RX 9070 XT (RADV, Mesa 26.2.5, GPU clock level forced to
high), 31 GB, transparent huge pagesalwayswith defragdefer+madvise, 3840x2160. PPSA21564 (ASTRO BOT 01.007.000), started intounderwater_aerial_gardenwith-lvl, standing at the spawn with no input, warm caches.Base:
main029463ceb6; change: this branch at98446ecb20run withAPS5_MIMALLOC=1, mimalloc built by this PR with its options. The branch was measured before it was rebased ontomain3ab5a11d66without conflicts (the same diff; rebuilt and its focused tests rerun after the rebase). Plainmainneeds a larger host-import budget than its default to run this scene at a usable rate, so both sides setAPS5_HOST_IMPORT_MIB=11815. Switches on both:APS5_DEPTH_PLANE_COPY_MIB=512 APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1 APS5_NO_PAD_INPUT=1 APS5_HOST_IMPORT_MIB=11815.The restart happened in every B run:
/proc/<pid>/mapsof the running title, read 60 s after it started, mapsrun-prMI/libs/libmimalloc.so(5 mappings) in all six B runs and in no A run, and the process keeps its PID and its nameapp.elf.Clean runs, each measured from 40 s to 130 s after the level started, in the order A B B A B A A B. The first B run was disturbed: memory pressure (PSI some avg10 up to 15.8 %, with 13 GB available and no other process loading the host), a 3.8 s frame and the video-start stall about 20 s later than in the other runs (2.755 FPS). It was rerun once. The table uses the four undisturbed runs per side; FPS from every frame of the window:
mainAPS5_MIMALLOC=1Graphics.Drawms per frameDriver.Draw.preparems per frameDriver.DrawFinishms per frame/procper thread. AnyPS5's threads keep the process name, so they are listed by rank. Every thread that allocates per draw saves CPU; the GPU time does not change.06_nx_controller_ship.mp4, about 90 s after the level started. Four runs per side do not separate B's (mean 793 ms) from A's (675 ms).mi_freepointer check) on an oldermainfound +5.3 % in this scene; the numbers above are this PR's own build and options.Summary lines of the attached traces, captured as the Performance report form describes (no other
APS5_TRACE_*orAPS5_PROFILE_*switch). The B capture keepsAPS5_MIMALLOC=1, which is the change itself. The window is 4 s (APS5_TRACE_SECONDS=51:4), so the queue worker's default event buffer does not fill; 13 and 14 presents are too few to compare frame times, which the clean runs above do:tools/trace_digest.py:main13 presents, frame p50 325.0 / p99 329.4 ms, GPU busy 167.2 ms per present; this PR 14 presents, frame p50 305.9 / p99 317.3 ms, GPU busy 162.4 ms per present;dropped: noon both. Busy time per frame: queue worker0x0278.7 -> 261.8 ms, draw committer 202.7 -> 189.6 ms, draw finisher 163.9 -> 151.6 ms.Tests:
mimalloc_restart_off,_on,_onceand the new_log(restart withANYPS5_LOG_FILEset) pass on Linux. Withmain's macOS-only restart,_on,_onceand_logfail. Without the stream hand-back,_logdies withSIGPIPE.ld.so, the restart test passes, and libkernel's host CPU line prints once with the restart. Alibs/path with a space prints the separator line and does not restart.release_packagepasses; without thepackage_release.pychange 14 of its cases fail and 1 errors.ctest -j8, 3,104 tests,ANYPS5_REQUIRE_VULKAN=1) passes apart fromagc_driver_tessellation(a crash inside RADV) andagc_idle_publish_wait, which fail onmainas well. The full suite again withAPS5_MIMALLOC=1set, so every test that loads libkernel restarts into mimalloc: the same two failures, nothing new.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)aps5-trace-029463ceb62c-636381.json.gz
aps5-trace-98446ecb20e5-636742.json.gz
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:00:51Z.
Review: COMMENTED
Reviewed — CI is red on the merged build, for reasons this PR does not touch
Relinked Linux games can now opt into mimalloc. The hosted relinker jobs fail on this head:
check_skips_ctestfails in the three relinker jobs I read (Ubuntu, macOS clang++ and Windows), andrelease_packagealso fails in the Windows relinker job. The macOS x86_64 relinker job also fails and was not read.check_skips.pyand its test are identical at the base and at this head, and this PR does not change them, so the failure comes from the base code. Therelease_packagefailure has no output in the log, so I could not attribute it. I did not read the mimalloc change itself in this pass.What I ran
15995c6640300c9abf19e1a4fc375e51853a8f3d; base7fad6837767a4f0cb1636ff835cd42522aae8fac. 13 files, includingcore/libs/prx/libkernel/System/src/MimallocRestart.cpp,MimallocMacOs.cpp,core/libs/tests/MimallocRestart.cpp, the root andcore/libs/CMake files, and the docs.check_skips_ctest(Test #63). The output showstest_notrun_without_ctest_skip_marker_is_rejectedfailing becausecheck_skips.skipsdoes not raise for anotruncase without a skip marker.clang++andx86_64) fail withcheck_skips_ctestonly. The Windows relinker job fails withcheck_skips_ctestandrelease_package(Test #112); its log has no assertion text forrelease_package.tools/check_skips.pyandtools/tests/test_check_skips_ctest.pyhave the same blob at the base and at this head, and the PR's changed files do not include them. The basecheck_skips.pycontains nonotrunhandling.Results
check_skips_ctest(hosted, three relinker jobs read)notruncase without a skip marker to raise; the basecheck_skips.pydoes notrelease_package(hosted, Windows relinker)Read-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed, no errors. Hosted:
gh api repos/boykopovar/AnyPS5/commits/15995c6640300c9abf19e1a4fc375e51853a8f3d/check-runs, and the relinker job logs (Ubuntu job 125008291567, macOS and Windows relinker jobs).Negative control
Not run here. A negative control needs a local build, and code from this head is not run here.
Findings
Blocking
check_skips_ctestfails in base code that this PR does not change, so the base needs a fix (or the test needs its expectation changed) before this PR can show green. Therelease_packagefailure on Windows is not explained.Non-blocking
Sources
check_skips_ctest)relinker (macos-latest, clang++)on 15995c6640300c9abf19e1a4fc375e51853a8f3d (check_skips_ctest)relinker (windows-latest, g++)on 15995c6640300c9abf19e1a4fc375e51853a8f3d (check_skips_ctestandrelease_package)github.com/boykopovar/AnyPS5@15995c6640/tools/tests/test_check_skips_ctest.pyNot verified
release_packagefailure.mainat7fad6837fails the same way (the base was not run here).To get this to a good state
check_skips_cteston the base first: eithercheck_skips.pylacks thenotrunrule the test expects, or the test is ahead of it. Then look at the Windowsrelease_packagelog.