Guest RAM: a listed chunk stays imported where the whole RAM fits the memory its imports count against
On RADV the first kernel submission that lists a guest-RAM chunk just imported waits while amdgpu writes the chunk's page tables, one entry per host page, through SDMA jobs that wait for room in the IB suballocator (amdgpu_cs_ioctl > amdgpu_vm_bo_update > amdgpu_vm_sdma_update > drm_suballoc). It holds the VM's reservation lock throughout, so every other submission of the device waits too, and so did the guest-RAM thread's next PRIME_FD_TO_HANDLE (218 ms in amdgpu_gem_object_open). Seen with a root /proc stack sampler on the Radeon 780M (gem10 job 4750): 231 to 275 ms of a gather's submission per 3.94 GiB chunk imported again. Every re-import after the idle release paid it again. A listed chunk, once imported, now stays imported while the device uses the RAM, where the whole RAM fits in half the device's memory heaps with unified memory (RADV reports an APU's GTT and carve-out together, split across two heaps), else in three quarters of the heaps that are not device-local (a discrete GPU's GTT). Chunks kept past their objects must fit in the kernel's GTT: RADV lists every import in every submission, which fails once they pass it. Where the RAM does not fit, chunks are released while idle as before. Each kept chunk costs every submission about half a microsecond (3 chunks for 8 GiB: 16 us against 14 us). Plan::releases says which; Device::count_host_ram_imports_against is the device tests' seam (cfg(test)): the release test makes the RAM too long, and a new test sees chunks kept past their objects and the idle window, with the next objects bound in them and no import made. The lane probe's gathers say how many chunks are live and were released. FAST-PATHS and HOWTO say what is true now. (cherry picked from commit 75f17258ddd0dc03e2f89a85819091cfa22c345a)
This commit is contained in:
1 parent
dcbe4552b7
commit
78a98addc1
5 files changed
+274
-38
No files matched your search
@@ -38,10 +38,19 @@
|
||||
//! alone, as below; those after it in the chunk's import. A buffer's run import is one more
|
||||
//! listed import, released while idle as a no-copy buffer's own import is (`host_residency.rs`),
|
||||
//! and the buffer is bound in the chunk at its next use; a heap's, or a buffer's whose address
|
||||
//! was handed out, stays while it lives. A chunk only its slot holds (no buffer bound in it, no
|
||||
//! pending command buffer that used one) is released once it stayed so for its window, as a
|
||||
//! no-copy buffer's idle import is (2 s, doubled at each release of the chunk up to 64 s), by
|
||||
//! the same thread; the next object over it asks for it again. Counted:
|
||||
//! was handed out, stays while it lives. The first kernel submission that lists a chunk just
|
||||
//! imported waits while the kernel writes the chunk's page tables, an entry a host page, and
|
||||
//! every other submission of the device waits for it, as it holds the lock of the device's
|
||||
//! page tables (measured with the kernel stacks of the waiting threads on the Radeon 780M,
|
||||
//! Mesa 26.2.6, Linux 7.3.1: 231 to 275 ms of a gather's submission for a chunk of 3.94 GiB
|
||||
//! imported again). So a chunk, once imported, stays imported while the device uses the RAM,
|
||||
//! where the whole RAM fits in the share of the memory the device's imports count against
|
||||
//! that [`releases_idle_chunks`] keeps it in: RADV lists every import in every kernel
|
||||
//! submission, which fails once they pass the kernel's GTT. Where it does not fit, a chunk
|
||||
//! only its slot holds (no buffer bound in it, no pending command buffer that used one) is
|
||||
//! released once it stayed so for its window, as a no-copy buffer's idle import is (2 s,
|
||||
//! doubled at each release of the chunk up to 64 s), by the same thread; the next object over
|
||||
//! it asks for it again, and the first submission after its import waits again. Counted:
|
||||
//! `WorkCounts::host_ram_chunks_released`.
|
||||
//! - **A window ahead of the objects.** From [`Device::use_host_ram`] on, a thread of the
|
||||
//! device's ([`import_ahead`]) keeps imported the chunk an object last took and a window of
|
||||
@@ -546,9 +555,14 @@ pub(crate) struct Plan {
|
||||
pub(crate) bytes: u64,
|
||||
/// The device's held imports add to the cost of every submission and the RAM's chunks are
|
||||
/// its dma-bufs (the module docs): its chunks are as long as [`listed_chunk_bytes`] allows,
|
||||
/// none is imported ahead, each is imported by the device's thread once an object over it
|
||||
/// asked, and one no object holds is released while idle.
|
||||
/// none is imported ahead, and each is imported by the device's thread once an object over
|
||||
/// it asked.
|
||||
pub(crate) listed: bool,
|
||||
/// A listed chunk no object holds is released once idle for its window
|
||||
/// ([`RamOnDevice::idle`]): only where the whole RAM does not fit in the share of the memory
|
||||
/// the device's imports count against that [`releases_idle_chunks`] keeps it in. Elsewhere
|
||||
/// every chunk stays imported while the device uses the RAM.
|
||||
pub(crate) releases: bool,
|
||||
}
|
||||
|
||||
impl Plan {
|
||||
@@ -556,6 +570,7 @@ impl Plan {
|
||||
pub(crate) const AHEAD: Plan = Plan {
|
||||
bytes: CHUNK_BYTES,
|
||||
listed: false,
|
||||
releases: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -576,6 +591,35 @@ pub(crate) fn listed_chunk_bytes(
|
||||
(most / CHUNK_BYTES).max(1) * CHUNK_BYTES
|
||||
}
|
||||
|
||||
/// The bytes of the memory a device's imports of host pages count against, from its memory
|
||||
/// `heaps`: with unified memory (`unified`), every heap, as the device's memory is the host's and
|
||||
/// its driver may report it in several (RADV on a Radeon 780M reports the kernel's GTT and the
|
||||
/// carve-out together, two thirds of them as a device-local heap and the rest as another);
|
||||
/// without, the heaps that are not `DEVICE_LOCAL` (a discrete GPU's GTT, which amdgpu charges
|
||||
/// with every dma-buf imported, as its `mem_info_gtt_used` shows).
|
||||
fn import_heap_bytes(heaps: &[vk::MemoryHeap], unified: bool) -> u64 {
|
||||
(heaps.iter())
|
||||
.filter(|heap| unified || !heap.flags.contains(vk::MemoryHeapFlags::DEVICE_LOCAL))
|
||||
.fold(0u64, |bytes, heap| bytes.saturating_add(heap.size))
|
||||
}
|
||||
|
||||
/// Whether a RAM of `ram_bytes` whose plan is [`Plan::listed`] has its idle chunks released
|
||||
/// ([`Plan::releases`]), on a device whose imports count against `import_heaps` bytes
|
||||
/// ([`import_heap_bytes`]), with unified memory or without (`unified`): only where the RAM does
|
||||
/// not fit in half of them with unified memory (where they hold the device's own memory too, and
|
||||
/// the carve-out besides the host's memory the imports count against), three quarters without.
|
||||
/// RADV lists every import in every kernel submission, which fails once they pass the kernel's
|
||||
/// GTT, so chunks kept past their objects must fit in it; and where they fit, a released chunk
|
||||
/// imported again costs the device's every submission a stall while the kernel writes its page
|
||||
/// tables again (the module docs).
|
||||
fn releases_idle_chunks(ram_bytes: u64, import_heaps: u64, unified: bool) -> bool {
|
||||
let kept = match unified {
|
||||
true => import_heaps / 2,
|
||||
false => import_heaps / 4 * 3,
|
||||
};
|
||||
ram_bytes > kept
|
||||
}
|
||||
|
||||
/// The chunks of `ranges` (host addresses, by start): `bytes` from each range's start, the last
|
||||
/// of each range ending at its end, so that no chunk crosses a range's end.
|
||||
fn chunk_spans(ranges: &[Range<u64>], bytes: u64) -> Vec<Range<u64>> {
|
||||
@@ -994,11 +1038,11 @@ fn import_ahead(device: WeakDevice, ram: Weak<RamOnDevice>, wake: Arc<Wake>) {
|
||||
/// [`import_ahead`]: it imports each chunk an object over it asked for
|
||||
/// ([`RamOnDevice::next_asked`]), one at a time, each once ([`RamOnDevice::chunk`]) and inside a
|
||||
/// section of the exit guard, off the threads making the objects, which are bound in imports of
|
||||
/// their own runs meanwhile ([`RamOnDevice::run_alone`]); between imports, and every
|
||||
/// `host_residency::TICK` while it waits, it releases the chunks only their slot has held for
|
||||
/// their window ([`RamOnDevice::idle`]), each freed inside a section of the exit guard as its last
|
||||
/// holder goes, and imported again once an object over it asks. Counted:
|
||||
/// `WorkCounts::host_ram_chunks_released`. A chunk it fails to import is left to the objects
|
||||
/// their own runs meanwhile ([`RamOnDevice::run_alone`]); where the plan releases idle chunks
|
||||
/// ([`Plan::releases`]), between imports, and every `host_residency::TICK` while it waits, it
|
||||
/// releases the chunks only their slot has held for their window ([`RamOnDevice::idle`]), each
|
||||
/// freed inside a section of the exit guard as its last holder goes, and imported again once an
|
||||
/// object over it asks. Counted: `WorkCounts::host_ram_chunks_released`. A chunk it fails to import is left to the objects
|
||||
/// over it, which import it on their own threads, as without this thread; so is a chunk asked
|
||||
/// for once one more import would leave the device less than a quarter of its
|
||||
/// `maxMemoryAllocationCount` (`allocations.rs`). It ends once the use ended, the device went or
|
||||
@@ -1033,11 +1077,13 @@ fn listed_chunks(device: WeakDevice, ram: Weak<RamOnDevice>, wake: Arc<Wake>) {
|
||||
std::thread::yield_now();
|
||||
continue;
|
||||
}
|
||||
let gone = ram.idle(Instant::now());
|
||||
for _ in &gone {
|
||||
shared.counts.host_ram_chunk_released();
|
||||
if ram.plan.releases {
|
||||
let gone = ram.idle(Instant::now());
|
||||
for _ in &gone {
|
||||
shared.counts.host_ram_chunk_released();
|
||||
}
|
||||
drop(gone);
|
||||
}
|
||||
drop(gone);
|
||||
drop((ram, device));
|
||||
wake.wait_for(host_residency::TICK);
|
||||
}
|
||||
@@ -1141,8 +1187,9 @@ fn give_back_untaken(device: WeakDevice) {
|
||||
/// do the command buffers that use them, until they completed; the device holds it while it uses
|
||||
/// the RAM ([`HostRamUse`]). The last holder destroys the `VkBuffer` and frees the memory, and the
|
||||
/// RAM, which the chunk holds, goes after the free: its keep-alive with it once no chunk holds it.
|
||||
/// Released while idle only where each listed import costs every submission ([`Plan::listed`],
|
||||
/// [`listed_chunks`]). Left to the process's end while it exits.
|
||||
/// Released while idle only where each listed import costs every submission and the RAM does not
|
||||
/// fit in the memory its imports count against ([`Plan::releases`], [`listed_chunks`]). Left to
|
||||
/// the process's end while it exits.
|
||||
pub(crate) struct RamChunk {
|
||||
device: Device,
|
||||
/// The host bytes imported.
|
||||
@@ -1358,6 +1405,10 @@ pub(crate) struct RamSource {
|
||||
/// while it is set starts none, so its chunks are imported by the objects over them alone.
|
||||
#[cfg(test)]
|
||||
held: AtomicBool,
|
||||
/// The tests' bytes of the memory the device's imports count against, in place of its heaps'
|
||||
/// ([`Device::count_host_ram_imports_against`]); 0 for the heaps'.
|
||||
#[cfg(test)]
|
||||
import_heaps: std::sync::atomic::AtomicU64,
|
||||
}
|
||||
|
||||
impl RamSource {
|
||||
@@ -1399,6 +1450,13 @@ impl Device {
|
||||
self.shared().host_ram.held.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Plan the RAMs used from now on as though the device's imports counted against `bytes` of
|
||||
/// memory, in place of its heaps' ([`releases_idle_chunks`]): the tests' way to see a listed
|
||||
/// RAM's idle chunks released, or kept, whatever the device's heaps.
|
||||
pub(crate) fn count_host_ram_imports_against(&self, bytes: u64) {
|
||||
(self.shared().host_ram.import_heaps).store(bytes, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Each RAM the device uses: whether it imports it as each listed import costing every
|
||||
/// submission ([`Plan::listed`]), and its chunks (read by the dma-buf tests, Linux's).
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -1460,7 +1518,11 @@ impl Device {
|
||||
/// hundreds of milliseconds), and that object and those over the chunk meanwhile are bound in
|
||||
/// imports of their own runs alone, as above; a buffer's is released while idle, the buffer
|
||||
/// bound in the chunk at its next use, and a heap's, or a buffer's whose address was handed
|
||||
/// out, stays while it lives. The thread releases a chunk no object nor pending command
|
||||
/// out, stays while it lives. A chunk stays imported once imported, as the first submission
|
||||
/// after a chunk's import waits while the kernel writes its page tables (hundreds of
|
||||
/// milliseconds for a chunk of 4 GiB on a Radeon 780M), where the whole RAM fits in half the
|
||||
/// device's memory heaps with unified memory, else in three quarters of those that are not
|
||||
/// device-local. Where it does not, the thread releases a chunk no object nor pending command
|
||||
/// buffer held for 2 s, the window doubled at each release of the chunk up to 64 s
|
||||
/// (`WorkCounts::host_ram_chunks_released`); the next object over it asks for it again.
|
||||
///
|
||||
@@ -1593,6 +1655,22 @@ impl Device {
|
||||
.limits
|
||||
.max_storage_buffer_range;
|
||||
let allocation = self.compile_device().allocation();
|
||||
let shared = self.shared();
|
||||
// SAFETY: the device's own physical device, of its instance.
|
||||
let memory =
|
||||
unsafe { (shared.instance.raw).get_physical_device_memory_properties(shared.physical) };
|
||||
let heaps =
|
||||
&memory.memory_heaps[..(memory.memory_heap_count as usize).min(vk::MAX_MEMORY_HEAPS)];
|
||||
let unified = self.properties().has_unified_memory;
|
||||
let import_heaps = import_heap_bytes(heaps, unified);
|
||||
#[cfg(test)]
|
||||
let import_heaps = match shared.host_ram.import_heaps.load(Ordering::Relaxed) {
|
||||
0 => import_heaps,
|
||||
set => set,
|
||||
};
|
||||
let ram_bytes = (ram.ranges.iter()).fold(0u64, |bytes, range| {
|
||||
bytes.saturating_add(range.end - range.start)
|
||||
});
|
||||
Plan {
|
||||
bytes: listed_chunk_bytes(
|
||||
ram.largest_dma_buf,
|
||||
@@ -1601,6 +1679,7 @@ impl Device {
|
||||
u64::from(storage),
|
||||
),
|
||||
listed: true,
|
||||
releases: releases_idle_chunks(ram_bytes, import_heaps, unified),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2021,6 +2100,38 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn listed_chunks_stay_imported_where_the_ram_fits_the_memory_imports_count_against() {
|
||||
const GIB: u64 = 1 << 30;
|
||||
let heap = |size: u64, flags: vk::MemoryHeapFlags| vk::MemoryHeap { size, flags };
|
||||
let local = vk::MemoryHeapFlags::DEVICE_LOCAL;
|
||||
let none = vk::MemoryHeapFlags::empty();
|
||||
// RADV on the Radeon 780M of a host with a 4 GiB carve-out and a 13,939 MiB GTT: both
|
||||
// reported together, two thirds device-local; on the RX 7900 XTX beside it, 24 GiB of
|
||||
// VRAM and the GTT.
|
||||
let (gtt, carve_out) = (13939 * MIB, 4 * GIB);
|
||||
let apu = [
|
||||
heap((gtt + carve_out) / 3, none),
|
||||
heap((gtt + carve_out) - (gtt + carve_out) / 3, local),
|
||||
];
|
||||
let discrete = [heap(24 * GIB, local), heap(gtt, none)];
|
||||
assert_eq!(import_heap_bytes(&apu, true), gtt + carve_out);
|
||||
assert_eq!(import_heap_bytes(&discrete, false), gtt);
|
||||
assert_eq!(import_heap_bytes(&[heap(8 * GIB, local)], false), 0);
|
||||
// An 8 GiB guest RAM stays imported on both; a 16 GiB one is released while idle.
|
||||
assert!(!releases_idle_chunks(8 * GIB, gtt + carve_out, true));
|
||||
assert!(!releases_idle_chunks(8 * GIB, gtt, false));
|
||||
assert!(releases_idle_chunks(16 * GIB, gtt + carve_out, true));
|
||||
assert!(releases_idle_chunks(16 * GIB, gtt, false));
|
||||
// The bounds: half with unified memory, three quarters without; nothing to count against
|
||||
// releases every RAM.
|
||||
assert!(!releases_idle_chunks(4 * GIB, 8 * GIB, true));
|
||||
assert!(releases_idle_chunks(4 * GIB + 1, 8 * GIB, true));
|
||||
assert!(!releases_idle_chunks(6 * GIB, 8 * GIB, false));
|
||||
assert!(releases_idle_chunks(6 * GIB + 1, 8 * GIB, false));
|
||||
assert!(releases_idle_chunks(1, 0, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_chunks_cut_each_range_from_its_start() {
|
||||
let chunk = 63 * CHUNK_BYTES;
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
//! imported ahead: the first object over a chunk lies in its own run's import and asks the
|
||||
//! device's thread for the chunk, which imports it; those after it lie in the chunk. The runs'
|
||||
//! imports, which only blits read, are released once idle, the next blit binding the buffer in
|
||||
//! the chunk; the chunk is kept while an object over it lives, and released by the device's
|
||||
//! thread once none did for its idle window (`WorkCounts::host_ram_chunks_released`); a copy
|
||||
//! over it then imports its run alone and asks for the chunk again.
|
||||
//! Elsewhere the RAM keeps its 64 MiB chunks.
|
||||
//! the chunk; the chunk is kept while an object over it lives. Where the RAM does not fit in
|
||||
//! the memory the device's imports count against (made so by the test), the device's thread
|
||||
//! releases it once none did for its idle window (`WorkCounts::host_ram_chunks_released`), and
|
||||
//! a copy over it then imports its run alone and asks for the chunk again; where the RAM fits,
|
||||
//! the chunks stay imported past their objects and the window, and the next object lies in its
|
||||
//! chunk with no import. Elsewhere the RAM keeps its 64 MiB chunks.
|
||||
//!
|
||||
//! Each run prints the device's verdict and the route its chunk took: the evidence of which path
|
||||
//! ran. Where `/dev/udmabuf` cannot be opened, or the device imports no host memory, the test says
|
||||
@@ -529,8 +531,9 @@ fn udmabuf_size_limit() -> u64 {
|
||||
/// Where each listed import costs every submission, a RAM whose dma-bufs may be as long as the
|
||||
/// host's udmabuf limit allows is imported in chunks that long (the whole RAM where the limit
|
||||
/// takes it, else two of 64 MiB), none ahead, each by the device's thread once an object over it
|
||||
/// asked, and released once idle (the module docs); elsewhere it keeps its 64 MiB chunks. The
|
||||
/// device's thread runs (no hold), so the imports and the release are its.
|
||||
/// asked, and, the RAM made too long for the memory the device's imports count against, released
|
||||
/// once idle (the module docs); elsewhere it keeps its 64 MiB chunks. The device's thread runs
|
||||
/// (no hold), so the imports and the release are its.
|
||||
#[test]
|
||||
fn where_each_listed_import_costs_a_submission_the_ram_is_long_chunks_released_once_idle() {
|
||||
let scratch = Scratch::new();
|
||||
@@ -542,6 +545,8 @@ fn where_each_listed_import_costs_a_submission_the_ram_is_long_chunks_released_o
|
||||
eprintln!("HOST-RAM-LISTED: the device imports no host memory here; nothing to test");
|
||||
return;
|
||||
}
|
||||
// Half the RAM, which it fits in with unified memory or without.
|
||||
device.count_host_ram_imports_against(RAM_BYTES / 2);
|
||||
let listed = device.pointer_imports_tax_submissions() && imports_dma_bufs(&device);
|
||||
let largest = udmabuf_size_limit();
|
||||
let (ram, start, view, asked, dropped) = ram(true);
|
||||
@@ -745,3 +750,107 @@ fn where_each_listed_import_costs_a_submission_the_ram_is_long_chunks_released_o
|
||||
std::thread::sleep(Duration::from_millis(5));
|
||||
}
|
||||
}
|
||||
|
||||
/// Where each listed import costs every submission and the RAM fits in the memory the device's
|
||||
/// imports count against (made four times the RAM by the test), its chunks, once imported, stay
|
||||
/// imported past their objects and the idle window: none is released, and the next object over
|
||||
/// each lies in its chunk with no import made for it. Elsewhere nothing to test.
|
||||
#[test]
|
||||
fn where_the_ram_fits_its_listed_chunks_stay_imported_once_idle() {
|
||||
let scratch = Scratch::new();
|
||||
if !udmabuf_openable() {
|
||||
return;
|
||||
}
|
||||
let device = device(&scratch.0);
|
||||
if device.shared().host_import.is_err() {
|
||||
eprintln!("HOST-RAM-KEPT: the device imports no host memory here; nothing to test");
|
||||
return;
|
||||
}
|
||||
device.count_host_ram_imports_against(4 * RAM_BYTES);
|
||||
let listed = device.pointer_imports_tax_submissions() && imports_dma_bufs(&device);
|
||||
if !listed {
|
||||
eprintln!(
|
||||
"HOST-RAM-KEPT {}: no listed imports here; nothing to test",
|
||||
device.name()
|
||||
);
|
||||
return;
|
||||
}
|
||||
let (ram, start, view, _asked, dropped) = ram(true);
|
||||
let ram = Arc::into_inner(ram).expect("the test's RAM");
|
||||
let ram = Arc::new(ram.with_largest_dma_buf(udmabuf_size_limit()));
|
||||
fill_pattern(view, RAM_BYTES);
|
||||
let used = device.use_host_ram(&ram).unwrap();
|
||||
let chunks = device.host_ram_chunks();
|
||||
let [(true, spans)] = &chunks[..] else {
|
||||
panic!("one listed RAM: {chunks:?}");
|
||||
};
|
||||
let count = spans.len() as u64;
|
||||
let before = device.work_counts();
|
||||
let until = |done: &dyn Fn(&crate::WorkCounts) -> bool, what: &str| {
|
||||
let began = Instant::now();
|
||||
loop {
|
||||
let counts = device.work_counts();
|
||||
if done(&counts) {
|
||||
return counts;
|
||||
}
|
||||
assert!(began.elapsed() < WAIT, "{what}");
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
};
|
||||
// One object over each chunk asks for it; the device's thread imports each.
|
||||
let firsts: Vec<Buffer> = (spans.iter())
|
||||
.map(|span| buffer(&device, view, start, span.start - start + AT, LENGTH))
|
||||
.collect();
|
||||
let imported = until(
|
||||
&|counts| counts.host_ram_chunks_imported - before.host_ram_chunks_imported == count,
|
||||
"the asked chunks were never imported",
|
||||
);
|
||||
// The objects gone, past the chunks' idle window and a tick of the thread: kept.
|
||||
drop(firsts);
|
||||
std::thread::sleep(IDLE_WAIT);
|
||||
let idle = device.work_counts();
|
||||
assert_eq!(
|
||||
idle.host_ram_chunks_released, before.host_ram_chunks_released,
|
||||
"a chunk of a RAM that fits was released"
|
||||
);
|
||||
assert_eq!(idle.host_ram_chunks_live, imported.host_ram_chunks_live);
|
||||
// The next object over each lies in its chunk, as imported: no import made for it.
|
||||
let nexts: Vec<Buffer> = (spans.iter())
|
||||
.map(|span| buffer(&device, view, start, span.start - start + AT, LENGTH))
|
||||
.collect();
|
||||
let after = device.work_counts();
|
||||
assert_eq!(
|
||||
(
|
||||
after.chunk_bound_buffers_made - idle.chunk_bound_buffers_made,
|
||||
after.run_bound_buffers_made - idle.run_bound_buffers_made,
|
||||
after.host_ram_chunks_imported - idle.host_ram_chunks_imported,
|
||||
after.host_ram_dma_buf_imports - idle.host_ram_dma_buf_imports,
|
||||
),
|
||||
(count, 0, 0, 0),
|
||||
"the objects after the idle window lie in the kept chunks"
|
||||
);
|
||||
// The GPU reads the file's bytes through them.
|
||||
let read = read_back(&device, LENGTH, |encoder, own| {
|
||||
(encoder.copy_from_buffer_to_buffer(&nexts[0], 0, own, 0, LENGTH)).unwrap();
|
||||
});
|
||||
assert!(
|
||||
read.iter()
|
||||
.zip(AT..)
|
||||
.all(|(&b, offset)| b == pattern(offset)),
|
||||
"the read through the kept chunk's import"
|
||||
);
|
||||
println!(
|
||||
"HOST-RAM-KEPT {}: {count} chunk(s) kept {} s past their objects, none released",
|
||||
device.name(),
|
||||
IDLE_WAIT.as_secs(),
|
||||
);
|
||||
drop((nexts, used, ram));
|
||||
let began = Instant::now();
|
||||
while !dropped.load(Ordering::SeqCst) {
|
||||
assert!(
|
||||
began.elapsed() < WAIT,
|
||||
"the RAM's keep-alive was never dropped"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(5));
|
||||
}
|
||||
}
|
||||
@@ -742,10 +742,11 @@ fn submit_per_ram_dma_buf() {
|
||||
/// made over chunks not imported (its pages resolved to the RAM's own, `HostMemory::with_runs`)
|
||||
/// and used by one command buffer; once the device's thread imported the chunks, one more object
|
||||
/// was made over each stride, the first objects' run imports were released while idle and each
|
||||
/// was used again (so lies in its chunk); and [`RAM_IDLE`] after the buffers went. Then three
|
||||
/// gathers (`copy_from_host_ram`) from the released chunks, encoded, committed and waited for:
|
||||
/// [`RAM_COPY_RUN`] at 16 strides of the first chunk, the same again once that chunk is imported,
|
||||
/// and one at each stride. Printed as `SUBMIT-PER-IMPORT` lines (`submit_per_import`'s) and
|
||||
/// was used again (so lies in its chunk); and [`RAM_IDLE`] after the buffers went, the chunks
|
||||
/// kept where the RAM fits in the memory the device's imports count against, else released.
|
||||
/// Then three gathers (`copy_from_host_ram`) from those chunks, encoded, committed and waited
|
||||
/// for: [`RAM_COPY_RUN`] at 16 strides of the first chunk, the same again once the device's
|
||||
/// thread settled (a released chunk imported again by then), and one at each stride. Printed as `SUBMIT-PER-IMPORT` lines (`submit_per_import`'s) and
|
||||
/// `SUBMIT-PER-RAM-CHUNK` lines: the chunks the device imported
|
||||
/// (`WorkCounts::host_ram_chunks_imported`, `host_ram_chunk_bytes`, `host_ram_chunks_live`,
|
||||
/// `host_ram_chunks_imported_ahead`, `host_ram_chunks_released`), the run imports and dma-buf
|
||||
@@ -970,7 +971,7 @@ fn submit_per_ram_chunk() {
|
||||
eprintln!(
|
||||
"SUBMIT-PER-RAM-CHUNK {}: {what}: a gather of {} runs of {} KiB encoded in {:.3} ms, \
|
||||
committed to completed in {:.3} ms ({:.3} ms of it submitting); {} dma-buf imports \
|
||||
made, {} chunks imported by then",
|
||||
made, {} chunks imported by then, {} live, {} released before it",
|
||||
device.name(),
|
||||
runs.len(),
|
||||
runs[0].end.saturating_sub(runs[0].start) >> 10,
|
||||
@@ -979,12 +980,14 @@ fn submit_per_ram_chunk() {
|
||||
submitting * 1e3,
|
||||
counts.host_ram_dma_buf_imports - before.host_ram_dma_buf_imports,
|
||||
counts.host_ram_chunks_imported - before.host_ram_chunks_imported,
|
||||
counts.host_ram_chunks_live,
|
||||
before.host_ram_chunks_released - made.host_ram_chunks_released,
|
||||
);
|
||||
};
|
||||
gather("16 in the first chunk, released", &few);
|
||||
gather("16 in the first chunk, after the idle wait", &few);
|
||||
std::thread::sleep(RAM_QUIET);
|
||||
gather("16 in the first chunk, imported again", &few);
|
||||
gather("one at each 64 MiB, the other chunks released", &every);
|
||||
gather("16 in the first chunk again", &few);
|
||||
gather("one at each 64 MiB", &every);
|
||||
report("after the copies", &made);
|
||||
drop(used);
|
||||
}
|
||||
+9
-2
@@ -184,8 +184,15 @@ recorded here.
|
||||
again at the first blit after the window (HOWTO.md section 6). For the same reason a guest RAM
|
||||
there (`Device::use_host_ram`, with a source of dma-bufs) is imported in a few long chunks
|
||||
(`HostRam::with_largest_dma_buf`, within the device's allocation, buffer and storage-range
|
||||
limits), none ahead of the objects, and a chunk no buffer nor pending command buffer holds is
|
||||
released after the same window (`WorkCounts::host_ram_chunks_released`). The first object over
|
||||
limits), none ahead of the objects. A chunk, once imported, stays imported where the whole RAM
|
||||
fits in half the device's memory heaps with unified memory, or in three quarters of those that
|
||||
are not device-local without: the first kernel submission after a chunk's import waits while
|
||||
the kernel writes its page tables, and every other submission of the device with it (231 to
|
||||
275 ms for a 3.94 GiB chunk on the Radeon 780M), where each kept chunk costs every submission
|
||||
about half a microsecond (3 chunks for an 8 GiB RAM: 16 µs a submission, 14 µs with none).
|
||||
Where the RAM does not fit, a chunk no buffer nor pending command buffer holds is released
|
||||
after the same window (`WorkCounts::host_ram_chunks_released`), as RADV lists every import in
|
||||
every kernel submission, which fails once they pass the kernel's GTT. The first object over
|
||||
a chunk not imported asks a thread of the device's for it, which imports it off the object's
|
||||
thread (it pins every page of the chunk: 660 to 692 ms for 2.7 GiB on the Radeon 780M and the
|
||||
RX 7900 XTX), and the objects over it meanwhile are each bound in an import of its own run,
|
||||
|
||||
+10
-4
@@ -570,10 +570,16 @@ submission, can give the device the guest's RAM once instead:
|
||||
object, and every object over the chunk until the import is done, is bound in an import of its
|
||||
own run alone, as above, so no making waits for the chunk; each is one more listed import, a
|
||||
buffer's released after its idle window and a heap's, or a buffer's whose address was handed
|
||||
out, kept while the object lives. A chunk no buffer bound in it and no pending command buffer that
|
||||
used it holds for its idle window (2 s, doubled at each release of the chunk up to 64 s) is
|
||||
released by the same thread (`host_ram_chunks_released`), and the next object over it asks for
|
||||
it again.
|
||||
out, kept while the object lives. The first kernel submission after a chunk's import waits while
|
||||
the kernel writes the chunk's page tables, and so does every other submission of the device
|
||||
(231 to 275 ms for a 3.94 GiB chunk on the Radeon 780M), so a chunk stays imported once
|
||||
imported where the whole RAM fits in half the device's memory heaps with unified memory, or in
|
||||
three quarters of its heaps that are not device-local without (an 8 GiB RAM does on the 780M
|
||||
and the RX 7900 XTX of a 27 GiB host). Each kept chunk adds about half a microsecond to every
|
||||
submission. Where the RAM does not fit, a chunk no buffer bound in it and no pending command
|
||||
buffer that used it holds for its idle window (2 s, doubled at each release of the chunk up to
|
||||
64 s) is released by the same thread (`host_ram_chunks_released`), and the next object over it
|
||||
asks for it again.
|
||||
- Any other answer (several runs, one run crossing a chunk's end, `None`) takes the paths above:
|
||||
the gate, then the import or the copy. The runs are kept with the object.
|
||||
- Elsewhere the chunks are never released while idle. Once the use is dropped, each is freed when
|
||||
|
||||
Reference in new issue
Block a user