✅ Give back the release test's own block, not offset 0
The release test took one block for each of contexts 1 to 4 on a fresh piece and gave back context 1's at offset 0, which holds only when context 1's take is carved first. It need not be: the zeroer claims a fresh piece's first chunk last, a take whose first fit holds bytes of the claimed chunk waits for it on its worker, and the zeroer lets its claim go before it wakes that worker. A later take carried out in between carves offset 0 at once, so context 1's block lies past it and the give of offset 0 finds another context's block: the "not given" a loaded merge run met once. The test now gives back the block context 1's take answered. A new test forces that order (a claim set with the zeroer shut, a take waiting for it, the claim ended, a second context's take): it failed on the old test's give, and holds with the fix. No behaviour change: the pool carved and answered so before, and a context's takes are still answered in its order by its one worker. The "Zeros ahead" doc said a block lies where it would with no zeroer; it now says what the code does.
This commit is contained in:
1 parent
e5b03f2d8b
commit
b5d5caf63a
2 files changed
+58
-9
No files matched your search
@@ -63,10 +63,14 @@
|
||||
//! waits for its write, the take workers among them, nor does any of the Private blocks'
|
||||
//! ([`super::private_blocks`], whose ledger, lock and workers it shares nothing with). One take
|
||||
//! may: where a take's first fit holds bytes of the claimed chunk, its worker waits for the chunk's
|
||||
//! write and mark, the zeroer claiming no other chunk meanwhile, and then carves that first fit,
|
||||
//! counted with its wait, in all and at its longest ([`super::TAKE_CLAIM_WAITS_CODE`]): one chunk's
|
||||
//! write at most. So the zeroer moves no carve: a block lies where it would with no zeroer, first
|
||||
//! fit over the carves alone. The device's release ends the zeroer once its chunk is written, and
|
||||
//! write and mark, the zeroer claiming no other chunk meanwhile, and then carves the first fit it
|
||||
//! finds then, counted with its wait, in all and at its longest ([`super::TAKE_CLAIM_WAITS_CODE`]):
|
||||
//! one chunk's write at most. Every block is a first fit over the carves at the moment it is
|
||||
//! carved, but not always where it would lie with no zeroer: the zeroer lets its claim go before
|
||||
//! it wakes the waiting take, and a later take, of the waiting take's context or another's,
|
||||
//! carried out between the claim's end and that wake carves that first fit at once, so the
|
||||
//! waiting take's block lies past it. A context's takes are still answered in its order, by its
|
||||
//! one worker. The device's release ends the zeroer once its chunk is written, and
|
||||
//! waits for it and for the take workers to let go of the pool ([`super::Threads`]). The guest
|
||||
//! writes no freed carve's bytes: the kext takes a block's mapping out of the process before its
|
||||
//! give, and the device frees it once the context's command buffers have finished.
|
||||
|
||||
@@ -881,11 +881,12 @@ fn the_release_returns_once_no_pool_thread_holds_the_pool() {
|
||||
let takes: Vec<Answers> = (1..=4)
|
||||
.map(|context| take(&ledger, context, TAKE_ALIGN))
|
||||
.collect();
|
||||
for rx in &takes {
|
||||
assert!(taken(rx).is_some());
|
||||
}
|
||||
// One of the piece's four blocks freed: the zeroer runs.
|
||||
let Give::Given(carve) = ledger.give(1, 0, TAKE_ALIGN, |_, _| false) else {
|
||||
let blocks: Vec<Taken> = takes.iter().map(|rx| taken(rx).expect("a block")).collect();
|
||||
// One of the piece's four blocks freed: the zeroer runs. Context 1's is the block its take
|
||||
// answered, which lies past a later take's where it waited for the zeroer's claim
|
||||
// (`a_take_waiting_for_the_zeroers_claim_may_be_carved_after_a_later_take`).
|
||||
let Give::Given(carve) = ledger.give(1, blocks[0].offset, blocks[0].length, |_, _| false)
|
||||
else {
|
||||
panic!("not given");
|
||||
};
|
||||
ledger.free(&[carve]);
|
||||
@@ -899,6 +900,50 @@ fn the_release_returns_once_no_pool_thread_holds_the_pool() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A take whose first fit holds bytes of the zeroer's claimed chunk is carved by its worker once
|
||||
/// the claim goes, and a later take carried out between the claim's end and the zeroer's wake
|
||||
/// carves that first fit before it: with context 1's take waiting for the claim of the piece's
|
||||
/// first chunk, which the zeroer claims last of a fresh piece, context 2's block lies at offset 0
|
||||
/// and context 1's past it. So the release test gives back the block context 1's take answered,
|
||||
/// and its give of offset 0 would find context 2's block
|
||||
#[test]
|
||||
fn a_take_waiting_for_the_zeroers_claim_may_be_carved_after_a_later_take() {
|
||||
let host = Arc::new(Host::default());
|
||||
let (mut pool, _blocks, ledger) = live_pool_unzeroed(&host, LONG);
|
||||
// The zeroer's claim, set here with its zeroer shut, so it stands until the test ends it.
|
||||
pool.shared.state.lock().claim = Some((BASE, 0..takes::ZERO_CHUNK));
|
||||
let first = take(&ledger, 1, TAKE_ALIGN);
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
while pool.shared.state.lock().claim_waits == 0 {
|
||||
assert!(
|
||||
Instant::now() < deadline,
|
||||
"the take did not wait for the chunk"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
// The claim ends, its waiters not woken yet, as the zeroer lets it go before its wake.
|
||||
pool.shared.state.lock().claim = None;
|
||||
let second = take(&ledger, 2, TAKE_ALIGN);
|
||||
assert_eq!(answer(&second), Some((0, TAKE_ALIGN)));
|
||||
let first = taken(&first).expect("a block");
|
||||
assert_eq!((first.offset, first.length), (TAKE_ALIGN, TAKE_ALIGN));
|
||||
assert!(matches!(
|
||||
ledger.give(1, 0, TAKE_ALIGN, |_, _| false),
|
||||
Give::NotFound
|
||||
));
|
||||
let Give::Given(carve) = ledger.give(1, first.offset, first.length, |_, _| false) else {
|
||||
panic!("not given");
|
||||
};
|
||||
ledger.free(&[carve]);
|
||||
drop(ledger);
|
||||
pool.close();
|
||||
assert_eq!(
|
||||
Arc::strong_count(&pool.shared),
|
||||
1,
|
||||
"a pool thread still holds the pool"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_take_of_no_bytes_or_past_the_longest_is_an_invalid_argument() {
|
||||
let host = Arc::new(Host::default());
|
||||
|
||||
Reference in new issue
Block a user