Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon Aug 9 10:17:27 PDT 2010
On Aug 9, 2010, at 9:54 AM, Török Edwin wrote:
> With mmap() it is always possible to fully release the memory once you
> are done using it.
Sure. Is that the goal, though? Why isn't malloc doing it already?
> With malloc() no, it takes just 1 allocation at the end of the heap to
> keep all the rest allocated. That wouldn't be a problem if libc would
> use mmap() as the low-level allocator for malloc but it doesn't.
> It uses sbrk() mostly for small (<128k) allocations, and even with
> mmaps it caches them for a while.
Recommended reading: http://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemalloc.pdf
> I think that is because mmap() is slow in multithreaded apps, since it
> needs to take a process level lock, which also contends with the lock
> taken by pagefaults from other existing mmaps (in fact that lock is held
> during disk I/O!).
Sounds awesome, let's do that ;-)
You are also leaving a bunch of 4K holes in your address space. On 32-bit systems, address space is a scarce resource.
More information about the llvm-dev