aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/idr.h
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 14:45:13 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:03 -0400
commit72dba584b695d8bc8c1a50ed54ad4cba7c62314d (patch)
treeb0938ea773953f869b22101bb021e5710d0a0fec /include/linux/idr.h
parente33ac8bdb0c84fe7afd2c45537b763faf28c589e (diff)
ida: implement idr based id allocator
Implement idr based id allocator. ida is used the same way idr is used but lacks id -> ptr translation and thus consumes much less memory. struct ida_bitmap is attached as leaf nodes to idr tree which is managed by the idr code. Each ida_bitmap is 128bytes long and contains slightly less than a thousand slots. ida is more aggressive with releasing extra resources acquired using ida_pre_get(). After every successful id allocation, ida frees one reserved idr_layer if possible. Reserved ida_bitmap is not freed automatically but only one ida_bitmap is reserved and it's almost always used right away. Under most circumstances, ida won't hold on to memory for too long which isn't actively used. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'include/linux/idr.h')
-rw-r--r--include/linux/idr.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 826803449db7..915572fa030b 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -83,4 +83,33 @@ void idr_remove(struct idr *idp, int id);
83void idr_destroy(struct idr *idp); 83void idr_destroy(struct idr *idp);
84void idr_init(struct idr *idp); 84void idr_init(struct idr *idp);
85 85
86
87/*
88 * IDA - IDR based id allocator, use when translation from id to
89 * pointer isn't necessary.
90 */
91#define IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */
92#define IDA_BITMAP_LONGS (128 / sizeof(long) - 1)
93#define IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8)
94
95struct ida_bitmap {
96 long nr_busy;
97 unsigned long bitmap[IDA_BITMAP_LONGS];
98};
99
100struct ida {
101 struct idr idr;
102 struct ida_bitmap *free_bitmap;
103};
104
105#define IDA_INIT(name) { .idr = IDR_INIT(name), .free_bitmap = NULL, }
106#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
107
108int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
109int ida_get_new_above(struct ida *ida, int starting_id, int *p_id);
110int ida_get_new(struct ida *ida, int *p_id);
111void ida_remove(struct ida *ida, int id);
112void ida_destroy(struct ida *ida);
113void ida_init(struct ida *ida);
114
86#endif /* __IDR_H__ */ 115#endif /* __IDR_H__ */