Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mem: use slice capacity instead of length, to determine whether to pool buffers or directly allocate them #7702

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PapaCharlie
Copy link
Contributor

@PapaCharlie PapaCharlie commented Oct 4, 2024

Fixes #7631

As the issue states, mem.NewBuffer would not pool buffers with a length below the pooling threshold but whose capacity is actually larger than the pooling threshold. This can lead to buffers being leaked.

RELEASE NOTES:

  • mem: use slice capacity instead of length, to determine whether to pool buffers or directly allocate them

Copy link

linux-foundation-easycla bot commented Oct 4, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: PapaCharlie / name: Paul Chesnais (aed354b)

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.88%. Comparing base (98d1550) to head (aed354b).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7702      +/-   ##
==========================================
+ Coverage   81.80%   81.88%   +0.07%     
==========================================
  Files         361      361              
  Lines       27827    27827              
==========================================
+ Hits        22765    22786      +21     
+ Misses       3861     3848      -13     
+ Partials     1201     1193       -8     
Files with missing lines Coverage Δ
mem/buffers.go 86.86% <100.00%> (+3.03%) ⬆️

... and 17 files with indirect coverage changes

As the issue states, `mem.NewBuffer` would not pool buffers with a length below
the pooling threshold but whose capacity is actually larger than the pooling
threshold. This can lead to buffers being leaked.
Copy link
Contributor

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@purnesh42H
Copy link
Contributor

@dfawley @easwars for second review

@easwars easwars changed the title Address #7631 by correctly pooling large-capacity buffers mem: use slice capacity instead of length, to determine whether to pool buffers or directly allocate them Oct 8, 2024
Copy link
Contributor

@easwars easwars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, modulo minor nits.

Comment on lines +95 to +97
// Use the buffer's capacity instead of the length, otherwise buffers may not be reused under certain
// conditions. For example, if a large buffer is acquired from the pool, but fewer bytes than the
// buffering threshold are written to it, the buffer will not be returned to the pool.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can you please wrap the comment lines, here and elsewhere in this PR, to 80-cols. Thanks.

mem.NewBuffer(&b, pool).Free()

if pool.data != nil {
t.Fatalf("buffer not returned to pool")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/buffer/Buffer

@easwars easwars assigned PapaCharlie and unassigned easwars and dfawley Oct 8, 2024
@easwars easwars added this to the 1.68 Release milestone Oct 8, 2024
@purnesh42H purnesh42H modified the milestones: 1.68 Release, 1.69 Release Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mem.NewBuffer() should look at slice capacity?
4 participants