fix(memory): preserve process-owned services during exit #5073
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5073"
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 krishalivaibhav on 2026-10-13T10:44:01Z.
What
Keep direct-memory services available during native process exit: the physical allocation pool, backing/page/mapping metadata, protection and reservation metadata, and their dependent guest arena, allocation registry, write-watch and Windows mapping owner. Explicit frees and unmaps keep their existing behavior; OS process termination reclaims outstanding resources.
Don’t Starve Together (PPSA02070) exposed a guest allocation using an invalid host map node while another thread was executing native static destructors. Retaining only the physical pool is insufficient: its backing registry is destroyed separately. The regression registers a native exit probe before loading the real runtime libraries, confirms fixture finalization occurred, and exercises the services afterward.
This is a service-lifetime correction, not a complete guest-thread quiescence design or a performance change. No immediate-exit replacement or callback bypass is introduced. #4994 handles independent path-service lifetimes; this code/test does not depend on it.
Tested
Current branch head:
d50eed2df30ab58e6abf9dce2147bee022dadf56, based ond4efd33978abb340c430fe09415ee32250d535e0. Adopted blawesom’s exact handoff after parent and independent review: author preserved, range comparison confirms the same patch on the newer base. blawesom reports a Linux Release build, passing conventions, and 1099/1100 full-suite tests on CachyOS / GCC 16.2.1 / AMD RX 9070 XT RADV; the reported remainingagc_driver_tessellationfailure is also on main (#4727). This is contributor-reported validation, not an independently reproduced full suite or formal approval. Earlier positive/negative controls and Windows tests below remain evidence for their explicitly stated older heads.Independent contributor simonbbby retested exact rebased head
3c0fa76211cc3c4f7e65d9454f00b01d22c8fc47: all four focused Linux tests passed three runs; reverting the six production files made the native-exit fixture fail with status 139; restoring them passed again. This is an independent reported focused Linux result, not full-suite or Windows exit-lifetime verification.Apple M2, macOS 27.2, Release x86-64 under Rosetta, modified local runtime: original owners fail at the physical-pool mutex; pool-only retention fails at the backing-map mutex. Complete candidate passes three repeated native-exit probes.
Probe covers allocation queries, backing mapping, allocation leases, watched writes, protection, explicit unmap/free and metadata removal, zeroed physical reuse, and reservation cleanup. Earlier negative controls fail before subsequently strengthened cleanup assertions.
Existing memory, five write-watch checks and guest/host exit ordering: 7/7 pass. Ordinary host exit callbacks remain enabled.
Two bounded local title probes requested normal exit at 30 seconds and exited with status 0 at 32.52/32.69 seconds, without timeout termination. This is not stable-session or universal shutdown evidence.
This branch is based on main
c7632f036f68f71a5e514f5b20f6df68a9062ada. Clean-port test sources compile against its headers; conventions and whitespace pass. Parent and a low-reasoning independent agent reviewed it.Independent contributor simonbbby tested the previous exact head
f67872b6eon Linux: four focused tests passed three times each, a production-only parent-source negative control failed during native exit, and restoring the candidate passed again. This is targeted contributor evidence, not full CI, Windows validation, or a title test. Their Linux write-watch attempt did not compile and is not counted as passing.Rebased onto main
dacd78525e537a779682032c0ace7f7af120af05; current head3c0fa76211cc3c4f7e65d9454f00b01d22c8fc47. Main now uses the physical-span reverse map on all platforms. The retained owner preserves that change and its mapping algorithms. Parent and low-reasoning independent review pass; conventions and whitespace pass. The additional hosted evidence below reruns focused tests on this rebased head. Clean Mac compilation of DirectMemory is blocked by its existing Windows-header fallback; no new clean-Mac pass is claimed.Windows normal memory and write-watch checks now pass on the exact rebased head, as recorded below. The native-exit fixture remains Unix-only; Windows post-destruction access is not exercised. Hosted full Linux/Windows jobs were skipped, not passed.
FPS improvement is not claimed. AGC callback/cache lifetimes and broader guest-thread shutdown coordination remain separate.
Additional clean-head hosted evidence
Exact rebased head
3c0fa76211cc3c4f7e65d9454f00b01d22c8fc47:guest_memory_lifetime,guest_memory,guest_exit_order, andapplication_heap_exit_ordereach passed three consecutive runs. Restoring only the six production files from the parent while retaining the new fixture/CMake registration caused the lifetime child to fail during native exit (status 139). Restoring the candidate and rebuilding passed all four tests three times again. Skips were rejected.guest_memorybuilt, andguest_memorypassed three consecutive runs. The overall job failed afterward because the separately selected standaloneWriteWatch.cppis explicitly a macOS backend and includesmach/mach.h; this does not represent a passing write-watch check or a production memory-test failure.windows_write_watch_teststarget and reject skipped/missing test cases. Corrected Windows run passed: the realguest_memoryand registeredwindows_write_watchtests each passed three consecutive runs on exact head3c0fa7621, with exactly two executed test cases and no skips. This remains normal Windows behavior coverage, not native-exit lifetime coverage. No full-suite or game-stability claim is made.Checklist
Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-13T10:45:27Z.
Could a maintainer dispatch
build.ymlfrommainwithpr=5073for the full Linux and Windows builds/tests? My earlier dispatch request was rejected because repository admin rights are required.The PR distinguishes modified local Mac runtime validation from this clean-main port. Its additional retained Linux physical-span map needs Linux validation; Windows ownership changes have not been executed locally. Please keep it draft until that evidence is available.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T11:13:14Z.
Review note (static, nothing built here): the description says the Windows ownership changes (
WindowsMappings::Get, the arena, the allocation registry and the write-watch owner now leaked on purpose so they outlive native static destructors) were inspected but not executed, and the newguest_memory_lifetimetest is registered underif(NOT WIN32)incore/libs/prx/libkernel/CMakeLists.txt(it usesdlopen). So nothing in this PR is exercised on Windows. We can build the branch on Windows 10 (MinGW GCC 15.2) and run the existing memory and write-watch tests (guest_memory,write_watch*) against it; please say if that would help. A Windows-side test for the exit-time lifetime (for example aFreeLibrary/atexit-ordered probe) would be needed to cover theWindowsMappingschange itself.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T11:30:22Z.
Independent Linux verification of exact PR head
f67872b6eaf3de0ae6202c1e910ed5cc5e8a346a(Ubuntu 24.04 / Linux 7.0, GCC 13.3, Ninja Release,BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON):guest_memory_lifetime_tests,guest_memory_tests,guest_exit_order_testsandapplication_heap_tests, including the real libc/libkernel and lifetime fixture module.guest_memory_lifetime,guest_memory,guest_exit_orderandapplication_heap_exit_orderall pass three consecutive runs each. The lifetime probe printsallocation, backing, mapping and explicit free survived native exiton every run.c7632f036f68f71a5e514f5b20f6df68a9062ada, keeping the PR's new tests/CMake registration. Rebuilt libc/libkernel and the fixture module.guest_memory_lifetimefails during native exit (child failed during native exit (status=139)), rather than a load/link failure.This is targeted Linux build/runtime evidence for the clean port, not a full project/CI run, Windows verification, or a title shutdown test. I also attempted the standalone
core/libs/tests/write_watchsuite, but its unchangedWriteWatch.cppincludesmach/mach.hfor non-Windows hosts and does not compile on Linux; those write-watch cases are not counted as passing.Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-13T19:31:43Z.
Thank you for the independent Linux positive/negative controls and the Windows coverage review. I have added both reports and their limitations to the description.
The PR is rebased onto main
dacd78525e537a779682032c0ace7f7af120af05; new exact head:3c0fa7621. Main now maintains its physical-span reverse map across platforms, so the retained owner preserves that newer behavior and the mapping algorithms. The conflict resolution passed parent and independent static review plus conventions; the older-head runtime report is not presented as verification of this new head.A Windows build and the existing
guest_memory/write_watch*tests would help, using this new head and recording the exact merged SHA if main is merged locally. They will not prove the Windows exit-lifetime change: the new lifetime fixture remains Unix-only. A Windows LoadLibrary/native-exit ordered regression is still a separate evidence gap. I am keeping this draft until that coverage and rebased-head runtime verification are resolved.AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-13T20:23:36Z.
Retested exact rebased head
3c0fa76211cc3c4f7e65d9454f00b01d22c8fc47on Linux, including the newer physical-span owner. This is fresh runtime evidence for this head, separate from my earlierf67872b6ereport.BUILD_TESTING=ON, SPIRV-Tools ON. Rebuilt the four test targets and real libc/libkernel/module dependencies.guest_memory_lifetime,guest_memory,guest_exit_orderandapplication_heap_exit_ordereach pass three consecutive runs. The lifetime fixture reaches its success message after native static destruction.dacd78525e537a779682032c0ace7f7af120af05, retaining this head's tests and CMake registration. Rebuilt successfully;guest_memory_lifetimefails during native exit (child failed during native exit (status=139)), not at load/link time.This verifies the focused Linux rebase path. It is not a full build/suite, title test, Windows run or Windows exit-lifetime regression; those limitations remain unchanged.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:19:53Z.
Rebase handoff — rebased onto current
main(applies cleanly now), 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
d50eed2df.Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-14T05:52:25Z.
Thank you. I adopted your exact tested head
d50eed2df30ab58e6abf9dce2147bee022dadf56, preserving authorship, and added your Linux report and the known tessellation failure limitation to the description. Parent and independent review confirmed the patch is unchanged on the newer base. Since the old head was not an ancestor of this rebase, I retained a backup and moved the branch to the exact tested commit rather than creating an untested merge. Earlier Windows and negative-control evidence is still labeled with its original heads.AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:38:21Z.
Checked on Linux (PR merged onto current main): builds, libs/libc/libkernel ctest scope green except
guest_current_cpu, which aborted only under parallel load and passes alone (unrelated code).guest_memory_lifetimepasses and fails with the six production files reverted. Windows/exit-lifetime coverage goes through the full Build dispatch; merging once it is green.