-
Notifications
You must be signed in to change notification settings - Fork 804
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
How to use a preallocated piece of memory as a heap/set of heaps? #53
Comments
Nice suggestion -- it should be not too hard to provide some callback hooks for this. Especially since this is already used internally in the |
An example would be the use of memory on a specific numa node or is this already possible to set ? |
Not him, but what prevents me from using mimalloc right now is to soft-limit the maximum contiguous memory per I'm developing an actor-like system for lua and each lua VM should have a limit on its maximum memory usage, so I'd like to prealloc the whole block at once (as to not introduce contention for a global memory pool) and use some other project to manage this memory region (this is where I'd like to use mimalloc). The actor-like part also means that I'll need to access this region from other threads (but only one thread at most will access it at any given time so I don't need any mutex to protect the There are many possible changes to mimalloc that would work for me. The preallocated piece of memory is one option. |
Interesting; I am interested to add this kind functionality -- also for embedded systems where we only want allocation from a pre-existing memory range. For this, However, I could add an function entry, like: You need more though I think; you also want to turn off any other allocation from the OS; i.e. if the arena memory is exhausted, start returning |
Rereading your comment, I guess you would like to have a specific |
Yes, that's correct! |
I'm not familiar with the mimalloc, so I don't know behaviour details at this point. From your description, that makes sense and it is what I want. What I want is vocabulary (malloc/realloc/free) to manage a reserved memory region that won't be accessed anywhere else. I may access this region from different threads in different moments, but never from two threads at one single time, so I don't need a mutex. If this memory region cannot fulfill some allocation request, the allocation must not fallback to other means (i.e. it must fail). A preallocated piece of memory could work, but your description of reserved arenas could also work. I'm happy with any choice you deem superior/closer-to-mimalloc-design-principles. |
Our use cases is consoles, so it follows your idea of embeded use. I would like to be able to tell mimalloc to use a memory range, and have all heaps use memory from that range. Both the default heaps, but also have a way to create other set of heaps in another area too. eg: 2GB (from address x to y) to be used by all default heaps That and a way to walk a heap are the two features that prevent mimalloc from being used in embeded situations. |
Is this issue being worked on? I would like to see dlmalloc's like |
Just stumbled upon this:
— https://lwn.net/Articles/830154/ So there are more Lua VM users stumbling upon this problem as well. However as I progressed on my Lua actor system I found out that the Lua VM API is quite quite quite tricky to work with. Long story short: there are two contexts to run your code — VM context and non-VM context. Code that runs on non-VM context cannot recover from allocation failures and your program would likely to crash. I can provide details if requested, but I don't think I should be flooding mimalloc issue tracker with Lua-related stuff (plus I'm close to release date so even if there is interest I think having public code samples would help to explain the thing). The solution I came up with was designing this API pattern for code that runs in non-VM context: allocator->enable_reserved_zone();
// many Lua VM calls such as lua_newtable()
allocator->try_reclaim_reserved_zone();
if (allocator->used_reserved_zone_size() != 0)
return ENOMEM;
// code to start/enter VM context The idea is: code running between However given that I'm essentially implementing fallback mechanisms and current mimalloc already implements them I'll probably experiment more here. We'll see. EDIT: And there is the alternative to call |
I'd like to chip in on this thread as we have a similar use case. For memory buffers that are used for communication - in particular, RMA operations between nodes, we would like to pre-allocate a chunk of memory, register it and assign a heap to use this memory and only this memory - and forbid other heaps from using it. We would want potentially to do this with multiple heaps
essentially, to allow mimalloc to act as a more general purpose heap manager for memory where each heap may be bound to a range of addresses. there are some extras, such as registered/pinned memory has a 'key' that is used for remote access, and this would need to be discoverable from the heap.
would be great - a well as something like this to make a heap use the arena exclusively
and then we might need something like
to fetch the registration keys or other mea data about the arena - now we would actually not need that because we'd create a memory block, pass it to mimalloc to use as an arena, bind a heap to it, wrap the metadata and the heap together inside a c++ allocator and store the info we need there - and return the memory registration keys using a fancy pointer if necessary to store address as well as info. Anyway, if there is any progress on custom area/heap management, it would be very useful to know what plans are in development. |
It seems that there's already some community effort on this feature: romange@f89ab56. I'm wondering if such effort could be accepted by the official repo? Thanks! |
I'd like to see this too. For example, I might get some huge page memory for which I'm ultimately responsible to cleanup. But I give it to mimalloc's heap function set and say: here's X bytes. Use it for malloc/free. Then I use that memory via mimalloc. In this way I might better guarantee alignment; I can know the base address and so on. See: |
FYI: this feature can be done with |
Is there any way right now to use a pre-allocated piece of memory for mimalloc? maybe just being able to create a heap with overriden mmap and munmap can be enough.
The text was updated successfully, but these errors were encountered: