简体   繁体   中英

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/doc/jemalloc.html#size_classes .

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.

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 )

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM