Re: [PATCH v2 2/2] lib/raid6: use kvmalloc() in raid6_select_algo()
From: Andrew Morton
Date: Tue May 26 2026 - 13:57:16 EST
On Tue, 26 May 2026 15:50:39 +0300 "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx> 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@xxxxxx)
From: "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx>
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@xxxxxxxxxx
Link: https://lore.kernel.org/20260526-lib-v2-2-ca3f0fc24b14@xxxxxxxxxx
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---
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;
}
_