Merge fork main 8dd30ab: writes through one view of a page are seen at its other views
The fork's guard over every view of a physical page is kept on our own block bits, known holes, kernel writes and changing blocks; what both had, ours. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
c45d109380
23 files changed
+4164
-221
No files matched your search
@@ -367,7 +367,11 @@ struct Views {
|
||||
shape_index: std::collections::BTreeMap<Shape, u32>,
|
||||
}
|
||||
|
||||
static VIEWS: std::sync::Mutex<Views> = std::sync::Mutex::new(Views {
|
||||
/// Read far more often than written: every slot a draw reads through a
|
||||
/// table is looked up here, on several recording threads at once in the
|
||||
/// world. Readers share it; only a view not seen before (a new table entry
|
||||
/// or shape) and a released resource take it alone.
|
||||
static VIEWS: std::sync::RwLock<Views> = std::sync::RwLock::new(Views {
|
||||
list: Vec::new(),
|
||||
index: std::collections::BTreeMap::new(),
|
||||
by_resource: std::collections::BTreeMap::new(),
|
||||
@@ -494,6 +498,12 @@ impl Views {
|
||||
Some(View::Placed(unordered, resource, desc))
|
||||
}
|
||||
|
||||
/// The record words of `view` as a table entry, if it has one.
|
||||
fn entry_of(&self, view: &View) -> Option<[u32; 2]> {
|
||||
let &i = self.index.get(view)?;
|
||||
Some([i, self.list[i as usize].1])
|
||||
}
|
||||
|
||||
/// The record words of `view` as a table entry: its entry (a new or a
|
||||
/// freed one if the view is not there yet) and that entry's generation.
|
||||
fn entry(&mut self, view: View) -> [u32; 2] {
|
||||
@@ -536,8 +546,10 @@ fn words_for(view: View) -> [u32; 2] {
|
||||
View::Placed(unordered, resource, desc) => {
|
||||
let (shape, address) = shape_of(*unordered, resource, desc);
|
||||
if address >> PLACED_ADDRESS_BITS == 0 {
|
||||
let mut views = VIEWS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some(shape) = views.shape(shape) {
|
||||
// Nearly every placed view has a shape seen before.
|
||||
let known = views_read().shape_index.get(&shape).copied();
|
||||
let shape = known.or_else(|| views_write().shape(shape));
|
||||
if let Some(shape) = shape {
|
||||
NAMED_WHOLE[1].fetch_add(1, Relaxed);
|
||||
return placed_words(shape, address);
|
||||
}
|
||||
@@ -546,7 +558,19 @@ fn words_for(view: View) -> [u32; 2] {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
VIEWS.lock().unwrap_or_else(|e| e.into_inner()).entry(view)
|
||||
// A view written before keeps its entry and generation.
|
||||
if let Some(words) = views_read().entry_of(&view) {
|
||||
return words;
|
||||
}
|
||||
views_write().entry(view)
|
||||
}
|
||||
|
||||
fn views_read() -> std::sync::RwLockReadGuard<'static, Views> {
|
||||
VIEWS.read().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
fn views_write() -> std::sync::RwLockWriteGuard<'static, Views> {
|
||||
VIEWS.write().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
/// For the memory line: the distinct views kept ([`Views`]), those of them
|
||||
@@ -560,7 +584,7 @@ fn words_for(view: View) -> [u32; 2] {
|
||||
#[cfg(all(windows, feature = "diagnostics"))]
|
||||
pub(crate) fn views_kept() -> [u64; 8] {
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
let views = VIEWS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let views = views_read();
|
||||
let each = size_of::<(View, u32)>() as u64;
|
||||
let shape = size_of::<Shape>() as u64;
|
||||
let (mut constants, mut placed) = (0, 0);
|
||||
@@ -711,7 +735,7 @@ pub(crate) fn forget(resource: usize) {
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.remove(&resource);
|
||||
let mut views = VIEWS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut views = views_write();
|
||||
let Some(entries) = views.by_resource.remove(&resource) else {
|
||||
return;
|
||||
};
|
||||
@@ -736,12 +760,12 @@ pub(crate) fn forget(resource: usize) {
|
||||
fn view_at(i: u32, generation: u32) -> Option<View> {
|
||||
match generation >> KIND_SHIFT {
|
||||
0 => {
|
||||
let views = VIEWS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let views = views_read();
|
||||
let (view, current) = views.list.get(i as usize)?;
|
||||
(*current == generation).then(|| view.clone())
|
||||
}
|
||||
CONSTANT => Some(constant_of(i, generation)),
|
||||
PLACED => VIEWS.lock().unwrap_or_else(|e| e.into_inner()).placed_of(i, generation),
|
||||
PLACED => views_read().placed_of(i, generation),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -1118,8 +1142,8 @@ mod tests {
|
||||
View::Placed(_, r, _) => *r == resource,
|
||||
_ => false,
|
||||
};
|
||||
let entries = || VIEWS.lock().unwrap().list.iter().filter(|(v, _)| mine(v)).count();
|
||||
let shapes = || VIEWS.lock().unwrap().shapes.iter().filter(|s| s.1 == resource).count();
|
||||
let entries = || VIEWS.read().unwrap().list.iter().filter(|(v, _)| mine(v)).count();
|
||||
let shapes = || VIEWS.read().unwrap().shapes.iter().filter(|s| s.1 == resource).count();
|
||||
for n in 0..20_000u64 {
|
||||
let address = 0x6_0000_0000 + n * 0x100;
|
||||
create_cbv(null, &[address as u32, (address >> 32) as u32, 512, 0], at);
|
||||
|
||||
Reference in new issue
Block a user