Deflake guarded_page_allocator_profile_test: fix a rate-limiter counter race and a test stop condition. - #953
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_982762477
branch
3 times, most recently
from
September 18, 2026 16:40
960c06d to
36f8ceb
Compare
…er race and a test stop condition. Two independent flakes (~0.05% each, -c opt), both in the guarded-sample rate limiter's accounting. 1) GuardedPageAllocator::TrySample counter race (production fix). NeverRateLimited sets equal guarded and profile sampling intervals and asserts that no allocation is ever RateLimited. With equal intervals the rate-limit predicate reduces to num_sampled < num_guarded, which should be impossible because sampled allocations are a superset of guarded ones. However num_guarded (successful_allocations_) and num_sampled (total_sampled_count_) are incremented non-atomically, and by design num_sampled is incremented after num_guarded. A concurrent or reentrant guarded allocation can bump num_guarded before its num_sampled increment, so a racing TrySample reads num_sampled < num_guarded and spuriously returns RateLimited. Clamp the read to the documented invariant (num_sampled >= num_guarded). This is a no-op in steady state; at equal intervals it makes rate-limiting provably impossible, and it does not change behavior when guarded_interval > profile_interval (at the floor num_sampled == num_guarded the ratio is still 10, which rate-limits as intended). 2) RateLimited test stop condition (test fix). The test looped until the first sampled-but-not-guarded allocation and assumed it must be RateLimited. TrySample also returns Filtered (probabilistic stacktrace filter) and NoAvailableSlots, so if the first non-guarded sample was Filtered the window contained no RateLimited sample and the assertion failed. Accumulate enough guarded allocations that the 2:1 rate limiter is guaranteed to have produced many RateLimited samples before stopping. Both tests still assert their original invariants (Guarded+RateLimited present under a 2:1 interval; never RateLimited under equal intervals). PiperOrigin-RevId: 983913752
copybara-service
Bot
force-pushed
the
test_982762477
branch
from
September 18, 2026 16:46
36f8ceb to
146e84e
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.
Deflake guarded_page_allocator_profile_test: fix a rate-limiter counter race and a test stop condition.
Two independent flakes (~0.05% each, -c opt), both in the guarded-sample rate
limiter's accounting.
GuardedPageAllocator::TrySample counter race (production fix).
NeverRateLimited sets equal guarded and profile sampling intervals and asserts
that no allocation is ever RateLimited. With equal intervals the rate-limit
predicate reduces to num_sampled < num_guarded, which should be impossible
because sampled allocations are a superset of guarded ones. However num_guarded
(successful_allocations_) and num_sampled (total_sampled_count_) are incremented
non-atomically, and by design num_sampled is incremented after num_guarded. A
concurrent or reentrant guarded allocation can bump num_guarded before its
num_sampled increment, so a racing TrySample reads num_sampled < num_guarded and
spuriously returns RateLimited. Clamp the read to the documented invariant
(num_sampled >= num_guarded). This is a no-op in steady state; at equal intervals
it makes rate-limiting provably impossible, and it does not change behavior when
guarded_interval > profile_interval (at the floor num_sampled == num_guarded the
ratio is still 10, which rate-limits as intended).
RateLimited test stop condition (test fix).
The test looped until the first sampled-but-not-guarded allocation and assumed
it must be RateLimited. TrySample also returns Filtered (probabilistic
stacktrace filter) and NoAvailableSlots, so if the first non-guarded sample was
Filtered the window contained no RateLimited sample and the assertion failed.
Accumulate enough guarded allocations that the 2:1 rate limiter is guaranteed to
have produced many RateLimited samples before stopping.
Both tests still assert their original invariants (Guarded+RateLimited present
under a 2:1 interval; never RateLimited under equal intervals).