From: Alexander Gordeev <agordeev@linux.ibm.com>
To: Harry Yoo <harry.yoo@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Daniel Axtens <dja@axtens.net>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
kasan-dev@googlegroups.com, linux-s390@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v6 1/1] kasan: Avoid sleepable page allocation from atomic context
Date: Mon, 12 May 2025 16:22:23 +0200 [thread overview]
Message-ID: <aCIEH5WvkhQreVrV@li-008a6a4c-3549-11b2-a85c-c5cc2836eea2.ibm.com> (raw)
In-Reply-To: <aB3ThByuJtxMpAXi@harry>
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.
prev parent reply other threads:[~2025-05-12 14:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-08 14:15 [PATCH v6 0/1] " Alexander Gordeev
2025-05-08 14:15 ` [PATCH v6 1/1] " Alexander Gordeev
2025-05-09 10:05 ` Harry Yoo
2025-05-12 14:22 ` Alexander Gordeev [this message]
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=aCIEH5WvkhQreVrV@li-008a6a4c-3549-11b2-a85c-c5cc2836eea2.ibm.com \
--to=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=dja@axtens.net \
--cc=harry.yoo@oracle.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=stable@vger.kernel.org \
/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