Skip to content

Commit f32f004

Browse files
author
Matthew Wilcox
committed
ida: Convert to XArray
Use the XA_TRACK_FREE ability to track which entries have a free bit, similarly to how it uses the radix tree's IDR_FREE tag. This eliminates the per-cpu ida_bitmap preload, and fixes the memory consumption regression I introduced when making the IDR able to store any pointer. Signed-off-by: Matthew Wilcox <willy@infradead.org>
1 parent 371c752 commit f32f004

4 files changed

Lines changed: 213 additions & 263 deletions

File tree

‎include/linux/idr.h‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ static inline void idr_preload_end(void)
214214
++id, (entry) = idr_get_next((idr), &(id)))
215215

216216
/*
217-
* IDA - IDR based id allocator, use when translation from id to
218-
* pointer isn't necessary.
217+
* IDA - ID Allocator, use when translation from id to pointer isn't necessary.
219218
*/
220219
#define IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */
221220
#define IDA_BITMAP_LONGS (IDA_CHUNK_SIZE / sizeof(long))
@@ -225,14 +224,14 @@ struct ida_bitmap {
225224
unsigned long bitmap[IDA_BITMAP_LONGS];
226225
};
227226

228-
DECLARE_PER_CPU(struct ida_bitmap *, ida_bitmap);
229-
230227
struct ida {
231-
struct radix_tree_root ida_rt;
228+
struct xarray xa;
232229
};
233230

231+
#define IDA_INIT_FLAGS (XA_FLAGS_LOCK_IRQ | XA_FLAGS_ALLOC)
232+
234233
#define IDA_INIT(name) { \
235-
.ida_rt = RADIX_TREE_INIT(name, IDR_RT_MARKER | GFP_NOWAIT), \
234+
.xa = XARRAY_INIT(name, IDA_INIT_FLAGS) \
236235
}
237236
#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
238237

@@ -292,7 +291,7 @@ static inline int ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp)
292291

293292
static inline void ida_init(struct ida *ida)
294293
{
295-
INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT);
294+
xa_init_flags(&ida->xa, IDA_INIT_FLAGS);
296295
}
297296

298297
#define ida_simple_get(ida, start, end, gfp) \
@@ -301,9 +300,6 @@ static inline void ida_init(struct ida *ida)
301300

302301
static inline bool ida_is_empty(const struct ida *ida)
303302
{
304-
return radix_tree_empty(&ida->ida_rt);
303+
return xa_empty(&ida->xa);
305304
}
306-
307-
/* in lib/radix-tree.c */
308-
int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
309305
#endif /* __IDR_H__ */

0 commit comments

Comments
 (0)