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
+12
-63
No files matched your search
@@ -9052,28 +9052,18 @@ impl Batch {
|
|||||||
crate::watch::ask_ahead(&ranges);
|
crate::watch::ask_ahead(&ranges);
|
||||||
}
|
}
|
||||||
FLUSHES[3].fetch_add(spans.len() as u64, Ordering::Relaxed);
|
FLUSHES[3].fetch_add(spans.len() as u64, Ordering::Relaxed);
|
||||||
const SPAN_CHUNK: usize = 32;
|
crate::shadow::wide_each(spans.len() + due.len(), move |i| {
|
||||||
let span_chunks = spans.len().div_ceil(SPAN_CHUNK);
|
// The textures first: they are the longer pieces.
|
||||||
let due_len = due.len();
|
let Some(i) = i.checked_sub(due.len()) else {
|
||||||
crate::shadow::wide_each(due_len + span_chunks, move |i| {
|
|
||||||
// The textures first (1 by 1): they are the longer pieces.
|
|
||||||
let Some(chunk_idx) = i.checked_sub(due_len) else {
|
|
||||||
due[i].refresh();
|
due[i].refresh();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let start = chunk_idx * SPAN_CHUNK;
|
let (shadow, from, to) = &spans[i];
|
||||||
let end = (start + SPAN_CHUNK).min(spans.len());
|
|
||||||
let mut skipped = 0u64;
|
|
||||||
for (shadow, from, to) in &spans[start..end] {
|
|
||||||
if many && shadow.nothing_new(*from, *to - *from) {
|
if many && shadow.nothing_new(*from, *to - *from) {
|
||||||
skipped += 1;
|
FLUSHES[2].fetch_add(1, Ordering::Relaxed);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
Self::update(shadow, *from, *to);
|
Self::update(shadow, *from, *to);
|
||||||
}
|
|
||||||
if skipped > 0 {
|
|
||||||
FLUSHES[2].fetch_add(skipped, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if ahead {
|
if ahead {
|
||||||
crate::watch::ask_ahead_done();
|
crate::watch::ask_ahead_done();
|
||||||
@@ -9225,22 +9215,15 @@ impl Batch {
|
|||||||
let before = PREPARING[0].load(Ordering::Relaxed);
|
let before = PREPARING[0].load(Ordering::Relaxed);
|
||||||
FLUSHES[3].fetch_add(self.refreshes.len() as u64, Ordering::Relaxed);
|
FLUSHES[3].fetch_add(self.refreshes.len() as u64, Ordering::Relaxed);
|
||||||
if light {
|
if light {
|
||||||
// Chunked work-stealing avoids per-item atomic contention.
|
// A number to a free thread, not a job to each copy.
|
||||||
let refreshes = std::mem::take(&mut self.refreshes);
|
let refreshes = std::mem::take(&mut self.refreshes);
|
||||||
let many = refreshes.len() > FEW;
|
crate::shadow::wide_each(refreshes.len(), move |i| {
|
||||||
let chunk = if many { 32 } else { 1 };
|
let (shadow, from, to) = &refreshes[i];
|
||||||
crate::shadow::wide_each_chunked(refreshes.len(), chunk, move |range| {
|
if refreshes.len() > FEW && shadow.nothing_new(*from, *to - *from) {
|
||||||
let mut skipped = 0u64;
|
FLUSHES[2].fetch_add(1, Ordering::Relaxed);
|
||||||
for (shadow, from, to) in &refreshes[range] {
|
return;
|
||||||
if many && shadow.nothing_new(*from, *to - *from) {
|
|
||||||
skipped += 1;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Self::update(shadow, *from, *to);
|
Self::update(shadow, *from, *to);
|
||||||
}
|
|
||||||
if skipped > 0 {
|
|
||||||
FLUSHES[2].fetch_add(skipped, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let jobs: Vec<Box<dyn FnOnce() + Send>> = self
|
let jobs: Vec<Box<dyn FnOnce() + Send>> = self
|
||||||
|
|||||||
@@ -1843,40 +1843,6 @@ pub(crate) fn wide_each(n: usize, work: impl Fn(usize) + Send + Sync + 'static)
|
|||||||
wide(jobs);
|
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`].
|
/// About this many bytes to a piece of work for [`wide`].
|
||||||
const WIDE_JOB: usize = 1 << 20;
|
const WIDE_JOB: usize = 1 << 20;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user