All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Scally" <dan.scally@ideasonboard.com>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>,
	"Brendan Jackman" <brendan.jackman@linux.dev>,
	"Zi Yan" <ziy@nvidia.com>, "David Hildenbrand" <david@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, hughd@google.com, kieran.bingham@ideasonboard.com
Subject: Re: [PATCH 2/2] mm: cma: Pass ACR_FLAGS_LAZY to alloc_contig_frozen_range()
Date: Thu, 03 Dec 2026 15:14:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-248086@kernel.org> (raw)
In-Reply-To: <20261202-lazy-cma-allocation-v1-2-af432f823fbd@ideasonboard.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm: cma: migration thrashing in cma_range_alloc() on
  ACR_FLAGS_LAZY pass
--

commit bff27908fdd0da13045bbc4d2d80382f106a9a63
Author: Daniel Scally <dan.scally@ideasonboard.com>

mm: cma: Pass ACR_FLAGS_LAZY to alloc_contig_frozen_range()

This commit reworks cma_range_alloc() to attempt contiguous allocation across
the CMA range with ACR_FLAGS_LAZY first, falling back to a second pass
without ACR_FLAGS_LAZY if the first pass returns -EBUSY.

> diff --git a/mm/cma.c b/mm/cma.c
> index 0c97aadcfea40..22a9c203cafb9 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -706,9 +706,10 @@ static void cma_debug_show_areas(struct cma *cma)
>  	spin_unlock_irq(&cma->lock);
>  }
>  
> -static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr,
> -				unsigned long count, unsigned int align,
> -				struct page **pagep, gfp_t gfp)
> +static int __cma_range_alloc(struct cma *cma, struct cma_memrange *cmr,
> +			     unsigned long count, unsigned int align,
> +			     struct page **pagep, gfp_t gfp,
> +			     acr_flags_t alloc_flags)
>  {
>  	unsigned long bitmap_maxno, bitmap_no, bitmap_count;
>  	unsigned long start, pfn, mask, offset;
> @@ -766,7 +767,7 @@ static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr,
>  		spin_unlock_irq(&cma->lock);
>  
>  		mutex_lock(&cma->alloc_mutex);
> -		ret = alloc_contig_frozen_range(pfn, pfn + count, ACR_FLAGS_CMA, gfp);
> +		ret = alloc_contig_frozen_range(pfn, pfn + count, alloc_flags, gfp);
>  		mutex_unlock(&cma->alloc_mutex);
>  		if (!ret)
>  			break;
> @@ -786,6 +787,21 @@ static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr,
>  	return ret;
>  }
>  
> +static int cma_range_alloc(struct cma *cma, struct cma_memrange *cmr,
> +			   unsigned long count, unsigned int align,
> +			   struct page **pagep, gfp_t gfp)
> +{
> +	int ret;
> +
> +	ret = __cma_range_alloc(cma, cmr, count, align, pagep, gfp,
> +				ACR_FLAGS_CMA | ACR_FLAGS_LAZY);
> +	if (ret == -EBUSY)
> +		ret = __cma_range_alloc(cma, cmr, count, align, pagep, gfp,
> +					ACR_FLAGS_CMA);
> +
> +	return ret;
> +}

[Severity: High]
Can the ACR_FLAGS_LAZY pass thrash page migrations across the entire CMA
range instead of failing fast when movable pages sit in per-CPU LRU batches?

In __alloc_contig_migrate_range(), ACR_FLAGS_LAZY only skips
lru_cache_disable() while still running the full pageblock isolation,
reclaim, and 5-try synchronous migrate_pages() loop on every candidate window
in cmr->bitmap:

mm/page_alloc.c:__alloc_contig_migrate_range() {
	...
	if (!(alloc_flags & ACR_FLAGS_LAZY))
		lru_cache_disable();

	while (pfn < end || !list_empty(&cc->migratepages)) {
	...
}

When a window contains a folio queued in a per-CPU LRU batch,
alloc_contig_frozen_range() still migrates all other LRU folios out of the
window (or retries migration 5 times if the batched folio is file-backed and
already has PG_lru set) before failing with -EBUSY. Because
lru_cache_disabled() is false during the lazy pass, migrate_folio_move() ->
folio_add_lru() and folio_putback_lru() also place newly migrated and
put-back folios into cpu_fbatches.lru_add without PG_lru set. If those
destination folios land in higher unisolated MIGRATE_CMA pageblocks, later
windows in the same lazy scan fail test_pages_isolated() on the folios it
just migrated, and when bitmap_count > mask + 1, advancing start by mask + 1
repeatedly re-isolates and migrates overlapping windows across the same
un-drained folio while holding cma->alloc_mutex.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-lazy-cma-allocation-v1-0-af432f823fbd@ideasonboard.com?part=2


      reply	other threads:[~2026-12-03 15:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:13 [PATCH 0/2] Add ACR_FLAGS_LAZY and use it in cma_range_alloc() Daniel Scally
2026-12-02 15:13 ` [PATCH 1/2] mm: page_alloc: Add a "lazy" flag for __alloc_contig_migrate_range() Daniel Scally
2026-12-02 15:13 ` [PATCH 2/2] mm: cma: Pass ACR_FLAGS_LAZY to alloc_contig_frozen_range() Daniel Scally
2026-12-03 15:14   ` sashiko-bot [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=sashiko-outbox-248086@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=dan.scally@ideasonboard.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --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.