All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com,
	jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com,
	david@redhat.com, anshuman.khandual@arm.com, linux-mm@kvack.org,
	dev.jain@arm.com, Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH] mm/page_alloc: fix alignment for alloc_contig_pages_noprof()
Date: Wed, 24 Sep 2025 13:31:11 +0200	[thread overview]
Message-ID: <aNPWf-OfqmUn8wzk@tiehlicka> (raw)
In-Reply-To: <20250924000528.plhmkfn4qnx44a6x@master>

On Wed 24-09-25 00:05:28, Wei Yang wrote:
> On Tue, Sep 23, 2025 at 09:29:12AM +0200, Michal Hocko wrote:
> >On Tue 23-09-25 00:19:43, 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.
> >
> >What is the problem you are trying to fix here? The ALIGN is certainly
> >not well defined for nr_pages that is not power of two but does any
> >caller of alloc_contig_pages assumes any specific alignment, especially
> >when nr_pages is not power of two?
> >
> 
> There is no real problem here. The initial thought is ALIGN() don't expect
> non-power_of_two value.
> 
> The discussion above sounds reasonable, we don't need alignment for
> non-power_of_two nr_pages.
> 
> So this looks we can start iteration from zone->zone_start_pfn for
> non-power_of_two nr_pages.
> 
> IMHO, How about the change below?
> 
>     pfn = zone->zone_start_pfn;
>     if (is_power_of_2(nr_pages))
>         pfn = ALIGN(pfn, nr_pages)

Why should we do that if we claim there is no alignment enforced and
therefore it shouldn't be expected. Something like this would merely
create a confusion and subtle bugs in the worst case.
-- 
Michal Hocko
SUSE Labs


      reply	other threads:[~2025-09-24 11:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23  0:19 [PATCH] mm/page_alloc: fix alignment for alloc_contig_pages_noprof() 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
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 [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=aNPWf-OfqmUn8wzk@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=linux-mm@kvack.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.