-
Notifications
You must be signed in to change notification settings - Fork 226
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
Implement simple allocator using enif_{alloc,free} #580
Conversation
500cabc
to
86bb26f
Compare
4a21c56
to
62aba90
Compare
TODO: Check with valgrind what's going on |
Locally on my Mac M1 both the Rust and Elixir tests are passing fine, so it might be something specific to the CI? |
Some notes:
|
70f900a
to
182f812
Compare
Reading https://github.com/E-xyza/zigler/blob/main/priv/beam/allocator.zig brought the fix, this works now. |
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.
Cool that this works! :) I left some questions.
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.
Great work! :)
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.
Awesome! 🚀
Since we can only expect a 64bit alignment from the Erlang allocator, we have to ensure larger alignments by overallocating. The allocator for this case behaves the same way as the zigler "large beam allocator", see https://github.com/E-xyza/zigler/blob/main/priv/beam/allocator.zig. If the alignment is greater than 8, we allocate enough memory to store an additional pointer. The result of the initial allocation is then written immediately before the aligned pointer, which is returned from the allocator. When deallocating, we can retrieve the original pointer and pass it on to `enif_free`.
@evnu As requested, added more comments to the allocator. |
Implement a Rust global allocator using Erlang's
enif_alloc
andenif_free
.Rumor has it that this makes Rust's memory usage show up in
erlang:memory()
.The tests are currently reproducibly seg-faulting on Linux x86-64 but run through on arm64.