-
Notifications
You must be signed in to change notification settings - Fork 6
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
Make sure all small allocations (<= 512 bytes) are batched together, #54
Open
greg7mdp
wants to merge
20
commits into
main
Choose a base branch
from
gh_1049
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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.
Resolves #58.
Currently, many nodeos allocations hit the segment manager, which is costly both in time (involves updating a
rbtree
and rebalancing it) and in space overhead (16 to 40 bytes depending on the size allocated).This PR adds a small size allocator, which internally maintains 64 free lists (for allocation sizes from
8
to512
bytes, increment =8
bytes). The first allocation allocates512
units (so511
remain of the free list), reducing the hits of the segment manager allocator by a factor of 512x.Also, the chainbase
node allocator
, which also does batch allocations forundo_index
tree nodes, is also using the small size allocator when allocating more than one value to be pushed into theundo_stack
deque.preallocate
Some tables loaded from the snapshot have a very large number of rows (I saw one with 95 million rows). I thought that instead of allocating by batches of 512 tree nodes, it might be faster to allocate for the 95 million rows in one allocation, which is what I tried with the preallocate.
However my testing didn't show any significant difference, so the call to
preallocate
is commented out incontroller.cpp
. I have left the implementation in case we want to experiment further later.batch size, number of allocators.
When experimenting with the batch size for allocations, it was clear that larger batch sizes provide better performance when loading the snapshot. The same goes with the number of allocators, and 128 allocators (allowing to batch allocations up to 1024 bytes) perform better than 64 allocators (allowing to batch allocations up to 512 bytes).
However, with 128 allocators, and a batch size of 512, some tests fail because the configuration of the chainbase memory segment in the test is too small.
So I added some code that grows the allocation batch size from 32 to 512.:
chainbase/include/chainbase/small_size_allocator.hpp
Lines 84 to 85 in a0797d2
I should note that I originally started at 4 (instead of the current 32), but my testing showed a slowdown compared to using 32 (which I found somewhat surprising).
Why keep the
chainbase_node_allocator
The
chainbase_node_allocator
still has some benefits:small_size_allocator
which is used from multiple threads when loading the snapshot).Why not link into the free list in
get_some
?My experimentation show that not linking newly allocated blocks into the free list is faster (even though the code in
allocate()
is slightly longer):chainbase/include/chainbase/chainbase_node_allocator.hpp
Lines 71 to 80 in a0797d2