ida: Move ida_bitmap to a percpu variable
When we preload the IDA, we allocate an IDA bitmap. Instead of storing
that preallocated bitmap in the IDA, we store it in a percpu variable.
Generally there are more IDAs in the system than CPUs, so this cuts down
on the number of preallocated bitmaps that are unused, and about half
of the IDA users did not call ida_destroy() so they were leaking IDA
bitmaps.
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
diff --git a/include/linux/idr.h b/include/linux/idr.h
index f58c0a3..2027c7a 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -14,6 +14,7 @@
#include <linux/radix-tree.h>
#include <linux/gfp.h>
+#include <linux/percpu.h>
struct idr {
struct radix_tree_root idr_rt;
@@ -171,9 +172,10 @@
unsigned long bitmap[IDA_BITMAP_LONGS];
};
+DECLARE_PER_CPU(struct ida_bitmap *, ida_bitmap);
+
struct ida {
struct radix_tree_root ida_rt;
- struct ida_bitmap *free_bitmap;
};
#define IDA_INIT { \
@@ -193,7 +195,6 @@
static inline void ida_init(struct ida *ida)
{
INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT);
- ida->free_bitmap = NULL;
}
/**