Thread (18 messages) 18 messages, 6 authors, 2018-06-26

Re: [PATCH v3 3/5] bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free()

From: Andy Shevchenko <hidden>
Date: 2018-06-18 22:52:19
Also in: dm-devel, linux-input, lkml

On Tue, Jun 19, 2018 at 1:01 AM, Dmitry Torokhov
[off-list ref] wrote:
On Mon, Jun 18, 2018 at 2:14 PM Andrew Morton [off-list ref] wrote:
quoted
On Mon, 18 Jun 2018 16:10:01 +0300 Andy Shevchenko [off-list ref] wrote:
quoted
A lot of code become ugly because of open coding allocations for bitmaps.

Introduce three helpers to allow users be more clear of intention
and keep their code neat.

...

+unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags)
+{
+     return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long), flags);
+}
+EXPORT_SYMBOL(bitmap_alloc);
+
+unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+     return bitmap_alloc(nbits, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL(bitmap_zalloc);
+
+void bitmap_free(const unsigned long *bitmap)
+{
+     kfree(bitmap);
+}
+EXPORT_SYMBOL(bitmap_free);
+
I suggest these functions are small and simple enough to justify
inlining them.
We can't as we end up including bitmap.h (by the way of cpumask.h)
form slab.h, so we gen circular dependency. Maybe if we removed memcg
stuff from slab.h so we do not need to include workqueue.h...
I will look at it. It might be doable.
Though I dunno what MM people would say about this. Anyone's name
comes to your mind to ask?

-- 
With Best Regards,
Andy Shevchenko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help