Snapshot memory, host lists and send memory kept for reuse (VICTORY_SNAPSHOT_POOL=8: as before)

Made anew and given back all the time: 30 % of the submitting thread in the opening (profile cpu-1: allocations of snapshots 11, preludes 12, lists dropped 5, send memory 3).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 03:50:04 -06:00
1 parent 74005234a2
commit d4943c43fb
3 files changed
+40 -17

No files matched your search

+3 -1
View File
@@ -129,7 +129,9 @@ fn memory(host: &Host, size: u64) -> Option<Memory> {
return Some(spare.swap_remove(i));
}
}
let size = size.next_multiple_of(8 << 20);
// By doubles, so that the next of about this size finds it: what
// submissions send differs from frame to frame.
let size = size.max(8 << 20).next_power_of_two();
let (buffer, data) = host.upload_buffer(size)?;
name(&buffer, || "bytes a submission sends up".into());
Some(Memory {
+5 -2
View File
@@ -218,11 +218,14 @@ unsafe impl Send for Idle {}
#[cfg(windows)]
static IDLE: std::sync::Mutex<(Vec<Idle>, u64)> = std::sync::Mutex::new((Vec::new(), 0));
/// The most host lists kept idle, and the most upload memory they may keep
/// The most host lists kept idle (128 were too few: flights land several at
/// a time, so lists were thrown away and others made in the same frame, with
/// their preludes and buffers, 12 % of the submitting thread in the opening,
/// profile cpu-1), and the most upload memory they may keep
/// between them (a list keeps scratch chunks over a reset only while lists
/// do not share them, `VICTORY_SCRATCH_POOL=0`).
#[cfg(windows)]
const IDLE_MOST: (usize, u64) = (128, 256 << 20);
const IDLE_MOST: (usize, u64) = (512, 256 << 20);
/// Whether host lists that have run are used again (on by default;
/// `VICTORY_LIST_POOL=0`: each is made new and thrown away, as before).
+32 -14
View File
@@ -1197,20 +1197,40 @@ fn pooled(n: usize) -> Vec<u8> {
v
}
/// Returns a snapshot buffer to the pool: at most 8 kept, the largest, and
/// of those the largest one and the next ones up to `KEPT` bytes in all.
/// How many snapshot buffers are kept (`VICTORY_SNAPSHOT_POOL`; `8`: as
/// before).
///
/// A frame gives some 330 ranges of copies in the PC's memory to shaders, and
/// most are of copies of their own; with two or three frames in the air eight
/// buffers were the eight largest, and every other snapshot was memory fresh
/// from the kernel and given back to it: 11 % of the submitting thread in the
/// opening (profile cpu-1: `NtAllocateVirtualMemory` under
/// [`Shadow::writing`]), and the page faults of filling it.
fn snapshots_kept() -> usize {
static MOST: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
*MOST.get_or_init(|| std::env::var("VICTORY_SNAPSHOT_POOL").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(1024))
}
/// Returns a snapshot buffer to the pool: at most [`snapshots_kept`] kept,
/// the largest, and of those the largest one and the next ones up to `KEPT`
/// bytes in all.
fn give_back(v: Vec<u8>) {
const KEPT: usize = 512 << 20;
let mut pool = POOL.lock().unwrap_or_else(|e| e.into_inner());
pool.push(v);
pool.sort_by_key(|v| std::cmp::Reverse(v.capacity()));
pool.truncate(8);
let (mut seen, mut total) = (0, 0usize);
pool.retain(|v| {
seen += 1;
let (mut kept, mut total) = (0, 0usize);
for v in pool.iter().take(snapshots_kept()) {
total = total.saturating_add(v.capacity());
seen == 1 || total <= KEPT
});
if kept > 0 && total > KEPT {
break;
}
kept += 1;
}
// (Given back to the kernel without the lock: milliseconds.)
let gone = pool.split_off(kept);
drop(pool);
drop(gone);
}
const NOT_WATCHED: u8 = 2;
@@ -3207,14 +3227,14 @@ impl Shadow {
note_stale(2);
return true;
}
*runs_left -= runs.len();
*runs_left -= copies;
let was = (!runs.is_empty() && crate::host::upcheck::on()).then(|| held.to_vec());
for (r, m) in runs {
for &(r, m) in &runs {
held[r..r + m].copy_from_slice(&title[r..r + m]);
self.card_changed(at + r, at + r + m);
MERGED[1].fetch_add(1, Ordering::Relaxed);
MERGED[2].fetch_add(m as u64, Ordering::Relaxed);
}
MERGED[1].fetch_add(runs.len() as u64, Ordering::Relaxed);
self.card_changed_runs(runs.into_iter().map(|(r, m)| (at + r, at + r + m)));
if let Some(was) = was {
crate::host::upcheck::note(self.id, at, &was, held);
}
@@ -3233,8 +3253,6 @@ impl Shadow {
// written here and nothing around them.
unsafe { std::ptr::copy_nonoverlapping(title.as_ptr().add(r), self.data.add(at + r), m) };
held[r..r + m].copy_from_slice(&title[r..r + m]);
MERGED[1].fetch_add(runs.len() as u64, Ordering::Relaxed);
self.card_changed_runs(runs.into_iter().map(|(r, m)| (at + r, at + r + m)));
MERGED[1].fetch_add(1, Ordering::Relaxed);
MERGED[2].fetch_add(m as u64, Ordering::Relaxed);
}