Files
metal2vulkan/docs
Anees Iqbal 0da1b0a342 RUNTIME 2462: Guest RAM: a resident, kept RAM takes chunks past 512 MiB, all imported as its use begins
On a device whose every held import costs each kernel submission (RADV, ANV on i915), a listed
guest RAM's chunks stopped at LONGEST_LISTED_CHUNK (512 MiB), our own constant: an 8 GiB guest
listed up to 16 chunk imports in every submission (the consumer's Iris Xe desktop: 15 live, about
4.7 ms/s at 0.35 us each and 1114 submissions/s). The cap bounds memory alone: a chunk's import
pins every page of it, and udmabuf allocates the pages of the guest's memfd that the guest never
touched. A RAM the VMM preallocated has every page allocated already, so there the cap bounds
nothing.

ram_plan now asks listed_chunks_of: where the cap would cut a range into more chunks than the
source's and the device's limits do, the chunks are kept (releases_idle_chunks false), and every
page of the RAM is resident as the use begins (every_page_resident: mincore over the ranges, a
chunk at a time, stopping at the first page missing), the chunks run to those limits (4032 MiB on
RADV and on ANV, whose maxStorageBufferRange is 4 GiB less one byte: an 8 GiB RAM in 3 chunks) and
the plan is whole. A whole plan's chunks are all imported on the calling thread before
Device::use_host_ram returns (Device::import_whole, counted as chunks imported ahead), then one
internal submission of no work is made and waited for: the first kernel submission that lists a
chunk just imported waits while the kernel writes its page tables, and every other submission of
the device waits with it (the VM's page-table lock), so that wait falls in the use's start, before
the guest's work, never inside a later submission. Vulkan used: the chunk import as before
(vkAllocateMemory with VkImportMemoryFdInfoKHR) and vkQueueSubmit with a fence, waited for. A RAM
with a hole, or one too long to keep, keeps the cap and its lazy imports as before.

listed_chunk_bytes now gives the limits' length alone; the cap moved into listed_chunks_of. The
module docs, use_host_ram's, Plan's, the imported-ahead count's, HOWTO section 6 and the
FAST-PATHS "Idle dma-buf imports are released" row say so.

Tests: listed_chunks_are_as_long_as_every_limit_takes_in_whole_64_mib (the limits' length);
a_resident_kept_ram_takes_chunks_past_the_cap_imported_whole (the rule, residency asked only where
the cap cuts the RAM; fails without the change, which answered the cap); and
a_ram_is_resident_once_every_page_of_its_file_is (mincore, a memfd with a hole then written). The
device tests tests::host_ram_whole (a 640 MiB resident RAM: one chunk imported as the use began;
one with a hole: 512 + 128 MiB, none imported) and the ignored whole_ram_bench (a consumer's
8 GiB RAM in 16 chunks of 512 MiB each imported against 3 imported whole: the use's time and a
submission's vkQueueSubmit time).

Also folded: the probe tests::listed_memories with the test-only census Memory::blocks_by_kind
(7120ba7212), and the unit tests' clippy fix (9efafb7742).

Verified: clippy x3 at 9efafb7742 (m3-max-37010 CLIPPY_GPU=0, m3-max-37011 CLIPPY=0 + 20 host_ram
unit tests, m3-max-37012 CLIPPY_CPU=0); rustdoc m3-max-36994 DOC=0; lavapipe host_ram 120 passed
(m3-max-36995). PHOENIX (m3-max-37009): a touched 640 MiB memfd took one 640 MiB chunk imported
ahead (use 126.2 ms); with a one-page hole [512, 128] MiB, none ahead. 8 GiB bench: 16 chunks
listed -> 3, vkQueueSubmit 11.6 us a submission resident against 971.7 us averaged over 300 with
the lazy chunks (first-listing stall included); use_host_ram 459.7 ms (89.0 ms imports).
2026-11-16 09:32:09 -08:00
..