Files
metal2vulkan/docs
Anees Iqbal 259be5d3c5 host RAM: fault in a VMM's shared memory by reads, not under the memory map lock
What: the import-ahead thread's fault_in now reads each page of a chunk where
every mapping over it is shared memory of base pages (a memfd, as QEMU maps a
guest's RAM), as PROCMAP_QUERY answers (vma_flags SHARED, vma_page_size the
host's page). A read fault on such a mapping allocates the page and maps it
writable, changing no byte, and since Linux 6.7 runs under the mapping's own
lock, so it holds no mmap_lock. Private memory, hugetlbfs (whose fault past
its pool is SIGBUS) and kernels without PROCMAP_QUERY (before 6.11) keep
MADV_POPULATE_WRITE in 2 MiB steps. host_memory.rs's PROCMAP_QUERY call is
factored into mapping_at, shared by queried_permitted and the new
shared_base_pages.

Why: in a consumer's guest boot on the RTX 5080 laptop, seven slow pipeline
compiles had no thread in an NVIDIA ioctl; their threads sat in an mmap_lock
convoy (vCPUs in get_user_pages, mprotect from heap growth, mmap/munmap in D),
and the one kernel-stack dump that caught the reader found m2v-host-ram in
MADV_POPULATE_WRITE. MADV_POPULATE holds mmap_lock read for each 2 MiB step,
which under reclaim and compaction takes milliseconds, and a waiting writer
queues every later reader behind it.

How verified so far: a C probe on um870 (Linux 7.3.1, 4 GiB memfd under
MADV_HUGEPAGE, a thread calling mprotect every 0.2 ms, two mapping, touching
and unmapping 4 MiB every 0.5 ms): populate in 2 MiB steps took 202-541 ms
with the longest mprotect 4.8-10.1 ms (four runs); per-page reads took
239-247 ms with the longest mprotect 0.40-0.52 ms (two runs), and the write
pass after them faulted no page en masse. New unit tests: the choice of way
(shared memfd by reads, private and a span over both by the advice), and that
a fault-in by reads leaves every page resident, writable (a write pass faults
nothing) and every byte unchanged. cargo fmt only; clippy, the tests and the
5080 before/after run follow as potluck jobs.

(cherry picked from commit e571995af620272b12bb3083a5c59fbf8b844e39)
2026-11-08 12:39:37 -08:00
..