gpu: restore 1-by-1 wide_each stealing for balanced dirty-buffer refresh load
This commit is contained in:
1 parent
8503191734
commit
5fff0f1fb7
2 files changed
+15
-66
No files matched your search
@@ -1843,40 +1843,6 @@ pub(crate) fn wide_each(n: usize, work: impl Fn(usize) + Send + Sync + 'static)
|
||||
wide(jobs);
|
||||
}
|
||||
|
||||
/// As [`wide_each`], but hands out contiguous slices of up to `chunk` indices
|
||||
/// per atomic claim to eliminate cross-core cache-line bouncing on thousands
|
||||
/// of lightweight items (e.g. unchanged copy checks).
|
||||
pub(crate) fn wide_each_chunked(
|
||||
n: usize,
|
||||
chunk: usize,
|
||||
work: impl Fn(std::ops::Range<usize>) + Send + Sync + 'static,
|
||||
) {
|
||||
let chunk = chunk.max(1);
|
||||
let chunks = n.div_ceil(chunk);
|
||||
if chunks == 0 {
|
||||
return;
|
||||
}
|
||||
let next = Arc::new(std::sync::atomic::AtomicUsize::new(0));
|
||||
let work = Arc::new(work);
|
||||
let threads = (wide_threads() + 1).min(chunks);
|
||||
let jobs = (0..threads)
|
||||
.map(|_| {
|
||||
let (next, work) = (next.clone(), work.clone());
|
||||
Box::new(move || {
|
||||
loop {
|
||||
let c = next.fetch_add(1, Ordering::Relaxed);
|
||||
let start = c.saturating_mul(chunk);
|
||||
if start >= n {
|
||||
break;
|
||||
}
|
||||
work(start..(start + chunk).min(n));
|
||||
}
|
||||
}) as Job
|
||||
})
|
||||
.collect();
|
||||
wide(jobs);
|
||||
}
|
||||
|
||||
/// About this many bytes to a piece of work for [`wide`].
|
||||
const WIDE_JOB: usize = 1 << 20;
|
||||
|
||||
|
||||
Reference in new issue
Block a user