From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010003.outbound.protection.outlook.com [40.93.198.3]) (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 CB72F1DFF0 for ; Mon, 8 Jun 2026 15:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.3 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780933011; cv=fail; b=uEOoBAxxfoSrZqGVY4m+9GOaSX5H1pioBsi7rcBCbE9PaXbnSqQnc+nVx+FNhLF0qyfKNXa7T1J8vQcTKIco7whk6Dxnv1+rCOE0oVFhW+CbBPSjoShNPwHKOJvqvckwXMOODvV4mcZdPVaOTXUdCxuL2PPz/y5ycJrQbsamfKA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780933011; c=relaxed/simple; bh=ckSO4JS0f2MuSmY8y46qF6SciuYvW11mLyzLyhDYR68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=T1/r4WBZSS++2W2agsyVTgIVReNrlzXf97WfBdK4PuYA4ZNUFxELkZlZcOIq/8cL4D3CFhZ/8s/jFMjIpW0CiyqtXatlojKxMixUGgWi1gVD+4nzSH6NdImmllLsjCBK6K1IJOxa3DIOs0O005aJRYL39Ca5g08NOjQELWlQaVk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ARccvoy1; arc=fail smtp.client-ip=40.93.198.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ARccvoy1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KN3hRSXL494tf3h9dYSyDylrUjKwWFi08nlgxAVc73i14GjKDJfME2wPOPHs2tlUOVAlNVVk+/LcKs96qG8/KHzqeLLzI+V4/b0OYre5z6GuVqiVt9F6AJP5YoIOtO+6nY7qhmC7zdM85Qt+RI6dIvsGQnjUgMNOF0a129sslXaBfnMBB3i6mBQ+3Hmnr8Wz23h8KW38vMrwipzzssYaI/yPVNqoIDJ2JMbLODohnhZjeOdGbtQBS8tGHXZ8kroTG+d6A2Ww6lcV/oBZmgiv2U4uk3pBx7rM5dS5OntewujlWet3cXRJUomTiHxxK8E9/7Rb5Jkg1Tt0iTZuA8jKGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wiNBNv6ygkVTPnjFQNiaC8DdFRx0BPCbbjg1Yj1uquc=; b=SGVNEYSEJn+JHCz9uU6s2mQojn+pdP3XC07GF0moC8/TuDDQCSw20jKWl3+vZYUccKNhnB+8Riz/WVHBbqv7KG/TOP9mr879npI0QxljSC+TpQJ94ggXvEARKmQti/Kw7+8DNvHa8g2Htl8IcHYTkSigVVK+4RajaqDGlhvflXo3ikGAXR8c1LXVmY71NQ476YW1kmXF0DSqs1ldJHwmT+mrk9Y8P89TQGttuPGMQAz9S+zmP/EdbR1IKCsPfeVZloiOuvdEw7/edhgdbYSaRVK5pgAknDjqbNYeuyNHqp1OfHY4EVUIRF+cYG1A/u6+klpG4/++rcTnaL1cW/Yg1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wiNBNv6ygkVTPnjFQNiaC8DdFRx0BPCbbjg1Yj1uquc=; b=ARccvoy1pwGrC39GHSKtZTh0ilg0D5d7d1Ik7P/j6JChe9MqYSU/gwQ6vCWlcjTkoePGXn2J6n8FjDWwN7N10WF2Rt5idn68Lf+y5VXpWqcXUtgWunOqJmqBSJo2V6RTNEJne0Bm+m86sqaeoQEjMXhgna1wIwyfL2Gpl8qSZtE8T6K7F4ET/XpJlsxA2K8htsqAtm9lARt96A5rbXptWu4f4D0VLNOiEpFg/uXGpfDBmPGwgYInGdjXiXLDSCxlI6VQfFOBG2PGSNCihygX9OedxhAu2+D4lXaykE0VpibwF5tQVdzH6BItaqFuNs291vHw/ONgO6S2jsv06HZaKw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by SN7PR12MB6982.namprd12.prod.outlook.com (2603:10b6:806:262::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.92.13; Mon, 8 Jun 2026 15:36:41 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::f01d:73d2:2dda:c7b2]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::f01d:73d2:2dda:c7b2%5]) with mapi id 15.21.0092.011; Mon, 8 Jun 2026 15:36:39 +0000 From: Zi Yan To: "David Hildenbrand (Arm)" Cc: "Garg, Shivank" , akpm@linux-foundation.org, kinseyho@google.com, weixugc@google.com, ljs@kernel.org, Liam.Howlett@oracle.com, vbabka@kernel.org, willy@infradead.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, dave@stgolabs.net, Jonathan.Cameron@huawei.com, rkodsara@amd.com, vkoul@kernel.org, bharata@amd.com, sj@kernel.org, rientjes@google.com, xuezhengchu@huawei.com, yiannis@zptcorp.com, dave.hansen@intel.com, hannes@cmpxchg.org, jhubbard@nvidia.com, peterx@redhat.com, riel@surriel.com, shakeel.butt@linux.dev, stalexan@redhat.com, tj@kernel.org, nifan.cxl@gmail.com, jic23@kernel.org, aneesh.kumar@kernel.org, nathan.lynch@amd.com, Frank.li@nxp.com, djbw@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 4/7] mm/migrate: add batch-copy path in migrate_pages_batch Date: Mon, 08 Jun 2026 11:36:31 -0400 X-Mailer: MailMate (2.0r6290) Message-ID: <8EAC3D9C-6956-44DF-861F-A4864F08273D@nvidia.com> In-Reply-To: <27f6f5d6-e81b-4e0a-af39-b175187299e2@kernel.org> References: <20260428155043.39251-2-shivankg@amd.com> <20260428155043.39251-10-shivankg@amd.com> <27f6f5d6-e81b-4e0a-af39-b175187299e2@kernel.org> Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR03CA0205.namprd03.prod.outlook.com (2603:10b6:a03:2ef::30) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|SN7PR12MB6982:EE_ X-MS-Office365-Filtering-Correlation-Id: e4c6ee83-8794-4a4a-5d7f-08dec573bbbe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024|11063799006|4143699003|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: RMlcPWJoEYb/wc2ZNuVigHWOq7faaKMLKTDxNezqIQPTxNwm02I/sFoNHOZbtvUgqfhTo9ArigMieOssB5xS/4qsOxs+n+ncaH0D6DtryHsXX/ZdmPR95eBZ/uGCeavylTP3r1LcLsHCXIPbhFqpbhR2nfAMT9oK0Wjt+nByvs7YQ9992HKK7RR+Jb+LxwRGSSqayujH3j9foMp52IGGY1Vm4Ug45Qt30wl14Uyu4QM0otg03wyjshGsv43ObP9DoRFJvsnD7ie46h6MdXxoXHwRXzbLjQz0bWfPss0Se2bh7Dq6kNL5pYhYhZLSHNxMMTj2KPLCKyx7UYpvcRnmE9jyxiymelt3dVAPnONVrD18CPNilsf+bDk6QtyWgBJk4exSp/o+pw8K3z4HRDseiAc6M3jFFI5c34vrOnmwB0neJMKZbDDRoTV8jcFY3avc0Kp7x9mjAFqij3gbEaQ2gRoQZpabBUrJ8rFlKnBpB6Y5tO5+FAQhqxkZozvfJ+z2l1OURI6i7r1y0fVxuMXT/0ljRg/c+vu991aaznNTkKsE9ujtyzq4LGAkX/PWyVMPId68tHBKmm4L2Mrm112KwfsSKNNZ97Qik/Jc/MpMqENgQnN5XWA0AAGsUC1aRubSx4318UWMVNd1/TGjY7nTj1mQfGdF5t1uq5fBt+d+bFTExb0OSs/9cNwcWaN2ok4I X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024)(11063799006)(4143699003)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?JL6J2wQbNfZHXYLlc4BFW9u2oT5htPLhpM9kdh363hMvt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WDYoTtgk44gDpo/MpmJdz3RUOVYCe0V4EueWRCA3u6z?= =?us-ascii?Q?9VXcZ90mnY88PnpxXrloG8ALhrfWkKpsSTRqvz5IefmtpciFW+I4lE6sYTJW?= =?us-ascii?Q?wNanXabSVhkWijrE8KmIbHS7Sn1UmrdoeLmcUCLFG0Kj02CpIhaYPVTtzcGM?= =?us-ascii?Q?sP4g52m0lx5NWnEBHQA6Qn6WISsZ3b99lD3nP1bHpVFT5ALEqPBjKiJdIOJY?= =?us-ascii?Q?yDE2ZXibCrf4YGbyacUi+6F8WxpwL4KLZR4qC5W0V24+Gx/7Dbfzt1f8DlfR?= =?us-ascii?Q?OfPZ/XTjWSZ72FUboEXqTUMPfgIF3xD0GtR1iCJW1RN5MV5CcrkUxRZ+v/8G?= =?us-ascii?Q?GbaMsT+83wTYWgfzlqK3nhFT0nAGVNb77d/J2/+ICjlTPQ1oOzzUkbs35x4k?= =?us-ascii?Q?8E20P0vgVz3SqI/yrvZ9U6/erV51AnMvZhLeu88nvfmXeUmyh7JhU1EJyE/S?= =?us-ascii?Q?DYZ6sSOxFioArKi4dPR8h+nWYQma1Ll6+51ka460HyqZBUGQOi77e9pmL0+k?= =?us-ascii?Q?wC7PFwldKyp42lYrsF9aW79w4J8rVRexXTz6dgVbODMmRebIeT5+Cr/P+tAb?= =?us-ascii?Q?jc1zrf5XVpGJpc7BLRWAhxEzPLla6EZR4T/9yytMvN2sBjbmGklZkpOu/pIu?= =?us-ascii?Q?cYj3VI/k7P/nc5W8Iwz5p6QmyX8ht7r3AofWv+kv/nBj251wsGCGhYUcYW58?= =?us-ascii?Q?a8arkYO/r/Gi/sz+N0RcFQJZFX7pSFxstA1eN/ZffgVGv/JJvS8g1mOu0UNU?= =?us-ascii?Q?seO9YLROKyJ0DLmk8g/hvXZLCIyv+PA7G8+BBHl0mx/eUqzR?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4c6ee83-8794-4a4a-5d7f-08dec573bbbe X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2026 15:36:39.6075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Av9LTRz/aErzAcMcdoPWL5Dy7Q6hmWqZdtEg9xELT9nrlJAHudNta1vI6q5cECpw X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6982 On 8 Jun 2026, at 11:25, David Hildenbrand (Arm) wrote: > On 5/20/26 17:06, Garg, Shivank wrote: >> >> >> On 5/11/2026 9:10 PM, David Hildenbrand (Arm) wrote: >>> On 4/28/26 17:50, Shivank Garg wrote: >>>> Add folios_mc_copy() which walks list of src and dst folios in locks= tep, >>>> and copies folio content via folio_mc_copy(). folios_cnt parameter i= s >>>> unused here, but is part of the offload_copy callback signature used= by >>>> later patches in the series. >>>> >>>> Split unmapped folios into batch-eligible (unmap_batch/dst_batch) an= d >>>> standard (unmap_single/dst_single) 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=3Dtrue into migrate_folios_move() so >>>> __migrate_folio() skips the per-folio copy. >>>> >>>> On batch copy failure, already_copied flag stays false and each foli= o >>>> fall back to individual copy. >>>> >>>> Signed-off-by: Shivank Garg >>>> --- >>>> include/linux/mm.h | 2 ++ >>>> mm/migrate.c | 61 +++++++++++++++++++++++++++++++++++--------= --- >>>> mm/util.c | 30 +++++++++++++++++++++++ >>>> 3 files changed, 79 insertions(+), 14 deletions(-) >>> >>> [...] >>> >>>> >>>> +DEFINE_STATIC_KEY_FALSE(migrate_offload_enabled); >>>> + >>>> static const struct movable_operations *offline_movable_ops; >>>> static const struct movable_operations *zsmalloc_movable_ops; >>>> >>>> @@ -1724,6 +1727,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)); >>>> +} >>> >>> As these things are not actually folios (and callers will have to be = taught to >>> distinguish them way, way earlier), I guess you should make this >>> >>> /* movable_ops pages have a separate migration path */ >>> static bool page_supports_batch_copy(struct page *page) >>> ... >> >> I'll change this. >> >>> >>>> + >>>> static void migrate_folios_move(struct list_head *src_folios, >>>> struct list_head *dst_folios, >>>> free_folio_t put_new_folio, unsigned long private, >>>> @@ -1752,7 +1761,7 @@ static void migrate_folios_move(struct list_he= ad *src_folios, >>>> /* >>>> * The rules are: >>>> * 0: folio will be freed >>>> - * -EAGAIN: stay on the unmap_folios list >>>> + * -EAGAIN: stay on the src_folios list >>>> * Other errno: put on ret_folios list >>>> */ >>>> switch (rc) { >>> >>> >>> [...] >>> >>>> --- a/mm/util.c >>>> +++ b/mm/util.c >>>> @@ -778,6 +778,36 @@ int folio_mc_copy(struct folio *dst, struct fol= io *src) >>>> } >>>> EXPORT_SYMBOL(folio_mc_copy); >>>> >>>> +/** >>>> + * folios_mc_copy - Copy the contents of list of folios. >>>> + * @dst_list: destination folio list. >>>> + * @src_list: source folio list. >>>> + * @folios_cnt: unused here, present for callback signature compati= bility. >>>> + * >>>> + * Walks list of src and dst folios in lockstep and copies folio >>>> + * content via folio_mc_copy(). The caller must ensure both lists h= ave >>>> + * the same number of entries. This may sleep. >>> >>> This *function* >>> >> >> Will add function. >> >>>> + * >>>> + * Return: 0 on success, negative errno on failure. >>>> + */ >>>> +int folios_mc_copy(struct list_head *dst_list, struct list_head *sr= c_list, >>>> + unsigned int __always_unused folios_cnt) >>>> +{ >>>> + struct folio *src, *dst; >>>> + int ret; >>>> + >>>> + dst =3D list_first_entry(dst_list, struct folio, lru); >>>> + list_for_each_entry(src, src_list, lru) { >>>> + ret =3D folio_mc_copy(dst, src); >>>> + if (ret) >>>> + return ret; >>>> + dst =3D list_next_entry(dst, lru); >>>> + } >>> >>> Wouldn't it be cleaner to remember "already copied" immediately after= we ... >>> performed the copy? (succeeded with folio_mc_copy) >> >> IIUC, you mean something like: >> list_for_each_entry(src, src_list, lru) { >> ret =3D folio_mc_copy(dst, src); >> if (ret) >> return ret; >> dst->migrate_info |=3D FOLIO_CONTENT_COPIED; >> dst =3D list_next_entry(dst, lru); >> } >> >> This will be cleaner. However, it will make the folios_mc_copy() speci= fic for >> page migration and can't be reused by other potential callers. >> And offload driver (like DCBM) must set the already copied marker >> themselves for successful copies. > > Right, maybe some helper for that would be possible? > >> This will have an upside that on partial-success (even a single failed= copy), >> it will no longer forces re-copy of the whole batch. >> If that's the intention, I'll move this to migrate.c itself. > > True. I'd probably have to take a look at the end result to see if it l= ooks > better that way. Maybe do this optimization in a separate patch to make it simpler to revi= ew. BTW, the whole migration code has become more and more complicated due to= batching at different levels, I wonder if it is worth the complication to= optimize for the rare memory error case. Best Regards, Yan, Zi