Repository navigation
xcl run: XCL_RAM_MB caps the RAM the process holds - #3304
Conversation
|
merge-check Candidate diff and focused regressionThis is a local candidate, not a pushed commit. diff --git a/crates/xcl/src/ram_budget.rs b/crates/xcl/src/ram_budget.rs
@@
fn setting_of(ram: Option<&str>, free: Option<&str>) -> Option<Setting> {
let ram = ram?.trim();
if ram.eq_ignore_ascii_case("auto") {
- let free = free.and_then(|v| v.trim().parse::<u64>().ok()).unwrap_or(6144);
- return Some(Setting::Auto(free * MB));
+ let free = free.and_then(|v| v.trim().parse::<u64>().ok()).and_then(|mb| mb.checked_mul(MB)).unwrap_or(6144 * MB);
+ return Some(Setting::Auto(free));
}
- ram.parse::<u64>().ok().filter(|&mb| mb > 0).map(|mb| Setting::Fixed((mb * MB).max(LEAST)))
+ ram.parse::<u64>().ok().filter(|&mb| mb > 0).and_then(|mb| mb.checked_mul(MB)).map(|bytes| Setting::Fixed(bytes.max(LEAST)))
}
@@
-/// beyond `keep`, and has to shrink by what is missing; `before` (None: no maximum yet) moves
-/// by `STEP` at most. None: no maximum is needed (more than `STEP` to spare).
+/// beyond `keep`, and has to shrink by what is missing. An active maximum moves by `STEP` at
+/// most while needed; surplus greater than `STEP` removes it.
@@
fn next_max(before: Option<u64>, ws: u64, available: u64, keep: u64) -> Option<u64> {
- let want = (ws + available).saturating_sub(keep).max(LEAST);
+ if available.saturating_sub(keep) > STEP { return None; }
+ let want = ws.saturating_add(available).saturating_sub(keep).max(LEAST);
match before {
- None if available > keep + STEP => None,
None => Some(want.max(ws.saturating_sub(STEP))),
- Some(b) => Some(want.clamp(b.saturating_sub(STEP), b + STEP).max(LEAST)),
+ Some(b) => Some(want.clamp(b.saturating_sub(STEP), b.saturating_add(STEP)).max(LEAST)),
}
}
@@
+ #[test]
+ fn oversized_megabyte_settings_do_not_overflow() {
+ assert_eq!(setting_of(Some("17592186044416"), None), None);
+ assert_eq!(setting_of(Some("auto"), Some("17592186044416")), Some(Setting::Auto(6144 * MB)));
+ let largest_mb = (u64::MAX / MB) * MB;
+ assert_eq!(next_max(None, LEAST, 0, largest_mb), Some(LEAST));
+ }
+
+ #[test]
+ fn automatic_limit_lifts_when_ram_is_plentiful_again() {
+ assert_eq!(next_max(Some(LEAST), LEAST, 16_384 * MB, 6144 * MB), None);
+ }
@@
- assert_eq!(next_max(Some(10000 * MB), 10000 * MB, 9000 * MB, keep), Some(10000 * MB + STEP));
+ assert_eq!(next_max(Some(10000 * MB), 10000 * MB, 6400 * MB, keep), Some(10256 * MB));Generated smoke blocksEach block came from The third block used |
|
merge-check
Three earlier runs of
|
A console title's GPU memory is its only copy of what is in it; here the title's pages are RAM and what the GPU reads of them is copied to video memory. A retail title's world held 5 GB of RAM in pages whose copy was on the card, most of them never touched again, and Windows only takes such pages out of a process when RAM is short for the whole system: on a 32 GB PC with 15 GB used by other programs that came at under 4 GB free. XCL_RAM_MB=<MB> gives the process's working set a hard maximum (SetProcessWorkingSetSizeEx): Windows takes the pages used least out of it as it grows past that, they stay in RAM on the standby list while nothing else needs it, and a page touched again comes back with a soft fault. XCL_RAM_MB=auto moves the maximum once a second so that XCL_RAM_FREE_MB (6144 unless given) stay available. Unset: no budget, as before. Commit is unchanged. Ported from amd-dev a68f609 (raylitebull, ram_budget.rs as on amd-dev) with its start call; left out: the preparation-worker count that amd-dev also bounds by available RAM (a default behaviour change of its own). Review fixes (xcl-dev#3304, from thehollowedone's candidate patch): a number of MB too large for bytes is no setting (XCL_RAM_MB) or the default reserve (XCL_RAM_FREE_MB) instead of an overflow panic, and an automatic maximum is lifted again when more than a step of RAM is spare (it only moved by a step before, so it never went away). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks thehollowedone. I applied your candidate patch in db9a8f0 (credited in the commit and the description):
I added more cases to the existing test: a step-limited raise, and a lift from the least maximum. Full suite on db9a8f0: 2608 passed, 4 failed (this machine's fuzz (Written with Claude Code, Claude Opus 5.5.) |
A console title's GPU memory is its only copy of what is in it; here
the title's pages are RAM and what the GPU reads of them is copied to
video memory. A retail title's world held 5 GB of RAM in pages whose
copy was on the card, most of them never touched again, and Windows
only takes such pages out of a process when RAM is short for the whole
system: on a 32 GB PC with 15 GB used by other programs that came at
under 4 GB free.
XCL_RAM_MB= gives the process's working set a hard maximum
(SetProcessWorkingSetSizeEx): Windows takes the pages used least out
of it as it grows past that, they stay in RAM on the standby list while
nothing else needs it, and a page touched again comes back with a soft
fault. XCL_RAM_MB=auto moves the maximum once a second so that
XCL_RAM_FREE_MB (6144 unless given) stay available. Unset: no budget,
as before. Commit is unchanged.
Ported from amd-dev a68f609 (raylitebull, ram_budget.rs as on
amd-dev) with its start call; left out: the preparation-worker count
that amd-dev also bounds by available RAM (a default behaviour change
of its own).
Review fixes (thehollowedone's candidate patch, with its tests): a number of MB too large for bytes (
XCL_RAM_MB=17592186044416) overflowed and panicked in debug builds; it is now no setting, and a too-largeXCL_RAM_FREE_MBgives the default reserve. An automatic maximum moved by a step at most, so once set it never went away; it is now lifted when more than a step of RAM is spare again (oversized_megabyte_settings_do_not_overflow, and new cases inan_automatic_maximum_follows_the_ram_available).What is in it
crates/xcl/src/ram_budget.rs(new): the setting, the automatic maximum, testscrates/xcl/src/host.rs:startafter the boot is set;lib.rs;README.md: the switchTested
cargo test --workspace --no-fail-fast -- --test-threads=4on db9a8f0: 2608 passed, 4 failed, 49 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(E_OUTOFMEMORYfromCreateComputePipelineState, seeds 70 / 545 / 1019 / 1507). They fail the same way on this branch's base, main fa20459, on this machine, and pass here on newer main (Recompiler: early-exit-safe multi-wave s_barrier in direct DXIL #3264, rebased onto 0fe06eb, has 0 failures). SKIPPED GPU tests: 44 distinct notices, almost allno wave64.Regression run
main:
this PR:
Not tested
XCL_RAM_MBset (the smoke run is without it: the default is unchanged); the effect on a memory-tight PC is amd-dev's reportAI use
🤖 Generated with Claude Code