Skip to content

Conversation

@cjc25
Copy link
Contributor

@cjc25 cjc25 commented Nov 13, 2025

By rounding up to the nearest page, we avoid repeatedly allocating similar sizes if requests happen to arrive in roughly increasing order.

The GCS client sends messages with 2MiB of data repeatedly when writing a large object. Therefore it has to repeatedly allocate just over 2MiB. This ultimately results in many, many allocations in the fallback buffer pool. In practice rounding up yields at least a 10x reduction in RAM when running 100 concurrent large writes. This is probably not unique to GCS: anyone who sends large messages may be affected.

This change in simpleBufferPool seems worthwhile vs. adding a tier. We use simpleBufferPool for any size greater than 1MiB, so this effectively lets us discover a reasonably tight tier around any large message size that comes in frequently. It increases infrequent allocation sizes by no more than 0.4%.

RELEASE NOTES:

  • mem: round up to nearest 4KiB for pool allocations larger than 1MiB

By rounding up to the nearest page, we avoid repeatedly allocating
similar sizes if requests happen to arrive in roughly increasing order.

The GCS client repeatedly sends messages with 2MiB of data when writing
a large object. Therefore it has to repeatedly allocate just over 2MiB.
This ultimately results in many, many allocations in the fallback buffer
pool. In practice this yields at least a 10x reduction in RAM when
running 100 concurrent large writes. This is probably not unique to GCS:
anyone who sends large messages may be affected.

This change in simpleBufferPool seems worthwhile vs. adding a tier. We
use simpleBufferPool for any size greater than 1MiB, so this effectively
lets us discover a reasonably tight tier around any large message size
that comes in frequently. It increases infrequent allocation sizes by no
more than 0.4%. Adding a single tier to address my specific issue would
increase 1MiB+epsilon allocations to 2MiB+4KiB, and adding more tiers
seems like wasteful over-tuning.

RELEASE NOTES:
* mem: round up to nearest 4KiB for pool allocations larger than 1MiB
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 13, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.33%. Comparing base (e816736) to head (4095e70).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8705      +/-   ##
==========================================
+ Coverage   83.29%   83.33%   +0.03%     
==========================================
  Files         416      416              
  Lines       32267    32268       +1     
==========================================
+ Hits        26876    26889      +13     
+ Misses       4017     4010       -7     
+ Partials     1374     1369       -5     
Files with missing lines Coverage Δ
mem/buffer_pool.go 96.61% <100.00%> (-3.39%) ⬇️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@arjan-bal arjan-bal added Type: Performance Performance improvements (CPU, network, memory, etc) Area: Transport Includes HTTP/2 client/server and HTTP server handler transports and advanced transport features. labels Nov 13, 2025
@arjan-bal arjan-bal added this to the 1.78 Release milestone Nov 13, 2025
@arjan-bal arjan-bal assigned arjan-bal and unassigned cjc25 Nov 14, 2025
Copy link
Contributor

@arjan-bal arjan-bal left a comment

Choose a reason for hiding this comment

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

LGTM. Adding a second reviewer.

@arjan-bal arjan-bal requested a review from easwars November 14, 2025 06:49
@arjan-bal arjan-bal assigned easwars and unassigned arjan-bal Nov 14, 2025
@cjc25
Copy link
Contributor Author

cjc25 commented Nov 17, 2025

Gentle ping on this review. Thanks.

@easwars easwars merged commit 50c6321 into grpc:master Nov 17, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Transport Includes HTTP/2 client/server and HTTP server handler transports and advanced transport features. Type: Performance Performance improvements (CPU, network, memory, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants