Repository navigation
Conversation
Defrag's starvation protection sizes each duty cycle from the time since the previous one ended, at up to 1.5x the wait with active-defrag-cycle-max 60. A few-ms scheduling stall on a shared CI runner therefore turns into a defrag cycle longer than 5ms even when every stage honors its deadline, and a stall landing mid-cycle adds directly to it. Every test using the default limit flakes this way, failing about 1 in 200 test-ubuntu-latest jobs. 20ms stays above the observed noise (max 11ms in CI) while still catching a stage that ignores its deadline. Signed-off-by: Madelyn Olson <madelyneolson@gmail.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.
The active defrag tests that use the default 5ms latency limit fail on about 1 in 200 test-ubuntu-latest jobs, for example "Active Defrag tracking table: standalone" with
Expected 9 <= 5. The cause is the runner, not defrag. Starvation protection makes each cycle about 1.5 times as long as the wait before it, so a few-ms scheduling stall shows up as a defrag cycle over 5ms. A stall that lands mid-cycle adds straight to the cycle time. This raises the default to 20ms, above the noise seen in CI and still well below what a stage that ignores its deadline produces.AI generated details
Problem
computeDefragCycleUs(src/defrag.c:1100) sizes the next duty cycle asD = P * W / (100 - P), whereWis the time since the previous cycle ended.perform_defrag_testsetsactive-defrag-cycle-max 60(tests/unit/memefficiency.tcl:194), soDcan reach1.5 * W. The latency monitor around the cycle (src/defrag.c:1170-1196) measures wall time, so a stall inside the cycle counts too. Both cases fail the 5ms limit when every stage honors its deadline.It is not specific to the tracking table. CI logs print
Validating max latency (N)for every defrag test, which makes the distribution visible. Across 518 failed jemalloc jobs since the tracking-table test landed (2026-10-14), 76 of 8,166 samples from 5ms-limit tests exceeded 5ms. They came from every test except big list: stream 22, main dictionary 14, tracking table 12, big hash 8, big zset 15, big set 5. The highest was 11ms. 58 jobs failed on it, 13 of them test-ubuntu-latest, out of about 2,800 test-ubuntu-latest jobs. Every outlier is a burst of 1 to 3 cycles inside one second, which fits a stall and not a stage that loops past its deadline.Repro
A debug log of
latencyanddutyCycleUsper cycle, plus a script thatSIGSTOPs the server for 6ms every 100 to 300ms, fails 3 of 6 tracking-table runs:With 4ms stops the maximum is 5ms and nothing fails. Running the full
./runtest --clients 16pinned to 4 cores next to the test, like a 4-vCPU runner, failed 2 of 16 runs with 13ms and 14ms. Plain busy-loop burners on the same cores did not reproduce it (12 runs, max 2ms), since wakeup preemption favors the server over CPU-bound loops.Why 20ms
20ms is above the CI maximum (11ms) and the local oversubscribed maximum (14ms). It still catches a deadline regression. With the deadline checks in
defragTrackingTabledisabled, the test fails withExpected 79 <= 20. The tradeoff is that a stage overrunning by 5 to 20ms per cycle would no longer be caught. valkey-io#2553 lowered the limit from 40 to 5 after its hit-threshold change.Alternatives considered:
active-defrag-cycle-maxin the test. Rejected: this only reduces starvation amplification, does nothing for in-cycle stalls, and slows every defrag test.--no-latencyin CI. Rejected: it turns the check off everywhere.The big list test keeps its explicit
latency 5. It had 0 outliers in 1,036 CI samples.Testing
With 6ms stops and this change, 4 of 6 runs measured 7ms and all passed.
This was generated by AI but verified, with love, by a human.