linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Gregory Price <gourry@gourry.net>
To: Zi Yan <ziy@nvidia.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com, akpm@linux-foundation.org, vbabka@suse.cz,
	surenb@google.com, mhocko@suse.com, jackmanb@google.com,
	hannes@cmpxchg.org, osalvador@suse.de, rientjes@google.com,
	david@redhat.com, joshua.hahnjy@gmail.com, fvdl@google.com
Subject: Re: [PATCH v6] page_alloc: allow migration of smaller hugepages during contig_alloc
Date: Sun, 21 Dec 2025 07:42:10 -0500	[thread overview]
Message-ID: <aUfrIqfo0mcGTSVU@gourry-fedora-PF4VCD3F> (raw)
In-Reply-To: <7EED2D83-AE17-49CB-BDB6-954793EAFDBF@nvidia.com>

On Fri, Dec 19, 2025 at 03:46:25PM -0500, Zi Yan wrote:
> On 19 Dec 2025, at 9:26, Gregory Price wrote:
> 
> > On Fri, Dec 19, 2025 at 12:08:00AM +0000, Wei Yang wrote:
> >>> +
> >>> +			page = compound_head(page);
> >>> +			order = compound_order(page);
> >>
> >> The order is get from head page.
> >>
> >>> +			if ((order >= MAX_FOLIO_ORDER) ||
> >>> +			    (nr_pages <= (1 << order)))
> >>> +				return false;
> >>> +
> >>> +			/* No need to check the pfns for this page */
> >>> +			i += (1 << order) - 1;
> >>
> >> So this advance should based on "head page" instead of original page, right?
> >>
> >
> > hm, I think the thought here was that since we're moving forward from
> > start of an aligned chunk, we'd never hit a non-head page - but this
> > may not be true.
> >
> > Will think about this for a bit.
> 
> The sole caller of pfn_range_valid_contig(), alloc_contig_pages_noprof(),
> scans from the beginning of a zone to the end. pfn_range_valid_contig()
> should see head pages all the time, except it scans in the middle of
> a 1GB hugetlb when alloc_contig_pages_noprof() is asking for a smaller
> nr_pages, like 2MB. But in that case, the if above i += (1 << order) - 1
> would return false without reaching it. Basically, to get to
> i += ..., pfn_range_valid_contig() needs to search for nr_pages larger
> than PageHuge(page) and nr_pages is always power of two based on
> alloc_contig_pages_noprof() requirement, but that means
> pfn_range_valid_contig() always sees such PageHuge pages as a whole
> within nr_pages range, thus cannot see a tail PageHuge page at the
> point of i += ....
> 

Thinking about this a bit more, it might be worthwhile to detect this
condiition and just skip that hugepage in the external code.

while (zone_spans_last_pfn(zone, pfn, nr_pages)) {
	if (pfn_range_valid_contig(zone, pfn, nr_pages,
				   skip_hugetlb,
				   &skipped_hugetlb)) {
		... snip ...
	}
	pfn += nr_pages;
	/*
	 * TODO: If the last scanned page was a hugepage that caused
	 *       the zone to be invalid, skip the rest of that page
	 *       (e.g. if we hit a 1GB page trying to allocate a 2MB
	 *       page, skip the entire 1GB instead of scanning the
	 *       same page 1GB/2MB times).
	 */
	 ...
}

But this solves a different problem than this patch, so i will defer.

~Gregory


  parent reply	other threads:[~2025-12-21 12:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18 23:38 Gregory Price
2025-12-19  0:08 ` Wei Yang
2025-12-19 14:26   ` Gregory Price
2025-12-19 20:46     ` Zi Yan
2025-12-19 20:56       ` Gregory Price
2025-12-20  6:37       ` Wei Yang
2025-12-21 11:32         ` Gregory Price
2025-12-21 12:42       ` Gregory Price [this message]
2025-12-19 20:48 ` Zi Yan
2025-12-19 20:59   ` Gregory Price

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=aUfrIqfo0mcGTSVU@gourry-fedora-PF4VCD3F \
    --to=gourry@gourry.net \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=fvdl@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=osalvador@suse.de \
    --cc=richard.weiyang@gmail.com \
    --cc=rientjes@google.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