From: Dev Jain <dev.jain@arm.com>
To: Wei Yang <richard.weiyang@gmail.com>,
akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com,
mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org,
ziy@nvidia.com, david@redhat.com, anshuman.khandual@arm.com
Cc: linux-mm@kvack.org, Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH] mm/page_alloc: fix alignment for alloc_contig_pages_noprof()
Date: Tue, 23 Sep 2025 12:17:48 +0530 [thread overview]
Message-ID: <fbbdd325-a8c4-46b3-b303-a8082a11548e@arm.com> (raw)
In-Reply-To: <20250923001943.2479-1-richard.weiyang@gmail.com>
On 23/09/25 5:49 am, Wei Yang wrote:
> Commit 5e27a2df03b8 ("mm/page_alloc: add alloc_contig_pages()")
> introduced generic method for alloc_contig_pages(). But the alignment
> calculation seems wrong.
>
> Since ALIGN() only accept power of two value, while nr_pages could be
> any positive one, the result is not defined.
>
> Use roundup() to calculate the correct alignment.
>
> Fixes: 5e27a2df03b8 ("mm/page_alloc: add alloc_contig_pages()")
The ALIGN() statement was even before this, but not sure if a potential
caller with non-power-of-2 nr_pages was present then.
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Oscar Salvador <osalvador@suse.de>
> Cc: Brendan Jackman <jackmanb@google.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Wei Yang <richard.weiyang@gmail.com>
> Cc: Zi Yan <ziy@nvidia.com>
> ---
> mm/page_alloc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index a1bcc1e003c7..a17a6014e3db 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7095,7 +7095,7 @@ struct page *alloc_contig_pages_noprof(unsigned long nr_pages, gfp_t gfp_mask,
> gfp_zone(gfp_mask), nodemask) {
> spin_lock_irqsave(&zone->lock, flags);
>
> - pfn = ALIGN(zone->zone_start_pfn, nr_pages);
> + pfn = roundup(zone->zone_start_pfn, nr_pages);
> while (zone_spans_last_pfn(zone, pfn, nr_pages)) {
> if (pfn_range_valid_contig(pfn, nr_pages)) {
> /*
The kernel-doc above alloc_contig_pages_noprof reads:
"If nr_pages is a power of two, then allocated range is always guaranteed
to be aligned to same nr_pages." This means that the function gives no
guarantee on alignment of non-power-of-2 requests - and why should it?
It doesn't make any sense to align pfn to 7 if nr_pages is 7.
next prev parent reply other threads:[~2025-09-23 6:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 0:19 Wei Yang
2025-09-23 1:46 ` Zi Yan
2025-09-23 7:06 ` Anshuman Khandual
2025-09-23 7:48 ` David Hildenbrand
2025-09-23 15:07 ` Zi Yan
2025-09-24 11:32 ` Michal Hocko
2025-09-24 11:40 ` David Hildenbrand
2025-09-24 12:01 ` Michal Hocko
2025-09-24 12:19 ` David Hildenbrand
2025-09-25 8:14 ` Michal Hocko
2025-09-25 9:22 ` David Hildenbrand
2025-09-25 9:50 ` Michal Hocko
2025-09-23 6:47 ` Dev Jain [this message]
2025-09-23 15:05 ` Zi Yan
2025-09-23 7:29 ` Michal Hocko
2025-09-24 0:05 ` Wei Yang
2025-09-24 11:31 ` Michal Hocko
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=fbbdd325-a8c4-46b3-b303-a8082a11548e@arm.com \
--to=dev.jain@arm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=richard.weiyang@gmail.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=ziy@nvidia.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