]> git.karo-electronics.de Git - karo-tx-linux.git/commit
lib, Make gen_pool memory allocator lockless
authorHuang Ying <ying.huang@intel.com>
Wed, 13 Jul 2011 05:14:24 +0000 (13:14 +0800)
committerLen Brown <len.brown@intel.com>
Thu, 14 Jul 2011 03:39:29 +0000 (23:39 -0400)
commitc1b9297cb623c9f2ea33ff6027e8100d76cd9944
treee2f82957072dd1ada3a4bc6c0281a6296123d8a0
parente6c823b7e890e54fb63c6687082a488e9cf3e1e5
lib, Make gen_pool memory allocator lockless

This version of the gen_pool memory allocator supports lockless
operation.

This makes it safe to use in NMI handlers and other special
unblockable contexts that could otherwise deadlock on locks.  This is
implemented by using atomic operations and retries on any conflicts.
The disadvantage is that there may be livelocks in extreme cases.  For
better scalability, one gen_pool allocator can be used for each CPU.

The lockless operation only works if there is enough memory available.
If new memory is added to the pool a lock has to be still taken.  So
any user relying on locklessness has to ensure that sufficient memory
is preallocated.

The basic atomic operation of this allocator is cmpxchg on long.  On
architectures that don't have NMI-safe cmpxchg implementation, the
allocator can NOT be used in NMI handler.  So code uses the allocator
in NMI handler should depend on CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.

Signed-off-by: Huang Ying <ying.huang@intel.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Len Brown <len.brown@intel.com>
include/linux/bitmap.h
include/linux/genalloc.h
lib/bitmap.c
lib/genalloc.c