Repository navigation
feat(memory): back GPU-visible guest memory with shareable memory behind a flag - #580
RINNECODER wants to merge 7 commits into
Conversation
|
@codex review |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57b38032e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| std::erase_if(shared.regions, [address, end](const Region& region) { | ||
| return region.address < end && address < region.address + region.bytes; | ||
| }); |
There was a problem hiding this comment.
Preserve unaffected registry fragments on overlap
When a registered mapping is only partially remapped or unmapped, this erases the entire overlapping Region; for example, replacing 16 KiB inside a 64 KiB arena allocation removes the manifest entry for the untouched 48 KiB even though those pages remain GPU-visible. Subsequent publication therefore leaves the native process unable to map valid surrounding memory, so registration and unregistration need to retain the non-overlapping fragments with adjusted object offsets.
Useful? React with 👍 / 👎.
| writeManifest(); | ||
| return true; |
There was a problem hiding this comment.
Report manifest write failures from publish
When the configured manifest directory is missing, unwritable, full, or the final rename fails, writeManifest() silently returns without publishing but this function still reports success. Callers such as the proof writer consequently proceed as though the native process received a current manifest; make the write/flush/close/rename path return a status and propagate it here.
Useful? React with 👍 / 👎.
| if (shared) GpuSharedMemory::GpuSharedMemoryAdoptObject_nid_postfix(name.c_str()); | ||
| const int created = shm_open(name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); | ||
| if (created < 0) throw std::system_error(errno, std::generic_category(), "create direct memory backing"); |
There was a problem hiding this comment.
Remove stale direct-memory objects before exclusive creation
With shared memory enabled, an abnormal engine termination bypasses the atexit unlink and leaves /aps5-dmem-<pid> named indefinitely. Once macOS reuses that PID, this O_EXCL open fails with EEXIST, causing direct-memory initialization for the new run to throw; clear the per-PID stale name before creation as the new arena-object creation path already does.
Useful? React with 👍 / 👎.
|
P1 and both P2s fixed in df77780: partial remap/unmap now keeps the surrounding fragments with adjusted object offsets ( |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df77780d4c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| #else | ||
| if (::mmap(reinterpret_cast<void*>(address), bytes, protection, MAP_SHARED | MAP_FIXED, file, static_cast<off_t>(fileOffset + offset)) == MAP_FAILED) throw std::system_error(errno, std::generic_category(), "map direct memory backing"); | ||
| #if defined(__APPLE__) | ||
| GpuSharedMemory::GpuSharedMemoryRegister_nid_postfix(address, bytes, PhysicalObjectName().c_str(), fileOffset + offset); |
There was a problem hiding this comment.
Exclude out-of-arena mappings from the manifest
When shared memory is enabled and a fixed direct-memory request lies outside the raw application area, DarwinRelocateFixed and MapPlaced intentionally leave it at its host address, but this unconditional registration still publishes that address. A native consumer maps manifest regions with MAP_FIXED, so an out-of-arena mapping—such as one overlapping the relinked image range—can replace the native process's own mappings and crash it; only mappings placed in the shared/slid address space should be registered.
Useful? React with 👍 / 👎.
|
@codex review |
|
P1 fixed in ce01d40: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce01d408a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (fixedAnonymous && !GuestArena::GuestArenaContains_nid_postfix(address, rounded)) { | ||
| auto slid = start; | ||
| if (!GuestArena::GuestArenaSlideAddress_nid_postfix(&slid, rounded)) return failed(GuestInvalid); | ||
| start = slid; | ||
| address = reinterpret_cast<void*>(slid); |
There was a problem hiding this comment.
Slide fixed anonymous mappings only once
When mmap_nid_postfix receives a fixed anonymous raw address below 496 GiB, this block adds the 512 GiB slide and then passes the resulting address to DoMapAnon; on Darwin, DoMapAnon calls DarwinRelocateFixed, whose range check still treats that once-slid address as belonging to the raw application area and adds the slide again. The mapping is consequently returned 512 GiB above the compiler/runtime address, and ReleaseFlexibleMappingRange also releases the once-slid range rather than the actual mapping. Let the lower mapping layer perform the slide, or make it recognize addresses already inside the slid arena.
Useful? React with 👍 / 👎.
| } | ||
| state.applied = ranges; | ||
| state.configured = true; | ||
| GpuSharedMemory::GpuSharedMemoryPublish_nid_postfix(); |
There was a problem hiding this comment.
Publish the manifest after later range changes
This is the only production call to GpuSharedMemoryPublish_nid_postfix, so it publishes only during initial driver configuration. When GPU allocations change afterward, DirectDriver() takes the ReplaceBorrowedRanges branch at lines 388–390 without rewriting the manifest; the registry is updated by the mapping code, but the native process keeps the initial snapshot and cannot map newly allocated or remapped GPU memory. Republish when the applied range set changes, not only on first configuration.
Useful? React with 👍 / 👎.
|
Both P1s fixed in 8f690ec: (1) |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f690ec907
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| } | ||
| #endif | ||
| return PlaceAt(pointer, bytes, protection); |
There was a problem hiding this comment.
Fail instead of falling back to private arena memory
When ANYPS5_GPU_SHARED_MEMORY=1 and either the arena shm object cannot be created or its MAP_SHARED mapping fails, this fallback silently commits the range as private anonymous memory. The guest allocation is still treated as GPU-visible, but no registry entry gives the native process access to its contents, so submissions using the range can read stale or unmapped data; propagate the shared-backing failure rather than continuing with PlaceAt.
Useful? React with 👍 / 👎.
| std::fprintf(file, "region 0x%llx 0x%llx %s 0x%llx\n", static_cast<unsigned long long>(region.address), | ||
| static_cast<unsigned long long>(region.bytes), region.object.c_str(), static_cast<unsigned long long>(region.offset)); | ||
| } | ||
| if (std::fflush(file) != 0 || std::fclose(file) != 0) { |
There was a problem hiding this comment.
Close the manifest file after a flush failure
When fflush fails, such as after the manifest filesystem becomes full, the short-circuiting || skips fclose(file). Every subsequent failed publication can therefore leak another descriptor until the process reaches its descriptor limit, at which point unrelated file and shared-memory operations also fail; call fclose regardless of the flush result and combine the recorded statuses afterward.
Useful? React with 👍 / 👎.
|
In 9f0d0c0: the arena commit path now throws when the shared object cannot be created or its |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27c9284441
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| state.applied = ranges; | ||
| state.configured = true; | ||
| GpuSharedMemory::GpuSharedMemoryPublish_nid_postfix(); |
There was a problem hiding this comment.
Move the AGC driver memory into shared space
With ANYPS5_GPU_SHARED_MEMORY=1, this publishes only ranges registered with GpuSharedMemory, but MapDriverMemory() in Execution/src/Driver/Lifecycle.cpp still creates its GPU-visible 2 MiB block as a private anonymous mapping at raw address 0xfe0000000 and merely adds it to GuestAllocations. Consequently the native process receives borrowed ranges that reference the FS table and routine block but no manifest entry or shared object from which to map them; this block must also be slid and shared, including its embedded fixed addresses, before the manifest is published.
Useful? React with 👍 / 👎.
|
In c4329aa: the driver's own 2 MiB GPU-visible FS-table block now slides with the arena and is committed from the arena's shared object, with the routine-table, routine and FS-slot addresses all derived from the mapped base, so the native process has a manifest entry and a shared object for it. The other two findings on 27c9284 were already fixed in 8f690ec and 27c9284 (the |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4329aab87
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| void* mapped = nullptr; | ||
| #if defined(__APPLE__) | ||
| if (GpuSharedMemory::GpuSharedMemoryEnabled_nid_postfix() && GuestArena::GuestArenaAvailable_nid_postfix()) { | ||
| GuestArena::GuestArenaCommit_nid_postfix(reinterpret_cast<void*>(base), DriverMemoryBytes, 0x04, DriverMemoryBytes); |
There was a problem hiding this comment.
Move driver memory outside the reserved arena interval
When ANYPS5_GPU_SHARED_MEMORY=1, this slides DriverMemoryAddress from 0xfe0000000 to 0x8fe0000000, but the raw address lies inside [GuestLayout::SystemReservedStart, GuestLayout::SystemReservedEnd). SeedDarwinUsedRanges() has already inserted that entire slid interval into the arena's _used map, so this commit calls MarkUsedForCommit() and throws an "overlaps a used range" exception whenever the AGC driver is initialized. Fresh evidence after the earlier driver-memory finding is this new shared commit path, which now prevents initialization rather than leaving the block private; place the internal block in an allocatable arena range or explicitly carve it out of the reservation.
Useful? React with 👍 / 👎.
| } | ||
| state.applied = ranges; | ||
| state.configured = true; | ||
| GpuSharedMemory::GpuSharedMemoryPublish_nid_postfix(); |
There was a problem hiding this comment.
Handle failed initial manifest publication
When shared memory is enabled but the configured manifest path is temporarily missing, unwritable, or full, GpuSharedMemoryPublish_nid_postfix() now correctly returns false, but this call discards it after marking the driver configured. If the borrowed ranges remain unchanged, DirectDriver() never calls publish again, so the native process receives no initial mapping manifest even after the filesystem problem is fixed; propagate the failure or leave publication pending for retry. The later replacement call at line 391 has the same unchecked failure behavior.
Useful? React with 👍 / 👎.
|
In 38cbe1a: the driver block is now allocated from the slid arena rather than slid by 512 GiB — its raw address sits inside the PS5 system reservation, whose slid image |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Correction: the commit in my previous comment is |
4daa44c to
f77c145
Compare
|
Rebased onto current |
…ind a flag P0 of the GPU-process plan: a native arm64 process has to be able to map the guest memory the AGC driver reads and writes at the addresses the x86_64 engine already uses, and macOS refuses fixed mappings in [64 GiB, 512 GiB). ANYPS5_GPU_SHARED_MEMORY=1 slides the Darwin guest arena by 512 GiB (the GuestLayout slide the native AOT lane uses), so the application area is at [520 GiB, 1520 GiB), moves a fixed guest request in the raw application area by the same amount, and backs every arena commit with one sparse shm object covering the arena. Direct memory keeps its shm object open under the flag, and the driver's command staging comes from the arena, so the staged words are shared too. GpuSharedMemory records each range with the object and offset backing it and writes them to ANYPS5_GPU_SHARED_MEMORY_MANIFEST. The flag defaults off and nothing changes without it: the slide is zero, the Darwin arena stays unavailable and its commits stay anonymous. Tested: core/libs/tests/gpu_shared_memory runs the engine's own memory code as an x86_64 process and a small arm64 program that maps the published objects at the registered addresses, reads the bytes the x86_64 process wrote and writes them back. Rosetta ctest 26/26, Metal ctest 63/63, check_conventions clean.
Review follow-ups on the shared-memory registry: - a partial remap or unmap now keeps the parts of a registered range around it, with the object offset advanced by the bytes kept, instead of dropping the whole range (a 16 KiB remap inside a 64 KiB arena allocation used to lose the manifest entry for the other 48 KiB); - GpuSharedMemoryPublish reports a manifest write, flush, close or rename failure instead of reporting success; - the direct memory object is unlinked before its exclusive create, so a name left behind by an earlier run that died before its exit handler does not make the next run with the same pid throw. Tested: ctest gpu_shared_memory_registry checks both fragment cases and the unwritable manifest path; Rosetta ctest 27/27, Metal ctest 63/63, check_conventions clean.
A fixed direct-memory request outside the raw PS5 application area keeps its host address, so publishing it would tell a native process to map that address with MAP_FIXED, over its own mappings (the relinked image range, for example). Register only ranges the guest arena contains, which is exactly the slid address space the server can map. Tested: the proof writer maps direct memory at 6 GiB, below the application area, and asserts the manifest does not mention it; the check fails without the guard. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.
…hanges Two review follow-ups: - mmap's fixed anonymous path slid the address and then let DoMapAnon slide it again, so a raw address below 496 GiB was mapped 512 GiB too high and the flexible-memory release used the wrong address. The validation now only refuses a fixed request no slide can move into the arena, the mapping layer does the single slide, and the release uses the returned address; - the manifest was published only when the driver was first configured, so a later GPU allocation or remap left the native process with the initial snapshot. It is now published whenever the applied range set changes, and only when the registry version changed (0.19 ms for 250 regions, so an unchanged set costs nothing). Tested: the proof writer maps a fixed anonymous range at 128 GiB and checks it comes back exactly 512 GiB higher; the registry test covers publishing after a change, the no-op publish, and the retry after a failed publish. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.
…fest file Review follow-ups: - the arena commit path fell back to private anonymous memory when the shared object could not be created or its MAP_SHARED mapping failed, which leaves a GPU-visible range the native process cannot map and would read as stale; it now throws instead; - a failed fflush no longer short-circuits past fclose, so repeated failed publications cannot leak descriptors. Tested: Rosetta ctest 27/27 (including the shared-memory registry and the cross-architecture proof), Metal ctest 63/63, check_conventions clean.
The driver's own 2 MiB GPU-visible block (the FS table and its routine record block) was a private anonymous mapping at a fixed raw address and only appeared in the guest allocations, so a native process got borrowed ranges for it with no shared object to map. Under ANYPS5_GPU_SHARED_MEMORY it now moves with the arena slide and is committed from the arena's shared object, and every address written into the block (the routine table and routine entries, and the FS table slot) follows the mapped base. Tested: Rosetta ctest 27/27, Metal ctest 63/63 (including anyps5_metal_agc_fs_table_calls, which maps its own block at the raw address), check_conventions clean. The flag-on replay gate could not be repeated: Steam is running.
The driver block's raw address is inside the PS5 system reservation, whose slid image ([544 GiB, 576 GiB)) the arena reserves too, so sliding it put it inside a reserved interval and the commit threw. Under the flag it is now allocated from the slid arena, which cannot hand out the reserved interval, and the manifest publication failures at driver configuration and range replacement are reported instead of being dropped. Tested: Rosetta ctest 27/27, Metal ctest 63/63, check_conventions clean.
f77c145 to
8ec2c32
Compare
|
Rebased onto current Gameplay gate with Frame rate on the map: 489 presented frames over the gate's 109.9 s = 4.45 fps average (≈225 ms/frame), steady across 30 s slices (4.34 / 4.01 / 4.80 fps), computed from the map.png: Rosetta ctest 26/27 and Metal ctest 63/63 on this head; |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8ec2c32e14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (GpuSharedMemory::GpuSharedMemoryEnabled_nid_postfix() && GuestArena::GuestArenaAvailable_nid_postfix()) { | ||
| base = reinterpret_cast<std::uint64_t>(GuestArena::GuestArenaAllocate_nid_postfix(DriverMemoryBytes, 0x1000)); | ||
| GuestArena::GuestArenaCommit_nid_postfix(reinterpret_cast<void*>(base), DriverMemoryBytes, 0x04, DriverMemoryBytes); |
There was a problem hiding this comment.
Keep the FS table at its fixed guest address
When ANYPS5_GPU_SHARED_MEMORY=1, allocating this block at the arena's next free address moves the FS table away from 0xfe0040000, but table-call shaders still embed that address unchanged: ReadTableCallees() dereferences the shader's constant pointer, and ComputeFsTableCalls.cpp explicitly verifies the table at 0xfe0040000. Such shaders will therefore fault while reading the descriptor instead of reaching the initialized table. Back the fixed address with shareable memory, or add a consistent relocation for every reference to it, rather than assigning an arbitrary arena address.
Useful? React with 👍 / 👎.
What
P0 of the GPU-process plan (
anyps5-ops/notes/perf/gpu-process-study-2026-10-14/MEMO.md): a nativearm64 process has to be able to map the guest memory the AGC driver reads and writes at the addresses
the x86_64 engine already uses. macOS refuses fixed mappings in
[64 GiB, 512 GiB), and a probe onthis Mac shows a native arm64 process refuses
6–256 GiBoutright, so the guest arena's raw[8, 1008) GiBcannot be mapped natively at all.Everything is behind
ANYPS5_GPU_SHARED_MEMORY=1and the default path is unchanged.GuestLayout.hpp(the slide the native AOT lane defined, byte-identical so the two tracks merge):with the flag on, the Darwin guest arena takes the 512 GiB slide, so the application area is
[520 GiB, 1520 GiB).addr, like the pre-existing 448 GiB hole relocation, so guest and server agree on every addressand the driver's borrowed ranges stay identity.
/aps5-gpu-<pid>-arena, 1000 GiB, created on the firstcommit), so the libc GPU heap, GPU-flagged anonymous maps and the driver's command staging are all
shareable through the one
GuestArenaCommitpath. Direct memory keeps itsshm_openobject openunder the flag instead of unlinking it immediately.
GpuSharedMemoryrecords each range with the object and offset backing it and writes them toANYPS5_GPU_SHARED_MEMORY_MANIFEST.Tested
core/libs/tests/gpu_shared_memory(ctestgpu_shared_memory_proof): an x86_64 process runs theengine's own memory code with the flag on and a native arm64 program opens the published objects,
maps each range at the recorded address, checks the bytes the x86_64 process wrote and writes a
counter-pattern the x86_64 process re-checks. Passes.
check_conventions.py --base origin/mainclean.--expect-hash 51a268f2e73efb9cmatches both;agc-live-map 79 px / 75 px and agc-menu 91 px / 61 px against
replay-ref-v3.png(limit 200).main-
808f8f3ecboot regression (Thread destructor callback is already registered, PR fix(relinker): stop running a guest module's preinit array from the startup stubs #579'sroot cause), before any GPU or arena work; Steam came up during the run and the rules forbid a game
run while it is running, so the control and the bootfix-assisted rerun did not happen.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)