gpu: fix STAGING pool cap leak and tighten idle snapshot/send pool caps on <=20GB RAM hosts
CI / check (push) Canceled after 0s

This commit is contained in:
theme613 committed 2026-11-28 20:28:10 +08:00
1 parent e4dbd89cd3
commit 604908e486
4 files changed
+17 -4

No files matched your search

+3 -1
View File
@@ -122,7 +122,9 @@ static SPARE: Mutex<Vec<Memory>> = Mutex::new(Vec::new());
/// On hosts with <= 32 GiB RAM, cap the idle upload pool at 256 MiB (instead
/// of 768 MiB) so streaming bursts have more commit headroom.
fn kept() -> u64 {
if on_card() || crate::residency::limited_host_ram() {
if crate::residency::tight_host_ram() {
128 << 20
} else if on_card() || crate::residency::limited_host_ram() {
256 << 20
} else {
768 << 20
+4 -1
View File
@@ -52,12 +52,15 @@ pub(crate) fn room(memory: Option<[u64; 4]>) {
pool.reclaim(tick, limit, true);
}
if let Ok(mut pool) = STAGING.try_lock() {
let tight = crate::residency::tight_host_ram();
let staging_limit = if crate::residency::critical_commit() {
0
} else if pressure {
1
} else if tight {
2
} else {
limit
limit.min(STAGING_KEPT)
};
pool.reclaim(tick, staging_limit, true);
}
+8
View File
@@ -95,6 +95,14 @@ pub(crate) fn limited_host_ram() -> bool {
*LIMITED.get_or_init(|| memory_status().is_some_and(|s| s.ullTotalPhys <= 32 * GIB))
}
/// True on hosts with <= 20 GiB physical RAM (e.g. 16 GB laptops), where idle
/// pools (staging blocks, snapshot buffers, upload scratch, command allocators)
/// should stay lean to leave physical RAM free for Windows and avoid paging.
pub(crate) fn tight_host_ram() -> bool {
static TIGHT: OnceLock<bool> = OnceLock::new();
*TIGHT.get_or_init(|| memory_status().is_some_and(|s| s.ullTotalPhys <= 20 * GIB))
}
fn next_pressure(was: bool, physical: u64, commit: u64) -> bool {
if was {
physical < 5 * GIB || commit < 6 * GIB
+2 -2
View File
@@ -1381,14 +1381,14 @@ fn snapshots_kept() -> usize {
/// 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 cap: usize = if crate::residency::tight_host_ram() { 128 << 20 } else { 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()));
let (mut kept, mut total) = (0, 0usize);
for v in pool.iter().take(snapshots_kept()) {
total = total.saturating_add(v.capacity());
if kept > 0 && total > KEPT {
if kept > 0 && total > cap {
break;
}
kept += 1;