GeezerVison is showing github.com — Fix buddy cache evicting chunks with live buffers (#17154) by franz1981 · Pull Request #17176 · netty/netty
Conversation
franz1981
commented
Jul 30, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_QUEUE when no idle chunks are available to evict.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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) {
|
Uh oh!
There was an error while loading. Please reload this page.
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)
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|