Repository navigation
feat(agc): import shared direct memory through udmabuf on Linux - #943
adriadam10 merged 4 commits into
Conversation
|
A note for whoever tests this on RADV: with these imports active, PPSA14632 (LEGO Horizon Adventures) hit amdgpu page faults and a ring reset within 1.5 to 3 minutes, and Unreal then aborted with The cause is not in this PR. It is a RADV bug that the larger number of in-place bindings exposes sooner. RADV (Mesa 26.0 and later) gives a #1065 keeps the overrun on the pool buffer's last page. With it and this PR, the title ran 5 minutes without a fault. With the udmabuf Environment: Arch Linux, kernel 7.2.9, Mesa 26.2.4 RADV, RX 9070 XT (RDNA4), i7-13700KF. |
|
Follow-up commit fc81399 fixes a large slowdown this PR caused on its own. The import write-watch probe imports private anonymous scratch pages through
On PPSA14632 that was over 800 GiB of storage uploads in 90 s. udmabuf takes the memfd's pages without touching the process page tables, so these imports don't need that treatment. The commit:
On RADV (RX 9070 XT, kernel 7.2.9): PPSA14632 storage uploads drop from ~2.7 s to ~0.1 s of GPU time per 10 s, with no |
|
Test on the same GPU, with PPSA21567 (Astro Bot). Setup: Linux (CachyOS, kernel 7.2.8, GCC 16.2.1), Ryzen 7 7800X3D, RX 9070 XT (RADV GFX1201, Mesa 26.2.3). oneandonlydean's
AI-assisted: yes (Claude Code ran the builds and wrote this report; the runs are on my machine). |
On Linux, direct memory is a memfd mapped MAP_SHARED. amdgpu accepts only private anonymous memory for a host pointer import (libdrm sets AMDGPU_GEM_USERPTR_ANONONLY), so every import of direct memory failed with VK_ERROR_INVALID_EXTERNAL_HANDLE and its ranges were copied. When a host pointer import fails, the range's memfd slice is turned into a dma-buf through /dev/udmabuf and imported with VK_EXT_external_memory_dma_buf. The direct memory backing is sealed against shrinking and growing, as udmabuf requires. libkernel reports the backing of a guest range through GuestArenaSharedBacking. Without /dev/udmabuf, or past its size limit, the range is copied as before. APS5_TRACE_HOST_IMPORT now prints the mappings behind a failed import on Linux too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…otection intact
The import write-watch probe imports private anonymous scratch pages
through VK_EXT_external_memory_host. On amdgpu that path resolves the
pages' write protection (the userptr is revalidated at every submission),
so the probe decides that imported ranges are compared instead of
watched, and every import is unwatched. Shared direct memory is never
imported that way: its imports go through udmabuf, which takes the
memfd's pages without touching the process page tables. Unwatching them
anyway left every surface in direct memory without write stamps: each
storage image refresh re-uploaded the whole surface ("untracked"), and
draw snapshots of imported ranges could never be reused. On PPSA14632
that was over 800 GiB of uploads in 90 s.
- HostImport records whether it is a dma-buf import, and the import
decides watch or unwatch after the import by its kind (ImportWatched
already absorbs the pages the import itself touches).
- A second probe, ProbeDmaBufImportWriteProtection, imports a sealed
shared memfd scratch range through udmabuf: dma-buf imports stay
watched when a GPU read of it marks no page written and a CPU store
after that is still collected. Otherwise, or when the probe fails,
they are compared like host-pointer imports.
- Both probes also report whether a CPU store after the GPU read was
collected (ImportProbe::writtenByCpu).
- APS5_WRITE_WATCH_IMPORTS=watch or unwatch overrides both kinds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…er a direct mapping Co-Authored-By: Claude <noreply@anthropic.com>
fc81399 to
c572650
Compare
|
Rebased onto main (mechanical conflict with Added two test commits:
Note on merge order: your comment says that with these imports active, RADV's descriptor pool overrun faults sooner, and that #1065 fixes it. #1065 should land before or together with this PR. |
On Linux, shared direct memory is imported through /dev/udmabuf (boykopovar#943). Many distributions create it as root:kvm 0660, so a user outside the kvm group cannot open it. The ranges are then copied instead of imported, and GPU stores through FLAT/GLOBAL addresses to them fail with "BDA access failed": DOOM PPSA99666's compute presenter falls back to its CPU scaler. The only trace was "failed at open /dev/udmabuf (-1000072003)", a Vulkan result that hides errno. Print the open error once, with the fix for EACCES, and document the requirement in USAGE.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
On Linux with an AMD GPU, no host import of direct memory ever succeeded, so every direct-memory range the GPU used was copied.
Since #203, direct memory is a memfd mapped
MAP_SHARED(before that it was a/tmpfile). RADV imports a host pointer through amdgpu userptr, and libdrm'samdgpu_create_bo_from_user_memsetsAMDGPU_GEM_USERPTR_ANONONLY, so the kernel refuses any file-backed VMA. Measured on Linux 7.2 with libdrm 2.4.134:amdgpu_create_bo_from_user_memMAP_PRIVATEMAP_SHAREDEPERMMAP_SHAREDEPERMIn the driver this showed up as
[gpu] host import of … failed at vkAllocateMemory (-1000072003); falling back to copies. In PPSA14632 all 466 import attempts failed, and every one was arw-s /memfd:direct memorymapping.This PR imports such ranges as dma-bufs instead:
createImporttries the host pointer import first, so a driver that accepts shared mappings behaves as before. When that fails and libkernel reports a memfd backing for the range, the range's slice of the memfd becomes a dma-buf through/dev/udmabuf(UDMABUF_CREATE). It is then imported withVK_EXT_external_memory_dma_buf(VK_KHR_external_memory_fd), bound to the same buffer usage and device address as a host pointer import.MFD_ALLOW_SEALINGand sealed withF_SEAL_SHRINK | F_SEAL_GROWafterftruncate, as udmabuf requires. It is never resized afterwards.GuestArenaSetSharedBacking_nid_postfix(libc). The driver asksGuestArenaSharedBacking_nid_postfix(address, bytes, &file, &offset)and gets a CLOEXEC duplicate of the memfd and the range's offset in it. The range must lie in direct mappings that continue in one backing; adjacent mappings that continue contiguously count as one. Flexible memory, unmapped ranges and non-contiguous ranges return false./dev/udmabufcannot be opened, or the range exceeds udmabuf'ssize_limit_mb(64 MiB by default), the import fails as before and the range is copied.APS5_TRACE_HOST_IMPORTnow prints the/proc/self/mapslines behind a failed import, as it already printed theVirtualQueryregions on Windows.Windows is unchanged.
Tested
Linux: Arch, kernel 7.2.7, GCC 16.2.1, RX 9070 XT (RADV GFX1201, Mesa 26.2.3).
ctest: 359/359 pass.New
CheckDirectMemorySharedBackinginguest_memory_testscovers:A standalone check of the import path (memfd slice → udmabuf → dma-buf → RADV, then
vkCmdCopyBuffer/vkCmdFillBuffer) found 0 wrong words in either direction and nothing written outside the slice. The imported memory type is host-visible, coherent and cached. udmabuf accepted 64 MiB and refused 65 MiB.PPSA14632 (LEGO Horizon Adventures,
--to-intel), 3-minute runs from boot into its boot-flow movie, on a test branch that also has perf(agc): query guest page access with PROCMAP_QUERY on Linux #157:[guestmem]readThe remaining failures are ranges above 64 MiB (
UDMABUF_CREATE): 112 to 576 MiB whole allocations, plus feat(agc): host import windows, least-recent eviction under the budget #290 windows above 64 MiB. The title's present rate did not change (5 per 10 s), so its frame rate is limited by something else.Windows: not tested. The Windows code paths are unchanged.
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)importAllocationaround thecreateImportcall this PR extends, and the two cherry-pick onto each other without conflicts./dev/udmabufisroot:kvm 0660on many distributions; this test machine had a per-user ACL on it.🤖 Generated with Claude Code