Blocks made ahead: the reserve counted in bytes with the pool's room, made again at large placements
The trigger of a pool's blocks made ahead skipped the pool while it had room for a whole block (`ready_if_growing`'s `has_room(bytes)`). A call that takes a block from the reserve leaves the pool a whole block of room and none made ahead, so nothing was made again until a later creation call found the pool short of a whole block; by then the placements had taken the room, and the next call that needed a block waited for a making it started itself. On an RX 550 (64 MiB blocks, textures of 4, 14.1 and 31.6 MiB one at a time, every making ended between two) the call after each 31.6 MiB texture waited so, at textures 8, 16 and 24 of 32 (job 12539, `tests::blocks_ahead::mixed_sizes_find_their_blocks_made_ahead`, with made-ahead empty from texture 6 on). On a Radeon 780M the bench's mixed arm waited for 8 and 6 of its blocks with none hurried (job 12513). - The reserve counts its own blocks in bytes together with the pool's room (`Memory::lacking`, the longest free range, `Pool::room`): none lacks while those made ahead and the room come to their worth (a block's worth, as before), and once they come to less, as many as bring those made ahead back to it. The trigger no longer skips a pool with room for a whole block: a pool that grew or is near its next block keeps what it lacks. The large block's rule is unchanged. - A placement of a quarter of a block or more in a pool whose blocks are made ahead runs that trigger there and then (`ready_after_placing`, in `place`), not at the next creation call, which may need the block at once: a quarter of a block is the lead `ahead_room` gives the next block's making before the half block `keep_room` keeps, so such a placement can use it up in one step. (A threshold of half a block would miss the 31.6 MiB texture, just under half of 64 MiB, and pooled placements are at most half a block.) Room is cached (`Pool::room`), so the check derives it where the next creation call would have. - A call whose waited making ended without its block waits once more, on a making that counts it from its start (`take_ready`), before it makes the block itself. A thread ends so without a failure: a reserve making no call waited for as it began makes no block within the device's allocation margin (`Allocations::room_ahead`), and its ending drops the sizes queued behind it, the waiting call's among them. This is the hole the M3 cost records' selection-only image and buffer blocks made in place point to (not measured here). Measured on a Radeon 780M (RADV PHOENIX, gem10, exclusive; job 12560, two runs each, the reclaim bench's images arms; RT 1991 is development with the ready threads' rename): - Mixed sizes, 64 MiB blocks: blocks waited for, quiet and pressed, RT 1991 8 and 6 in both runs (none hurried), with this change 0 and 0 in both. Slowest creation call in the pressed phase 8.5 and 5.8 ms at RT 1991, 3.6 and 1.9 ms with it (RT 1987: 5.2 and 1.5 ms, with 8 and 6 blocks of images made in place, none since). Blocks made, 13 and 14 a phase, unchanged. - Bursts of 16 textures, 16 MiB blocks: waited for, quiet 24 and 25 at RT 1991, 20 and 21 with it; pressed 27 and 27, then 23 and 23; hurried 11 to 12 at both (RT 1987: 60 a phase). - Images one a frame and mixed sizes on 16 MiB blocks, and the 64 MiB images and bursts arms: no wait at either, none in place, the same blocks made. On an RX 550 the mixed-sizes test waited at textures 8, 16 and 24 without this change and at none with it (job 12556); lavapipe, whose slow makings made its blocks 16 MiB, waits only at texture 7, the first texture larger than its blocks. The mixed-sizes test allows the one wait it should: where a device's slow makings made its blocks of images smaller (lavapipe, 16 MiB), the first texture larger than them waits for a block of its own size, which nothing foretold. Work counts expected to move: blocks_ahead_waited_for down (the mixed and burst arms' waits on makings started late become blocks made ahead and found ready); image/buffer_blocks_made_ahead about the same in total, with makings started earlier; blocks_ahead_hurried down where those makings would have been cut short; image/buffer_blocks_made_in_place down to 0 in the M3 selection where the room_ahead ending was the cause (expected, unmeasured). The bytes kept ahead are bounded as before: a block's worth a pool, plus the large block. (cherry picked from commit 384c96121f7fa1ff8dec80ccfbf98f401ab77a74)
This commit is contained in:
1 parent
42fc02883a
commit
40831926fd
4 files changed
+90
-27
No files matched your search
@@ -2669,7 +2669,13 @@ impl Memory {
|
||||
|
||||
/// Of the blocks `pool`, its blocks of `bytes`, keeps made ahead ([`ahead_sizes`]), those
|
||||
/// `held` lacks (the bytes of each block made, being made and still to make): the larger
|
||||
/// first.
|
||||
/// first. Its own blocks are counted in bytes together with its room ([`Pool::room`]): none
|
||||
/// lacks while those held and its room come to their worth ([`ahead_sizes`]'s count of
|
||||
/// them) or more, and once they come to less, as many as bring those held to that worth. So a
|
||||
/// block just taken from them, which leaves the pool a whole block of room, is made again
|
||||
/// as soon as a placement takes any of that room, not only once the pool lacks room for a
|
||||
/// whole block: the room left then is less than the next creation calls' placements may
|
||||
/// take before the making ends (a 31.6 MiB texture after a 64 MiB block was taken).
|
||||
///
|
||||
/// [`ahead_sizes`]: Self::ahead_sizes
|
||||
fn lacking(&mut self, pool: (Holds, u32), bytes: u64, held: &[u64]) -> Vec<u64> {
|
||||
@@ -2683,8 +2689,11 @@ impl Memory {
|
||||
// Its own blocks: those below its large placements' bytes, which those leave to them.
|
||||
let below = large.unwrap_or(u64::MAX);
|
||||
let have: u64 = held.iter().filter(|&&size| size < below).sum();
|
||||
let more = (count * bytes).saturating_sub(have) / bytes.max(1);
|
||||
lacking.extend((0..more).map(|_| bytes));
|
||||
let worth = count * bytes;
|
||||
if self.pool(pool.0, pool.1).room().saturating_add(have) < worth {
|
||||
let more = worth.saturating_sub(have) / bytes.max(1);
|
||||
lacking.extend((0..more).map(|_| bytes));
|
||||
}
|
||||
lacking
|
||||
}
|
||||
|
||||
@@ -4617,6 +4626,7 @@ fn place(
|
||||
if let Some(placement) =
|
||||
guard.place_pooled(device, pool, (size, align), addressed, class)?
|
||||
{
|
||||
ready_after_placing(&mut guard, pool, size);
|
||||
return Ok(guard.mark_overflowed(placement, overflowing));
|
||||
}
|
||||
// A dedicated placement takes a kept dedicated block its size fits.
|
||||
@@ -4651,6 +4661,7 @@ fn place(
|
||||
if let Some(placement) =
|
||||
guard.place_pooled(device, pool, (size, align), addressed, class)?
|
||||
{
|
||||
ready_after_placing(&mut guard, pool, size);
|
||||
return Ok(guard.mark_overflowed(placement, overflowing));
|
||||
}
|
||||
}
|
||||
@@ -4734,9 +4745,11 @@ pub(super) fn keep_none(memory: &Mutex<Memory>, device: &ash::Device) {
|
||||
/// (`memory/ready.rs`); only where that making fails or no thread starts is the block made here. A block of buffers gets
|
||||
/// its buffer of addresses (counted in `counts`) where blocks carry one. A block that fails to be
|
||||
/// made, or a pool the query fails for, is left to the placement that needs it. A pool that grew
|
||||
/// within [`KEPT_EMPTY_FOR`] and lacks room for a whole block gets the blocks it lacks of a block's
|
||||
/// worth made ahead ([`Memory::keep_ahead`]), through `functions`, made once a burst of `quiet`'s
|
||||
/// queue uses ended; so does each pool of exportable buffers that grew so
|
||||
/// within [`KEPT_EMPTY_FOR`], or is near its next block, gets the blocks it lacks of a block's
|
||||
/// worth made ahead, counted in bytes with its room ([`Memory::lacking`], [`Memory::keep_ahead`]),
|
||||
/// through `functions`, made once a burst of `quiet`'s queue uses ended (as it does after a
|
||||
/// placement of a quarter of a block or more there, [`place`]); so does each pool of exportable
|
||||
/// buffers that grew so
|
||||
/// (`allocate_exported`), whose room is otherwise left to its placements, which are the creation
|
||||
/// calls themselves. The pool host copies place in, where `copies` says the device
|
||||
/// copies color textures on the host, gets its blocks made ahead once it lacks room for half a
|
||||
@@ -4850,19 +4863,31 @@ pub(super) fn ahead_room(bytes: u64) -> u64 {
|
||||
|
||||
/// Keep `pool`'s blocks made ahead (`memory/ready.rs`, [`Memory::keep_ahead`]), made once a burst
|
||||
/// of the device's queue uses ended, with a buffer of addresses where its blocks carry one, where
|
||||
/// the pool grew within [`KEPT_EMPTY_FOR`] lacking room for a whole block, or, grown or not, is
|
||||
/// near its next block ([`Pool::near_next`]).
|
||||
/// the pool grew within [`KEPT_EMPTY_FOR`], or, grown or not, is near its next block
|
||||
/// ([`Pool::near_next`]): those it lacks, its own blocks counted in bytes with its room
|
||||
/// ([`Memory::lacking`]).
|
||||
fn ready_if_growing(memory: &mut Memory, pool: (Holds, u32)) {
|
||||
let bytes = memory.pooled_bytes(pool);
|
||||
let pool_of = memory.pool(pool.0, pool.1);
|
||||
let grew = (pool_of.grew(None)).is_some_and(|at| at.elapsed() < KEPT_EMPTY_FOR);
|
||||
let near = pool_of.near_next(bytes);
|
||||
if !(grew || near) || pool_of.has_room(bytes) {
|
||||
if !grew && !pool_of.near_next(bytes) {
|
||||
return;
|
||||
}
|
||||
memory.keep_ahead(pool, bytes);
|
||||
}
|
||||
|
||||
/// After a placement of `size` bytes in `pool`'s blocks ([`place`]): where the pool's blocks are
|
||||
/// made ahead and the placement took a quarter of a block or more, the room [`ahead_room`] leaves
|
||||
/// the pool's next block's making before [`keep_room`]'s half block, those it lacks are kept
|
||||
/// there and then ([`ready_if_growing`]), not at the next creation call's [`keep_room`], which
|
||||
/// may need the block at once. A smaller placement leaves that to the next creation call.
|
||||
fn ready_after_placing(memory: &mut Memory, pool: (Holds, u32), size: u64) {
|
||||
let bytes = memory.pooled_bytes(pool);
|
||||
if size >= bytes - ahead_room(bytes) && memory.makes_ahead(pool) {
|
||||
ready_if_growing(memory, pool);
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep blocks made ahead for the pool host copies place in (`memory/ready.rs`,
|
||||
/// [`Memory::host_copy_pool`], where `copies`, asked with `memory`'s lock released until the pool
|
||||
/// was found, says the device copies color textures on the host; [`Memory::keep_ahead`]), made
|
||||
@@ -4883,14 +4908,20 @@ fn ready_ahead(memory: &Mutex<Memory>, device: &ash::Device, copies: impl FnOnce
|
||||
/// Add a block of `need` bytes or more made ahead for `pool` to it, `guard` held on `memory`
|
||||
/// (`memory/ready.rs`): at once where one is made; else once one is, waited for with the lock
|
||||
/// released ([`Memory::wait_for`]), and waited for again where another call took the block made
|
||||
/// meanwhile. Whether one was added: not where no making serves the call, or the one waited for
|
||||
/// failed. The lock is released as it returns.
|
||||
/// meanwhile, or where the pool's thread ended without one. A thread ends so without a failure:
|
||||
/// a making no call waited for as it began makes no block within the margin of the device's
|
||||
/// allocations (`allocations.rs`'s `Allocations::room_ahead`), and its ending drops the sizes
|
||||
/// queued behind it, the call's among them; the second wait is on a making the call waits for
|
||||
/// from its start, which makes its block. Whether one was added: not where no making serves the
|
||||
/// call, or the makings of both waits ended without its block. The lock is released as it
|
||||
/// returns.
|
||||
fn take_ready<'a>(
|
||||
memory: &'a Mutex<Memory>,
|
||||
mut guard: MutexGuard<'a, Memory>,
|
||||
pool: (Holds, u32),
|
||||
need: u64,
|
||||
) -> bool {
|
||||
let mut ended_without = false;
|
||||
loop {
|
||||
if guard.add_ready(pool, need) {
|
||||
return true;
|
||||
@@ -4903,7 +4934,10 @@ fn take_ready<'a>(
|
||||
let made = waiter.wait();
|
||||
guard = lock(memory);
|
||||
if !made {
|
||||
return guard.add_ready(pool, need);
|
||||
if ended_without {
|
||||
return guard.add_ready(pool, need);
|
||||
}
|
||||
ended_without = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@
|
||||
//!
|
||||
//! - **Ahead.** `memory::keep_room`, which the device's creation calls run, starts a making for a
|
||||
//! pool the encodings and commits place in once the pool grew (a second or later pooled block
|
||||
//! was added to it within `KEPT_EMPTY_FOR`) and lacks room for a whole block, so that a growth
|
||||
//! was added to it within `KEPT_EMPTY_FOR`), so that a growth
|
||||
//! like a guest's scroll on the 780M (from 20 to 63 live blocks of 64 MiB in about 20 s, about 4
|
||||
//! a second) finds a block made when it needs one; and, grown or not, once the pool is near its
|
||||
//! next block (`Pool::near_next`: it holds a pooled block and lacks room for three quarters of
|
||||
@@ -49,8 +49,17 @@
|
||||
//! its own size (`memory::pooled_block_bytes`), one block of the largest such size besides
|
||||
//! them, which a call that needs one of the pool's own blocks leaves to those placements, so
|
||||
//! that a burst of textures that outruns the makings of the pool's own blocks does not take it
|
||||
//! (`tests::blocks_ahead`). They are made one after another once a burst ended; those it lacks are queued after the blocks its thread still makes, or made on a
|
||||
//! new thread where that ended. So each making stays as short as its block, and the pool's growth
|
||||
//! (`tests::blocks_ahead`). Its own blocks are counted in bytes with its room
|
||||
//! (`Memory::lacking`): it lacks them once those made ahead and the longest free range of its
|
||||
//! blocks come to less than their worth, and then as many as bring those made ahead to it. So
|
||||
//! the block a call just took, which leaves a whole block of room, is made again as soon as a
|
||||
//! placement takes any of that room, not once the pool lacks room for a whole block: on an RX 550
|
||||
//! a 31.6 MiB texture placed in a 64 MiB block just taken left less than the half block the next
|
||||
//! creation call keeps, and that call waited for a making it started itself
|
||||
//! (`tests::blocks_ahead`'s mixed sizes, at textures 8, 16 and 24 of 32). A placement of a
|
||||
//! quarter of a block or more starts the making there and then (`memory::place`), not at the
|
||||
//! next creation call. They are made one after another once a burst ended; those it lacks are
|
||||
//! queued after the blocks its thread still makes, or made on a new thread where that ended. So each making stays as short as its block, and the pool's growth
|
||||
//! still finds its blocks made: with one block of 16 MiB ahead at a time, a guest's scroll on a
|
||||
//! Radeon 780M whose blocks were made so made 82 to 114 blocks of images on its own threads and
|
||||
//! waited for 110 to 159 of those made ahead. It keeps them for as long as it stays near its
|
||||
@@ -79,7 +88,10 @@
|
||||
//! the thread looks for a waiting call after it says it reads and before each run of reads. A
|
||||
//! call makes its own block (`WorkCounts::buffer_blocks_made_in_place`,
|
||||
//! `image_blocks_made_in_place`) only where no making serves it: a placement in the host copies'
|
||||
//! pool while its thread reads; a call whose making failed, or whose host starts no thread; and
|
||||
//! pool while its thread reads; a call whose makings failed twice (a making that ended without
|
||||
//! its block, as one no call waited for as it began does within the allocation margin below,
|
||||
//! dropping the sizes queued behind it, is waited for once more on a making the call waits for
|
||||
//! from its start), or whose host starts no thread; and
|
||||
//! a placement before the device's first creation call, which gives the makings the device's
|
||||
//! functions and queues. A pool's blocks change only at those calls, never as a making here
|
||||
//! ends.
|
||||
|
||||
@@ -405,22 +405,32 @@ const MIXED_ROUNDS: usize = 4;
|
||||
|
||||
/// A pool of 64 MiB blocks whose placements take up to half a block each keeps its next block
|
||||
/// made ahead of the call that needs it: after the pool's first block, no creation call waits for
|
||||
/// a block of images, and none makes one. On a Radeon 780M, `tests::reclaim_submit_bench`'s mixed
|
||||
/// arm waited for 8 of its 13 blocks of images in its quiet phase, each making started only as
|
||||
/// the call needed it.
|
||||
/// a block of images, and none makes one. On an RX 550 the calls after a 31.6 MiB texture waited
|
||||
/// for a making they started themselves (textures 8, 16 and 24) while the pool's blocks made
|
||||
/// ahead were counted by whole blocks of room, and on a Radeon 780M
|
||||
/// `tests::reclaim_submit_bench`'s mixed arm waited for 8 of its 13 blocks of images in its quiet
|
||||
/// phase. Where the device's makings were slow and its blocks of images were made smaller
|
||||
/// (`Memory::plain_block_made`, lavapipe), the first texture larger than them waits for its
|
||||
/// block of its own size, which nothing foretold
|
||||
/// (`placements_past_a_pool_s_small_blocks_find_a_block_of_their_size_made_ahead`); no other.
|
||||
#[test]
|
||||
fn mixed_sizes_find_their_blocks_made_ahead() {
|
||||
let scratch = Scratch::new("mixed");
|
||||
let device = device(&scratch.0);
|
||||
let shared = device.shared();
|
||||
let ahead = || crate::device::lock(&shared.memory).ahead_blocks();
|
||||
let plain = || crate::device::lock(&shared.memory).plain_block_bytes();
|
||||
let mut held: Vec<Texture> = Vec::new();
|
||||
texture(&device, MIXED_SIDES[0], &mut held);
|
||||
let start = ahead();
|
||||
let mut waits = Vec::new();
|
||||
let (mut waits, mut first_large) = (Vec::new(), None);
|
||||
for at in 1..MIXED_SIDES.len() * MIXED_ROUNDS {
|
||||
let (width, height) = MIXED_SIDES[at % MIXED_SIDES.len()];
|
||||
if first_large.is_none() && width * height * 4 > plain() {
|
||||
first_large = Some(at);
|
||||
}
|
||||
let before = ahead().images_waited_for;
|
||||
texture(&device, MIXED_SIDES[at % MIXED_SIDES.len()], &mut held);
|
||||
texture(&device, (width, height), &mut held);
|
||||
let after = ahead();
|
||||
if after.images_waited_for > before {
|
||||
waits.push(at);
|
||||
@@ -445,10 +455,11 @@ fn mixed_sizes_find_their_blocks_made_ahead() {
|
||||
(end.images_ahead + end.images_in_place) - (start.images_ahead + start.images_in_place);
|
||||
println!(
|
||||
"BLOCKS-AHEAD {}: {} textures of mixed sizes in blocks of {} MiB; after the first, {blocks} \
|
||||
blocks of images, {} made ahead, {} waited for (at textures {waits:?}), {} in place",
|
||||
blocks of images, {} made ahead, {} waited for (at textures {waits:?}; the first larger \
|
||||
than the blocks {first_large:?}), {} in place",
|
||||
device.name(),
|
||||
held.len(),
|
||||
crate::device::lock(&shared.memory).plain_block_bytes() >> 20,
|
||||
plain() >> 20,
|
||||
end.images_ahead - start.images_ahead,
|
||||
end.images_waited_for - start.images_waited_for,
|
||||
end.images_in_place - start.images_in_place,
|
||||
@@ -457,9 +468,12 @@ fn mixed_sizes_find_their_blocks_made_ahead() {
|
||||
end.images_in_place, start.images_in_place,
|
||||
"a creation call made a block of images itself"
|
||||
);
|
||||
let unforetold: Vec<usize> = (waits.iter().copied())
|
||||
.filter(|&at| Some(at) != first_large)
|
||||
.collect();
|
||||
assert!(
|
||||
waits.is_empty(),
|
||||
"creation calls waited for a block of images at textures {waits:?}"
|
||||
unforetold.is_empty(),
|
||||
"creation calls waited for a block of images at textures {unforetold:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -992,7 +992,10 @@ driver's. Each is open work.
|
||||
a block's worth of bytes made ahead (`memory/ready.rs`; the pools of exportable buffers, which
|
||||
hold the pictures, among them): as many of its blocks as one 64 MiB block holds, and while its
|
||||
placements larger than a plain pool's smaller blocks are recent, one block of their size
|
||||
besides, one `vkAllocateMemory` each, right after a burst of the device's submissions ended. A
|
||||
besides, one `vkAllocateMemory` each, right after a burst of the device's submissions ended.
|
||||
Its own blocks are counted in bytes with its free room: they are made again once those made
|
||||
ahead and its room come to less than a block's worth, a placement of a quarter of a block or
|
||||
more starting their making at once rather than at the next creation call. A
|
||||
creation call that needs one while its making still waits for that end makes it at once and
|
||||
waits for it, as for a block made in place, and one that finds none of its size made waits for
|
||||
the ready thread to make it first. A pool near its next block keeps those blocks at rest for as
|
||||
|
||||
Reference in new issue
Block a user