perf(memory): reduce repeated write-tracking range scans #1310

Merged
TibixDev merged 1 commit from upstream-pr/1310 into main 2026-10-09 23:29:30 +00:00
TibixDev commented 2026-10-07 23:09:51 +00:00 (Migrated from github.com)

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


What

Scan version stamps within each contiguous leaf instead of finding the leaf for every block. On Linux, collect nearby watched pages together within existing queue epochs.

Select the range before collection. Widen it only when Linux confirms full watched coverage. Keep the requested range on Windows, for uncached reads, and for threads without epochs. Do not retry a failed collection.

Related: #1201 and #1202 change queue scheduling and retain more collected ranges. This change keeps epoch boundaries and the existing cache size.

Tested

Fedora 44, Release build:

  • Write tracking and graphics tests.
  • Write tracking with collection caching disabled and with the shared cache enabled.
  • Write-history comparisons across a sparse-leaf boundary; guest writes, driver writes, partial unwatches, and epoch changes.
  • Contribution checks.

Isolated comparison against upstream a9ba39c9: unchanged 64 MiB checks fell from 510 to 208 ns. A saved 4,172-request replay used 11–12% less time. Checks that found a write at the first block were about 1 ns slower. These are component timings, not title frame times. Windows was not tested.

Checklist

  • Current main; related PRs are described above.
  • One topic.
  • No new code comments.
  • Unsupported paths still throw; UI stubs are documented.
  • No notes, logs, or images in the repository.
  • No new third-party code.
  • General behavior.
  • Depends on: none.
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4779581134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1310). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-07T23:09:51Z. --- ### What Scan version stamps within each contiguous leaf instead of finding the leaf for every block. On Linux, collect nearby watched pages together within existing queue epochs. Select the range before collection. Widen it only when Linux confirms full watched coverage. Keep the requested range on Windows, for uncached reads, and for threads without epochs. Do not retry a failed collection. Related: #1201 and #1202 change queue scheduling and retain more collected ranges. This change keeps epoch boundaries and the existing cache size. ### Tested Fedora 44, Release build: - Write tracking and graphics tests. - Write tracking with collection caching disabled and with the shared cache enabled. - Write-history comparisons across a sparse-leaf boundary; guest writes, driver writes, partial unwatches, and epoch changes. - Contribution checks. Isolated comparison against upstream `a9ba39c9`: unchanged 64 MiB checks fell from 510 to 208 ns. A saved 4,172-request replay used 11–12% less time. Checks that found a write at the first block were about 1 ns slower. These are component timings, not title frame times. Windows was not tested. ### Checklist - [x] Current `main`; related PRs are described above. - [x] One topic. - [x] No new code comments. - [x] Unsupported paths still throw; UI stubs are documented. - [x] No notes, logs, or images in the repository. - [x] No new third-party code. - [x] General behavior. - [x] Depends on: none. - [x] AI-assisted: yes.
oneandonlydean commented 2026-10-08 03:26:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:26:14Z.


When the widened walk fails, GuestMemory.cpp:1017 walks the requested pages again. Retrying after a failed attempt isn't allowed here (#182); please decide the range before the first walk. For numbers, see #1324.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051544495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1310#issuecomment-6051544495). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T03:26:14Z. --- When the widened walk fails, `GuestMemory.cpp:1017` walks the requested pages again. Retrying after a failed attempt isn't allowed here (#182); please decide the range before the first walk. For numbers, see #1324.
TibixDev commented 2026-10-08 04:17:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T04:17:39Z.


The range is now selected before the walk. Linux widens it only after checking watched coverage. Windows keeps the requested range because its arena check does not prove that neighboring pages are committed. A failed walk returns without a retry.

I also compared upstream a9ba39c9 with that upstream plus this revised PR alone. Both used the same test harness and libc.prx. Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3; six runs per variant in ABBA order. Each run had one warmup and nine measured batches. Values below are medians of the six run medians.

Version checks, ns/check (upstream → PR):

Range Unchanged Write at first block Write at last block
64 KiB 17.7 → 17.6 17.5 → 18.2 17.8 → 17.7
1 MiB 23.3 → 20.7 17.6 → 18.4 22.8 → 20.7
4 MiB 44.8 → 28.9 17.3 → 18.5 55.7 → 28.6
32 MiB 266.2 → 113.7 17.7 → 18.2 263.3 → 113.7
64 MiB 510.0 → 208.4 17.4 → 18.4 515.5 → 207.4

The saved 4,172-request replay fell from 471.4 to 418.4 ns/request with clean pages, and from 496.3 to 435.6 ns/request with a write every 64 requests: 11.2% and 12.2% less time. The observed run ranges did not overlap for either replay case.

The early-exit cases are about 1 ns slower. This replay preserves request ranges and epochs, not the complete game workload; it does not establish a frame-time gain.

Write-history and graphics tests pass. Write-tracking tests also pass with caching disabled and with the shared cache enabled. Windows was not tested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052107431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1310#issuecomment-6052107431). Originally posted by [TibixDev](https://github.com/TibixDev) on 2026-10-08T04:17:39Z. --- The range is now selected before the walk. Linux widens it only after checking watched coverage. Windows keeps the requested range because its arena check does not prove that neighboring pages are committed. A failed walk returns without a retry. I also compared upstream `a9ba39c9` with that upstream plus this revised PR alone. Both used the same test harness and `libc.prx`. Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3; six runs per variant in ABBA order. Each run had one warmup and nine measured batches. Values below are medians of the six run medians. Version checks, ns/check (upstream → PR): | Range | Unchanged | Write at first block | Write at last block | | --- | ---: | ---: | ---: | | 64 KiB | 17.7 → 17.6 | 17.5 → 18.2 | 17.8 → 17.7 | | 1 MiB | 23.3 → 20.7 | 17.6 → 18.4 | 22.8 → 20.7 | | 4 MiB | 44.8 → 28.9 | 17.3 → 18.5 | 55.7 → 28.6 | | 32 MiB | 266.2 → 113.7 | 17.7 → 18.2 | 263.3 → 113.7 | | 64 MiB | 510.0 → 208.4 | 17.4 → 18.4 | 515.5 → 207.4 | The saved 4,172-request replay fell from **471.4 to 418.4 ns/request** with clean pages, and from **496.3 to 435.6 ns/request** with a write every 64 requests: **11.2% and 12.2% less time**. The observed run ranges did not overlap for either replay case. The early-exit cases are about 1 ns slower. This replay preserves request ranges and epochs, not the complete game workload; it does not establish a frame-time gain. Write-history and graphics tests pass. Write-tracking tests also pass with caching disabled and with the shared cache enabled. Windows was not tested.
popcoder565 commented 2026-10-08 08:06:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-08T08:06:37Z.


Tested on Windows, since the description says it wasn't: Windows 10 (19045), RTX 3060 Laptop (driver 616.92), MinGW-w64 GCC 15.2.0, Release, main da402739 merged with f26ea472.

  • agc_write_tracking with the new cases passes 5 of 5 runs.
  • Full ctest passes 419 of 420. The failure is agc_driver_dcc_keys_first_write, which fails on main too (#1434).
  • agc_driver_recorder_tests, which is not in ctest, passes 3 of 3 runs.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6055570542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1310#issuecomment-6055570542). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-08T08:06:37Z. --- Tested on Windows, since the description says it wasn't: Windows 10 (19045), RTX 3060 Laptop (driver 616.92), MinGW-w64 GCC 15.2.0, Release, `main` da402739 merged with f26ea472. - `agc_write_tracking` with the new cases passes 5 of 5 runs. - Full ctest passes 419 of 420. The failure is `agc_driver_dcc_keys_first_write`, which fails on `main` too (#1434). - `agc_driver_recorder_tests`, which is not in ctest, passes 3 of 3 runs.
oneandonlydean commented 2026-10-09 09:21:56 +00:00 (Migrated from github.com)

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


Conflicts with main in tests/WriteTracking.cpp (new cases landed at the same spot); please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078115382 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1310#issuecomment-6078115382). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:21:56Z. --- Conflicts with main in `tests/WriteTracking.cpp` (new cases landed at the same spot); please rebase.
adriadam10 commented 2026-10-09 22:58:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:58:31Z.


Rebased on current main (conflict in tests/WriteTracking.cpp with the new unwatch/private-mapping cases; kept both sets). Linux build + full ctest pass (553/553), including agc_write_tracking. The range is selected before the walk with no retry, as asked in #182, and the Windows path keeps the linear scan. Merging once CI is green on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090689743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1310#issuecomment-6090689743). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:58:31Z. --- Rebased on current `main` (conflict in `tests/WriteTracking.cpp` with the new unwatch/private-mapping cases; kept both sets). Linux build + full ctest pass (553/553), including `agc_write_tracking`. The range is selected before the walk with no retry, as asked in #182, and the Windows path keeps the linear scan. Merging once CI is green on the rebased head.
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!1310
No description provided.