Linux RAID subsystem development
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fnnas.com>,
	Li Nan <linan122@huawei.com>, Xiao Ni <xiao@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-raid@vger.kernel.org
Subject: Re: [PATCH 2/2] lib/raid6: use kmalloc() in raid6_select_algo()
Date: Tue, 26 May 2026 17:38:24 +0300	[thread overview]
Message-ID: <ahWwYIOycuWZnETn@kernel.org> (raw)
In-Reply-To: <20260520140657.2b5b5f3b@pumpkin>

On Wed, May 20, 2026 at 02:06:57PM +0100, David Laight wrote:
> On Wed, 20 May 2026 11:17:52 +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.
> 
> Should this code really be using a 4k buffer rather than a PAGE_SIZE one?

Why?
 
> -- David
> 
> > 
> > For such large allocations kmalloc() would fall back to alloc_pages() but
> > still kmalloc() is a better API as it does not require unnecessary
> > castings and may provide more debugging possibilities.
> > 
> > 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/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;
> >  }
> > 
> 
> 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2026-05-26 14:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20  8:17 [PATCH 0/2] lib/raid: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
2026-05-20  8:17 ` [PATCH 1/2] lib/raid: use kmalloc() in calibrate_xor_blocks() Mike Rapoport (Microsoft)
2026-05-20 13:00   ` David Laight
2026-05-20  8:17 ` [PATCH 2/2] lib/raid6: use kmalloc() in raid6_select_algo() Mike Rapoport (Microsoft)
2026-05-20 13:06   ` David Laight
2026-05-26 14:38     ` Mike Rapoport [this message]
2026-05-27  8:37       ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahWwYIOycuWZnETn@kernel.org \
    --to=rppt@kernel.org \
    --cc=david.laight.linux@gmail.com \
    --cc=linan122@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    --cc=yukuai@fnnas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox