-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Allow aligned allocations in NIFs #6665
Comments
I see that there already is such function in ERTS, but I am not experienced enough right now to come up with an idea how to expose such function there. |
What function are you referring to? |
|
I'm also in need of this (or something similar). For me, I am attempting to use |
@hauleth I added I'll try to create a PR for this. |
currently tracking it in zigler: though here we use a custom allocator for wide alignments: If there's a better internally supported choice, that would be amazing. |
Is your feature request related to a problem? Please describe.
When using Rust (via Rustler) it would be handy to have a way to use Rust
GlobalAlloc
withenif_alloc
function. The problem is thatenif_alloc
do not have counterpart that allows passing alignment, which would be needed there. This can sometimes lead toSIGBUS
errors.Describe the solution you'd like
Have another allocation function (for example
void *enif_alloc_aligned(size_t size, size_t alignment)
) that would allow to explicitly set the alignment. It will then pick themax(erlang_alignment, alignment)
and will use that as the target alignment (AFAIK we can always expand alignment, but never contract it).With such hypothetical function we could then implement Rust
GlobalAlloc
as:Describe alternatives you've considered
I was thinking about implementing this as try and error or by doing some extra magic with allocating more memory than needed and then storing required metadata there, but all of that is just set of hacks, that could be instead implemented directly in OTP.
Additional context
I believe that it would be useful to have such function, as it may help with having Rust global allocator that will allow introspection and observability of memory usage in Rustler NIFs.
The text was updated successfully, but these errors were encountered: