ke/smr: allow invalid sequences in deferred_advance_commit

This was buggy when the race was lost and it ended up trying to commit a
deferred advance of 0, now explicitly make the magazine's sequence invalid and
do nothing in deferred_advance_commit, avoiding an integer underflow.
This commit is contained in:
Loïc Grégoire
2026-09-19 23:03:39 -04:00
parent e7655e9725
commit a9028e53ff
2 changed files with 6 additions and 0 deletions
+2
View File
@@ -274,6 +274,8 @@ pub fn deferred_advance(dom: *Domain) Sequence {
/// Actually advance the global clock to a value previously returned by /// Actually advance the global clock to a value previously returned by
/// deferred_advance(). /// deferred_advance().
pub fn deferred_advance_commit(dom: *Domain, seq: Sequence) void { pub fn deferred_advance_commit(dom: *Domain, seq: Sequence) void {
if (seq == seq_invalid) return;
_ = dom.clock.write_seq.cmpxchgStrong( _ = dom.clock.write_seq.cmpxchgStrong(
seq - seq_incr, seq - seq_incr,
seq, seq,
+4
View File
@@ -792,6 +792,10 @@ pub const Zone = struct {
// We lost the race. If the magazine we got was fully filled, // We lost the race. If the magazine we got was fully filled,
// then put it in the depot. Otherwise, dispose of it. // then put it in the depot. Otherwise, dispose of it.
if (cnt == magazine_size.load()) { if (cnt == magazine_size.load()) {
// Ensure this magazine isn't counted as a freed one,
// it is instantly reclaimable.
nm.seq = ke.smr.seq_invalid;
Depot.free(nm, &cpu.depot.full_mags, self.reuse_policy); Depot.free(nm, &cpu.depot.full_mags, self.reuse_policy);
continue; continue;
} }