Files
reims-vgpu/docs
Anees Iqbal 0a2b3827b4 🐎 Map a view one dma-buf holds through it, kept for imports
On a device that needs imported pages mapped from their files and takes the
pages one dma-buf holds in the pointer's place (ANV and NVIDIA's driver), a
view of scattered guest pages was mapped a run at a time, one mmap a run,
however small it was, and only went through a dma-buf past the views'
budget. An x86-64 macOS guest's walk on an Iris Xe made 2,082 views of 2 to
1,024 runs within 64 MiB, 140,322 runs; the host held 36,897 mappings at the
desktop, and each such view's make and teardown paid a syscall a run.

Where textures over such pages also lie in place, such a view (more than one
run of one protection within udmabuf's limits) is now mapped through one
udmabuf of its pages from the first, one mapping, and the udmabuf is kept
with the view's runs (files::Kept). A no-copy buffer's import leaves the
view so, and the runtime's import of the whole view is handed a duplicate of
the kept descriptor, so no udmabuf is made again. Two imports still need the
pages mapped from their files and get them so: a heap's (import_heap_view),
and CUDA's registration of a video surface for NVDEC, which pins a
pointer's pages and cannot pin a dma-buf's mapping
(device_lend::map_for_pointer). A view of more runs than one udmabuf takes
keeps today's route, and so does the fold probe's view (vm::from_files).

The device's probe learns whether textures lie in place
(ONE_DMA_BUF_VIEWS): it makes two linear BGRA8 textures over its one-dma-buf
buffer, rows that fill a page and rows a texel short, sampled, written and
rendered, and takes the route only where neither is a shadow; where the
runtime's check has not answered yet it stays off for the process. NVIDIA's
driver fails it: on an RTX 3090 such a texture is a shadow (the runtime's
check makes no image over pages imported as dma-bufs, job m3-max-31400), and
the import through the dma-buf of 1,024 pages took 10.3-12.8 ms against
2.4-2.6 ms by pointer (job m3-max-31405), so NVIDIA keeps today's route.
The probe's textures are heard by no one, so the runtime now announces each
shadowed texture, as it does copied host pages, keeping the device's notice.

With metal2vulkan fb33065288 (RUNTIME 2381) ANV passes it, so the Iris Xe
takes the route: on homelab-ms01-1's Iris Xe (Linux 7.3.1, Mesa 26.2.6) both
textures lie in place (job m3-max-33714). At 9ce951f521 the texture whose
rows are a texel short of a page was a shadow there (job m3-max-33240), the
runtime's check having found a render pass's load and store over pages
imported as dma-bufs changing bytes the CPU wrote beside texels in the line
of memory they share; 2381 takes such a texture in place where its buffer
holds its last row to the pitch. The RTX 3090 stays a shadow (job
m3-max-33224). The probe answers once, as the device is made: in a host's
first process after a driver update or a change of the runtime's in-place
check, before the runtime keeps the check's verdicts, the probe finds the
check pending and that whole process keeps today's route; the next takes it.
The first guest boot on the Iris after the pin move ran so (job
m3-max-33721), and the next process recalled the kept verdicts as its
device was made (job m3-max-33777). The measurements below were taken
before the probe had its textures. A heap's import on Windows is a no-copy
buffer's, as on macOS.

The fold tests now take views of more runs than one udmabuf, 1,025 pages,
and their GPU fill of half the buffer ended mid-page: it now fills whole
pages.

Measured, release build, a view of 1,024 pages backwards, three rounds, on
homelab-ms01-1's Iris Xe (job m3-max-31409): make 1,086-1,121 us ->
551-574 us, import 46-52 -> 116-120 us, unmap 696-705 -> 118-200 us, 1,024
mappings -> 1. The walk on the same host (jobs m3-max-31194, 31453, the
same guest set): mappings held at the desktop 36,897 -> 33,509, its steps,
Geekbench 7.1 and clbw within their spread, no fatal line. GPU results,
guest-visible values and refusals are unchanged.
2026-11-15 15:06:13 -08:00
..