Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH v4 0/2] lib/raid: replace __get_free_pages() call with kvmalloc()
@ 2026-05-28  9:52 Mike Rapoport (Microsoft)
  2026-05-28  9:53 ` [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
  2026-05-28  9:53 ` [PATCH v4 2/2] raid6: use kmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
  0 siblings, 2 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28  9:52 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Christoph Hellwig, David Laight, Li Nan, Mike Rapoport, Song Liu,
	Xiao Ni, Yu Kuai, linux-kernel, linux-mm, linux-raid,
	Christoph Hellwig

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

Nowadays the right way to say "I need a buffer" is kmalloc() rather than
ancient and ugly __get_free_pages().

---
v4 changes:
* s/kvfee/kfree

v3: https://patch.msgid.link/20260528-lib-v3-0-feccddf1cb6d@kernel.org
* restore kmalloc() per Christoph
* update changelog

v2: https://patch.msgid.link/20260526-lib-v2-0-ca3f0fc24b14@kernel.org
* replace kmalloc() with kvmalloc()

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

---
Mike Rapoport (Microsoft) (2):
      xor: use kmalloc() in calibrate_xor_blocks()
      raid6: use kmalloc() 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] 5+ messages in thread

* [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks()
  2026-05-28  9:52 [PATCH v4 0/2] lib/raid: replace __get_free_pages() call with kvmalloc() Mike Rapoport (Microsoft)
@ 2026-05-28  9:53 ` Mike Rapoport (Microsoft)
  2026-05-28  9:55   ` Hannes Reinecke
  2026-05-28 12:47   ` Christoph Hellwig
  2026-05-28  9:53 ` [PATCH v4 2/2] raid6: use kmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
  1 sibling, 2 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28  9:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Christoph Hellwig, David Laight, Li Nan, Mike Rapoport, Song Liu,
	Xiao Ni, Yu Kuai, linux-kernel, linux-mm, linux-raid

The xor benchmark allocates 4 pages for a scratch buffer that is used
purely as a CPU-only XOR working area.

This buffer can be allocated with kmalloc() as there's nothing special
about it to go directly to the page allocator.

kmalloc() provides a better API than ancient __get_free_pages().
kmalloc() does not require ugly casts and kfree() does not need to know the
size of the freed object.

There is no performance difference because kmalloc() redirects allocations
of such size to the page allocator.

Replace __get_free_pages() call with kmalloc().

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..50931fbf0324 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 = kmalloc(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);
+	kfree(b1);
 	return 0;
 }
 

-- 
2.53.0


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

* [PATCH v4 2/2] raid6: use kmalloc() in raid6_select_algo()
  2026-05-28  9:52 [PATCH v4 0/2] lib/raid: replace __get_free_pages() call with kvmalloc() Mike Rapoport (Microsoft)
  2026-05-28  9:53 ` [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
@ 2026-05-28  9:53 ` Mike Rapoport (Microsoft)
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28  9:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Christoph Hellwig, David Laight, Li Nan, Mike Rapoport, Song Liu,
	Xiao Ni, Yu Kuai, linux-kernel, linux-mm, linux-raid,
	Christoph Hellwig

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

This buffer can be allocated with kmalloc() as there's nothing special
about it to go directly to the page allocator.

kmalloc() provides a better API than ancient __get_free_pages().
kmalloc() does not require ugly casts and kfree() does not need to know the
size of the freed object.

There is no performance difference because kmalloc() redirects allocations
of such size to the page allocator.

Replace __get_free_pages() call with kmalloc().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 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..89e627c62e30 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 = kmalloc(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);
+	kfree(disk_ptr);
 
 	return gen_best && rec_best ? 0 : -EINVAL;
 }

-- 
2.53.0


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

* Re: [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks()
  2026-05-28  9:53 ` [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
@ 2026-05-28  9:55   ` Hannes Reinecke
  2026-05-28 12:47   ` Christoph Hellwig
  1 sibling, 0 replies; 5+ messages in thread
From: Hannes Reinecke @ 2026-05-28  9:55 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Andrew Morton
  Cc: Christoph Hellwig, David Laight, Li Nan, Song Liu, Xiao Ni,
	Yu Kuai, linux-kernel, linux-mm, linux-raid

On 5/28/26 11:53, Mike Rapoport (Microsoft) wrote:
> The xor benchmark allocates 4 pages for a scratch buffer that is used
> purely as a CPU-only XOR working area.
> 
> This buffer can be allocated with kmalloc() as there's nothing special
> about it to go directly to the page allocator.
> 
> kmalloc() provides a better API than ancient __get_free_pages().
> kmalloc() does not require ugly casts and kfree() does not need to know the
> size of the freed object.
> 
> There is no performance difference because kmalloc() redirects allocations
> of such size to the page allocator.
> 
> Replace __get_free_pages() call with kmalloc().
> 
> 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(-)
> 
Reviewed-by: Hannes Reinecke <hare@kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich

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

* Re: [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks()
  2026-05-28  9:53 ` [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
  2026-05-28  9:55   ` Hannes Reinecke
@ 2026-05-28 12:47   ` Christoph Hellwig
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2026-05-28 12:47 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Andrew Morton, Christoph Hellwig, David Laight, Li Nan, Song Liu,
	Xiao Ni, Yu Kuai, linux-kernel, linux-mm, linux-raid

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28  9:52 [PATCH v4 0/2] lib/raid: replace __get_free_pages() call with kvmalloc() Mike Rapoport (Microsoft)
2026-05-28  9:53 ` [PATCH v4 1/2] xor: use kmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
2026-05-28  9:55   ` Hannes Reinecke
2026-05-28 12:47   ` Christoph Hellwig
2026-05-28  9:53 ` [PATCH v4 2/2] raid6: use kmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)

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