rt: a recorder's pool is reset releasing its memory, so a submission is not held for a free beside it
On NVIDIA's Linux driver (RTX 2080 and 3090), a vkQueueSubmit2 of a command buffer from a pool that was reset keeping its memory waited until any vkFreeMemory of host-visible memory beside it ended: in the paced runs a submission was held 20-23 ms, and in the probe a commit 1 ms into a 64 MiB Shared free completed 24-46 ms late (median; up to 70). The probe isolated it to the pool: neither the host barrier, nor the batch's shape (one SubmitInfo2, no waits, one command buffer), nor the memory the command buffer touches, nor the completion thread's calls are held. A non-transient reused pool, or a reset on the recording thread, is held the same. A fresh pool, or the reused pool reset with VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT, is not. give_back now resets with RELEASE_RESOURCES: one form on every device, no query. It also bounds a recorder's memory: a pool that once recorded a long command buffer keeps none of it past its next reset, where before each of up to IDLE_MAX pools kept its high-water mark. Probe 6be5985659 (jobs m3-max-46001 2080, 46002 3090, 46003 XTX, 46004 Iris; ms, median): commit to completion during a free, as it was / released: 2080 24.2 / 0.16, 3090 45.6 / 0.22; with no free: 2080 0.45 / 0.48, 3090 0.95 / 1.11, XTX 1.55 / 1.49, Iris 1.14 / 1.26 (ranges overlap); the reset at retire 0.01-0.03 either way on all four. A device test commits 1 ms into a 64 MiB Shared free the GPU used and fails where the commit's completion takes half the free's time or more, on a device whose free takes 10 ms or more. make_allocation, free_allocation and Allocation's memory are pub(crate) for it.
This commit is contained in:
1 parent
3cbf244329
commit
3dff069f08
3 files changed
+100
-6
No files matched your search
@@ -318,8 +318,8 @@ impl Drop for Block {
|
||||
}
|
||||
|
||||
/// One `VkDeviceMemory` of a class and the ranges of it no block holds.
|
||||
struct Allocation {
|
||||
memory: vk::DeviceMemory,
|
||||
pub(crate) struct Allocation {
|
||||
pub(crate) memory: vk::DeviceMemory,
|
||||
len: u64,
|
||||
mapping: Option<Mapping>,
|
||||
device_local: bool,
|
||||
@@ -1238,7 +1238,11 @@ fn new_buffer(device: &ash::Device, len: u64) -> Result<vk::Buffer, Error> {
|
||||
/// Makes an allocation of `len` bytes of `class` with device addresses, mapped whole if
|
||||
/// Shared, its free ranges all of it. Its bytes are undefined: nothing writes them, and a Shared
|
||||
/// allocation's pages become resident as they are first written.
|
||||
fn make_allocation(core: &Core, class: MemoryClass, len: u64) -> Result<Allocation, Error> {
|
||||
pub(crate) fn make_allocation(
|
||||
core: &Core,
|
||||
class: MemoryClass,
|
||||
len: u64,
|
||||
) -> Result<Allocation, Error> {
|
||||
let device = &core.device;
|
||||
let buffer = vk::BufferCreateInfo::default()
|
||||
.size(len)
|
||||
@@ -1367,7 +1371,7 @@ fn free_idle(core: &Core, allocation: Allocation, kept: &[Memory]) {
|
||||
}
|
||||
|
||||
/// Frees an allocation, whose blocks are all retired. Freeing the memory also unmaps it.
|
||||
fn free_allocation(core: &Core, allocation: Allocation) {
|
||||
pub(crate) fn free_allocation(core: &Core, allocation: Allocation) {
|
||||
// SAFETY: no buffer is bound to it any more, and no GPU work uses it.
|
||||
unsafe { core.device.free_memory(allocation.memory, None) };
|
||||
core.counters.fall(Gauge::Blocks);
|
||||
|
||||
@@ -183,13 +183,22 @@ impl Recorders {
|
||||
}
|
||||
|
||||
/// Takes back a recorder whose work has completed, or that never submitted: its pool is reset
|
||||
/// for the next one, or, past [`IDLE_MAX`], given to the reaper to destroy.
|
||||
/// for the next one, its memory given back to the driver, or, past [`IDLE_MAX`], given to the
|
||||
/// reaper to destroy.
|
||||
///
|
||||
/// The reset releases the pool's memory, so a recorder that once recorded a long command
|
||||
/// buffer keeps none of it. A pool reset keeping its memory made NVIDIA's Linux driver hold
|
||||
/// the next `vkQueueSubmit2` of the pool's command buffers until any `vkFreeMemory` of
|
||||
/// host-visible memory beside it ended: 20 to 70 ms beside a 64 MiB free on an RTX 2080 and
|
||||
/// an RTX 3090, against 0.2 ms with the memory released, as with a new pool. The release
|
||||
/// cost no measurable time per command buffer there, on a Radeon RX 7900 XTX or on an Iris Xe
|
||||
/// (probe 6be5985659, jobs m3-max-46001 to m3-max-46004).
|
||||
pub(crate) fn give_back(&self, core: &Core, mut recorder: Recorder) {
|
||||
// SAFETY: no command buffer of the pool is pending. A failed reset (a lost device) leaves
|
||||
// the pool to be destroyed.
|
||||
let reset = unsafe {
|
||||
core.device
|
||||
.reset_command_pool(recorder.pool, vk::CommandPoolResetFlags::empty())
|
||||
.reset_command_pool(recorder.pool, vk::CommandPoolResetFlags::RELEASE_RESOURCES)
|
||||
};
|
||||
let mut idle = lock(&self.idle);
|
||||
if reset.is_ok() && idle.len() < IDLE_MAX {
|
||||
|
||||
@@ -130,6 +130,8 @@ fn the_idle_rule_keeps_idle_allocations_under_the_window_s_peak() {
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod on_device {
|
||||
use crate::device::lock;
|
||||
use crate::memory::{free_allocation, make_allocation};
|
||||
use crate::tests::command::on_device::each_device;
|
||||
use crate::tests::devices_of_the_cfgs_kind;
|
||||
use crate::{
|
||||
Block, BlockId, BlockInfo, BlockMappings, Buffer, CommandBufferStatus, Device,
|
||||
@@ -1197,6 +1199,85 @@ mod on_device {
|
||||
}
|
||||
}
|
||||
|
||||
/// A commit is not held for a free of host-visible memory beside it: a command buffer
|
||||
/// committed 1 ms into the free of a 64 MiB Shared allocation the GPU used completes in less
|
||||
/// than half the free's time. NVIDIA's Linux driver held the submission of a command buffer
|
||||
/// from a pool reset keeping its memory for the whole of such a free (20 to 70 ms on an RTX
|
||||
/// 2080 and 3090); the recorders' pools are reset releasing it. A device whose free takes
|
||||
/// under 10 ms only prints its times.
|
||||
#[test]
|
||||
fn every_device_completes_a_commit_beside_a_free_of_shared_memory_unheld() {
|
||||
each_device("commit beside a free", |name, _, device| {
|
||||
let core = device.core();
|
||||
let queue = device.new_command_queue(4).expect("a queue");
|
||||
let target = device
|
||||
.take_block(MemoryClass::Private, 4096)
|
||||
.expect("a block");
|
||||
let kept = device
|
||||
.new_buffer(target.id, 0, 256, None)
|
||||
.expect("a buffer");
|
||||
let to = device.block(target.id).expect("a held block").memory.buffer;
|
||||
let commit = |fill: vk::Buffer| {
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
command_buffer
|
||||
.record_for_test(&[&kept], |device, command| unsafe {
|
||||
device.cmd_fill_buffer(command, fill, 0, 256, 7)
|
||||
})
|
||||
.expect("a fill");
|
||||
let started = Instant::now();
|
||||
command_buffer.commit().expect("a commit");
|
||||
command_buffer.wait_until_completed();
|
||||
started.elapsed()
|
||||
};
|
||||
// The queue's recorders reused, as a program's are.
|
||||
for _ in 0..3 {
|
||||
commit(to);
|
||||
}
|
||||
for _ in 0..3 {
|
||||
let allocation =
|
||||
make_allocation(core, MemoryClass::Shared, 64 << 20).expect("an allocation");
|
||||
let info = vk::BufferCreateInfo::default()
|
||||
.size(256)
|
||||
.usage(crate::floor::BUFFER_USAGE)
|
||||
.sharing_mode(vk::SharingMode::EXCLUSIVE);
|
||||
// SAFETY: the device is live; the buffer is bound once, to memory of its usage's
|
||||
// type, and destroyed once the fill that uses it completed.
|
||||
let used = unsafe {
|
||||
let used = core.device.create_buffer(&info, None).expect("a buffer");
|
||||
(core.device)
|
||||
.bind_buffer_memory(used, allocation.memory, 0)
|
||||
.expect("its memory");
|
||||
used
|
||||
};
|
||||
commit(used);
|
||||
// SAFETY: the fill that used it completed.
|
||||
unsafe { core.device.destroy_buffer(used, None) };
|
||||
let (freed, completed) = thread::scope(|scope| {
|
||||
let committed = scope.spawn(|| {
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
commit(to)
|
||||
});
|
||||
let started = Instant::now();
|
||||
free_allocation(core, allocation);
|
||||
let freed = started.elapsed();
|
||||
(freed, committed.join().expect("the commit"))
|
||||
});
|
||||
println!(
|
||||
"{name}: a 64 MiB Shared free took {freed:?}; a commit 1 ms into it completed \
|
||||
in {completed:?}"
|
||||
);
|
||||
if freed >= Duration::from_millis(10) {
|
||||
assert!(
|
||||
completed < freed / 2,
|
||||
"{name}: the commit waited for the free: {completed:?} of {freed:?}"
|
||||
);
|
||||
}
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
drop((kept, target, queue));
|
||||
});
|
||||
}
|
||||
|
||||
/// Idle allocations are freed only in quiet gaps, and a submission during a free is counted.
|
||||
/// Four Shared blocks of 16 MiB are given back while command buffers are committed every
|
||||
/// 2 ms; the clock moves past the window, so the idle rule frees all four but the reserve, yet
|
||||
|
||||
Reference in new issue
Block a user