fix(agc): read the process's private memory from task_info on macOS #9971

Merged
tkcm01 merged 1 commit from upstream-pr/9971 into main 2026-10-28 04:17:46 +00:00
tkcm01 commented 2026-10-23 01:16:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-23T01:16:46Z.


What

ReadProcessPrivateBytes (Execution/src/PerformanceOverlay.cpp) reads RssAnon and VmSwap from /proc/self/status on every host other than Windows. macOS has no /proc, so the overlay's RAM line stays empty and agc_performance_overlay_statistics fails with the process's private memory cannot be read. On macOS it now returns the task's phys_footprint from task_info(TASK_VM_INFO): the process's resident and compressed private memory, the figure Activity Monitor shows. Linux and Windows are unchanged.

@jotitadev measured that this makes the test pass on macOS (#7886's description) and left it out of #7886 because #7332 had it; #7332 is closed. The same change is part of #8658 (@iamthehimansh). Both are credited as co-authors; this splits it out as a small change, as for the other macOS pieces on #1. #8658 has since been closed in favour of topic PRs based on main, so no other open PR carries this change.

Tested

macOS 27.0.1, Apple M4 (10-core GPU), Apple clang 21, x86-64 build under Rosetta 2, MoltenVK 1.4.2 from the Vulkan SDK 1.4.363.0 (its universal loader, through VK_DRIVER_FILES). The libraries do not link on macOS from main alone, so the run is on mugurc's ci/macos-series-2 (53db0badb, main 3fd1cc393) with #7524, the code commits of #7937 and the libSceSsl change from #7332, as described on #1, plus my local macOS fixes listed there and #7886, so that agc_performance_overlay loads libvulkan.1.dylib and runs. ReadProcessPrivateBytes is the same in that tree as on main.

  • ctest -R '^agc_performance_overlay(_statistics)?$' -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:
    • without this change: both fail with the process's private memory cannot be read;
    • with it: both pass. agc_performance_overlay shows RAM: 0.1 GB; one read takes 1.3 us.
    • Neither log reports was not found but was requested by env var VK_INSTANCE_LAYERS. Both logs have the same two validation messages, VUID-VkDeviceCreateInfo-pProperties-04451 from #7886's test instance (it doesn't enable VK_KHR_portability_subset); this change adds none.
  • Full ctest -j4 on the same tree with Vulkan, with and without this change: 1648 tests each. Without it 60 failed, with it 59 in two runs; the two overlay tests are the only consistent difference. The others that differ are flaky under load on both builds and never reach this code (their recorders don't present): agc_driver_vertex_target_range_imported also fails without the change (6 of 100 serial runs), agc_driver_sgpr_pattern_fill_keys failed in a full run without it, and precise_wait is a known flake.
  • python3 tools/check_conventions.py --base upstream/main: passed. tools/pr_overlap.py lists only #8658 for this file, with this same change.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M4 (10-core GPU), MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.0.1
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4976363712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9971). Originally posted by [tkcm01](https://github.com/tkcm01) on 2026-10-23T01:16:46Z. --- ### What `ReadProcessPrivateBytes` (`Execution/src/PerformanceOverlay.cpp`) reads `RssAnon` and `VmSwap` from `/proc/self/status` on every host other than Windows. macOS has no `/proc`, so the overlay's RAM line stays empty and `agc_performance_overlay_statistics` fails with `the process's private memory cannot be read`. On macOS it now returns the task's `phys_footprint` from `task_info(TASK_VM_INFO)`: the process's resident and compressed private memory, the figure Activity Monitor shows. Linux and Windows are unchanged. @jotitadev measured that this makes the test pass on macOS (#7886's description) and left it out of #7886 because #7332 had it; #7332 is closed. The same change is part of #8658 (@iamthehimansh). Both are credited as co-authors; this splits it out as a small change, as for the other macOS pieces on #1. #8658 has since been closed in favour of topic PRs based on `main`, so no other open PR carries this change. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> macOS 27.0.1, Apple M4 (10-core GPU), Apple clang 21, x86-64 build under Rosetta 2, MoltenVK 1.4.2 from the Vulkan SDK 1.4.363.0 (its universal loader, through `VK_DRIVER_FILES`). The libraries do not link on macOS from `main` alone, so the run is on mugurc's `ci/macos-series-2` (53db0badb, `main` 3fd1cc393) with #7524, the code commits of #7937 and the libSceSsl change from #7332, as described on #1, plus my local macOS fixes listed there and #7886, so that `agc_performance_overlay` loads `libvulkan.1.dylib` and runs. `ReadProcessPrivateBytes` is the same in that tree as on `main`. - `ctest -R '^agc_performance_overlay(_statistics)?$' -V` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: - without this change: both fail with `the process's private memory cannot be read`; - with it: both pass. `agc_performance_overlay` shows `RAM: 0.1 GB`; one read takes 1.3 us. - Neither log reports `was not found but was requested by env var VK_INSTANCE_LAYERS`. Both logs have the same two validation messages, `VUID-VkDeviceCreateInfo-pProperties-04451` from #7886's test instance (it doesn't enable `VK_KHR_portability_subset`); this change adds none. - Full `ctest -j4` on the same tree with Vulkan, with and without this change: 1648 tests each. Without it 60 failed, with it 59 in two runs; the two overlay tests are the only consistent difference. The others that differ are flaky under load on both builds and never reach this code (their recorders don't present): `agc_driver_vertex_target_range_imported` also fails without the change (6 of 100 serial runs), `agc_driver_sgpr_pattern_fill_keys` failed in a full run without it, and `precise_wait` is a known flake. - `python3 tools/check_conventions.py --base upstream/main`: passed. `tools/pr_overlap.py` lists only #8658 for this file, with this same change. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: Apple M4 (10-core GPU), MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.0.1 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-23 02:55:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T02:55:52Z.

Review: COMMENTED


Second Mac, different chip and OS build from the M4 run in the description: red→green reproduces here, and phys_footprint matches what footprint(1) reports for a translated process.

Machine: Apple M2 Max (30-core GPU), 32 GB, macOS 27.2, Apple clang 21, x86-64 build under Rosetta 2, Release, BUILD_TESTING=ON.

Base/method: main doesn't link on macOS, so the tree is #8658 (feat/macos-port) @ c5fa39620a, full cmake --build -j4. #8658's ReadProcessPrivateBytes hunk is the same as this PR's at 8f2db802d3 except for the one-line code comment, so the green build is #8658 as is. The red build is the same tree with only the #elif defined(__APPLE__) branch of ReadProcessPrivateBytes removed, so macOS falls through to the /proc/self/status path as on main.

  • Red: agc_performance_overlay_statistics fails 3/3 with the process's private memory cannot be read.
  • Green: passes 3/3. costReport gives 1.3, 1.7 and 1.4 us per read, in line with the 1.3 us on the M4.

agc_performance_overlay_statistics doesn't create a Vulkan device, so this result doesn't depend on the GPU. I didn't run the Vulkan agc_performance_overlay test in this window.

Metric check. I wanted to confirm that phys_footprint is the right figure under Rosetta, so I wrote a small C probe (not part of the tree) with the same task_info(mach_task_self(), TASK_VM_INFO, ...) call. It reads the value before and after a 256 MiB malloc + memset, then I ran footprint <pid> against it while it slept:

build returned count delta after touching 256 MiB final phys_footprint footprint
-arch x86_64 (Rosetta) 93 (TASK_VM_INFO_COUNT) 256.5 MiB 271,455,696 B 64-bit (translated) Footprint: 259 MB
arm64 93 256.1 MiB 269,763,112 B Footprint: 257 MB

So the value is the one footprint reports, also for a translated process. The kernel fills the whole struct, which includes phys_footprint (it arrived in rev1, TASK_VM_INFO_REV1_COUNT = 38). The info{} zero-init plus the == 0 check would also catch an older kernel that returned a shorter struct, so the error handling looks complete to me.

Diff: <mach/mach.h> is under #elif defined(__APPLE__) next to the Windows includes, and the /proc path is still the #else, so Linux and Windows don't change.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623370278 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9971#pullrequestreview-5623370278). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-23T02:55:52Z. **Review:** COMMENTED --- Second Mac, different chip and OS build from the M4 run in the description: red→green reproduces here, and `phys_footprint` matches what `footprint(1)` reports for a translated process. **Machine:** Apple M2 Max (30-core GPU), 32 GB, macOS 27.2, Apple clang 21, x86-64 build under Rosetta 2, Release, `BUILD_TESTING=ON`. **Base/method:** `main` doesn't link on macOS, so the tree is #8658 (`feat/macos-port`) @ `c5fa39620a`, full `cmake --build -j4`. #8658's `ReadProcessPrivateBytes` hunk is the same as this PR's at `8f2db802d3` except for the one-line code comment, so the green build is #8658 as is. The red build is the same tree with only the `#elif defined(__APPLE__)` branch of `ReadProcessPrivateBytes` removed, so macOS falls through to the `/proc/self/status` path as on `main`. - **Red:** `agc_performance_overlay_statistics` fails 3/3 with `the process's private memory cannot be read`. - **Green:** passes 3/3. `costReport` gives 1.3, 1.7 and 1.4 us per read, in line with the 1.3 us on the M4. `agc_performance_overlay_statistics` doesn't create a Vulkan device, so this result doesn't depend on the GPU. I didn't run the Vulkan `agc_performance_overlay` test in this window. **Metric check.** I wanted to confirm that `phys_footprint` is the right figure under Rosetta, so I wrote a small C probe (not part of the tree) with the same `task_info(mach_task_self(), TASK_VM_INFO, ...)` call. It reads the value before and after a 256 MiB `malloc` + `memset`, then I ran `footprint <pid>` against it while it slept: | build | returned `count` | delta after touching 256 MiB | final `phys_footprint` | `footprint` | |---|---|---|---|---| | `-arch x86_64` (Rosetta) | 93 (`TASK_VM_INFO_COUNT`) | 256.5 MiB | 271,455,696 B | `64-bit (translated) Footprint: 259 MB` | | arm64 | 93 | 256.1 MiB | 269,763,112 B | `Footprint: 257 MB` | So the value is the one `footprint` reports, also for a translated process. The kernel fills the whole struct, which includes `phys_footprint` (it arrived in rev1, `TASK_VM_INFO_REV1_COUNT` = 38). The `info{}` zero-init plus the `== 0` check would also catch an older kernel that returned a shorter struct, so the error handling looks complete to me. Diff: `<mach/mach.h>` is under `#elif defined(__APPLE__)` next to the Windows includes, and the `/proc` path is still the `#else`, so Linux and Windows don't change. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-23 05:31:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:31:30Z.

Review: DISMISSED


The ReadProcessPrivateBytes implementation in this PR is also present in the open macOS-port PR #8658 (same TASK_VM_INFO/phys_footprint hunk; #8658 currently remains open). Your description explains this split and preserves credit, but the two PRs do not record which copy should land first or how the other branch will drop its duplicate. CONTRIBUTING asks authors to agree on shared work and declare dependencies where needed. Please coordinate with #8658’s author/maintainers and record the integration order: either make #9971 the standalone change and remove the duplicate from #8658 when it rebases, or keep this hunk in #8658 and make the split PR dependent on that work. I compared the exact hunk: Linux/Windows paths remain unchanged, current-main sync is clean, and local check_main_sync, conventions and git diff --check pass (the branch is 136 commits behind, but this file has no intervening main edits). The reported two-platform macOS red/green evidence is relevant; this host cannot independently run macOS tests. This request is for avoiding duplicate implementation and clarifying integration, not queue size.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624307204 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9971#pullrequestreview-5624307204). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:31:30Z. **Review:** DISMISSED --- The `ReadProcessPrivateBytes` implementation in this PR is also present in the open macOS-port PR #8658 (same `TASK_VM_INFO`/`phys_footprint` hunk; #8658 currently remains open). Your description explains this split and preserves credit, but the two PRs do not record which copy should land first or how the other branch will drop its duplicate. CONTRIBUTING asks authors to agree on shared work and declare dependencies where needed. Please coordinate with #8658’s author/maintainers and record the integration order: either make #9971 the standalone change and remove the duplicate from #8658 when it rebases, or keep this hunk in #8658 and make the split PR dependent on that work. I compared the exact hunk: Linux/Windows paths remain unchanged, current-main sync is clean, and local `check_main_sync`, conventions and `git diff --check` pass (the branch is 136 commits behind, but this file has no intervening main edits). The reported two-platform macOS red/green evidence is relevant; this host cannot independently run macOS tests. This request is for avoiding duplicate implementation and clarifying integration, not queue size.
imellag commented 2026-10-24 19:48:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-24T19:48:39Z.

Review: APPROVED


Tested head 8f2db802d3 on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2, with MoltenVK 1.4.2 from the Vulkan SDK 1.4.363.0.

libSceAgcDriver doesn't link on main on macOS yet, so I tested on main 3fcb5e4d76 plus the open macOS build PRs and the AGC parts of mugurc's series. On that tree, with ANYPS5_REQUIRE_VULKAN=1:

  • Without this PR, agc_performance_overlay_statistics fails with the process's private memory cannot be read.
  • With it, the test passes 3 runs out of 3.
  • agc_performance_overlay and agc_performance_overlay_device_selection fail with and without it: they load libvulkan.so.1 themselves (AGC graphics: cannot load Vulkan), which is unrelated to this change.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639696770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9971#pullrequestreview-5639696770). Originally posted by [imellag](https://github.com/imellag) on 2026-10-24T19:48:39Z. **Review:** APPROVED --- Tested head `8f2db802d3` on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2, with MoltenVK 1.4.2 from the Vulkan SDK 1.4.363.0. `libSceAgcDriver` doesn't link on `main` on macOS yet, so I tested on `main` `3fcb5e4d76` plus the open macOS build PRs and the AGC parts of mugurc's series. On that tree, with `ANYPS5_REQUIRE_VULKAN=1`: - **Without this PR**, `agc_performance_overlay_statistics` fails with `the process's private memory cannot be read`. - **With it**, the test passes 3 runs out of 3. - `agc_performance_overlay` and `agc_performance_overlay_device_selection` fail with and without it: they load `libvulkan.so.1` themselves (`AGC graphics: cannot load Vulkan`), which is unrelated to this change. AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9971
No description provided.