Recycles slices allocated by OwnedImpl back to the thread-local freelist#46136
Draft
birenroy wants to merge 4 commits into
Draft
Recycles slices allocated by OwnedImpl back to the thread-local freelist#46136birenroy wants to merge 4 commits into
birenroy wants to merge 4 commits into
Conversation
This change allows mutable slices of default size (16KB) to be recycled back to the thread-local freelist when they are drained and destroyed, rather than being deleted. This reduces memory allocation frequency for steady-state read operations. We introduce a static `recycle` method to `OwnedImplReservationSlicesOwnerMultiple` and call it from `Slice` destructor. To resolve circular dependency, the `Slice` destructor is declared in the class and defined inline at the end of the header. We also make `Slice` a friend of `OwnedImpl` to allow access to the private nested class. Added unit tests in `buffer_test.cc` to verify: - Successful recycling and reuse of default-sized slices. - Non-default-sized slices are not recycled. TAG=agy CONV=95b3d3e4-0d80-4daa-b3ba-7097db5a23ce Signed-off-by: Biren Roy <birenroy@google.com>
Signed-off-by: Biren Roy <birenroy@google.com>
Ensure that the old storage of a Slice is recycled when the Slice is overwritten via move assignment. This occurs during pop_front and pop_back operations in SliceDeque, which are used when draining the buffer. Also update recycling tests to use spoiler allocations, preventing false-positive passes caused by the allocator reusing the same addresses for freed blocks. TAG=agy CONV=95b3d3e4-0d80-4daa-b3ba-7097db5a23ce Signed-off-by: Biren Roy <birenroy@google.com>
Increase the thread-local freelist max size to 32 (4 * MAX_SLICES_) to better support concurrent connections on the same thread without freelist thrashing. Add a multi-buffer benchmark bufferReserveCommitMultiBuffer to simulate concurrent connections and demonstrate the benefit of the larger freelist. TAG=agy CONV=95b3d3e4-0d80-4daa-b3ba-7097db5a23ce Signed-off-by: Biren Roy <birenroy@google.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change allows mutable slices of default size (16KB) to be recycled
back to the thread-local freelist when they are drained and destroyed,
rather than being deleted. This reduces memory allocation frequency
for steady-state read operations.
We introduce a static
recyclemethod toOwnedImplReservationSlicesOwnerMultipleand call it from
Slicedestructor. To resolve circular dependency, theSlicedestructor is declared in the class and defined inline at theend of the header. We also make
Slicea friend ofOwnedImplto allowaccess to the private nested class.
Added unit tests in
buffer_test.ccto verify:This change was entirely generated by the Gemini AI model. I have read the code and
understand how it operates.
Benchmarks before:
Benchmarks after:
Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features: