Small block allocator on Linux (or RedHat Linux) to avoid memory fragmentation
I know that there is an allocator for user applications than handles lots of small block allocation on HP-UX link text and on Windows XP Low-fragmentation Heap. On HP-UX it is possible to tune the allocator and on Windows XP it considers block of size less than 16 K as small.
My problem is that I can't find any information about this kind of allocator for user programs running on Linux (RedHat Linux actually). If there is such an allocator I actually would like to find what maximum size of blocks it can handle.
Update I have found jemalloc (http://www.canonware.com/jemalloc/). It handles small, large and huge blocks: http://www.canonware.com/download/jemalloc/jemalloc-latest/do开发者_如何学Pythonc/jemalloc.html#size_classes.
Redhat Linux or any Linux based distributions mostly use DL-Malloc (http://gee.cs.oswego.edu/dl/html/malloc.html).
For user applications as Kirill pointed out, better to use separate memory allocators if fragmentation is more because of smaller blocks.
If the user application is small, you can try using C++ placement new/delete which can override the default allocator pattern. (http://en.wikipedia.org/wiki/Placement_syntax)
As platform independent solution try Boost.Pool Library. It has pool
interface that can handle blocks of any size. You can use also pool_alloc
which satisfy Standard Allocator requirements.
As platform specific solution you could try mallopt function from glibc library. But as far as I know it will be not helpful for small blocks.
It's a general-purpose allocator, but the Hoard heap claims to have "strict bounds on fragmentation" [1]:
All of the blocks in a superblock are in the same size class. By using size classes that are a power of b apart (where b is greater than 1) and rounding the requested size up to the nearest size class, we bound worst-case internal fragmentation within a block to a factor of b. In order to reduce external fragmentation, we recycle completely empty superblocks for re-use by any size class.
Dunno if it would help, but it's easy enough to try it out.
TCMalloc:Thread-Caching Malloc
A good alternative has been found to the default Linux allocator.
精彩评论