-
Notifications
You must be signed in to change notification settings - Fork 35
Improve coarse_alloc()
#1249
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
base: main
Are you sure you want to change the base?
Improve coarse_alloc()
#1249
Conversation
The sanitizers CI builds fail, because #1225 has not been merged yet. |
*resultPtr = NULL; | ||
// If the block that we want to reuse has a greater size, split it. | ||
// Try to merge the split part with the successor if it is not used. | ||
enum { ACTION_NONE = 0, ACTION_USE, ACTION_SPLIT } action = ACTION_NONE; |
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.
ACTION_NONE
AFAIK, starting enum entry is 0
, so there is no need to set it up.
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.
Right, but IMHO it is more readable as it is now
609a850
to
fd816f5
Compare
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.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (1)
- src/coarse/coarse.c: Language not supported
fd816f5
to
2718712
Compare
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.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (1)
- src/coarse/coarse.c: Language not supported
2718712
to
7a075dd
Compare
Refactor coarse_alloc(): move the code responsible for handling the `(curr == NULL)` case just after `curr = find_free_block()`. Add coarse_add_free_block(). Now (before this change) when a user calls `coarse_alloc(1, 2MB)` (allocate 1 byte with 2MB alignment) and there is no suitable blok inside the coarse allocator, a new block is allocated from the provider of size `coarse->page_size` at least, but it is added to the inner lists with the requested size of only 1 byte and the rest of space will not be able to be utilized. After this change, when a user calls `coarse_alloc(1, 2MB)` (allocate 1 byte with 2MB alignment) and there is no suitable blok inside the coarse allocator, a new block is allocated from the provider of size `alignment` (>= `coarse->page_size`) and it is added to the inner lists with the `alignment` size. The new free block will be used as a whole or split and the rest of space can be utilized later. Signed-off-by: Lukasz Dorau <[email protected]>
7a075dd
to
3a8cbaa
Compare
@bratpiorka please review |
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.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (1)
- src/coarse/coarse.c: Language not supported
Description
Improve
coarse_alloc()
: move the code responsible for handling the(curr == NULL)
case just aftercurr = find_free_block()
. Addcoarse_add_free_block()
.Now (before this change) when a user calls
coarse_alloc(1, 2MB)
(allocate 1 byte with 2MB alignment) and there is no suitable blok inside the coarse allocator, a new block is allocated from the provider of sizecoarse->page_size
at least, but it is added to the inner lists with the requested size of only 1 byte and the rest of space will not be able to be utilized.After this change, when a user calls
coarse_alloc(1, 2MB)
(allocate 1 byte with 2MB alignment) and there is no suitable blok inside the coarse allocator, a new block is allocated from the provider of sizealignment
(>=coarse->page_size
) and it is added to the inner lists with thealignment
size. The new free block will be used as a whole or split and the rest of space can be utilized later.The sanitizers CI builds fail, because #1225 has not been merged yet.
Checklist