-
Notifications
You must be signed in to change notification settings - Fork 19
Use red-black-tree in zone_malloc #710
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
Open
devreal
wants to merge
4
commits into
ICLDisco:master
Choose a base branch
from
devreal:zone-malloc-rbtree
base: master
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.
Open
Conversation
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
946099b to
8e51c3f
Compare
bosilca
reviewed
Nov 25, 2024
parsec/class/parsec_rbtree.c
Outdated
| parsec_rbtree_node_construct, NULL); | ||
|
|
||
| void parsec_rbtree_init(parsec_rbtree_t* tree, size_t offset) { | ||
| tree->nil = PARSEC_OBJ_NEW(parsec_rbtree_node_t); |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of allocating the nil you can make it point to the tree itself. The code only uses it to compare for end, of branches, so it should work just fine.
Contributor
|
It would be interesting to see a comparison with the current allocator. |
8e51c3f to
9601f2f
Compare
Currently, zone_malloc iterates linearly over its blocks, leading to O(N) complexity and significant overhead if all blocks are taken. We now use a red-black-tree to order lists of free blocks in a binary search tree. Lookup, insert, and delete are log(N). If all blocks are taken lookup is constant. When allocating memory, we look for blocks or the requested size or the next larger size. In the latter case, the block is split and put back into the tree, potentially allocating a new node. When releasing a block, it is either inserted directly or merged with its predecessor/successor blocks, which are then removed and reinserted as a larger block. In the previous scheme, freeing had O(1) complexity, which is now O(log(N)). However, the vastly better worst-case complexity will amortize this. Plus, using a binary search tree will help reuse of same-size fragments and avoids splitting larger segements when possible. RB trees have lower average complexity than AVL trees and are widely used (C++ std::map, Linux kernel allocator). Signed-off-by: Joseph Schuchart <joseph.schuchart@stonybrook.edu>
Signed-off-by: Joseph Schuchart <joseph.schuchart@stonybrook.edu>
Zone allocators are used exclusively single-threaded. Signed-off-by: Joseph Schuchart <joseph.schuchart@stonybrook.edu>
8a69809 to
89f418a
Compare
Signed-off-by: Joseph Schuchart <joseph.schuchart@stonybrook.edu>
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.
Currently, zone_malloc iterates linearly over its blocks, leading to O(N) complexity and significant overhead if all blocks are taken. We now use a red-black-tree to order lists of free blocks in a binary search tree. Lookup, insert, and delete are log(N). If all blocks are taken lookup is constant.
When allocating memory, we look for blocks or the requested size or the next larger size. In the latter case, the block is split and put back into the tree, potentially allocating a new node.
When releasing a block, it is either inserted directly or merged with its predecessor/successor blocks, which are then removed and reinserted as a larger block.
In the previous scheme, freeing was of O(1) complexity, which is now O(log(N)). However, the better worst-case complexity will amortize this. Plus, using a binary search tree will help reuse of same-size fragments and avoids splitting larger segements when possible.
RB trees have lower average complexity than AVL trees and are widely used (C++ std::map, Linux kernel allocator).