🆕 Pre-fault the guest's Shared pool pieces in QEMU

QEMU's reims-graphics-pci now fills the second-level tables of each pool
piece once its add is answered, on a thread of its own in 2 MiB slices, so
the guest's first touch of a piece takes no fault where it took one a 4 KiB
page: 140,289 for 548 MiB, 184 ms on um870's 3090 and 262 ms on um790's
780M under KVM, and 1.3 s on the Windows mini under WHPX. Under KVM the
call is KVM_PRE_FAULT_MEMORY on a vCPU of the thread's that never runs,
which keeps KVM's master clock on across guest reboots and is never waited
for under the BQL; under WHPX it is WHvAdviseGpaRange's populate.

vendor/qemu moves to b561d79c (dd0e0d4a..b561d79c on 0590cfde), and
docs/qemu.md says what the populate does.
This commit is contained in:
Anees Iqbal committed 2026-11-18 22:08:45 -08:00
1 parent c6ab041d68
commit 6f733d6e78
2 files changed
+23 -1

No files matched your search

+22
View File
@@ -150,6 +150,7 @@ virtio device (`d151bcd9`, upstream's `b501f21312`).
| WHPX offers the guest no TSC deadline timer where Hyper-V refuses its register (`WHvX64RegisterTscDeadline`), asked of a vCPU made for the question at init: the CPU model's `tsc-deadline` is filtered out as a feature the host lacks, and a macOS guest arms the local APIC's timer ("Windows hosts", below) | `c3704402` |
| `vmapple` asks HVF for 40 bits of guest physical address, or the host's most where that is fewer (the machine's `get_physical_address_range`), where HVF's default is 36, and refuses to start where its RAM ends past them; the guest reads the size as its `ID_AA64MMFR0_EL1.PARange` ("arm64 guests", below) | `dc1b6821` |
| `vmapple` answers the room past its RAM, from the end of RAM rounded up to 1 GiB to the end of the guest's physical addresses (the CPU's `PARange`, at most 40 bits, and under KVM at most KVM's largest IPA size), in whole GiB, as read-only machine properties, `x-pool-room-base` and `x-pool-room-size`, and places nothing there; `reims-graphics-pci` gives the library that room for the guest's Shared pool where no PC host bridge answers one, and reserves the range it took without fw_cfg where the machine has none ("The reims-graphics device", below) | `0590cfde` |
| `reims-graphics-pci` populates each Shared pool piece once its add is answered, on a thread of its own in 2 MiB slices, so the guest's first touch of it takes no second-level fault: under KVM with `KVM_PRE_FAULT_MEMORY` on a vCPU of the thread's that never runs, under WHPX with `WHvAdviseGpaRange`'s populate. For that vCPU `KVM_CAP_MAX_VCPU_ID` is one past the guest's APIC ids, its TSC rejoins the guest vCPUs' generation after each of their reset-level puts, and a 20 ms timer ends a call left retrying ("The reims-graphics device", below) | `dd0e0d4a`, `9c95b677`, `a4dfdbf1`, `cfe57e55`, `b561d79c` |
The branch's other commits are the apple-gfx work `96e1b470` removes, and
`cfaadbfa09`, an HVF workaround that `478c28ff70` reverts, upstream having
@@ -348,6 +349,27 @@ is its transport:
KVM, a piece used again with its slot kept took no EPT fault in 20 reps,
where removing it and adding it again cost a full first touch, 140,289
faults for 548 MiB, 184 ms on the 3090 and 262 ms on the 780M.
- **The pool's populate**: once a piece's add is answered, a thread of the
VM's (`rgfx-prefault`) fills the second-level tables for it ahead of the
guest's first touch, lowest address first, in 2 MiB slices, one call a
slice. A piece's removal stops its populate between slices, and a call
that fails leaves the rest of the piece to the guest's first touch. Under
KVM the call is `KVM_PRE_FAULT_MEMORY` on a vCPU of the thread's own
that never runs, with vCPU 0's CPUID and TSC frequency, its id one past
every APIC id the machine can give (`KVM_CAP_MAX_VCPU_ID` is one higher
for it, fw_cfg's CPU count unchanged; an id past 254 makes none). A call
holds KVM's SRCU, which a slot change waits for under the BQL, so each
run of pool adds or removals pauses the populate first, signalling the
call in flight to end it, and a 20 ms timer ends a call that a slot change
from elsewhere left retrying on an obsolete root. The vCPU's TSC is
written to 0 after each reset-level put of a guest vCPU's, so it stays in
their TSC generation and KVM's master clock stays on across a guest
reboot. Under WHPX the call is `WHvAdviseGpaRange`'s populate, a
partition call; the pool's maps and unmaps run outside the BQL there, and
the populate takes no pause. HVF takes no populate. The
`reims_graphics_prefault_*` traces give each piece's slices, cuts, wall
and thread CPU time, each pause's wait, and the thread's totals at the
device's teardown.
- **The guest's RAM**: on Linux the device gives the library the map of the
RAM ranges that are a shared file in pages of the host's size (the memfd of
`reims-ctl`'s VMs), with the files behind them, and the GPU uses an
Vendored
+1 -1
Submodule vendor/qemu updated: 0590cfdea8...b561d79cbe.