[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aCIEH5WvkhQreVrV@li-008a6a4c-3549-11b2-a85c-c5cc2836eea2.ibm.com>
Date: Mon, 12 May 2025 16:22:23 +0200
From: Alexander Gordeev <agordeev@...ux.ibm.com>
To: Harry Yoo <harry.yoo@...cle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Andrey Ryabinin <ryabinin.a.a@...il.com>,
Daniel Axtens <dja@...ens.net>, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, kasan-dev@...glegroups.com,
linux-s390@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH v6 1/1] kasan: Avoid sleepable page allocation from
atomic context
On Fri, May 09, 2025 at 07:05:56PM +0900, Harry Yoo wrote:
> > + while (nr_total) {
> > + nr_pages = min(nr_total, PAGE_SIZE / sizeof(data.pages[0]));
> > + nr_populated = alloc_pages_bulk(GFP_KERNEL, nr_pages, data.pages);
> > + if (nr_populated != nr_pages) {
> > + free_pages_bulk(data.pages, nr_populated);
> > + free_page((unsigned long)data.pages);
> > + return -ENOMEM;
> > + }
> > +
> > + data.start = start;
> > + ret = apply_to_page_range(&init_mm, start, nr_pages * PAGE_SIZE,
> > + kasan_populate_vmalloc_pte, &data);
> > + free_pages_bulk(data.pages, nr_pages);
>
> A minor suggestion:
>
> I think this free_pages_bulk() can be moved outside the loop
> (but with PAGE_SIZE / sizeof(data.pages[0]) instead of nr_pages),
Because we know the number of populated pages I think we could
use it instead of maximal (PAGE_SIZE / sizeof(data.pages[0])).
> because alloc_pages_bulk() simply skips allocating pages for any
> non-NULL entries.
>
> If some pages in the array were not used, it doesn't have to be freed;
> on the next iteration of the loop alloc_pages_bulk() can skip
> allocating pages for the non-NULL entries.
Thanks for the suggestion! I will send an updated version.
Powered by blists - more mailing lists