GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix buddy cache evicting chunks with live buffers (#17154) by franz1981 · Pull Request #17176 · netty/netty

Conversation

@franz1981

@franz1981 franz1981 commented Jul 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@franz1981
franz1981 requested a review from chrisvest July 30, 2026 09:37
@franz1981
franz1981 force-pushed the backport-17154-4.1 branch from bb18a1a to 31df236 Compare July 30, 2026 09:38
@franz1981
Fix buddy cache evicting chunks with live buffers (netty#17154)
3c0cc62
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
franz1981 force-pushed the backport-17154-4.1 branch from 31df236 to 3c0cc62 Compare July 30, 2026 09:41
@franz1981
franz1981 requested a review from Copilot July 30, 2026 13:19
Copilot started reviewing on behalf of franz1981 July 30, 2026 13:19
View session
Copilot AI reviewed Jul 30, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
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 thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
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 chrisvest added this to the 4.1.137.Final milestone Jul 30, 2026
chrisvest
chrisvest approved these changes Jul 30, 2026
View reviewed changes
@chrisvest
chrisvest merged commit 8689960 into netty:4.1 Jul 30, 2026
17 of 18 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari mentioned this pull request Aug 10, 2026
[fix][sec][branch-4.2] Upgrade Netty to 4.1.137 to address several CVEs and bugs apache/pulsar#26301
Merged
2 of 11 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Sep 18, 2026
fix(deps): close the amqp-client credential-leak advisory left open on dev OpenResilienceInitiative/ORISO-UserService#1190
Merged
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@franz1981 @lltopk
Fix buddy cache evicting chunks with live buffers (netty#17154) (nett…
1aea09e
…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)
@franz1981 franz1981 mentioned this pull request Nov 16, 2026
Adaptive allocator may retain chunks beyond reuse cap and exhaust direct memory under burst load #18434
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@chrisvest chrisvest chrisvest approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.137.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@franz1981 @chrisvest
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.