host_ram: pace the ahead import, and import host pointers with the memory lock released
What:
- The thread that imports a used RAM's chunks ahead now runs as the system's batch work:
SCHED_BATCH on Linux, with its nice value kept, and the utility QoS class on Apple's systems.
- It yields between chunks.
- On Linux, before each chunk's import, it faults the chunk's pages in 2 MiB at a time with
MADV_POPULATE_WRITE, yielding between steps. That changes no byte. A kernel that refuses
the advice leaves the faults to the import, as before.
- memory::import_host (it was Memory::import_host) makes the vkAllocateMemory import with
the device's memory lock released, as import_own_pages and new blocks already do. It
re-locks only to record the block. Its callers are the chunk import (host_ram.rs) and a
no-copy object's own import (buffer_descriptor.rs).
- No CPU pinning, and no kernel, boot or module parameter.
Why: a reviewer accepted pinning all of guest RAM ahead on condition that the thread does
not stall the host while a VM starts.
- The pin of a 64 MiB chunk holds the VMM process's mmap lock while it faults in fresh pages.
Every mmap, munmap, and every page fault queued behind one, waits on that lock.
- The chunk import used to run under the device's memory lock, so every other placement on
the device waited for it too.
- A low-weight thread that holds those locks is worse, not better. On the RTX 5080 laptop
(24 threads, kernel 7.2), a thread faulting in 64 MiB pieces of a fresh THP memfd ran
against 24 or 48 spinning threads at nice 0. Another thread's mmap+munmap waited:
policy 24 busy: p99 / max 48 busy: p99 / max chunks faulted in 6 s
default 0.23 / 12.4 ms 3.6 / 26.9 ms 883 / 276
SCHED_BATCH 1.4 / 12.4 ms 11.2 / 13.9 ms 850 / 581
nice 19 131 / 511 ms 164 / 1012 ms 4 / 2
SCHED_IDLE 0.004 / 1039 ms 0.005 / 1419 ms 1 / 1
So the thread keeps the default weight (SCHED_BATCH only marks it as batch work) and paces
itself by yielding and by faulting in small steps.
Measured on the same laptop, release build, 16 GiB of fresh THP memfd RAM imported ahead
whole. "Unpaced" is the parent commit (df5beeecaa, in stack19 as 97a69f70ab). A sampler
thread timed mmap+munmap of one page every millisecond:
run time mmap p99 / max >10 ms compact_stall / fail / allocstall_normal
unpaced, idle, first run of a hold 5088 ms 57.8 / 98.8 ms 76 2411 / 183 / 67
paced, idle, right after it 8374 ms 7.5 / 45.9 ms 32 930 / 209 / 0
unpaced, idle, calm memory (x3) 1515-1824 ms 5.2-6.4 / 6.7-6.8 0 none
paced, idle, calm memory (x3) 1552-1600 ms 4.9-5.0 / 5.3-6.6 0 none
unpaced, 24 threads busy (x3) 2212-5649 ms 9.7-19.2 / 12.3-24.9 7-238 none
paced, 24 threads busy (x3) 3720-6693 ms 0.27-1.6 / 1.9-7.7 0 none
- The earlier unpaced measurement (batch at df5beeecaa) was 3.47 s, with compact_stall 1152
and allocstall_normal 54.
- Compaction follows the host's memory state, not the pace. Only the first run of each hold
met page cache to reclaim and fragmented free memory, and the hold that had it ran unpaced
first. So the compaction rows are not a like-for-like comparison.
- The pace costs time only when the CPUs are busy, where the thread now shares them. In
return, the process's other threads wait at most a few ms for the memory map lock.
- In calm memory, the remaining ~5 ms p99 is the import's pin of 64 MiB of resident pages.
Verified at the tip of this branch (this commit and the next), on the RTX 5080 laptop with
--cfg m2v_gpu, release: the host_ram device tests pass, including
chunks_are_imported_ahead_so_no_making_waits_for_one (4 chunks ahead in 31.6 ms, the slowest
of 40 heap makings 52 us). Clippy is clean with all targets and features, plain and with
--cfg m2v_gpu.
(cherry picked from commit aff66f6a5dc424d97854c0908dee022475e8dc01)
(cherry picked from commit 9bbe4518ceff598e5fa0172d5624f6af7a75b6a2)
This commit is contained in:
1 parent
b2ac8d2abb
commit
f739bea1eb
5 files changed
+157
-67
No files matched your search
@@ -1766,12 +1766,13 @@ impl Device {
|
||||
}
|
||||
}
|
||||
// SAFETY: the caller's contract keeps the pages mapped until the placement is freed.
|
||||
let placement =
|
||||
unsafe { lock(&shared.memory).import_host(raw_device, pages, size, allowed, class) }
|
||||
.map_err(|failure| match failure {
|
||||
ImportFailure::NoMemoryType => not_importable(),
|
||||
ImportFailure::Vulkan(error) => import_refused(error),
|
||||
})?;
|
||||
let placement = unsafe {
|
||||
super::memory::import_host(&shared.memory, raw_device, pages, size, allowed, class)
|
||||
}
|
||||
.map_err(|failure| match failure {
|
||||
ImportFailure::NoMemoryType => not_importable(),
|
||||
ImportFailure::Vulkan(error) => import_refused(error),
|
||||
})?;
|
||||
// SAFETY: the placement is the pages' memory, the buffer's size and requirements of it
|
||||
// available from `at` (the caller's), and the buffer is unbound.
|
||||
let bound = unsafe {
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
//! what an object over fresh RAM waited for at every chunk's first object (a 2 MiB heap in 32
|
||||
//! over consecutive fresh RAM): so the whole RAM is resident and pinned from soon after the
|
||||
//! use begins. Counted: `WorkCounts::host_ram_chunks_imported_ahead`.
|
||||
//! - **Paced.** The thread runs as the system's batch work (never at a weight the system may
|
||||
//! starve: it holds a chunk's lock and, pinning, the process's memory map lock), yields between
|
||||
//! chunks, and on Linux faults each chunk's pages in 2 MiB at a time before its import, so that
|
||||
//! the import pins pages in place rather than holding the memory map lock while it faults in
|
||||
//! 64 MiB ([`pace`], [`fault_in`]). Each import is made with the device's memory lock released
|
||||
//! (`memory::import_host`), so the device's other placements wait for none of it.
|
||||
//! - **One run in place.** A no-copy object whose pages are one run inside one chunk is a
|
||||
//! `VkBuffer` bound in that chunk's import (`buffer_descriptor.rs`), made and bound as an import
|
||||
//! of the object's own pages would be: its size reaches no further than the object's last page,
|
||||
@@ -331,10 +337,15 @@ impl RamOnDevice {
|
||||
/// ([`Device::use_host_ram`]): one chunk at a time ([`RamOnDevice::next_ahead`]), each under its
|
||||
/// own lock and inside a section of the exit guard, until every chunk is imported or failed, the
|
||||
/// use ended, the device went or was lost, or the process exits. It holds the device and the RAM
|
||||
/// weakly between chunks, so neither outlives its last holder for it by more than one import. A
|
||||
/// chunk it fails to import (out of memory, pages the driver or the runtime refuses) is left to
|
||||
/// the first object over it, which meets the same answer on its own thread, as without this thread.
|
||||
/// weakly between chunks, so neither outlives its last holder for it by more than one import. A chunk it fails to import
|
||||
/// (out of memory, pages the driver or the runtime refuses) is left to the first object over it,
|
||||
/// which meets the same answer on its own thread, as without this thread.
|
||||
///
|
||||
/// Paced ([`pace`], [`fault_in`]): it runs as the system's batch work, yields between chunks,
|
||||
/// and on Linux faults a chunk's pages in 2 MiB at a time before its import, so that the
|
||||
/// import, which pins them, finds them in place.
|
||||
fn import_ahead(device: WeakDevice, ram: Weak<RamOnDevice>) {
|
||||
pace();
|
||||
loop {
|
||||
let (Some(device), Some(ram)) = (device.upgrade(), ram.upgrade()) else {
|
||||
return;
|
||||
@@ -349,6 +360,8 @@ fn import_ahead(device: WeakDevice, ram: Weak<RamOnDevice>) {
|
||||
let Some(slot) = ram.next_ahead() else {
|
||||
return;
|
||||
};
|
||||
// With no lock held: an object over the chunk meanwhile imports it itself, as before.
|
||||
fault_in(&ram.slots[slot].span);
|
||||
let Some(busy) = exit_guard::enter() else {
|
||||
return;
|
||||
};
|
||||
@@ -356,9 +369,67 @@ fn import_ahead(device: WeakDevice, ram: Weak<RamOnDevice>) {
|
||||
ram.slots[slot].tried.store(true, Ordering::Relaxed);
|
||||
}
|
||||
drop(busy);
|
||||
drop((ram, device));
|
||||
std::thread::yield_now();
|
||||
}
|
||||
}
|
||||
|
||||
/// The scheduling the device's thread ([`import_ahead`]) runs at: the system's batch work, never
|
||||
/// a lower weight. It holds a chunk's lock, which an object over the chunk waits on, and the
|
||||
/// pin it makes holds the process's memory map lock, which every `mmap`, `munmap` and, behind
|
||||
/// one queued, every page fault of the process waits on: a thread the system starves would hold
|
||||
/// those for as long as it is starved. On Linux, `SCHED_BATCH` (its nice value kept): measured on
|
||||
/// an RTX 5080 laptop's 24 threads all busy, a thread faulting in 64 MiB pieces of fresh memory
|
||||
/// at nice 19 kept another thread's `mmap` waiting up to 511 ms and at `SCHED_IDLE` 1039 ms,
|
||||
/// where at `SCHED_BATCH` it waited at most 12 ms, as at the default. On Apple's systems, the
|
||||
/// utility class, the lowest the system does not hold to its efficiency cores alone.
|
||||
fn pace() {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let keep = libc::sched_param { sched_priority: 0 };
|
||||
// SAFETY: the calling thread's own policy, from a live parameter; a refusal leaves it.
|
||||
let _ = unsafe { libc::sched_setscheduler(0, libc::SCHED_BATCH, &keep) };
|
||||
}
|
||||
#[cfg(target_vendor = "apple")]
|
||||
{
|
||||
// SAFETY: the calling thread's own class; a refusal leaves it.
|
||||
let _ =
|
||||
unsafe { libc::pthread_set_qos_class_self_np(libc::qos_class_t::QOS_CLASS_UTILITY, 0) };
|
||||
}
|
||||
}
|
||||
|
||||
/// Fault in the pages of `span`, a chunk of the RAM, 2 MiB at a time, yielding between
|
||||
/// (`MADV_POPULATE_WRITE`, Linux 5.14: each page as a write would, no byte changed), so that the
|
||||
/// chunk's import pins pages in place: each step holds the process's memory map lock for one
|
||||
/// huge page's fault, where an import of fresh pages holds it while it faults in all 64 MiB.
|
||||
/// A kernel that refuses (an older one) leaves the faults to the import, as before.
|
||||
#[cfg(target_os = "linux")]
|
||||
fn fault_in(span: &Range<u64>) {
|
||||
const STEP: u64 = 2 * 1024 * 1024;
|
||||
let mut at = span.start;
|
||||
while at < span.end {
|
||||
let length = STEP.min(span.end - at);
|
||||
// SAFETY: the span is pages of the RAM's ranges, mapped readable and writable while the
|
||||
// RAM lives (`HostRam::new`), which the caller holds; the advice writes no byte.
|
||||
let faulted = unsafe {
|
||||
libc::madvise(
|
||||
at as *mut libc::c_void,
|
||||
length as usize,
|
||||
libc::MADV_POPULATE_WRITE,
|
||||
)
|
||||
};
|
||||
if faulted != 0 {
|
||||
return;
|
||||
}
|
||||
std::thread::yield_now();
|
||||
at += length;
|
||||
}
|
||||
}
|
||||
|
||||
/// Elsewhere the import faults the chunk's pages in itself.
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn fault_in(_: &Range<u64>) {}
|
||||
|
||||
/// A device's import of one chunk of a RAM (`VK_EXT_external_memory_host`): the memory, and a
|
||||
/// `VkBuffer` over the whole chunk, for the runtime's own copies between the chunk and memory of
|
||||
/// the device's own alone; no Metal buffer, root entry or binding ever names it. Buffers bound
|
||||
@@ -373,7 +444,7 @@ pub(crate) struct RamChunk {
|
||||
span: Range<u64>,
|
||||
/// The `VkBuffer` over the whole chunk.
|
||||
raw: vk::Buffer,
|
||||
/// The import's placement: a dedicated block of the device's memory (`Memory::import_host`).
|
||||
/// The import's placement: a dedicated block of the device's memory (`memory::import_host`).
|
||||
placement: Placement,
|
||||
/// The RAM, let go of once the memory is freed; `None` once let go of.
|
||||
ram: Option<Arc<HostRam>>,
|
||||
@@ -569,8 +640,9 @@ impl Device {
|
||||
/// not reached imports it as it is made, one over the chunk the thread is importing waits for
|
||||
/// that import, and once the thread is done no making waits for one
|
||||
/// (`WorkCounts::host_ram_chunks_imported_ahead`). So the whole RAM's pages are faulted in
|
||||
/// and pinned from soon after this call. A system that cannot start the thread leaves every
|
||||
/// chunk to the first object over it. The use lasts until the returned [`HostRamUse`] is
|
||||
/// and pinned from soon after this call. The thread is paced (the system's batch work, a
|
||||
/// yield between chunks). A system that cannot start the thread leaves every chunk to the
|
||||
/// first object over it. The use lasts until the returned [`HostRamUse`] is
|
||||
/// dropped; a device may use several RAMs at once whose ranges are apart, and a new RAM once
|
||||
/// an earlier use of the same ranges ended (a VMM's next guest).
|
||||
///
|
||||
@@ -705,7 +777,7 @@ impl Device {
|
||||
|
||||
/// Import `span`, host pages of `ram`, as a chunk: a dedicated block of memory of a coherent
|
||||
/// type both the pages and a host-allocation buffer allow, with the device-address flag where
|
||||
/// the device enables `bufferDeviceAddress` (`Memory::import_host`), and a `VkBuffer` over the
|
||||
/// the device enables `bufferDeviceAddress` (`memory::import_host`), and a `VkBuffer` over the
|
||||
/// whole of it. Refused where the device's import alignment misses the span's start or end,
|
||||
/// it passes the device's allocation size, or the driver refuses the pages (or the runtime
|
||||
/// does for it, `Device::refuse_unpinnable`).
|
||||
@@ -769,7 +841,8 @@ impl Device {
|
||||
// SAFETY: the caller's contract keeps the pages mapped while the chunk, which frees the
|
||||
// placement as it goes, holds the RAM.
|
||||
let imported = unsafe {
|
||||
lock(&shared.memory).import_host(
|
||||
super::memory::import_host(
|
||||
&shared.memory,
|
||||
raw_device,
|
||||
(pointer, None),
|
||||
size,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//! - **Entry point.** [`allocate`] with the resource's memory requirements and its
|
||||
//! [`MemoryClass`]; [`Memory::free`] with the placement it gave. Buffers use it in step 1;
|
||||
//! textures and heaps add their classes and callers in their own steps. Imported host memory
|
||||
//! has its own entry, [`Memory::import_host`]: one dedicated block per import, never
|
||||
//! has its own entry, [`import_host`]: one dedicated block per import, never
|
||||
//! pooled, freed through the same [`Memory::free`]. So has a buffer's fresh pages
|
||||
//! ([`import_own_pages`], `fresh_pages.rs`): a dedicated block that unmaps them once its
|
||||
//! memory is freed, as an import through a read-only view of the caller's pages unmaps the view
|
||||
@@ -146,7 +146,7 @@ enum Fit {
|
||||
Apart,
|
||||
}
|
||||
|
||||
/// Why [`Memory::import_host`] imported nothing.
|
||||
/// Why [`import_host`] imported nothing.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) enum ImportFailure {
|
||||
/// No memory type of the class is among the allowed ones.
|
||||
@@ -640,7 +640,7 @@ pub(super) enum FreeCause {
|
||||
/// A kept empty pooled block freed so that a block of its memory type can be made
|
||||
/// ([`Memory::release_kept`]).
|
||||
KeptForRoom = 3,
|
||||
/// The caller's host memory, imported as a dedicated block ([`Memory::import_host`]) and
|
||||
/// The caller's host memory, imported as a dedicated block ([`import_host`]) and
|
||||
/// freed as its placement went.
|
||||
HostImport = 4,
|
||||
/// A buffer's fresh pages, imported as a dedicated block ([`import_own_pages`],
|
||||
@@ -665,7 +665,7 @@ pub(super) struct Census {
|
||||
pub(super) empty: u64,
|
||||
/// Dedicated blocks: a placement larger than half a block, or one placed apart.
|
||||
pub(super) dedicated: u64,
|
||||
/// The caller's host memory imported ([`Memory::import_host`]), a block each.
|
||||
/// The caller's host memory imported ([`import_host`]), a block each.
|
||||
pub(super) imported: u64,
|
||||
}
|
||||
|
||||
@@ -701,13 +701,13 @@ pub(super) struct Block {
|
||||
/// Its buffer of addresses, from the first placement that needs an address (the module
|
||||
/// docs).
|
||||
addresses: Option<BlockAddresses>,
|
||||
/// It is the caller's host memory, imported ([`Memory::import_host`]).
|
||||
/// It is the caller's host memory, imported ([`import_host`]).
|
||||
imported: bool,
|
||||
/// The pages its memory was imported from, where the runtime mapped them for it
|
||||
/// ([`import_own_pages`]): unmapped once the memory is freed.
|
||||
pages: Option<OwnPages>,
|
||||
/// The read-only view of the caller's pages its memory was imported from, which drops the
|
||||
/// GPU's writes ([`Memory::import_host`], `read_only_view.rs`): unmapped once the memory is
|
||||
/// GPU's writes ([`import_host`], `read_only_view.rs`): unmapped once the memory is
|
||||
/// freed.
|
||||
view: Option<ReadOnlyView>,
|
||||
/// Its memory type.
|
||||
@@ -730,7 +730,7 @@ struct BlockAddresses {
|
||||
impl Block {
|
||||
/// The cause its `vkFreeMemory` is counted under. A block freed as the one placement in it
|
||||
/// went ([`FreeCause::Dedicated`]) that is an import of its own is counted as that import
|
||||
/// instead: the caller's host memory ([`Memory::import_host`]) or a buffer's fresh pages
|
||||
/// instead: the caller's host memory ([`import_host`]) or a buffer's fresh pages
|
||||
/// ([`import_own_pages`]), each a dedicated block of one placement. Any other cause stands:
|
||||
/// a block freed at the device's teardown is counted there whatever it held.
|
||||
fn cause(&self, given: FreeCause) -> FreeCause {
|
||||
@@ -1557,47 +1557,6 @@ impl Memory {
|
||||
reached
|
||||
}
|
||||
|
||||
/// Import the caller's host memory, `size` bytes at `pointer` (both multiples of the device's
|
||||
/// import alignment), as a dedicated block of the best memory type of `class` among
|
||||
/// `allowed` (the types both the pointer and the resource take): its placement at offset 0,
|
||||
/// whose `mapped` is `pointer`. Where `view` is given, a read-only view of those pages
|
||||
/// (`read_only_view.rs`), the view is imported in their place, and unmapped once the memory
|
||||
/// is freed. The block is never pooled and is freed with the placement, as a dedicated block
|
||||
/// is (`host_memory.rs`). Refused when no type of `class` is among `allowed`, else with the
|
||||
/// failure of the last type tried, the view unmapped.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The `size` bytes at `pointer` are host memory of this process that stays mapped until the
|
||||
/// placement is freed; `view`, where given, views them whole.
|
||||
pub(super) unsafe fn import_host(
|
||||
&mut self,
|
||||
device: &ash::Device,
|
||||
(pointer, view): (NonNull<u8>, Option<ReadOnlyView>),
|
||||
size: u64,
|
||||
allowed: u32,
|
||||
class: MemoryClass,
|
||||
) -> Result<Placement, ImportFailure> {
|
||||
let types = candidates(&self.types, allowed, class, self.unified);
|
||||
let imported = view.as_ref().map_or(pointer, ReadOnlyView::pointer);
|
||||
// SAFETY: the caller's contract; the view stays mapped while the block holds it.
|
||||
let (memory, type_index) =
|
||||
unsafe { import_pointer(device, imported, size, &types, self.device_address) }?;
|
||||
let block = Block {
|
||||
memory,
|
||||
size,
|
||||
mapped: Some(Mapped(pointer)),
|
||||
addresses: None,
|
||||
imported: true,
|
||||
pages: None,
|
||||
view,
|
||||
type_index,
|
||||
};
|
||||
let host = pointer.as_ptr() as usize;
|
||||
self.say_block(&format!("imported host memory 0x{host:x}"), &block);
|
||||
Ok(self.add_import(block, type_index, size))
|
||||
}
|
||||
|
||||
/// The best memory type of `class` among `allowed`, where it has one.
|
||||
pub(super) fn best_type(&self, allowed: u32, class: MemoryClass) -> Option<u32> {
|
||||
candidates(&self.types, allowed, class, self.unified)
|
||||
@@ -1912,8 +1871,58 @@ fn color_image_types(device: &ash::Device, sharing: Sharing<'_>) -> Result<u32,
|
||||
})
|
||||
}
|
||||
|
||||
/// Import the caller's host memory, `size` bytes at `pointer` (both multiples of the device's
|
||||
/// import alignment), as a dedicated block of `memory`'s best memory type of `class` among
|
||||
/// `allowed` (the types both the pointer and the resource take): its placement at offset 0,
|
||||
/// whose `mapped` is `pointer`. Where `view` is given, a read-only view of those pages
|
||||
/// (`read_only_view.rs`), the view is imported in their place, and unmapped once the memory
|
||||
/// is freed. The block is never pooled and is freed with the placement, as a dedicated block
|
||||
/// is (`host_memory.rs`). The import, which faults in and pins the pages, is made with
|
||||
/// `memory`'s lock released, as a new block is ([`place`]): the device's other placements wait
|
||||
/// for none of it. Refused when no type of `class` is among `allowed`, else with the failure of
|
||||
/// the last type tried, the view unmapped.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The `size` bytes at `pointer` are host memory of this process that stays mapped until the
|
||||
/// placement is freed; `view`, where given, views them whole.
|
||||
pub(super) unsafe fn import_host(
|
||||
memory: &Mutex<Memory>,
|
||||
device: &ash::Device,
|
||||
(pointer, view): (NonNull<u8>, Option<ReadOnlyView>),
|
||||
size: u64,
|
||||
allowed: u32,
|
||||
class: MemoryClass,
|
||||
) -> Result<Placement, ImportFailure> {
|
||||
let (types, device_address) = {
|
||||
let memory = lock(memory);
|
||||
(
|
||||
candidates(&memory.types, allowed, class, memory.unified),
|
||||
memory.device_address,
|
||||
)
|
||||
};
|
||||
let imported = view.as_ref().map_or(pointer, ReadOnlyView::pointer);
|
||||
// SAFETY: the caller's contract; the view stays mapped while the block holds it.
|
||||
let (raw, type_index) =
|
||||
unsafe { import_pointer(device, imported, size, &types, device_address) }?;
|
||||
let block = Block {
|
||||
memory: raw,
|
||||
size,
|
||||
mapped: Some(Mapped(pointer)),
|
||||
addresses: None,
|
||||
imported: true,
|
||||
pages: None,
|
||||
view,
|
||||
type_index,
|
||||
};
|
||||
let host = pointer.as_ptr() as usize;
|
||||
let mut memory = lock(memory);
|
||||
memory.say_block(&format!("imported host memory 0x{host:x}"), &block);
|
||||
Ok(memory.add_import(block, type_index, size))
|
||||
}
|
||||
|
||||
/// Import `pages`, which the runtime mapped for a buffer of its own (`fresh_pages.rs`), as
|
||||
/// memory of type `type_index` in `memory`, as [`Memory::import_host`] imports the caller's: a
|
||||
/// memory of type `type_index` in `memory`, as [`import_host`] imports the caller's: a
|
||||
/// dedicated block, which unmaps the pages once its memory is freed, and its placement at
|
||||
/// offset 0. The import is made with `memory`'s lock released, as a new block is ([`place`]).
|
||||
/// Refused with the driver's failure, the pages unmapped.
|
||||
|
||||
@@ -2339,7 +2339,7 @@ impl Counters {
|
||||
}
|
||||
}
|
||||
|
||||
/// The device imported `bytes` of host pages by their pointer (`Memory::import_host`).
|
||||
/// The device imported `bytes` of host pages by their pointer (`memory::import_host`).
|
||||
pub(crate) fn host_pointer_import_made(&self, bytes: u64) {
|
||||
(self.host_pointer_imports_made).fetch_add(1, Ordering::Relaxed);
|
||||
(self.host_pointer_import_bytes_made).fetch_add(bytes, Ordering::Relaxed);
|
||||
@@ -3235,7 +3235,7 @@ pub struct MemoryFrees {
|
||||
/// failed to be made: the allocator giving memory back under pressure.
|
||||
pub kept_for_room: u64,
|
||||
/// Imports of the caller's host memory, a dedicated block each, freed as their placement went
|
||||
/// (`Memory::import_host`).
|
||||
/// (`memory::import_host`).
|
||||
pub host_import: u64,
|
||||
/// Imports of a buffer's fresh pages, a dedicated block each, freed as their placement went
|
||||
/// (`fresh_pages.rs`).
|
||||
@@ -3712,7 +3712,7 @@ pub struct WorkCounts {
|
||||
/// `vkFreeMemory` each, and the allocator's whole share of
|
||||
/// `object_churn.vk_memory_freed`.
|
||||
pub memory_frees: MemoryFrees,
|
||||
/// Its live imports of the caller's host memory, a block each (`Memory::import_host`).
|
||||
/// Its live imports of the caller's host memory, a block each (`memory::import_host`).
|
||||
pub host_imports_live: u64,
|
||||
/// Its blocks that went while batches submitted before were in flight, on a device whose
|
||||
/// driver fails pending work as memory a device-address buffer lay in is freed
|
||||
|
||||
+8
-1
@@ -450,7 +450,14 @@ pages then takes a kernel mapping per page) can give the device the guest's RAM
|
||||
it is importing waits for that import, and once it is done no making waits for one. So the whole
|
||||
RAM is faulted in and pinned from soon after `use_host_ram`, where a chunk's pages were faulted
|
||||
in only when an object over it was first made (on an RTX 5080 laptop with no other load: 7.5 ms
|
||||
a chunk of fresh `memfd` RAM under `MADV_HUGEPAGE`, 2 s for 16 GiB). The
|
||||
a chunk of fresh `memfd` RAM under `MADV_HUGEPAGE`, 1.5 to 8.4 s for 16 GiB, the most where
|
||||
the kernel compacts memory for the huge pages). The thread is paced: it runs as the system's batch
|
||||
work (`SCHED_BATCH` on Linux, the utility class on Apple's systems), never at a weight the
|
||||
system starves, since it holds a chunk's lock and, as it pins, the process's memory map lock; it
|
||||
yields between chunks; and on Linux it faults each chunk's pages in 2 MiB at a time
|
||||
(`MADV_POPULATE_WRITE`) before the import pins them. On that laptop with every CPU busy,
|
||||
another thread's `mmap` waited at most 7.7 ms (in 99 of 100 at most 1.6 ms) during the import
|
||||
of 16 GiB, which took 3.7 to 6.7 s. Each import is made with the device's memory lock released. The
|
||||
object's `VkBuffer` is made as an import of its own pages would make it and bound in the chunk
|
||||
at its run (`chunk_bound_buffers_made`): no import of its own, no gate asked, its `contents`
|
||||
still the pointer, and its size reaching no page past its own, so neither its Metal range, a
|
||||
|
||||
Reference in new issue
Block a user