ore/pool: enforce budget for inserts turned away by single-flight#37824
Open
def- wants to merge 1 commit into
Open
ore/pool: enforce budget for inserts turned away by single-flight#37824def- wants to merge 1 commit into
def- wants to merge 1 commit into
Conversation
Budget enforcement in `mz_ore::pool` is single-flight: an insert that trips it while another pass holds the `enforcing` guard returns on `WouldBlock`, trusting the in-progress pass to enforce on its behalf. That trust is misplaced once the holder is already past its final `resident_bytes` read: the turned-away insert's bytes are neither seen by the holder nor enforced by the bailer, and nothing re-trips budget enforcement afterward (only a later insert or a `set_budget` shrink does, and the spill loop sweeps the compressed cap but not the budget). The pool then sits over `budget_bytes` until insert activity resumes. Add an `enforce_pending` flag: a turned-away caller sets it (Release), and the holder re-runs its pass while it is set (Acquire on the swap so the re-read sees the caller's bump). This closes the last-read-to-guard-release window down to a few instructions. The module is behind the (currently unwired) `pool` feature, so this is a latent fix with no user-visible effect yet. Adds a regression test, racing_insert_is_not_dropped_by_budget_single_flight, which drives the losing interleaving deterministically via a one-shot, test-only seam fired between the pass's final counter read and the guard release. It fails on the pre-fix code (resident 128 KiB against a 64 KiB budget) and passes with the flag. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Budget enforcement in
mz_ore::poolis single-flight: an insert that trips it while another pass holds theenforcingguard returns onWouldBlock, trusting the in-progress pass to enforce on its behalf. That trust is misplaced once the holder is already past its finalresident_bytesread: the turned-away insert's bytes are neither seen by the holder nor enforced by the bailer, and nothing re-trips budget enforcement afterward (only a later insert or aset_budgetshrink does, and the spill loop sweeps the compressed cap but not the budget). The pool then sits overbudget_bytesuntil insert activity resumes.Add an
enforce_pendingflag: a turned-away caller sets it (Release), and the holder re-runs its pass while it is set (Acquire on the swap so the re-read sees the caller's bump). This closes the last-read-to-guard-release window down to a few instructions.Follow-up to #37718
I'm not sure if the design of this is great, I can also open a Linear issue instead if you prefer @DAlperin