AGC: whole-registry leases make every guest munmap/mprotect wait for GPU work; Onimusha (PPSA27836) drops below 1 FPS for 15-20 s at a time #6453

Open
opened 2026-10-15 16:04:28 +00:00 by simonbronk · 2 comments
simonbronk commented 2026-10-15 16:04:28 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T16:04:28Z.


Summary

In Onimusha: Way of the Sword (PPSA27836), the controller-layout screen runs at about 9.7 FPS. Every minute or two it drops below 1 FPS for 15 to 20 seconds. Each drop matches a burst of guest munmap/mprotect calls on GPU-registered memory. Each of those calls waits in GuestAllocationsRequireUnpinned until GPU work finishes. The pin waiter (WaitForLeasesAndImports) then mostly drains the whole recorder under the GPU mutex, so queue 0's draws slow down 3 to 30 times.

The blocks being freed are not what the GPU holds. A GuestAllocations::Lease is a snapshot of every readable range (GuestAllocationsAcquire/AcquireAll). Any batch that keeps a lease therefore raises the use_count of every registered range, and RequireUnpinned treats every range as pinned while such a batch is in flight.

Setup

Windows 11 26200, RTX 5070 (NVIDIA 617.42), WinLibs GCC 15.2, Release. main 0afa6a607 plus the title's open PRs (#5907 #5776 #5770 #5703 #5841 #5884 #5915 #5815). Warm shader cache, APS5_PROFILE_DRAW=1, APS5_TRACE_SUMMARY_EVERY=5. The title sits idle on the controller-layout screen with no input.

Measurements

Per 10 s window, from the [address-sync] and [draw] driver phases lines (pin counters are deltas):

window pin waits recorder drains guest time in pin waits draws lock wait per draw Graphics::Draw per draw
steady (30 windows in a row) 0 0 0.0 s 17,766 to 19,775 1.8 to 2.6 µs 251 to 276 µs
stall start 846 755 4.2 s 19,766 1.9 µs 253 µs
stall 2,241 2,008 10.0 s 8,670 68 µs 667 µs
earlier stall 1,897 1,524 9.8 s 708 718 µs 5,634 µs
earlier stall 2,887 498 4.7 s 603 490 µs 6,623 µs

During a stall the frame summaries show queue worker 0x0 at 99.9% busy, and frame p50 goes from 104 ms to 1.3 to 2.1 s. In the same runs, GPU fence waits from draws ([recorder] sync sites) barely move. RAM and VRAM stay flat.

The waiting calls come from a local trace in GuestAllocationsRequireUnpinned, not for merging. Over 150 s from boot there were 11,309 waits, 34 s in total:

  • callers: UnmapRegistered 9,725, DoMprotect 1,584
  • sizes: 10,672 of them are 64 KiB, a few are 2 to 4 MiB
  • use_count of the pinned range: 3 in 11,190 cases, i.e. the registry plus the two shared lease snapshots
  • 96% needed one round
  • threads at boot: GameThread, JobThread(High), ResourceManager::parallelProc/loadProc. On the idle screen: JobThread(High) and MovieDispatcher.

Why it looks avoidable

The 64 KiB blocks are distinct addresses in the title's heap. A wait only ends once every batch holding any lease completes, because the snapshot holds every range. If the pin check were limited to the ranges a batch actually binds, imports, or writes back into, most of these unmaps would not wait at all.

Related, but none covers this:

  • #1324 and its split (AcquireAround): lease copy cost.
  • #6182: window imports that pin an unmapped range.
  • #6246: a lease while storing idle results.
  • #4634: registry walks in Cyberpunk.

How would you want leases scoped: per batch, with the ranges each one touched, or something else? I can test a change on this title on Windows (NVIDIA and AMD).

AI-assisted: measured with Claude Code. The trace patch was local and has been removed.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5869586498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6453). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-15T16:04:28Z. --- ### Summary In Onimusha: Way of the Sword (PPSA27836), the controller-layout screen runs at about 9.7 FPS. Every minute or two it drops below 1 FPS for 15 to 20 seconds. Each drop matches a burst of guest `munmap`/`mprotect` calls on GPU-registered memory. Each of those calls waits in `GuestAllocationsRequireUnpinned` until GPU work finishes. The pin waiter (`WaitForLeasesAndImports`) then mostly drains the whole recorder under the GPU mutex, so queue 0's draws slow down 3 to 30 times. The blocks being freed are not what the GPU holds. A `GuestAllocations::Lease` is a snapshot of every readable range (`GuestAllocationsAcquire`/`AcquireAll`). Any batch that keeps a lease therefore raises the `use_count` of every registered range, and `RequireUnpinned` treats every range as pinned while such a batch is in flight. ### Setup Windows 11 26200, RTX 5070 (NVIDIA 617.42), WinLibs GCC 15.2, Release. `main` 0afa6a607 plus the title's open PRs (#5907 #5776 #5770 #5703 #5841 #5884 #5915 #5815). Warm shader cache, `APS5_PROFILE_DRAW=1`, `APS5_TRACE_SUMMARY_EVERY=5`. The title sits idle on the controller-layout screen with no input. ### Measurements Per 10 s window, from the `[address-sync]` and `[draw] driver phases` lines (pin counters are deltas): | window | pin waits | recorder drains | guest time in pin waits | draws | lock wait per draw | `Graphics::Draw` per draw | |---|---|---|---|---|---|---| | steady (30 windows in a row) | 0 | 0 | 0.0 s | 17,766 to 19,775 | 1.8 to 2.6 µs | 251 to 276 µs | | stall start | 846 | 755 | 4.2 s | 19,766 | 1.9 µs | 253 µs | | stall | 2,241 | 2,008 | 10.0 s | 8,670 | 68 µs | 667 µs | | earlier stall | 1,897 | 1,524 | 9.8 s | 708 | 718 µs | 5,634 µs | | earlier stall | 2,887 | 498 | 4.7 s | 603 | 490 µs | 6,623 µs | During a stall the frame summaries show queue worker 0x0 at 99.9% busy, and frame p50 goes from 104 ms to 1.3 to 2.1 s. In the same runs, GPU fence waits from draws (`[recorder]` sync sites) barely move. RAM and VRAM stay flat. The waiting calls come from a local trace in `GuestAllocationsRequireUnpinned`, not for merging. Over 150 s from boot there were 11,309 waits, 34 s in total: - callers: `UnmapRegistered` 9,725, `DoMprotect` 1,584 - sizes: 10,672 of them are 64 KiB, a few are 2 to 4 MiB - `use_count` of the pinned range: 3 in 11,190 cases, i.e. the registry plus the two shared lease snapshots - 96% needed one round - threads at boot: `GameThread`, `JobThread(High)`, `ResourceManager::parallelProc`/`loadProc`. On the idle screen: `JobThread(High)` and `MovieDispatcher`. ### Why it looks avoidable The 64 KiB blocks are distinct addresses in the title's heap. A wait only ends once every batch holding *any* lease completes, because the snapshot holds every range. If the pin check were limited to the ranges a batch actually binds, imports, or writes back into, most of these unmaps would not wait at all. Related, but none covers this: - #1324 and its split (`AcquireAround`): lease copy cost. - #6182: window imports that pin an unmapped range. - #6246: a lease while storing idle results. - #4634: registry walks in Cyberpunk. How would you want leases scoped: per batch, with the ranges each one touched, or something else? I can test a change on this title on Windows (NVIDIA and AMD). AI-assisted: measured with Claude Code. The trace patch was local and has been removed.
simonbronk commented 2026-10-15 18:30:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T18:30:34Z.


Follow-up: two local experiments (not for merging). Same machine and base, Onimusha booting to the menu, 150 s, APS5_PROFILE_DRAW=1.

1. Skip the wait when it looks safe. A filter in GuestAllocationsRequireUnpinned, run before the pin waiter with the registry lock released, under the GPU mutex. It let the mutation through only when the bytes overlap no live or parked host import, no recorder pending write (PendingWriteOverlaps) and no pending image result (StorageTexture::AnyPendingOverlaps).

pin waits passed by the filter refused because of
filter 11,553 289 (2.6%) a live host import overlaps: 10,711 (100% of refusals)

So nearly every unmapped 64 KiB block lies inside a live host import, and a filter of this kind cannot help.

2. Never wait (unsafe, to find the upper bound). The filter passed everything. Pin waits dropped to 0 (0.0 s, against 24.1 s in a matching run without the filter). The run then failed within 20 s on the driver side:

[gpu] driver failure: AGC driver: guest memory is not readable at 0x2218800000 (range 0x2218800000+0x800000)

So the whole-registry lease also protects the driver's own CPU reads of guest memory, not only the GPU's access through imports. Narrowing which ranges a lease pins is not enough on its own.

Given that, I see two directions, both beyond a quick local change:

  • Defer the host-side release. Let the guest unmap or reprotect at once in the registry, and keep the host pages (and any import over them) alive until the batches in flight at that moment complete. A fixed mapping that reuses the address before then would still wait (RequireAvailable).
  • Per-import last-use batch serial. The waiter would then wait only for the batch that last used the overlapping import (often already complete) and retire it. Today it finishes up to the newest lease batch, or drains the recorder when that serial is already finished. In the stall windows, drains were about 90% of the waits.

Which of these, if either, fits the GuestBufferMemory design? I'm happy to measure a branch on this title.

AI-assisted: experiments with Claude Code. Both patches are reverted.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6199384583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6453#issuecomment-6199384583). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-15T18:30:34Z. --- Follow-up: two local experiments (not for merging). Same machine and base, Onimusha booting to the menu, 150 s, `APS5_PROFILE_DRAW=1`. **1. Skip the wait when it looks safe.** A filter in `GuestAllocationsRequireUnpinned`, run before the pin waiter with the registry lock released, under the GPU mutex. It let the mutation through only when the bytes overlap no live or parked host import, no recorder pending write (`PendingWriteOverlaps`) and no pending image result (`StorageTexture::AnyPendingOverlaps`). | | pin waits | passed by the filter | refused because of | |---|---|---|---| | filter | 11,553 | 289 (2.6%) | a live host import overlaps: 10,711 (100% of refusals) | So nearly every unmapped 64 KiB block lies inside a live host import, and a filter of this kind cannot help. **2. Never wait (unsafe, to find the upper bound).** The filter passed everything. Pin waits dropped to 0 (0.0 s, against 24.1 s in a matching run without the filter). The run then failed within 20 s on the driver side: ``` [gpu] driver failure: AGC driver: guest memory is not readable at 0x2218800000 (range 0x2218800000+0x800000) ``` So the whole-registry lease also protects the driver's own CPU reads of guest memory, not only the GPU's access through imports. Narrowing which ranges a lease pins is not enough on its own. Given that, I see two directions, both beyond a quick local change: - **Defer the host-side release.** Let the guest unmap or reprotect at once in the registry, and keep the host pages (and any import over them) alive until the batches in flight at that moment complete. A fixed mapping that reuses the address before then would still wait (`RequireAvailable`). - **Per-import last-use batch serial.** The waiter would then wait only for the batch that last used the overlapping import (often already complete) and retire it. Today it finishes up to the newest lease batch, or drains the recorder when that serial is already finished. In the stall windows, drains were about 90% of the waits. Which of these, if either, fits the GuestBufferMemory design? I'm happy to measure a branch on this title. AI-assisted: experiments with Claude Code. Both patches are reverted.
MarcZX10 commented 2026-10-17 02:44:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T02:44:05Z.


I checked the current waiter and import tracking. HostImport::lastUse is an LRU/use counter today, not a recorder submission serial, and the waiter currently finishes the newest batch holding any address-space lease before retiring overlapping imports. #6182 handles the distinct oversized-registration case where non-overlapping windows keep one allocation range pinned.

For this report, a useful split test would be to record (a) which import windows actually overlap each munmap/mprotect range and (b) the last recorder batch that used those imports, then compare a wait through that serial with the current newest-lease wait. The title’s experiment shows we must retain the overlapping import and any CPU-read protection until its work completes; it does not show that unrelated leased work must also finish. A regression fixture should keep an unrelated import/batch in flight while mutating a separate range and verify the unrelated work is not drained, then verify the overlapping import is retired only after its last GPU use. I have not implemented this path or claimed the title workload is fixed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228648295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6453#issuecomment-6228648295). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T02:44:05Z. --- I checked the current waiter and import tracking. `HostImport::lastUse` is an LRU/use counter today, not a recorder submission serial, and the waiter currently finishes the newest batch holding any address-space lease before retiring overlapping imports. #6182 handles the distinct oversized-registration case where non-overlapping windows keep one allocation range pinned. For this report, a useful split test would be to record (a) which import windows actually overlap each `munmap`/`mprotect` range and (b) the last recorder batch that used those imports, then compare a wait through that serial with the current newest-lease wait. The title’s experiment shows we must retain the overlapping import and any CPU-read protection until its work completes; it does not show that unrelated leased work must also finish. A regression fixture should keep an unrelated import/batch in flight while mutating a separate range and verify the unrelated work is not drained, then verify the overlapping import is retired only after its last GPU use. I have not implemented this path or claimed the title workload is fixed.
Sign in to join this conversation.
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#6453
No description provided.