Files
reims-vgpu/docs
Anees Iqbal bd8f89bccc 🆕 Hand NVIDIA's device the guest's RAM whole
On a device that needs imported pages mapped from their files, the guest's
RAM is now handed to the device whole. NVIDIA's 615 driver refuses foreign
dma-bufs, so there a view of scattered guest pages takes one kernel mapping
per run. Each lease of the guest's memory makes the runtime's HostRam of its
ranges, with the dirty log's answers where the device has one, and every
such device uses it while the lease lives. Each no-copy object's memory
carries a resolver of the RAM's runs its pages are. An object over one run
inside one 64 MiB chunk is bound in the device's import of that chunk: no
import of its own, no kernel mapping, no gate. Other objects keep the views.
A device without VK_EXT_external_memory_host keeps the views, said once.
Only writable pages of the RAM resolve: read-only pages, files of zeros,
twins and the library's own memory answer none.

Every import the library makes now asks the views' gate, rebinds included.
A rebind's import of a view's pages used to have no other way than kernel
mappings: no gate was asked, its pages were mapped from their files into the
views' headroom, and past the whole budget it was handed over as mapped,
which NVIDIA's driver refuses (in strict mode a death). The runtime now
makes a rebind over a copy where the gate refuses or the import fails,
including a heap's, an image's in place and moved bytes'. So a rebind stops
short of the headroom like a no-copy buffer. Gone with it: ImportSite::gated,
the ungated import's way into the headroom (Reach::Whole for unfolds), and
the hand-over past the budget with its death and its `noroom` count.

A device lend (the video device's decoder writing a frame into the guest's
buffer through CUDA) also stops short of the headroom. It used to map its
pages from their files as far as the whole budget, as a rebind did. A lend
has another way: where the device does not register the pages, the decoder
declines the frame and the session copies it into the guest's buffer on the
CPU, the same bytes. Past the headroom its pages stay in their views through
dma-bufs, the device refuses them, and the CPU copies the frame. It no
longer counts as an import handed over, and no longer ends the process in
strict mode.

The headroom now holds only what has no other way: views through dma-bufs,
ranges, stand-ins, and twins where no device needs imported pages mapped
from their files. What the guest sees changes only where a run died: a
guest whose objects met the views' limit used to end the process there,
and now runs, a copy holding the same bytes where no mapping was left.

docs/qemu.md says:
- how NVIDIA's device takes the guest's RAM whole;
- that the copy reads the pages with the CPU, and that rebinds and lends are
  gated;
- how the RTX 5080 Laptop host booted at the kernel's default
  vm.max_map_count (65,530), where objects go past the gate to copies.
  Before the route, a 4K x86-64 guest died about 17 s in, at a 63.3 MiB
  surface whose copy could not read its pages. With the route at
  daf1bf625f, it reached its desktop and ran the workload with no fatal
  line, at a Finder drag of 5 fps. At f4f88dad89, whose copies compare only
  the pages the dirty log reports written, the desktop came by 30 s and the
  drag ran at 29 fps.

Checked with the previous commit at f4f88dad89: the checks it lists, the
route's test on the 5080 among them, and that boot, with no wrong frame in
29 screenshots.

Squashes fc5ab85ef, b5bdc1a8f, 7fee65ff4, 7d9f0df6f, f30bb371c and
ef416d02d.
2026-10-29 15:50:30 +02:00
..