-
Notifications
You must be signed in to change notification settings - Fork 30
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
Replace dlmalloc with bitmap+buddy allocators #131
Conversation
The code is well documented indeed, but, as you said, we don't know yet the implication on our different applications of such new allocator. It can be interesting to test it with a widely used application such as To clarify the goal of this PR, it's to help our upgrade to OCaml 5, I'm right? One possibility (as we did for Mirage) is to maintain 2 |
Thank you for your feedback! I can explain a bit about my motivations here: I started writing this patch for the 500-cleaned PR because Ocaml 5+ needs So far I tested with About this PR, I think it could be an intermediate step with Ocaml4 before moving to Ocaml5. And I agree with you, it'll be a pain to maintain two |
I didn't observed yet issues, I guess it's ready for review (maybe also related to a potential issue in mirage/ocaml-git#631 and the difficulties around bug tracking). |
And FWIW a couple of notes to have in mind when reviewing:
|
I continued testing and it seems the O(n) time complexity should be avoided (at least with qubes-mirage-fw, I got a bandwidth degradation over time). Another algorithm like TLSF (e.g. https://github.com/mattconte/tlsf) is probably a better candidate and it also seems to have good performance with low fragmentation :) https://www.researchgate.net/publication/234785757_A_comparison_of_memory_allocators_for_real-time_applications |
Hi devs!
The current memory allocation implementation is dlmalloc which provides great performances [1] but with a big amount of code (~6k LoC) and has recently some issues with memory used computation (the
mallinfo
provided is clean but need to walk along the whole heap and a fast pre-computed value was wrongly computed due to a bug in my code :( ). My observation is that the complexity of the code makes it hard to get into.The Ocaml-5 support PR shows that Ocaml 5 now needs
mmap
/munmap
which is not provided by dlmalloc, and this needs some more work.Therefore I resued the bitmap allocator in mirage-xen (for grant pages) to be able to provide page aligned memory areas (this is useful for
mmap
andposix_mem_align
). At the same time I added a binary buddy allocator for small memory requests (32< x <4096), large requests (>=4096) fall back toposix_mem_align
. The code is now shorter (~700 LoC) and it should be simpler to understand (I hope).Naturally I'm unable to provide a deep survey with that allocator :(
I run some basic tests and it works with qubes-mirage-firewall with similar performance, I planed to run long run tests to find some more issues.
The bitmap allocator is similar to a first-fit allocator and will probably lead to fragmentated memory which is not great, it may be possible to find a smarter allocator using linked lists for example at the cost of more code complexity. Time will tell.
[1]: as example a performance survey https://www.researchgate.net/publication/314689739_Experimental_Evaluation_and_Comparison_of_Memory_Allocators_in_the_GNULinux_Operating_System