summaryrefslogtreecommitdiff
path: root/include/linux/bitmap.h
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2011-07-13 09:14:24 +0400
committerLen Brown <len.brown@intel.com>2011-08-03 19:15:57 +0400
commit7f184275aa306046fe7edcbef3229754f0d97402 (patch)
treee2f82957072dd1ada3a4bc6c0281a6296123d8a0 /include/linux/bitmap.h
parentf49f23abf3dd786ddcac1c1e7db3c2013b07413f (diff)
downloadlinux-7f184275aa306046fe7edcbef3229754f0d97402.tar.xz
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>
Diffstat (limited to 'include/linux/bitmap.h')
-rw-r--r--include/linux/bitmap.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index dcafe0bf0005..907dd58aa228 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -145,6 +145,7 @@ extern void bitmap_release_region(unsigned long *bitmap, int pos, int order);
extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order);
extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
+#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
#define BITMAP_LAST_WORD_MASK(nbits) \
( \
((nbits) % BITS_PER_LONG) ? \