-
Notifications
You must be signed in to change notification settings - Fork 815
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
Aligned memory allocation #4277
Aligned memory allocation #4277
Conversation
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.
Thanks for the patch. You beat me to it! Pls find my review, sorry there are many of them!
Plus pls find patch to make PJ_HAS_POOL_ALT_API
work (at least compilable):
alt_pool_diff.txt
Note: the API compatibility is broken (potentially) for pool implementors and not pool users. |
Hi! I'm currently "out of my virtual office" and will be back early next week. Regarding alt_pool_diff.txt: is it possible to find this commit somewhere on GH? Or can you push it to my fork, please? |
No worries.
Done, created PR in your fork. I probably can create PR for the other fixes too. |
…nment, and refactor to use unit test API
Pool Alt API and unit testing
…ligned-memory-allocaion # Conflicts: # pjlib/src/pjlib-test/pool.c
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.
minor only
pjlib/include/pj/pool.h
Outdated
@@ -331,6 +331,10 @@ struct pj_pool_t | |||
/** The callback to be called when the pool is unable to allocate memory. */ | |||
pj_pool_callback *callback; | |||
|
|||
/** The default alignment of memory block allocated from this pool | |||
* (must be power of 2). */ | |||
size_t alignment; |
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.
pj_size_t ?
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.
Yes! However see also line 952
/**
* Internal pool.
*/
char pool_buf[256 * (sizeof(size_t) / 4)];
pjlib/include/pj/pool_alt.h
Outdated
@@ -46,6 +46,7 @@ struct pj_pool_t | |||
char obj_name[32]; | |||
pj_size_t used_size; | |||
pj_pool_callback *cb; | |||
size_t alignment; |
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.
pj_size_t
PJ_ASSERT_RETURN(!alignment || PJ_IS_POWER_OF_TWO(alignment), NULL); | ||
|
||
if (alignment < PJ_POOL_ALIGNMENT) | ||
alignment = PJ_POOL_ALIGNMENT; |
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.
It seems this is not specified in the doc, that alignment can't be smaller than PJ_POOL_ALIGNMENT?
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.
added to doc
|
Currently pjsip library supports only global (library level) memory allocation alignment control.
This PR introduce more granular control of this process.
This feature allows to set the default alignment for all subsequent allocations from the pool created here.
The actual allocation alignment will be at least equal to the alignment argument of the function, but not less than PJ_POOL_ALIGNMENT. (Pool created by pj_pool_create() has the default alignment equal to PJ_POOL_ALIGNMENT.)
The second API allow to control the alignment of memory allocated by the current allocation request:
The actual alignment of the allocation will be at least equal to the alignment argument of the function, but not less than the default pool alignment specified when the pool was created.