perf(agc): cache page permissions within registered allocations #1330

Closed
TibixDev wants to merge 2 commits from upstream-pr/1330 into main
TibixDev commented 2026-10-07 23:41:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-07T23:41:15Z.


Status after review

Current page caches overlap the original motivation.

Current GuestMemory.cpp already caches arena page states, additionally caches the Windows image extent, and registers ForgetPages with GuestAllocationsSetInvalidator_nid_postfix. This changes the baseline substantially beyond the original #157 comparison. The new Skyrim loading sample on main + experimental NGS reports zero OS query calls while servicing tens of thousands of verifies; that is a limited workload observation, not a universal conclusion.

There is no new evidence that an extra 64-entry registered-range cache pays for its previously measured 7–20% invalidation/large-set/unregistered regressions. Nor is there a demonstrated need for another disable knob/export. A future version must audit permission changes outside Mutation against the existing invalidation path. #157 is merged; the carried copy is historical and is not an open dependency. No new code push.

What

Cache Linux page permissions only inside registered allocation bounds. Keep at most 64 positive results per thread. Mapping generations invalidate them; a busy registry skips the cache fill. Unregistered host memory still uses a kernel query.

Tested

Earlier branch-specific tests and measurements remain in the discussion. They have not been rerun on a redesigned current-main version of this PR. The review audit and shared NGS-assisted title exploration do not establish that this head is merge-ready. No full Linux/Windows platform CI was dispatched in this pass.

Checklist

  • Current-main implementation and outstanding review requirements complete.
  • Isolated title benefit / reference validation established where required.
  • Depends on: none; the included #157 copy must be removed in any redesign.
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4779806788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-07T23:41:15Z. --- ### Status after review **Current page caches overlap the original motivation.** Current `GuestMemory.cpp` already caches arena page states, additionally caches the Windows image extent, and registers `ForgetPages` with `GuestAllocationsSetInvalidator_nid_postfix`. This changes the baseline substantially beyond the original #157 comparison. The new Skyrim loading sample on main + experimental NGS reports zero OS query calls while servicing tens of thousands of verifies; that is a limited workload observation, not a universal conclusion. There is no new evidence that an extra 64-entry registered-range cache pays for its previously measured 7–20% invalidation/large-set/unregistered regressions. Nor is there a demonstrated need for another disable knob/export. A future version must audit permission changes outside `Mutation` against the existing invalidation path. #157 is merged; the carried copy is historical and is not an open dependency. No new code push. ### What Cache Linux page permissions only inside registered allocation bounds. Keep at most 64 positive results per thread. Mapping generations invalidate them; a busy registry skips the cache fill. Unregistered host memory still uses a kernel query. ### Tested Earlier branch-specific tests and measurements remain in the discussion. They have not been rerun on a redesigned current-main version of this PR. The review audit and shared NGS-assisted title exploration do not establish that this head is merge-ready. No full Linux/Windows platform CI was dispatched in this pass. ### Checklist - [ ] Current-main implementation and outstanding review requirements complete. - [ ] Isolated title benefit / reference validation established where required. - [x] Depends on: none; the included #157 copy must be removed in any redesign. - [x] AI-assisted: yes.
TibixDev commented 2026-10-08 06:07:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T06:07:24Z.


Rebased on e9846679. The #157 prerequisite retains Pacuka's authorship.

Measured upstream plus #157 (5b65345a) against that same baseline plus this PR's final commit (ebfe2b70). Thus both sides use PROCMAP_QUERY.

Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3. Six processes per variant, ABBA × 3. Each process has one warmup and nine batches of 4,096 calls to production GuestMemory::Accessible. Requests rotate across separate registered 4 KiB ranges in one host mapping. The unregistered case uses the same host mapping without registry entries. No game or build ran during timing.

Registered ranges Registry state Upstream + #157 median (ns) PR median (ns) Baseline range PR range
0 stable 650.5 693.9 643.7–810.9 679.5–704.6
1 stable 651.7 22.1 642.0–800.9 21.9–22.5
1 invalidated 678.2 729.6 673.6–690.0 719.6–737.3
64 stable 652.4 39.8 639.1–732.2 39.6–67.5
64 invalidated 690.2 763.4 676.3–949.7 743.8–839.6
128 stable 654.3 784.4 640.1–889.6 775.9–861.3
128 invalidated 710.3 769.3 677.1–882.4 757.1–850.1

Stable sets of 1 and 64 ranges use 96.6% and 93.9% less time. The 128-range cycle exceeds the 64-entry cache and has a 19.9% slower median. Ending a registry mutation before every query forces invalidation; those medians regress by 7.6–10.6%. The unregistered median regresses by 6.7%, with overlapping ranges. These costs are included rather than omitted from the result.

Every query returns the expected access result. Driver, graphics, and PM4 tests pass. Graphics tests also pass with the cache disabled and with the text /proc/self/maps fallback. These include adjacent unregistered memory, protection changes, partial unmaps, address reuse, a busy registry, and cross-thread invalidation. Contribution checks pass. No title frame time or Windows result is claimed. AI-assisted.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6053540937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330#issuecomment-6053540937). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T06:07:24Z. --- Rebased on `e9846679`. The #157 prerequisite retains Pacuka's authorship. Measured upstream plus #157 (`5b65345a`) against that same baseline plus this PR's final commit (`ebfe2b70`). Thus both sides use `PROCMAP_QUERY`. Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3. Six processes per variant, ABBA × 3. Each process has one warmup and nine batches of 4,096 calls to production `GuestMemory::Accessible`. Requests rotate across separate registered 4 KiB ranges in one host mapping. The unregistered case uses the same host mapping without registry entries. No game or build ran during timing. | Registered ranges | Registry state | Upstream + #157 median (ns) | PR median (ns) | Baseline range | PR range | |---:|---|---:|---:|---:|---:| | 0 | stable | 650.5 | 693.9 | 643.7–810.9 | 679.5–704.6 | | 1 | stable | 651.7 | 22.1 | 642.0–800.9 | 21.9–22.5 | | 1 | invalidated | 678.2 | 729.6 | 673.6–690.0 | 719.6–737.3 | | 64 | stable | 652.4 | 39.8 | 639.1–732.2 | 39.6–67.5 | | 64 | invalidated | 690.2 | 763.4 | 676.3–949.7 | 743.8–839.6 | | 128 | stable | 654.3 | 784.4 | 640.1–889.6 | 775.9–861.3 | | 128 | invalidated | 710.3 | 769.3 | 677.1–882.4 | 757.1–850.1 | Stable sets of 1 and 64 ranges use 96.6% and 93.9% less time. The 128-range cycle exceeds the 64-entry cache and has a 19.9% slower median. Ending a registry mutation before every query forces invalidation; those medians regress by 7.6–10.6%. The unregistered median regresses by 6.7%, with overlapping ranges. These costs are included rather than omitted from the result. Every query returns the expected access result. Driver, graphics, and PM4 tests pass. Graphics tests also pass with the cache disabled and with the text `/proc/self/maps` fallback. These include adjacent unregistered memory, protection changes, partial unmaps, address reuse, a busy registry, and cross-thread invalidation. Contribution checks pass. No title frame time or Windows result is claimed. AI-assisted.
oneandonlydean commented 2026-10-09 09:22:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:02Z.


#157 is in; please rebase to drop its copy (it conflicts in GuestMemory.cpp).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078117002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330#issuecomment-6078117002). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:02Z. --- #157 is in; please rebase to drop its copy (it conflicts in `GuestMemory.cpp`).
adriadam10 commented 2026-10-09 23:03:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:03:06Z.

Review: CHANGES_REQUESTED


Thanks for the measurements. Two things before this can go in:

  • Rebase. #157 is merged; as @oneandonlydean asked, rebase onto main to drop its copy of describePages (the PR conflicts in GuestMemory.cpp). After that, only the final commit should remain.
  • Justification. Your own table shows this cache is 7–20 % slower in the invalidated, 128-range and unregistered cases, and #157 alone already removes the slowdown in a real title (see Dean's test on #157: 60 fps held where main fell to single digits). Please show a case from a title or a workload where the query cost is still visible after #157 and this cache fixes it; otherwise the regressions outweigh a gain that only appears in stable sets of ≤ 64 ranges.
  • Staleness. The cache is only invalidated by GuestAllocations mutations. A host-side mprotect inside a registered allocation outside a Mutation (your test needs the explicit GuestAllocationsInvalidate call for it) keeps returning the old permissions. Please state which callers can do that, or drop the cache for them.
  • Surface. APS5_NO_MAPPING_CACHE is a new environment knob and GuestAllocationsTryDescribeRange_nid_no_patch a new libc export-style function; keep them only if needed.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476188100 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330#pullrequestreview-5476188100). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:03:06Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements. Two things before this can go in: - **Rebase.** #157 is merged; as @oneandonlydean asked, rebase onto `main` to drop its copy of `describePages` (the PR conflicts in `GuestMemory.cpp`). After that, only the final commit should remain. - **Justification.** Your own table shows this cache is 7–20 % slower in the invalidated, 128-range and unregistered cases, and #157 alone already removes the slowdown in a real title (see Dean's test on #157: 60 fps held where `main` fell to single digits). Please show a case from a title or a workload where the query cost is still visible after #157 and this cache fixes it; otherwise the regressions outweigh a gain that only appears in stable sets of ≤ 64 ranges. - **Staleness.** The cache is only invalidated by `GuestAllocations` mutations. A host-side `mprotect` inside a registered allocation outside a `Mutation` (your test needs the explicit `GuestAllocationsInvalidate` call for it) keeps returning the old permissions. Please state which callers can do that, or drop the cache for them. - **Surface.** `APS5_NO_MAPPING_CACHE` is a new environment knob and `GuestAllocationsTryDescribeRange_nid_no_patch` a new libc export-style function; keep them only if needed.
adriadam10 commented 2026-10-11 08:53:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:53:00Z.

Review: CHANGES_REQUESTED


Still blocked on the same points from the previous review:

  • Rebase. #157 is merged; the PR still carries its copy of describePages and conflicts in GuestMemory.cpp. Only the final commit (ebfe2b70b) should remain.
  • Justification. The measured gains are in stable sets of ≤ 64 ranges; the invalidated, 128-range and unregistered cases are 7–20 % slower, and #157 alone already removes the slowdown in a real title (@oneandonlydean held 60 fps where main dropped to single digits). Please show a title or workload where the query cost is still visible after #157 and this cache fixes it. Without that the regressions and the extra surface outweigh the gain.
  • Surface. If it stays, say why APS5_NO_MAPPING_CACHE and the new GuestAllocationsTryDescribeRange_nid_no_patch export are needed, and which callers can change permissions inside a registered allocation outside a Mutation (the test needs the explicit GuestAllocationsInvalidate call for that).

Closing as stale later if there is no activity; feel free to reopen rebased with the evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482648499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330#pullrequestreview-5482648499). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T08:53:00Z. **Review:** CHANGES_REQUESTED --- Still blocked on the same points from the previous review: - **Rebase.** #157 is merged; the PR still carries its copy of `describePages` and conflicts in `GuestMemory.cpp`. Only the final commit (`ebfe2b70b`) should remain. - **Justification.** The measured gains are in stable sets of ≤ 64 ranges; the invalidated, 128-range and unregistered cases are 7–20 % slower, and #157 alone already removes the slowdown in a real title (@oneandonlydean held 60 fps where `main` dropped to single digits). Please show a title or workload where the query cost is still visible after #157 and this cache fixes it. Without that the regressions and the extra surface outweigh the gain. - **Surface.** If it stays, say why `APS5_NO_MAPPING_CACHE` and the new `GuestAllocationsTryDescribeRange_nid_no_patch` export are needed, and which callers can change permissions inside a registered allocation outside a `Mutation` (the test needs the explicit `GuestAllocationsInvalidate` call for that). Closing as stale later if there is no activity; feel free to reopen rebased with the evidence.
TibixDev commented 2026-10-12 04:52:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-12T04:52:09Z.


Review-pass update:

Current GuestMemory.cpp already caches arena page states, additionally caches the Windows image extent, and registers ForgetPages with GuestAllocationsSetInvalidator_nid_postfix. This changes the baseline substantially beyond the original #157 comparison. The new Skyrim loading sample on main + experimental NGS reports zero OS query calls while servicing tens of thousands of verifies; that is a limited workload observation, not a universal conclusion.

There is no new evidence that an extra 64-entry registered-range cache pays for its previously measured 7–20% invalidation/large-set/unregistered regressions. Nor is there a demonstrated need for another disable knob/export. A future version must audit permission changes outside Mutation against the existing invalidation path. #157 is merged; the carried copy is historical and is not an open dependency. No new code push.

I have updated the PR description to match this status. The PR remains open; the outstanding review requirements are not being marked resolved. AI-assisted audit.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117976000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330#issuecomment-6117976000). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-12T04:52:09Z. --- Review-pass update: Current `GuestMemory.cpp` already caches arena page states, additionally caches the Windows image extent, and registers `ForgetPages` with `GuestAllocationsSetInvalidator_nid_postfix`. This changes the baseline substantially beyond the original #157 comparison. The new Skyrim loading sample on main + experimental NGS reports zero OS query calls while servicing tens of thousands of verifies; that is a limited workload observation, not a universal conclusion. There is no new evidence that an extra 64-entry registered-range cache pays for its previously measured 7–20% invalidation/large-set/unregistered regressions. Nor is there a demonstrated need for another disable knob/export. A future version must audit permission changes outside `Mutation` against the existing invalidation path. #157 is merged; the carried copy is historical and is not an open dependency. No new code push. I have updated the PR description to match this status. The PR remains open; the outstanding review requirements are not being marked resolved. AI-assisted audit.
oneandonlydean commented 2026-10-14 05:09:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:09:21Z.


Closing for now: main's page cache (#157) now covers it. With the queue this large we're closing stalled perf PRs that don't show a gain in a title; reopen it with before/after numbers from a title scene (the summary lines from the performance report form) if you pick it up again.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161375753 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1330#issuecomment-6161375753). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T05:09:21Z. --- Closing for now: main's page cache (#157) now covers it. With the queue this large we're closing stalled perf PRs that don't show a gain in a title; reopen it with before/after numbers from a title scene (the summary lines from the performance report form) if you pick it up again.

Pull request closed

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!1330
No description provided.