feat(libSceAgcDriver): import scattered direct memory as a dma-buf run list and probe its coherence #4449
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4449"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 ontomain'ssharedBackingimport structure (port/4449, authorship kept), plus the fixes from the review of 10-17.GuestArenaSharedBackingRuns(libkernel, registered byDirectMemory) resolves a range into its runs in address order, up to udmabuf's 1024; one run keepsmain's chunked and sparse paths, several runs create one udmabuf throughUDMABUF_CREATE_LIST. The single resolver stays as the fallback for registrations that do not provide runs.guest_memorygainsCheckDirectMemorySharedBackingRuns: 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.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 onmain9f25d0bf5:guest_memory(with the new case),agc_dma_data_tests,agc_write_watch_coverage,agc_host_import_unmap,agc_driver_host_import_at_mapandagc_driver_host_import_teardownpass. The probe on this GPU reports4 stale after a GPU store over CPU writesfor dma-buf imports, so the fallback stays off here.tools/check_conventions.py --base origin/mainandgit diff --checkpass. 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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
SharedBackingon 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 leaveSharedBackingRunsfor a PR with a device that needs it.dmaBufImportsCoherentalso stays false on the early returns ofdecideImportWatch(APS5_WRITE_WATCH_IMPORTS=watchorunwatch, no write watch), which turns the fallback off there without a probe.It needs a rebase as well:
docs/dev/TechnicalDebt.mdwas split, so the entry goes underdocs/dev/debt/.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
e7c70a2dfplus Mickey fixes, including #5030). B adds this PR, which merged cleanly onto that base.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, andSharedBackingon main refuses non-contiguous runs. So these ranges are copied on the CPU instead.[buffers]outside imports)host import ... failedlinesCoherence probe on RADV:
0 stale after a GPU store over CPU writesfor both host-pointer and dma-buf imports, so the fallback stays enabled here:Checks
GuestBufferMemory.cppconflict against the newcreateBackingImportstructure for a local build: fullctest1033/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
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),SharedBackingon 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 ... failedlines 40 to 0, no visual change, and his probe reads0 stalefor both import kinds so the fallback stays on there. On i915 the probe turns the fallback off, so nothing changes here. I'd keepSharedBackingRunsin this PR on that evidence; if you'd rather see it separately I can split it, with the probe first.The early returns of
decideImportWatchare a real gap:dmaBufImportsCoherentstays false underAPS5_WRITE_WATCH_IMPORTS=watchorunwatchand 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 todocs/dev/debt/libSceAgcDriver.md; johnmaia already resolved thecreateBackingImportconflict for his local build).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.mainhas since landedBackingFile/sharedBacking— a single (file, offset) shared backing per import, resolved throughGuestArenaSharedBacking_nid_postfix, feedingcreateChunkedDmaBufImport/createDmaBufImportwith one offset. This PR implements the run list:SharedBackingRunarrays throughGuestArenaSharedBackingRuns_nid_postfix, aDmaBufRunLimit, and a span-of-runscreateDmaBufImport— 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.
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-backingsharedBackingimport path, so the run list needs porting onto it rather than a text rebase.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, andGuestMemory::WriteWatched()is false.decideImportWatchreturns on that path before it can setdmaBufImportsCoherent, so the flag stays at its default and the dma-buf fallback is skipped. The log then fills withhost 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
dmaBufImportsCoherenttrue 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 astaleAfterFillreading 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.
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
decideImportWatchreturns before the probe,dmaBufImportsCoherentkeeps 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 thesharedBackingversion of the same import this needs a port, not a rebase.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T08:28:49Z.
The port, as directed — since
mainnow carries thesharedBackingversion 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:decideImportWatchnow 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:GuestArenaSharedBackingRunsresolves a guest range into the runs of its direct memory backing (one per physical allocation, up to udmabuf's 1024), registered byDirectMemory; a single run keepsmain's chunked and sparse paths, several runs create one udmabuf buffer per run throughUDMABUF_CREATE_LISTwatchedDmaBuf != watchedHostPointer) is ported to the runs APIdmaBufImportsCoherentdefaults 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 disabledmain's sparse path before any probe ranVerified 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 knownmainregression (agc_driver_tessellationsegfault, #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.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T08:33:45Z.
Thanks @blawesom, that covers both asks (the port onto
sharedBackingand the probe on the no-write-watch path). We're reviewing8d3627214now, including thedmaBufImportsCoherentdefault 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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T08:37:54Z.
Review of the port (
port/4449at 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_CREATEplus main's chunked/sparse paths, several runs throughUDMABUF_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.
decideImportWatchnow callsProbeDmaBufImportWriteProtectionwhen!GuestMemory::WriteWatched(), but that probe still starts withif (!GuestWriteWatchAvailable_nid_postfix()) { probe.failure = "the write watch"; return probe; }. On LinuxWriteWatched()isGuestWriteWatchAvailable(), so the probe always fails there,dmaBufImportsCoherentkeeps 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.ProbeDmaBufImportWriteProtection, guard itsGuestWriteWatchRegister/Unregistercalls the way the host probe does, and log "not measured" whenfailure != nullptr(it currently prints "CPU-coherent (0 of 0 pages stale)" for an unmeasured device).MAP_SHAREDmemfd, 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 branchif (step != nullptr && watchedDmaBuf != watchedHostPointer)callscreateBackingImportwith nodmaBufImportsCoherentcheck. 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.&& state.dmaBufImportsCoherentto that condition.Smaller notes:
CheckDirectMemorySharedBackingRunstest is good (runs,preadoffset, capacity), but nothing covers theCREATE_LISTimport, the probe or the mixed-path gate.dmaBufImportsCoherentdefaulting to true, theAPS5_WRITE_WATCH_IMPORTSoverrides 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.
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. WhensharedBackingfailed it ran by default on Linux, much like this PR's several-runs path.Kena: Bridge of Spirits (PPSA01802), forest title scene, no input.
mainf8b22edfb,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:main+ a run-bounds memomainSo 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/4449branch. Once the port is the PR's base, I can run the same scene on it.AI-assisted: yes (Claude Code)
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.
Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-18T12:22:12Z.
@blawesom's
port/4449is now this PR's head, rebased ontomain9f25d0bf5(249ef873b, authorship kept; the only conflict was the debt file, both entries stay), with the review's fixes on top inca1d48211:ProbeDmaBufImportWriteProtectionno 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 ofdecideImportWatchmeasures on Linux.dma-buf coherence not measured (probe failed at %s, %d)when the probe fails, instead of reporting an unmeasured device as coherent.importRunAtrequiresstate.dmaBufImportsCoherent.CheckDirectMemorySharedBackingRunscloses 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_mapandagc_driver_host_import_teardownpass; the probe here reports 4 of 4 pages stale after a GPU store, so the fallback stays off on this GPU. Conventions andgit diff --checkpass. The description is rewritten for the port. Not covered yet: a test on the no-watch branch and coverage of theCREATE_LISTimport, 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.
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 tookcommitDmaStore'sWaitIdlepath. A gdb sample of the committer showed ~38% of its time incommitDmaStore→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):The image is correct. The only flicker (a ground shadow briefly getting lighter) was there before and is unchanged.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-18T13:02:39Z.
Follow-up: without
APS5_PROFILE_DRAWthe 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).
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
main9f25d0bf5. 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.host import ... failedlinesmain9f25d0bf5That 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:
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)
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.
main61d3d3080(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 printsForcing submitDone to avoid TRC R4089 breachwhile the GPU thread is busy). The log shows 32host import of 0x2xx000000+0x800000 failed at vkAllocateMemory (-1000072003); falling back to copies. gdb samples of the draw thread land inHostImportFor→GuestAllocationsAcquire.main61d3d3080+ this PR (ca1d48211, clean merge): 0 host import failures, same image.main(FPS from the window title, rough numbers from normal play, not a same-spot benchmark.)
AI-assisted (Claude Code).
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=1only (for the present counts).main7a015c094(no PRs): boots, loads, plays the intro and gives player control afterwards; the image looks right. 27host import ... failedlines. The first run stalled during loading (no presents for over 3 minutes,Forcing submitDone to avoid TRC R4089 breachrepeating), and a restart got through. In game after the intro: ~92 presents per 10 s.maina4c04c75d+ 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).
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.createBackingImportnow receives the duplicated backingfileas a raw integer. When the chunked import succeeds, or the sparse path succeeds or throws, it returns before the consumingcreateDmaBufImportcall. Those paths do not close this backing descriptor; removingBackingFilealso removed the former scope cleanup.I retained scope ownership until handing the descriptor to
createDmaBufImportviastd::exchange. I also addedfcntl(F_GETFD)/EBADFassertions 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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T01:53:27Z.
@Mouad-Scriptz-0 We confirmed JJenkx's report on
fa671820514fby reading the code.createBackingImporttakes the backing fd as a rawint, and onlycreateDmaBufImportcloses 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 hadBackingFileRAII here, and this head removes it.Could you restore scope ownership on both callers (
createSharedBackingImportand the runs path in the import function)? ABackingFile-style guard works, and so does JJenkx'sstd::exchangehand-off intocreateDmaBufImport. Please also add a test that checksfcntl(fd, F_GETFD) == -1 && errno == EBADFafter 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.
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
7.0.0-38-generic, Mesa 25.2.8, RADV1002:7550,renderD128(RDNA 4)v0.1.3tag (3fd1cc393) plus this PR's current headfa671820; the 6 code hunks applied, only thedocs/hunk did not apply to that tagAPS5_TRACE_HOST_IMPORT=1, no other switchesSame-tree control (RX 9070)
-13failuresv0.1.3, this PR revertedv0.1.3+ this PR7.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.38line 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-
mainA/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:
-13isVK_ERROR_UNKNOWN; the trace prints the rawVkResult. A standalone Vulkan program on this device reproduces the mechanism:VkImportMemoryHostPointerInfoEXT+vkAllocateMemory):-13udmabufimport of the same bytes:VK_SUCCESSVK_BUFFER_CREATE_SPARSE_BINDING_BIT+vkQueueBindSparse):VK_SUCCESSSo 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
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:
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
v0.1.3tag, notmain.mainwas atb85d972f4when this was written and is now339217ebc; the merge-base of this PR andmainis903cbbd5, noteaa5c923(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.host import failuresis in fact the attempt count, and-13is the allocation-failure count - the PR leg's-13: 0means zero allocation failures, not zero attempts.Happy to redo the A/B on
port/4449against currentmainif that is more useful than a tag-based build.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
-13on 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 againstmain: 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.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.
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
ab5c1a66a9fc645ea0d8a1e7683c17826f02fc37includes main6c12024f7d9bceb93c9c9030126212ea37aee239, #8091, #8802 and cache diagnostics; candidate47c36e0618e0ac570fe7b5825b11c0e94bf0b826adds 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.
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) atfa67182051.On
main,BackingFileowns the duplicated backing descriptor: its destructor closes it, and the descriptor is handed on only throughstd::exchange(backing.file, -1)tocreateDmaBufImport, which closes it. This PR passes the descriptor as a plainint file.createDmaBufImportis still the only call that closes it, butcreateBackingImportreturns before reaching it in three cases:createChunkedDmaBufImportsucceeds (fits, returnsnullptr),createSparseDmaBufImportsucceeds,createSparseDmaBufImportthrows.Each import that takes one of these paths leaks one descriptor, from
createSharedBackingImportand from the run-list import inimportRunAt. 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, plusfcntl(F_GETFD)/EBADFchecks 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.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_mbfails with EINVAL, and on a default kernel that limit is 64 MiB.Evidence
size_limit_mb64 (the kernel default),list_limit1024. A probe with a memfd sealed SHRINK|GROW (asDirectMemory.cppmakes it):UDMABUF_CREATEandUDMABUF_CREATE_LIST(2 items) both succeed up to 64 MiB and fail with EINVAL from 65 MiB, whatever the item count.33a6d6bbfb+ #8089 + #8762 + #8091 + this PR: every remaining import failure is a join throughUDMABUF_CREATE_LISTwith 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.
createBackingImportsends one run tocreateChunkedDmaBufImport(fits one 64 MiB file chunk) orcreateSparseDmaBufImport(a sparse buffer bound to the shared 64 MiBimportChunkudmabufs). Neither makes a udmabuf aboveImportChunkBytes. A run list skips both and askscreateDmaBufImportfor one udmabuf of the whole list.Suggested change (one commit on this PR's head
fa67182051:github.com/JJenkx/AnyPS5@d5b768f027, branchJJenkx:fix/udmabuf-runlist-on-4449):createSparseDmaBufImporttakes the run list. Each run is split at 64 MiB file chunks and every piece is bound from the sharedimportChunkat 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 usesUDMABUF_CREATE_LIST.Tests (
HostImportSparseDmaBuf.cpp):ScatteredRunsAboveTheLimitBindTheirChunks(two runs at out-of-order file offsets, total abovesize_limit_mb; every bind maps its run's chunk at the right memory offset and the binds cover the range exactly) andUnalignedInteriorRunKeepsTheFallback(sparse block 128 KiB, interior run 64 KiB off: no binds).fa67182051with 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.host import sparse dma-buf tests passed,100% tests passed out of 1(Linux 7.2.9, GCC 16, Release,size_limit_mb64, real/dev/udmabufwith 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.
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 commitd5b768f027binds 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.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.
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":
createSparseDmaBufImportstill returns false at its first check whenentry.bytes <= ImportChunkBytes(64 MiB), or when sparse binding, a usable queue or/dev/udmabufis missing (GuestBufferMemory.cpp:800ind5b768f027). So:UDMABUF_CREATE_LISTimport, as before.UDMABUF_CREATE_LIST. That import works only whensize_limit_mballows 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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:52:28Z.
@JJenkx you're right, thanks. I missed the
entry.bytes <= ImportChunkBytesreturn at the top ofcreateSparseDmaBufImport(GuestBufferMemory.cpp:800ind5b768f027). 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.Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T10:46:09Z.
Verification of the
>64 MiBrun-list path on the RX 9070 — buildingfa671820+d5b768f02and 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 byANYPS5_GPU=AMD Radeon RX 9070withMESA_VK_DEVICE_SELECT=1002:7550, and the launcher's runtime device assertion passes on every leg.udmabufmodule 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/udmabufhere takes the offset-capable API —struct udmabuf_create { memfd, flags, offset, size }, andUDMABUF_CREATE_LISTwith a per-item offset:UDMABUF_CREATE, 224 MiBUDMABUF_CREATE, 64 MiBUDMABUF_CREATE, 64 MiB at file offset 64 MiBUDMABUF_CREATE_LIST, 2 runs totalling 128 MiBUDMABUF_CREATE_LIST, 2 runs totalling 64 MiBSo 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
udmabufchunks imported asVK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXTmemory and bound to one 128 MiBVK_BUFFER_CREATE_SPARSE_BINDING_BITbuffer viavkQueueBindSparse→VK_SUCCESS; a 128 MiBvkCmdCopyBufferthrough that buffer round-trips (8192 probe words match). That is the mechanismd5b768f02uses, 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(theEXCLUDE_FROM_ALLhost target) onfa671820alone fails:and with
d5b768f02applied it passes (host import sparse dma-buf tests passed, exit 0). I applied your commit withgit amon top offa671820, 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, interleavedhead,fix / fix,head / head,fix, decks identical apart fromlibSceAgcDriver.prx(352 PRX each; md5146676fe…vs6afe0580…):-13fa671820fa671820+d5b768f02+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.
size_limit_mb. A machine with the limit raised would not see the EINVAL and would not need the fix.Raw logs, samples, both mock-test outputs and the probe source are archived on my side — say the word and I will post them.
Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-21T10:52:08Z.
Follow-up: the scattered
>64 MiBrun 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
GuestBufferMemoryimport 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 withsize_limit_mb=64. Implemented astests/execution/ScatteredRuns.cpp: reserve the guest range,MAP_FIXED-map each segment from one sealed memfd at its scattered offset, register aSharedBackingRunsresolver returning those two runs, thenImportGuestMemoryand write through the GPU into the second run.fa671820host 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+d5b768f02limit 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 oneUDMABUF_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 withpread) 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/.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
d5b768f02had only been checked against the mock device. Your rawioctltable confirms that the size limit applies to a list's total, and the scattered-run case through the realGuestBufferMemoryimport, including thepreadplacement 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.cppcase 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.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
createBackingImportleak 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 withANYPS5_GPU=AMD Radeon RX 9070andMESA_VK_DEVICE_SELECT=1002:7550; the launcher's device assertion reportsAMD Radeon RX 9070 (RADV GFX1201)on every leg. Title PPSA14299 (Mafia: The Old Country), relinked per deck.Arms. Same tree (
fa671820+d5b768f027), sameapp.elf, sameapp0/, 352 PRX in every deck. The only difference islibSceAgcDriver.prx: md56afe0580a6b79fbe9decd43a6b0028a9unguarded,0d8d9d9a50b24add7b4de3b029f6b4f1guarded. Four 70 s legs, with the arm order alternated between the two pairs.Method. A sampler reads
/proc/<pid>/fdevery 10 s: total descriptors, and the subset whose link target is a memfd.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.
libkernelraisesRLIMIT_NOFILEtorlim_maxat 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::exchangehand-off:createBackingImportowns the duplicate for its whole scope and releases it only intocreateDmaBufImport, which already closes what it is handed. It also carries thePiece::filetofileOffsetrename, which removes the shadowing of the fd parameter ind5b768f027.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_testsand 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>/fdis a direct way to see it.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.cppcase, as a patch. It applies on top ofd5b768f027(or any head that carries it) and adds one file with no build-system edit:core/libs/prx/libSceAgcDriver/CMakeLists.txtglobstests/execution/*.cpp, so it registers itself asagc_driver_scattered_runs_tests(EXCLUDE_FROM_ALL), next to the existing execution tests.What it drives:
MAP_SHAREDat non-contiguous file offsets in one sealed memfd (0 and 128 MiB), so the resolver returns a genuine two-run scattered list;GuestArenaSharedBackingRunsis registered with that resolver andImportGuestMemoryruns on the real device, so this exercises the production import path rather than a mock;/dev/udmabufis 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
fa671820alone (UDMABUF_CREATE_LIST, EINVAL, falls back to copies) and passes onfa671820+d5b768f027withlimit 64 MiB, imported 128 MiB as two scattered runs.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
d5b768f027and it is right.createDmaBufImportcloses the descriptor it is handed (GuestBufferMemory.cpp:601).importChunkonly uses it forfstatandUDMABUF_CREATE, where the kernel takes its own reference, and keeps nothing. So the chunked and sparse paths that return early fromcreateBackingImportnever close the duplicate today, and neither does athrowSparseImportinside them. An owner scoped tocreateBackingImportthat hands the descriptor off only tocreateDmaBufImportcovers all of those, the throw included.To move this forward, could you fold these three into this PR?
d5b768f027(run lists above the udmabuf limit through the sparse chunk path).ScatteredRuns.cppexecution case, as the test that drives the real import path. It skips where/dev/udmabufor a guest-memory import isn't available.@socket1001 thank you again for both. The
/proc/<pid>/fdcontrol was exactly what this question needed.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
fa67182051merged locally ontomainb5d763770a, withoutd5b768f027and without a descriptor guard, against plainmainb5d763770a.runusershell for the game's user reports 65535 for soft and hardulimit -n. I did not read the game process's own limit.main, PR, PR,main; 280 s each.main(2 runs)Too many open files[gpu] import of GPU memory mapped at 0x21fe40000+0x10000 failed: duplicate direct memory backing: Too many open files(35 and 36 times), thenvkAcquireNextImageKHR: Vulkan result -2,terminate, abort at ~58 sUntil 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
mainthis title logs 48failed at vkAllocateMemory (-1000072003)andhost 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.
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/udmabufread-write through thekvmgroup,size_limit_mb64,list_limit1024.mainis2f161d4f3. The change is this PR's headfa67182051with @JJenkx'sd5b768f027and @socket1001's descriptor guard on top, merged onto thatmainlocally (only the TechnicalDebt file conflicts; I keptmain's text for the build). Both arms use the sameapp.elf; four libraries differ (libc,libkernel,libSceAgcDriver,libSceVideoOut). Each run starts from the same save, gets no input, and runs 13 minutes withAPS5_TRACE_SUMMARY_EVERY=10,ANYPS5_NO_SHADER_CACHE=1andAPS5_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 oldermain,aa1b1bfce), the failed imports wererw-sviews of/memfd:direct memory, and most of the 4–8 MiB requests spanned two to eight mappings at scattered file offsets, for example0x3500000000+0x400000over file offsets0x200000and0x29c00000.mainmain+ this PRfailed at vkAllocateMemory)host import budget loweredDriver.Packet.memory_waitper frame on the title screenThe 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
0x3f00094200crosses a 2 MiB and a 12 MiB registered range, sojoinedRunrefuses 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.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).
createBackingImportholds 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 withstd::exchangeonly tocreateDmaBufImport. That is the shape described above.Setup
mainb5d763770aagainstmain+ this PR (fa67182051) + the guard.main, PR, PR,main.APS5_TRACE_SECONDS=200:30with 2097152 events. Every trace reports dirty false and dropped false./proc/<pid>/fdcountmainmainToo many open files, both PR runs reach the planned close, and no import fails.mainrun here and below two earliermainruns of the same scene (46.9 and 54.1).mainrefuses 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 (maprequester), 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.
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 atvkAllocateMemoryand 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
fa67182051with the shutdown counters.AI-assisted: yes (Claude Code)
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:
mainmainThe 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 earlyfailed at vkAllocateMemory (-1000072003)lower the host import budget (host import budget lowered18 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.
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.
main1896871baagainstmain+ 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), withAPS5_PROFILE_DRAW=1. Rough numbers, not a scripted benchmark.mainmap/proc/<pid>/fdmapimports), Subnautica makes only ~3.7k, so the PR is a clear win on this title.futex_do_wait. The count had jumped from 221 to 2568 in 40 s. I couldn't attach gdb (ptrace_scope1), 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)
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 inlibSceAgcDriver.prx(146676feadhead vs6afe0580a6head +d5b768f027), interleaved head, fix / fix, head / head, fix.host import budget loweredfa671820d5b768f027Mafia 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
mainarm is the opposite failure: 107-117 import attempts, 12-13failed 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>/fd2,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.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>/fdflat 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)
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, andmain+ #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>/fdgrows from 450 to 3706 in about 3 minutes in Pacuka's PPSA02453 run.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:
main1896871ba+ 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./proc/<pid>/fdNo 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)
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:52:30Z.
Review: COMMENTED
dmaBufImportsCoherentstarts attrueand only a successful probe sets it. IndecideImportWatchthe early returns (APS5_WRITE_WATCH_IMPORTS=watch, for example, and the no-watch branch whenProbeDmaBufImportWriteProtectionfails) leave ittrue, 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:
SharedBackingRunsreturns false once a range needs more thanDmaBufRunLimit(1024) runs, andresolveBackingRunsthen falls back toGuestArenaSharedBacking_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?