From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 364B438B154 for ; Tue, 24 Mar 2026 08:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774341739; cv=none; b=MLvsDbC/Au0bO6q5WAUL1UNMclOKFbJu6M/hV/2sH5Xsg/ZWP679K79xCyxZRAKUA/Fmfm3NDUUxnyn/zOlhNCE+LWhQtXwN7MfiblOhBmL3/4MgxPVZCkwTnhyZABXJi3CYazakSc7fk6bQUPAumwUsPOOLsxHvGeT+G+I1cgc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774341739; c=relaxed/simple; bh=bkc8UcEfAxUjeF5u3U5zddmTLkwzWAot8zJ/aTR57iI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=lGQBsg0WyG83fswTyvlUEoR+hVQvCvYlm/nfnHvvhZOSPtqlqhZ5LKorR99y2gVSM/c6Ig1BAzCUssJUKZGzdYrBKARCMuU2KI0cU6eLL1ihfZmHPI/RXEXkCiBOjvkikpiGKDWFb9coxbhZeAn/axUIZlTtlaa0eKqnaqYSCOg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=GccVIiwF; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="GccVIiwF" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1774341724; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=pbAujaAPG3PI7tjdCMceehwF0A1vZDewqB4hYIY6V0E=; b=GccVIiwFYQMjSOXoLvM/EbY+mPwnF6ay6BDzLpu3gybj29u70f7Q/d1cKsoi+3nB9eOpvizFD5Zsmjzg34GLTQImxCg0B3Mr5IglzYB5DP/GaYzRgXl8+HMpfrCWGJ0395IKYRDLdb6WbU9VoWrMLemjqZpD60B7P23lLge9DUA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R541e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=ying.huang@linux.alibaba.com;NM=1;PH=DS;RN=39;SR=0;TI=SMTPD_---0X.duPY3_1774341719; Received: from DESKTOP-5N7EMDA(mailfrom:ying.huang@linux.alibaba.com fp:SMTPD_---0X.duPY3_1774341719 cluster:ay36) by smtp.aliyun-inc.com; Tue, 24 Mar 2026 16:42:01 +0800 From: "Huang, Ying" To: Shivank Garg Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [RFC PATCH v4 3/6] mm/migrate: add batch-copy path in migrate_pages_batch In-Reply-To: <20260309120725.308854-10-shivankg@amd.com> (Shivank Garg's message of "Mon, 9 Mar 2026 12:07:27 +0000") References: <20260309120725.308854-3-shivankg@amd.com> <20260309120725.308854-10-shivankg@amd.com> Date: Tue, 24 Mar 2026 16:42:00 +0800 Message-ID: <87se9pzkiv.fsf@DESKTOP-5N7EMDA> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Shivank Garg writes: > Split unmapped folios into batch-eligible (src_batch/dst_batch) and > standard (src_std/dst_std) lists, gated by the migrate_offload_enabled > which is off by default. So, when no offload driver is active, the > branch is never taken and everything goes through the standard path. > > After TLB flush, batch copy the eligible folios via folios_mc_copy() > and pass already_copied=true into migrate_folios_move() so > __migrate_folio() skips the per-folio copy. > > On batch copy failure, already_copied flag stays false and each folio > fall back to individual copy. > > Signed-off-by: Shivank Garg > --- > mm/migrate.c | 55 +++++++++++++++++++++++++++++++++++++++++----------- > 1 file changed, 44 insertions(+), 11 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 1d8c1fb627c9..69daa16f9cf3 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -43,6 +43,7 @@ > #include > #include > #include > +#include > > #include > > @@ -51,6 +52,8 @@ > #include "internal.h" > #include "swap.h" > > +DEFINE_STATIC_KEY_FALSE(migrate_offload_enabled); > + > static const struct movable_operations *offline_movable_ops; > static const struct movable_operations *zsmalloc_movable_ops; > > @@ -1706,6 +1709,12 @@ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_folio, > return nr_failed; > } > > +/* movable_ops folios have their own migrate path */ > +static bool folio_supports_batch_copy(struct folio *folio) > +{ > + return likely(!page_has_movable_ops(&folio->page)); > +} > + > static void migrate_folios_move(struct list_head *src_folios, > struct list_head *dst_folios, > free_folio_t put_new_folio, unsigned long private, > @@ -1805,8 +1814,12 @@ static int migrate_pages_batch(struct list_head *from, > bool is_large = false; > struct folio *folio, *folio2, *dst = NULL; > int rc, rc_saved = 0, nr_pages; > - LIST_HEAD(unmap_folios); > - LIST_HEAD(dst_folios); > + unsigned int nr_batch = 0; > + bool batch_copied = false; > + LIST_HEAD(src_batch); > + LIST_HEAD(dst_batch); > + LIST_HEAD(src_std); > + LIST_HEAD(dst_std); IMHO, the naming appears too copy centric, how about unmap_batch and unmap_single? "unmap" is one step of migration. > bool nosplit = (reason == MR_NUMA_MISPLACED); > > VM_WARN_ON_ONCE(mode != MIGRATE_ASYNC && > @@ -1943,7 +1956,7 @@ static int migrate_pages_batch(struct list_head *from, unmap/dst_folios in comments need to be changed too. rc = migrate_folio_unmap(get_new_folio, put_new_folio, private, folio, &dst, mode, ret_folios); /* * The rules are: * 0: folio will be put on unmap_folios list, * dst folio put on dst_folios list * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * Other errno: put on ret_folios list */ > /* nr_failed isn't updated for not used */ > stats->nr_thp_failed += thp_retry; > rc_saved = rc; > - if (list_empty(&unmap_folios)) > + if (list_empty(&src_batch) && list_empty(&src_std)) > goto out; > else > goto move; > @@ -1953,8 +1966,15 @@ static int migrate_pages_batch(struct list_head *from, > nr_retry_pages += nr_pages; > break; > case 0: > - list_move_tail(&folio->lru, &unmap_folios); > - list_add_tail(&dst->lru, &dst_folios); > + if (static_branch_unlikely(&migrate_offload_enabled) && > + folio_supports_batch_copy(folio)) { > + list_move_tail(&folio->lru, &src_batch); > + list_add_tail(&dst->lru, &dst_batch); > + nr_batch++; > + } else { > + list_move_tail(&folio->lru, &src_std); > + list_add_tail(&dst->lru, &dst_std); > + } > break; > default: > /* > @@ -1977,17 +1997,28 @@ static int migrate_pages_batch(struct list_head *from, > /* Flush TLBs for all unmapped folios */ > try_to_unmap_flush(); > > + /* Batch-copy eligible folios before the move phase */ > + if (!list_empty(&src_batch)) { > + rc = folios_mc_copy(&dst_batch, &src_batch, nr_batch); > + batch_copied = (rc == 0); > + } > + > retry = 1; > for (pass = 0; pass < nr_pass && retry; pass++) { > retry = 0; > thp_retry = 0; > nr_retry_pages = 0; > > - /* Move the unmapped folios */ > - migrate_folios_move(&unmap_folios, &dst_folios, > - put_new_folio, private, mode, reason, > - ret_folios, stats, &retry, &thp_retry, > - &nr_failed, &nr_retry_pages, false); > + if (!list_empty(&src_batch)) > + migrate_folios_move(&src_batch, &dst_batch, put_new_folio, > + private, mode, reason, ret_folios, stats, > + &retry, &thp_retry, &nr_failed, > + &nr_retry_pages, batch_copied); > + if (!list_empty(&src_std)) > + migrate_folios_move(&src_std, &dst_std, put_new_folio, > + private, mode, reason, ret_folios, stats, > + &retry, &thp_retry, &nr_failed, > + &nr_retry_pages, false); > } > nr_failed += retry; > stats->nr_thp_failed += thp_retry; > @@ -1996,7 +2027,9 @@ static int migrate_pages_batch(struct list_head *from, > rc = rc_saved ? : nr_failed; > out: > /* Cleanup remaining folios */ > - migrate_folios_undo(&unmap_folios, &dst_folios, > + migrate_folios_undo(&src_batch, &dst_batch, > + put_new_folio, private, ret_folios); > + migrate_folios_undo(&src_std, &dst_std, > put_new_folio, private, ret_folios); > > return rc; --- Best Regards, Huang, Ying