From acfb2e8d70ecc4da1b92ab040ede2107d8c57d2c Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 10 Nov 2026 04:27:31 -0800 Subject: [PATCH] Host RAM test: the room at the limit counts the runtime's own pooled blocks made meanwhile an_allocation_at_the_limit_waits_for_the_untaken_chunks_to_go_back failed on the M3 Max under MoltenVK (4/4 in full runtime gpucfg suites at 81d7268023; m3-max-13593 at e72579a8b7): 2 buffers made of a room of 3, the next refused at the limit. The M3 runs (m3-max-13619, alone 3/3 and in the suite, with the work counts printed around the window) show the give-back itself did its work: all 3 untaken chunks went back before the first allocation's retry (host_imports_live 4 -> 2, host_ram_chunks_live 2, one wait for the give-back), and the live count then stayed at the limit for 2.5 s after the refusal, so no free lagged. The third allocation of the room went to the device's first pooled block, a block of buffers made ahead that a placement waited for, made once the give-back left room past the margin (pooled_memory_blocks_made 0 -> 1, buffer_blocks_made_ahead 0 -> 1, blocks_ahead_waited_for 0 -> 1, memory_blocks_live 0 -> 1). allocations.rs's room_ahead lets the runtime's own work take that room by design; lavapipe makes no block in this window. So the test's arithmetic assumed lavapipe's order, not a path the fix misses. The test now counts the runtime's pooled blocks live at the refusal that were not live before the object (memory_blocks_live + empty_memory_blocks_live) with the objects' buffers against the room, prints them, and keeps every other assertion: the untaken chunks went back, only the objects' chunks were live at the refusal, an allocation waited for the give-back, and the refusal came at the limit. Verified: the next potluck jobs (M3 alone and in the suite, a control with the give-back wait removed, lavapipe). (cherry picked from commit 75de915a59ff3a3a6d3eb74eeb3d374e1388ae1b) --- .../src/tests/host_ram_device.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/host_ram_device.rs b/crates/metal2vulkan-runtime/src/tests/host_ram_device.rs index a45f70a0e..c76ea2b4c 100644 --- a/crates/metal2vulkan-runtime/src/tests/host_ram_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/host_ram_device.rs @@ -771,7 +771,10 @@ fn the_ahead_thread_leaves_the_allocation_limit_to_the_objects() { /// before those chunks went: the allocation that finds the limit waits for that give-back, and /// is made, rather than refused while chunks no object took hold the device's allocations /// (`allocations.rs`). The objects have the whole rest of the limit, as Metal, which holds no -/// such chunks, would give them. +/// such chunks, would give them, but for the blocks of the runtime's own pools made meanwhile +/// (`Allocations::room_ahead` leaves the runtime's work the room past the margin): on the M3 Max +/// under MoltenVK a pool of buffers makes the device's first pooled block in that room, once the +/// chunks went (a block made ahead that a placement waited for), where lavapipe makes none here. #[test] fn an_allocation_at_the_limit_waits_for_the_untaken_chunks_to_go_back() { const GIVE_BACK_HELD: Duration = Duration::from_millis(500); @@ -784,6 +787,7 @@ fn an_allocation_at_the_limit_waits_for_the_untaken_chunks_to_go_back() { allocations.hold_give_backs(GIVE_BACK_HELD); let waits = allocations.give_back_waits(); let begun = Instant::now(); + let start = device.work_counts(); let object = at.object_past(&device); // At once: the room the margin left, and the untaken chunks' once they went back. let untaken = u64::from(AHEAD) - 1; @@ -791,10 +795,15 @@ fn an_allocation_at_the_limit_waits_for_the_untaken_chunks_to_go_back() { let (made, refused) = dedicated_until_refused(&device, limit, at.page); let took = begun.elapsed(); let full = device.work_counts(); + // The runtime's pooled blocks live at the refusal that were not before the object. + let pooled = + |counts: &crate::WorkCounts| counts.memory_blocks_live + counts.empty_memory_blocks_live; + let own = pooled(&full).saturating_sub(pooled(&start)); eprintln!( "HOST-RAM: a limit of {limit}: the give-back held {GIVE_BACK_HELD:?}; {} buffers of \ - blocks of their own made at once of a room of {room} in {took:?}, the next refused \ - ({refused:?}); {} chunks given back, {} live then; {} waits for the give-back", + blocks of their own made at once of a room of {room} in {took:?}, beside {own} block(s) \ + of the runtime's pools, the next refused ({refused:?}); {} chunks given back, {} live \ + then; {} waits for the give-back", made.len(), at.given(&full), at.chunks_live(&full), @@ -807,7 +816,7 @@ fn an_allocation_at_the_limit_waits_for_the_untaken_chunks_to_go_back() { ); assert_eq!(at.given(&full), untaken, "the untaken chunks went back"); assert!( - made.len() >= room as usize, + made.len() as u64 + own >= u64::from(room), "the objects lacked part of the rest of the limit ({refused:?})" ); assert!(