Skip to content

AdaptivePoolingAllocator: assign a more explicit value to BuddyChunk.freeListCapacity (#16334)#16368

Merged
chrisvest merged 2 commits into
netty:4.1from
chrisvest:4.1-freeListCapacity
Feb 26, 2026
Merged

AdaptivePoolingAllocator: assign a more explicit value to BuddyChunk.freeListCapacity (#16334)#16368
chrisvest merged 2 commits into
netty:4.1from
chrisvest:4.1-freeListCapacity

Conversation

@chrisvest
Copy link
Copy Markdown
Member

@chrisvest chrisvest commented Feb 25, 2026

Motivation:

Currently, the value of BuddyChunk.freeListCapacity is less than the real max size of the freeList.

  1. It may lead to the freeList.drain(freeListCapacity, this) can not drain all the elements at once.
  2. When calling MpscIntQueue.create(freeListCapacity, -1), we rely on MpscIntQueue implicitly calling
    MathUtil.safeFindNextPositivePowerOfTwo(freeListCapacity) to set the proper max size. This makes the code less explicit.
  3. Semantically, freeListCapacity should be equal to the value of capFactor, if I understand correctly.
  4. In addition, use freeListCapacity = capFactor eliminates a bit-shift operation.

Modification:

Use freeListCapacity = capFactor; instead of `freeListCapacity = tree

1;`.

Result:

More clean code.


Co-authored-by: lao
Co-authored-by: Chris Vest [email protected]

(cherry picked from commit b7ec449)

…freeListCapacity (netty#16334)

Motivation:

Currently, the value of `BuddyChunk.freeListCapacity` is less than the
real max size of the `freeList`.
1. It may lead to the `freeList.drain(freeListCapacity, this)` can not
drain all the elements at once.
2. When calling `MpscIntQueue.create(freeListCapacity, -1)`, we rely on
`MpscIntQueue` implicitly calling
`MathUtil.safeFindNextPositivePowerOfTwo(freeListCapacity)` to set the
proper max size. This makes the code less explicit.
3. Semantically, `freeListCapacity` should be equal to the value of
`capFactor`, if I understand correctly.
4. In addition, use `freeListCapacity = capFactor` eliminates a
bit-shift operation.

Modification:

Use `freeListCapacity = capFactor;` instead of `freeListCapacity = tree
>> 1;`.

Result:

More clean code.

---------

Co-authored-by: lao <none>
Co-authored-by: Chris Vest <[email protected]>

(cherry picked from commit b7ec449)
@chrisvest chrisvest added this to the 4.1.132.Final milestone Feb 25, 2026
@chrisvest chrisvest changed the title AdaptivePoolingAllocator: assign a more explicit value to BuddyChunk.… AdaptivePoolingAllocator: assign a more explicit value to BuddyChunk.freeListCapacity (#16334) Feb 25, 2026
@chrisvest chrisvest enabled auto-merge (squash) February 25, 2026 22:48
Comment thread buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java Outdated
@chrisvest chrisvest merged commit 4f46db0 into netty:4.1 Feb 26, 2026
18 checks passed
@chrisvest chrisvest deleted the 4.1-freeListCapacity branch February 26, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants