]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
raid6: use kmalloc() in raid6_select_algo()
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Thu, 28 May 2026 09:53:01 +0000 (12:53 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jun 2026 21:49:28 +0000 (14:49 -0700)
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
Link: https://lore.kernel.org/20260528-lib-v4-2-4e3ad1277279@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Hannes Reinecke <hare@kernel.org>
Cc: Li Nan <linan122@huawei.com>
Cc: Song Liu <song@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/raid/raid6/algos.c

index a600d585367298c3a6838688076b53aa0744e71d..6f5c89ab2b17be4b84f49cca03d440e5c5464cf6 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/module.h>
 #include <linux/gfp.h>
 #include <linux/raid/pq.h>
+#include <linux/slab.h>
 #include <linux/static_call.h>
 #include <kunit/visibility.h>
 #include "algos.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 = kmalloc(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);
+       kfree(disk_ptr);
 
        return error;
 }