feat(libSceAgcDriver): import scattered direct memory as a dma-buf run list and probe its coherence #4449

Merged
Mouad-Scriptz-0 merged 14 commits from upstream-pr/4449 into main 2026-11-02 07:55:20 +00:00
Mouad-Scriptz-0 commented 2026-10-12 11:56:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-12T11:56:18Z.


What

Linux only. The dma-buf fallback of host imports (createImport, when the host-pointer import fails) had two problems, found while chasing Minecraft's untracked textures. This is @blawesom's port of the original branch onto main's sharedBacking import structure (port/4449, authorship kept), plus the fixes from the review of 10-17.

  • Scattered backing. A guest range mapped from several physical allocations is several runs of the direct memory backing file (a 4 MiB Minecraft atlas spans 53), and the fallback took one offset for the whole range. GuestArenaSharedBackingRuns (libkernel, registered by DirectMemory) resolves a range into its runs in address order, up to udmabuf's 1024; one run keeps main's chunked and sparse paths, several runs create one udmabuf through UDMABUF_CREATE_LIST. The single resolver stays as the fallback for registrations that do not provide runs. guest_memory gains CheckDirectMemorySharedBackingRuns: three physical allocations mapped back to back resolve to their runs with the right offsets and total, a sub-range starts inside the first run, and a short run array, a range past the mapping or an empty range are refused.
  • Coherence. i915 maps a dma-buf without snooping the CPU caches: after the CPU stores to the pages and the GPU fills the import, the CPU keeps reading its stale lines. The start-up probe now stores to every page from the CPU, fills from the GPU and counts the pages the CPU still reads stale (staleAfterFill, in the [write-watch] line); a device measured incoherent does not use dma-buf imports and copies instead, which rules them out on Intel. Without a write watch the probe still runs, since that measurement is a plain CPU read after a GPU fill; it registers and collects the watch only where one exists, and the no-watch line says when nothing was measured. The mixed-watch import path (watchedDmaBuf != watchedHostPointer) also requires the coherence result.

Tested

Fedora 44 (kernel 7.2.11, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, Intel Arc Meteor Lake, Mesa 26.2), branch on main 9f25d0bf5: guest_memory (with the new case), agc_dma_data_tests, agc_write_watch_coverage, agc_host_import_unmap, agc_driver_host_import_at_map and agc_driver_host_import_teardown pass. The probe on this GPU reports 4 stale after a GPU store over CPU writes for dma-buf imports, so the fallback stays off here. tools/check_conventions.py --base origin/main and git diff --check pass. Not tested: a device without a write watch (the branch the review found unmeasured), AMD or NVIDIA, Windows (no dma-buf path), and no title was run on this head; @alfalfa-star offered the Kena scene (#4449, 10-17) on the port.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4829030030 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-12T11:56:18Z. --- ### What Linux only. The dma-buf fallback of host imports (`createImport`, when the host-pointer import fails) had two problems, found while chasing Minecraft's untracked textures. This is @blawesom's port of the original branch onto `main`'s `sharedBacking` import structure (`port/4449`, authorship kept), plus the fixes from the review of 10-17. - **Scattered backing.** A guest range mapped from several physical allocations is several runs of the direct memory backing file (a 4 MiB Minecraft atlas spans 53), and the fallback took one offset for the whole range. `GuestArenaSharedBackingRuns` (libkernel, registered by `DirectMemory`) resolves a range into its runs in address order, up to udmabuf's 1024; one run keeps `main`'s chunked and sparse paths, several runs create one udmabuf through `UDMABUF_CREATE_LIST`. The single resolver stays as the fallback for registrations that do not provide runs. `guest_memory` gains `CheckDirectMemorySharedBackingRuns`: three physical allocations mapped back to back resolve to their runs with the right offsets and total, a sub-range starts inside the first run, and a short run array, a range past the mapping or an empty range are refused. - **Coherence.** i915 maps a dma-buf without snooping the CPU caches: after the CPU stores to the pages and the GPU fills the import, the CPU keeps reading its stale lines. The start-up probe now stores to every page from the CPU, fills from the GPU and counts the pages the CPU still reads stale (`staleAfterFill`, in the `[write-watch]` line); a device measured incoherent does not use dma-buf imports and copies instead, which rules them out on Intel. Without a write watch the probe still runs, since that measurement is a plain CPU read after a GPU fill; it registers and collects the watch only where one exists, and the no-watch line says when nothing was measured. The mixed-watch import path (`watchedDmaBuf != watchedHostPointer`) also requires the coherence result. ### Tested Fedora 44 (kernel 7.2.11, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, Intel Arc Meteor Lake, Mesa 26.2), branch on `main` 9f25d0bf5: `guest_memory` (with the new case), `agc_dma_data_tests`, `agc_write_watch_coverage`, `agc_host_import_unmap`, `agc_driver_host_import_at_map` and `agc_driver_host_import_teardown` pass. The probe on this GPU reports `4 stale after a GPU store over CPU writes` for dma-buf imports, so the fallback stays off here. `tools/check_conventions.py --base origin/main` and `git diff --check` pass. Not tested: a device without a write watch (the branch the review found unmeasured), AMD or NVIDIA, Windows (no dma-buf path), and no title was run on this head; @alfalfa-star offered the Kena scene (#4449, 10-17) on the port. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-13 00:20:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:20:26Z.


Which device takes the run-list path once the coherence probe is in? On i915 the probe turns the dma-buf fallback off, and SharedBacking on main already refuses a range whose mappings are not contiguous in the backing file (DirectMemory.cpp:496), so nothing is imported with a wrong offset today. Please keep the probe here and leave SharedBackingRuns for a PR with a device that needs it.

dmaBufImportsCoherent also stays false on the early returns of decideImportWatch (APS5_WRITE_WATCH_IMPORTS=watch or unwatch, no write watch), which turns the fallback off there without a probe.

It needs a rebase as well: docs/dev/TechnicalDebt.md was split, so the entry goes under docs/dev/debt/.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135177646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6135177646). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:20:26Z. --- Which device takes the run-list path once the coherence probe is in? On i915 the probe turns the dma-buf fallback off, and `SharedBacking` on main already refuses a range whose mappings are not contiguous in the backing file (`DirectMemory.cpp:496`), so nothing is imported with a wrong offset today. Please keep the probe here and leave `SharedBackingRuns` for a PR with a device that needs it. `dmaBufImportsCoherent` also stays false on the early returns of `decideImportWatch` (`APS5_WRITE_WATCH_IMPORTS=watch` or `unwatch`, no write watch), which turns the fallback off there without a probe. It needs a rebase as well: `docs/dev/TechnicalDebt.md` was split, so the entry goes under `docs/dev/debt/`.
johnmaia commented 2026-10-13 10:57:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T10:57:01Z.


Test report: AMD / RADV, where the run-list path is needed (re @oneandonlydean's question).

Setup

  • Linux 7.0, RX 7600 (RADV, Mesa 25.2.8).
  • Title: Epic Mickey: Rebrushed (PPSA15657), Dark Beauty Castle level.
  • Two builds of the same base: my Mickey test bed (main e7c70a2df plus Mickey fixes, including #5030). B adds this PR, which merged cleanly onto that base.
  • Each build ran a 5-minute scripted play session with APS5_PROFILE_DRAW=1. Numbers are averaged from 30 to 300 s after loading the save.

Why AMD takes this path: host-pointer imports of this title's direct memory fail at vkAllocateMemory (-13). The guest ranges are stitched from many memfd mappings at non-contiguous file offsets. For example, 0x2010000000–0x2016000000 is 11 separate VMAs. amdgpu's userptr import can't span VMAs, and SharedBacking on main refuses non-contiguous runs. So these ranges are copied on the CPU instead.

A (base) B (+#4449)
In-level FPS 4.57 4.93 (+8%)
Buffer regions copied on the CPU, MiB per 10 s ([buffers] outside imports) 231,027 64,643 (−72%)
host import ... failed lines 40 0
GPU busy / idle gaps per present 106.1 / 108.7 ms 107.7 / 91.5 ms

Coherence probe on RADV: 0 stale after a GPU store over CPU writes for both host-pointer and dma-buf imports, so the fallback stays enabled here:

[write-watch] dma-buf imports keep write protection: yes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import, 1 seen after a CPU store, 0 stale after a GPU store over CPU writes); imported ranges stay watched

Checks

  • No visual change; the level renders as before.
  • No new errors in the log.
  • Both sessions survived 5 minutes of play.
  • I also merged this PR onto current main, resolving the GuestBufferMemory.cpp conflict against the new createBackingImport structure for a local build: full ctest 1033/1033 passed. That build doesn't boot the title for an unrelated reason, so the in-game numbers above are from the older base.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144013027 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6144013027). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-13T10:57:01Z. --- **Test report: AMD / RADV, where the run-list path is needed** (re @oneandonlydean's question). **Setup** - Linux 7.0, RX 7600 (RADV, Mesa 25.2.8). - Title: Epic Mickey: Rebrushed (PPSA15657), Dark Beauty Castle level. - Two builds of the same base: my Mickey test bed (main e7c70a2df plus Mickey fixes, including #5030). B adds this PR, which merged cleanly onto that base. - Each build ran a 5-minute scripted play session with `APS5_PROFILE_DRAW=1`. Numbers are averaged from 30 to 300 s after loading the save. **Why AMD takes this path:** host-pointer imports of this title's direct memory fail at `vkAllocateMemory` (-13). The guest ranges are stitched from many memfd mappings at non-contiguous file offsets. For example, 0x2010000000–0x2016000000 is 11 separate VMAs. amdgpu's userptr import can't span VMAs, and `SharedBacking` on main refuses non-contiguous runs. So these ranges are copied on the CPU instead. | | A (base) | B (+#4449) | |---|---|---| | In-level FPS | 4.57 | **4.93** (+8%) | | Buffer regions copied on the CPU, MiB per 10 s (`[buffers]` outside imports) | 231,027 | **64,643** (−72%) | | `host import ... failed` lines | 40 | **0** | | GPU busy / idle gaps per present | 106.1 / 108.7 ms | 107.7 / 91.5 ms | **Coherence probe on RADV:** `0 stale after a GPU store over CPU writes` for both host-pointer and dma-buf imports, so the fallback stays enabled here: ``` [write-watch] dma-buf imports keep write protection: yes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import, 1 seen after a CPU store, 0 stale after a GPU store over CPU writes); imported ranges stay watched ``` **Checks** - No visual change; the level renders as before. - No new errors in the log. - Both sessions survived 5 minutes of play. - I also merged this PR onto current main, resolving the `GuestBufferMemory.cpp` conflict against the new `createBackingImport` structure for a local build: full `ctest` 1033/1033 passed. That build doesn't boot the title for an unrelated reason, so the in-game numbers above are from the older base. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Mouad-Scriptz-0 commented 2026-10-13 13:50:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-13T13:50:54Z.


Agreed on the probe staying in; on the run list, @johnmaia's RADV report above is the device that needs it: on the RX 7600 the host-pointer import of Epic Mickey's direct memory fails at vkAllocateMemory (the ranges are stitched from many memfd mappings at non-contiguous offsets, 11 VMAs for one 96 MiB range), SharedBacking on main refuses the non-contiguous run, and the buffers are copied on the CPU instead. With the run list the import succeeds: +8 % in-level FPS, CPU-copied buffer regions down 72 % (231,027 to 64,643 MiB per 10 s), host import ... failed lines 40 to 0, no visual change, and his probe reads 0 stale for both import kinds so the fallback stays on there. On i915 the probe turns the fallback off, so nothing changes here. I'd keep SharedBackingRuns in this PR on that evidence; if you'd rather see it separately I can split it, with the probe first.

The early returns of decideImportWatch are a real gap: dmaBufImportsCoherent stays false under APS5_WRITE_WATCH_IMPORTS=watch or unwatch and without a write watch, which disables the fallback with no probe. I'll run the coherence probe on those paths too, and rebase (the entry moves to docs/dev/debt/libSceAgcDriver.md; johnmaia already resolved the createBackingImport conflict for his local build).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147094166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6147094166). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-13T13:50:54Z. --- Agreed on the probe staying in; on the run list, @johnmaia's RADV report above is the device that needs it: on the RX 7600 the host-pointer import of Epic Mickey's direct memory fails at `vkAllocateMemory` (the ranges are stitched from many memfd mappings at non-contiguous offsets, 11 VMAs for one 96 MiB range), `SharedBacking` on main refuses the non-contiguous run, and the buffers are copied on the CPU instead. With the run list the import succeeds: +8 % in-level FPS, CPU-copied buffer regions down 72 % (231,027 to 64,643 MiB per 10 s), `host import ... failed` lines 40 to 0, no visual change, and his probe reads `0 stale` for both import kinds so the fallback stays on there. On i915 the probe turns the fallback off, so nothing changes here. I'd keep `SharedBackingRuns` in this PR on that evidence; if you'd rather see it separately I can split it, with the probe first. The early returns of `decideImportWatch` are a real gap: `dmaBufImportsCoherent` stays false under `APS5_WRITE_WATCH_IMPORTS=watch` or `unwatch` and without a write watch, which disables the fallback with no probe. I'll run the coherence probe on those paths too, and rebase (the entry moves to `docs/dev/debt/libSceAgcDriver.md`; johnmaia already resolved the `createBackingImport` conflict for his local build).
blawesom commented 2026-10-14 05:56:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:56:16Z.


Rebase-state diagnosis, before anyone spends merge effort: this PR's run-list import design now collides with main's newer single-backing version of the same mechanism.

main has since landed BackingFile/sharedBacking — a single (file, offset) shared backing per import, resolved through GuestArenaSharedBacking_nid_postfix, feeding createChunkedDmaBufImport/createDmaBufImport with one offset. This PR implements the run list: SharedBackingRun arrays through GuestArenaSharedBackingRuns_nid_postfix, a DmaBufRunLimit, and a span-of-runs createDmaBufImport — plus the coherence probe extensions (importsStampPages, staleAfterFill).

The two are different generations of the same import architecture, so the rebase is a port of this PR's run-list semantics onto main's refactored path (or a decision that the single-backing version suffices for the devices seen so far). Given the run-list discussion with @johnmaia's RADV report is active on this thread, I've left the merge to that design outcome rather than forcing one side — happy to do the full port onto main's structure if the run list is what should win.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161936225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6161936225). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-14T05:56:16Z. --- **Rebase-state diagnosis, before anyone spends merge effort:** this PR's run-list import design now collides with `main`'s newer single-backing version of the same mechanism. `main` has since landed `BackingFile`/`sharedBacking` — a **single** (file, offset) shared backing per import, resolved through `GuestArenaSharedBacking_nid_postfix`, feeding `createChunkedDmaBufImport`/`createDmaBufImport` with one offset. This PR implements the **run list**: `SharedBackingRun` arrays through `GuestArenaSharedBackingRuns_nid_postfix`, a `DmaBufRunLimit`, and a span-of-runs `createDmaBufImport` — plus the coherence probe extensions (`importsStampPages`, `staleAfterFill`). The two are different generations of the same import architecture, so the rebase is a port of this PR's run-list semantics onto main's refactored path (or a decision that the single-backing version suffices for the devices seen so far). Given the run-list discussion with @johnmaia's RADV report is active on this thread, I've left the merge to that design outcome rather than forcing one side — happy to do the full port onto main's structure if the run list is what should win.
oneandonlydean commented 2026-10-14 21:32:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T21:32:56Z.


Any update here? On 10-13 you said you'd run the coherence probe on the early returns of decideImportWatch (APS5_WRITE_WATCH_IMPORTS=watch/unwatch, no write watch) and rebase, but the branch is still at 371a549f. Note main now has the single-backing sharedBacking import path, so the run list needs porting onto it rather than a text rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6178975551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6178975551). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T21:32:56Z. --- Any update here? On 10-13 you said you'd run the coherence probe on the early returns of `decideImportWatch` (`APS5_WRITE_WATCH_IMPORTS=watch`/`unwatch`, no write watch) and rebase, but the branch is still at 371a549f. Note main now has the single-backing `sharedBacking` import path, so the run list needs porting onto it rather than a text rebase.
darklinkworker commented 2026-10-15 15:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by darklinkworker on 2026-10-15T15:44:08Z.


A data point from a local port of this branch onto current main. Linux, RADV Phoenix (Radeon 760M), Dragon Quest III HD-2D (PPSA20612).

On this host the write-watch probe does not run: there is no [write-watch] line, and GuestMemory::WriteWatched() is false. decideImportWatch returns on that path before it can set dmaBufImportsCoherent, so the flag stays at its default and the dma-buf fallback is skipped. The log then fills with host import ... falling back to copies. In the opening scene the character was missing, at about 1.5 FPS.

For a local test only, I set dmaBufImportsCoherent true on that early return, with no probe result. The copy lines dropped to zero, and the character was visible in the opening scene. I do not have a staleAfterFill reading for this GPU, so I cannot say those imports are coherent, and I am not suggesting the fallback be forced on. It is the same early-return gap already noted on this pull request: without a write watch, the fallback is disabled and no probe runs. Running the probe on that path, as discussed, is what would let this machine decide.

This was a local build, not a rebase of the branch. A later save-load screen can still stop presenting here; I don't think that belongs on this pull request.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6196106812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6196106812). Originally posted by [darklinkworker](https://github.com/darklinkworker) on 2026-10-15T15:44:08Z. --- A data point from a local port of this branch onto current main. Linux, RADV Phoenix (Radeon 760M), Dragon Quest III HD-2D (PPSA20612). On this host the write-watch probe does not run: there is no `[write-watch]` line, and `GuestMemory::WriteWatched()` is false. `decideImportWatch` returns on that path before it can set `dmaBufImportsCoherent`, so the flag stays at its default and the dma-buf fallback is skipped. The log then fills with `host import ... falling back to copies`. In the opening scene the character was missing, at about 1.5 FPS. For a local test only, I set `dmaBufImportsCoherent` true on that early return, with no probe result. The copy lines dropped to zero, and the character was visible in the opening scene. I do not have a `staleAfterFill` reading for this GPU, so I cannot say those imports are coherent, and I am not suggesting the fallback be forced on. It is the same early-return gap already noted on this pull request: without a write watch, the fallback is disabled and no probe runs. Running the probe on that path, as discussed, is what would let this machine decide. This was a local build, not a rebase of the branch. A later save-load screen can still stop presenting here; I don't think that belongs on this pull request.
oneandonlydean commented 2026-10-17 01:44:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T01:44:13Z.


That is the early-return gap from 10-14: without a write watch decideImportWatch returns before the probe, dmaBufImportsCoherent keeps its default and the dma-buf fallback is skipped, which is the copy lines and the 1.5 FPS. Setting it true is a measurement, not a fix, as you say. @Mouad-Scriptz-0, the probe has to run on that path, and since main now has the sharedBacking version of the same import this needs a port, not a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228099982 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6228099982). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T01:44:13Z. --- That is the early-return gap from 10-14: without a write watch `decideImportWatch` returns before the probe, `dmaBufImportsCoherent` keeps its default and the dma-buf fallback is skipped, which is the copy lines and the 1.5 FPS. Setting it true is a measurement, not a fix, as you say. @Mouad-Scriptz-0, the probe has to run on that path, and since main now has the `sharedBacking` version of the same import this needs a port, not a rebase.
blawesom commented 2026-10-17 08:28:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T08:28:49Z.


The port, as directed — since main now carries the sharedBacking version of this import, I ported this PR's run-list semantics onto that structure rather than rebasing, and included the early-return fix from the 10-14/10-17 discussion: decideImportWatch now runs the dma-buf coherence probe even when there is no write watch (its stale measurement is a plain CPU read after a GPU fill), so such devices measure coherence instead of skipping the fallback.

What the branch carries, on top of current main:

  • GuestArenaSharedBackingRuns resolves a guest range into the runs of its direct memory backing (one per physical allocation, up to udmabuf's 1024), registered by DirectMemory; a single run keeps main's chunked and sparse paths, several runs create one udmabuf buffer per run through UDMABUF_CREATE_LIST
  • the start-up probe measures dma-buf CPU coherence: it stores to the import from the GPU after CPU stores to the same pages and counts pages the CPU still reads stale (the i915 case in the debt entry); an incoherent measurement keeps the fallback off
  • the single shared backing resolver stays as a fallback for registrations that do not provide runs (the sparse-import tests rely on it), and the mixed-watch path (watchedDmaBuf != watchedHostPointer) is ported to the runs API
  • one reconciliation to review: dmaBufImportsCoherent defaults to true (probe-not-run = main's unconditional fallback, which the sparse tests assume) and is only turned off by an incoherent measurement — the PR's original default of false would have disabled main's sparse path before any probe ran

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite 1335/1336 — only the known main regression (agc_driver_tessellation segfault, #4727). The new runs test (CheckDirectMemorySharedBackingRuns) and the sparse/chunked import tests all pass, and the probe's coherence measurement runs end-to-end here: 0 stale after a GPU store over CPU writes (coherent, fallback available on this device).

Branch: blawesom:port/4449 (8d3627214) — happy to hand it over as the base for this PR, or open it separately if that is easier; the design is @Mouad-Scriptz-0's, carried with co-authorship.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231748723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6231748723). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-17T08:28:49Z. --- **The port, as directed** — since `main` now carries the `sharedBacking` version of this import, I ported this PR's run-list semantics onto that structure rather than rebasing, and included the early-return fix from the 10-14/10-17 discussion: `decideImportWatch` now runs the dma-buf coherence probe even when there is no write watch (its stale measurement is a plain CPU read after a GPU fill), so such devices measure coherence instead of skipping the fallback. What the branch carries, on top of current `main`: - `GuestArenaSharedBackingRuns` resolves a guest range into the **runs** of its direct memory backing (one per physical allocation, up to udmabuf's 1024), registered by `DirectMemory`; a single run keeps `main`'s chunked and sparse paths, several runs create one udmabuf buffer per run through `UDMABUF_CREATE_LIST` - the start-up probe **measures dma-buf CPU coherence**: it stores to the import from the GPU after CPU stores to the same pages and counts pages the CPU still reads stale (the i915 case in the debt entry); an incoherent measurement keeps the fallback off - the single shared backing resolver stays as a **fallback** for registrations that do not provide runs (the sparse-import tests rely on it), and the mixed-watch path (`watchedDmaBuf != watchedHostPointer`) is ported to the runs API - one reconciliation to review: `dmaBufImportsCoherent` defaults to **true** (probe-not-run = `main`'s unconditional fallback, which the sparse tests assume) and is only turned off by an incoherent measurement — the PR's original default of false would have disabled `main`'s sparse path before any probe ran Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; **full suite 1335/1336** — only the known `main` regression (`agc_driver_tessellation` segfault, #4727). The new runs test (`CheckDirectMemorySharedBackingRuns`) and the sparse/chunked import tests all pass, and the probe's coherence measurement runs end-to-end here: `0 stale after a GPU store over CPU writes` (coherent, fallback available on this device). Branch: `blawesom:port/4449` (`8d3627214`) — happy to hand it over as the base for this PR, or open it separately if that is easier; the design is @Mouad-Scriptz-0's, carried with co-authorship.
oneandonlydean commented 2026-10-17 08:33:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T08:33:45Z.


Thanks @blawesom, that covers both asks (the port onto sharedBacking and the probe on the no-write-watch path). We're reviewing 8d3627214 now, including the dmaBufImportsCoherent default you flagged.

@Mouad-Scriptz-0, it's your design: are you happy to take blawesom's commit as the base of this PR (it keeps your co-authorship), or would you prefer it as a separate PR? Either works for us.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231792681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6231792681). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T08:33:45Z. --- Thanks @blawesom, that covers both asks (the port onto `sharedBacking` and the probe on the no-write-watch path). We're reviewing `8d3627214` now, including the `dmaBufImportsCoherent` default you flagged. @Mouad-Scriptz-0, it's your design: are you happy to take blawesom's commit as the base of this PR (it keeps your co-authorship), or would you prefer it as a separate PR? Either works for us.
oneandonlydean commented 2026-10-17 08:37:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T08:37:54Z.


Review of the port (port/4449 at f1bb5cb9a6b1, same tree as 8d3627214), @blawesom:

The run-list port is faithful. The kernel, libc and runs code matches #4449 line for line: one run goes through UDMABUF_CREATE plus main's chunked/sparse paths, several runs through UDMABUF_CREATE_LIST (capped at 1024), and the single resolver stays as the fallback. It merges cleanly with current main. Two things need fixing before we run CI:

1. The no-write-watch probe still never runs on Linux. decideImportWatch now calls ProbeDmaBufImportWriteProtection when !GuestMemory::WriteWatched(), but that probe still starts with if (!GuestWriteWatchAvailable_nid_postfix()) { probe.failure = "the write watch"; return probe; }. On Linux WriteWatched() is GuestWriteWatchAvailable(), so the probe always fails there, dmaBufImportsCoherent keeps its default, and nothing is measured. The early return was removed from the host probe (ProbeImportWriteProtection) but not from the dma-buf one. Your 0-stale run was on RX 9070 XT, which has a write watch, so it went down the watched branch.

  • Ask: drop that early return in ProbeDmaBufImportWriteProtection, guard its GuestWriteWatchRegister/Unregister calls the way the host probe does, and log "not measured" when failure != nullptr (it currently prints "CPU-coherent (0 of 0 pages stale)" for an unmeasured device).
  • The measurement itself is a valid coherence test without a watch (CPU store through the MAP_SHARED memfd, fenced GPU fill, plain read), so this is only about letting it run.

2. The mixed-watch path ignores the coherence result. In importRunAt, the branch if (step != nullptr && watchedDmaBuf != watchedHostPointer) calls createBackingImport with no dmaBufImportsCoherent check. On a watched i915 whose dma-buf and host watch decisions differ, it imports dma-buf right after logging "dma-buf imports are not CPU-coherent and are not used". Main added that path after #4449, so the gap is new in the port.

  • Ask: add && state.dmaBufImportsCoherent to that condition.

Smaller notes:

  • A test on the no-watch branch would have caught (1); one is worth adding if it's practical. The new CheckDirectMemorySharedBackingRuns test is good (runs, pread offset, capacity), but nothing covers the CREATE_LIST import, the probe or the mixed-path gate.
  • In that test, the capacity-1 call leaks the dup'd fd when it returns true.
  • With dmaBufImportsCoherent defaulting to true, the APS5_WRITE_WATCH_IMPORTS overrides and a dma-buf probe failure on the watched branch still leave the fallback on. That's the same as main today, so it's not blocking.

On where it lands: from the code side either way works, since it fully replaces #4449's diff. That choice is @Mouad-Scriptz-0's. It's a guest-memory change, so after the fixes it gets full CI on the exact head and our game checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6231829784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6231829784). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T08:37:54Z. --- Review of the port (`port/4449` at f1bb5cb9a6b1, same tree as 8d3627214), @blawesom: The run-list port is faithful. The kernel, libc and runs code matches #4449 line for line: one run goes through `UDMABUF_CREATE` plus main's chunked/sparse paths, several runs through `UDMABUF_CREATE_LIST` (capped at 1024), and the single resolver stays as the fallback. It merges cleanly with current main. Two things need fixing before we run CI: **1. The no-write-watch probe still never runs on Linux.** `decideImportWatch` now calls `ProbeDmaBufImportWriteProtection` when `!GuestMemory::WriteWatched()`, but that probe still starts with `if (!GuestWriteWatchAvailable_nid_postfix()) { probe.failure = "the write watch"; return probe; }`. On Linux `WriteWatched()` is `GuestWriteWatchAvailable()`, so the probe always fails there, `dmaBufImportsCoherent` keeps its default, and nothing is measured. The early return was removed from the host probe (`ProbeImportWriteProtection`) but not from the dma-buf one. Your 0-stale run was on RX 9070 XT, which has a write watch, so it went down the watched branch. - Ask: drop that early return in `ProbeDmaBufImportWriteProtection`, guard its `GuestWriteWatchRegister`/`Unregister` calls the way the host probe does, and log "not measured" when `failure != nullptr` (it currently prints "CPU-coherent (0 of 0 pages stale)" for an unmeasured device). - The measurement itself is a valid coherence test without a watch (CPU store through the `MAP_SHARED` memfd, fenced GPU fill, plain read), so this is only about letting it run. **2. The mixed-watch path ignores the coherence result.** In `importRunAt`, the branch `if (step != nullptr && watchedDmaBuf != watchedHostPointer)` calls `createBackingImport` with no `dmaBufImportsCoherent` check. On a watched i915 whose dma-buf and host watch decisions differ, it imports dma-buf right after logging "dma-buf imports are not CPU-coherent and are not used". Main added that path after #4449, so the gap is new in the port. - Ask: add `&& state.dmaBufImportsCoherent` to that condition. Smaller notes: - A test on the no-watch branch would have caught (1); one is worth adding if it's practical. The new `CheckDirectMemorySharedBackingRuns` test is good (runs, `pread` offset, capacity), but nothing covers the `CREATE_LIST` import, the probe or the mixed-path gate. - In that test, the capacity-1 call leaks the dup'd fd when it returns true. - With `dmaBufImportsCoherent` defaulting to true, the `APS5_WRITE_WATCH_IMPORTS` overrides and a dma-buf probe failure on the watched branch still leave the fallback on. That's the same as main today, so it's not blocking. On where it lands: from the code side either way works, since it fully replaces #4449's diff. That choice is @Mouad-Scriptz-0's. It's a guest-memory change, so after the fixes it gets full CI on the exact head and our game checks.
alfalfa-star commented 2026-10-17 10:38:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-17T10:38:00Z.


A data point for the run-list idea, from our own variant, not from this PR. In #6951 (since cut down to a run memo) I had imported windows whose direct-memory backing is scattered as one UDMABUF_CREATE_LIST. When sharedBacking failed it ran by default on Linux, much like this PR's several-runs path.

Kena: Bridge of Spirits (PPSA01802), forest title scene, no input. main f8b22edfb, APS5_TRACE_SECONDS=100:30, warm cache, three rotated rounds. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release. Presents in 30 s:

build presents in 30 s
main + a run-bounds memo 234 / 243 / 244
the same + the run-list import 344 / 323 / 314
main 191 / 227 / 208

So about +36 % over the memo alone in this scene; Kena maps its pools in many small direct-memory pieces. I haven't run this PR or the port/4449 branch. Once the port is the PR's base, I can run the same scene on it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232903190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6232903190). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-17T10:38:00Z. --- A data point for the run-list idea, from our own variant, not from this PR. In #6951 (since cut down to a run memo) I had imported windows whose direct-memory backing is scattered as one `UDMABUF_CREATE_LIST`. When `sharedBacking` failed it ran by default on Linux, much like this PR's several-runs path. Kena: Bridge of Spirits (PPSA01802), forest title scene, no input. `main` f8b22edfb, `APS5_TRACE_SECONDS=100:30`, warm cache, three rotated rounds. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release. Presents in 30 s: | build | presents in 30 s | |---|---| | `main` + a run-bounds memo | 234 / 243 / 244 | | the same + the run-list import | 344 / 323 / 314 | | `main` | 191 / 227 / 208 | So about +36 % over the memo alone in this scene; Kena maps its pools in many small direct-memory pieces. I haven't run this PR or the `port/4449` branch. Once the port is the PR's base, I can run the same scene on it. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-17 10:44:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T10:44:59Z.


Thanks, that's a useful data point: +36% over the memo alone in a scene that maps its pools in many small pieces is a good argument for the run-list path. A run on the port branch, once it's this PR's base, would be welcome, ideally with the same scene and the same three rotated rounds so the numbers compare directly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232968912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6232968912). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T10:44:59Z. --- Thanks, that's a useful data point: +36% over the memo alone in a scene that maps its pools in many small pieces is a good argument for the run-list path. A run on the port branch, once it's this PR's base, would be welcome, ideally with the same scene and the same three rotated rounds so the numbers compare directly.
Mouad-Scriptz-0 commented 2026-10-18 12:22:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-18T12:22:12Z.


@blawesom's port/4449 is now this PR's head, rebased onto main 9f25d0bf5 (249ef873b, authorship kept; the only conflict was the debt file, both entries stay), with the review's fixes on top in ca1d48211:

  • ProbeDmaBufImportWriteProtection no longer returns early without a write watch; it registers, collects and unregisters the watch only where one exists, as the host probe does, so the no-watch branch of decideImportWatch measures on Linux.
  • That branch logs dma-buf coherence not measured (probe failed at %s, %d) when the probe fails, instead of reporting an unmeasured device as coherent.
  • The mixed-watch branch of importRunAt requires state.dmaBufImportsCoherent.
  • CheckDirectMemorySharedBackingRuns closes the duplicated file of the capacity-1 call when it succeeds.

Fedora 44, Intel Arc Meteor Lake, Mesa 26.2: guest_memory, agc_dma_data_tests, agc_write_watch_coverage, agc_host_import_unmap, agc_driver_host_import_at_map and agc_driver_host_import_teardown pass; the probe here reports 4 of 4 pages stale after a GPU store, so the fallback stays off on this GPU. Conventions and git diff --check pass. The description is rewritten for the port. Not covered yet: a test on the no-watch branch and coverage of the CREATE_LIST import, the probe and the mixed gate; I would take those as a follow-up unless you want them here.

@alfalfa-star, this head is the port plus those fixes, if the Kena scene with the same three rotated rounds is still on offer.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249859321 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6249859321). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-18T12:22:12Z. --- @blawesom's `port/4449` is now this PR's head, rebased onto `main` `9f25d0bf5` (`249ef873b`, authorship kept; the only conflict was the debt file, both entries stay), with the review's fixes on top in `ca1d48211`: - `ProbeDmaBufImportWriteProtection` no longer returns early without a write watch; it registers, collects and unregisters the watch only where one exists, as the host probe does, so the no-watch branch of `decideImportWatch` measures on Linux. - That branch logs `dma-buf coherence not measured (probe failed at %s, %d)` when the probe fails, instead of reporting an unmeasured device as coherent. - The mixed-watch branch of `importRunAt` requires `state.dmaBufImportsCoherent`. - `CheckDirectMemorySharedBackingRuns` closes the duplicated file of the capacity-1 call when it succeeds. Fedora 44, Intel Arc Meteor Lake, Mesa 26.2: `guest_memory`, `agc_dma_data_tests`, `agc_write_watch_coverage`, `agc_host_import_unmap`, `agc_driver_host_import_at_map` and `agc_driver_host_import_teardown` pass; the probe here reports 4 of 4 pages stale after a GPU store, so the fallback stays off on this GPU. Conventions and `git diff --check` pass. The description is rewritten for the port. Not covered yet: a test on the no-watch branch and coverage of the `CREATE_LIST` import, the probe and the mixed gate; I would take those as a follow-up unless you want them here. @alfalfa-star, this head is the port plus those fixes, if the Kena scene with the same three rotated rounds is still on offer.
Pacuka commented 2026-10-18 12:58:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-18T12:58:23Z.


AMD data point (the PR was only tested on Intel, where the fallback stays off): The Smurfs - Dreams (PPSA21607, Unreal Engine), CachyOS kernel 7.2.2, Ryzen 9 5950X, RX 6650 XT / RADV Mesa 26.2.4, main 9f25d0bf5 + this PR + #6208 + #6501 + #6617 + #6566 (+ unrelated local rendering fixes). Same spot in the Smurfs' Village, standing still, APS5_PROFILE_DRAW=1.

On RADV the host-pointer import of shared direct memory fails (vkAllocateMemory -1000072003), and the title's scattered direct memory (e.g. 0x1e41000000+0x800000, many 64 KiB runs of the backing file) was not covered by the single-offset dma-buf fallback, so those ranges fell back to copies, and small DMA stores into them took commitDmaStore's WaitIdle path. A gdb sample of the committer showed ~38% of its time in commitDmaStore → VulkanDevice::WaitIdle.

With this PR the probe reports 0 stale after a GPU store over CPU writes, so dma-buf imports stay on, and every import succeeds (12 failures → 0):

  • presents per 10 s: 80–83 → 142–145 (~8.2 → ~14.4 fps, about +75%)
  • committer: ~70 → ~38 us per commit (~125k → ~215k commits per 10 s)
  • GPU idle per frame: ~78 → ~28 ms
  • DMA stores: 36k on the GPU / 157k on the CPU (idle) → 564k on the GPU / 22k on the CPU

The image is correct. The only flicker (a ground shadow briefly getting lighter) was there before and is unchanged.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250196636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6250196636). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-18T12:58:23Z. --- AMD data point (the PR was only tested on Intel, where the fallback stays off): The Smurfs - Dreams (PPSA21607, Unreal Engine), CachyOS kernel 7.2.2, Ryzen 9 5950X, RX 6650 XT / RADV Mesa 26.2.4, main 9f25d0bf5 + this PR + #6208 + #6501 + #6617 + #6566 (+ unrelated local rendering fixes). Same spot in the Smurfs' Village, standing still, `APS5_PROFILE_DRAW=1`. On RADV the host-pointer import of shared direct memory fails (`vkAllocateMemory` -1000072003), and the title's scattered direct memory (e.g. `0x1e41000000+0x800000`, many 64 KiB runs of the backing file) was not covered by the single-offset dma-buf fallback, so those ranges fell back to copies, and small DMA stores into them took `commitDmaStore`'s `WaitIdle` path. A gdb sample of the committer showed ~38% of its time in `commitDmaStore` → `VulkanDevice::WaitIdle`. With this PR the probe reports `0 stale after a GPU store over CPU writes`, so dma-buf imports stay on, and every import succeeds (12 failures → 0): - presents per 10 s: 80–83 → **142–145** (~8.2 → ~14.4 fps, about +75%) - committer: ~70 → ~38 us per commit (~125k → ~215k commits per 10 s) - GPU idle per frame: ~78 → ~28 ms - DMA stores: 36k on the GPU / 157k on the CPU (idle) → 564k on the GPU / 22k on the CPU The image is correct. The only flicker (a ground shadow briefly getting lighter) was there before and is unchanged. AI-assisted (Claude Code).
Pacuka commented 2026-10-18 13:02:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-18T13:02:39Z.


Follow-up: without APS5_PROFILE_DRAW the same build runs at ~17 fps in the Smurfs' Village (it was ~6–7 fps this morning without this PR and the other perf PRs). The ground-shadow flicker I mentioned above is gone too in this run, so it was probably a timing effect of the slow frames, not something this PR changes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250237793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6250237793). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-18T13:02:39Z. --- Follow-up: without `APS5_PROFILE_DRAW` the same build runs at ~17 fps in the Smurfs' Village (it was ~6–7 fps this morning without this PR and the other perf PRs). The ground-shadow flicker I mentioned above is gone too in this run, so it was probably a timing effect of the slow frames, not something this PR changes. AI-assisted (Claude Code).
alfalfa-star commented 2026-10-18 13:33:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-18T13:33:36Z.


@Mouad-Scriptz-0 @oneandonlydean Kena on this head (ca1d48211) against its base main 9f25d0bf5. Same setup as my 10-17 numbers: forest title scene, no input, APS5_TRACE_SECONDS=100:30, warm cache, three rotated rounds of 150 s. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release.

build presents in 30 s frame p50 (ms) GPU busy per present (ms) host import ... failed lines
main 9f25d0bf5 189 / 236 / 242 154 / 126 / 119 70.8 / 66.9 / 66.9 59 / 52 / 55
+ #4449 345 / 317 / 344 86 / 94 / 85 62.3 / 68.1 / 62.7 0 / 0 / 0

That is about +51% (mean 335 against 222 presents). It matches the 344 / 323 / 314 from our own run-list variant on 10-17, so the port keeps the gain. On main, the failures are host imports of Kena's 8 MiB pool windows (0x13c2800000+0x800000 failed at vkAllocateMemory (-1000072003); falling back to copies). With the PR all of them import.

The probe on this GPU (write watch present, so the watched branch) keeps the fallback on:

[write-watch] dma-buf imports keep write protection: yes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import, 1 seen after a CPU store, 0 stale after a GPU store over CPU writes); imported ranges stay watched

No crash, skip or GPU reset in any of the six runs. These were perf runs without frame dumps, so they say nothing about the image. Tests on the head: the 24 guest_memory, host-import, write-watch and DMA tests pass. I didn't cover the no-watch branch: this machine has a write watch.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250532314 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6250532314). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-18T13:33:36Z. --- @Mouad-Scriptz-0 @oneandonlydean Kena on this head (ca1d48211) against its base `main` 9f25d0bf5. Same setup as my 10-17 numbers: forest title scene, no input, `APS5_TRACE_SECONDS=100:30`, warm cache, three rotated rounds of 150 s. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release. | build | presents in 30 s | frame p50 (ms) | GPU busy per present (ms) | `host import ... failed` lines | |---|---|---|---|---| | `main` 9f25d0bf5 | 189 / 236 / 242 | 154 / 126 / 119 | 70.8 / 66.9 / 66.9 | 59 / 52 / 55 | | + #4449 | **345 / 317 / 344** | **86 / 94 / 85** | 62.3 / 68.1 / 62.7 | **0 / 0 / 0** | That is about +51% (mean 335 against 222 presents). It matches the 344 / 323 / 314 from our own run-list variant on 10-17, so the port keeps the gain. On `main`, the failures are host imports of Kena's 8 MiB pool windows (`0x13c2800000+0x800000 failed at vkAllocateMemory (-1000072003); falling back to copies`). With the PR all of them import. The probe on this GPU (write watch present, so the watched branch) keeps the fallback on: ``` [write-watch] dma-buf imports keep write protection: yes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import, 1 seen after a CPU store, 0 stale after a GPU store over CPU writes); imported ranges stay watched ``` No crash, skip or GPU reset in any of the six runs. These were perf runs without frame dumps, so they say nothing about the image. Tests on the head: the 24 `guest_memory`, host-import, write-watch and DMA tests pass. I didn't cover the no-watch branch: this machine has a write watch. AI-assisted: yes (Claude Code)
Pacuka commented 2026-10-18 18:47:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-18T18:47:17Z.


Another AMD data point, on a Unity title this time: Subnautica (PPSA02453), CachyOS kernel 7.2.2, Ryzen 9 5950X, RX 6650 XT / RADV Mesa 26.2.4, Release. Both builds without any env switches.

  • Plain main 61d3d3080 (no PRs): boots, title screen, new game, the lifepod intro (fire, emergency boot), outside on the ocean and underwater. Rendering looks right, but it's slow. Loading stalls for minutes on the progress bar (Unity prints Forcing submitDone to avoid TRC R4089 breach while the GPU thread is busy). The log shows 32 host import of 0x2xx000000+0x800000 failed at vkAllocateMemory (-1000072003); falling back to copies. gdb samples of the draw thread land in HostImportFor → GuestAllocationsAcquire.
  • main 61d3d3080 + this PR (ca1d48211, clean merge): 0 host import failures, same image.
spot main + #4449
title screen ~20 fps 33-35 fps
lifepod fire ~5 fps ~13 fps
ocean surface ~10 fps ~14 fps
underwater – ~14 fps

(FPS from the window title, rough numbers from normal play, not a same-spot benchmark.)

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253726244 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6253726244). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-18T18:47:17Z. --- Another AMD data point, on a **Unity** title this time: **Subnautica** (PPSA02453), CachyOS kernel 7.2.2, Ryzen 9 5950X, RX 6650 XT / RADV Mesa 26.2.4, Release. Both builds without any env switches. - **Plain `main` 61d3d3080** (no PRs): boots, title screen, new game, the lifepod intro (fire, emergency boot), outside on the ocean and underwater. Rendering looks right, but it's slow. Loading stalls for minutes on the progress bar (Unity prints `Forcing submitDone to avoid TRC R4089 breach` while the GPU thread is busy). The log shows 32 `host import of 0x2xx000000+0x800000 failed at vkAllocateMemory (-1000072003); falling back to copies`. gdb samples of the draw thread land in `HostImportFor` → `GuestAllocationsAcquire`. - **`main` 61d3d3080 + this PR** (ca1d48211, clean merge): 0 host import failures, same image. | spot | `main` | + #4449 | |---|---|---| | title screen | ~20 fps | 33-35 fps | | lifepod fire | ~5 fps | ~13 fps | | ocean surface | ~10 fps | ~14 fps | | underwater | – | ~14 fps | (FPS from the window title, rough numbers from normal play, not a same-spot benchmark.) AI-assisted (Claude Code).
Pacuka commented 2026-10-19 17:38:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-19T17:38:13Z.


Another Unity data point: Subnautica: Below Zero (PPSA02457), CachyOS kernel 7.2.2, Ryzen 9 5950X, RX 6650 XT / RADV Mesa 26.2.4, Release, APS5_PROFILE_DRAW=1 only (for the present counts).

  • Plain main 7a015c094 (no PRs): boots, loads, plays the intro and gives player control afterwards; the image looks right. 27 host import ... failed lines. The first run stalled during loading (no presents for over 3 minutes, Forcing submitDone to avoid TRC R4089 breach repeating), and a restart got through. In game after the intro: ~92 presents per 10 s.
  • main a4c04c75d + this PR + #6959 + #6948 + #6501 + #6617 (APS5_PIPELINE_DMA=1): 0 host-import failures, no loading stall, same image; in game after the intro: 145–158 presents per 10 s.

The second build stacks several open PRs, so the gain isn't from this PR alone. The host-import failures going to 0 is the part that matches this PR, like on Subnautica.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273368796 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6273368796). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-19T17:38:13Z. --- Another Unity data point: **Subnautica: Below Zero** (PPSA02457), CachyOS kernel 7.2.2, Ryzen 9 5950X, RX 6650 XT / RADV Mesa 26.2.4, Release, `APS5_PROFILE_DRAW=1` only (for the present counts). - **Plain `main` 7a015c094** (no PRs): boots, loads, plays the intro and gives player control afterwards; the image looks right. 27 `host import ... failed` lines. The first run stalled during loading (no presents for over 3 minutes, `Forcing submitDone to avoid TRC R4089 breach` repeating), and a restart got through. In game after the intro: ~92 presents per 10 s. - **`main` a4c04c75d + this PR + #6959 + #6948 + #6501 + #6617** (`APS5_PIPELINE_DMA=1`): 0 host-import failures, no loading stall, same image; in game after the intro: 145–158 presents per 10 s. The second build stacks several open PRs, so the gain isn't from this PR alone. The host-import failures going to 0 is the part that matches this PR, like on Subnautica. AI-assisted (Claude Code).
JJenkx commented 2026-10-19 22:01:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T22:01:32Z.


While integrating this work for Lodoss PPSA05347, I found a backing-descriptor ownership issue that is still present in the current patch at fa671820514f.

createBackingImport now receives the duplicated backing file as a raw integer. When the chunked import succeeds, or the sparse path succeeds or throws, it returns before the consuming createDmaBufImport call. Those paths do not close this backing descriptor; removing BackingFile also removed the former scope cleanup.

I retained scope ownership until handing the descriptor to createDmaBufImport via std::exchange. I also added fcntl(F_GETFD) / EBADF assertions for chunk success, sparse success and throwing sparse import paths. The local combined stack passes the same 20 focused tests with physical RADV, shader cache disabled and Vulkan validation, without skips, missing-layer diagnostics or VUIDs. The tests were run in the combined stack, not in isolation on this PR's exact head.

Focused two-file source/test patch. Please feel free to fold this into this PR; I am not opening a competing implementation PR. Combined-stack test logs and matched game evidence are available, with the composition limitations stated there.

AI-assisted review, patch and testing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278350290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6278350290). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-19T22:01:32Z. --- While integrating this work for Lodoss PPSA05347, I found a backing-descriptor ownership issue that is still present in the current patch at `fa671820514f`. `createBackingImport` now receives the duplicated backing `file` as a raw integer. When the chunked import succeeds, or the sparse path succeeds or throws, it returns before the consuming `createDmaBufImport` call. Those paths do not close this backing descriptor; removing `BackingFile` also removed the former scope cleanup. I retained scope ownership until handing the descriptor to `createDmaBufImport` via `std::exchange`. I also added `fcntl(F_GETFD)` / `EBADF` assertions for chunk success, sparse success and throwing sparse import paths. The local combined stack passes the same 20 focused tests with physical RADV, shader cache disabled and Vulkan validation, without skips, missing-layer diagnostics or VUIDs. The tests were run in the combined stack, not in isolation on this PR's exact head. [Focused two-file source/test patch](https://github.com/JJenkx/AnyPS5/releases/download/game-library-checks-20261016/agc-backing-descriptor-ownership.patch). Please feel free to fold this into this PR; I am not opening a competing implementation PR. [Combined-stack test logs and matched game evidence](https://github.com/boykopovar/AnyPS5/discussions/6460#discussioncomment-19052670) are available, with the composition limitations stated there. AI-assisted review, patch and testing.
oneandonlydean commented 2026-10-20 01:53:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T01:53:27Z.


@Mouad-Scriptz-0 We confirmed JJenkx's report on fa671820514f by reading the code. createBackingImport takes the backing fd as a raw int, and only createDmaBufImport closes it. The chunked-success return, the sparse-success return and a sparse-import throw all leave without closing it. That leaks one memfd per successful chunked or sparse import and per sparse failure. These are the common RADV paths this PR adds, and they run again on every re-import, so a long session can reach the fd limit. Main had BackingFile RAII here, and this head removes it.

Could you restore scope ownership on both callers (createSharedBackingImport and the runs path in the import function)? A BackingFile-style guard works, and so does JJenkx's std::exchange hand-off into createDmaBufImport. Please also add a test that checks fcntl(fd, F_GETFD) == -1 && errno == EBADF after a chunk success, a sparse success and a sparse throw.

Apart from this, the content matches the head we already ran the no-worse gate on, so an fd-ownership-only fix needs just CI and a quick re-review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281482904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6281482904). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T01:53:27Z. --- @Mouad-Scriptz-0 We confirmed JJenkx's report on `fa671820514f` by reading the code. `createBackingImport` takes the backing fd as a raw `int`, and only `createDmaBufImport` closes it. The chunked-success return, the sparse-success return and a sparse-import throw all leave without closing it. That leaks one memfd per successful chunked or sparse import and per sparse failure. These are the common RADV paths this PR adds, and they run again on every re-import, so a long session can reach the fd limit. Main had `BackingFile` RAII here, and this head removes it. Could you restore scope ownership on both callers (`createSharedBackingImport` and the runs path in the import function)? A `BackingFile`-style guard works, and so does JJenkx's `std::exchange` hand-off into `createDmaBufImport`. Please also add a test that checks `fcntl(fd, F_GETFD) == -1 && errno == EBADF` after a chunk success, a sparse success and a sparse throw. Apart from this, the content matches the head we already ran the no-worse gate on, so an fd-ownership-only fix needs just CI and a quick re-review.
socket1001 commented 2026-10-20 18:55:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-20T18:55:59Z.


AMD data point: RX 9070 (RDNA 4), with a same-tree control.

AI-assisted: yes. These numbers were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted.

Environment

  • AM5, Ubuntu 24.04, kernel 7.0.0-38-generic, Mesa 25.2.8, RADV
  • GPU: Radeon RX 9070, 1002:7550, renderD128 (RDNA 4)
  • Title: Mafia: The Old Country (PPSA14299), fully relinked against the same source tree
  • Build: v0.1.3 tag (3fd1cc393) plus this PR's current head fa671820; the 6 code hunks applied, only the docs/ hunk did not apply to that tag
  • Knob: APS5_TRACE_HOST_IMPORT=1, no other switches

Same-tree control (RX 9070)

build FPS (10 s samples) import attempts -13 failures copy fallback storage-image races
v0.1.3, this PR reverted 3.31 - 3.46 40 7 yes 8
v0.1.3 + this PR 25.60 - 26.82 3857 0 none 8

7.75x from the PR alone (mean 3.402 vs 26.358 FPS; 7.73x min/min, 7.75x max/max): the control is the same tree with the PR's commit reverted, rebuilt and relinked, with the title and knobs unchanged. Both FPS ranges are the last 5 of 6 samples per leg, the first being warm-up; the final win : FPS: 3.38 line in the control log is a final-window statistic, not a sample.

Updated: the per-leg table, the corrected numbers and the current-head-vs-main A/B are in the follow-up comment.

Why RADV needs the run list

Without the PR the host-pointer import of the direct-memory arena fails on RADV:

[gpu] host import of 0x1e40000000+0x80000 failed at vkAllocateMemory (-13); falling back to copies, requested by map
[gpu]   1e40000000-1e40010000 rw-s 13e20000 00:01 93464   /memfd:direct memory (deleted)

-13 is VK_ERROR_UNKNOWN; the trace prints the raw VkResult. A standalone Vulkan program on this device reproduces the mechanism:

  • host-pointer import of a memfd-backed mapping (VkImportMemoryHostPointerInfoEXT + vkAllocateMemory): -13
  • udmabuf import of the same bytes: VK_SUCCESS
  • sparse buffer bound to two dma-bufs at discontinuous file offsets (VK_BUFFER_CREATE_SPARSE_BINDING_BIT + vkQueueBindSparse): VK_SUCCESS

So on RADV the arena cannot come in as a host pointer, and the dma-buf path is the one that works - which is what the run list makes usable for a range that spans several physical allocations. With the PR the chain stops at "falling back to copies" and the import succeeds by map.

Coherence probe on this device

[write-watch] host imports resolve write protection: yes (4 of 4 scratch pages written after a GPU read, 4 after a GPU write, 4 after the import)
[write-watch] dma-buf imports keep write protection: yes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import, 1 seen after a CPU store, 0 stale after a GPU store over CPU writes); imported ranges stay watched

The probe measures this device as coherent, so the dma-buf path stays enabled here - on i915 the same probe is what turns it off and leaves the copy path in place.

The 8 storage-image races are not from this PR

Both legs show the same 8 events, with the PR and with it reverted:

[gpu] storage image 0x303fa30000: guest memory changed while GPU results were pending; keeping the CPU's blocks

Same count either way, so this PR neither causes nor fixes them. The wording matches #865's subject (storage image write-back dropping GPU results for CPU-stamped 64 KiB blocks). #4448 is adjacent - keeping storage surfaces tracked around unwatching host imports - but that is not what these lines show.

Caveats

  • Base is the v0.1.3 tag, not main. main was at b85d972f4 when this was written and is now 339217ebc; the merge-base of this PR and main is 903cbbd5, not eaa5c923 (which is 5 commits further along a side path and is not an ancestor of the head). I applied the PR head as a patch instead of rebasing onto it.
  • One title reached a rendered frame here, so the numbers are single-title.
  • The attempt count varies between runs (3857 / 3813 / 3980) because it depends on what the run touches; the failure count is the stable number. The counter the log labels host import failures is in fact the attempt count, and -13 is the allocation-failure count - the PR leg's -13: 0 means zero allocation failures, not zero attempts.

Happy to redo the A/B on port/4449 against current main if that is more useful than a tag-based build.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298732457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6298732457). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-20T18:55:59Z. --- **AMD data point: RX 9070 (RDNA 4), with a same-tree control.** AI-assisted: yes. These numbers were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted. **Environment** - AM5, Ubuntu 24.04, kernel `7.0.0-38-generic`, Mesa 25.2.8, RADV - GPU: Radeon RX 9070, `1002:7550`, `renderD128` (RDNA 4) - Title: Mafia: The Old Country (PPSA14299), fully relinked against the same source tree - Build: `v0.1.3` tag (`3fd1cc393`) plus this PR's current head `fa671820`; the 6 code hunks applied, only the `docs/` hunk did not apply to that tag - Knob: `APS5_TRACE_HOST_IMPORT=1`, no other switches **Same-tree control (RX 9070)** | build | FPS (10 s samples) | import attempts | `-13` failures | copy fallback | storage-image races | |---|---|---|---|---|---| | `v0.1.3`, this PR reverted | 3.31 - 3.46 | 40 | 7 | yes | 8 | | `v0.1.3` + this PR | 25.60 - 26.82 | 3857 | 0 | none | 8 | 7.75x from the PR alone (mean 3.402 vs 26.358 FPS; 7.73x min/min, 7.75x max/max): the control is the same tree with the PR's commit reverted, rebuilt and relinked, with the title and knobs unchanged. Both FPS ranges are the last 5 of 6 samples per leg, the first being warm-up; the `final win : FPS: 3.38` line in the control log is a final-window statistic, not a sample. **Updated:** the per-leg table, the corrected numbers and the current-head-vs-`main` A/B are in the follow-up comment. **Why RADV needs the run list** Without the PR the host-pointer import of the direct-memory arena fails on RADV: ``` [gpu] host import of 0x1e40000000+0x80000 failed at vkAllocateMemory (-13); falling back to copies, requested by map [gpu] 1e40000000-1e40010000 rw-s 13e20000 00:01 93464 /memfd:direct memory (deleted) ``` `-13` is `VK_ERROR_UNKNOWN`; the trace prints the raw `VkResult`. A standalone Vulkan program on this device reproduces the mechanism: - host-pointer import of a memfd-backed mapping (`VkImportMemoryHostPointerInfoEXT` + `vkAllocateMemory`): `-13` - `udmabuf` import of the same bytes: `VK_SUCCESS` - sparse buffer bound to two dma-bufs at discontinuous file offsets (`VK_BUFFER_CREATE_SPARSE_BINDING_BIT` + `vkQueueBindSparse`): `VK_SUCCESS` So on RADV the arena cannot come in as a host pointer, and the dma-buf path is the one that works - which is what the run list makes usable for a range that spans several physical allocations. With the PR the chain stops at "falling back to copies" and the import succeeds by map. **Coherence probe on this device** ``` [write-watch] host imports resolve write protection: yes (4 of 4 scratch pages written after a GPU read, 4 after a GPU write, 4 after the import) [write-watch] dma-buf imports keep write protection: yes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import, 1 seen after a CPU store, 0 stale after a GPU store over CPU writes); imported ranges stay watched ``` The probe measures this device as coherent, so the dma-buf path stays enabled here - on i915 the same probe is what turns it off and leaves the copy path in place. **The 8 storage-image races are not from this PR** Both legs show the same 8 events, with the PR and with it reverted: ``` [gpu] storage image 0x303fa30000: guest memory changed while GPU results were pending; keeping the CPU's blocks ``` Same count either way, so this PR neither causes nor fixes them. The wording matches #865's subject (storage image write-back dropping GPU results for CPU-stamped 64 KiB blocks). #4448 is adjacent - keeping storage surfaces tracked around unwatching host imports - but that is not what these lines show. **Caveats** - Base is the `v0.1.3` tag, not `main`. `main` was at `b85d972f4` when this was written and is now `339217ebc`; the merge-base of this PR and `main` is `903cbbd5`, not `eaa5c923` (which is 5 commits further along a side path and is not an ancestor of the head). I applied the PR head as a patch instead of rebasing onto it. - One title reached a rendered frame here, so the numbers are single-title. - The attempt count varies between runs (3857 / 3813 / 3980) because it depends on what the run touches; the failure count is the stable number. The counter the log labels `host import failures` is in fact the attempt count, and `-13` is the allocation-failure count - the PR leg's `-13: 0` means zero allocation failures, not zero attempts. Happy to redo the A/B on `port/4449` against current `main` if that is more useful than a tag-based build.
Mouad-Scriptz-0 commented 2026-10-20 19:58:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-20T19:58:09Z.


@socket1001 thank you. A same-tree control with the PR reverted is the comparison this needed, and the RADV -13 on the host-pointer import with the udmabuf and sparse-bind successes in the standalone program explains the mechanism better than my i915 data could. Yes to the A/B on this branch's current head against main: that is what @oneandonlydean asked for on the 17th, same scene with the rounds rotated, and it replaces the tag-based base. The 8 storage-image races being identical on both legs is useful too; I'll quote that on #4448, the adjacent PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300174886 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6300174886). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-20T19:58:09Z. --- @socket1001 thank you. A same-tree control with the PR reverted is the comparison this needed, and the RADV `-13` on the host-pointer import with the udmabuf and sparse-bind successes in the standalone program explains the mechanism better than my i915 data could. Yes to the A/B on this branch's current head against `main`: that is what @oneandonlydean asked for on the 17th, same scene with the rounds rotated, and it replaces the tag-based base. The 8 storage-image races being identical on both legs is useful too; I'll quote that on #4448, the adjacent PR.
socket1001 commented 2026-10-20 21:59:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-20T21:59:05Z.


AI-assisted: yes. These numbers were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted.

A/B on this branch's current head against main.

Device attribution

Every leg in this comment reports device selected: AMD Radeon RX 9070 (RADV GFX1201), PCI 1002:7550, ~4.1 GiB VRAM in use, and the launcher's runtime device assertion passes on every leg.

The A/B that was asked for

Current head vs main, same title (PPSA14299), three rotated rounds (R1 = A/B, R2 = B/A, R3 = A/B, so each arm gets the same slot mix), same knobs, RX 9070 only. Every leg was pinned to the RX 9070 by PCI id (1002:7550) so no other device can confound it.

Arm A = main @ 73b6a4cc7144d80ba5c720306ec1516728dfb59b
Arm B = this branch's current head @ fa671820514fb212b83abbbfc0b7ca0eddea0115 (fix/dmabuf-import-coherence)

Deck check: main and the isolation arm each link 354 PRX libs; the head arm links 352 - libSceAt9Enc and libSceM4aacEnc were added to main after the fork point, so only the head arm carries that deck-set difference.

leg build FPS (steady state) host import attempts import failures storage-image races asserts faults
n3-A-r1 main 3.29 - 3.54 117 12 8 0 0
n3-B-r1 head 22.32 - 22.65 3894 0 8 0 0
n3-B-r2 head 22.17 - 22.79 4112 0 8 0 0
n3-A-r2 main 3.12 - 3.42 107 12 0 0 0
n3-A-r3 main 3.23 - 3.50 107 13 8 0 0
n3-B-r3 head 22.15 - 22.65 3826 0 8 0 0

(FPS is the steady-state range over the last 5 of 6 samples per leg; the first sample is warm-up.)

~6.60x FPS (mean 3.400 vs 22.453; 6.26x comparing each arm's worst leg to the other's best), ~3800-4100 host imports per leg with zero failures against main's 107-117 attempts with 12-13 failures, and 0 asserts / 0 device faults in all 6 legs. The storage-image races show up on both arms (0-8 on main, 8 on head), so they are not introduced by this PR.

Isolation arm

The head forks from main at 903cbbd5, and main has moved 920 commits / 785 files between that fork point and the 73b6a4cc I benchmarked against, so head-vs-main alone cannot attribute the win to this PR. I also ran a third arm: main @ 73b6a4cc plus the PR's import-path commit e00eaac2f only cherry-picked on top (all six source files apply cleanly; only docs/dev/debt/libSceAgcDriver.md conflicts, resolved by taking the PR's version). That arm is not the full PR: the head's second commit fa671820 - which runs the coherence probe without a write watch and gates the mixed-watch import on it - is absent from it.

leg build FPS (steady state) host import attempts import failures storage-image races asserts faults
n2-A-r1 main 3.23 - 3.52 117 15 1 0 0
n2-B-r1 main+e00eaac2f 25.12 - 26.73 3919 0 8 0 0
n2-B-r2 main+e00eaac2f 25.69 - 26.83 3853 0 8 0 0
n2-A-r2 main 3.20 - 3.27 143 17 0 0 0
n2-A-r3 main 3.10 - 3.49 108 12 8 0 0
n2-B-r3 main+e00eaac2f 25.40 - 26.79 3851 0 8 0 0

~7.82x FPS on current main with the import-path commit alone (mean 3.344 vs 26.145; 8.10x worst-vs-worst). The win is attributable to this PR's import path, not to upstream churn - and it does not require the coherence-gate commit, since that commit is not in this arm.

What the numbers show about the mechanism

The PR description says the dma-buf fallback of host imports had two problems, one being that a guest range mapped from several physical allocations is several runs, while the fallback took one offset for the whole range. The logs line up with that:

  • On main, the scattered-range imports fail outright and fall back to copies: host import of 0x1e40000000+0x80000 failed at vkAllocateMemory (-13); falling back to copies. 12-17 per leg, across a spread of sizes (+0x20000, +0x40000, +0x80000).
  • On the head and the main+e00eaac2f arm, the same address and size succeeds: host import of 0x1e40000000+0x80000 ok (2 live, 0.6 MiB live, 0.6 MiB ever) by map. Zero import failures in all six legs of each A/B.
  • The dma-buf import path is correspondingly exercised far more: settled the dma-buf import of ... goes from 4-5 per leg on main to 270-290 per leg on the PR arms, and copy fallbacks go from 12-17 per leg to 0.

On the coherence probe, on AMD

The PR description reports the probe measuring 4 stale after a GPU store over CPU writes on Intel, so the dma-buf fallback stays off there. On this AMD GPU the probe reports 0 stale after a GPU store over CPU writes (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import), so the measured device is coherent and the dma-buf import path stays enabled — which is what makes the head/mixed arms above run at all. Worth recording, since the PR lists AMD as untested.

One note on main moving again

main advanced once more after this was measured - it is now 339217ebc90f6fe91556525425aa18292d5f563b, 18 commits past the 73b6a4cc I benchmarked against. I checked that delta: it touches the shader recompiler, the audio export tables, an AGC perf change and a libkernel_sys readlink fix, and no file in the host-import / dma-buf path (GuestBufferMemory.cpp, DirectMemory and the udmabuf run-list code are all untouched). So I would expect the numbers to carry over to the newer main - but I have not re-measured them and am not claiming that I have. Everything above is measured against 73b6a4cc as stated.

Caveats

  • One title (PPSA14299) on one machine, one GPU model (RX 9070), 70s per leg, 3 rotated rounds. Not a matrix.
  • The head-vs-main arm necessarily carries 920 commits / 785 files of upstream churn plus a two-library deck difference; the isolation arm carries 354 libs like main and differs by one commit, so it is the one that attributes the win to this PR's import path.

If it would help, I can run more titles, longer legs, or the same A/B on the Intel Arc, and I can supply the raw logs and the exact build commands for either arm.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302645176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6302645176). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-20T21:59:05Z. --- AI-assisted: yes. These numbers were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted. > **A/B on this branch's current head against `main`.** > > ### Device attribution > > Every leg in this comment reports `device selected: AMD Radeon RX 9070 (RADV GFX1201)`, PCI `1002:7550`, ~4.1 GiB VRAM in use, and the launcher's runtime device assertion passes on every leg. > > ### The A/B that was asked for > > Current head vs `main`, same title (`PPSA14299`), three rotated rounds (R1 = A/B, R2 = B/A, R3 = A/B, so each arm gets the same slot mix), same knobs, RX 9070 only. Every leg was pinned to the RX 9070 by PCI id (`1002:7550`) so no other device can confound it. > > **Arm A** = `main` @ `73b6a4cc7144d80ba5c720306ec1516728dfb59b` > **Arm B** = this branch's current head @ `fa671820514fb212b83abbbfc0b7ca0eddea0115` (`fix/dmabuf-import-coherence`) > > Deck check: `main` and the isolation arm each link **354** PRX libs; the **head arm links 352** - `libSceAt9Enc` and `libSceM4aacEnc` were added to `main` after the fork point, so only the head arm carries that deck-set difference. > > | leg | build | FPS (steady state) | host import attempts | import failures | storage-image races | asserts | faults | > |---|---|---|---|---|---|---|---| > | n3-A-r1 | `main` | 3.29 - 3.54 | 117 | 12 | 8 | 0 | 0 | > | n3-B-r1 | head | 22.32 - 22.65 | 3894 | 0 | 8 | 0 | 0 | > | n3-B-r2 | head | 22.17 - 22.79 | 4112 | 0 | 8 | 0 | 0 | > | n3-A-r2 | `main` | 3.12 - 3.42 | 107 | 12 | 0 | 0 | 0 | > | n3-A-r3 | `main` | 3.23 - 3.50 | 107 | 13 | 8 | 0 | 0 | > | n3-B-r3 | head | 22.15 - 22.65 | 3826 | 0 | 8 | 0 | 0 | > > (FPS is the steady-state range over the last 5 of 6 samples per leg; the first sample is warm-up.) > > **~6.60x FPS** (mean 3.400 vs 22.453; 6.26x comparing each arm's worst leg to the other's best), **~3800-4100 host imports per leg with zero failures** against `main`'s 107-117 attempts with 12-13 failures, and **0 asserts / 0 device faults in all 6 legs**. The storage-image races show up on both arms (0-8 on `main`, 8 on head), so they are not introduced by this PR. > > ### Isolation arm > > The head forks from `main` at `903cbbd5`, and `main` has moved **920 commits / 785 files** between that fork point and the `73b6a4cc` I benchmarked against, so head-vs-`main` alone cannot attribute the win to this PR. I also ran a third arm: `main` @ `73b6a4cc` plus the PR's **import-path commit `e00eaac2f` only** cherry-picked on top (all six source files apply cleanly; only `docs/dev/debt/libSceAgcDriver.md` conflicts, resolved by taking the PR's version). That arm is *not* the full PR: the head's second commit `fa671820` - which runs the coherence probe without a write watch and gates the mixed-watch import on it - is absent from it. > > | leg | build | FPS (steady state) | host import attempts | import failures | storage-image races | asserts | faults | > |---|---|---|---|---|---|---|---| > | n2-A-r1 | `main` | 3.23 - 3.52 | 117 | 15 | 1 | 0 | 0 | > | n2-B-r1 | `main`+`e00eaac2f` | 25.12 - 26.73 | 3919 | 0 | 8 | 0 | 0 | > | n2-B-r2 | `main`+`e00eaac2f` | 25.69 - 26.83 | 3853 | 0 | 8 | 0 | 0 | > | n2-A-r2 | `main` | 3.20 - 3.27 | 143 | 17 | 0 | 0 | 0 | > | n2-A-r3 | `main` | 3.10 - 3.49 | 108 | 12 | 8 | 0 | 0 | > | n2-B-r3 | `main`+`e00eaac2f` | 25.40 - 26.79 | 3851 | 0 | 8 | 0 | 0 | > > **~7.82x FPS** on current `main` with the import-path commit alone (mean 3.344 vs 26.145; 8.10x worst-vs-worst). The win is attributable to this PR's import path, not to upstream churn - and it does not require the coherence-gate commit, since that commit is not in this arm. > > ### What the numbers show about the mechanism > > The PR description says the dma-buf fallback of host imports had two problems, one being that a guest range mapped from several physical allocations is several runs, while the fallback took one offset for the whole range. The logs line up with that: > > - On `main`, the scattered-range imports **fail outright** and fall back to copies: `host import of 0x1e40000000+0x80000 failed at vkAllocateMemory (-13); falling back to copies`. 12-17 per leg, across a spread of sizes (`+0x20000`, `+0x40000`, `+0x80000`). > - On the head and the `main`+`e00eaac2f` arm, the **same address and size succeeds**: `host import of 0x1e40000000+0x80000 ok (2 live, 0.6 MiB live, 0.6 MiB ever) by map`. Zero import failures in all six legs of each A/B. > - The dma-buf import path is correspondingly exercised far more: `settled the dma-buf import of ...` goes from **4-5 per leg** on `main` to **270-290 per leg** on the PR arms, and copy fallbacks go from 12-17 per leg to **0**. > > ### On the coherence probe, on AMD > > The PR description reports the probe measuring `4 stale after a GPU store over CPU writes` on Intel, so the dma-buf fallback stays off there. On this AMD GPU the probe reports **`0 stale after a GPU store over CPU writes`** (`0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 0 after the import`), so the measured device is coherent and the dma-buf import path stays **enabled** — which is what makes the head/mixed arms above run at all. Worth recording, since the PR lists AMD as untested. > > ### One note on `main` moving again > > `main` advanced once more after this was measured - it is now `339217ebc90f6fe91556525425aa18292d5f563b`, 18 commits past the `73b6a4cc` I benchmarked against. I checked that delta: it touches the shader recompiler, the audio export tables, an AGC perf change and a `libkernel_sys` readlink fix, and **no file in the host-import / dma-buf path** (`GuestBufferMemory.cpp`, `DirectMemory` and the udmabuf run-list code are all untouched). So I would expect the numbers to carry over to the newer `main` - but I have not re-measured them and am not claiming that I have. Everything above is measured against `73b6a4cc` as stated. > > ### Caveats > > - One title (`PPSA14299`) on one machine, one GPU model (RX 9070), 70s per leg, 3 rotated rounds. Not a matrix. > - The head-vs-`main` arm necessarily carries 920 commits / 785 files of upstream churn plus a two-library deck difference; the isolation arm carries 354 libs like `main` and differs by one commit, so it is the one that attributes the win to this PR's import path. > > If it would help, I can run more titles, longer legs, or the same A/B on the Intel Arc, and I can supply the raw logs and the exact build commands for either arm.
JJenkx commented 2026-10-21 03:20:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T03:20:09Z.


Additional Linux title evidence for Lodoss (PPSA05347): adding this PR at fa671820514fb212b83abbbfc0b7ca0eddea0115, together with the backing-descriptor ownership guard reported above, eliminated the import failures in a 250-second scripted tutorial run. Full-run failure log counts changed from 542,455 to 0. The candidate shutdown counters report 712,951 successful imports, 0 refused, 0 failed; substantial successful-import recreation remains.

This is a combined-stack functional diagnostic, not an isolated main-versus-PR benchmark: previous ab5c1a66a9fc645ea0d8a1e7683c17826f02fc37 includes main 6c12024f7d9bceb93c9c9030126212ea37aee239, #8091, #8802 and cache diagnostics; candidate 47c36e0618e0ac570fe7b5825b11c0e94bf0b826 adds this PR and the descriptor guard. Both runs were instrumented and used warm caches. No FPS improvement is claimed.

The candidate passed 4/4 focused tests with Khronos validation loaded and no VUIDs or skips. The native run exited cleanly, its process was gone and the temporary kernel limit was restored. The 240-second screenshot shows the tutorial player, columns and readable sword/jump instructions. These focused checks cover the candidate stack, not a paired main validation run.

Evidence archive: logs, exact pins/protocol, counters, trace, screenshot and initial cache/save manifests (SHA256 975791677d9f1a32facb168c15652111cd7f0f3635b6d4046ddb9aa5bd49a557). The README also corrects stale protocol prose about three cache clones: only the diagnostic clone was used here.

AI-assisted testing and analysis.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307193242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6307193242). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T03:20:09Z. --- Additional Linux title evidence for Lodoss (PPSA05347): adding this PR at `fa671820514fb212b83abbbfc0b7ca0eddea0115`, together with the backing-descriptor ownership guard reported above, eliminated the import failures in a 250-second scripted tutorial run. Full-run failure log counts changed from **542,455 to 0**. The candidate shutdown counters report **712,951 successful imports, 0 refused, 0 failed**; substantial successful-import recreation remains. This is a **combined-stack functional diagnostic**, not an isolated main-versus-PR benchmark: previous `ab5c1a66a9fc645ea0d8a1e7683c17826f02fc37` includes main `6c12024f7d9bceb93c9c9030126212ea37aee239`, #8091, #8802 and cache diagnostics; candidate `47c36e0618e0ac570fe7b5825b11c0e94bf0b826` adds this PR and the descriptor guard. Both runs were instrumented and used warm caches. **No FPS improvement is claimed.** The candidate passed 4/4 focused tests with Khronos validation loaded and no VUIDs or skips. The native run exited cleanly, its process was gone and the temporary kernel limit was restored. The 240-second screenshot shows the tutorial player, columns and readable sword/jump instructions. These focused checks cover the candidate stack, not a paired main validation run. [Evidence archive: logs, exact pins/protocol, counters, trace, screenshot and initial cache/save manifests](https://github.com/JJenkx/AnyPS5/releases/download/game-library-checks-20261016/20261021-lodoss4449-diagnostic.tar.gz) (SHA256 `975791677d9f1a32facb168c15652111cd7f0f3635b6d4046ddb9aa5bd49a557`). The README also corrects stale protocol prose about three cache clones: only the diagnostic clone was used here. AI-assisted testing and analysis.
oneandonlydean commented 2026-10-21 03:38:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T03:38:33Z.


@Mouad-Scriptz-0 one blocker before merge: a file descriptor leaks in createBackingImport (core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp) at fa67182051.

On main, BackingFile owns the duplicated backing descriptor: its destructor closes it, and the descriptor is handed on only through std::exchange(backing.file, -1) to createDmaBufImport, which closes it. This PR passes the descriptor as a plain int file. createDmaBufImport is still the only call that closes it, but createBackingImport returns before reaching it in three cases:

  • createChunkedDmaBufImport succeeds (fits, returns nullptr),
  • createSparseDmaBufImport succeeds,
  • createSparseDmaBufImport throws.

Each import that takes one of these paths leaks one descriptor, from createSharedBackingImport and from the run-list import in importRunAt. A long run creates hundreds of thousands of imports, so it eventually hits the open-file limit.

JJenkx posted a fix above (keep scope ownership until the hand-off to createDmaBufImport, plus fcntl(F_GETFD) / EBADF checks on the chunk-success, sparse-success and sparse-throw paths), and offered it for folding into this PR: https://github.com/JJenkx/AnyPS5/releases/download/game-library-checks-20261016/agc-backing-descriptor-ownership.patch. Could you fold it in (with a Co-authored-by for JJenkx), or an equivalent RAII hand-off with those three tests? We'll re-check the new head and dispatch CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307432811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6307432811). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T03:38:33Z. --- @Mouad-Scriptz-0 one blocker before merge: a file descriptor leaks in `createBackingImport` (core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp) at fa671820514f. On `main`, `BackingFile` owns the duplicated backing descriptor: its destructor closes it, and the descriptor is handed on only through `std::exchange(backing.file, -1)` to `createDmaBufImport`, which closes it. This PR passes the descriptor as a plain `int file`. `createDmaBufImport` is still the only call that closes it, but `createBackingImport` returns before reaching it in three cases: - `createChunkedDmaBufImport` succeeds (`fits`, returns `nullptr`), - `createSparseDmaBufImport` succeeds, - `createSparseDmaBufImport` throws. Each import that takes one of these paths leaks one descriptor, from `createSharedBackingImport` and from the run-list import in `importRunAt`. A long run creates hundreds of thousands of imports, so it eventually hits the open-file limit. JJenkx posted a fix above (keep scope ownership until the hand-off to `createDmaBufImport`, plus `fcntl(F_GETFD)` / `EBADF` checks on the chunk-success, sparse-success and sparse-throw paths), and offered it for folding into this PR: https://github.com/JJenkx/AnyPS5/releases/download/game-library-checks-20261016/agc-backing-descriptor-ownership.patch. Could you fold it in (with a Co-authored-by for JJenkx), or an equivalent RAII hand-off with those three tests? We'll re-check the new head and dispatch CI.
JJenkx commented 2026-10-21 06:50:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T06:50:15Z.


Thanks for the run-list import; it removes almost all of the copied ranges in Echoes of the End PPSA25636 here. One limit remains: a run list whose total is above udmabuf's size_limit_mb fails with EINVAL, and on a default kernel that limit is 64 MiB.

Evidence

  • Linux 7.2.9, size_limit_mb 64 (the kernel default), list_limit 1024. A probe with a memfd sealed SHRINK|GROW (as DirectMemory.cpp makes it): UDMABUF_CREATE and UDMABUF_CREATE_LIST (2 items) both succeed up to 64 MiB and fail with EINVAL from 65 MiB, whatever the item count.
  • Echoes on main 33a6d6bbfb + #8089 + #8762 + #8091 + this PR: every remaining import failure is a join through UDMABUF_CREATE_LIST with two runs, EINVAL, aligned, unique pages inside the file: 0x30c73d0000+0x7000000 (112 MiB), 0x3124c00000+0x282b0000 (643 MiB), 0x8fc0000000+0x22000000 (544 MiB). Those ranges fall back to CPU copies.

Why single runs work. createBackingImport sends one run to createChunkedDmaBufImport (fits one 64 MiB file chunk) or createSparseDmaBufImport (a sparse buffer bound to the shared 64 MiB importChunk udmabufs). Neither makes a udmabuf above ImportChunkBytes. A run list skips both and asks createDmaBufImport for one udmabuf of the whole list.

Suggested change (one commit on this PR's head fa67182051: github.com/JJenkx/AnyPS5@d5b768f027, branch JJenkx:fix/udmabuf-runlist-on-4449): createSparseDmaBufImport takes the run list. Each run is split at 64 MiB file chunks and every piece is bound from the shared importChunk at its resource offset. It falls back as today when an interior run is off the sparse block size, a chunk's file range is past the backing file, or a chunk's memory type is not allowed. The lead of the first run, the queue, fence and chunk lifetimes are unchanged. A run list at or below 64 MiB still uses UDMABUF_CREATE_LIST.

Tests (HostImportSparseDmaBuf.cpp): ScatteredRunsAboveTheLimitBindTheirChunks (two runs at out-of-order file offsets, total above size_limit_mb; every bind maps its run's chunk at the right memory offset and the binds cover the range exactly) and UnalignedInteriorRunKeepsTheFallback (sparse block 128 KiB, interior run 64 KiB off: no binds).

  • Control, this PR's head fa67182051 with only the new tests, ctest -R '^agc_host_import_sparse$': FAIL: a range of two scattered runs larger than udmabuf's size limit was not imported, 1 sparse dma-buf import checks failed.
  • With the change: host import sparse dma-buf tests passed, 100% tests passed out of 1 (Linux 7.2.9, GCC 16, Release, size_limit_mb 64, real /dev/udmabuf with the mock Vulkan device).

On Echoes (the integration above, one 240 s run per arm, shared caches, loading screen only, so not a speed claim): import failures 3 to 0, CPU-copied bytes 1.92e6 MiB to 6.5e5 MiB, and the stall where presents stop at about 122 s did not occur within 226 s. No GPU timeout in the kernel log during those runs.

Happy to drop this if you prefer to solve it differently; feel free to fold the commit into this PR.

AI-assisted (Claude Code); I am responsible for the change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309936285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6309936285). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T06:50:15Z. --- Thanks for the run-list import; it removes almost all of the copied ranges in Echoes of the End PPSA25636 here. One limit remains: a run list whose total is above udmabuf's `size_limit_mb` fails with EINVAL, and on a default kernel that limit is 64 MiB. **Evidence** - Linux 7.2.9, `size_limit_mb` 64 (the kernel default), `list_limit` 1024. A probe with a memfd sealed SHRINK|GROW (as `DirectMemory.cpp` makes it): `UDMABUF_CREATE` and `UDMABUF_CREATE_LIST` (2 items) both succeed up to 64 MiB and fail with EINVAL from 65 MiB, whatever the item count. - Echoes on main 33a6d6bbfb + #8089 + #8762 + #8091 + this PR: every remaining import failure is a join through `UDMABUF_CREATE_LIST` with two runs, EINVAL, aligned, unique pages inside the file: 0x30c73d0000+0x7000000 (112 MiB), 0x3124c00000+0x282b0000 (643 MiB), 0x8fc0000000+0x22000000 (544 MiB). Those ranges fall back to CPU copies. **Why single runs work.** `createBackingImport` sends one run to `createChunkedDmaBufImport` (fits one 64 MiB file chunk) or `createSparseDmaBufImport` (a sparse buffer bound to the shared 64 MiB `importChunk` udmabufs). Neither makes a udmabuf above `ImportChunkBytes`. A run list skips both and asks `createDmaBufImport` for one udmabuf of the whole list. **Suggested change** (one commit on this PR's head `fa67182051`: https://github.com/JJenkx/AnyPS5/commit/d5b768f027305f50e201d6c78c831dac455260bd, branch `JJenkx:fix/udmabuf-runlist-on-4449`): `createSparseDmaBufImport` takes the run list. Each run is split at 64 MiB file chunks and every piece is bound from the shared `importChunk` at its resource offset. It falls back as today when an interior run is off the sparse block size, a chunk's file range is past the backing file, or a chunk's memory type is not allowed. The lead of the first run, the queue, fence and chunk lifetimes are unchanged. A run list at or below 64 MiB still uses `UDMABUF_CREATE_LIST`. **Tests** (`HostImportSparseDmaBuf.cpp`): `ScatteredRunsAboveTheLimitBindTheirChunks` (two runs at out-of-order file offsets, total above `size_limit_mb`; every bind maps its run's chunk at the right memory offset and the binds cover the range exactly) and `UnalignedInteriorRunKeepsTheFallback` (sparse block 128 KiB, interior run 64 KiB off: no binds). - Control, this PR's head `fa67182051` with only the new tests, `ctest -R '^agc_host_import_sparse$'`: `FAIL: a range of two scattered runs larger than udmabuf's size limit was not imported`, `1 sparse dma-buf import checks failed`. - With the change: `host import sparse dma-buf tests passed`, `100% tests passed out of 1` (Linux 7.2.9, GCC 16, Release, `size_limit_mb` 64, real `/dev/udmabuf` with the mock Vulkan device). On Echoes (the integration above, one 240 s run per arm, shared caches, loading screen only, so not a speed claim): import failures 3 to 0, CPU-copied bytes 1.92e6 MiB to 6.5e5 MiB, and the stall where presents stop at about 122 s did not occur within 226 s. No GPU timeout in the kernel log during those runs. Happy to drop this if you prefer to solve it differently; feel free to fold the commit into this PR. _AI-assisted (Claude Code); I am responsible for the change._
oneandonlydean commented 2026-10-21 06:56:19 +00:00 (Migrated from github.com)

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


@Mouad-Scriptz-0 @JJenkx found a real limit here: a run list above udmabuf's size_limit_mb (64 MiB by default) fails with EINVAL, and the suggested commit d5b768f027 binds those runs from the shared 64 MiB import chunks instead, with a test that fails without it. Thanks @JJenkx. We will review that commit; whether to fold it into this PR is your call, and the fd-ownership question above is still open.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310028856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6310028856). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T06:56:19Z. --- @Mouad-Scriptz-0 @JJenkx found a real limit here: a run list above udmabuf's `size_limit_mb` (64 MiB by default) fails with EINVAL, and the suggested commit `d5b768f027` binds those runs from the shared 64 MiB import chunks instead, with a test that fails without it. Thanks @JJenkx. We will review that commit; whether to fold it into this PR is your call, and the fd-ownership question above is still open.
oneandonlydean commented 2026-10-21 06:59:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T06:59:46Z.


@Mouad-Scriptz-0 @JJenkx we read d5b768f027. The code looks right: each run is split into sparse pieces with the alignment, size and file-size checks, and the mock tests cover both the bind and the fallback. One thing to confirm if it is folded in: its scope is wider than the size limit. Every multi-run list now tries the sparse path first at any size, and this PR's udmabuf run-list import becomes the fallback. That matches the order single runs already use, which seems fine, but please confirm it's intended and say so in the debt entry.

The fd-ownership question above is still open.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310080442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6310080442). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T06:59:46Z. --- @Mouad-Scriptz-0 @JJenkx we read `d5b768f027`. The code looks right: each run is split into sparse pieces with the alignment, size and file-size checks, and the mock tests cover both the bind and the fallback. One thing to confirm if it is folded in: its scope is wider than the size limit. Every multi-run list now tries the sparse path first at any size, and this PR's udmabuf run-list import becomes the fallback. That matches the order single runs already use, which seems fine, but please confirm it's intended and say so in the debt entry. The fd-ownership question above is still open.
JJenkx commented 2026-10-21 08:25:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T08:25:26Z.


@oneandonlydean thanks for reading it. The sparse path is narrower than "every multi-run list at any size": createSparseDmaBufImport still returns false at its first check when entry.bytes <= ImportChunkBytes (64 MiB), or when sparse binding, a usable queue or /dev/udmabuf is missing (GuestBufferMemory.cpp:800 in d5b768f027). So:

  • A run list of 64 MiB or less still goes to this PR's UDMABUF_CREATE_LIST import, as before.
  • A run list above 64 MiB tries the sparse chunk binds first. If they do not apply (an interior run off the sparse block size, a chunk past the backing file, an unsupported memory type, no sparse binding), it falls back to UDMABUF_CREATE_LIST. That import works only when size_limit_mb allows the total, and otherwise is copied as today.

That is the order single runs already use (one chunk, then sparse above 64 MiB, then one udmabuf), and it is intended. Suggested wording for the debt entry, if @Mouad-Scriptz-0 folds it in: "A run list above 64 MiB is bound from the shared 64 MiB chunk imports in one sparse buffer, as a single run above 64 MiB is; one at or below 64 MiB, or one whose runs are not on the sparse block size, is one udmabuf of the list, which the kernel refuses above size_limit_mb (64 MiB by default)."

I have no opinion to add on the fd-ownership question; that is the author's code.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311512650 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6311512650). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T08:25:26Z. --- @oneandonlydean thanks for reading it. The sparse path is narrower than "every multi-run list at any size": `createSparseDmaBufImport` still returns false at its first check when `entry.bytes <= ImportChunkBytes` (64 MiB), or when sparse binding, a usable queue or `/dev/udmabuf` is missing (`GuestBufferMemory.cpp:800` in `d5b768f027`). So: - A run list of 64 MiB or less still goes to this PR's `UDMABUF_CREATE_LIST` import, as before. - A run list above 64 MiB tries the sparse chunk binds first. If they do not apply (an interior run off the sparse block size, a chunk past the backing file, an unsupported memory type, no sparse binding), it falls back to `UDMABUF_CREATE_LIST`. That import works only when `size_limit_mb` allows the total, and otherwise is copied as today. That is the order single runs already use (one chunk, then sparse above 64 MiB, then one udmabuf), and it is intended. Suggested wording for the debt entry, if @Mouad-Scriptz-0 folds it in: "A run list above 64 MiB is bound from the shared 64 MiB chunk imports in one sparse buffer, as a single run above 64 MiB is; one at or below 64 MiB, or one whose runs are not on the sparse block size, is one udmabuf of the list, which the kernel refuses above `size_limit_mb` (64 MiB by default)." I have no opinion to add on the fd-ownership question; that is the author's code.
oneandonlydean commented 2026-10-21 08:52:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:52:28Z.


@JJenkx you're right, thanks. I missed the entry.bytes <= ImportChunkBytes return at the top of createSparseDmaBufImport (GuestBufferMemory.cpp:800 in d5b768f027). Only run lists above 64 MiB try the sparse chunk binds first, the same order single runs use, so my "every multi-run list, whatever its size" was wrong. Your suggested debt wording describes it correctly. The fd-ownership question for the author still stands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311996076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6311996076). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T08:52:28Z. --- @JJenkx you're right, thanks. I missed the `entry.bytes <= ImportChunkBytes` return at the top of `createSparseDmaBufImport` (`GuestBufferMemory.cpp:800` in `d5b768f027`). Only run lists above 64 MiB try the sparse chunk binds first, the same order single runs use, so my "every multi-run list, whatever its size" was wrong. Your suggested debt wording describes it correctly. The fd-ownership question for the author still stands.
socket1001 commented 2026-10-21 10:46:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T10:46:09Z.


Verification of the >64 MiB run-list path on the RX 9070 — building fa671820 + d5b768f02 and measuring the udmabuf limit on a real kernel.

AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted.

Environment — am5, Ubuntu 24.04, kernel 7.0.0-38-generic, Mesa 25.2.8, RADV; RX 9070 (1002:7550, 16 GiB), pinned by ANYPS5_GPU=AMD Radeon RX 9070 with MESA_VK_DEVICE_SELECT=1002:7550, and the launcher's runtime device assertion passes on every leg. udmabuf module params on this kernel: size_limit_mb=64, list_limit=1024.

1. The limit is real on a default kernel (raw ioctl, no GPU involved). /dev/udmabuf here takes the offset-capable API — struct udmabuf_create { memfd, flags, offset, size }, and UDMABUF_CREATE_LIST with a per-item offset:

request result
UDMABUF_CREATE, 224 MiB EINVAL
UDMABUF_CREATE, 64 MiB created
UDMABUF_CREATE, 64 MiB at file offset 64 MiB created (offset honoured)
UDMABUF_CREATE_LIST, 2 runs totalling 128 MiB EINVAL
UDMABUF_CREATE_LIST, 2 runs totalling 64 MiB created

So the EINVAL is reproducible on a stock 64 MiB-limit kernel, and it applies to the total of a list, not to a single run.

2. The sparse-chunk path works on the 9070 (real Vulkan, real dma-bufs). Host-side probe: two 64 MiB udmabuf chunks imported as VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT memory and bound to one 128 MiB VK_BUFFER_CREATE_SPARSE_BINDING_BIT buffer via vkQueueBindSparse → VK_SUCCESS; a 128 MiB vkCmdCopyBuffer through that buffer round-trips (8192 probe words match). That is the mechanism d5b768f02 uses, exercised against RADV and the real kernel rather than a mock.

3. Your new test is a genuine regression test. agc_host_import_sparse_tests (the EXCLUDE_FROM_ALL host target) on fa671820 alone fails:

FAIL: a range of two scattered runs larger than udmabuf's size limit was not imported

and with d5b768f02 applied it passes (host import sparse dma-buf tests passed, exit 0). I applied your commit with git am on top of fa671820, so it is a direct child, unmodified.

4. No regression on the game. Six 70 s legs of PPSA14299 (Mafia: The Old Country), head vs head+fix, interleaved head,fix / fix,head / head,fix, decks identical apart from libSceAgcDriver.prx (352 PRX each; md5 146676fe… vs 6afe0580…):

arm per-leg mean FPS arm mean import failures -13 storage-image races
fa671820 22.724 / 22.390 / 21.852 22.322 0 0 8 / 8 / 8
fa671820 + d5b768f02 22.186 / 22.618 / 22.212 22.339 0 0 8 / 8 / 8

+0.07 % — inside run-to-run noise, and both arms sit where the published head arm measured (22.453).

Caveats — what this does not show.

  • Mafia never produces a scattered run list over the limit. Its large imports (30 of them, up to 224.6 MiB) are single runs, which is why they succeed on the unmodified head. So measurement 4 is a no-regression result, not evidence that the fix buys anything on this title; the reproduction of the failure is measurements 1 and 3.
  • I do not have PPSA25636, the title where you hit this, so I could not reproduce the failing guest workload itself.
  • Measurement 1 is on a default 64 MiB size_limit_mb. A machine with the limit raised would not see the EINVAL and would not need the fix.
  • Measurement 2 is my own host-side program and measurement 3 is upstream's host-side test with Vulkan mocked; neither drives the emulator's own import path from a guest.

Raw logs, samples, both mock-test outputs and the probe source are archived on my side — say the word and I will post them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314064729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6314064729). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-21T10:46:09Z. --- **Verification of the `>64 MiB` run-list path on the RX 9070** — building `fa671820` + `d5b768f02` and measuring the udmabuf limit on a real kernel. AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted. **Environment** — am5, Ubuntu 24.04, kernel `7.0.0-38-generic`, Mesa 25.2.8, RADV; RX 9070 (`1002:7550`, 16 GiB), pinned by `ANYPS5_GPU=AMD Radeon RX 9070` with `MESA_VK_DEVICE_SELECT=1002:7550`, and the launcher's runtime device assertion passes on every leg. `udmabuf` module params on this kernel: `size_limit_mb=64`, `list_limit=1024`. **1. The limit is real on a default kernel** (raw `ioctl`, no GPU involved). `/dev/udmabuf` here takes the offset-capable API — `struct udmabuf_create { memfd, flags, offset, size }`, and `UDMABUF_CREATE_LIST` with a per-item offset: | request | result | |---|---| | `UDMABUF_CREATE`, 224 MiB | EINVAL | | `UDMABUF_CREATE`, 64 MiB | created | | `UDMABUF_CREATE`, 64 MiB at file offset 64 MiB | created (offset honoured) | | `UDMABUF_CREATE_LIST`, 2 runs totalling 128 MiB | EINVAL | | `UDMABUF_CREATE_LIST`, 2 runs totalling 64 MiB | created | So the EINVAL is reproducible on a stock 64 MiB-limit kernel, and it applies to the **total of a list**, not to a single run. **2. The sparse-chunk path works on the 9070** (real Vulkan, real dma-bufs). Host-side probe: two 64 MiB `udmabuf` chunks imported as `VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT` memory and bound to one 128 MiB `VK_BUFFER_CREATE_SPARSE_BINDING_BIT` buffer via `vkQueueBindSparse` → `VK_SUCCESS`; a 128 MiB `vkCmdCopyBuffer` through that buffer round-trips (8192 probe words match). That is the mechanism `d5b768f02` uses, exercised against RADV and the real kernel rather than a mock. **3. Your new test is a genuine regression test.** `agc_host_import_sparse_tests` (the `EXCLUDE_FROM_ALL` host target) on `fa671820` alone **fails**: ``` FAIL: a range of two scattered runs larger than udmabuf's size limit was not imported ``` and with `d5b768f02` applied it **passes** (`host import sparse dma-buf tests passed`, exit 0). I applied your commit with `git am` on top of `fa671820`, so it is a direct child, unmodified. **4. No regression on the game.** Six 70 s legs of `PPSA14299` (Mafia: The Old Country), head vs head+fix, interleaved `head,fix / fix,head / head,fix`, decks identical apart from `libSceAgcDriver.prx` (352 PRX each; md5 `146676fe…` vs `6afe0580…`): | arm | per-leg mean FPS | arm mean | import failures | `-13` | storage-image races | |---|---|---|---|---|---| | `fa671820` | 22.724 / 22.390 / 21.852 | 22.322 | 0 | 0 | 8 / 8 / 8 | | `fa671820` + `d5b768f02` | 22.186 / 22.618 / 22.212 | 22.339 | 0 | 0 | 8 / 8 / 8 | +0.07 % — inside run-to-run noise, and both arms sit where the published head arm measured (22.453). **Caveats — what this does *not* show.** - Mafia never produces a scattered run list over the limit. Its large imports (30 of them, up to 224.6 MiB) are **single** runs, which is why they succeed on the unmodified head. So measurement 4 is a no-regression result, not evidence that the fix buys anything on this title; the reproduction of the failure is measurements 1 and 3. - I do not have PPSA25636, the title where you hit this, so I could not reproduce the failing guest workload itself. - Measurement 1 is on a default 64 MiB `size_limit_mb`. A machine with the limit raised would not see the EINVAL and would not need the fix. - Measurement 2 is my own host-side program and measurement 3 is upstream's host-side test with Vulkan mocked; neither drives the emulator's own import path from a guest. Raw logs, samples, both mock-test outputs and the probe source are archived on my side — say the word and I will post them.
socket1001 commented 2026-10-21 10:52:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T10:52:08Z.


Follow-up: the scattered >64 MiB run list reproduced in the emulator's own import path, not just in a mock.

In my earlier comment, measurements 2 and 3 were host-side (my own probe, and upstream's test with Vulkan mocked). This closes that gap: a local execution-test case driving the real GuestBufferMemory import against the real device, with a genuine two-run scattered range.

AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted.

Case. A 128 MiB guest range whose two 64 MiB segments are backed at non-contiguous file offsets — segment 0 from file [0, 64 MiB), segment 1 from [128 MiB, 192 MiB) — on a kernel with size_limit_mb=64. Implemented as tests/execution/ScatteredRuns.cpp: reserve the guest range, MAP_FIXED-map each segment from one sealed memfd at its scattered offset, register a SharedBackingRuns resolver returning those two runs, then ImportGuestMemory and write through the GPU into the second run.

build result
fa671820 host import of 0x…+0x8000000 failed at UDMABUF_CREATE_LIST (-1000072003); falling back to copies → a range of two scattered runs larger than udmabuf's size limit was not imported (exit 1)
fa671820 + d5b768f02 limit 64 MiB, imported 128 MiB as two scattered runs → passed (exit 0)

Note 0x8000000 = 128 MiB: the unmodified head hands the whole two-run list to one UDMABUF_CREATE_LIST, which the kernel refuses, so it falls back to copies.

The fixed build also checks placement, not just success: a 64 KiB GPU fill at the start of run 1 lands at file offset 128 MiB (read back with pread) and does not appear in the first region. The per-run sparse binding therefore maps the correct file ranges, not merely "an import exists".

Both binaries are on this machine and the run is repeatable. The case is ~150 lines against the existing test scaffolding — say the word and I will post it as a patch if you want it in tests/execution/.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314166399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6314166399). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-21T10:52:08Z. --- **Follow-up: the scattered `>64 MiB` run list reproduced in the emulator's own import path**, not just in a mock. In my earlier comment, measurements 2 and 3 were host-side (my own probe, and upstream's test with Vulkan mocked). This closes that gap: a local execution-test case driving the real `GuestBufferMemory` import against the real device, with a genuine two-run scattered range. AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted. **Case.** A 128 MiB guest range whose two 64 MiB segments are backed at *non-contiguous* file offsets — segment 0 from file `[0, 64 MiB)`, segment 1 from `[128 MiB, 192 MiB)` — on a kernel with `size_limit_mb=64`. Implemented as `tests/execution/ScatteredRuns.cpp`: reserve the guest range, `MAP_FIXED`-map each segment from one sealed memfd at its scattered offset, register a `SharedBackingRuns` resolver returning those two runs, then `ImportGuestMemory` and write through the GPU into the second run. | build | result | |---|---| | `fa671820` | `host import of 0x…+0x8000000 failed at UDMABUF_CREATE_LIST (-1000072003); falling back to copies` → *a range of two scattered runs larger than udmabuf's size limit was not imported* (exit 1) | | `fa671820` + `d5b768f02` | `limit 64 MiB, imported 128 MiB as two scattered runs` → passed (exit 0) | Note `0x8000000` = 128 MiB: the unmodified head hands the whole two-run list to one `UDMABUF_CREATE_LIST`, which the kernel refuses, so it falls back to copies. The fixed build also checks *placement*, not just success: a 64 KiB GPU fill at the start of run 1 lands at file offset `128 MiB` (read back with `pread`) and does not appear in the first region. The per-run sparse binding therefore maps the correct file ranges, not merely "an import exists". Both binaries are on this machine and the run is repeatable. The case is ~150 lines against the existing test scaffolding — say the word and I will post it as a patch if you want it in `tests/execution/`.
oneandonlydean commented 2026-10-21 11:01:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T11:01:05Z.


@socket1001 thank you, this is the evidence we couldn't get ourselves. Our bench has no dma-buf import (NVIDIA proprietary), so d5b768f02 had only been checked against the mock device. Your raw ioctl table confirms that the size limit applies to a list's total, and the scattered-run case through the real GuestBufferMemory import, including the pread placement check, shows the path working on RADV.

Your caveats are right, and they are how we'll read it: the game legs show no regression, and they say nothing about the fix, since that title never builds a scattered list over the limit.

If you post the ScatteredRuns.cpp case as a patch, @Mouad-Scriptz-0 and @JJenkx can decide whether to add it next to the mock test. It would skip on a device without dma-buf import, but it is the only test that drives the real path. The fd-ownership question for the author still stands.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314318713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6314318713). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T11:01:05Z. --- @socket1001 thank you, this is the evidence we couldn't get ourselves. Our bench has no dma-buf import (NVIDIA proprietary), so `d5b768f02` had only been checked against the mock device. Your raw `ioctl` table confirms that the size limit applies to a list's total, and the scattered-run case through the real `GuestBufferMemory` import, including the `pread` placement check, shows the path working on RADV. Your caveats are right, and they are how we'll read it: the game legs show no regression, and they say nothing about the fix, since that title never builds a scattered list over the limit. If you post the `ScatteredRuns.cpp` case as a patch, @Mouad-Scriptz-0 and @JJenkx can decide whether to add it next to the mock test. It would skip on a device without dma-buf import, but it is the only test that drives the real path. The fd-ownership question for the author still stands.
socket1001 commented 2026-10-21 11:35:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T11:35:23Z.


Measured cost of the open fd-ownership blocker, with a guarded control.

AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted.

@Mouad-Scriptz-0 @oneandonlydean this quantifies the createBackingImport leak you and @JJenkx flagged. On RADV it is not a slow drift: it is about 2.2k descriptors inside the first 12 s of load.

Environment. am5, Ubuntu 24.04, kernel 7.0.0-38-generic, Mesa 25.2.8, RX 9070 (1002:7550, 16 GiB) pinned with ANYPS5_GPU=AMD Radeon RX 9070 and MESA_VK_DEVICE_SELECT=1002:7550; the launcher's device assertion reports AMD Radeon RX 9070 (RADV GFX1201) on every leg. Title PPSA14299 (Mafia: The Old Country), relinked per deck.

Arms. Same tree (fa671820 + d5b768f027), same app.elf, same app0/, 352 PRX in every deck. The only difference is libSceAgcDriver.prx: md5 6afe0580a6b79fbe9decd43a6b0028a9 unguarded, 0d8d9d9a50b24add7b4de3b029f6b4f1 guarded. Four 70 s legs, with the arm order alternated between the two pairs.

Method. A sampler reads /proc/<pid>/fd every 10 s: total descriptors, and the subset whose link target is a memfd.

leg arm t=12 s fds / memfd t=63 s fds / memfd
1 unguarded 2257 / 2224 2354 / 2321
2 unguarded 2241 / 2208 2321 / 2288
3 guarded 39 / 6 39 / 6
4 guarded 39 / 6 39 / 6

That is roughly 2.2k descriptors leaked during load, plus about 95 per 70 s of steady state, and the guard removes all of it (39 descriptors total, 6 of them memfd, flat across both legs).

It is a ceiling problem, not a rate-limit one. libkernel raises RLIMIT_NOFILE to rlim_max at startup (core/libs/prx/libkernel/File/src/OpenFileLimit.cpp), so the 1024 soft default never applies: the hard limit here is 1048576, which is why the unguarded run survives to 70 s. What bounds a session is the hard limit itself (4096 to 65536 on many distributions), and each leaked descriptor also holds a reference to the backing memfd, so direct memory that the guest has released cannot be reclaimed while a stray duplicate of it is still open.

The guard. An RAII variant of the std::exchange hand-off: createBackingImport owns the duplicate for its whole scope and releases it only into createDmaBufImport, which already closes what it is handed. It also carries the Piece::file to fileOffset rename, which removes the shadowing of the fd parameter in d5b768f027.

diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
index 7d03f7da3..c7ed9a898 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
@@ -805,7 +805,7 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil
     const auto requirements = dmaBufBufferRequirements(context, entry, VK_BUFFER_CREATE_SPARSE_BINDING_BIT, SparseImportUsage, lead + entry.bytes, &buffer);
     const auto alignment = requirements.alignment;
     struct Piece {
-        std::uint64_t file;
+        std::uint64_t fileOffset;
         VkDeviceSize resource;
         VkDeviceSize bytes;
     };
@@ -813,12 +813,12 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil
     bool chosen = alignment != 0 && ImportChunkBytes % alignment == 0 && (chunkTypes & ~requirements.memoryTypeBits) == 0 && (requirements.memoryTypeBits & chunkTypes) != 0;
     VkDeviceSize resource = 0;
     for (std::size_t index = 0; chosen && index < runs.size(); ++index) {
-        const auto file = index == 0 ? runs[0].offset - lead : runs[index].offset;
+        const auto fileOffset = index == 0 ? runs[0].offset - lead : runs[index].offset;
         const VkDeviceSize bytes = index == 0 ? lead + runs[0].bytes : runs[index].bytes;
         const auto length = index + 1 == runs.size() ? requirements.size - resource : bytes;
-        chosen = file % alignment == 0 && resource % alignment == 0 && (index + 1 == runs.size() || bytes % alignment == 0) && resource + bytes <= requirements.size &&
-            (file + length + ImportChunkBytes - 1) / ImportChunkBytes * ImportChunkBytes <= static_cast<std::uint64_t>(backing.st_size);
-        pieces.push_back({file, resource, length});
+        chosen = fileOffset % alignment == 0 && resource % alignment == 0 && (index + 1 == runs.size() || bytes % alignment == 0) && resource + bytes <= requirements.size &&
+            (fileOffset + length + ImportChunkBytes - 1) / ImportChunkBytes * ImportChunkBytes <= static_cast<std::uint64_t>(backing.st_size);
+        pieces.push_back({fileOffset, resource, length});
         resource += bytes;
     }
     const auto fail = [&](const char* step, VkResult result) {
@@ -833,7 +833,7 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil
     std::vector<VkSparseMemoryBind> binds;
     for (const auto& piece : pieces) {
         for (VkDeviceSize done = 0; done < piece.bytes;) {
-            const auto position = piece.file + done;
+            const auto position = piece.fileOffset + done;
             const auto index = position / ImportChunkBytes;
             const auto within = position - index * ImportChunkBytes;
             const auto size = std::min<VkDeviceSize>(ImportChunkBytes - within, piece.bytes - done);
@@ -879,12 +879,27 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil
 #endif
 
 #ifndef _WIN32
+// The shared-backing resolver hands out a duplicated descriptor, so this function owns it on every
+// exit. Neither import path below consumes it: a udmabuf holds its own reference to the memfd, so
+// without closing the duplicate here every imported buffer leaks one descriptor.
+struct OwnedDescriptor {
+    explicit OwnedDescriptor(int descriptor) : file(descriptor) {}
+    OwnedDescriptor(const OwnedDescriptor&) = delete;
+    OwnedDescriptor& operator=(const OwnedDescriptor&) = delete;
+    ~OwnedDescriptor() {
+        if (file >= 0) close(file);
+    }
+    int Release() { return std::exchange(file, -1); }
+    int file;
+};
+
 const char* createBackingImport(const Context& context, HostImport& entry, int file, const GuestArena::SharedBackingRun* runs, std::size_t count, VkResult& failure) {
     bool fits = false;
     VkResult chunkFailure = VK_SUCCESS;
-    if (count == 1 && createChunkedDmaBufImport(context, entry, file, runs[0].offset, fits, chunkFailure) == nullptr && fits) return nullptr;
-    if ((count > 1 || !fits) && createSparseDmaBufImport(context, entry, file, std::span<const GuestArena::SharedBackingRun>(runs, count))) return nullptr;
-    return createDmaBufImport(context, entry, file, std::span<const GuestArena::SharedBackingRun>(runs, count), failure);
+    OwnedDescriptor owned(file);
+    if (count == 1 && createChunkedDmaBufImport(context, entry, owned.file, runs[0].offset, fits, chunkFailure) == nullptr && fits) return nullptr;
+    if ((count > 1 || !fits) && createSparseDmaBufImport(context, entry, owned.file, std::span<const GuestArena::SharedBackingRun>(runs, count))) return nullptr;
+    return createDmaBufImport(context, entry, owned.Release(), std::span<const GuestArena::SharedBackingRun>(runs, count), failure);
 }
 
 const char* createSharedBackingImport(const Context& context, HostImport& entry, VkResult& failure) {

No behavioural change. Frames rendered by t=63 s: 1341 and 1314 (unguarded) against 1320 and 1319 (guarded). Zero [error] or assert lines, zero -13, zero device faults on all four legs, and the device assertion passes on every leg. agc_host_import_sparse_tests and the scattered-run execution case both still pass on the guarded build. Take whichever guard is preferable, mine or @JJenkx's patch; the substance is that the three returning paths need scope ownership back, and /proc/<pid>/fd is a direct way to see it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314920674 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6314920674). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-21T11:35:23Z. --- **Measured cost of the open fd-ownership blocker, with a guarded control.** AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed the measurements and this write-up before it was posted. @Mouad-Scriptz-0 @oneandonlydean this quantifies the `createBackingImport` leak you and @JJenkx flagged. On RADV it is not a slow drift: it is about 2.2k descriptors inside the first 12 s of load. **Environment.** am5, Ubuntu 24.04, kernel `7.0.0-38-generic`, Mesa 25.2.8, RX 9070 (`1002:7550`, 16 GiB) pinned with `ANYPS5_GPU=AMD Radeon RX 9070` and `MESA_VK_DEVICE_SELECT=1002:7550`; the launcher's device assertion reports `AMD Radeon RX 9070 (RADV GFX1201)` on every leg. Title PPSA14299 (Mafia: The Old Country), relinked per deck. **Arms.** Same tree (`fa671820` + `d5b768f027`), same `app.elf`, same `app0/`, 352 PRX in every deck. The only difference is `libSceAgcDriver.prx`: md5 `6afe0580a6b79fbe9decd43a6b0028a9` unguarded, `0d8d9d9a50b24add7b4de3b029f6b4f1` guarded. Four 70 s legs, with the arm order alternated between the two pairs. **Method.** A sampler reads `/proc/<pid>/fd` every 10 s: total descriptors, and the subset whose link target is a memfd. | leg | arm | t=12 s fds / memfd | t=63 s fds / memfd | |---|---|---|---| | 1 | unguarded | 2257 / 2224 | 2354 / 2321 | | 2 | unguarded | 2241 / 2208 | 2321 / 2288 | | 3 | guarded | 39 / 6 | 39 / 6 | | 4 | guarded | 39 / 6 | 39 / 6 | That is roughly 2.2k descriptors leaked during load, plus about 95 per 70 s of steady state, and the guard removes all of it (39 descriptors total, 6 of them memfd, flat across both legs). **It is a ceiling problem, not a rate-limit one.** `libkernel` raises `RLIMIT_NOFILE` to `rlim_max` at startup (`core/libs/prx/libkernel/File/src/OpenFileLimit.cpp`), so the 1024 soft default never applies: the hard limit here is 1048576, which is why the unguarded run survives to 70 s. What bounds a session is the hard limit itself (4096 to 65536 on many distributions), and each leaked descriptor also holds a reference to the backing memfd, so direct memory that the guest has released cannot be reclaimed while a stray duplicate of it is still open. **The guard.** An RAII variant of the `std::exchange` hand-off: `createBackingImport` owns the duplicate for its whole scope and releases it only into `createDmaBufImport`, which already closes what it is handed. It also carries the `Piece::file` to `fileOffset` rename, which removes the shadowing of the fd parameter in `d5b768f027`. ```diff diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp index 7d03f7da3..c7ed9a898 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp @@ -805,7 +805,7 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil const auto requirements = dmaBufBufferRequirements(context, entry, VK_BUFFER_CREATE_SPARSE_BINDING_BIT, SparseImportUsage, lead + entry.bytes, &buffer); const auto alignment = requirements.alignment; struct Piece { - std::uint64_t file; + std::uint64_t fileOffset; VkDeviceSize resource; VkDeviceSize bytes; }; @@ -813,12 +813,12 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil bool chosen = alignment != 0 && ImportChunkBytes % alignment == 0 && (chunkTypes & ~requirements.memoryTypeBits) == 0 && (requirements.memoryTypeBits & chunkTypes) != 0; VkDeviceSize resource = 0; for (std::size_t index = 0; chosen && index < runs.size(); ++index) { - const auto file = index == 0 ? runs[0].offset - lead : runs[index].offset; + const auto fileOffset = index == 0 ? runs[0].offset - lead : runs[index].offset; const VkDeviceSize bytes = index == 0 ? lead + runs[0].bytes : runs[index].bytes; const auto length = index + 1 == runs.size() ? requirements.size - resource : bytes; - chosen = file % alignment == 0 && resource % alignment == 0 && (index + 1 == runs.size() || bytes % alignment == 0) && resource + bytes <= requirements.size && - (file + length + ImportChunkBytes - 1) / ImportChunkBytes * ImportChunkBytes <= static_cast<std::uint64_t>(backing.st_size); - pieces.push_back({file, resource, length}); + chosen = fileOffset % alignment == 0 && resource % alignment == 0 && (index + 1 == runs.size() || bytes % alignment == 0) && resource + bytes <= requirements.size && + (fileOffset + length + ImportChunkBytes - 1) / ImportChunkBytes * ImportChunkBytes <= static_cast<std::uint64_t>(backing.st_size); + pieces.push_back({fileOffset, resource, length}); resource += bytes; } const auto fail = [&](const char* step, VkResult result) { @@ -833,7 +833,7 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil std::vector<VkSparseMemoryBind> binds; for (const auto& piece : pieces) { for (VkDeviceSize done = 0; done < piece.bytes;) { - const auto position = piece.file + done; + const auto position = piece.fileOffset + done; const auto index = position / ImportChunkBytes; const auto within = position - index * ImportChunkBytes; const auto size = std::min<VkDeviceSize>(ImportChunkBytes - within, piece.bytes - done); @@ -879,12 +879,27 @@ bool createSparseDmaBufImport(const Context& context, HostImport& entry, int fil #endif #ifndef _WIN32 +// The shared-backing resolver hands out a duplicated descriptor, so this function owns it on every +// exit. Neither import path below consumes it: a udmabuf holds its own reference to the memfd, so +// without closing the duplicate here every imported buffer leaks one descriptor. +struct OwnedDescriptor { + explicit OwnedDescriptor(int descriptor) : file(descriptor) {} + OwnedDescriptor(const OwnedDescriptor&) = delete; + OwnedDescriptor& operator=(const OwnedDescriptor&) = delete; + ~OwnedDescriptor() { + if (file >= 0) close(file); + } + int Release() { return std::exchange(file, -1); } + int file; +}; + const char* createBackingImport(const Context& context, HostImport& entry, int file, const GuestArena::SharedBackingRun* runs, std::size_t count, VkResult& failure) { bool fits = false; VkResult chunkFailure = VK_SUCCESS; - if (count == 1 && createChunkedDmaBufImport(context, entry, file, runs[0].offset, fits, chunkFailure) == nullptr && fits) return nullptr; - if ((count > 1 || !fits) && createSparseDmaBufImport(context, entry, file, std::span<const GuestArena::SharedBackingRun>(runs, count))) return nullptr; - return createDmaBufImport(context, entry, file, std::span<const GuestArena::SharedBackingRun>(runs, count), failure); + OwnedDescriptor owned(file); + if (count == 1 && createChunkedDmaBufImport(context, entry, owned.file, runs[0].offset, fits, chunkFailure) == nullptr && fits) return nullptr; + if ((count > 1 || !fits) && createSparseDmaBufImport(context, entry, owned.file, std::span<const GuestArena::SharedBackingRun>(runs, count))) return nullptr; + return createDmaBufImport(context, entry, owned.Release(), std::span<const GuestArena::SharedBackingRun>(runs, count), failure); } const char* createSharedBackingImport(const Context& context, HostImport& entry, VkResult& failure) { ``` **No behavioural change.** Frames rendered by t=63 s: 1341 and 1314 (unguarded) against 1320 and 1319 (guarded). Zero `[error]` or assert lines, zero `-13`, zero device faults on all four legs, and the device assertion passes on every leg. `agc_host_import_sparse_tests` and the scattered-run execution case both still pass on the guarded build. Take whichever guard is preferable, mine or @JJenkx's patch; the substance is that the three returning paths need scope ownership back, and `/proc/<pid>/fd` is a direct way to see it.
socket1001 commented 2026-10-21 11:35:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T11:35:30Z.


The scattered-run execution case, as a patch.

AI-assisted: yes. This test and write-up were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed them before they were posted.

As invited in the last comment: this is the ScatteredRuns.cpp case, as a patch. It applies on top of d5b768f027 (or any head that carries it) and adds one file with no build-system edit: core/libs/prx/libSceAgcDriver/CMakeLists.txt globs tests/execution/*.cpp, so it registers itself as agc_driver_scattered_runs_tests (EXCLUDE_FROM_ALL), next to the existing execution tests.

What it drives:

  • a 128 MiB guest range whose two 64 MiB halves are MAP_SHARED at non-contiguous file offsets in one sealed memfd (0 and 128 MiB), so the resolver returns a genuine two-run scattered list;
  • GuestArenaSharedBackingRuns is registered with that resolver and ImportGuestMemory runs on the real device, so this exercises the production import path rather than a mock;
  • assertions on placement, not just success: a 64 KiB GPU fill at the start of run 1 must read back at file offset 128 MiB and must not appear in the first region, so a bind that maps the wrong run cannot pass;
  • it reports a skip (77) rather than a failure when /dev/udmabuf is unavailable, the device does not import guest memory, the udmabuf limit is not below two chunks, or it is built on Windows.

Measured on this machine: it fails on fa671820 alone (UDMABUF_CREATE_LIST, EINVAL, falls back to copies) and passes on fa671820 + d5b768f027 with limit 64 MiB, imported 128 MiB as two scattered runs.

diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cpp
new file mode 100644
index 0000000..a680056
--- /dev/null
+++ b/core/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cpp
@@ -0,0 +1,192 @@
+// Execution test: a scattered TWO-RUN guest range whose total is larger than udmabuf's
+// size_limit_mb (64 MiB by default). Without the run-list sparse import the range goes to one
+// UDMABUF_CREATE_LIST, which the kernel refuses with EINVAL, and falls back to copies; with it,
+// each run is bound from the shared 64 MiB chunk imports and the range imports.
+#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
+#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
+#include "prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp"
+#include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp"
+#include "prx/libSceAgcDriver/Graphics/include/Resources.hpp"
+#include "prx/libc/include/GuestAllocations.hpp"
+#include "VulkanTestDevice.hpp"
+#ifndef _WIN32
+#include "prx/libc/include/GuestArena.hpp"
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#endif
+#include <algorithm>
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
+#include <iostream>
+#include <mutex>
+#include <span>
+
+#ifdef _WIN32
+int main() {
+    std::printf("skipped, udmabuf imports are Linux only\n");
+    return 77;
+}
+#else
+namespace AgcDriver {
+
+struct VulkanDeviceTestAccess {
+    static Graphics::Context ContextOf(const VulkanDevice& device) { return device.graphicsContext(); }
+};
+
+}
+
+namespace {
+
+using AgcDriver::Graphics::Require;
+
+constexpr std::uint64_t ChunkBytes = std::uint64_t{64} << 20u;
+
+std::uint8_t* mapping = nullptr;
+std::uint64_t mappingBytes = 0;
+int backing = -1;
+
+// Guest segment 0 -> file [0, ChunkBytes); guest segment 1 -> file [2*ChunkBytes, 3*ChunkBytes).
+// Non-contiguous file offsets, so this is a genuine scattered run list, not one long range.
+bool ResolveRuns(std::uintptr_t address, std::size_t bytes, int* file, GuestArena::SharedBackingRun* runs, std::size_t capacity, std::size_t* count) {
+    const auto begin = reinterpret_cast<std::uintptr_t>(mapping);
+    if (address < begin || address + bytes > begin + mappingBytes) return false;
+    const std::size_t offset = address - begin;
+    std::size_t done = 0;
+    std::size_t used = 0;
+    while (done < bytes) {
+        const std::size_t guestPos = offset + done;
+        const std::size_t segment = guestPos / ChunkBytes;
+        const std::size_t within = guestPos % ChunkBytes;
+        const std::size_t take = std::min<std::size_t>(bytes - done, ChunkBytes - within);
+        if (used >= capacity) return false;
+        runs[used++] = {static_cast<std::uint64_t>(segment) * 2 * ChunkBytes + within, take};
+        done += take;
+    }
+    *file = dup(backing);
+    if (*file < 0) return false;
+    *count = used;
+    return true;
+}
+
+std::uint64_t UdmabufLimitBytes() {
+    std::ifstream limit("/sys/module/udmabuf/parameters/size_limit_mb");
+    std::uint64_t megabytes = 64;
+    limit >> megabytes;
+    return megabytes << 20u;
+}
+
+bool Imported(VkDevice device, std::uint64_t address, std::size_t bytes) {
+    AgcDriver::Graphics::Context probe{};
+    probe.device = device;
+    probe.hostImportAlignment = 1;
+    return AgcDriver::Graphics::HostImportCovers(probe, address, bytes);
+}
+
+bool DmaBufImport(const AgcDriver::VulkanDevice& device, std::uint64_t address, std::size_t bytes) {
+    std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex());
+    const auto* import = AgcDriver::Graphics::HostImportFor(AgcDriver::VulkanDeviceTestAccess::ContextOf(device), address, bytes);
+    return import != nullptr && import->dmaBuf;
+}
+
+}
+
+int main() {
+    try {
+        const int udmabuf = open("/dev/udmabuf", O_RDWR | O_CLOEXEC);
+        if (udmabuf < 0) {
+            std::printf("skipped, host imports are unavailable: /dev/udmabuf is not accessible\n");
+            return 77;
+        }
+        close(udmabuf);
+        const auto limit = UdmabufLimitBytes();
+        auto device = OpenVulkanTestDevice();
+        if (!device) return 77;
+
+        // A device probe, so an unsupported device reads as a skip rather than a failure.
+        constexpr std::size_t ProbeBytes = 65536;
+        auto* probe = static_cast<std::uint8_t*>(std::aligned_alloc(ProbeBytes, ProbeBytes));
+        Require(probe != nullptr, "scattered import: cannot allocate the probe");
+        GuestAllocations::Mutation().Add(probe, ProbeBytes, true, true, true);
+        bool adopted = false;
+        {
+            std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex());
+            const std::array<std::uint32_t, 4> pattern{1u, 2u, 3u, 4u};
+            adopted = device->FillBuffer(reinterpret_cast<std::uint64_t>(probe), ProbeBytes, pattern);
+            device->WaitIdle();
+        }
+        if (!adopted) {
+            std::printf("skipped, the device does not import guest memory\n");
+            return 77;
+        }
+
+        // Two 64 MiB segments = 128 MiB total, above a default 64 MiB udmabuf limit.
+        Require(2 * ChunkBytes > limit, "scattered import: run this where the udmabuf limit is below two chunks");
+        mappingBytes = 2 * ChunkBytes;
+        const std::uint64_t fileBytes = 3 * ChunkBytes;
+        backing = memfd_create("anyps5-scattered-runs", MFD_CLOEXEC | MFD_ALLOW_SEALING);
+        Require(backing >= 0 && ftruncate(backing, static_cast<off_t>(fileBytes)) == 0, "scattered import: cannot make the backing file");
+        Require(fcntl(backing, F_ADD_SEALS, F_SEAL_SHRINK) == 0, "scattered import: cannot seal the backing file");
+        void* reservation = mmap(nullptr, mappingBytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+        Require(reservation != MAP_FAILED, "scattered import: cannot reserve the guest range");
+        for (std::uint64_t segment = 0; segment < 2; ++segment) {
+            void* piece = mmap(static_cast<std::uint8_t*>(reservation) + segment * ChunkBytes, ChunkBytes,
+                               PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, backing,
+                               static_cast<off_t>(segment * 2 * ChunkBytes));
+            Require(piece != MAP_FAILED, "scattered import: cannot map a segment");
+        }
+        mapping = static_cast<std::uint8_t*>(reservation);
+        std::memset(mapping, 0, static_cast<std::size_t>(mappingBytes));
+        GuestArena::GuestArenaSetSharedBackingRuns_nid_postfix(ResolveRuns);
+
+        GuestAllocations::Mutation().Add(mapping, static_cast<std::size_t>(mappingBytes), true, true, true);
+        GuestAllocations::Mapped ranges;
+        for (const auto& range : GuestAllocations::GuestAllocationsAcquire_nid_postfix()) {
+            if (range->address == reinterpret_cast<std::uint64_t>(mapping)) ranges.push_back(range);
+        }
+        Require(ranges.size() == 1, "scattered import: the allocation is not registered");
+
+        const auto address = reinterpret_cast<std::uint64_t>(mapping);
+        bool imported = false;
+        {
+            std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex());
+            imported = device->ImportGuestMemory(ranges, GuestAllocations::GuestAllocationsGeneration_nid_postfix(), false);
+            device->WaitIdle();
+        }
+        Require(imported, "scattered import: ImportGuestMemory refused the range");
+        Require(Imported(device->Device(), address, static_cast<std::size_t>(mappingBytes)),
+                "a range of two scattered runs larger than udmabuf's size limit was not imported");
+        Require(DmaBufImport(*device, address, static_cast<std::size_t>(mappingBytes)),
+                "a range of two scattered runs larger than udmabuf's size limit was not imported as a dma-buf");
+
+        // Write through the GPU into the second run; it must land in the second file region.
+        constexpr std::uint32_t Pattern = 0x5CA77E12u;
+        {
+            std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex());
+            Require(device->FillBuffer(address + ChunkBytes, 65536, std::array<std::uint32_t, 4>{Pattern, Pattern, Pattern, Pattern}),
+                    "scattered import: the fill in the second run was not served by the import");
+            device->WaitIdle();
+        }
+        std::uint32_t second = 0;
+        Require(pread(backing, &second, sizeof(second), static_cast<off_t>(2 * ChunkBytes)) == static_cast<ssize_t>(sizeof(second)),
+                "scattered import: cannot read the second run's file region");
+        Require(second == Pattern, "scattered import: the second run's GPU write did not land at its scattered file offset");
+        std::uint32_t first = 0;
+        Require(pread(backing, &first, sizeof(first), 0) == static_cast<ssize_t>(sizeof(first)),
+                "scattered import: cannot read the first run's file region");
+        Require(first != Pattern, "scattered import: the second run's write landed in the first run's file region");
+
+        std::printf("limit %llu MiB, imported %llu MiB as two scattered runs\n",
+                    static_cast<unsigned long long>(limit >> 20u), static_cast<unsigned long long>(mappingBytes >> 20u));
+        std::cout << "AGC scattered run-list import test passed\n";
+        return 0;
+    } catch (const std::exception& error) {
+        std::cerr << error.what() << '\n';
+        return 1;
+    }
+}
+#endif
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314922858 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6314922858). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-21T11:35:30Z. --- **The scattered-run execution case, as a patch.** AI-assisted: yes. This test and write-up were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed them before they were posted. As invited in the last comment: this is the `ScatteredRuns.cpp` case, as a patch. It applies on top of `d5b768f027` (or any head that carries it) and adds one file with no build-system edit: `core/libs/prx/libSceAgcDriver/CMakeLists.txt` globs `tests/execution/*.cpp`, so it registers itself as `agc_driver_scattered_runs_tests` (`EXCLUDE_FROM_ALL`), next to the existing execution tests. What it drives: - a 128 MiB guest range whose two 64 MiB halves are `MAP_SHARED` at **non-contiguous** file offsets in one sealed memfd (0 and 128 MiB), so the resolver returns a genuine two-run scattered list; - `GuestArenaSharedBackingRuns` is registered with that resolver and `ImportGuestMemory` runs on the real device, so this exercises the production import path rather than a mock; - assertions on **placement**, not just success: a 64 KiB GPU fill at the start of run 1 must read back at file offset 128 MiB and must not appear in the first region, so a bind that maps the wrong run cannot pass; - it reports a skip (77) rather than a failure when `/dev/udmabuf` is unavailable, the device does not import guest memory, the udmabuf limit is not below two chunks, or it is built on Windows. Measured on this machine: it fails on `fa671820` alone (`UDMABUF_CREATE_LIST`, EINVAL, falls back to copies) and passes on `fa671820` + `d5b768f027` with `limit 64 MiB, imported 128 MiB as two scattered runs`. ```diff diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cpp new file mode 100644 index 0000000..a680056 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cpp @@ -0,0 +1,192 @@ +// Execution test: a scattered TWO-RUN guest range whose total is larger than udmabuf's +// size_limit_mb (64 MiB by default). Without the run-list sparse import the range goes to one +// UDMABUF_CREATE_LIST, which the kernel refuses with EINVAL, and falls back to copies; with it, +// each run is bound from the shared 64 MiB chunk imports and the range imports. +#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp" +#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" +#include "prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Resources.hpp" +#include "prx/libc/include/GuestAllocations.hpp" +#include "VulkanTestDevice.hpp" +#ifndef _WIN32 +#include "prx/libc/include/GuestArena.hpp" +#include <fcntl.h> +#include <sys/mman.h> +#include <unistd.h> +#endif +#include <algorithm> +#include <array> +#include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <fstream> +#include <iostream> +#include <mutex> +#include <span> + +#ifdef _WIN32 +int main() { + std::printf("skipped, udmabuf imports are Linux only\n"); + return 77; +} +#else +namespace AgcDriver { + +struct VulkanDeviceTestAccess { + static Graphics::Context ContextOf(const VulkanDevice& device) { return device.graphicsContext(); } +}; + +} + +namespace { + +using AgcDriver::Graphics::Require; + +constexpr std::uint64_t ChunkBytes = std::uint64_t{64} << 20u; + +std::uint8_t* mapping = nullptr; +std::uint64_t mappingBytes = 0; +int backing = -1; + +// Guest segment 0 -> file [0, ChunkBytes); guest segment 1 -> file [2*ChunkBytes, 3*ChunkBytes). +// Non-contiguous file offsets, so this is a genuine scattered run list, not one long range. +bool ResolveRuns(std::uintptr_t address, std::size_t bytes, int* file, GuestArena::SharedBackingRun* runs, std::size_t capacity, std::size_t* count) { + const auto begin = reinterpret_cast<std::uintptr_t>(mapping); + if (address < begin || address + bytes > begin + mappingBytes) return false; + const std::size_t offset = address - begin; + std::size_t done = 0; + std::size_t used = 0; + while (done < bytes) { + const std::size_t guestPos = offset + done; + const std::size_t segment = guestPos / ChunkBytes; + const std::size_t within = guestPos % ChunkBytes; + const std::size_t take = std::min<std::size_t>(bytes - done, ChunkBytes - within); + if (used >= capacity) return false; + runs[used++] = {static_cast<std::uint64_t>(segment) * 2 * ChunkBytes + within, take}; + done += take; + } + *file = dup(backing); + if (*file < 0) return false; + *count = used; + return true; +} + +std::uint64_t UdmabufLimitBytes() { + std::ifstream limit("/sys/module/udmabuf/parameters/size_limit_mb"); + std::uint64_t megabytes = 64; + limit >> megabytes; + return megabytes << 20u; +} + +bool Imported(VkDevice device, std::uint64_t address, std::size_t bytes) { + AgcDriver::Graphics::Context probe{}; + probe.device = device; + probe.hostImportAlignment = 1; + return AgcDriver::Graphics::HostImportCovers(probe, address, bytes); +} + +bool DmaBufImport(const AgcDriver::VulkanDevice& device, std::uint64_t address, std::size_t bytes) { + std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex()); + const auto* import = AgcDriver::Graphics::HostImportFor(AgcDriver::VulkanDeviceTestAccess::ContextOf(device), address, bytes); + return import != nullptr && import->dmaBuf; +} + +} + +int main() { + try { + const int udmabuf = open("/dev/udmabuf", O_RDWR | O_CLOEXEC); + if (udmabuf < 0) { + std::printf("skipped, host imports are unavailable: /dev/udmabuf is not accessible\n"); + return 77; + } + close(udmabuf); + const auto limit = UdmabufLimitBytes(); + auto device = OpenVulkanTestDevice(); + if (!device) return 77; + + // A device probe, so an unsupported device reads as a skip rather than a failure. + constexpr std::size_t ProbeBytes = 65536; + auto* probe = static_cast<std::uint8_t*>(std::aligned_alloc(ProbeBytes, ProbeBytes)); + Require(probe != nullptr, "scattered import: cannot allocate the probe"); + GuestAllocations::Mutation().Add(probe, ProbeBytes, true, true, true); + bool adopted = false; + { + std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex()); + const std::array<std::uint32_t, 4> pattern{1u, 2u, 3u, 4u}; + adopted = device->FillBuffer(reinterpret_cast<std::uint64_t>(probe), ProbeBytes, pattern); + device->WaitIdle(); + } + if (!adopted) { + std::printf("skipped, the device does not import guest memory\n"); + return 77; + } + + // Two 64 MiB segments = 128 MiB total, above a default 64 MiB udmabuf limit. + Require(2 * ChunkBytes > limit, "scattered import: run this where the udmabuf limit is below two chunks"); + mappingBytes = 2 * ChunkBytes; + const std::uint64_t fileBytes = 3 * ChunkBytes; + backing = memfd_create("anyps5-scattered-runs", MFD_CLOEXEC | MFD_ALLOW_SEALING); + Require(backing >= 0 && ftruncate(backing, static_cast<off_t>(fileBytes)) == 0, "scattered import: cannot make the backing file"); + Require(fcntl(backing, F_ADD_SEALS, F_SEAL_SHRINK) == 0, "scattered import: cannot seal the backing file"); + void* reservation = mmap(nullptr, mappingBytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + Require(reservation != MAP_FAILED, "scattered import: cannot reserve the guest range"); + for (std::uint64_t segment = 0; segment < 2; ++segment) { + void* piece = mmap(static_cast<std::uint8_t*>(reservation) + segment * ChunkBytes, ChunkBytes, + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, backing, + static_cast<off_t>(segment * 2 * ChunkBytes)); + Require(piece != MAP_FAILED, "scattered import: cannot map a segment"); + } + mapping = static_cast<std::uint8_t*>(reservation); + std::memset(mapping, 0, static_cast<std::size_t>(mappingBytes)); + GuestArena::GuestArenaSetSharedBackingRuns_nid_postfix(ResolveRuns); + + GuestAllocations::Mutation().Add(mapping, static_cast<std::size_t>(mappingBytes), true, true, true); + GuestAllocations::Mapped ranges; + for (const auto& range : GuestAllocations::GuestAllocationsAcquire_nid_postfix()) { + if (range->address == reinterpret_cast<std::uint64_t>(mapping)) ranges.push_back(range); + } + Require(ranges.size() == 1, "scattered import: the allocation is not registered"); + + const auto address = reinterpret_cast<std::uint64_t>(mapping); + bool imported = false; + { + std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex()); + imported = device->ImportGuestMemory(ranges, GuestAllocations::GuestAllocationsGeneration_nid_postfix(), false); + device->WaitIdle(); + } + Require(imported, "scattered import: ImportGuestMemory refused the range"); + Require(Imported(device->Device(), address, static_cast<std::size_t>(mappingBytes)), + "a range of two scattered runs larger than udmabuf's size limit was not imported"); + Require(DmaBufImport(*device, address, static_cast<std::size_t>(mappingBytes)), + "a range of two scattered runs larger than udmabuf's size limit was not imported as a dma-buf"); + + // Write through the GPU into the second run; it must land in the second file region. + constexpr std::uint32_t Pattern = 0x5CA77E12u; + { + std::lock_guard lock(AgcDriver::GuestMemory::GpuMutex()); + Require(device->FillBuffer(address + ChunkBytes, 65536, std::array<std::uint32_t, 4>{Pattern, Pattern, Pattern, Pattern}), + "scattered import: the fill in the second run was not served by the import"); + device->WaitIdle(); + } + std::uint32_t second = 0; + Require(pread(backing, &second, sizeof(second), static_cast<off_t>(2 * ChunkBytes)) == static_cast<ssize_t>(sizeof(second)), + "scattered import: cannot read the second run's file region"); + Require(second == Pattern, "scattered import: the second run's GPU write did not land at its scattered file offset"); + std::uint32_t first = 0; + Require(pread(backing, &first, sizeof(first), 0) == static_cast<ssize_t>(sizeof(first)), + "scattered import: cannot read the first run's file region"); + Require(first != Pattern, "scattered import: the second run's write landed in the first run's file region"); + + std::printf("limit %llu MiB, imported %llu MiB as two scattered runs\n", + static_cast<unsigned long long>(limit >> 20u), static_cast<unsigned long long>(mappingBytes >> 20u)); + std::cout << "AGC scattered run-list import test passed\n"; + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} +#endif ```
oneandonlydean commented 2026-10-21 11:47:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T11:47:17Z.


@Mouad-Scriptz-0 socket1001's measurement settles the fd-ownership question. On RADV, about 2.2k descriptors leak during load and about 95 more per 70 s after that, and the guarded build stays flat at 39. Each leaked duplicate also pins the memfd, so released direct memory can't be reclaimed.

We read the guard against d5b768f027 and it is right. createDmaBufImport closes the descriptor it is handed (GuestBufferMemory.cpp:601). importChunk only uses it for fstat and UDMABUF_CREATE, where the kernel takes its own reference, and keeps nothing. So the chunked and sparse paths that return early from createBackingImport never close the duplicate today, and neither does a throwSparseImport inside them. An owner scoped to createBackingImport that hands the descriptor off only to createDmaBufImport covers all of those, the throw included.

To move this forward, could you fold these three into this PR?

  1. @JJenkx's d5b768f027 (run lists above the udmabuf limit through the sparse chunk path).
  2. One of the two descriptor guards (@JJenkx's or @socket1001's; either does the job).
  3. @socket1001's ScatteredRuns.cpp execution case, as the test that drives the real import path. It skips where /dev/udmabuf or a guest-memory import isn't available.

@socket1001 thank you again for both. The /proc/<pid>/fd control was exactly what this question needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315136669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6315136669). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T11:47:17Z. --- @Mouad-Scriptz-0 socket1001's measurement settles the fd-ownership question. On RADV, about 2.2k descriptors leak during load and about 95 more per 70 s after that, and the guarded build stays flat at 39. Each leaked duplicate also pins the memfd, so released direct memory can't be reclaimed. We read the guard against `d5b768f027` and it is right. `createDmaBufImport` closes the descriptor it is handed (`GuestBufferMemory.cpp:601`). `importChunk` only uses it for `fstat` and `UDMABUF_CREATE`, where the kernel takes its own reference, and keeps nothing. So the chunked and sparse paths that return early from `createBackingImport` never close the duplicate today, and neither does a `throwSparseImport` inside them. An owner scoped to `createBackingImport` that hands the descriptor off only to `createDmaBufImport` covers all of those, the throw included. To move this forward, could you fold these three into this PR? 1. @JJenkx's `d5b768f027` (run lists above the udmabuf limit through the sparse chunk path). 2. One of the two descriptor guards (@JJenkx's or @socket1001's; either does the job). 3. @socket1001's `ScatteredRuns.cpp` execution case, as the test that drives the real import path. It skips where `/dev/udmabuf` or a guest-memory import isn't available. @socket1001 thank you again for both. The `/proc/<pid>/fd` control was exactly what this question needed.
JJenkx commented 2026-10-21 14:52:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T14:52:14Z.


The descriptor leak is fatal on a real title, for the fd-ownership point above.

Setup

  • Record of Lodoss War (PPSA05347) on Linux, RX 6650 XT, RADV (Mesa 26.2.4).
  • This PR's head fa67182051 merged locally onto main b5d763770a, without d5b768f027 and without a descriptor guard, against plain main b5d763770a.
  • A runuser shell for the game's user reports 65535 for soft and hard ulimit -n. I did not read the game process's own limit.
  • Each run starts from the same shader-cache and save seed, with the same scripted inputs, alternated main, PR, PR, main; 280 s each.
Run Result
main (2 runs) ran to the planned close; 0 Too many open files
this PR (2 runs) at ~56 s, [gpu] import of GPU memory mapped at 0x21fe40000+0x10000 failed: duplicate direct memory backing: Too many open files (35 and 36 times), then vkAcquireNextImageKHR: Vulkan result -2, terminate, abort at ~58 s

Until the descriptor runs out, the PR's runs present at 59.94 FPS, the same as main. So with a guard in place this title would give a usable A/B. I will repeat it on a head that carries the guard once one is pushed here.

On main this title logs 48 failed at vkAllocateMemory (-1000072003) and host import budget lowered to the 138.2 MiB live. That is the scattered direct-memory case this PR fixes, so Lodoss should be a good second title for it once the leak is closed.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6319009466 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6319009466). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T14:52:14Z. --- The descriptor leak is fatal on a real title, for the fd-ownership point above. **Setup** - Record of Lodoss War (PPSA05347) on Linux, RX 6650 XT, RADV (Mesa 26.2.4). - This PR's head fa67182051 merged locally onto `main` b5d763770a, without d5b768f027 and without a descriptor guard, against plain `main` b5d763770a. - A `runuser` shell for the game's user reports 65535 for soft and hard `ulimit -n`. I did not read the game process's own limit. - Each run starts from the same shader-cache and save seed, with the same scripted inputs, alternated `main`, PR, PR, `main`; 280 s each. | Run | Result | |---|---| | `main` (2 runs) | ran to the planned close; 0 `Too many open files` | | this PR (2 runs) | at ~56 s, `[gpu] import of GPU memory mapped at 0x21fe40000+0x10000 failed: duplicate direct memory backing: Too many open files` (35 and 36 times), then `vkAcquireNextImageKHR: Vulkan result -2`, `terminate`, abort at ~58 s | Until the descriptor runs out, the PR's runs present at 59.94 FPS, the same as `main`. So with a guard in place this title would give a usable A/B. I will repeat it on a head that carries the guard once one is pushed here. On `main` this title logs 48 `failed at vkAllocateMemory (-1000072003)` and `host import budget lowered to the 138.2 MiB live`. That is the scattered direct-memory case this PR fixes, so Lodoss should be a good second title for it once the leak is closed. AI-assisted: yes (Claude Code); results above were run on this machine.
hugodearaujo commented 2026-10-21 14:55:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-21T14:55:47Z.


Another AMD-on-Linux title for the scattered-runs case: 007 First Light (PPSA11386, 01.018.000).

Setup. Arch Linux, kernel 7.2.11, RX 9070 XT, RADV (Mesa 26.2.5); /dev/udmabuf read-write through the kvm group, size_limit_mb 64, list_limit 1024. main is 2f161d4f3. The change is this PR's head fa67182051 with @JJenkx's d5b768f027 and @socket1001's descriptor guard on top, merged onto that main locally (only the TechnicalDebt file conflicts; I kept main's text for the build). Both arms use the same app.elf; four libraries differ (libc, libkernel, libSceAgcDriver, libSceVideoOut). Each run starts from the same save, gets no input, and runs 13 minutes with APS5_TRACE_SUMMARY_EVERY=10, ANYPS5_NO_SHADER_CACHE=1 and APS5_PROFILE_DRAW=1. Two pairs, in the order change, main, main, change.

Why this title needs it. With APS5_TRACE_HOST_IMPORT=1 (on an older main, aa1b1bfce), the failed imports were rw-s views of /memfd:direct memory, and most of the 4–8 MiB requests spanned two to eight mappings at scattered file offsets, for example 0x3500000000+0x400000 over file offsets 0x200000 and 0x29c00000.

main main + this PR
title screen reached (it waits for ✕) 8.5 / 9.0 min 6.0 / 5.5 min
frame rate on the title screen (560–770 s) 0.96 / 0.96 1.63 / 1.66
failed host imports (failed at vkAllocateMemory) 114 / 126 0 / 0
host import budget lowered 42 / 43 0 / 0
refused imports at shutdown 299 / 306 0 / 0
Driver.Packet.memory_wait per frame on the title screen 4.0 / 4.0 s 2.3 / 2.3 s
GPU busy per present on the title screen 96 / 96 ms 96 / 96 ms

The write-watch line reads dma-buf imports keep write protection: yes (… 0 stale after a GPU store over CPU writes), so the coherence check passes on RADV here too. No amdgpu timeout or reset in the kernel log during the four runs, and none of them crashed.

What is left on the title screen is not this PR's case: one 12.5 MiB writable buffer at 0x3f00094200 crosses a 2 MiB and a 12 MiB registered range, so joinedRun refuses the partial join (it would be 14 MiB, over the 8 MiB window) and the buffer is copied on the CPU about 450 times a second, the same on both arms.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6319081073 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6319081073). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-21T14:55:47Z. --- Another AMD-on-Linux title for the scattered-runs case: 007 First Light (PPSA11386, 01.018.000). **Setup.** Arch Linux, kernel 7.2.11, RX 9070 XT, RADV (Mesa 26.2.5); `/dev/udmabuf` read-write through the `kvm` group, `size_limit_mb` 64, `list_limit` 1024. `main` is 2f161d4f3. The change is this PR's head fa67182051 with @JJenkx's d5b768f027 and @socket1001's descriptor guard on top, merged onto that `main` locally (only the TechnicalDebt file conflicts; I kept `main`'s text for the build). Both arms use the same `app.elf`; four libraries differ (`libc`, `libkernel`, `libSceAgcDriver`, `libSceVideoOut`). Each run starts from the same save, gets no input, and runs 13 minutes with `APS5_TRACE_SUMMARY_EVERY=10`, `ANYPS5_NO_SHADER_CACHE=1` and `APS5_PROFILE_DRAW=1`. Two pairs, in the order change, `main`, `main`, change. **Why this title needs it.** With `APS5_TRACE_HOST_IMPORT=1` (on an older `main`, aa1b1bfce), the failed imports were `rw-s` views of `/memfd:direct memory`, and most of the 4–8 MiB requests spanned two to eight mappings at scattered file offsets, for example `0x3500000000+0x400000` over file offsets `0x200000` and `0x29c00000`. | | `main` | `main` + this PR | |---|---|---| | title screen reached (it waits for ✕) | 8.5 / 9.0 min | 6.0 / 5.5 min | | frame rate on the title screen (560–770 s) | 0.96 / 0.96 | 1.63 / 1.66 | | failed host imports (`failed at vkAllocateMemory`) | 114 / 126 | 0 / 0 | | `host import budget lowered` | 42 / 43 | 0 / 0 | | refused imports at shutdown | 299 / 306 | 0 / 0 | | `Driver.Packet.memory_wait` per frame on the title screen | 4.0 / 4.0 s | 2.3 / 2.3 s | | GPU busy per present on the title screen | 96 / 96 ms | 96 / 96 ms | The write-watch line reads `dma-buf imports keep write protection: yes (… 0 stale after a GPU store over CPU writes)`, so the coherence check passes on RADV here too. No amdgpu timeout or reset in the kernel log during the four runs, and none of them crashed. What is left on the title screen is not this PR's case: one 12.5 MiB writable buffer at `0x3f00094200` crosses a 2 MiB and a 12 MiB registered range, so `joinedRun` refuses the partial join (it would be 14 MiB, over the 8 MiB window) and the buffer is copied on the CPU about 450 times a second, the same on both arms.
JJenkx commented 2026-10-21 16:10:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T16:10:26Z.


Follow-up on Lodoss with a descriptor guard. The leak is gone, but this title runs slower with the PR.

Guard. I added a local guard on top of the earlier merge, for this test only (bb0edaf0fe; not pushed here). createBackingImport holds the descriptor in a scope owner, which closes it on the chunked and sparse return paths and on a throw. It passes the descriptor on with std::exchange only to createDmaBufImport. That is the shape described above.

Setup

  • Record of Lodoss War (PPSA05347), Linux, RX 6650 XT, RADV (Mesa 26.2.4).
  • main b5d763770a against main + this PR (fa67182051) + the guard.
  • Identical shader-cache and save seeds, scripted inputs, 280 s per run, alternated main, PR, PR, main.
  • APS5_TRACE_SECONDS=200:30 with 2097152 events. Every trace reports dirty false and dropped false.
  • A 2 s sampler saw no compiler running during any run.
Run FPS (presents/window) frame p50 / p99 ms /proc/<pid>/fd count host imports at shutdown: made / refused / failed
main 53.41 18.3 / 26.3 34–35 8787 / 1307016 / 48
PR + guard 35.04 27.7 / 40.6 26–36 758586 / 0 / 0
PR + guard 34.98 27.6 / 46.5 34–36 789750 / 0 / 0
main 40.72 26.2 / 66.4 34–36 19355 / 1051045 / 58
  • The guard works. The descriptor count stays flat, there is no Too many open files, both PR runs reach the planned close, and no import fails.
  • Lodoss is slower with the PR. Both PR runs measure ~35 FPS, below each main run here and below two earlier main runs of the same scene (46.9 and 54.1).
  • The likely cause is import churn. main refuses about a million map-time imports and copies those ranges. With the PR, the same map events become 760–790k actual imports in one run (map requester), and that costs more than the copies.

Code Violet (above) gains, because there the imports are what lets the title render. So whether to import scattered runs is right per range, but repeated map-time imports of the same short-lived ranges need a check before this is a net win on titles that map and unmap often. I have not profiled where the time goes in the PR runs.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6320642522 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6320642522). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T16:10:26Z. --- Follow-up on Lodoss with a descriptor guard. The leak is gone, but this title runs slower with the PR. **Guard.** I added a local guard on top of the earlier merge, for this test only (bb0edaf0fe; not pushed here). `createBackingImport` holds the descriptor in a scope owner, which closes it on the chunked and sparse return paths and on a throw. It passes the descriptor on with `std::exchange` only to `createDmaBufImport`. That is the shape described above. **Setup** - Record of Lodoss War (PPSA05347), Linux, RX 6650 XT, RADV (Mesa 26.2.4). - `main` b5d763770a against `main` + this PR (fa67182051) + the guard. - Identical shader-cache and save seeds, scripted inputs, 280 s per run, alternated `main`, PR, PR, `main`. - `APS5_TRACE_SECONDS=200:30` with 2097152 events. Every trace reports dirty false and dropped false. - A 2 s sampler saw no compiler running during any run. | Run | FPS (presents/window) | frame p50 / p99 ms | `/proc/<pid>/fd` count | host imports at shutdown: made / refused / failed | |---|---|---|---|---| | `main` | 53.41 | 18.3 / 26.3 | 34–35 | 8787 / 1307016 / 48 | | PR + guard | 35.04 | 27.7 / 40.6 | 26–36 | 758586 / 0 / 0 | | PR + guard | 34.98 | 27.6 / 46.5 | 34–36 | 789750 / 0 / 0 | | `main` | 40.72 | 26.2 / 66.4 | 34–36 | 19355 / 1051045 / 58 | - **The guard works.** The descriptor count stays flat, there is no `Too many open files`, both PR runs reach the planned close, and no import fails. - **Lodoss is slower with the PR.** Both PR runs measure ~35 FPS, below each `main` run here and below two earlier `main` runs of the same scene (46.9 and 54.1). - **The likely cause is import churn.** `main` refuses about a million map-time imports and copies those ranges. With the PR, the same map events become 760–790k actual imports in one run (`map` requester), and that costs more than the copies. Code Violet (above) gains, because there the imports are what lets the title render. So whether to import scattered runs is right per range, but repeated map-time imports of the same short-lived ranges need a check before this is a net win on titles that map and unmap often. I have not profiled where the time goes in the PR runs. AI-assisted: yes (Claude Code); results above were run on this machine.
Pacuka commented 2026-10-21 19:16:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-21T19:16:00Z.


@JJenkx for contrast with Lodoss: Subnautica (PPSA02453, Unity) went the other way on the same GPU, RX 6650 XT with RADV 26.2.4 (earlier comment). On main, 32 host imports fail at vkAllocateMemory and fall back to copies. With this PR (ca1d48211), none fail: the title screen goes from ~20 to 33-35 fps and the lifepod fire from ~5 to ~13 fps.

That run used an older head, before the descriptor fix, and I didn't log the made/refused import counts. So I can't tell yet whether Subnautica also shows the map-time import churn. If it helps, I can rerun on fa67182051 with the shutdown counters.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324423992 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6324423992). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-21T19:16:00Z. --- @JJenkx for contrast with Lodoss: Subnautica (PPSA02453, Unity) went the other way on the same GPU, RX 6650 XT with RADV 26.2.4 ([earlier comment](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6253726244)). On `main`, 32 host imports fail at `vkAllocateMemory` and fall back to copies. With this PR (ca1d48211), none fail: the title screen goes from ~20 to 33-35 fps and the lifepod fire from ~5 to ~13 fps. That run used an older head, before the descriptor fix, and I didn't log the made/refused import counts. So I can't tell yet whether Subnautica also shows the map-time import churn. If it helps, I can rerun on fa67182051 with the shutdown counters. AI-assisted: yes (Claude Code)
JJenkx commented 2026-10-21 19:33:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T19:33:47Z.


Follow-up on the Lodoss slowdown, with a correction to what causes it.

Test. I tried deferring map-time imports of scattered backings (more than one run) to their first GPU use, on top of the guarded build. It changed nothing:

Run FPS map-time imports made
guarded PR + deferral 35.35 790,166
guarded PR + deferral 35.11 787,916
main 44.18 4,885
main 54.36 2,474

The setup was the same as above: alternated, dropped: no, with a 2-compiler overlap in one trace window. So the imports that churn are not scattered ranges.

What actually differs. On main, a few early failed at vkAllocateMemory (-1000072003) lower the host import budget (host import budget lowered 18 times per run). The collapsed budget then refuses about a million map-time imports, and those ranges are copied. This PR removes those failures, so the budget never collapses and every map event is imported.

So the Lodoss difference is not specific to the run-list path. It is the cost of importing on every map event in a title that maps and unmaps constantly, a cost the collapsed budget hides on main. Any change that keeps the budget intact should show it on this title. If so, it is a separate map-time import policy question, not a defect in the run-list import itself.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324777823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6324777823). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-21T19:33:47Z. --- Follow-up on the Lodoss slowdown, with a correction to what causes it. **Test.** I tried deferring map-time imports of scattered backings (more than one run) to their first GPU use, on top of the guarded build. It changed nothing: | Run | FPS | map-time imports made | |---|---|---| | guarded PR + deferral | 35.35 | 790,166 | | guarded PR + deferral | 35.11 | 787,916 | | `main` | 44.18 | 4,885 | | `main` | 54.36 | 2,474 | The setup was the same as above: alternated, `dropped: no`, with a 2-compiler overlap in one trace window. So the imports that churn are not scattered ranges. **What actually differs.** On `main`, a few early `failed at vkAllocateMemory (-1000072003)` lower the host import budget (`host import budget lowered` 18 times per run). The collapsed budget then refuses about a million map-time imports, and those ranges are copied. This PR removes those failures, so the budget never collapses and every map event is imported. So the Lodoss difference is not specific to the run-list path. It is the cost of importing on every map event in a title that maps and unmaps constantly, a cost the collapsed budget hides on `main`. Any change that keeps the budget intact should show it on this title. If so, it is a separate map-time import policy question, not a defect in the run-list import itself. AI-assisted: yes (Claude Code); results above were run on this machine.
Pacuka commented 2026-10-21 19:35:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-21T19:35:53Z.


Follow-up with fresh runs, as offered. Subnautica (PPSA02453), RX 6650 XT, RADV 26.2.4, CachyOS 7.2.2. main 1896871ba against main + this PR (fa67182051, without a descriptor guard). I played the same route by hand in each run (intro, lifepod fire, PDA, out of the pod), with APS5_PROFILE_DRAW=1. Rough numbers, not a scripted benchmark.

main + this PR
presents per 10 s near the end 40-46 120-140
host imports at shutdown: made / refused / failed 51330 / 6859973 / 94 3916 / 0 / 0
made by map 992 3693
/proc/<pid>/fd ~60-70, flat 450 → 3706 over ~3 min
  • No map-time churn here. Unlike Lodoss (760-790k map imports), Subnautica makes only ~3.7k, so the PR is a clear win on this title.
  • The descriptor count keeps rising. 1682 imports were live at shutdown, but 3706 descriptors were open. This matches the leak socket1001 measured.
  • One of two PR runs froze during loading. About 20 s after the first presents, the log stopped and every thread sat in futex_do_wait. The count had jumped from 221 to 2568 in 40 s. I couldn't attach gdb (ptrace_scope 1), and the rerun under gdb didn't freeze, so I don't know whether the freeze is related to the leak.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324818911 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6324818911). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-21T19:35:53Z. --- Follow-up with fresh runs, as offered. Subnautica (PPSA02453), RX 6650 XT, RADV 26.2.4, CachyOS 7.2.2. `main` 1896871ba against `main` + this PR (fa67182051, without a descriptor guard). I played the same route by hand in each run (intro, lifepod fire, PDA, out of the pod), with `APS5_PROFILE_DRAW=1`. Rough numbers, not a scripted benchmark. | | `main` | + this PR | |---|---|---| | presents per 10 s near the end | 40-46 | 120-140 | | host imports at shutdown: made / refused / failed | 51330 / 6859973 / 94 | 3916 / 0 / 0 | | made by `map` | 992 | 3693 | | `/proc/<pid>/fd` | ~60-70, flat | 450 → 3706 over ~3 min | - **No map-time churn here.** Unlike Lodoss (760-790k `map` imports), Subnautica makes only ~3.7k, so the PR is a clear win on this title. - **The descriptor count keeps rising.** 1682 imports were live at shutdown, but 3706 descriptors were open. This matches the leak socket1001 measured. - **One of two PR runs froze during loading.** About 20 s after the first presents, the log stopped and every thread sat in `futex_do_wait`. The count had jumped from 221 to 2568 in 40 s. I couldn't attach gdb (`ptrace_scope` 1), and the rerun under gdb didn't freeze, so I don't know whether the freeze is related to the leak. AI-assisted: yes (Claude Code)
socket1001 commented 2026-10-21 20:22:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T20:22:00Z.


A third data class for the map-time import question @JJenkx raised: Mafia is import-hungry but not churn-heavy, so its numbers separate "importing is expensive" from "importing per map event is expensive".

AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed this write-up before it was posted.

Setup. PPSA14299 (Mafia: The Old Country), RX 9070 (1002:7550), RADV Mesa 25.2.8, Ubuntu 24.04, APS5_TRACE_HOST_IMPORT=1, 70 s legs, deployed arms differing only in libSceAgcDriver.prx (146676fead head vs 6afe0580a6 head + d5b768f027), interleaved head, fix / fix, head / head, fix.

arm imports per leg failed imports host import budget lowered FPS
head fa671820 3841 / 3791 / 3801 0 0 22.72 / 22.39 / 21.85
head + d5b768f027 3914 / 3768 / 3777 0 0 22.19 / 22.62 / 22.21

Mafia makes ~3,800 imports in 70 s -- about 55 per second, the same order as Subnautica's ~3.7k per session, and roughly fifty times lower than Lodoss's 760-790k per 280 s (~2.8k/s). It also never collapses the import budget on either arm, and the FPS is unchanged (22.32 vs 22.34 arm means). Its main arm is the opposite failure: 107-117 import attempts, 12-13 failed at vkAllocateMemory, 3.4 FPS -- a title where importing is the whole win.

So Mafia fits the "rate, not path" reading: same run-list import, ~4k calls per run, no regression. The title that pays for map-time imports is paying for the rate, not for the scattered-run case.

For the leak side, our guarded control matches what @Pacuka measured independently: /proc/<pid>/fd 2,224 memfd descriptors by t=12 s unguarded (2,321 by t=63 s) against 6 flat with the guard, frames unchanged (1341/1314 vs 1320/1319 by t=63 s). The guard @hugodearaujo used is the same shape.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325706958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6325706958). Originally posted by [socket1001](https://github.com/socket1001) on 2026-10-21T20:22:00Z. --- A third data class for the map-time import question @JJenkx raised: Mafia is import-hungry but **not** churn-heavy, so its numbers separate "importing is expensive" from "importing per map event is expensive". AI-assisted: yes. These measurements were produced by an autonomous agent (Hermes) running on the user's behalf; the user reviewed this write-up before it was posted. **Setup.** PPSA14299 (Mafia: The Old Country), RX 9070 (`1002:7550`), RADV Mesa 25.2.8, Ubuntu 24.04, `APS5_TRACE_HOST_IMPORT=1`, 70 s legs, deployed arms differing only in `libSceAgcDriver.prx` (`146676fead` head vs `6afe0580a6` head + `d5b768f027`), interleaved head, fix / fix, head / head, fix. | arm | imports per leg | failed imports | `host import budget lowered` | FPS | |---|---|---|---|---| | head `fa671820` | 3841 / 3791 / 3801 | 0 | 0 | 22.72 / 22.39 / 21.85 | | head + `d5b768f027` | 3914 / 3768 / 3777 | 0 | 0 | 22.19 / 22.62 / 22.21 | Mafia makes ~3,800 imports in 70 s -- about 55 per second, the same order as Subnautica's ~3.7k per session, and roughly **fifty times lower** than Lodoss's 760-790k per 280 s (~2.8k/s). It also never collapses the import budget on either arm, and the FPS is unchanged (22.32 vs 22.34 arm means). Its `main` arm is the opposite failure: 107-117 import attempts, 12-13 `failed at vkAllocateMemory`, 3.4 FPS -- a title where importing is the whole win. So Mafia fits the "rate, not path" reading: same run-list import, ~4k calls per run, no regression. The title that pays for map-time imports is paying for the rate, not for the scattered-run case. For the leak side, our guarded control matches what @Pacuka measured independently: `/proc/<pid>/fd` 2,224 memfd descriptors by t=12 s unguarded (2,321 by t=63 s) against 6 flat with the guard, frames unchanged (1341/1314 vs 1320/1319 by t=63 s). The guard @hugodearaujo used is the same shape.
JJenkx commented 2026-10-22 01:49:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T01:49:43Z.


@Pacuka @socket1001 thanks, that settles the Lodoss question. It is the import rate, not the run-list path. Subnautica and Mafia make about 4k imports per run and gain or hold steady; Lodoss makes about 2.8k map-time imports per second.

The Lodoss cost is handled separately by #7465, which defers small imports until their first GPU use. With #7465 alongside, Lodoss holds its 60 FPS cap (posted on #7465 and #8091). So it is not a reason to change this PR.

@Pacuka on the loading freeze: the guard I used locally (bb0edaf0fe, the same shape as socket1001's, closing the duplicate on the chunked and sparse return paths and on a throw) kept /proc/<pid>/fd flat at about 35 on Lodoss. If you rerun Subnautica with a guarded build, that would tell whether the freeze comes from the descriptor growth.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330733136 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6330733136). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T01:49:43Z. --- @Pacuka @socket1001 thanks, that settles the Lodoss question. It is the import rate, not the run-list path. Subnautica and Mafia make about 4k imports per run and gain or hold steady; Lodoss makes about 2.8k map-time imports per second. The Lodoss cost is handled separately by #7465, which defers small imports until their first GPU use. With #7465 alongside, Lodoss holds its 60 FPS cap (posted on #7465 and #8091). So it is not a reason to change this PR. @Pacuka on the loading freeze: the guard I used locally (bb0edaf0fe, the same shape as socket1001's, closing the duplicate on the chunked and sparse return paths and on a throw) kept `/proc/<pid>/fd` flat at about 35 on Lodoss. If you rerun Subnautica with a guarded build, that would tell whether the freeze comes from the descriptor growth. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-22 03:14:42 +00:00 (Migrated from github.com)

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


@JJenkx thanks, that matches the numbers from all four titles: the run-list import itself is not the cost, and PPSA05347's drop comes from the map-time import rate, which #7465 handles. I agree it isn't a reason to change this PR.

One run would settle it: could you run PPSA05347 on the same scene in three builds, main, main + #4449, and main + #4449 + #7465, and post the FPS and the refused-import count for each? Our test machine is NVIDIA without dma-buf import, so it never takes this PR's path, and your AMD + udmabuf setup is the one that shows how the two interact.

The descriptor guard still needs to be in the head (bb0edaf0fe or d5b768f027, whichever you prefer). Without it /proc/<pid>/fd grows from 450 to 3706 in about 3 minutes in Pacuka's PPSA02453 run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331786269 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6331786269). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-22T03:14:42Z. --- @JJenkx thanks, that matches the numbers from all four titles: the run-list import itself is not the cost, and PPSA05347's drop comes from the map-time import rate, which #7465 handles. I agree it isn't a reason to change this PR. One run would settle it: could you run PPSA05347 on the same scene in three builds, `main`, `main` + #4449, and `main` + #4449 + #7465, and post the FPS and the refused-import count for each? Our test machine is NVIDIA without dma-buf import, so it never takes this PR's path, and your AMD + udmabuf setup is the one that shows how the two interact. The descriptor guard still needs to be in the head (bb0edaf0fe or `d5b768f027`, whichever you prefer). Without it `/proc/<pid>/fd` grows from 450 to 3706 in about 3 minutes in Pacuka's PPSA02453 run.
Pacuka commented 2026-10-22 15:36:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-22T15:36:39Z.


@JJenkx @oneandonlydean rerun with a guarded build, as suggested. Subnautica (PPSA02453), RX 6650 XT, RADV 26.2.4: main 1896871ba + this PR (fa67182051) + d5b768f027 + socket1001's descriptor guard. Same hand-played route as yesterday (intro, lifepod fire, PDA, out of the pod), APS5_PROFILE_DRAW=1, ~2.5 min.

unguarded (yesterday) guarded
/proc/<pid>/fd 450 → 3706 over ~3 min 58-72, flat (4-5 memfd)
presents per 10 s 120-140 106-265
host imports made / refused / failed 3916 / 0 / 0 3217 / 0 / 0

No freeze while loading in this run. That is a single run, so I can't rule it out completely, but the descriptor growth is gone and the speedup is unchanged.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6344727018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#issuecomment-6344727018). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-10-22T15:36:39Z. --- @JJenkx @oneandonlydean rerun with a guarded build, as suggested. Subnautica (PPSA02453), RX 6650 XT, RADV 26.2.4: `main` 1896871ba + this PR (fa67182051) + `d5b768f027` + socket1001's descriptor guard. Same hand-played route as yesterday (intro, lifepod fire, PDA, out of the pod), `APS5_PROFILE_DRAW=1`, ~2.5 min. | | unguarded (yesterday) | guarded | |---|---|---| | `/proc/<pid>/fd` | 450 → 3706 over ~3 min | 58-72, flat (4-5 memfd) | | presents per 10 s | 120-140 | 106-265 | | host imports made / refused / failed | 3916 / 0 / 0 | 3217 / 0 / 0 | No freeze while loading in this run. That is a single run, so I can't rule it out completely, but the descriptor growth is gone and the speedup is unchanged. AI-assisted: yes (Claude Code)
CnRJay commented 2026-11-01 19:52:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:52:30Z.

Review: COMMENTED


dmaBufImportsCoherent starts at true and only a successful probe sets it. In decideImportWatch the early returns (APS5_WRITE_WATCH_IMPORTS=watch, for example, and the no-watch branch when ProbeDmaBufImportWriteProtection fails) leave it true, and the log line then says dma-buf imports "are used". On i915 that is the incoherent case this PR exists for: the import serves stale CPU lines. Could the default be "not coherent" until a probe has measured otherwise, so a failed or skipped probe takes the copy path?

On the run limit: SharedBackingRuns returns false once a range needs more than DmaBufRunLimit (1024) runs, and resolveBackingRuns then falls back to GuestArenaSharedBacking_nid_postfix, which returns one offset for the whole range. Is that the same single-offset mistake the PR fixes, for ranges with more than 1024 runs? I'd expect that case to refuse the dma-buf import, and a test with 1025 runs would pin it.

This and #4448 both change import creation in GuestBufferMemory.cpp; which one goes first?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729932188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4449#pullrequestreview-5729932188). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:52:30Z. **Review:** COMMENTED --- `dmaBufImportsCoherent` starts at `true` and only a successful probe sets it. In `decideImportWatch` the early returns (`APS5_WRITE_WATCH_IMPORTS=watch`, for example, and the no-watch branch when `ProbeDmaBufImportWriteProtection` fails) leave it `true`, and the log line then says dma-buf imports "are used". On i915 that is the incoherent case this PR exists for: the import serves stale CPU lines. Could the default be "not coherent" until a probe has measured otherwise, so a failed or skipped probe takes the copy path? On the run limit: `SharedBackingRuns` returns false once a range needs more than `DmaBufRunLimit` (1024) runs, and `resolveBackingRuns` then falls back to `GuestArenaSharedBacking_nid_postfix`, which returns one offset for the whole range. Is that the same single-offset mistake the PR fixes, for ranges with more than 1024 runs? I'd expect that case to refuse the dma-buf import, and a test with 1025 runs would pin it. This and #4448 both change import creation in `GuestBufferMemory.cpp`; which one goes first?
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!4449
No description provided.