Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhiteng Qiu" <qiuzhiteng@hygon.cn>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"David Hildenbrand" <david@kernel.org>
Cc: "Ying Huang" <ying.huang@linux.alibaba.com>,
	"Zi Yan" <ziy@nvidia.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Joshua Hahn" <joshua.hahnjy@gmail.com>,
	"Byungchul Park" <byungchul@sk.com>,
	"Gregory Price" <gourry@gourry.net>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Xin Hao" <xhao@linux.alibaba.com>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Yuan Zhong" <zhongyuan@hygon.cn>,
	"Shifei Ge" <geshifei@hygon.cn>,
	"Jianyong Wu" <wujianyong@hygon.cn>,
	"Shijie Huang" <huangsj@hygon.cn>,
	"Yibin Liu" <liuyibin@hygon.cn>,
	"Fengyu Wang" <wangfengyu@hygon.cn>,
	linux-mm@kvack.org
Subject: Re: [PATCH v7] mm/migrate: don't batch the TLB flush when there is nothing to batch
Date: Sun, 06 Dec 2026 10:31:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-252361@kernel.org> (raw)
In-Reply-To: <20261205103115.2552729-1-qiuzhiteng@hygon.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm: folio_migrate_ttu_flags() reaches into rmap internal tlb_ubc
  state
--

commit 9fca0aa81908e53f9d294e047c190b0b06869c1b
Author: Zhiteng Qiu <qiuzhiteng@hygon.cn>

mm/migrate: don't batch the TLB flush when there is nothing to batch

This commit adds folio_migrate_ttu_flags() so migrate_pages_batch() omits
TTU_BATCH_FLUSH during asynchronous migration when there is no pending
batched flush and only one small, unshared folio remains to unmap.

Link: https://lore.kernel.org/r/20261122171706.9376E1F000C4@smtp.kernel.org

> diff --git a/mm/migrate.c b/mm/migrate.c
> index f59dd50b3f229..0737a373c850e 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -1227,9 +1227,41 @@ static void migrate_folio_done(struct folio *src,
>  		folio_put(src);
>  }
>  
> +static enum ttu_flags folio_migrate_ttu_flags(struct folio *folio,
> +		enum migrate_mode mode,
> +		struct list_head *new_folios)
> +{
> +	if (mode != MIGRATE_ASYNC)
> +		return 0;
> +
> +#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
> +	/*
> +	 * Keep batching the tail if the current task already has a batched
> +	 * unmap flush to complete, possibly for another mm.
> +	 */
> +	if (current->tlb_ubc.flush_required)
> +		return TTU_BATCH_FLUSH;
> +#endif
> +
> +	/* A batch with multiple folios can benefit from a batched flush. */
> +	if (!list_is_singular(new_folios))
> +		return TTU_BATCH_FLUSH;
> +
> +	/* Keep the existing flush behavior for large folios. */
> +	if (folio_test_large(folio))
> +		return TTU_BATCH_FLUSH;
> +
> +	/* A shared mapping can have more than one PTE to flush. */
> +	if (folio_maybe_mapped_shared(folio))
> +		return TTU_BATCH_FLUSH;
> +
> +	return 0;
> +}

[Severity: Low]
Should folio_migrate_ttu_flags() read current->tlb_ubc.flush_required
directly here?

Elsewhere in the kernel, task_struct.tlb_ubc is private to mm/rmap.c,
and all batched-unmap TLB flush helpers and their disabled-config stubs
live in mm/internal.h.  Coordinating a helper in mm/internal.h would
keep the tlb_ubc internals and the ifdef out of mm/migrate.c.

Also, when CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH is disabled,
should_defer_flush() in mm/rmap.c always returns false.  Returning 0
early on !IS_ENABLED(CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH) would
skip the remaining checks for an unused TTU_BATCH_FLUSH flag.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205103115.2552729-1-qiuzhiteng@hygon.cn?part=1


      reply	other threads:[~2026-12-06 10:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 10:31 [PATCH v7] mm/migrate: don't batch the TLB flush when there is nothing to batch Zhiteng Qiu
2026-12-06 10:31 ` 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-252361@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=byungchul@sk.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=geshifei@hygon.cn \
    --cc=gourry@gourry.net \
    --cc=huangsj@hygon.cn \
    --cc=joshua.hahnjy@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=liuyibin@hygon.cn \
    --cc=matthew.brost@intel.com \
    --cc=qiuzhiteng@hygon.cn \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wangfengyu@hygon.cn \
    --cc=wujianyong@hygon.cn \
    --cc=xhao@linux.alibaba.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=zhongyuan@hygon.cn \
    --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