Fix eviction queue dead_nodes counter underflow causing excessive purge iterations#40
Draft
krleonid wants to merge 1 commit into
Draft
Fix eviction queue dead_nodes counter underflow causing excessive purge iterations#40krleonid wants to merge 1 commit into
krleonid wants to merge 1 commit into
Conversation
…er underflow When total_dead_nodes underflows (decremented more than incremented due to accounting mismatch), the wrapped unsigned value is always greater than approx_q_size. The old code clamped it to approx_q_size, making approx_alive_nodes=0, which prevented condition 2.2 from ever triggering. This caused the loop to run all max_purges iterations unnecessarily. Fix: if approx_dead_nodes > approx_q_size, break immediately — the counter is unreliable and there is no meaningful dead node pressure to address. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
60dc284 to
1d1cec7
Compare
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.
Summary
total_dead_nodesfromatomic<idx_t>(unsigned) toatomic<int64_t>(signed) to prevent underflowPurge()loop early-out condition to treat negative dead_nodes as zeroUnsafeNumericCastinduckdb_eviction_queuesoutputProblem
The
total_dead_nodescounter underflows becauseDecrementDeadNodes()is called for nodes that were never counted byIncrementDeadNodes()— specifically, nodes that die (weak_ptr expires or block is pinned) without ever being superseded by a newer version.When the unsigned counter wraps to a massive value, the
Purge()loop's condition 2.2 never triggers:This causes the purge loop to run all
max_purgesiterations (up toapprox_q_size / 8192) unnecessarily, holdingpurge_lockthe entire time.Observed output from
duckdb_eviction_queues{ "data": [ {"approximate_size": 5098963, "dead_nodes": 3873616, "queue_index": 0, "queue_type": "BLOCK_AND_EXTERNAL_FILE", "total_insertions": 605198908}, {"approximate_size": 224455537, "dead_nodes": 163476417, "queue_index": 1, "queue_type": "MANAGED_BUFFER", "total_insertions": 1977873276}, {"approximate_size": 29715, "dead_nodes": -107922767, "queue_index": 2, "queue_type": "MANAGED_BUFFER", "total_insertions": 108300237}, {"approximate_size": 32337, "dead_nodes": -134953305, "queue_index": 3, "queue_type": "MANAGED_BUFFER", "total_insertions": 135275557}, {"approximate_size": 30044, "dead_nodes": -73130179, "queue_index": 4, "queue_type": "MANAGED_BUFFER", "total_insertions": 73253127}, {"approximate_size": 28361, "dead_nodes": -32992668, "queue_index": 5, "queue_type": "MANAGED_BUFFER", "total_insertions": 33069332}, {"approximate_size": 33218, "dead_nodes": -171896118, "queue_index": 6, "queue_type": "MANAGED_BUFFER", "total_insertions": 172673075}, {"approximate_size": 0, "dead_nodes": 0, "queue_index": 7, "queue_type": "TINY_BUFFER", "total_insertions": 0} ] }Queues 2-6 show negative
dead_nodes— these are the underflowed counters causing excessive purge iterations on every trigger.Test plan
*eviction*— 10 test cases, 4095 assertions)test/sql/storage/buffer*— 4 test cases)test/sql/parallelism/*— 68 test cases, 412018 assertions)