linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Zi Yan <ziy@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Dev Jain <dev.jain@arm.com>, Wei Yang <richard.weiyang@gmail.com>,
	akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com,
	jackmanb@google.com, hannes@cmpxchg.org, linux-mm@kvack.org,
	Oscar Salvador <osalvador@suse.de>
Subject: Re: [PATCH] mm/page_alloc: fix alignment for alloc_contig_pages_noprof()
Date: Wed, 24 Sep 2025 13:32:49 +0200	[thread overview]
Message-ID: <aNPW4Ynrxyn23Ko8@tiehlicka> (raw)
In-Reply-To: <760C8EBD-9201-4680-8B9B-CAD7641A81C4@nvidia.com>

On Tue 23-09-25 11:07:28, Zi Yan wrote:
> On 23 Sep 2025, at 3:48, David Hildenbrand wrote:
> 
> > On 23.09.25 09:06, Anshuman Khandual wrote:
> >> On 23/09/25 7:16 AM, Zi Yan wrote:
> >>> On 22 Sep 2025, at 20:19, 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.
> >>>
> >>> The result would not be any value lower than zone->zone_start_pfn,
> >>> so the worst case is getting an unaligned PFN range. I guess
> >>> most of the time nr_pages would be power of 2.
> >>
> >> Agreed.
> >>
> >> Also as Dev had pointed out earlier, this function gives no
> >> guarantee on alignment of non-power-of-2 requests. Hence I
> >> don't have a strong opinion either way, but does it really
> >> qualify for a "Fixes:" tag ?
> >
> > I'd say if there is nothing to fix, then this patch is not required.
> >
> > What likely does make sense would be that a non-power-of-2 would be aligned to the smallest contained power of 2.
> >
> > E.g., a 6 MiB request would be aligned to 2 MiB instead of multiples of 6 MiB.
> >
> > Not sure what the existing ALIGN would do with that ...
> 
> Something like the code below:
> 
> pfn = ALIGN(zone->zone_start_pfn, rounddown_pow_of_two(nr_pages));

Please let's not try to fix a non-existent problem here. If there is no
alignement requirement then make sure we document it and drop the
existing ALIGN which doesn't seem to serve any actual purpose rather
than make the code more subtle and more obscure for no known reason.
-- 
Michal Hocko
SUSE Labs


  reply	other threads:[~2025-09-24 11:32 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 [this message]
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

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=aNPW4Ynrxyn23Ko8@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox