From: Mike Rapoport (Microsoft) Date: Thu, 28 May 2026 09:53:01 +0000 (+0300) Subject: raid6: use kmalloc() in raid6_select_algo() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=19c000ba93d609e15e95fed76a9e3b8055833098;p=thirdparty%2Fkernel%2Flinux.git raid6: use kmalloc() in raid6_select_algo() 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) Reviewed-by: Christoph Hellwig Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Li Nan Cc: Song Liu Signed-off-by: Andrew Morton --- diff --git a/lib/raid/raid6/algos.c b/lib/raid/raid6/algos.c index a600d5853672..6f5c89ab2b17 100644 --- a/lib/raid/raid6/algos.c +++ b/lib/raid/raid6/algos.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #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; }