-
Notifications
You must be signed in to change notification settings - Fork 199
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
Fixed memory_pool::min_block_size calculation #110
Conversation
Previously, memory_pool::min_block_size() would not compute true node size in the same way that the individual free list implementations did. For instance, ordered_free_memory_list uses 2*node_size as debug fence memory, which memory_pool was disregarding. This could result in a failure at runtime, if the block was too small for a full node, including debug fences. Now, each free_list impl exposes "actual_node_size(n)", which produces the true required size, given the requested node size. This function is the same as what's used in the real internal size computations. Also hoisted fence_size() into constexpr functions in each free_list implementation, as well as added an "adjusted_node_size" function, which is mainly for readability, to avoid having "x > y ? x : y" repeated. Test added to exercise the bug.
Note: the test added is pretty minimal; I'm curious if there are other tests that you think would be worthwhile. |
static constexpr std::size_t min_node_size = | ||
FOONATHAN_IMPL_DEFINED(free_list::min_element_size); | ||
FOONATHAN_IMPL_DEFINED(free_list::actual_node_size(free_list::min_element_size)); |
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.
This is one part I'm not 100% sure of. Is min_node_size
meant to be the minimum amount that can be requested (in which case I should not change it), or is it meant to be the minimum you'll actually get, as it is in this update?
@MiguelCompany Sure — is it purely a case of adding a new Also: note that the added public functions are all in the |
@jwdevel I'm just a user of this project that has done some contributions. I did contribute the method you are fixing, and that is why I'm commenting on this PR, as I am highly interested on it working properly. I write this just to say that the final judgement should be from @foonathan.
I was just thinking on the
🤔 Even though they are in the Looking at that file, I also see that this PR is missing changes on |
Eh? That type is just a typedef for
Unless I misunderstand something? That aside, I am now adding tests for All that aside, yes, I agree would like to hear back from @foonathan about the public API/ |
You are right! Sorry for the confusion! |
Regarding the failure in
And therefore it allocates 0 new nodes from the chunk, and fails the assert. So it seems like instead of |
I've started reviewing this PR, but I found many API inconsistencies and potential bugs (in my code, not yours). Thank you for doing that, but I'll think I need to refactor a bit of the free list logic in general. For starters, I'm not sure the debug fence size handling of the small node list is correct at all with regard to alignment, and I have absolutely no idea why I'll see what I can come up with. |
@foonathan Do you want me to create an issue for this overall set of problems? I could add some (failing) tests, if you like. |
I think I've already fixed it? |
Oh, my mistake — sorry, I had not seen the pushes you made. |
Previously, memory_pool::min_block_size() would not compute true node
size in the same way that the individual free list implementations did.
For instance, ordered_free_memory_list uses 2*node_size as debug fence
memory, which memory_pool was disregarding. This could result in a
failure at runtime, if the block was too small for a full node,
including debug fences.
Now, each free_list impl exposes "actual_node_size(n)", which produces
the true required size, given the requested node size. This function is
the same as what's used in the real internal size computations.
Also hoisted fence_size() into constexpr functions in each free_list
implementation, as well as added an "adjusted_node_size" function, which
is mainly for readability, to avoid having "x > y ? x : y" repeated.
Test added to exercise the bug.
Addresses issue #109