Repository navigation
Fix buddy cache evicting chunks with live buffers (#17154) - #17176
Merged
Merged
Conversation
franz1981
force-pushed
the
backport-17154-4.1
branch
from
July 30, 2026 09:38
bb18a1a to
31df236
Compare
Motivation: The shared ConcurrentSkipListChunkCache eviction policy picked the chunk with the lowest refCnt when the cache exceeded CHUNK_REUSE_QUEUE. Since chunks enter the cache with refCnt = 1 + N (N live buffers), evicting them creates zombie chunks: out of the cache, backing buffer still alive until all N buffers release. This caused 16 GB RSS on the AG benchmark. Modification: Only evict chunks where refCnt == 1 (no live buffers — just the base construction reference). If no idle chunk exists, let the cache grow past the cap. markToDeallocate on an idle chunk decrements refCnt to 0, triggering deallocate which frees the backing buffer cleanly. Result: Less memory churn under allocation pressure still allowing it to shrink on subsequence cache requests (cherry picked from commit 34bfcc7)
franz1981
force-pushed
the
backport-17154-4.1
branch
from
July 30, 2026 09:41
31df236 to
3c0cc62
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts the shared Buddy-chunk reuse cache eviction policy in AdaptivePoolingAllocator to avoid evicting/deallocating chunks that still have live buffers, preventing “zombie chunks” and associated RSS growth under allocation pressure.
Changes:
- Restrict eviction to chunks with
refCnt() == 1(idle: no live buffers). - Allow the cache to exceed
CHUNK_REUSE_QUEUEwhen no idle chunks are available to evict.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
621
to
+625
| Chunk candidate = entry.getValue(); | ||
| if (candidate != null) { | ||
| if (toDeallocate == null) { | ||
| toDeallocate = candidate; | ||
| key = entry.getKey(); | ||
| } else { | ||
| int candidateRefCnt = candidate.refCnt(); | ||
| int toDeallocateRefCnt = toDeallocate.refCnt(); | ||
| if (candidateRefCnt < toDeallocateRefCnt || | ||
| candidateRefCnt == toDeallocateRefCnt && | ||
| candidate.capacity() < toDeallocate.capacity()) { | ||
| toDeallocate = candidate; | ||
| key = entry.getKey(); | ||
| } | ||
| } | ||
| if (candidate != null && candidate.refCnt() == 1) { | ||
| toDeallocate = candidate; | ||
| key = entry.getKey(); | ||
| break; |
Comment on lines
618
to
+622
| int key = -1; | ||
| Chunk toDeallocate = null; | ||
| for (IntEntry<Chunk> entry : chunks) { | ||
| Chunk candidate = entry.getValue(); | ||
| if (candidate != null) { | ||
| if (toDeallocate == null) { | ||
| toDeallocate = candidate; | ||
| key = entry.getKey(); | ||
| } else { | ||
| int candidateRefCnt = candidate.refCnt(); | ||
| int toDeallocateRefCnt = toDeallocate.refCnt(); | ||
| if (candidateRefCnt < toDeallocateRefCnt || | ||
| candidateRefCnt == toDeallocateRefCnt && | ||
| candidate.capacity() < toDeallocate.capacity()) { | ||
| toDeallocate = candidate; | ||
| key = entry.getKey(); | ||
| } | ||
| } | ||
| if (candidate != null && candidate.refCnt() == 1) { |
chrisvest
approved these changes
Jul 30, 2026
lltopk
pushed a commit
to lltopk/netty
that referenced
this pull request
Oct 24, 2026
…y#17176) Motivation: The shared ConcurrentSkipListChunkCache eviction policy picked the chunk with the lowest refCnt when the cache exceeded CHUNK_REUSE_QUEUE. Since chunks enter the cache with refCnt = 1 + N (N live buffers), evicting them creates zombie chunks: out of the cache, backing buffer still alive until all N buffers release. This caused 16 GB RSS on the AG benchmark. Modification: Only evict chunks where refCnt == 1 (no live buffers — just the base construction reference). If no idle chunk exists, let the cache grow past the cap. markToDeallocate on an idle chunk decrements refCnt to 0, triggering deallocate which frees the backing buffer cleanly. Result: Less memory churn under allocation pressure still allowing it to shrink on subsequence cache requests (cherry picked from commit franz1981@34bfcc7)
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.
Motivation:
The shared ConcurrentSkipListChunkCache eviction policy picked the chunk
with the lowest refCnt when the cache exceeded CHUNK_REUSE_QUEUE. Since
chunks enter the cache with refCnt = 1 + N (N live buffers), evicting
them creates zombie chunks: out of the cache, backing buffer still alive
until all N buffers release. This caused 16 GB RSS on the AG benchmark.
Modification:
Only evict chunks where refCnt == 1 (no live buffers — just the base
construction reference). If no idle chunk exists, let the cache grow
past the cap. markToDeallocate on an idle chunk decrements refCnt to 0,
triggering deallocate which frees the backing buffer cleanly.
Result:
Less memory churn under allocation pressure still allowing it to shrink
on subsequence cache requests
(cherry picked from commit franz1981@34bfcc7)