diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs index 2635dca21..2ef0b08ff 100644 --- a/crates/metal2vulkan-runtime/src/memory.rs +++ b/crates/metal2vulkan-runtime/src/memory.rs @@ -857,6 +857,11 @@ pub(super) struct Pool { /// The pooled blocks added and freed so far ([`Pool::turnover`]). made: u64, freed: u64, + /// Their bytes, for the crate's device tests ([`Pool::turnover_bytes`]). + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + made_bytes: u64, + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + freed_bytes: u64, /// The bytes of its live blocks with nothing placed in them: the empty blocks it keeps /// ([`Pool::kept_bytes`]). kept_bytes: u64, @@ -912,6 +917,10 @@ impl Default for Pool { visited: 0, made: 0, freed: 0, + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + made_bytes: 0, + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + freed_bytes: 0, kept_bytes: 0, grew: None, large: None, @@ -1041,6 +1050,10 @@ impl Pool { placed_to: used, }); self.made += u64::from(!dedicated); + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + { + self.made_bytes += if dedicated { 0 } else { size }; + } if used == 0 { self.kept_bytes += size; } @@ -1236,6 +1249,10 @@ impl Pool { fn take(&mut self, index: usize) -> Option { let block = self.blocks.get_mut(index)?.take()?; self.freed += u64::from(!block.dedicated); + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + { + self.freed_bytes += if block.dedicated { 0 } else { block.size }; + } if block.empty() { self.kept_bytes -= block.size; } @@ -1248,6 +1265,12 @@ impl Pool { (self.made, self.freed) } + /// The bytes of the pooled blocks added and freed so far, for the crate's device tests. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(super) fn turnover_bytes(&self) -> (u64, u64) { + (self.made_bytes, self.freed_bytes) + } + /// When it last grew: a pooled block was added to it while it held another, at `now` where /// `adding` names one being added. Blocks made ahead are made for a pool that grew, and for /// one near its next block ([`Pool::near_next`], `memory/ready.rs`). @@ -2002,6 +2025,9 @@ pub(super) struct Memory { /// bytes, since a test last cleared it ([`AheadBlocks::made_in_place`]). #[cfg(test)] pub(crate) in_place_bytes: std::collections::BTreeMap, + /// The bytes of the blocks made ahead and freed unused ([`AheadBlocks::unused`]). + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + unused_bytes: u64, /// Blocks of images are allocated with `VK_MEMORY_ALLOCATE_ZERO_INITIALIZE_BIT_EXT` /// ([`Memory::zero_image_blocks`]). zero_images: bool, @@ -2191,6 +2217,8 @@ impl Memory { longest_making: Duration::ZERO, #[cfg(test)] in_place_bytes: std::collections::BTreeMap::new(), + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + unused_bytes: 0, } } @@ -3315,6 +3343,10 @@ impl Memory { } for block in self.readying.swap_remove(at).stop() { self.ahead.unused += 1; + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + { + self.unused_bytes += block.size; + } // SAFETY: nothing was placed in the block, and no command reads it. drop(unsafe { self.let_go(device, block, FreeCause::KeptStale, None) }); } @@ -3356,6 +3388,18 @@ impl Memory { }) } + /// The bytes of [`Memory::turnover`]'s blocks, and of those of them made ahead and freed + /// unused, for the crate's device tests. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn turnover_bytes(&self) -> (u64, u64, u64) { + let unused = self.unused_bytes; + let (made, freed) = (self.pools.iter().map(Pool::turnover_bytes)) + .fold((unused, unused), |(made, freed), (m, f)| { + (made + m, freed + f) + }); + (made, freed, unused) + } + /// Free `block`, or where the device parks freed memory (`freed_memory.rs`), destroy its /// buffer of addresses and let its memory wait, with `after`, for the batches submitted /// before now, unless they completed. `after`, given back where the memory was freed here. diff --git a/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs b/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs index aa5d6b935..055c77ac5 100644 --- a/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs +++ b/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs @@ -595,11 +595,12 @@ fn phase( (length, making): (Duration, Making), made: &mut Made, ) { - { + let bytes_before = { let mut memory = crate::device::lock(&device.shared().memory); memory.longest_making = Duration::ZERO; memory.in_place_bytes.clear(); - } + memory.turnover_bytes() + }; let before = (vmstat(), device.work_counts()); let stop = AtomicBool::new(false); let (submits, turnarounds, makes) = std::thread::scope(|scope| { @@ -619,12 +620,16 @@ fn phase( (submits, turnarounds, maker.join().unwrap()) }); let after = (vmstat(), device.work_counts()); - let (longest, in_place) = { + let (longest, in_place, bytes_after) = { let memory = crate::device::lock(&device.shared().memory); let sizes: Vec = (memory.in_place_bytes.iter()) .map(|(bytes, count)| format!("{count} of {} MiB", bytes >> 20)) .collect(); - (memory.longest_making, sizes.join(", ")) + ( + memory.longest_making, + sizes.join(", "), + memory.turnover_bytes(), + ) }; let over = |times: &[(Duration, f64)], bound: f64| { (times.iter()) @@ -682,6 +687,21 @@ fn phase( counts.empty_memory_blocks_live, meminfo("MemAvailable") >> 20, ); + let (frees, earlier_frees) = (&counts.memory_frees, &earlier.memory_frees); + eprintln!( + "RECLAIM-SUBMIT {arm}, {name}: churn: pooled blocks made {} ({} MiB), freed {} ({} MiB); \ + of them made ahead and freed unused {} ({} MiB); pooled frees emptied {}, stale {}, \ + for room {}", + counts.pooled_memory_blocks_made - earlier.pooled_memory_blocks_made, + (bytes_after.0 - bytes_before.0) >> 20, + counts.pooled_memory_blocks_freed - earlier.pooled_memory_blocks_freed, + (bytes_after.1 - bytes_before.1) >> 20, + counts.blocks_ahead_unused - earlier.blocks_ahead_unused, + (bytes_after.2 - bytes_before.2) >> 20, + frees.pooled_emptied - earlier_frees.pooled_emptied, + frees.kept_stale - earlier_frees.kept_stale, + frees.kept_for_room - earlier_frees.kept_for_room, + ); eprintln!("RECLAIM-SUBMIT {arm}, {name}: slowest submissions {slow}"); eprintln!("RECLAIM-SUBMIT {arm}, {name}: slowest turnarounds {slow_turns}"); eprintln!("RECLAIM-SUBMIT {arm}, {name}: slowest makings {slow_makes}");