feat(kernel range reader): Add buffer pooling support for large reads on regional buckets#4852
feat(kernel range reader): Add buffer pooling support for large reads on regional buckets#4852abhishek10004 wants to merge 9 commits into
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request optimizes memory management for large file reads by implementing a buffer pooling strategy. By using a sync.Pool and lazy allocation, the system significantly reduces allocation overhead and memory fragmentation during high-throughput read operations on regional buckets. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces on-demand buffer allocation and recycling using a sync.Pool for vectored reads when the kernel reader is enabled on regional buckets. It refactors ReadRequest to accept a BufferPool interface and updates VectoredWriter to allocate and release buffers dynamically. The review feedback highlights two critical issues: a potential runtime panic in bufferPoolWrapper.Put if the slice capacity is smaller than expected, and a potential memory leak in ReadWithKernelReader if an error occurs during a partial read, as the release callback might not be executed by the FUSE server.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4852 +/- ##
==========================================
+ Coverage 83.67% 83.70% +0.03%
==========================================
Files 170 172 +2
Lines 20948 21026 +78
==========================================
+ Hits 17528 17600 +72
- Misses 2763 2769 +6
Partials 657 657
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
74830c9 to
2b95a8c
Compare
2b95a8c to
7495346
Compare
7495346 to
22011eb
Compare
| package gcsx | ||
|
|
||
| // TestBufferPool is a generic mock implementation of BufferPool used for testing across packages. | ||
| type TestBufferPool struct { |
There was a problem hiding this comment.
Should we use mock instead for unit test?
There was a problem hiding this comment.
I thought about it and for now let's use this stub implementation as well. This allows us to test the state that's needed and also prevents test from getting noisy (otherwise we'd have to add extra statements in all tests). If in future, we need to modify the test pool or add extra functionality, then we can consider moving to mock. Let me know what you think.
Description
Overview
This PR optimizes memory usage and reduces allocation overhead during large file reads by introducing a
sync.Poolfor buffer allocation and refactoring the vectored reading mechanism to allocate buffers on-demand (lazily).High-Level Changes
1. Read Buffer Pooling (
internal/fs)sync.PoolIntegration: Introduced a 1 MiB buffer pool (readBufferPool) infileSystemto reuse read buffers across requests and minimize GC pressure.op.Dst == nil), the filesystem now attaches aBufferPoolwrapper to the read request instead of pre-allocating static slices upfront.2. Lazy Vectored Buffer Allocation (
internal/gcsx)BufferPoolinterface inReadRequest, replacing staticBuffers [][]byteslices. RefactoredVectoredWriterto allocate buffers lazily from the pool up to a requested maximum size as data is read.ReadFromOffsetinVectoredWriterto support zero-copy vectored reading directly from inode sources when source generation is not authoritative.VectoredWriter.Release(), ensuring allocated buffers are returned to the pool immediately upon completion via response callbacks, or on 0-byte reads and early errors.3. Kernel Reader Integration (
internal/gcsx/kernel_readers)KernelRangeReader.ReadAtto stream data into a pool-backedVectoredWriterwhenBufferPoolis provided.4. Comprehensive Testing & Coverage
large_read_regional_test.go) verifying pool allocation and zero-copy read behavior.vectored_writer_test.goin AAA format covering buffer recycling (Release), non-zero offset reads (ReadFromOffset), oversized buffer truncation, pool exhaustion, and zero/negative max size limits.Link to the issue in case of a bug fix.
b/530765312
Testing details
Any backward incompatible change? If so, please explain.