All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bitmap: Add bitmap_valloc(), bitmap_vzalloc() and bitmap_vfree()
@ 2018-12-27 16:18 Peng Wang
  2018-12-28 23:41 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Peng Wang @ 2018-12-27 16:18 UTC (permalink / raw)
  To: andriy.shevchenko, linux, ynorov, arnd, rocking, courbet, osandov, akpm
  Cc: linux-kernel

Introduce bitmap alloc/free helpers when contiguous
memory is not necessary.

Signed-off-by: Peng Wang <rocking@whu.edu.cn>
---
 include/linux/bitmap.h |  3 +++
 lib/bitmap.c           | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index f58e97446abc..aaad1b33dfd5 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -111,6 +111,9 @@
 extern unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags);
 extern unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags);
 extern void bitmap_free(const unsigned long *bitmap);
+extern unsigned long *bitmap_valloc(unsigned int nbits, gfp_t flags);
+extern unsigned long *bitmap_vzalloc(unsigned int nbits, gfp_t flags);
+extern void bitmap_vfree(const unsigned long *bitmap);
 
 /*
  * lib/bitmap.c provides these functions:
diff --git a/lib/bitmap.c b/lib/bitmap.c
index eead55aa7170..739597e436ad 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -1139,6 +1139,25 @@ void bitmap_free(const unsigned long *bitmap)
 }
 EXPORT_SYMBOL(bitmap_free);
 
+unsigned long *bitmap_valloc(unsigned int nbits, gfp_t flags)
+{
+	return kvmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long),
+			     flags);
+}
+EXPORT_SYMBOL(bitmap_valloc);
+
+unsigned long *bitmap_vzalloc(unsigned int nbits, gfp_t flags)
+{
+	return bitmap_valloc(nbits, flags | __GFP_ZERO);
+}
+EXPORT_SYMBOL(bitmap_vzalloc);
+
+void bitmap_vfree(const unsigned long *bitmap)
+{
+	kvfree(bitmap);
+}
+EXPORT_SYMBOL(bitmap_vfree);
+
 #if BITS_PER_LONG == 64
 /**
  * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bitmap: Add bitmap_valloc(), bitmap_vzalloc() and bitmap_vfree()
  2018-12-27 16:18 [PATCH] bitmap: Add bitmap_valloc(), bitmap_vzalloc() and bitmap_vfree() Peng Wang
@ 2018-12-28 23:41 ` Andrew Morton
  2018-12-29  3:11   ` 王鹏
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2018-12-28 23:41 UTC (permalink / raw)
  To: Peng Wang
  Cc: andriy.shevchenko, linux, ynorov, arnd, courbet, osandov, linux-kernel

On Fri, 28 Dec 2018 00:18:29 +0800 Peng Wang <rocking@whu.edu.cn> wrote:

> Introduce bitmap alloc/free helpers when contiguous
> memory is not necessary.

That's a large bitmap you have there.  What code needs this?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH] bitmap: Add bitmap_valloc(), bitmap_vzalloc() and bitmap_vfree()
  2018-12-28 23:41 ` Andrew Morton
@ 2018-12-29  3:11   ` 王鹏
  0 siblings, 0 replies; 3+ messages in thread
From: 王鹏 @ 2018-12-29  3:11 UTC (permalink / raw)
  To: andrew morton
  Cc: andriy.shevchenko, linux, ynorov, arnd, courbet, osandov, linux-kernel

On Date: Fri, 28 Dec 2018 15:41:37 -0800 Andrew Morton <akpm@linux-foundation.org> wrote:

> From: "Andrew Morton" <akpm@linux-foundation.org>
> Sent Time: 2018-12-29 07:41:37 (Saturday)
> To: "Peng Wang" <rocking@whu.edu.cn>
> Cc: andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, ynorov@caviumnetworks.com, arnd@arndb.de, courbet@google.com, osandov@fb.com, linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] bitmap: Add bitmap_valloc(), bitmap_vzalloc() and bitmap_vfree()
> 
> On Fri, 28 Dec 2018 00:18:29 +0800 Peng Wang <rocking@whu.edu.cn> wrote:
> 
> > Introduce bitmap alloc/free helpers when contiguous
> > memory is not necessary.
> 
> That's a large bitmap you have there.  What code needs this?

Hi Andrew,
Not only for large bitmap. This can also benefit from high memory pressure with no requirement for physical continuousness.

While these two casees are rather rare. And I only find one place in mm/swapfile.c.

3224         /* frontswap enabled? set up bit-per-page map for frontswap */
3225         if (IS_ENABLED(CONFIG_FRONTSWAP))
3226                 frontswap_map = kvcalloc(BITS_TO_LONGS(maxpages),
3227                                          sizeof(long),
3228                                          GFP_KERNEL);

I am not sure whether these helper functions can gain as much benefits as the efforts to introduce them.

Cheers,
Peng

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-29  4:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-27 16:18 [PATCH] bitmap: Add bitmap_valloc(), bitmap_vzalloc() and bitmap_vfree() Peng Wang
2018-12-28 23:41 ` Andrew Morton
2018-12-29  3:11   ` 王鹏

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.