Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] lib/raid: replace __get_free_pages() call with kvmalloc()
@ 2026-05-26 12:50 Mike Rapoport (Microsoft)
  2026-05-26 12:50 ` [PATCH v2 1/2] lib/raid: use kvmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
  2026-05-26 12:50 ` [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
  0 siblings, 2 replies; 8+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-26 12:50 UTC (permalink / raw)
  To: Andrew Morton, Song Liu, Yu Kuai, Li Nan, Xiao Ni
  Cc: David Laight, Mike Rapoport, linux-kernel, linux-mm, linux-raid

This is a (tiny) part of larger work of replacing page allocator calls
with k*malloc:

Also in git:
https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/lib

---
v2 changes:
* replace kmalloc() with kvmalloc()

v1: https://patch.msgid.link/20260520-lib-v1-0-cb3045bef2d8@kernel.org

---
Mike Rapoport (Microsoft) (2):
      lib/raid: use kvmalloc() in calibrate_xor_blocks()
      lib/raid6: use kvmalloc() in raid6_select_algo()

 lib/raid/xor/xor-core.c | 5 +++--
 lib/raid6/algos.c       | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
---
base-commit: 5d6919055dec134de3c40167a490f33c74c12581
change-id: 20260520-lib-8afb92134307

Best regards,
--  
Sincerely yours,
Mike.



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

* [PATCH v2 1/2] lib/raid: use kvmalloc() in calibrate_xor_blocks()
  2026-05-26 12:50 [PATCH v2 0/2] lib/raid: replace __get_free_pages() call with kvmalloc() Mike Rapoport (Microsoft)
@ 2026-05-26 12:50 ` Mike Rapoport (Microsoft)
  2026-05-27  7:32   ` Christoph Hellwig
  2026-05-26 12:50 ` [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
  1 sibling, 1 reply; 8+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-26 12:50 UTC (permalink / raw)
  To: Andrew Morton, Song Liu, Yu Kuai, Li Nan, Xiao Ni
  Cc: David Laight, Mike Rapoport, linux-kernel, linux-mm, linux-raid

The xor benchmark allocates an order 2 (4 pages) scratch buffer that is
used purely as a CPU-only XOR working area.

This buffer does not need to be physically contiguous and can be
allocated with kvmalloc().

Replace __get_free_pages() call with kvmalloc().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 lib/raid/xor/xor-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/raid/xor/xor-core.c b/lib/raid/xor/xor-core.c
index bd4e6e434418..9f90620617cd 100644
--- a/lib/raid/xor/xor-core.c
+++ b/lib/raid/xor/xor-core.c
@@ -8,6 +8,7 @@
 
 #include <linux/module.h>
 #include <linux/gfp.h>
+#include <linux/slab.h>
 #include <linux/raid/xor.h>
 #include <linux/jiffies.h>
 #include <linux/preempt.h>
@@ -114,7 +115,7 @@ static int __init calibrate_xor_blocks(void)
 	if (forced_template)
 		return 0;
 
-	b1 = (void *) __get_free_pages(GFP_KERNEL, 2);
+	b1 = kvmalloc(PAGE_SIZE * 4, GFP_KERNEL);
 	if (!b1) {
 		pr_warn("xor: Yikes!  No memory available.\n");
 		return -ENOMEM;
@@ -132,7 +133,7 @@ static int __init calibrate_xor_blocks(void)
 	pr_info("xor: using function: %s (%d MB/sec)\n",
 	       fastest->name, fastest->speed);
 
-	free_pages((unsigned long)b1, 2);
+	kvfree(b1);
 	return 0;
 }
 

-- 
2.53.0



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

* [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo()
  2026-05-26 12:50 [PATCH v2 0/2] lib/raid: replace __get_free_pages() call with kvmalloc() Mike Rapoport (Microsoft)
  2026-05-26 12:50 ` [PATCH v2 1/2] lib/raid: use kvmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
@ 2026-05-26 12:50 ` Mike Rapoport (Microsoft)
  2026-05-26 17:34   ` Andrew Morton
  2026-05-27  7:33   ` Christoph Hellwig
  1 sibling, 2 replies; 8+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-26 12:50 UTC (permalink / raw)
  To: Andrew Morton, Song Liu, Yu Kuai, Li Nan, Xiao Ni
  Cc: David Laight, Mike Rapoport, linux-kernel, linux-mm, linux-raid

raid6_select_algo() allocates an order 3 (8 pages) buffer that is used
as a scratch area for selection of the best algorithm.

This buffer does not need to be physically contiguous and can be
allocated with kvmalloc().

Replace __get_free_pages() call with kvmalloc().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 lib/raid6/algos.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c
index 799e0e5eac26..1f565c3b63ce 100644
--- a/lib/raid6/algos.c
+++ b/lib/raid6/algos.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/raid/pq.h>
+#include <linux/slab.h>
 #ifndef __KERNEL__
 #include <sys/mman.h>
 #include <stdio.h>
@@ -129,7 +130,6 @@ const struct raid6_recov_calls *const raid6_recov_algos[] = {
 #endif
 
 #define RAID6_TEST_DISKS	8
-#define RAID6_TEST_DISKS_ORDER	3
 
 static inline const struct raid6_recov_calls *raid6_choose_recov(void)
 {
@@ -250,7 +250,7 @@ int __init raid6_select_algo(void)
 	int i, cycle;
 
 	/* prepare the buffer and fill it circularly with gfmul table */
-	disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER);
+	disk_ptr = kvmalloc(PAGE_SIZE * RAID6_TEST_DISKS, GFP_KERNEL);
 	if (!disk_ptr) {
 		pr_err("raid6: Yikes!  No memory available.\n");
 		return -ENOMEM;
@@ -275,7 +275,7 @@ int __init raid6_select_algo(void)
 	/* select raid recover functions */
 	rec_best = raid6_choose_recov();
 
-	free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER);
+	kvfree(disk_ptr);
 
 	return gen_best && rec_best ? 0 : -EINVAL;
 }

-- 
2.53.0



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

* Re: [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo()
  2026-05-26 12:50 ` [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
@ 2026-05-26 17:34   ` Andrew Morton
  2026-05-27  6:38     ` Christoph Hellwig
  2026-05-27  7:33   ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2026-05-26 17:34 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Song Liu, Yu Kuai, Li Nan, Xiao Ni, David Laight, linux-kernel,
	linux-mm, linux-raid, Christoph Hellwig

On Tue, 26 May 2026 15:50:39 +0300 "Mike Rapoport (Microsoft)" <rppt@kernel.org> wrote:

> raid6_select_algo() allocates an order 3 (8 pages) buffer that is used
> as a scratch area for selection of the best algorithm.
> 
> This buffer does not need to be physically contiguous and can be
> allocated with kvmalloc().
> 
> Replace __get_free_pages() call with kvmalloc().

This one needed some massaging due to hch's "cleanup the RAID6 P/Q
library" in mm-nonmm-unstable
(https://lore.kernel.org/20260518051804.462141-1-hch@lst.de)


From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Subject: lib/raid6: use kvmalloc() in raid6_select_algo()
Date: Tue, 26 May 2026 15:50:39 +0300

raid6_select_algo() allocates an order 3 (8 pages) buffer that is used
as a scratch area for selection of the best algorithm.

This buffer does not need to be physically contiguous and can be
allocated with kvmalloc().

Replace __get_free_pages() call with kvmalloc().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Link: https://lore.kernel.org/20260526-lib-v2-2-ca3f0fc24b14@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/raid/raid6/algos.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/lib/raid/raid6/algos.c~lib-raid6-use-kvmalloc-in-raid6_select_algo
+++ a/lib/raid/raid6/algos.c
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/gfp.h>
+#include <linux/slab.h>
 #include <linux/raid/pq.h>
 #include <linux/static_call.h>
 #include <kunit/visibility.h>
@@ -153,7 +154,6 @@ EXPORT_SYMBOL_GPL(raid6_recov_datap);
 
 #define RAID6_TIME_JIFFIES_LG2	4
 #define RAID6_TEST_DISKS	8
-#define RAID6_TEST_DISKS_ORDER	3
 
 static int raid6_choose_gen(void *(*const dptrs)[RAID6_TEST_DISKS],
 		const int disks)
@@ -247,7 +247,7 @@ static int __init raid6_select_algo(void
 	}
 
 	/* prepare the buffer and fill it circularly with gfmul table */
-	disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER);
+	disk_ptr = kvmalloc(PAGE_SIZE * RAID6_TEST_DISKS, GFP_KERNEL);
 	if (!disk_ptr) {
 		pr_err("raid6: Yikes!  No memory available.\n");
 		return -ENOMEM;
@@ -269,7 +269,7 @@ static int __init raid6_select_algo(void
 	/* select raid gen_syndrome function */
 	error = raid6_choose_gen(&dptrs, disks);
 
-	free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER);
+	kvfree(disk_ptr);
 
 	return error;
 }
_



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

* Re: [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo()
  2026-05-26 17:34   ` Andrew Morton
@ 2026-05-27  6:38     ` Christoph Hellwig
  2026-05-27 11:28       ` Mike Rapoport
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2026-05-27  6:38 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Mike Rapoport (Microsoft), Song Liu, Yu Kuai, Li Nan, Xiao Ni,
	David Laight, linux-kernel, linux-mm, linux-raid,
	Christoph Hellwig

On Tue, May 26, 2026 at 10:34:24AM -0700, Andrew Morton wrote:
>  	/* prepare the buffer and fill it circularly with gfmul table */
> -	disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER);
> +	disk_ptr = kvmalloc(PAGE_SIZE * RAID6_TEST_DISKS, GFP_KERNEL);

This changes to vmalloc for no good reason.  It also doesn't use
the _array version for overflow-safe multiplying (not that it matters
much here..)



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

* Re: [PATCH v2 1/2] lib/raid: use kvmalloc() in calibrate_xor_blocks()
  2026-05-26 12:50 ` [PATCH v2 1/2] lib/raid: use kvmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
@ 2026-05-27  7:32   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-05-27  7:32 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Andrew Morton, Song Liu, Yu Kuai, Li Nan, Xiao Ni, David Laight,
	linux-kernel, linux-mm, linux-raid

Can you stick to the xor: prefix used for all commits since moving it
to lib?



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

* Re: [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo()
  2026-05-26 12:50 ` [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
  2026-05-26 17:34   ` Andrew Morton
@ 2026-05-27  7:33   ` Christoph Hellwig
  1 sibling, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-05-27  7:33 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Andrew Morton, Song Liu, Yu Kuai, Li Nan, Xiao Ni, David Laight,
	linux-kernel, linux-mm, linux-raid

Please stick to the raid6: prefix used for all commits since the move
and most before that.



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

* Re: [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo()
  2026-05-27  6:38     ` Christoph Hellwig
@ 2026-05-27 11:28       ` Mike Rapoport
  0 siblings, 0 replies; 8+ messages in thread
From: Mike Rapoport @ 2026-05-27 11:28 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Andrew Morton, Song Liu, Yu Kuai, Li Nan, Xiao Ni, David Laight,
	linux-kernel, linux-mm, linux-raid

On Wed, May 27, 2026 at 08:38:14AM +0200, Christoph Hellwig wrote:
> On Tue, May 26, 2026 at 10:34:24AM -0700, Andrew Morton wrote:
> >  	/* prepare the buffer and fill it circularly with gfmul table */
> > -	disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER);
> > +	disk_ptr = kvmalloc(PAGE_SIZE * RAID6_TEST_DISKS, GFP_KERNEL);
> 
> This changes to vmalloc for no good reason.  It also doesn't use

TBH, I didn't look around and just presumed that order-3 allocation is a
good candidate for vmalloc(). 
But given this runs early on boot, there's no real reason for vmalloc().

> the _array version for overflow-safe multiplying (not that it matters
> much here..)
 
Can do _array if you'd like, no strong feelings here.

-- 
Sincerely yours,
Mike.


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

end of thread, other threads:[~2026-05-27 11:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26 12:50 [PATCH v2 0/2] lib/raid: replace __get_free_pages() call with kvmalloc() Mike Rapoport (Microsoft)
2026-05-26 12:50 ` [PATCH v2 1/2] lib/raid: use kvmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
2026-05-27  7:32   ` Christoph Hellwig
2026-05-26 12:50 ` [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
2026-05-26 17:34   ` Andrew Morton
2026-05-27  6:38     ` Christoph Hellwig
2026-05-27 11:28       ` Mike Rapoport
2026-05-27  7:33   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox