From 651867a496efaa7dae595aabc64b4d2d34451946 Mon Sep 17 00:00:00 2001 From: pr1sm-dev <29008292+pr1sm-dev@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:51:05 +0200 Subject: [PATCH] xcl run: preparation workers count the commit left in MiB, not bytes prepare_workers passes host::system_commit(), which is in bytes (commit pages times the page size), to workers_for(cores, free_mb), which divides by 3072 as MiB. The commit bound therefore never applied: the count was always the logical processors less four (at most 32), so 16 threads with 6 GiB of commit left got 12 workers instead of 2. Reported by pickles976 on #2624. The commit figures are now converted to MiB in a new workers_for_commit, which prepare_workers calls; workers_for and its tests are unchanged, and XCL_PREPARE_WORKERS still sets the count directly. The new test passes the figures in bytes; without the conversion it fails (12, expected 2). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BuVT2rKpD9DAmDGg1zuzbB (cherry picked from commit 231c4f1d06b567d5fece22ab659d1b0ecd21c7f8) --- crates/xcl/src/shaders.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index f9567215f8..182316062a 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -2118,7 +2118,13 @@ fn prepare_workers() -> usize { } let cores = std::thread::available_parallelism().map_or(4, |n| n.get()); let (used, limit) = crate::host::system_commit(); - workers_for(cores, limit.saturating_sub(used)) + workers_for_commit(cores, used, limit) +} + +/// The workers for `cores` logical processors and the system's commit charge `used` and its +/// `limit`, both in bytes as `host::system_commit` gives them. +fn workers_for_commit(cores: usize, used: u64, limit: u64) -> usize { + workers_for(cores, limit.saturating_sub(used) >> 20) } /// The workers for `cores` logical processors (threads, not cores) and `free_mb` of commit left. @@ -3248,6 +3254,17 @@ mod tests { assert_eq!(workers_for(32, 0), 1); } + /// The commit figures come in bytes: 6 GiB left on 16 logical processors is room for two + /// workers, not twelve; a commit that is not known (0, 0) gives one. + #[test] + fn preparation_workers_take_the_commit_left_in_bytes() { + const GIB: u64 = 1 << 30; + assert_eq!(workers_for_commit(16, 10 * GIB, 16 * GIB), 2); + assert_eq!(workers_for_commit(16, 0, 64 * GIB), 12); + assert_eq!(workers_for_commit(16, 0, 0), 1); + assert_eq!(workers_for_commit(16, 20 * GIB, 16 * GIB), 1); + } + /// A builder's progress line gives its record count; its other lines give none. #[test] fn a_builders_progress_line_gives_its_count() {