Is anyone aware of a good/fast single threaded allocator for cases where you don't need/want to pay for thread safety?
If you're single threaded then you'll never have mutex contention so they'll always be fast-path. I'd suggest you actually prove that the memory barriers are actually a problem for you via profiling, since it's somewhat unlikely it is.
Mimalloc – A compact general-purpose allocator
41–50 of 70 posts
Re: Mimalloc – A compact general-purpose allocator
#42Earlier quoted context omitted.
>it looks like it avoids atomics on common cases of malloc and free. That’s a big deal and not all malloc a accomplish that. Many mallocs implementations try to avoid one cache per thread because it can waste a huge amount of memory in applications with thousands of threads opting for per cpu pools or similar solutions. These solutions help with contention but still require atomics (unless using something like restar…
All modern allocator implementations I am aware of (including Hoard and Mesh) use per-thread caches (of a limited size), and thus avoid the use of atomic operations in the common case while also avoiding blowup (wasted memory caused by using a memory allocator that "leaks" -- see the Hoard paper (ASPLOS 2000, https://people.cs.umass.edu/~emery/pubs/berger-asplos2000.pd... ) for a full discussion).
Re: Mimalloc – A compact general-purpose allocator
#43I never like names that require a “pronounced like” note, but cool project regardless.
Given the rather unpredictable nature of English pronunciation that's basically required for any made up word.
Re: Mimalloc – A compact general-purpose allocator
#44I never like names that require a “pronounced like” note, but cool project regardless.
Re: Mimalloc – A compact general-purpose allocator
#45Re: Mimalloc – A compact general-purpose allocator
#46Are there functions available with which I can at run-time query how much OS memory is used, how much handed out in allocations, how many mmap()ed pools are used, and so on? I find that one of the most important features of a malloc library to debug memory usage. glibc has these functions (like malloc_info()) -- they are very bugged in that they return wrong results, but after patching them to be correct, they are su…
Re: Mimalloc – A compact general-purpose allocator
#47We tried mimalloc in ClickHouse and it is two times slower than jemalloc in our common use case https://github.com/microsoft/mimalloc/issues/11
To be clear, your program ran at half speed, right? That's far worse than doubling the time spent in memory-management functions.
Re: Mimalloc – A compact general-purpose allocator
#48Is anyone aware of a good/fast single threaded allocator for cases where you don't need/want to pay for thread safety?
If you're single threaded then you'll never have mutex contention so they'll always be fast-path. I'd suggest you actually prove that the memory barriers are actually a problem for you via profiling, since it's somewhat unlikely it is.
Concurrent algorithms (to which multi-thread capable allocators belong) typically necessitate design and performance compromises which aren't nullified by creating only a single thread.
> I'd suggest you actually prove that the memory barriers are actually a problem for you via profiling, since it's somewhat unlikely it is.
civility's reply to your post is somewhat rude, but they're right. It's rather arrogant to assume that the poster doesn't know what they're doing, without knowing anything about their specific problem. Modern allocators are complex pieces of software, typically with a lot of knobs and dials, and it is entirely plausible that an allocator tuned for single-threaded programs is more performant for a specific use case than a generic multi-thread allocator.
Re: Mimalloc – A compact general-purpose allocator
#49Earlier quoted context omitted.
This allocator appears to have some genuinely interesting things in its multi thread support: - it looks like it avoids atomics on common cases of malloc and free. That’s a big deal and not all malloc a accomplish that. - it looks like it has cleverness specifically for the case that one thread frees an object into another thread’s heap. It seems like this case was given some special consideration - in particular avo…
This is quite possibly an uninformed question, but is it possible to use multiple allocator implementations simultaneously in the same program? Obviously this would introduce additional creative ways in which to mess up memory management, but at least theoretically it seems like it ought to be doable. When I tried to search for information on the topic just now, I found only a few items about using multiple allocator…
Re: Mimalloc – A compact general-purpose allocator
#50The tricky part with allocators is always the multi-threaded setups. Even something as simple as a bunch of threads doing malloc-free in a loop will drop performance of a lot of allocators to the floor, due to some sort of central locking or excessive cache thrashing. This is typically solved by adding per-thread block pools, free lists or some such. If you go further down the rabbit hole, there's a case when blocks…
What if I'm writing code that's strictly single-threaded? Presumably malloc could be simpler and/or faster in this special case? Is there a production-ready allocator that's optimized for single-threaded use?