From nobody Sat Sep 26 10:01:31 2026 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012027.outbound.protection.outlook.com [52.101.53.27]) (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 DB47A47209B; Wed, 2 Sep 2026 10:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.27 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346396; cv=fail; b=LueO+hSQXlF1TSuNO4p/E+XIyqBTl0j2BCOi4gp7IN8dPODns8o+QOQA8V76aIGj9MkugJ5Nrmrsgd/A6R7h8dcw3nsELUJHk+rBkzGFiDKTQ+fZBdFSqZih1YKNfHC8lKyXeG4jBOEROJEs1mcAZbuD2ZN+WEh7OpQMYsz8iSY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346396; c=relaxed/simple; bh=8xeFRHABNScN0jpjYHKuyRPcy+HQ6Ma6c3BY2BbVZAc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=OOVw//T3AOmENiU4/5MSfxo28GOKuF18phJCH14Xwk23hM4AHglRGo6r8IiqbzdL/VjUmgmHHnFE2yUUrQS69f85OPz+TyZ5KRZOpAbV7CWhantDe78Pn2rzEUbW7H+3SZ4dKrpoQHiQkxpbN8DkYo+jsVY0v57EjTsm3zzRgrM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=XLlHDOjW; arc=fail smtp.client-ip=52.101.53.27 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="XLlHDOjW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hJh9Jt/GduqL6wt2A/iILGVsC7xDTYhwLbkhxfj3E4ZLpbS/w+rCBFeN4/7pRmNbTqaJmxJGJR0ZETGJz78zBdWDUs5bIy2u2B82Hb4LLVqZfCpQLZxNio4Z0pHbej2IcxrpYzqhIGPOiw9DC1Ij4xr4U/68N77ogd90QpX69ZLnHmdfEnOwZoB9H5NuyNudeeePeiIHBBHDcE9QvJCNVsM+iqVb+D/EAu3k8oq8aTi6LirzbaC3A0bH2u08U6wcLpmP3b02zfHrCVMPljBIyPMwmPxs0b4317M4K8TXCBnseS6ciN5+jVStb0UaTAkU3HrvPYxsVVqC9BQBriongQ== 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=opo4fFYNUWbP/vzFTuX+fFp2clt1D0XJJIbeiibySew=; b=T8HTyA+5TKNP/KVu2uxwHMQnH7DO6MeKcYenVc4SARRXW5KEqFqMFuovfE7yMru98IU/nAC2e5gmDEHQBL9oGpDTpieOz5AokjSHCIhoz5O9Ma1ddki43s6UgOIgi9/syVDP8ywDnliLQFIDeSiGa+552rTRe0nYnPbsOJhhfOw6KXtCgJP1YOIf/FLY3Gt2TVCxjt5qT5iLL8Hf0COzUq/yhdFa1kSZHIogA7066+nTkZ/42+8NjoNc4dkp6xdl4uxMgocHkgcfOQRrJ6j/PcfIVqEUVHCPcUsGhnty8LRKBkkJ5Y1ZSpa7WyrdaM0/CxT9c9MKrkRTI3REmMLdEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=opo4fFYNUWbP/vzFTuX+fFp2clt1D0XJJIbeiibySew=; b=XLlHDOjW+SzKYn5qwjMuUsH3dQCZpAPU0fJCV6XNozjDOuBewdZI9dGiuNIiEWD2E72OEWyZmyvLSBR+ZvobaY6cVxuxNeXw5HMb9bWGDlD8i9Q/2mLdMTJT5G1HGYjoIOnMedNUL1/nWLmpcAk5ry4lSsdKdYGrJSBH8w8Ow8I= Received: from BN9PR03CA0043.namprd03.prod.outlook.com (2603:10b6:408:fb::18) by LV2PR12MB6014.namprd12.prod.outlook.com (2603:10b6:408:170::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:52:57 +0000 Received: from BN1PEPF00004682.namprd03.prod.outlook.com (2603:10b6:408:fb:cafe::21) by BN9PR03CA0043.outlook.office365.com (2603:10b6:408:fb::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.11 via Frontend Transport; Wed, 2 Sep 2026 10:52:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN1PEPF00004682.mail.protection.outlook.com (10.167.243.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:52:57 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:52:42 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:15 +0000 Subject: [PATCH RFC 01/11] mm/migrate: extract folio unmap phase 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-1-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=6697; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=8xeFRHABNScN0jpjYHKuyRPcy+HQ6Ma6c3BY2BbVZAc=; b=axPoZ3keUNUxapQCqastHA9QugWbwkleGKZRjhNsPoKYn8kDP41y1DN2g9SXNf+DJH0JJJbmx RB2vCPFbJSrBjvmI/RWEZSRrX0HLun0BCdutuAoOAyTxbouo41giDlW X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004682:EE_|LV2PR12MB6014:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bbe204d-9562-4505-b567-08df08e05955 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|23010399003|36860700016|82310400026|1800799024|11063799006|921020|10067099003|18002099003|22082099003|56012099006; X-Microsoft-Antispam-Message-Info: WbFXNrJu82ii08KVEh1bhu6CjcYUu57L4yGygaGeCe+K7SIqhjpSLgMMk2iqYrBpTKqQH6OoE97ay0mtKLRMntAZ5/eZFbMxcVye1qOa7D87d5wn3aDT26qdUF5knkBLZEkC9ciRa+mZIv511t00J6nnDptZb4ZgfPO+AnfkjApAqM8zk5jROywwFKoLR8bf0MLHxvu6WO9I80RqvE15B+yJU5N1PXwtp4r071vitaqNJuM2B0PrmlApIN/ih+w6mRsRQFbLNum0OCW9IrD5qtNGWS5gNPTi3YylYdU0N29meQ5kmjleSJCdeApfop2CvqFNc/v4/2dGFGTYvoEWQn+J4AGkgqNtVyIIAaKN4HUQNiDoMWTbcGg2tvkrYOVKY832rtHQpYheb2IcspfiBiYspdXZp4QslFdwOJrlLR202S6NC+wfnVpMAG1Bf5RxaCsH9ObEZZ2trggAzmYhTgK72G8RAuDCOiRwZArksTFXqN3eGdTpK5rKgvDlBc6T1JqZlXrpGxB7YA3LyMspS3fAoC9Zc9WKYLC+TM/hPx87KA3yz76qGQBvPltUSv8xyIjEml+0TEN4POhhaSiFDMW/svzQSxUN/Ny7geHqORl8s48pwR3QI9/03XCoX0AqU3h2p13J/9Woaw8mrbPfFfuHncbTv1rQ1T67XILzfOsxK5UXx2+/fmWoMXRhSqcY4Fld2mUh2vhg+nLHFxp2SXfyPv60uzTAZiLsOkw9As0rCYBKhZXWjFMo25kUUthJ X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(23010399003)(36860700016)(82310400026)(1800799024)(11063799006)(921020)(10067099003)(18002099003)(22082099003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NsmhZT/F2qLzsgjoW0FnfUdYJa+ezpTvcLgiozeHpN6cqQjcZx0koMUahi90SarJufnyqz84wZnYsknZBWNZN80NBEIbBKVxqbZnLB9WtTgP89Mm3tFdm/axcDy+7XxMSOls2YinkOyaBdInAnByQXy6TAA+x/twLQ68exaqZEZF++s1OHDT+6SR71/EjjNAvLDqYCTpAkQ1/KrFnxEw5a9/jVHomH/u5MfDSb0QMSHgRqCQfEXKuCl2u11x/Y4cD11yiXxknzgM3S26xTLtVIKbaxaAyiTH4IZDG7u7s0jM27vvx/jdAr0PM0ODe0DGMgPAEmU15lm48PdYnanz0Iw7buvzm8jLZYl7IQeJj4ug0/efiCy0GshZ/uVJ6GiIhFmjuIN9KNGrBL/O5PhZwRiTMdLsMV7zTEyAH/K3edJ465VXAXCQHNZIP668yEbd X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:52:57.3962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bbe204d-9562-4505-b567-08df08e05955 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004682.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB6014 migrate_pages_batch() was hard to follow with the unmap retry handling inline alongside TLB flush, move, and cleanup. Extract the unmap phase into migrate_folios_unmap(), which fills @unmap_folios and @dst_folios for the steps that follow. This makes the unmap phase boundaries clear and the code more readable. No functional change intended. Suggested-by: Zi Yan Signed-off-by: Shivank Garg --- mm/migrate.c | 89 ++++++++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 15b45832bcfa..14a0f84009c6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1800,36 +1800,30 @@ static void migrate_folios_undo(struct list_head *s= rc_folios, } =20 /* - * migrate_pages_batch() first unmaps folios in the from list as many as - * possible, then move the unmapped folios. + * Unmap the folios in @from, queuing successfully unmapped sources on + * @unmap_folios and their destination on @dst_folios. Increment @nr_fail= ed for + * each failure. * - * We only batch migration if mode =3D=3D MIGRATE_ASYNC to avoid to wait a - * lock or bit when we have locked more than one folio. Which may cause - * deadlock (e.g., for loop device). So, if mode !=3D MIGRATE_ASYNC, the - * length of the from list must be <=3D 1. + * Return: -ENOMEM on destination allocation failure stop the unmap phase, + * otherwise 0. Folios already unmapped remain queued for the move phase. */ -static int migrate_pages_batch(struct list_head *from, +static int migrate_folios_unmap(struct list_head *from, new_folio_t get_new_folio, free_folio_t put_new_folio, unsigned long private, enum migrate_mode mode, enum migrate_reason reaso= n, struct list_head *ret_folios, struct list_head *split_folios, - struct migrate_pages_stats *stats, int nr_pass) + struct list_head *unmap_folios, struct list_head *dst_folios, + struct migrate_pages_stats *stats, int nr_pass, int *nr_failed) { int retry =3D 1; int thp_retry =3D 1; - int nr_failed =3D 0; int nr_retry_pages =3D 0; int pass =3D 0; bool is_thp =3D false; bool is_large =3D false; struct folio *folio, *folio2, *dst =3D NULL; - int rc, rc_saved =3D 0, nr_pages; - LIST_HEAD(unmap_folios); - LIST_HEAD(dst_folios); + int rc, nr_pages; bool nosplit =3D (reason =3D=3D MR_NUMA_MISPLACED); =20 - VM_WARN_ON_ONCE(mode !=3D MIGRATE_ASYNC && - !list_empty(from) && !list_is_singular(from)); - for (pass =3D 0; pass < nr_pass && retry; pass++) { retry =3D 0; thp_retry =3D 0; @@ -1869,7 +1863,7 @@ static int migrate_pages_batch(struct list_head *from, !list_empty(&folio->_deferred_list) && folio_test_partially_mapped(folio)) { if (!try_split_folio(folio, split_folios, mode)) { - nr_failed++; + *nr_failed +=3D 1; stats->nr_thp_failed +=3D is_thp; stats->nr_thp_split +=3D is_thp; stats->nr_split++; @@ -1888,7 +1882,7 @@ static int migrate_pages_batch(struct list_head *from, * list is processed. */ if (!thp_migration_supported() && is_thp) { - nr_failed++; + *nr_failed +=3D 1; stats->nr_thp_failed++; if (!try_split_folio(folio, split_folios, mode)) { stats->nr_thp_split++; @@ -1925,13 +1919,13 @@ static int migrate_pages_batch(struct list_head *fr= om, * -ENOMEM: stay on the from list * Other errno: put on ret_folios list */ - switch(rc) { + switch (rc) { case -ENOMEM: /* * When memory is low, don't bother to try to migrate * other folios, move unmapped folios, then exit. */ - nr_failed++; + *nr_failed +=3D 1; stats->nr_thp_failed +=3D is_thp; /* Large folio NUMA faulting doesn't split to retry. */ if (is_large && !nosplit) { @@ -1951,7 +1945,7 @@ static int migrate_pages_batch(struct list_head *from, thp_retry +=3D is_thp; nr_retry_pages +=3D nr_pages; /* Undo duplicated failure counting. */ - nr_failed--; + *nr_failed -=3D 1; stats->nr_thp_failed -=3D is_thp; break; } @@ -1960,19 +1954,15 @@ static int migrate_pages_batch(struct list_head *fr= om, stats->nr_failed_pages +=3D nr_pages + nr_retry_pages; /* nr_failed isn't updated for not used */ stats->nr_thp_failed +=3D thp_retry; - rc_saved =3D rc; - if (list_empty(&unmap_folios)) - goto out; - else - goto move; + return -ENOMEM; case -EAGAIN: retry++; thp_retry +=3D is_thp; nr_retry_pages +=3D nr_pages; break; case 0: - list_move_tail(&folio->lru, &unmap_folios); - list_add_tail(&dst->lru, &dst_folios); + list_move_tail(&folio->lru, unmap_folios); + list_add_tail(&dst->lru, dst_folios); break; default: /* @@ -1981,17 +1971,56 @@ static int migrate_pages_batch(struct list_head *fr= om, * removed from migration folio list and not * retried in the next outer loop. */ - nr_failed++; + *nr_failed +=3D 1; stats->nr_thp_failed +=3D is_thp; stats->nr_failed_pages +=3D nr_pages; break; } } } - nr_failed +=3D retry; + *nr_failed +=3D retry; stats->nr_thp_failed +=3D thp_retry; stats->nr_failed_pages +=3D nr_retry_pages; -move: + + return 0; +} + +/* + * migrate_pages_batch() first unmaps as many folios in the source list as + * possible, flushes the TLBs, then moves the unmapped folios. + * + * Only MIGRATE_ASYNC may batch multiple folios. Waiting for a lock or bit + * while multiple folios are locked may deadlock (e.g. with a loop device). + * Therefore, if mode !=3D MIGRATE_ASYNC, the source list must contain at = most + * one folio. + */ +static int migrate_pages_batch(struct list_head *from, + new_folio_t get_new_folio, free_folio_t put_new_folio, + unsigned long private, enum migrate_mode mode, enum migrate_reason reaso= n, + struct list_head *ret_folios, struct list_head *split_folios, + struct migrate_pages_stats *stats, int nr_pass) +{ + int retry =3D 1; + int thp_retry =3D 1; + int nr_failed =3D 0; + int nr_retry_pages =3D 0; + int pass =3D 0; + int rc, rc_saved; + LIST_HEAD(unmap_folios); + LIST_HEAD(dst_folios); + + VM_WARN_ON_ONCE(mode !=3D MIGRATE_ASYNC && + !list_empty(from) && !list_is_singular(from)); + + rc_saved =3D migrate_folios_unmap(from, get_new_folio, put_new_folio, + private, mode, reason, ret_folios, split_folios, + &unmap_folios, &dst_folios, stats, nr_pass, + &nr_failed); + if (rc_saved && list_empty(&unmap_folios)) { + rc =3D rc_saved; + goto out; + } + /* Flush TLBs for all unmapped folios */ try_to_unmap_flush(); =20 --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013005.outbound.protection.outlook.com [40.107.201.5]) (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 1F4EF4756BC; Wed, 2 Sep 2026 10:53:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346414; cv=fail; b=Sw2oSSjFUwGJQFL5goLgUB+eqkv04tHWawZte87K35XsDyrB9w3kraW1OxSmq+hig2PfD1CYDg70bhmxFKiz993nHJs4pR72wW/zabq9XXjrBvVMrXz2D0Jj1K3hmLPVoDpn0buejhOl62ZtFfJ7pA14ZYAW1B4rFLD+NaToVyk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346414; c=relaxed/simple; bh=RzsQpuq/nFhcE4vUneY1Dkea/cwh24Q+Fcfa4e0Y1IY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=fJERqiTLRsG2V0kMs4IHRYC0/Ih6kZsMJaih1ls4fj92xmst2AieTXM4/PL7IfODA+ryIcWnLn3SsuWKaCtlkqoD/CfOhRfkZrR6A9Pa5MK8Rtc6tHbV/T0ohvKtPC2Q6OT5uIrvWvQZnDvEjFeNWY6dg9Il5rcwzZGep/Itj8M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=d/c2UT43; arc=fail smtp.client-ip=40.107.201.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="d/c2UT43" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AGGx7cAWXnPvbO+dk0ngaxXsfIOKI5Zehvts5d8NShyWjrnoyyoOqo9wlBZJ0NOoFwJzHKTI8Ejrsh9ue/7g+wAYEevz+MQlU4l0G3rB6J63Zm6Lrgqg33ywPHBNbh43GHaYPdYQfKjKRcoBdFIgc+tK+rbFPphBUTkoyXwqh5I85i9gUQi1NGoK4qcuROeMxvjQudzVyFlDWvdhXSbNYAaICN2ZkUdAX9knYCzHZV7MpgVSPWYd7kQEjG1s6+EHemnmnMvyOyMjBeTrCo7qsH9gw9ewhQcZxqCNXoTScgKqqHtAYEHP30EbZblXqGAMbZHP1rsfQVjVyF+uo6OLXw== 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=pE9co85aDR/F++LDVwEW5UciCB+/hgsn1n/YSWS2h6Y=; b=HN0W0mjPKpzVD5qe8D6GcQG4Zpz8F76Xt45rNuZsk5qa9w9O1oM/s6mukxH26yjIBq3h++Rk7szX0EuDfw9r990W2BnW4PBmUQmlQ+T49p/tCUAssvN2EKquZkK5PD8aFgUmNfOYH7b6lpAzOsPZ2VAhLvh/qHcNJtwvBRG/6uQ40xSxNnRSXM0UsGfiPbjs5WQKXrzYRGv+Rqd/4VQA3GFBDo6fwHjIYx9GvOmRB5cqB7m/y+EqZ1j1ukWeX3iHgyXCWrZGceWv+wFh0bbycvbX7Cifv8J6fWxgtJr74sdM6U5pMpq5wNXoAbw6x8U79RBzgKtDeGEv9VoB0+ccUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pE9co85aDR/F++LDVwEW5UciCB+/hgsn1n/YSWS2h6Y=; b=d/c2UT430aVl7vj1u7rUsnHe1BPlCy3aqn+lOaY6MVKDaE5D9ehNrfE0ysnm55rQR+OdA2sH/mjdXDauT9bZ6GrrDwAnHlNk2XqudnKp5Cq5dAAqkjg9fRkJU+nrbLhP3azKcRfrMBhfJqJcTFfWuJOWjdptOOZfj3wywJTu7RU= Received: from BN0PR02CA0047.namprd02.prod.outlook.com (2603:10b6:408:e5::22) by DS0PR12MB9060.namprd12.prod.outlook.com (2603:10b6:8:c4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:53:10 +0000 Received: from BN1PEPF00004683.namprd03.prod.outlook.com (2603:10b6:408:e5:cafe::37) by BN0PR02CA0047.outlook.office365.com (2603:10b6:408:e5::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.11 via Frontend Transport; Wed, 2 Sep 2026 10:53:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN1PEPF00004683.mail.protection.outlook.com (10.167.243.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:53:10 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:52:56 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:16 +0000 Subject: [PATCH RFC 02/11] mm/migrate: handle retries in migrate_folios_move() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-2-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=4845; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=RzsQpuq/nFhcE4vUneY1Dkea/cwh24Q+Fcfa4e0Y1IY=; b=PKss8nrPoTGv7s7z+Uemf5NWtBYz6x1kgLF59bnjeZKk8C0sg+mJBwc15dt3GRUkGkLItFKjl vduKOsF0MhQAMYQ0f4oqUqQSFGcGfGccCdETD3xTKqN29CK2A1WBgBG X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004683:EE_|DS0PR12MB9060:EE_ X-MS-Office365-Filtering-Correlation-Id: 30478cca-e29d-421e-b75e-08df08e06110 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|82310400026|1800799024|7416014|376014|921020|6133799003|56012099006|10067099003|11063799006|22082099003|3023799007|18002099003; X-Microsoft-Antispam-Message-Info: CYeto4gR7y2zfNvtnh2wkvDlEY7F9pAELuj1NYAXMJmJATf622IbZ6qpkfhO+3x5nC9vt4+QwJb/uz88qUA89pIlUcUjiAtutrTewHCKVtgeazuokA1ihcUaYL56Fn6/llVnzcuWUKuRr1JWUyl8sW85QpN0zPw13c4+3tkhFnh3+sSsVcIKHdZIiYB5tfzCmDNFqyW+worjvLMBvz7RL0/mfdpXo6SPVBX3f/YCw6sHw+O9CxJed29mXD7czHGKc8zvnvlkDifTfrrfiWwLGIefodt1+ymZ93tOVfCi0iv07eiVKmiS2uS/F7EAm8Wi9HaoMZ0tAZ5NnxYUDfzmeXkkcGthTxaIZvagetI4lYpfbJgeWCtQuqHsU1Xgks1grXvCNwQneXd1OCZrz6058Jbsvoe9kaExnA4Zb4zKv6o5va7+k2AeP89hke4x7P290Tdi8Y4SIsTpwJSiRrgKZ0Ir+g9yVguA828cOF9iO/qpaAuQmsueIyCIMvBdw8TssmTYlN+E+ofsc7YMWfAamdxITBiasAtfNfASQdXJc9nP3Q/22l6Rix1YtRND127AhYia9UnFsrQMAIDHjow/4nne7pDzBLwqguxfq4kRBcFhahIWLn29x6tmdZQOYI3ZhbD6ow2OcaMwluqmdBC3ZDrgp7JaUWBIWU6ftresVs0ngAYY0Lgwn5Zc/GV5Ow0PLfMbiijMKAFioSvNyA76DPsGN30g+wZvUNjbHTW9WaJfFmvJKW0kunZxIo/UnbsE X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(36860700016)(82310400026)(1800799024)(7416014)(376014)(921020)(6133799003)(56012099006)(10067099003)(11063799006)(22082099003)(3023799007)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 166o3IsiLT4XRf6KeNYrIh27+Su+2jotCPja4qHH8WVaE8e1+AOn2oABcnQavHvHINQbVX8EREvojV+RG9cFja6lDgvJEGpiPHH+5juuuDJiyvGZvW7C6ns0Gi3Sa+fc76hkSRaduHmmAbD9+PW1Mu/7xmGOIzX2rIO5hg5m4Lnk8C9xe6GTqbEN3HhuILK5/XmfU3QTtNPWuZLcFpdlVikBiPpH4kTonLrIaGoKG89PJxFuoK/OYTzXkNen5PC0/xBgMhfsn1bZPkvK2UhNTZ7Xjhlc1LdqtGIXGSsEqLktw7BFONNWGFBuVe56vPBUqbGSVXJf/RCjEH+cV86LlrWtAXrzvkZ1frNffghBMhl+Zgf298y/WToYCDPAVkYB2GjcFPsP8Mh8O4SnNOh3u1LZpoXHCeTr8rSlISrmY4HYuSspebLCKUQj8SAzq+9A X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:53:10.3692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30478cca-e29d-421e-b75e-08df08e06110 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004683.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9060 After extracting the unmap phase, migrate_pages_batch() still drives the retry loop for the move phase and passes its retry bookkeeping to migrate_folios_move(). This splits the move phase across the two functions and requires several output parameters. Move the retry loop and its bookkeeping into migrate_folios_move(). The function now takes the number of passes and reports failures through @nr_failed, matching migrate_folios_unmap(). No functional change is intended. Signed-off-by: Shivank Garg --- mm/migrate.c | 104 ++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 49 insertions(+), 55 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 14a0f84009c6..89207bf515b9 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1729,51 +1729,61 @@ static void migrate_folios_move(struct list_head *s= rc_folios, free_folio_t put_new_folio, unsigned long private, enum migrate_mode mode, enum migrate_reason reason, struct list_head *ret_folios, - struct migrate_pages_stats *stats, - int *retry, int *thp_retry, int *nr_failed, - int *nr_retry_pages) + struct migrate_pages_stats *stats, int nr_pass, + int *nr_failed) { struct folio *folio, *folio2, *dst, *dst2; + int retry =3D 1; + int thp_retry =3D 0; + int nr_retry_pages =3D 0; bool is_thp; int nr_pages; - int rc; + int pass, rc; =20 - dst =3D list_first_entry(dst_folios, struct folio, lru); - dst2 =3D list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, src_folios, lru) { - is_thp =3D folio_test_large(folio) && folio_test_pmd_mappable(folio); - nr_pages =3D folio_nr_pages(folio); + for (pass =3D 0; pass < nr_pass && retry; pass++) { + retry =3D 0; + thp_retry =3D 0; + nr_retry_pages =3D 0; =20 - cond_resched(); + dst =3D list_first_entry(dst_folios, struct folio, lru); + dst2 =3D list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + is_thp =3D folio_test_large(folio) && folio_test_pmd_mappable(folio); + nr_pages =3D folio_nr_pages(folio); =20 - rc =3D migrate_folio_move(put_new_folio, private, - folio, dst, mode, - reason, ret_folios); - /* - * The rules are: - * 0: folio will be freed - * -EAGAIN: stay on the src_folios list - * Other errno: put on ret_folios list - */ - switch (rc) { - case -EAGAIN: - *retry +=3D 1; - *thp_retry +=3D is_thp; - *nr_retry_pages +=3D nr_pages; - break; - case 0: - stats->nr_succeeded +=3D nr_pages; - stats->nr_thp_succeeded +=3D is_thp; - break; - default: - *nr_failed +=3D 1; - stats->nr_thp_failed +=3D is_thp; - stats->nr_failed_pages +=3D nr_pages; - break; + cond_resched(); + + rc =3D migrate_folio_move(put_new_folio, private, + folio, dst, mode, reason, ret_folios); + /* + * The rules are: + * 0: folio will be freed + * -EAGAIN: stay on the src_folios list + * Other errno: put on ret_folios list + */ + switch (rc) { + case -EAGAIN: + retry++; + thp_retry +=3D is_thp; + nr_retry_pages +=3D nr_pages; + break; + case 0: + stats->nr_succeeded +=3D nr_pages; + stats->nr_thp_succeeded +=3D is_thp; + break; + default: + *nr_failed +=3D 1; + stats->nr_thp_failed +=3D is_thp; + stats->nr_failed_pages +=3D nr_pages; + break; + } + dst =3D dst2; + dst2 =3D list_next_entry(dst, lru); } - dst =3D dst2; - dst2 =3D list_next_entry(dst, lru); } + *nr_failed +=3D retry; + stats->nr_thp_failed +=3D thp_retry; + stats->nr_failed_pages +=3D nr_retry_pages; } =20 static void migrate_folios_undo(struct list_head *src_folios, @@ -2000,11 +2010,7 @@ static int migrate_pages_batch(struct list_head *fro= m, struct list_head *ret_folios, struct list_head *split_folios, struct migrate_pages_stats *stats, int nr_pass) { - int retry =3D 1; - int thp_retry =3D 1; int nr_failed =3D 0; - int nr_retry_pages =3D 0; - int pass =3D 0; int rc, rc_saved; LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); @@ -2024,21 +2030,9 @@ static int migrate_pages_batch(struct list_head *fro= m, /* Flush TLBs for all unmapped folios */ try_to_unmap_flush(); =20 - retry =3D 1; - for (pass =3D 0; pass < nr_pass && retry; pass++) { - retry =3D 0; - thp_retry =3D 0; - nr_retry_pages =3D 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); - } - nr_failed +=3D retry; - stats->nr_thp_failed +=3D thp_retry; - stats->nr_failed_pages +=3D nr_retry_pages; + /* Move the unmapped folios */ + migrate_folios_move(&unmap_folios, &dst_folios, put_new_folio, private, + mode, reason, ret_folios, stats, nr_pass, &nr_failed); =20 rc =3D rc_saved ? : nr_failed; out: --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013035.outbound.protection.outlook.com [40.107.201.35]) (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 8D89C47ACFD; Wed, 2 Sep 2026 10:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.35 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346426; cv=fail; b=i/rjvnh5NQ5Th5tqUTSyigrD+XN6ektg9054hoH/Zqg+Os2PVUJJ7Of6rxcche7Tpkwi5OCLIfFKORh5ZxF6nlGxQGMaLhzpX6HJvl++C9EzpiJKbVb484+nnf3c/FDWmkewpNpL0BK+sRY9S4fPEv6cETl/2tYAhGs5UAtzEzw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346426; c=relaxed/simple; bh=/JxnB8st+ToDiE6MnHWThIRZ2LywdNjTjPkffj1Qf68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=ha2Gc8UZLYop93UA7rFp+NCFDUvfIic852ef+uAzry0MFvl9J1OqGc2kt1DimynhQnp5/UpsTGiSEc6JcglF5l1mJjLNVwuWXk7IO9o7zdQGcQY2f6Y0YRXjo4kRuAgiNAUo7P3Si5P4to1Fl4N1/VdPX5MipYs6ymnhIdb0pLU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=mFCB1MsP; arc=fail smtp.client-ip=40.107.201.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="mFCB1MsP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AkgjLory456MAIGKbFAAxcc4JGtV5NTgeNIiXrIDIkUe3JysWRPtDh/Uohkmcnx7y+x4L81h3khYkeRB8NFYmEg5GuwmMfZcT/3LodAsHXYm50jsP4Q23+wA9UNEtQ0FNO4NHQ1VU5+HBQ0YSEMnam7IuNwTo1MgWUtko6Rr5XEJXvmobYXVvj1QXpa4qiH4SkLLEdurn27gAzI/JccdilWBDA6i0V7rjGBZPw5aE1UZOVu0nCQVTvhevlgtAgBmdnMxz3udMxuV6wsm13IAItNnAClh+O2E9iokF5mRd7f+IKn245skLXHJkhblAYBPH5hCz5caOulmqlGnha6aFQ== 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=bU+UL8NKIGvBCO/o+qeY9aeQfFCC3b6xl8+STqtXFkg=; b=Kh+cZ9ZE+HjnnMz7K8KD+USlw0RCwdzYTRbrrNpbayCUbf5+qCa6SPLdaohgVZR9jgRtgL9AuyMDusDRvysRKzUgdlfmlTxjI5Xs9Bw86CqsJd4uGJcDfPOkTz4zgBxh1+fYepHZ8gq2k8G+D03rwrPG0CVyiq/N+JqoDSGKYwXSsBlJiFcIf4y7SjDp4KxeSdJhasDNjLRkfWh4aLH79WXFKLbNgJM2X3YX3e/UGxVsYl4Bk7iVA1fvSgKmWstoMNVIm9e74RrzLE58FHjOrd3aVcKdEph7uDQ0KqA1Yiqw/ggIe/X1eRf0pyVNvkkv13/Euuow9nh+NkEvBOQeWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bU+UL8NKIGvBCO/o+qeY9aeQfFCC3b6xl8+STqtXFkg=; b=mFCB1MsP0OuX+GwywJB2fr0WnSvWSroA5Ip1TiCeJpb2mCZdIcv2jyNKagzjRMHZU3AoNXpV8aN+3Ekpgd+9uovgD5QrHgX/vG5/a3S7C8zMzM9YHzaCaknZ1tzR+qSFGZCAdzG78OL0v6yaVMLmLQdWi2kNiEKGeXj2fjEiRdc= Received: from BN9PR03CA0713.namprd03.prod.outlook.com (2603:10b6:408:ef::28) by SA1PR12MB6773.namprd12.prod.outlook.com (2603:10b6:806:258::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:53:25 +0000 Received: from BN1PEPF0000467F.namprd03.prod.outlook.com (2603:10b6:408:ef:cafe::9c) by BN9PR03CA0713.outlook.office365.com (2603:10b6:408:ef::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.11 via Frontend Transport; Wed, 2 Sep 2026 10:53:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN1PEPF0000467F.mail.protection.outlook.com (10.167.243.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:53:24 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:53:10 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:17 +0000 Subject: [PATCH RFC 03/11] mm/migrate: factor out folio splitting on allocation failure 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-3-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=3615; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=/JxnB8st+ToDiE6MnHWThIRZ2LywdNjTjPkffj1Qf68=; b=uthfNhzsNdSB9qClSgRMWX6hdgqq8bCKeKI9zTwDpd0pZFnJ3KatPzbj7TvfElm0ZmOlA1V7W NHiLIEYiVoHBGQbPdeS1V/97EdEqGpvWfO/+541WcNYjV+tBEI60ifk X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000467F:EE_|SA1PR12MB6773:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e2f9f49-7daf-4857-a660-08df08e0697d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|82310400026|1800799024|7416014|376014|921020|10067099003|56012099006|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: iPmU/b2Splm99CrkVXk93Y1Ie93q7bkIgwC+NZn37FeCidDDS3P1J9bOZH9gXu4foKOBleM838N1Q/x9wwaASsRCGFCzPSV+bYkcdhuVqVzcfv+0u02y9i17Hpv3VCGYPgobwnlcBE/XQnHDBRu8EKoNbbguL4pQN0HaB5ndjIZEH056AhRnenaEzCH56rkpjGmljZ2WBZys1rwW4NNJRys4sCh+51RxqPQ42VBN5wAqYxeh2nqlTjUJu6kdC2J8Il5w3UWi9MzP5+DBKvuPup7LPHL6sx0XKgAJbaagrKrTReZaidyNbqQ1ioAO+HmSiTKnx5avOucrD2iND1OxOIx0DQZ1YSeVcSBweou+49aM9dsxkkJ53DZr7I4U7o0OCwiIoDA4PXHUqXZWv0/TAfygpsSW8VUFGjSH1GfhbjQUxSKkdyj5TUTIwMePh6WA6XCP57ksJU9DAGEHlKo4NNmt58Hol06lG02uDUzewtboQoKzv0gWH9hWWwA5W8lQ5oRMWW8jiipqe5rF0sM5O7zX3R2WkRgRnVyAYTMX6r25FnZwSO5r57g9smUhYbf8YUuf91JelXOS/K3i42z9HHc1zxGv+M/yKuja23hmuYv7l4LlqFMrus3rQ9vCmkP7ZVUqaoHkh1ExOYZkZHRZchAmKF1ApcIqTchHoNiB/vouymGjmHnat+SUpHDvY2KiMZ1Uy5t1Qgbot/8xNSPrGycQQ/0Lhy03/vRNzFJMAe6vVknHg5TCK86TCmELVgJF X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(36860700016)(82310400026)(1800799024)(7416014)(376014)(921020)(10067099003)(56012099006)(11063799006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nITZiMGgOfmQDAiXF8/7ukiFQeu2QbjNsPWlxy/UITva8HASk8Hz8ZCMzf1UrVS50wB6pFvCTyRvP0yCPRq10L236Oetpt4kSSX6Iz1jRZL4Fait8HLkIR4g3a09jY224tnsPWbPxkeVfRkqXFtJ2tjpxgTyDM/NQ5jG94lX/2eanrVuCE55atKKaXgTAtOoIzgol2iiBMk7xBJPHw2PMEZp3Q4vCzRmBUta0fxEWJ43vnJbzqbwJXCl4LynKSsrnK6x6IGazuEhoR7sjIEzswICtqyzaA8QkYB9ObgBcMAkUaSmo4Xw+GKCh7S+HiIGIEOB1UpEVVO6ngpTS4BdhEv9zNFhHMAGgeObulm23uwEZz3uUBSJMRQBONbJeWGMkeLcVqMp/9ufIZjFD/pcow4qP81QyDAXQXOzGM9AWNkXan8PK1TYh+5OsmGccG8Q X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:53:24.4815 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e2f9f49-7daf-4857-a660-08df08e0697d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000467F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6773 If destination folio allocation fails, migrate_folios_unmap() may split a large folio and retry migration with smaller folios. Factor this logic out into migrate_folio_split_on_alloc_fail() to simplify the allocation failure path. No functional change intended. Signed-off-by: Shivank Garg --- mm/migrate.c | 69 +++++++++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 89207bf515b9..510dfffa7235 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1809,6 +1809,34 @@ static void migrate_folios_undo(struct list_head *sr= c_folios, } } =20 +static int migrate_folio_split_on_alloc_fail(struct folio *folio, + struct list_head *split_folios, enum migrate_mode mode, + enum migrate_reason reason, struct migrate_pages_stats *stats) +{ + bool is_thp =3D folio_test_pmd_mappable(folio); + int rc; + + /* Large folio NUMA faulting doesn't split to retry. */ + if (!folio_test_large(folio) || reason =3D=3D MR_NUMA_MISPLACED) + return -ENOMEM; + + rc =3D try_split_folio(folio, split_folios, mode); + if (!rc) { + stats->nr_thp_split +=3D is_thp; + stats->nr_split++; + return 0; + } + + /* + * Try again to split large folio to mitigate the failure of longterm + * pinning. + */ + if (reason =3D=3D MR_LONGTERM_PIN && rc =3D=3D -EAGAIN) + return -EAGAIN; + + return -ENOMEM; +} + /* * Unmap the folios in @from, queuing successfully unmapped sources on * @unmap_folios and their destination on @dst_folios. Increment @nr_fail= ed for @@ -1829,10 +1857,8 @@ static int migrate_folios_unmap(struct list_head *fr= om, int nr_retry_pages =3D 0; int pass =3D 0; bool is_thp =3D false; - bool is_large =3D false; struct folio *folio, *folio2, *dst =3D NULL; - int rc, nr_pages; - bool nosplit =3D (reason =3D=3D MR_NUMA_MISPLACED); + int rc, split_rc, nr_pages; =20 for (pass =3D 0; pass < nr_pass && retry; pass++) { retry =3D 0; @@ -1840,7 +1866,6 @@ static int migrate_folios_unmap(struct list_head *fro= m, nr_retry_pages =3D 0; =20 list_for_each_entry_safe(folio, folio2, from, lru) { - is_large =3D folio_test_large(folio); is_thp =3D folio_test_pmd_mappable(folio); nr_pages =3D folio_nr_pages(folio); =20 @@ -1937,28 +1962,20 @@ static int migrate_folios_unmap(struct list_head *f= rom, */ *nr_failed +=3D 1; stats->nr_thp_failed +=3D is_thp; - /* Large folio NUMA faulting doesn't split to retry. */ - if (is_large && !nosplit) { - int ret =3D try_split_folio(folio, split_folios, mode); - - if (!ret) { - stats->nr_thp_split +=3D is_thp; - stats->nr_split++; - break; - } else if (reason =3D=3D MR_LONGTERM_PIN && - ret =3D=3D -EAGAIN) { - /* - * Try again to split large folio to - * mitigate the failure of longterm pinning. - */ - retry++; - thp_retry +=3D is_thp; - nr_retry_pages +=3D nr_pages; - /* Undo duplicated failure counting. */ - *nr_failed -=3D 1; - stats->nr_thp_failed -=3D is_thp; - break; - } + + split_rc =3D migrate_folio_split_on_alloc_fail(folio, + split_folios, mode, reason, stats); + if (!split_rc) + break; + /* Retry this folio in a later pass. */ + if (split_rc =3D=3D -EAGAIN) { + retry++; + thp_retry +=3D is_thp; + nr_retry_pages +=3D nr_pages; + /* Undo duplicated failure counting. */ + *nr_failed -=3D 1; + stats->nr_thp_failed -=3D is_thp; + break; } =20 stats->nr_failed_pages +=3D nr_pages + nr_retry_pages; --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010000.outbound.protection.outlook.com [52.101.201.0]) (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 14B6B46C852; Wed, 2 Sep 2026 10:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.0 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346447; cv=fail; b=Z2zBlzvWZgm/K52PgO844cs7GgHWQT5YGta5mO0eKCNkv5tIDgg2aDe3sTQJLWiym2zVfkVW4uzkttPtgrmrMIvIuBPLFj2el5eOi78wlkXSveR4Z6OJRyr7LCBS/rwTDS29oPeyQTC2FM1QulBcGBdoWwqLFxwePboGRiiA8Dk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346447; c=relaxed/simple; bh=VlSFNAND6SnpBBF3+pJnsJtkrGSAlaiY/oieiuTQDjI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=r3IiQib97OgFR1ywEyn9YiDL5oaATw39NMT2gQol5UU2zLbrfAPrx81DWc7bw43qifeJn5iQ5bahAbdnZo9K9/kDxdZv2uK2AVYK3idS5AiHouoYeSQU833LUd+b4QQ2OyZiMPcRNCf6UkRIpq9Ty8SMaB9tUhkf5ICDQAn/lGs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ATwjC9Ve; arc=fail smtp.client-ip=52.101.201.0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ATwjC9Ve" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vfBc8V3lffiFXIMLjB8dH3ZhojZvpCnSSOkpK3QdTWy8wT438zireTSQezbCO+iTSXIxMFaynxLZydTeUodhvI90QwXG4RHQ5fO1bPLSpvLh6c+fCWYNBt0KJC2UlJPoEsHMEyrjNlDzE6hdRW2tIa+JOK3UNWgoe8O+6m0z6xE5hRUfLKHxcoJPk/EUh/nDkjQZqfyIadYkOjZ7VnMieic30xKQ92YZzIwUim0iTXQLUXK8ROGGtYWdEV31PEDh2zd077xif6fs9pbu/rUzVWSxGl2APL887dfI+WT3vHuV3c/WYooynLszIfF75fuxNn0ZhkvpnnIwA5PtePjnYw== 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=aWr4bvvbw5bvm5oL4VFn72K+pg4VO4PWtKMFN92Gnm8=; b=O4rOBNGy93vdyhKJsYYPw5eZ+t/iJcPSbHV7gdPe0dmLePNHuy9odl508OTh+9vSc32b84uy6OujwlMn9tz1MAMfOmzTURp9OJLARDif7artjo9w0ONyi0dwpxNZd+oJQl2eequGCyUlLJqdqi1OM6ybYid0R8TMtzAkWhO0pMldsBk7oNKzJBL4M+JacuzyAFkKh0GxWPRDeEwEPMzjv7u3pQVwqd5CBMjHP7mBRFji0MckhrDN+GzngxtPOM686cNQtmGpaoAZECnr7FzpsPEusxg2VVbRxReP/1IK4DU7IXtgW3Aovg9R7z+gbH2MTqTbZdWfKdJ/A9IoBEGBhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aWr4bvvbw5bvm5oL4VFn72K+pg4VO4PWtKMFN92Gnm8=; b=ATwjC9VeszYc9gTgolpFejMaLxu5BJWLvGIHADakcasmIpKYn3ZlhWclJ40334QiRO7Ya528Tn26+Z7N8OhwuuVnNE6BvkBDcHBU3WNAbVoci4m08eQitinppRjzCXo7BuS4gnwJ1jV6YBggbQl7W9VqTr6PX4S4BD3MJHyZWk4= Received: from BN0PR07CA0022.namprd07.prod.outlook.com (2603:10b6:408:141::14) by SN7PR12MB7105.namprd12.prod.outlook.com (2603:10b6:806:2a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:53:38 +0000 Received: from BN1PEPF00004683.namprd03.prod.outlook.com (2603:10b6:408:141:cafe::85) by BN0PR07CA0022.outlook.office365.com (2603:10b6:408:141::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.11 via Frontend Transport; Wed, 2 Sep 2026 10:53:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN1PEPF00004683.mail.protection.outlook.com (10.167.243.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:53:38 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:53:24 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:18 +0000 Subject: [PATCH RFC 04/11] mm/migrate: use a dedicated list for hugetlb folios 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-4-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=3801; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=VlSFNAND6SnpBBF3+pJnsJtkrGSAlaiY/oieiuTQDjI=; b=aw3wzdkKJY9UFNX5TTTWthol5mESU/+Pct7T6sKEZ9lFRDITy/dGihQe0QzZowvjvJuiv7/pL vQlQvkOQVpiBP1ZxJVaCn2ZrAgds3kk6XVf50KCgJKSdyk7AaoPz3zv X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004683:EE_|SN7PR12MB7105:EE_ X-MS-Office365-Filtering-Correlation-Id: f68a553a-bb09-4804-c7b2-08df08e071dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|82310400026|376014|7416014|23010399003|1800799024|921020|10067099003|11063799006|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: UfdRpVIHS6/Tg9UrLnmJAOaUOQuX0CX09NsEbAn43ij7AY6jfkQDTbgIQ3E+yrXzuisEkgUpDp41ejLTPxjGCCKeU14D3P9814lbwEP28zNzL7v7YTBwZSkCUU1o70m2Q1P8N29v9MJZtxB32CBD+6lcy6s09pgy052JXS+CEWsqmoZaKrn5wwN7BUfRTnq2Zip7WiuGk9ufhXhLSLG8UM1AAkTBiCtFiy/aaGQ/xeNcivaE2sCm9j/Mzm1TehcUJ/G215TCLyheo/2+tyOr4LDPDMJhxP9YPO+38Sck6rSqAGZqyOqTfeAKvdq1IuGYPxjF6UyPmnxNUpzOljmOBZuMxD2KGsLzCoFjmy5Wq/bw52SNmrgzR7RT/Ll6bC6iasjubH/1sHvb5nS9ehnI3De3JunawC8zH385M0ZbEbs5Cw4ehnQuiLvmL3cdRKUszguxxr5+umKriA3SWCrocOZV3FsKWDT8kQmohk3d8Xjxiz8Zl/cJNzRzwCyeqesusPamoRK9qDXy+Yp1ZvfEgKSay5JMlLR5EgJETfyArpk99HIsUwSN5lj3ZploEy9WOh1VvzAx5glyt1nnt4Uh4wcw5IM/1w/rahRuSKvV0aPZABFE6iD7g/zwb0aj5ICjCZdtGuF3cMxJ03BdhZIHYxhHSTWBrpsYfsh+GCJH321H5cuBS/wGi5Kuv/7vSqt15sY1LjWAYHkWx+OSoxOZYCiKnYr6QvwGP4wsEDSVE+We8VuJMYVpgmch2CJpDjq8 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(82310400026)(376014)(7416014)(23010399003)(1800799024)(921020)(10067099003)(11063799006)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: arY20hyuwLiaSz9KMrD+z6cgcB8BPzyZj56SdmzIQ64I9qsFjUC2F+kZDatEv+blhAM8zWlYFdTSkqxhIIFjAd736snFBNk1H/vm/jCoHxK/gKx7XPEa38gIpyTwZ+CjNkvKpqTr8Y9LbF/o+3uyxlqWiBajgxQXm+gLt6BrzDEKiKkoomHHjmmFVfJjdnwf8yApoeN9SttQxix6Q1qqxKK/ICFqLrErIrVUkH0j9leJBOGbt8ypAzgKYjJ7Wi3Wm1TZvn05FS8DSYVioP/sSJfyZT6q/pdg3pbMcjorRokPBjD3aOYjV0r+7KEB3oQgZi0A+WRPM3dY2R4LQ/d6NeILzXYpHZqy+EVcHRxDnuiDO+lPiz43Q6lfRbJHb0oNYyoWSO4+RaK1fNaLHWm1MBP8T8nxM/fgI7lryo48fTje/RAEyP9gKkCWCqfgQ+7u X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:53:38.5472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f68a553a-bb09-4804-c7b2-08df08e071dc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004683.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7105 migrate_hugetlbs() scans the full source list on every retry pass, even though it only handles hugetlb folios. Move hugetlb folios to a local list before migration and move any remaining folios to @ret_folios. This avoids scanning unrelated folios and removes the later hugetlb check from migrate_pages(). No functional change intended. Signed-off-by: Shivank Garg --- mm/migrate.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 510dfffa7235..7a136cec275f 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1629,11 +1629,12 @@ struct migrate_pages_stats { }; =20 /* - * Returns the number of hugetlb folios that were not migrated, or an erro= r code - * after NR_MAX_MIGRATE_PAGES_RETRY attempts or if no hugetlb folios are m= ovable - * any more because the list has become empty or no retryable hugetlb foli= os - * exist any more. It is caller's responsibility to call putback_movable_p= ages() - * only if ret !=3D 0. + * Move hugetlb folios from @from to a local list and try to migrate each = folio + * up to NR_MAX_MIGRATE_PAGES_RETRY times. Any remaining folios are moved = to + * @ret_folios list. + * + * Return the number of failed folios, or a negative errno. + * */ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_fo= lio, free_folio_t put_new_folio, unsigned long private, @@ -1646,16 +1647,18 @@ static int migrate_hugetlbs(struct list_head *from,= new_folio_t get_new_folio, int nr_retry_pages =3D 0; int pass =3D 0; struct folio *folio, *folio2; - int rc, nr_pages; + int rc, ret, nr_pages; + LIST_HEAD(hugetlbs); + + list_for_each_entry_safe(folio, folio2, from, lru) + if (folio_test_hugetlb(folio)) + list_move_tail(&folio->lru, &hugetlbs); =20 for (pass =3D 0; pass < NR_MAX_MIGRATE_PAGES_RETRY && retry; pass++) { retry =3D 0; nr_retry_pages =3D 0; =20 - list_for_each_entry_safe(folio, folio2, from, lru) { - if (!folio_test_hugetlb(folio)) - continue; - + list_for_each_entry_safe(folio, folio2, &hugetlbs, lru) { nr_pages =3D folio_nr_pages(folio); =20 cond_resched(); @@ -1681,18 +1684,19 @@ static int migrate_hugetlbs(struct list_head *from,= new_folio_t get_new_folio, /* * The rules are: * 0: hugetlb folio will be put back - * -EAGAIN: stay on the from list - * -ENOMEM: stay on the from list + * -EAGAIN: stay on hugetlbs, retried by a later pass + * -ENOMEM: give up; rest of the list goes to ret_folios * Other errno: put on ret_folios list */ - switch(rc) { + switch (rc) { case -ENOMEM: /* * When memory is low, don't bother to try to migrate * other folios, just exit. */ stats->nr_failed_pages +=3D nr_pages + nr_retry_pages; - return -ENOMEM; + ret =3D -ENOMEM; + goto out; case -EAGAIN: retry++; nr_retry_pages +=3D nr_pages; @@ -1720,8 +1724,11 @@ static int migrate_hugetlbs(struct list_head *from, = new_folio_t get_new_folio, */ nr_failed +=3D retry; stats->nr_failed_pages +=3D nr_retry_pages; + ret =3D nr_failed; +out: + list_splice_tail(&hugetlbs, ret_folios); =20 - return nr_failed; + return ret; } =20 static void migrate_folios_move(struct list_head *src_folios, @@ -2161,12 +2168,6 @@ int migrate_pages(struct list_head *from, new_folio_= t get_new_folio, again: nr_pages =3D 0; list_for_each_entry_safe(folio, folio2, from, lru) { - /* Retried hugetlb folios will be kept in list */ - if (folio_test_hugetlb(folio)) { - list_move_tail(&folio->lru, &ret_folios); - continue; - } - nr_pages +=3D folio_nr_pages(folio); if (nr_pages >=3D NR_MAX_BATCHED_MIGRATION) break; --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011032.outbound.protection.outlook.com [52.101.52.32]) (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 E111447D945; Wed, 2 Sep 2026 10:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346458; cv=fail; b=XyGWPVj/4GTfzEzylhX1lvUfCfrRfkNNSMxhhykqdpJKDfLjizN5kf5qSMjS7gUl+/0UYIA3QxeZ7GQQbluCuRdJbU7hDkRKYE0cnPaOhIpLUhWGy/3xhmWLg6kYwUqT+3xkWcr3I/Msgi7iXJsH42uUSzwHZGjW53ovfMOLN3I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346458; c=relaxed/simple; bh=RI02LIU5Xi5+P6WIx4/tIFhoYu3m0iIqrPm3yd4Pync=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=X+q3HC96KPGdF6jn9LhEEa6c5tbEUULW+wa0Vx+2Gsfr6ZeSUi80gWNZa7iJY6R8jxvr+yEpym7Yds7bDziIiLW58plEHuRuXGhD1aEbOJD2t3BcMUbTIRCiYkUoLa5ZgotA6W/Yx9mlbgj8OlSa0J9BWRR5abaa5/T16wrLUHc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KJVsKZmq; arc=fail smtp.client-ip=52.101.52.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="KJVsKZmq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kd4rbzA4h2ohuWRDSW2ETZ1bg3pTm2JvmOEkAG9pABPCERKQ0My2sxtnurkYOKUMC/V58tEleKU6JdjzDi7Lqja5JrlZe2ISdqI4rJC5Jp8yUU9+Ucq0+KmyXU0GId5XWEhcnJxISPvh6pkUXT6QF9ql+E6FBIYFZlqY0wy2EiTDGFfrCHE0eDBLgSE9gSqfAz2RoVjM9yYLUzoiG+zqwydQ152XcYNBohSAmnvOcJKA+IX13TBy11HH2RnyJTMcSJthy/bpCJOu5gapOu2W/RdnfpqZrCgBzwz2O6TWxtLa2AbAnscuGhfB1WK9tPFXkU/t2haaeN06Eus4Viw4vQ== 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=UvMQi60+FK1dsYsCkrpCg0bZwxaBYKJwFTlW/+3nxs0=; b=hGcURAFlDFaN67O54aplpIIF2V8bOYNbkUN2dHEIedJYXrERwedeH+k5JyHQhzPLZJswVw53+KX0eIwaGMsMuntWX7lF6qlIqQZgYX6+KvTNNZmF2ZWZH6YPxDDDJw7H5D7EQ9gUOXlt6GBMMCFelVjoMqUzU57lsMbE7q26FtMbSGTv9dix5bou2Vxq2GZU8JDrYh2UWL/XTMxBvpfAnF4A9J6HLHgFTMsrZx7CkF8F13URoRgaGGsCRh9vlvBad6uxT0/fVmMKqwD3h0Ed4/bnALf0GONlVddH/Y5KTcjeYBhI5HP8AYpQeqdgxWSfYC3/Ix/zIUOfNZw5gfbXzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UvMQi60+FK1dsYsCkrpCg0bZwxaBYKJwFTlW/+3nxs0=; b=KJVsKZmqWyvBnly57LP8j92xJ1D5zHt4BKzxOwl9fOlqSmy1hNJYzVvgLp2+Ruupr8purDFcBNFDMaR1Wgg4nJiUP/NbsG8yvknF63XyksfPSojvLNwdwP1YDzZpVRS4puPpsMncFHeeM8gm7NopXPjrMUGb7DYcV4/oZ4xwRN0= Received: from BN9P222CA0028.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::33) by DM4PR12MB6206.namprd12.prod.outlook.com (2603:10b6:8:a7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.8; Wed, 2 Sep 2026 10:53:53 +0000 Received: from BN5PEPF00046988.namprd02.prod.outlook.com (2603:10b6:408:10c:cafe::24) by BN9P222CA0028.outlook.office365.com (2603:10b6:408:10c::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.11 via Frontend Transport; Wed, 2 Sep 2026 10:53:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF00046988.mail.protection.outlook.com (10.167.245.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:53:52 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:53:38 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:19 +0000 Subject: [PATCH RFC 05/11] mm/migrate: add a dedicated movable_ops migration pass 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-5-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=7549; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=RI02LIU5Xi5+P6WIx4/tIFhoYu3m0iIqrPm3yd4Pync=; b=RgY8vSnVIPQsmK943ISVn6MTBagX09K5oB348FwCOtuM9MSJH0KouONPqM5xSgCuB6HKJbT1g GGA6rUEJZdGC5n7GadcCcNT3I8f8fzzWx31E3cImzeyhxTKOIRGl7om X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF00046988:EE_|DM4PR12MB6206:EE_ X-MS-Office365-Filtering-Correlation-Id: f937f727-3c07-4d69-c0d4-08df08e07a6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|23010399003|36860700016|1800799024|7416014|376014|921020|11063799006|10067099003|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: JLmKwFcWA2ODtF1rJV7WikYZo/kj67e0p+yiPjpjzLaJapqNvdztWQ+yzjtrw/gfORv4JynGHzkHF5ZwYc5Vqqkb5b6ndJkCfo36mJGRhhfWbzWH/dsSTeaY0vFKCoVX5xSNJ6ABR44zmYxVOB7AX5kVvZwtrloZ5p3we3ibf/yqC1fNr/NQtcCAMsezzQu2PYif0hORmbiheiZgbXEx15TI9rFm4z+yXnpQse5ol0C2wmiObA/Ufl3aeow6ZjYK13PAfcEr7Mm+fpGONYnjYujB9hh2IRjNQzFYjrkpP50iEeX7Uo5gliok01KnsyIQ5oQGIS3ZLFYkw/mJEIfzdl4Qm0f11XB02I2BCz2baJ5FFSwM+C5bB0OjAqrMfMOKdD26k2FdiOCEs3G/b26hXnE68yjOneWHuoPpaboYvmHrfkzGkH+xgjGYXED81/TRcCfvnYJ6ZwRHNlOteZ0YwigC7yVWxnZK8ecN/1Rxk25tn7e9nX1ioW+EBbtvBLnr2aX1HX4O4mNAEvHV9nvkgyBKkREQqAwBiLxXb9BBzpAgMvQOFHTAW/Yxcs82Nq47TlMN2Jh0mwloAhcHpnxTVysP5fcdJNh6JT3epZC40rDhWgDNQlyZQzZD8/x8cOrLmTbc3cYPpbE4by6USDAqgC/b20FVVN8OK1aClYaoLbNeQnC9BbHFjTBVXHIxZayc9gymAj6RQ/fgEC0U5W9JipimTxTQLUODlDLe/VKikgJdlBaVZuuGxypYiQztQCZz X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(23010399003)(36860700016)(1800799024)(7416014)(376014)(921020)(11063799006)(10067099003)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Rzl/PSo5863amWDCOMMJnDej+UR52MhjzYogGUotGK0/LH2WoUNcTUs+7bUhxxz1nBBoaT+gdjjDRKf5OuC0aZBOfxuDslKHZeq5wQnh8vRAqKIDHqH4zJSAqKnaB9XlSMtPEZNP+V41oRil74Kili9bCKXcL5I0LnRSDNMfNAJlSIOwNuikrRA66dGjOTshGSoe6IaDNvpuNAzgaMfD+vMzvXFK9dd9Q1vzWLGl3/mOvjmHGESREMtmMRWxChRaRddEglpb7sQ03/I1P41ShT8ZgGxtqr2+zvg610mU4mz31f3y/Kck06a1uJyjXcA7JhUnuqQURaZz9Vi402uVPDwaPRjdc4PVWyzw9xzZhnUmnKBOGYgwhAHN7K5OGakuOU6gml6EMMv8vsPt7ccoeYfGhiJ7uopCHaPXLkDEuHeO+7OnJsCr1jnvU98luc1T X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:53:52.9141 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f937f727-3c07-4d69-c0d4-08df08e07a6c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF00046988.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6206 Pages with movable_ops transfer ownership through a driver callback and do not need the unmap, TLB flush, copy, or LRU handling used for LRU folios. These pages are expected to stop being represented as folios. Separating their migration from the LRU folio path prepares for that conversion. Add migrate_movable_ops_pages() before LRU folio migration to handle allocation, locking, retries, and cleanup on a separate list. Return remaining pages through @ret_folios and remove the now-unreachable movable_ops branches from the LRU path. This changes three details of movable_ops migration: - Pages are processed before LRU folios rather than in source-list order. - Synchronous callers use the requested mode from the first attempt instead of the LRU asynchronous pre-pass. - A callback returning -EAGAIN ends the current attempt, so a later retry allocates a fresh destination. - MIGRATE_SYNC_LIGHT waits for the page lock instead of giving up, because !uptodate check is not applicable for movable_ops pages. Suggested-by: Zi Yan Suggested-by: David Hildenbrand (Arm) Signed-off-by: Shivank Garg --- mm/migrate.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 140 insertions(+), 16 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 7a136cec275f..55f352efdf2b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1200,7 +1200,7 @@ static void migrate_folio_undo_dst(struct folio *dst,= bool locked, static void migrate_folio_done(struct folio *src, enum migrate_reason reason) { - if (likely(!page_has_movable_ops(&src->page)) && reason !=3D MR_DEMOTION) + if (reason !=3D MR_DEMOTION) mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + folio_is_file_lru(src), -folio_nr_pages(src)); =20 @@ -1309,11 +1309,6 @@ static int migrate_folio_unmap(new_folio_t get_new_f= olio, goto out; dst_locked =3D true; =20 - if (unlikely(page_has_movable_ops(&src->page))) { - __migrate_folio_record(dst, old_folio_state, anon_vma); - return 0; - } - /* * Corner case handling: * 1. When a new swap-cache page is read into, it is added to the LRU @@ -1376,13 +1371,6 @@ static int migrate_folio_move(free_folio_t put_new_f= olio, unsigned long private, prev =3D dst->lru.prev; list_del(&dst->lru); =20 - if (unlikely(page_has_movable_ops(&src->page))) { - rc =3D migrate_movable_ops_page(&dst->page, &src->page, mode); - if (rc) - goto out; - goto out_unlock_both; - } - if (folio_order(src) > 1 && !data_race(list_empty(&src->_deferred_list))) { src_deferred_split =3D true; @@ -1418,7 +1406,6 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, if (old_folio_state & FOLIO_WAS_MAPPED) remove_migration_ptes(src, dst, 0); =20 -out_unlock_both: folio_unlock(dst); folio_set_owner_migrate_reason(dst, reason); /* @@ -1816,6 +1803,135 @@ static void migrate_folios_undo(struct list_head *s= rc_folios, } } =20 +/* + * Migrate one isolated movable_ops page. Keep @src on its list for retry = and + * move it to @ret_folios on permanent failure. + * + * Return 0 on success or a negative error. + */ +static int move_movable_ops_page(struct folio *src, + new_folio_t get_new_folio, free_folio_t put_new_folio, + unsigned long private, enum migrate_mode mode, + enum migrate_reason reason, struct list_head *ret_folios) +{ + struct folio *dst; + int rc =3D -EAGAIN; + + dst =3D get_new_folio(src, private); + if (!dst) + return -ENOMEM; + + if (!folio_trylock(src)) { + if (mode =3D=3D MIGRATE_ASYNC) + goto out_put_dst; + if (current->flags & PF_MEMALLOC) + goto out_put_dst; + folio_lock(src); + } + + if (unlikely(!folio_trylock(dst))) + goto out_unlock_src; + + rc =3D migrate_movable_ops_page(&dst->page, &src->page, mode); + folio_unlock(dst); + if (rc) + goto out_unlock_src; + + folio_set_owner_migrate_reason(dst, reason); + /* Drop migration's reference after transferring ownership to dst. */ + folio_put(dst); + + list_del(&src->lru); + folio_unlock(src); + + if (reason !=3D MR_MEMORY_FAILURE) + folio_put(src); + + return 0; + +out_unlock_src: + folio_unlock(src); +out_put_dst: + if (put_new_folio) + put_new_folio(dst, private); + else + folio_put(dst); + + if (rc !=3D -EAGAIN) + list_move_tail(&src->lru, ret_folios); + + return rc; +} + +/* + * Move movable_ops pages from @from to a local list and try to migrate ea= ch + * page up to NR_MAX_MIGRATE_PAGES_RETRY times. Any remaining pages are mo= ved + * to @ret_folios. + * + * Return the number of failed pages, or a negative error. + */ +static int migrate_movable_ops_pages(struct list_head *from, + new_folio_t get_new_folio, free_folio_t put_new_folio, + unsigned long private, enum migrate_mode mode, + enum migrate_reason reason, struct migrate_pages_stats *stats, + struct list_head *ret_folios) +{ + int retry =3D 1; + int nr_failed =3D 0; + int pass; + struct folio *folio, *folio2; + int rc, ret; + LIST_HEAD(movable_ops_pages); + + list_for_each_entry_safe(folio, folio2, from, lru) + if (page_has_movable_ops(&folio->page)) + list_move_tail(&folio->lru, &movable_ops_pages); + + for (pass =3D 0; pass < NR_MAX_MIGRATE_PAGES_RETRY && retry; pass++) { + retry =3D 0; + + list_for_each_entry_safe(folio, folio2, &movable_ops_pages, lru) { + cond_resched(); + + rc =3D move_movable_ops_page(folio, get_new_folio, + put_new_folio, private, + mode, reason, ret_folios); + switch (rc) { + case -ENOMEM: + /* Count this page and those awaiting retry. */ + nr_failed +=3D 1 + retry; + ret =3D -ENOMEM; + goto out; + case -EAGAIN: + retry++; + break; + case 0: + stats->nr_succeeded++; + break; + default: + nr_failed++; + break; + } + } + } + /* Count pages that exhausted the retry limit. */ + nr_failed +=3D retry; + ret =3D nr_failed; +out: + /* movable_ops pages are order-0, so one failed page each. */ + stats->nr_failed_pages +=3D nr_failed; + list_splice_tail(&movable_ops_pages, ret_folios); + + return ret; +} + +/* + * Split a large folio after destination allocation fails and queue the re= sulting + * folios on @split_folios. + * + * Return: 0 on success, -EAGAIN to retry splitting later, or -ENOMEM to s= top the + * unmap phase. + */ static int migrate_folio_split_on_alloc_fail(struct folio *folio, struct list_head *split_folios, enum migrate_mode mode, enum migrate_reason reason, struct migrate_pages_stats *stats) @@ -1940,8 +2056,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, * If we are holding the last folio reference, the folio * was freed from under us, so just drop our reference. */ - if (likely(!page_has_movable_ops(&folio->page)) && - folio_ref_count(folio) =3D=3D 1) { + if (folio_ref_count(folio) =3D=3D 1) { folio_clear_active(folio); folio_clear_unevictable(folio); list_del(&folio->lru); @@ -2165,6 +2280,15 @@ int migrate_pages(struct list_head *from, new_folio_= t get_new_folio, if (rc_gather < 0) goto out; =20 + rc =3D migrate_movable_ops_pages(from, get_new_folio, put_new_folio, + private, mode, reason, &stats, + &ret_folios); + if (rc < 0) { + rc_gather =3D rc; + goto out; + } + rc_gather +=3D rc; + again: nr_pages =3D 0; list_for_each_entry_safe(folio, folio2, from, lru) { --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013070.outbound.protection.outlook.com [40.107.201.70]) (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 C24ED47DD50; Wed, 2 Sep 2026 10:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346461; cv=fail; b=pvhat79osU3VavRYijHpDFY3UZQuvxQLpwCU7oqy32ljgqS3NIW9Tm2qm9/flUX8Q/IfEnuTUqDUcDR2Kvn0YNgo7DblEjJ6h0SwI7/+XgYed8rE4pyhU10uPChivauM/XSjNIiu+wDoCUZE33jWgNDXkCsyocEMhyMMwNaD5oA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346461; c=relaxed/simple; bh=Fqi07cuj0t9DVgFdFNJBSPyRAcnfPff5xqiyG0YOAAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=nLtwTCgWCq/wIwV6lcROYDedGOri8UGXfnYTTNtXrcUdlbfIHiPhl+c9a+eWBMCmjF3pnufcqQM3Ix0xuR2fP6DYfWIKwNhkzcgTdkTDNLnIOdRMcp5vgKMKEW6dzqh0VqNfTanD4OauYkC+EBXtAa80N21cLfClorLqlorqLMk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=XkSr4OIV; arc=fail smtp.client-ip=40.107.201.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="XkSr4OIV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iIaoH0+VMqzW4UnCD/UPupJ3APS7/eh14+pokliPzOyQoNk68yQNASNKuzwAFyKDRzBJRA9WRDtfAqXHvvDJRH68DR+7wZCSs+8NlFr/2hapwcD7y7WiedacDyt3DZf6Unj/aatADOHIoCVs75eXGVHvendXS58XnrhFghQVmOSO3pmEI9cf9ipk5HWvWPJsX8yg7nlLoDXoc9gBDwxOZoglIvOuznCW1kOcMDFfU7eYbzvz881rt0f1GCMrkscf7b3acKLoBSHKIbetu4P4lnR1pP31i4doqLGlEx4DH1dsm1Ur9MM0W+uzuZ6phpT49wJ0Len86uzGVrXBFWf/XA== 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=EUHxLZc87SIo516dLR77xd1rSetSYWKvVm1R29rwnEo=; b=DaM5DE60asU/X4fCw0hPREJNYlnf7Yzekpw1pBVAWcAhUwbroSjnETeEf/VMKOBIpqu4EOuOdj1vIlzs2q/o84bGxj0gjShiS5TtWtHcchdVhw0Zo1cs6Lxss6Y0gqYkwNTK9eykZ2WBvjSTxT/+CLDGgtjPMsns1Cn/5xPLcVNAAWFj/MwSB/ByCfNbmUb/+6w5+r4IcluChYYGmXdiup+EnOuGS0mVgq7uXjzIo5nTcjunn37vPkMEDbOYjcLncqP/yW47WbTNJMkR+PymwUN3oxsgO4YBlpFEHOguIKTCxIKGXzWSOw0E/xAeVOWwQx/qxMo72iviGfpmAFxRgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EUHxLZc87SIo516dLR77xd1rSetSYWKvVm1R29rwnEo=; b=XkSr4OIVNDkzw4Fd4JubaEBjjaNHFc6KjZoEKeDbEFwTO7+X1RJ1v1dV9PFStwADGlz4J49KS+Cue7/JaLMu3iN7V7uPDAWU8BkG2Th6TkFBVOAlnoehF2BAJMVb7I7ngit0Bhw88FHKWISWpgeN+PeubhoPeuULK0R91JjOPZI= Received: from BN0PR08CA0022.namprd08.prod.outlook.com (2603:10b6:408:142::7) by PH7PR12MB5805.namprd12.prod.outlook.com (2603:10b6:510:1d1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:54:08 +0000 Received: from BN5PEPF00046987.namprd02.prod.outlook.com (2603:10b6:408:142:cafe::78) by BN0PR08CA0022.outlook.office365.com (2603:10b6:408:142::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.10 via Frontend Transport; Wed, 2 Sep 2026 10:54:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF00046987.mail.protection.outlook.com (10.167.245.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:54:06 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:53:52 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:20 +0000 Subject: [PATCH RFC 06/11] mm/migrate: rename migrate_pages_batch() to migrate_folios_batch() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-6-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=4160; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=Fqi07cuj0t9DVgFdFNJBSPyRAcnfPff5xqiyG0YOAAw=; b=VHLvgbIhFwCVKeh3oI8OLZ9ydq0iu/G94dLsgBxliBbC+D46x3iUwPS7POszEmY//eC7P6oMg gV+QETr+4YXAqnn+IE+sRMapWHGUQIqQCmMzyFGF194eBrHcUM44WS9 X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF00046987:EE_|PH7PR12MB5805:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e69fecc-25f3-4590-34a3-08df08e08298 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|23010399003|36860700016|1800799024|7416014|376014|921020|11063799006|56012099006|10067099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: wCiWB8umVAN6134xVLMiVPh1HwKUaAPCTI8G4upmfK1rHsH3dPW+47NrjMXaBHkbxJP0py2uYnXLmWTub5t3bIPD5GQn5PswYtQKA007xX6m3iIdRh+PvedmBXNkFfWw3uk1Zs1n892OyOQCMUyErlgHqzXEHxSv7WQEUUth9G78c2UY171U8hhNaRAuEmXXHmkaNAr6kCQttBt05WD5NbxwWr02nSEC5hyZBDh6UZcC6U34cyg4nHhZZ/NefebEZrbyC56nKd1ikttLU4k7PxZPLxPqZ9L/bGc4MzOqeSumrL5Pf6kOeABSNFg5p26wfM6+fhZBoJeY7CyTyH8ytNkM2tlyZ2sEWuT1z92MBM0a5O8BBT1QcwdxYc6cvcUlOX2A9GwBZajnWuYfH10S1xV1HWTEr2/22JGNPQ5bX7RGWKEYm5Bbmc5kn6eK8SuYWLCqEAlBf8q0rlxoaITygu9B8fgzJJgSk3K76CsmPI4P1zDNaXg/FA6vQqQf3IlvH4i5dkQUkDu9St1Dtq16LSuMVAUbQL8LLdM+xNkdDhY7tGL4yl+ayev7tV2cY019zCRv0sFGy1yjkYHeQmzSSVm8u/VxIJHWG1p6Bei1spQFwfhrpDDFvHx6iLPYFUcs55QC+wYEmzom0x6REQZByfUIAJ3KrJtHFft3qM1hQBBaGxB38HLrutWSYIXyLAkDRcpptrV122T+tAOTCdhLeKVwL8BLrejgSyLKANPrUrfZsN/S0rWMabr84xd+3xAn X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(23010399003)(36860700016)(1800799024)(7416014)(376014)(921020)(11063799006)(56012099006)(10067099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vcf/vHEnOgh/JYtjSJnVGWMwa4G08e5YASq1Da20l61TbFQrUh0TfM/Ey4IZLrnoEOh85gSJoY7XmnsLH6NBvpQGpmKulUgKmI3Cey5TUpjZU0eFCPlikBZ7+oqj8PW4EuGHkYMBLZIiineTHxGRDJTOLwkrnHtKHQIWie+PNrhK3xcv9gLtKOvWf/hbK+uWaAHTsaKNszgZkpLbnbQbX2XNrzPDtEJRDWzwn68YTRheZ0vPJg1EEtAVDQjFkBC2zV43XitVIQoh8AyvQ2Qk5L3LW7VozovrkM3uTu9n+aG+EFiuKVQ/ocAW2vFytHVL8nMWZX9jLvXnjCvoNgUCUmWUC8pNmGc8diOSsK52WyxWEGnOy0LuFMCGM76zyY/Z20ehf1BrE5NEIgLv0UlkQOXkmZjQsMIyggkWD7dC9JFsALXTshnFjcHfhLHK3i6q X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:54:06.6144 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1e69fecc-25f3-4590-34a3-08df08e08298 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF00046987.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5805 migrate_pages_batch() operates on folios and calls the folio-based unmap, move and undo helpers. Now that movable_ops-based page migration has been separated out, rename it to migrate_folios_batch(). No functional changes intended. Suggested-by: Zi Yan Signed-off-by: Shivank Garg --- mm/migrate.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 55f352efdf2b..163f13344fd2 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2003,7 +2003,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, * always reports success when its fromlist is empty. * stats->nr_thp_failed should be increased too, * otherwise stats inconsistency will happen when - * migrate_pages_batch is called via migrate_pages() + * migrate_folios_batch is called via migrate_pages() * with MIGRATE_SYNC and MIGRATE_ASYNC. * * Only check it without removing it from the list. @@ -2135,7 +2135,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, } =20 /* - * migrate_pages_batch() first unmaps as many folios in the source list as + * migrate_folios_batch() first unmaps as many folios in the source list as * possible, flushes the TLBs, then moves the unmapped folios. * * Only MIGRATE_ASYNC may batch multiple folios. Waiting for a lock or bit @@ -2143,7 +2143,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, * Therefore, if mode !=3D MIGRATE_ASYNC, the source list must contain at = most * one folio. */ -static int migrate_pages_batch(struct list_head *from, +static int migrate_folios_batch(struct list_head *from, new_folio_t get_new_folio, free_folio_t put_new_folio, unsigned long private, enum migrate_mode mode, enum migrate_reason reaso= n, struct list_head *ret_folios, struct list_head *split_folios, @@ -2194,9 +2194,9 @@ static int migrate_pages_sync(struct list_head *from,= new_folio_t get_new_folio, =20 memset(&astats, 0, sizeof(astats)); /* Try to migrate in batch with MIGRATE_ASYNC mode firstly */ - rc =3D migrate_pages_batch(from, get_new_folio, put_new_folio, private, M= IGRATE_ASYNC, - reason, &folios, split_folios, &astats, - NR_MAX_MIGRATE_ASYNC_RETRY); + rc =3D migrate_folios_batch(from, get_new_folio, put_new_folio, private, + MIGRATE_ASYNC, reason, &folios, split_folios, &astats, + NR_MAX_MIGRATE_ASYNC_RETRY); stats->nr_succeeded +=3D astats.nr_succeeded; stats->nr_thp_succeeded +=3D astats.nr_thp_succeeded; stats->nr_thp_split +=3D astats.nr_thp_split; @@ -2221,9 +2221,9 @@ static int migrate_pages_sync(struct list_head *from,= new_folio_t get_new_folio, list_splice_tail_init(&folios, from); while (!list_empty(from)) { list_move(from->next, &folios); - rc =3D migrate_pages_batch(&folios, get_new_folio, put_new_folio, - private, mode, reason, ret_folios, - split_folios, stats, NR_MAX_MIGRATE_SYNC_RETRY); + rc =3D migrate_folios_batch(&folios, get_new_folio, put_new_folio, + private, mode, reason, ret_folios, split_folios, + stats, NR_MAX_MIGRATE_SYNC_RETRY); list_splice_tail_init(&folios, ret_folios); if (rc < 0) return rc; @@ -2301,7 +2301,7 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, else list_splice_init(from, &folios); if (mode =3D=3D MIGRATE_ASYNC) - rc =3D migrate_pages_batch(&folios, get_new_folio, put_new_folio, + rc =3D migrate_folios_batch(&folios, get_new_folio, put_new_folio, private, mode, reason, &ret_folios, &split_folios, &stats, NR_MAX_MIGRATE_PAGES_RETRY); @@ -2321,7 +2321,7 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, * is counted as 1 failure already. And, we only try to migrate * with minimal effort, force MIGRATE_ASYNC mode and retry once. */ - migrate_pages_batch(&split_folios, get_new_folio, + migrate_folios_batch(&split_folios, get_new_folio, put_new_folio, private, MIGRATE_ASYNC, reason, &ret_folios, NULL, &stats, 1); list_splice_tail_init(&split_folios, &ret_folios); --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011058.outbound.protection.outlook.com [52.101.52.58]) (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 E530948095E; Wed, 2 Sep 2026 10:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346468; cv=fail; b=igrohRed+b8B5gMucrQ/DGC0aAi9S4MO8kCqMfvSmARD1+f1DJKvfl//udbBKf1klq+SnpqZI9oKjdLmXtV7AhFA6ZDU2260y8fzK6rUa36n3AN5QJRHNE01yixhiLBO9J30zUNvP0sM2Sbm78Z0FGhPR8CN8HpIzziCniJkjYY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346468; c=relaxed/simple; bh=u2F2xCkZE0q+qmMOCPw9IxCNywUjEYGF+hTf65vZiD4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=PazNxDS2hzqQNKGw9rkqYL1aO102ffODV+5t+fn1Gb6zx3dV7iRQWkDVBlfhgfcCBl3SGUkGjbnlhXaFsQ9bskASQgtWKlGotu1sD4q0nAkseVH7hlXFIGKvZJmVVsuy8LJ9FMlHFUJmLVX1gcXYUTnKX/1vmtZi7ixKfsOexRM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=2U+Lt/VU; arc=fail smtp.client-ip=52.101.52.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="2U+Lt/VU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=V0WuO4dSMOu2i53smEJzpy9iM8sKFQ/JbW27a8CdRDRMNr/XKUnYNdYptpEnDPkuZspMeOHTzgaDuhT0S1n7QeVnDx5/nk//I51l1WBQQNQvb8uD3yd4pvpMxstKRtSGeFlrXG1UcwMkOBitnkeCZtSrKxYd628wOIkM5HLSmcIKQibwHwmyqdvS2V2LannUqIF08Yl2FcJYMaLTggN/Vqt7pL5XBbrvmL8BJVB2O1wgSjK8jqIYFFd3sLLMy2hm+sd5Ur0TvxhhNsY8JpU8AiLrn5/YFVjZGL+TLA2IHPdFDi63XiZeDZ5oF9a7fyvvTDRzkJEC0/mDm6ehKV99Rg== 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=Tdz5xv3kSUOFgxN7OQPUeQ34gulDFo6FUym0A+A2cuk=; b=ktpfbSFkKjrc4muC0XllgBtX3fGPIzomntQB052F3NWNQ93xS0gQFBtSxkMvWy3j6Lj8Q6UZPpeh+A7dh5XzhDw1gNFyzNh9hww1reWLsjGV2Tcv9FbSwXyCFZwMn3HqdJoRMkCqqAeUxC6hRlLCwnIVu5ShkvDTqina9xjN8qSzqZlJIqy0Stpo741PsoEmxhrmxG5m3H/Wf03gHaDnOSlvVckpZoib9CAYGf6DzcJlUhiTI99+5cxWP2cTgqVqKozQ/Ghca5M1guncOQ4AsSpFeKxrJT41xqK3CBnp3Qyn5fj85e4bN9ZaybQQU2YPH5uPu+FMwI7CcM5vw2LAFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tdz5xv3kSUOFgxN7OQPUeQ34gulDFo6FUym0A+A2cuk=; b=2U+Lt/VUY3odyMW62j/k6Bd76vtcxf8fnmnJOT/YIYnxiQwjytxYyQU0wg8jMspXxks0wXAEl8CcEAsSBExuz0sJw2HCSfFUsTB3mevkN4sf47tLhvYq5aTNHZ3RV52MXiVH1GVdunIAejVoPAGXHBvAkuAR/Ctr/szAjl+Y0IU= Received: from BN0PR08CA0027.namprd08.prod.outlook.com (2603:10b6:408:142::25) by DS7PR12MB5840.namprd12.prod.outlook.com (2603:10b6:8:7b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:54:20 +0000 Received: from BN5PEPF00046987.namprd02.prod.outlook.com (2603:10b6:408:142:cafe::6f) by BN0PR08CA0027.outlook.office365.com (2603:10b6:408:142::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.10 via Frontend Transport; Wed, 2 Sep 2026 10:54:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF00046987.mail.protection.outlook.com (10.167.245.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:54:20 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:54:06 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:21 +0000 Subject: [PATCH RFC 07/11] mm/migrate: add migrate_lru_folios() entry point 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-7-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=5305; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=u2F2xCkZE0q+qmMOCPw9IxCNywUjEYGF+hTf65vZiD4=; b=zqyQvwcNEi60YOe3AxACpfKEgwGmV73sSQzkEJMafgIW3N0CXpY2388d84qsUylEeGLAFlZUM cEsPDSIVPOTAuwHu2AWobA6LL5zUqJp1pgclWiK6rwE6Dw0s3MUzb1W X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF00046987:EE_|DS7PR12MB5840:EE_ X-MS-Office365-Filtering-Correlation-Id: 74e23bd3-ff60-47b7-34d0-08df08e08ae8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|82310400026|1800799024|7416014|376014|921020|56012099006|10067099003|11063799006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: k8b/OHNwOl28Wf4jqbJs24GBLk2c6/IftKlUZE4XPiQQOqkSUyaoLlL9sB9rbaPN4LXxpzO6J6vkAOoTkKMFGBCKfoBudDS+t4vt2Jzaa5FF0rL6JcdKX3t/tYgFz+7drolHVVuB82HTQdB0c5aRxcyqUp9gsC9xayC6ep5z03gLq4z1cIwlwzDxG6rEnL+Ra8MzeqAqTv2NNFlaw6mehBJaF6ajlPqB1sYwBwS6uLKmHSEzPg1ZmVZfn0gTqIdK49oDTHVT3TXk6znOXkpA6JIHsRqIl+EbBZsv2pQyKODY220WLk5tst4DrTUS8bhFOGBuAXQ1N4wZ/hfcaRDj6ZMiPZoBD68pFADYU5H0w6sGFZKF6tNtDLqwqG+Pi7BKsHOMqXhJK4y3YU8kBtuDrv+XNjjTYnB8/BtlDJge+TLPwKE3Tr743d7rSpTsQBMqVYQmjQwKvHNdjMpWwwBaNohBv7YJXgrE9lAx998lJU/JEhpBWuFspwl+VB4wd7C89eVwy5q5u2GJpCb32PQurt9LcFRZ6uPD/YX3vAavMFv+W78mP8aLZiuZG1m0+jiXK2sVSI+lv4dn6Dj8UYC+aahwLD0Tl/EhEzNsIXlwW9XJs7NBEJKkMU1gmKRawh2FKPjABJFbX0C0kNuxkCrFYH/1OCmMeCFy/RBZEa+mW4uRHFVVaIwetzEZaiG3c7uhebls5FNEeJ82Jdtwd7YHSscE5KUdt4yO4LZ3w8+ajtK3Z9oRz+FOZKWCnLcf7MXg X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(36860700016)(82310400026)(1800799024)(7416014)(376014)(921020)(56012099006)(10067099003)(11063799006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0/r4dlIPGtuXD4B2ND+NmRl6NVufQQwZ8kJAFjMu3+hfl0abn5qt16LYADGUBLlb8FvK3O9KWKE0vUvHEsu7RqDrkq/hBT9a2SzspGsWkUCJSKe654c8MZGa/xvlzTHDHaA/sLBKnkw68v50Rl6Evf0Svc3hgxLWbi7pCk/pewqTzgLiWYegCZn4t70PdE7fUqEBOuSIZvsxbmBwAU48ltEGe7IHA22cwi36uFM1Pr7/ooAqWxPj4gBxini9Ueic/SavG5qtgz+72pl1y89WUzNWafrxFOVfwEwGClrACh0QZ01BQy+6nmB/BMdy1gJKVAeUktTJdsbklXQ5S45l/lpxU6wrwiJWtu4drdbc1lkrM7fTp9wixhybqKGWHT4ZpwuWXqfVGbODnlShBpkyGWHRcPTzX5OekonYvc1jAkynihu7+WYLD3MOlDKSJGrX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:54:20.5638 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74e23bd3-ff60-47b7-34d0-08df08e08ae8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF00046987.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5840 migrate_pages() currently handles the asynchronous and synchronous LRU paths separately and retries split folios itself. Move this logic into migrate_lru_folios(), leaving migrate_pages() to dispatch hugetlb, movable_ops, and LRU folios through their respective entry points. Keep the existing retry and accounting behavior unchanged. Signed-off-by: Shivank Garg --- mm/migrate.c | 70 ++++++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 163f13344fd2..d39149cbd43d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2182,20 +2182,34 @@ static int migrate_folios_batch(struct list_head *f= rom, return rc; } =20 -static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_= folio, +/* + * Migrate LRU folios. MIGRATE_ASYNC processes a batch directly. The + * other modes first make a short asynchronous pass, then retry each remai= ning + * folio separately in the requested mode. + */ +static int migrate_lru_folios(struct list_head *from, new_folio_t get_new_= folio, free_folio_t put_new_folio, unsigned long private, enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret_folios, struct list_head *split_folios, + struct list_head *ret_folios, struct migrate_pages_stats *stats) { int rc, nr_failed =3D 0; LIST_HEAD(folios); + LIST_HEAD(split_folios); struct migrate_pages_stats astats; =20 + if (mode =3D=3D MIGRATE_ASYNC) { + rc =3D migrate_folios_batch(from, get_new_folio, put_new_folio, + private, mode, reason, ret_folios, + &split_folios, stats, + NR_MAX_MIGRATE_PAGES_RETRY); + goto out; + } + memset(&astats, 0, sizeof(astats)); /* Try to migrate in batch with MIGRATE_ASYNC mode firstly */ rc =3D migrate_folios_batch(from, get_new_folio, put_new_folio, private, - MIGRATE_ASYNC, reason, &folios, split_folios, &astats, + MIGRATE_ASYNC, reason, &folios, &split_folios, &astats, NR_MAX_MIGRATE_ASYNC_RETRY); stats->nr_succeeded +=3D astats.nr_succeeded; stats->nr_thp_succeeded +=3D astats.nr_thp_succeeded; @@ -2205,7 +2219,7 @@ static int migrate_pages_sync(struct list_head *from,= new_folio_t get_new_folio, stats->nr_failed_pages +=3D astats.nr_failed_pages; stats->nr_thp_failed +=3D astats.nr_thp_failed; list_splice_tail(&folios, ret_folios); - return rc; + goto out; } stats->nr_thp_failed +=3D astats.nr_thp_split; /* @@ -2222,15 +2236,31 @@ static int migrate_pages_sync(struct list_head *fro= m, new_folio_t get_new_folio, while (!list_empty(from)) { list_move(from->next, &folios); rc =3D migrate_folios_batch(&folios, get_new_folio, put_new_folio, - private, mode, reason, ret_folios, split_folios, - stats, NR_MAX_MIGRATE_SYNC_RETRY); + private, mode, reason, ret_folios, + &split_folios, stats, + NR_MAX_MIGRATE_SYNC_RETRY); list_splice_tail_init(&folios, ret_folios); if (rc < 0) - return rc; + goto out; nr_failed +=3D rc; } + rc =3D nr_failed; +out: + if (rc < 0) { + list_splice_tail(&split_folios, ret_folios); + } else if (!list_empty(&split_folios)) { + /* + * Folios split along the way get one asynchronous attempt at + * their new order. Their failure is not counted: the large + * folio they came from was already counted as one failure. + */ + migrate_folios_batch(&split_folios, get_new_folio, put_new_folio, + private, MIGRATE_ASYNC, reason, ret_folios, + NULL, stats, 1); + list_splice_tail_init(&split_folios, ret_folios); + } =20 - return nr_failed; + return rc; } =20 /* @@ -2268,7 +2298,6 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, struct folio *folio, *folio2; LIST_HEAD(folios); LIST_HEAD(ret_folios); - LIST_HEAD(split_folios); struct migrate_pages_stats stats; =20 trace_mm_migrate_pages_start(mode, reason); @@ -2300,32 +2329,13 @@ int migrate_pages(struct list_head *from, new_folio= _t get_new_folio, list_cut_before(&folios, from, &folio2->lru); else list_splice_init(from, &folios); - if (mode =3D=3D MIGRATE_ASYNC) - rc =3D migrate_folios_batch(&folios, get_new_folio, put_new_folio, - private, mode, reason, &ret_folios, - &split_folios, &stats, - NR_MAX_MIGRATE_PAGES_RETRY); - else - rc =3D migrate_pages_sync(&folios, get_new_folio, put_new_folio, - private, mode, reason, &ret_folios, - &split_folios, &stats); + rc =3D migrate_lru_folios(&folios, get_new_folio, put_new_folio, + private, mode, reason, &ret_folios, &stats); list_splice_tail_init(&folios, &ret_folios); if (rc < 0) { rc_gather =3D rc; - list_splice_tail(&split_folios, &ret_folios); goto out; } - if (!list_empty(&split_folios)) { - /* - * Failure isn't counted since all split folios of a large folio - * is counted as 1 failure already. And, we only try to migrate - * with minimal effort, force MIGRATE_ASYNC mode and retry once. - */ - migrate_folios_batch(&split_folios, get_new_folio, - put_new_folio, private, MIGRATE_ASYNC, reason, - &ret_folios, NULL, &stats, 1); - list_splice_tail_init(&split_folios, &ret_folios); - } rc_gather +=3D rc; if (!list_empty(from)) goto again; --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010054.outbound.protection.outlook.com [52.101.46.54]) (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 8373846D54B; Wed, 2 Sep 2026 10:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346482; cv=fail; b=VOpX+3n4OCpK2TeEbQM1fyGqUom2OGReYsqV6WiDDeeMw4IDNYbqjbuCIEsFWw87XikwlmRKZfVCcQ+sd2Er98b4Z7SFDxGzGav2iaMxHXn3kjOSx7r3v1CqGWj9UVAE2CjIQwY1RHjmyp+ZBQc2osy5wx8U0jQrla8Y3PaP2k4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346482; c=relaxed/simple; bh=DCCSRJxS6zqpx884DZJiD1RXEp4RSjaLXabCPBXH4QE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=ZmZMTBZyKGg3nktD+2SX3g0b0D9BcPDfZFe3dtcWIH04UhhxhG0ihNDrGXsXWOojDCW2LGUC1YDuOC4mm+xIhVAvL7eNVBFaZOUiZ2hvvpIyGv4EsVY2dohsLuvy3id0P6JyiUTUo6zWEBFea28RTQ2OVERH8LPF1SD8VdrX83M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=NTgjTX3D; arc=fail smtp.client-ip=52.101.46.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="NTgjTX3D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rswb8q8M64YBiU0SUKi2xX3e/4/VCnN4Z0Z/SIaQk7GFH39L4LiLBjZCog7Ae6a8Pb2OmYnRYJdN95Qmqacl5Dw3ugcT2oiiHy8BAvhfIiBMrgCt0DMoqZfkw+hFwK6ED3skYji+X0bWFKslpM1D1FWA5u7H5jZYP3dlO4VphbESEfFg7cVaNXZsVSDStkQYnnnkKHaB1JdVi/0gotLDKFrDYHpORgOA16hgg3DpQmR/3yg8KuwC5yNHVInBom5DBXs7LPx96k9cYqrC7B2ckyxgoUUiCoj0/PvwCWNnenH59zx0TQWzURis1VDppQxsKqhSQ+T71BR5h4WjwaFT8g== 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=koojTOYdkiiZND7qr2ZlBjOYh7v1IXhkGuZoYr86pp4=; b=M1ZM5qbossP+fyLniezhWDswAJmnENeLbf8GLwPUaIvjvoEMG9wc+GmMI0/Bh4pydmR41WWWs0Yi6FrvjilBaGLl1q0WjzfdkyD0/bfjuhfwGXWjJpfrUCr1sMgKMSQI+JJF2BMqbjKhdanFPb+77aJDkaJjhM6py7Y5EHxInZGAFpM+DDYaN0Ml9EpkW3lWgFUuAV3TA0fBdCdR0soLiS6YZTyeazHSUVrR3CoakIt7jMZV/ZYzHtBh7AzATtdZX/wuR3MDAY75F5M8jW/kNGWJvMJHAVJkqKANj5nfC/RB48smrDXbVXrMHg4ED018WAABspy+vNA4a9ufw/PK+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=koojTOYdkiiZND7qr2ZlBjOYh7v1IXhkGuZoYr86pp4=; b=NTgjTX3DYTbOYYAwbQGXuUhOUO4Lbrxcqq2wzR3ofTMU2xQOwPoOs9GJmHeJD0Ic3MQLuKzxhgwP54LhvD7BV6mFjUZwo1JIeqSLIDOabPsiVB7DHVyqcVtHSyLQaMHRif931dBG/Ry16eP8aGe2H5V8DSpSnT8zS1rk9xBFUfs= Received: from BN0PR08CA0021.namprd08.prod.outlook.com (2603:10b6:408:142::16) by MW4PR12MB6681.namprd12.prod.outlook.com (2603:10b6:303:1e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.11; Wed, 2 Sep 2026 10:54:35 +0000 Received: from BN5PEPF00046987.namprd02.prod.outlook.com (2603:10b6:408:142:cafe::53) by BN0PR08CA0021.outlook.office365.com (2603:10b6:408:142::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.10 via Frontend Transport; Wed, 2 Sep 2026 10:54:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF00046987.mail.protection.outlook.com (10.167.245.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:54:34 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:54:20 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:22 +0000 Subject: [PATCH RFC 08/11] mm/migrate: move LRU batching into migrate_lru_folios() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-8-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=4077; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=DCCSRJxS6zqpx884DZJiD1RXEp4RSjaLXabCPBXH4QE=; b=iWZUKvsWOy8mQUDpMHuudCi9GxqEOGUHUA7WVUzj1iVzL/XrVKKYT2GjjYldTEEpf53g6YbXz f5aUiwYXYeKC7ybklBQTt7fsRz2v3IluZ+WW2obwJGeaMLJfE22F2c5 X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF00046987:EE_|MW4PR12MB6681:EE_ X-MS-Office365-Filtering-Correlation-Id: cceebce7-d38e-4bdf-cc11-08df08e09334 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|23010399003|36860700016|921020|10067099003|11063799006|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: arDuwY6bPoGJqo0qIUkcHZzlKvq9oyUL4748ZLkhmWhD4Rjel91CSjKLILfuaGz+/+VDmbI/z4FglllyBklOprQ5vLoX3GUhEfD4BQroV3pXeITlaIcrZhhP9dvweU0xWe7ooiNa15xBhRfrslJJPyCtAZkspFlrE97W8hDry54wsXrZhlv222J0E0AEAq45vROKlnFR5/0vHFJyegNI6vIn7NTMUEldizX7x17RuEv6TlDU1cjYfzpQrQUVgvIYH6kaLFlpvm05UberJlby1d5uYX/nqSQ2SzltK7pDavZ/U5a7JGQXyF8Wkj0KNHSxXiQ2P5bPxPABM+tWY57WksZFGN7cvL3zGTxSKZoQNtuspknNeWVRybg7knFdC9oxyE4H0MOKmLMwAEEU8B/lD0+pgw4+Bx+qVGEn2abrsXXta4b9PAMzWMwfIn7dg2MV0pKh7g617uGDZ4AW9NrQdfwwmlH7Eo5xndhYs/8J2xXu8baRk814xuYesvBXLHnrcwYKDpogB13X5lU7mK3SJ+GQJJh+NDmuWhFa2JdrRLjcd95FXSiH9XHKrwooMpMux7Pm/m+Qeh4psyCkxSon62S5V90ruEGVXKpLmvziXDRI0ylZ9jfXg9oQLFvMzVbyB9UkwO/JbK5nS4BlZDb7JHEP+9yqCcVKLypKn8HL4Of35rkOjgJGJlM+7KFbM7MOvQSRjtZyGFhNSPf1AQBXjgrNa2+HGPl6atnT5Uw0+Vmtfx/ZAbO8GPhcUxEHdASC X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(7416014)(23010399003)(36860700016)(921020)(10067099003)(11063799006)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HzTTJNBcFqq99LcVkpcumXu9lTQyo2VmchhFr2LSebVuDWLvEi0Tahx9dGrK9xeJdGQSkyGLoZ6XgqdiRq4wonTXBdbYyQtCfBGvc1cAs2mW4Lhn3Xa4L626GI4kud73jmONKb6qRgKTlWI7y7fm3InmFJRUSV99nKlS7u2yRO+A28HVUHw2mXv9csUpsRAi7eRcms+g5SBk+QTV1ULRlHTxKPYL+GS6kWft6RPizaQL3j9NM8JfvxY+EmvQLOkVfYOISb4862iXtgHnUHaCQFqwSU9oG3ncwLbjW0iCWJsY2N+N9rzvVV8zUveuqLE2q6YeGYVjo8xyZXxnX1xH5Z/0jGCe/y3YcpvK0tQ11OOQfXh0SSJRmq3yzL/8d39XvyUmNXpcJBIzwN4pnDCUu0uvax5py/dMhQibMo6n1XQS6RDuQI3GXfger0FwcJdC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:54:34.4883 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cceebce7-d38e-4bdf-cc11-08df08e09334 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF00046987.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6681 The NR_MAX_BATCHED_MIGRATION limit is specific to LRU folio migration, where the batch engine can keep multiple folios locked at once. Move the batching loop into migrate_lru_folios() and rename the per-batch worker to __migrate_lru_folios(). This leaves migrate_pages() responsible only for dispatching the different migration classes. No functional change intended. Signed-off-by: Shivank Garg --- mm/migrate.c | 62 ++++++++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index d39149cbd43d..8914358cc434 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2183,11 +2183,11 @@ static int migrate_folios_batch(struct list_head *f= rom, } =20 /* - * Migrate LRU folios. MIGRATE_ASYNC processes a batch directly. The + * Migrate one batch of LRU folios. MIGRATE_ASYNC processes it directly. = The * other modes first make a short asynchronous pass, then retry each remai= ning * folio separately in the requested mode. */ -static int migrate_lru_folios(struct list_head *from, new_folio_t get_new_= folio, +static int __migrate_lru_folios(struct list_head *from, new_folio_t get_ne= w_folio, free_folio_t put_new_folio, unsigned long private, enum migrate_mode mode, enum migrate_reason reason, struct list_head *ret_folios, @@ -2263,6 +2263,45 @@ static int migrate_lru_folios(struct list_head *from= , new_folio_t get_new_folio, return rc; } =20 +/* + * Migrate LRU folios. The batch engine keeps every folio of a batch lock= ed + * at once, so feed it at most NR_MAX_BATCHED_MIGRATION pages at a time + * rather than however many the caller supplied. + */ +static int migrate_lru_folios(struct list_head *from, new_folio_t get_new_= folio, + free_folio_t put_new_folio, unsigned long private, + enum migrate_mode mode, enum migrate_reason reason, + struct list_head *ret_folios, + struct migrate_pages_stats *stats) +{ + struct folio *folio, *folio2; + int rc, nr_failed =3D 0; + int nr_pages; + LIST_HEAD(folios); + + while (!list_empty(from)) { + nr_pages =3D 0; + list_for_each_entry_safe(folio, folio2, from, lru) { + nr_pages +=3D folio_nr_pages(folio); + if (nr_pages >=3D NR_MAX_BATCHED_MIGRATION) + break; + } + if (nr_pages >=3D NR_MAX_BATCHED_MIGRATION) + list_cut_before(&folios, from, &folio2->lru); + else + list_splice_init(from, &folios); + + rc =3D __migrate_lru_folios(&folios, get_new_folio, put_new_folio, + private, mode, reason, ret_folios, stats); + list_splice_tail_init(&folios, ret_folios); + if (rc < 0) + return rc; + nr_failed +=3D rc; + } + + return nr_failed; +} + /* * migrate_pages - migrate the folios specified in a list, to the free fol= ios * supplied as the target for the page migration @@ -2294,9 +2333,6 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, enum migrate_mode mode, enum migrate_reason reason, unsigned int *ret_su= cceeded) { int rc, rc_gather; - int nr_pages; - struct folio *folio, *folio2; - LIST_HEAD(folios); LIST_HEAD(ret_folios); struct migrate_pages_stats stats; =20 @@ -2318,27 +2354,13 @@ int migrate_pages(struct list_head *from, new_folio= _t get_new_folio, } rc_gather +=3D rc; =20 -again: - nr_pages =3D 0; - list_for_each_entry_safe(folio, folio2, from, lru) { - nr_pages +=3D folio_nr_pages(folio); - if (nr_pages >=3D NR_MAX_BATCHED_MIGRATION) - break; - } - if (nr_pages >=3D NR_MAX_BATCHED_MIGRATION) - list_cut_before(&folios, from, &folio2->lru); - else - list_splice_init(from, &folios); - rc =3D migrate_lru_folios(&folios, get_new_folio, put_new_folio, + rc =3D migrate_lru_folios(from, get_new_folio, put_new_folio, private, mode, reason, &ret_folios, &stats); - list_splice_tail_init(&folios, &ret_folios); if (rc < 0) { rc_gather =3D rc; goto out; } rc_gather +=3D rc; - if (!list_empty(from)) - goto again; out: /* * Put the permanent failure folio back to migration list, they --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010016.outbound.protection.outlook.com [40.93.198.16]) (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 7845F4746AB; Wed, 2 Sep 2026 10:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346503; cv=fail; b=S4xUnoVP6hhasoaAZTMrjfsb3S8dmeh6zKWAjU/UxcQ40g8bwj7xJz8yxW47VYF7n8o0LnZ6SfNzfMVjJ1Os/5CIPxRegyY7m9/RQrLa2lWf5TEKnEb7U/pIUqPg3CRaOZ0XhD8flMiKZa/t9HT7vW4H6x0jYPVSXTCKeEK2ijY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346503; c=relaxed/simple; bh=6EMcmpBQI1vPSYfcMlDJn/BtPcuSul8OlWNINOe6fN8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=l0i064aJHCTi0oyN17wa1+1gS/TPNNJTR1mYpXs5A36+2n8eN2y8N5kldxXihSFsQ0nCFo2gQXS4KLEe7MeBHhk0M/zdDYL3kWDtuJ74yVwnrJV7w0opQuGVR07ihXMBYJJNHEtDmSA5TOUKIJ/9OoIkabZ1s6lnrTexjP98J7Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=oNun03Vy; arc=fail smtp.client-ip=40.93.198.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="oNun03Vy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yXZ1f4OkCC8Y2RLnk2Z19aAUVT5g4G4bW8WsTuAhkq0c/gcDk3AzD945wwFNMXtHukosctIeeDLuHXbbuKbM3lugK6sf9BZQ/j98kU3qBJS+GbfHCGlNbICgrE5mRFO37vez4neMJ1qMf31IlurWAr/JhVIrFHCPKUxOnyQ1OYoi/NxRXhVEEcCGoGxjWHsRhL4D3LhNyNCtfuqBQilZ10iQpfkZ9G+JCaA8nC7ecRlWtf5wkPCJpxEJpVEYJMGtYu0Rttn96GxtUpcT0j2I04dftBiywjA1cMzoDW415Vq3iDEDTFHiLBkuFklq6dmtDJjeDbaJgkq3JehUwEOFtQ== 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=KosfdVldCAz+hZA49sh2dczO17gkZdiCZzF6bF0k6fk=; b=R3urjMGSUG6VSNmBxnEHLLvRkpV+a8VHlO5fSYCfiFjKZ2Ua/f0QtI+TusTHfriVpL0i5wyetysmFygPl2hes10PT18KE8OXUu9Sn4gyzHkdH+p3YsQVWZPkPHWuxkTbxNeT37os8YVbgaVha3iIJW8/LWEYsnq5DS+Mh6AdA3ZchEwEZxIJdqfxcryOJDsEuZNm1jByv5dfQfRnNv8lmCLDZ0PQf8jNpMCgRUUSFhI93TNDybCxWpN7mLa4gKofj/6GtpVtFPJNdNxbedfl4hSzSMaaLmUWweGOOwMcECdeUxNja6U2ZdXLjHYgZqH53EeaIiuOKJPZBD8BIJZvng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KosfdVldCAz+hZA49sh2dczO17gkZdiCZzF6bF0k6fk=; b=oNun03VyDhzf4qEzPkaibKIGTmd8w7Dqg7UepyU+oPRAAkpW+uJplKh4mC4h3cNr7RkT18E565LveUXXskN9o/TlraTRe9D1dERazikcTlRSnYbZos6k5NBVNXxznbyV1/Lc2noNnSbOB066Hl1Mmt4m6SocWnis/q+oJmJKjqU= Received: from BN0PR04CA0149.namprd04.prod.outlook.com (2603:10b6:408:ed::34) by DS7PR12MB8290.namprd12.prod.outlook.com (2603:10b6:8:d8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:54:54 +0000 Received: from BN5PEPF0004698B.namprd02.prod.outlook.com (2603:10b6:408:ed:cafe::a7) by BN0PR04CA0149.outlook.office365.com (2603:10b6:408:ed::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.10 via Frontend Transport; Wed, 2 Sep 2026 10:54:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF0004698B.mail.protection.outlook.com (10.167.245.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:54:51 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:54:34 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:23 +0000 Subject: [PATCH RFC 09/11] mm/migrate: thread migration policy through a control struct 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-9-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=21523; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=6EMcmpBQI1vPSYfcMlDJn/BtPcuSul8OlWNINOe6fN8=; b=OS3tT5J3qLHhG6i6qqPZamCFGRqB92OjoDv19KfNij+wdhrXOVUMFCv2B8FdwsAYzlIoZdmce /ziy+FH18AXD2hbrKkJU8vaHPWUDMQnfQMTFxomu30zZ+2VLRT6dDOm X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF0004698B:EE_|DS7PR12MB8290:EE_ X-MS-Office365-Filtering-Correlation-Id: 808b2fb9-c295-4075-d486-08df08e09d87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|82310400026|7416014|1800799024|23010399003|921020|10067099003|11063799006|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 4QS7S28TIID30AQxFymuvb4Ak9eSLf6egl7agpX3dVZodsB4UOUQCnYK3DyBhwJUdyZ6FLPVvjERmebGO4FqIu+nnYvMIv7Z4v5rFYfSTRz1biM6p72a2Z2eqAIHvjvws1vw3HVaLJQeC9FdsVo/FAosbaqfjcleAcJiOQkcl8UiRKOuEy01OSJK2fYw9frAX68Ll7B4k70X3DOHv1lcX5GPLuAlcRQaaULRZqhWvyW0uv+5XfUn7zW/l/jkS76cdMBz3Kbut4uz+KwLaJT7xm0qxcO2uLNgP5DkKE5S/l948F1mRroIWdaaR6h3YiCG3GuMzr6CQbrYRuywb0Csc27O3UAX92zHSS/YfVadStgjwF008As6gNv7hci5KtkccggTOT6zRDLL6Aq0cWPNgVGGfa7/PKaYSvn8OG8/XTgBdf3n8fYs0KJ1mSUbrRf4VYXHBZqFkdoost7PRbkVyPpLZtFUgSiZeFZwDmeMb+ugkRBbTlDNCtSnh6P+DeVblRkM6oEg7+RLWMw1F7GaGrcv7UcWMCMkwm+fUkB4kVPyNLmzPp8k8kbWRFsU5h0bIAw3ZIEhotuFmHia3fwBDJ5ZXZy7jvn94yMfKsLZ14I52PLVOE8RxxBMWvDTb/sKbFSnJUo6m6c/1+gWTV7rI3iJDzZkSPZFS/UeiGvL8+bOuW/yEHYT49mb984kda6MagUasNl044/jq7CsAFANBfdy9wpijNSTg7zgJ/OCPq4NDGI7+J6wx3zddEol+Cij X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(376014)(82310400026)(7416014)(1800799024)(23010399003)(921020)(10067099003)(11063799006)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rQ8FFx1BowldtA4pmQ505jAvXIIw+3m14etpmTbQKqZN4wfE6YazFCF8RhncfbmlCA2iXoFtdBQ02K7VAbtvyE53rr8RMtBLzEMYFjs9kKCDIR7uheAELARRNxb84/SbVlwi3lANXnLeSYUSoNpBpIkScFts45K8m6fAuKimzrpAvnUbKylwV58R0acXnqY6WHW0lZIkkgzM3M0MJc1sUI8ND3yXYEMqTOHEbl2nsWUm7NCa0YtKRsM6Tj0NI/0Wd5+smXvUln5EKvQUfxPj8kMS30xColFE7Lyh35xXftqEmdhZ5hVd8xqVEGnXjvfLlxuWc/R5jsiwgo8Vq5/W/eklv8JdTwyQCqToeg6lVpj1vdyxXoXvOZLYCjXyQrAdJOfR4D9NMhofUn+1JXJgQUh7Utio+SCb8+tGK0iRFP2wwo1+MOZNfGL09UuiC+Qy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:54:51.7937 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 808b2fb9-c295-4075-d486-08df08e09d87 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF0004698B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8290 Migration mode and reason describe one migration invocation, but are passed separately through every migration engine and phase. Adding more policy would require another parameter through the same call graph or overloading migrate_mode with unrelated information. Add struct migrate_control, initialize it on the migrate_pages() stack, and pass it as const through the internal migration helpers. This provides one place for additional policy, such as copy-cache hints. Use a derived control for asynchronous pre-passes and split-folio retries. Keep the public migration and filesystem callback interfaces unchanged in this patch and will be handled separately in upcoming patch. No functional change intended. Signed-off-by: Shivank Garg --- include/linux/migrate_mode.h | 14 +++++ mm/migrate.c | 144 ++++++++++++++++++++++-----------------= ---- 2 files changed, 88 insertions(+), 70 deletions(-) diff --git a/include/linux/migrate_mode.h b/include/linux/migrate_mode.h index 05102d4d2490..388acddfdae8 100644 --- a/include/linux/migrate_mode.h +++ b/include/linux/migrate_mode.h @@ -29,4 +29,18 @@ enum migrate_reason { MR_TYPES }; =20 +/** + * struct migrate_control - Policy for one migration invocation + * @mode: Blocking discipline for migration operations + * @reason: Reason the migration was requested + * + * Per-folio completion state does not belong here. Callers keep this + * structure on the stack; migration must not allocate it under memory + * pressure. + */ +struct migrate_control { + enum migrate_mode mode; + enum migrate_reason reason; +}; + #endif /* MIGRATE_MODE_H_INCLUDED */ diff --git a/mm/migrate.c b/mm/migrate.c index 8914358cc434..e4bc7122076e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1103,7 +1103,7 @@ static int fallback_migrate_folio(struct address_spac= e *mapping, * 0 - success */ static int move_to_new_folio(struct folio *dst, struct folio *src, - enum migrate_mode mode) + const struct migrate_control *ctl) { struct address_space *mapping =3D folio_mapping(src); int rc =3D -EAGAIN; @@ -1112,7 +1112,7 @@ static int move_to_new_folio(struct folio *dst, struc= t folio *src, VM_BUG_ON_FOLIO(!folio_test_locked(dst), dst); =20 if (!mapping) - rc =3D migrate_folio(mapping, dst, src, mode); + rc =3D migrate_folio(mapping, dst, src, ctl->mode); else if (mapping_inaccessible(mapping)) rc =3D -EOPNOTSUPP; else if (mapping->a_ops->migrate_folio) @@ -1123,10 +1123,9 @@ static int move_to_new_folio(struct folio *dst, stru= ct folio *src, * migrate_folio callback. This is the most common path * for page migration. */ - rc =3D mapping->a_ops->migrate_folio(mapping, dst, src, - mode); + rc =3D mapping->a_ops->migrate_folio(mapping, dst, src, ctl->mode); else - rc =3D fallback_migrate_folio(mapping, dst, src, mode); + rc =3D fallback_migrate_folio(mapping, dst, src, ctl->mode); =20 if (!rc) { /* @@ -1198,13 +1197,13 @@ static void migrate_folio_undo_dst(struct folio *ds= t, bool locked, =20 /* Cleanup src folio upon migration success */ static void migrate_folio_done(struct folio *src, - enum migrate_reason reason) + const struct migrate_control *ctl) { - if (reason !=3D MR_DEMOTION) + if (ctl->reason !=3D MR_DEMOTION) mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + folio_is_file_lru(src), -folio_nr_pages(src)); =20 - if (reason !=3D MR_MEMORY_FAILURE) + if (ctl->reason !=3D MR_MEMORY_FAILURE) /* We release the page in page_handle_poison. */ folio_put(src); } @@ -1212,8 +1211,8 @@ static void migrate_folio_done(struct folio *src, /* Obtain the lock on page, remove all ptes. */ static int migrate_folio_unmap(new_folio_t get_new_folio, free_folio_t put_new_folio, unsigned long private, - struct folio *src, struct folio **dstp, enum migrate_mode mode, - struct list_head *ret) + struct folio *src, struct folio **dstp, + const struct migrate_control *ctl, struct list_head *ret) { struct folio *dst; int rc =3D -EAGAIN; @@ -1230,7 +1229,7 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, dst->migrate_info =3D 0; =20 if (!folio_trylock(src)) { - if (mode =3D=3D MIGRATE_ASYNC) + if (ctl->mode =3D=3D MIGRATE_ASYNC) goto out; =20 /* @@ -1254,7 +1253,7 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, * inserting a page into the page table), but it's not * worth waiting for I/O. */ - if (mode =3D=3D MIGRATE_SYNC_LIGHT && !folio_test_uptodate(src)) + if (ctl->mode =3D=3D MIGRATE_SYNC_LIGHT && !folio_test_uptodate(src)) goto out; =20 folio_lock(src); @@ -1270,7 +1269,7 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, * the retry loop is too short and in the sync-light case, * the overhead of stalling is too much */ - switch (mode) { + switch (ctl->mode) { case MIGRATE_SYNC: break; default: @@ -1330,7 +1329,8 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, /* Establish migration ptes */ VM_BUG_ON_FOLIO(folio_test_anon(src) && !folio_test_ksm(src) && !anon_vma, src); - try_to_migrate(src, mode =3D=3D MIGRATE_ASYNC ? TTU_BATCH_FLUSH : 0); + try_to_migrate(src, ctl->mode =3D=3D MIGRATE_ASYNC ? + TTU_BATCH_FLUSH : 0); old_folio_state |=3D FOLIO_WAS_MAPPED; } =20 @@ -1356,9 +1356,8 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, =20 /* Migrate the folio to the newly allocated folio in dst. */ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long pr= ivate, - struct folio *src, struct folio *dst, - enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret) + struct folio *src, struct folio *dst, + const struct migrate_control *ctl, struct list_head *ret) { int rc; int old_folio_state =3D 0; @@ -1377,7 +1376,7 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, src_partially_mapped =3D folio_test_partially_mapped(src); } =20 - rc =3D move_to_new_folio(dst, src, mode); + rc =3D move_to_new_folio(dst, src, ctl); if (rc) goto out; =20 @@ -1407,7 +1406,7 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, remove_migration_ptes(src, dst, 0); =20 folio_unlock(dst); - folio_set_owner_migrate_reason(dst, reason); + folio_set_owner_migrate_reason(dst, ctl->reason); /* * If migration is successful, decrease refcount of dst, * which will not free the page because new page owner increased @@ -1424,7 +1423,7 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, if (anon_vma) put_anon_vma(anon_vma); folio_unlock(src); - migrate_folio_done(src, reason); + migrate_folio_done(src, ctl); =20 return rc; out: @@ -1466,8 +1465,8 @@ static int migrate_folio_move(free_folio_t put_new_fo= lio, unsigned long private, */ static int unmap_and_move_hugetlb_folio(new_folio_t get_new_folio, free_folio_t put_new_folio, unsigned long private, - struct folio *src, int force, enum migrate_mode mode, - enum migrate_reason reason, struct list_head *ret) + struct folio *src, int force, const struct migrate_control *ctl, + struct list_head *ret) { struct folio *dst; int rc =3D -EAGAIN; @@ -1489,7 +1488,7 @@ static int unmap_and_move_hugetlb_folio(new_folio_t g= et_new_folio, if (!folio_trylock(src)) { if (!force) goto out; - switch (mode) { + switch (ctl->mode) { case MIGRATE_SYNC: break; default: @@ -1534,7 +1533,7 @@ static int unmap_and_move_hugetlb_folio(new_folio_t g= et_new_folio, } =20 if (!folio_mapped(src)) - rc =3D move_to_new_folio(dst, src, mode); + rc =3D move_to_new_folio(dst, src, ctl); =20 if (was_mapped) remove_migration_ptes(src, !rc ? dst : src, ttu); @@ -1550,7 +1549,7 @@ static int unmap_and_move_hugetlb_folio(new_folio_t g= et_new_folio, put_anon_vma(anon_vma); =20 if (!rc) { - move_hugetlb_state(src, dst, reason); + move_hugetlb_state(src, dst, ctl->reason); put_new_folio =3D NULL; } =20 @@ -1625,7 +1624,7 @@ struct migrate_pages_stats { */ static int migrate_hugetlbs(struct list_head *from, new_folio_t get_new_fo= lio, free_folio_t put_new_folio, unsigned long private, - enum migrate_mode mode, enum migrate_reason reason, + const struct migrate_control *ctl, struct migrate_pages_stats *stats, struct list_head *ret_folios) { @@ -1666,8 +1665,8 @@ static int migrate_hugetlbs(struct list_head *from, n= ew_folio_t get_new_folio, =20 rc =3D unmap_and_move_hugetlb_folio(get_new_folio, put_new_folio, private, - folio, pass > 2, mode, - reason, ret_folios); + folio, pass > 2, ctl, + ret_folios); /* * The rules are: * 0: hugetlb folio will be put back @@ -1721,7 +1720,7 @@ static int migrate_hugetlbs(struct list_head *from, n= ew_folio_t get_new_folio, static void migrate_folios_move(struct list_head *src_folios, struct list_head *dst_folios, free_folio_t put_new_folio, unsigned long private, - enum migrate_mode mode, enum migrate_reason reason, + const struct migrate_control *ctl, struct list_head *ret_folios, struct migrate_pages_stats *stats, int nr_pass, int *nr_failed) @@ -1748,7 +1747,7 @@ static void migrate_folios_move(struct list_head *src= _folios, cond_resched(); =20 rc =3D migrate_folio_move(put_new_folio, private, - folio, dst, mode, reason, ret_folios); + folio, dst, ctl, ret_folios); /* * The rules are: * 0: folio will be freed @@ -1811,8 +1810,8 @@ static void migrate_folios_undo(struct list_head *src= _folios, */ static int move_movable_ops_page(struct folio *src, new_folio_t get_new_folio, free_folio_t put_new_folio, - unsigned long private, enum migrate_mode mode, - enum migrate_reason reason, struct list_head *ret_folios) + unsigned long private, const struct migrate_control *ctl, + struct list_head *ret_folios) { struct folio *dst; int rc =3D -EAGAIN; @@ -1822,7 +1821,7 @@ static int move_movable_ops_page(struct folio *src, return -ENOMEM; =20 if (!folio_trylock(src)) { - if (mode =3D=3D MIGRATE_ASYNC) + if (ctl->mode =3D=3D MIGRATE_ASYNC) goto out_put_dst; if (current->flags & PF_MEMALLOC) goto out_put_dst; @@ -1832,19 +1831,19 @@ static int move_movable_ops_page(struct folio *src, if (unlikely(!folio_trylock(dst))) goto out_unlock_src; =20 - rc =3D migrate_movable_ops_page(&dst->page, &src->page, mode); + rc =3D migrate_movable_ops_page(&dst->page, &src->page, ctl->mode); folio_unlock(dst); if (rc) goto out_unlock_src; =20 - folio_set_owner_migrate_reason(dst, reason); + folio_set_owner_migrate_reason(dst, ctl->reason); /* Drop migration's reference after transferring ownership to dst. */ folio_put(dst); =20 list_del(&src->lru); folio_unlock(src); =20 - if (reason !=3D MR_MEMORY_FAILURE) + if (ctl->reason !=3D MR_MEMORY_FAILURE) folio_put(src); =20 return 0; @@ -1872,8 +1871,8 @@ static int move_movable_ops_page(struct folio *src, */ static int migrate_movable_ops_pages(struct list_head *from, new_folio_t get_new_folio, free_folio_t put_new_folio, - unsigned long private, enum migrate_mode mode, - enum migrate_reason reason, struct migrate_pages_stats *stats, + unsigned long private, const struct migrate_control *ctl, + struct migrate_pages_stats *stats, struct list_head *ret_folios) { int retry =3D 1; @@ -1895,7 +1894,7 @@ static int migrate_movable_ops_pages(struct list_head= *from, =20 rc =3D move_movable_ops_page(folio, get_new_folio, put_new_folio, private, - mode, reason, ret_folios); + ctl, ret_folios); switch (rc) { case -ENOMEM: /* Count this page and those awaiting retry. */ @@ -1933,17 +1932,17 @@ static int migrate_movable_ops_pages(struct list_he= ad *from, * unmap phase. */ static int migrate_folio_split_on_alloc_fail(struct folio *folio, - struct list_head *split_folios, enum migrate_mode mode, - enum migrate_reason reason, struct migrate_pages_stats *stats) + struct list_head *split_folios, const struct migrate_control *ctl, + struct migrate_pages_stats *stats) { bool is_thp =3D folio_test_pmd_mappable(folio); int rc; =20 /* Large folio NUMA faulting doesn't split to retry. */ - if (!folio_test_large(folio) || reason =3D=3D MR_NUMA_MISPLACED) + if (!folio_test_large(folio) || ctl->reason =3D=3D MR_NUMA_MISPLACED) return -ENOMEM; =20 - rc =3D try_split_folio(folio, split_folios, mode); + rc =3D try_split_folio(folio, split_folios, ctl->mode); if (!rc) { stats->nr_thp_split +=3D is_thp; stats->nr_split++; @@ -1954,7 +1953,7 @@ static int migrate_folio_split_on_alloc_fail(struct f= olio *folio, * Try again to split large folio to mitigate the failure of longterm * pinning. */ - if (reason =3D=3D MR_LONGTERM_PIN && rc =3D=3D -EAGAIN) + if (ctl->reason =3D=3D MR_LONGTERM_PIN && rc =3D=3D -EAGAIN) return -EAGAIN; =20 return -ENOMEM; @@ -1970,7 +1969,7 @@ static int migrate_folio_split_on_alloc_fail(struct f= olio *folio, */ static int migrate_folios_unmap(struct list_head *from, new_folio_t get_new_folio, free_folio_t put_new_folio, - unsigned long private, enum migrate_mode mode, enum migrate_reason reaso= n, + unsigned long private, const struct migrate_control *ctl, struct list_head *ret_folios, struct list_head *split_folios, struct list_head *unmap_folios, struct list_head *dst_folios, struct migrate_pages_stats *stats, int nr_pass, int *nr_failed) @@ -2020,7 +2019,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, if (nr_pages > 2 && !list_empty(&folio->_deferred_list) && folio_test_partially_mapped(folio)) { - if (!try_split_folio(folio, split_folios, mode)) { + if (!try_split_folio(folio, split_folios, ctl->mode)) { *nr_failed +=3D 1; stats->nr_thp_failed +=3D is_thp; stats->nr_thp_split +=3D is_thp; @@ -2042,7 +2041,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, if (!thp_migration_supported() && is_thp) { *nr_failed +=3D 1; stats->nr_thp_failed++; - if (!try_split_folio(folio, split_folios, mode)) { + if (!try_split_folio(folio, split_folios, ctl->mode)) { stats->nr_thp_split++; stats->nr_split++; continue; @@ -2060,14 +2059,14 @@ static int migrate_folios_unmap(struct list_head *f= rom, folio_clear_active(folio); folio_clear_unevictable(folio); list_del(&folio->lru); - migrate_folio_done(folio, reason); + migrate_folio_done(folio, ctl); stats->nr_succeeded +=3D nr_pages; stats->nr_thp_succeeded +=3D is_thp; continue; } =20 rc =3D migrate_folio_unmap(get_new_folio, put_new_folio, - private, folio, &dst, mode, ret_folios); + private, folio, &dst, ctl, ret_folios); /* * The rules are: * 0: folio will be put on unmap_folios list, @@ -2086,7 +2085,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, stats->nr_thp_failed +=3D is_thp; =20 split_rc =3D migrate_folio_split_on_alloc_fail(folio, - split_folios, mode, reason, stats); + split_folios, ctl, stats); if (!split_rc) break; /* Retry this folio in a later pass. */ @@ -2145,7 +2144,7 @@ static int migrate_folios_unmap(struct list_head *fro= m, */ static int migrate_folios_batch(struct list_head *from, new_folio_t get_new_folio, free_folio_t put_new_folio, - unsigned long private, enum migrate_mode mode, enum migrate_reason reaso= n, + unsigned long private, const struct migrate_control *ctl, struct list_head *ret_folios, struct list_head *split_folios, struct migrate_pages_stats *stats, int nr_pass) { @@ -2154,11 +2153,11 @@ static int migrate_folios_batch(struct list_head *f= rom, LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); =20 - VM_WARN_ON_ONCE(mode !=3D MIGRATE_ASYNC && + VM_WARN_ON_ONCE(ctl->mode !=3D MIGRATE_ASYNC && !list_empty(from) && !list_is_singular(from)); =20 rc_saved =3D migrate_folios_unmap(from, get_new_folio, put_new_folio, - private, mode, reason, ret_folios, split_folios, + private, ctl, ret_folios, split_folios, &unmap_folios, &dst_folios, stats, nr_pass, &nr_failed); if (rc_saved && list_empty(&unmap_folios)) { @@ -2171,7 +2170,7 @@ static int migrate_folios_batch(struct list_head *fro= m, =20 /* Move the unmapped folios */ migrate_folios_move(&unmap_folios, &dst_folios, put_new_folio, private, - mode, reason, ret_folios, stats, nr_pass, &nr_failed); + ctl, ret_folios, stats, nr_pass, &nr_failed); =20 rc =3D rc_saved ? : nr_failed; out: @@ -2189,27 +2188,29 @@ static int migrate_folios_batch(struct list_head *f= rom, */ static int __migrate_lru_folios(struct list_head *from, new_folio_t get_ne= w_folio, free_folio_t put_new_folio, unsigned long private, - enum migrate_mode mode, enum migrate_reason reason, - struct list_head *ret_folios, + const struct migrate_control *ctl, struct list_head *ret_folios, struct migrate_pages_stats *stats) { int rc, nr_failed =3D 0; LIST_HEAD(folios); LIST_HEAD(split_folios); struct migrate_pages_stats astats; + struct migrate_control async_ctl; =20 - if (mode =3D=3D MIGRATE_ASYNC) { + if (ctl->mode =3D=3D MIGRATE_ASYNC) { rc =3D migrate_folios_batch(from, get_new_folio, put_new_folio, - private, mode, reason, ret_folios, + private, ctl, ret_folios, &split_folios, stats, NR_MAX_MIGRATE_PAGES_RETRY); goto out; } =20 + async_ctl =3D *ctl; + async_ctl.mode =3D MIGRATE_ASYNC; memset(&astats, 0, sizeof(astats)); /* Try to migrate in batch with MIGRATE_ASYNC mode firstly */ rc =3D migrate_folios_batch(from, get_new_folio, put_new_folio, private, - MIGRATE_ASYNC, reason, &folios, &split_folios, &astats, + &async_ctl, &folios, &split_folios, &astats, NR_MAX_MIGRATE_ASYNC_RETRY); stats->nr_succeeded +=3D astats.nr_succeeded; stats->nr_thp_succeeded +=3D astats.nr_thp_succeeded; @@ -2236,8 +2237,7 @@ static int __migrate_lru_folios(struct list_head *fro= m, new_folio_t get_new_foli while (!list_empty(from)) { list_move(from->next, &folios); rc =3D migrate_folios_batch(&folios, get_new_folio, put_new_folio, - private, mode, reason, ret_folios, - &split_folios, stats, + private, ctl, ret_folios, &split_folios, stats, NR_MAX_MIGRATE_SYNC_RETRY); list_splice_tail_init(&folios, ret_folios); if (rc < 0) @@ -2255,7 +2255,7 @@ static int __migrate_lru_folios(struct list_head *fro= m, new_folio_t get_new_foli * folio they came from was already counted as one failure. */ migrate_folios_batch(&split_folios, get_new_folio, put_new_folio, - private, MIGRATE_ASYNC, reason, ret_folios, + private, &async_ctl, ret_folios, NULL, stats, 1); list_splice_tail_init(&split_folios, ret_folios); } @@ -2270,7 +2270,7 @@ static int __migrate_lru_folios(struct list_head *fro= m, new_folio_t get_new_foli */ static int migrate_lru_folios(struct list_head *from, new_folio_t get_new_= folio, free_folio_t put_new_folio, unsigned long private, - enum migrate_mode mode, enum migrate_reason reason, + const struct migrate_control *ctl, struct list_head *ret_folios, struct migrate_pages_stats *stats) { @@ -2292,7 +2292,7 @@ static int migrate_lru_folios(struct list_head *from,= new_folio_t get_new_folio, list_splice_init(from, &folios); =20 rc =3D __migrate_lru_folios(&folios, get_new_folio, put_new_folio, - private, mode, reason, ret_folios, stats); + private, ctl, ret_folios, stats); list_splice_tail_init(&folios, ret_folios); if (rc < 0) return rc; @@ -2335,18 +2335,22 @@ int migrate_pages(struct list_head *from, new_folio= _t get_new_folio, int rc, rc_gather; LIST_HEAD(ret_folios); struct migrate_pages_stats stats; + const struct migrate_control ctl =3D { + .mode =3D mode, + .reason =3D reason, + }; =20 - trace_mm_migrate_pages_start(mode, reason); + trace_mm_migrate_pages_start(ctl.mode, ctl.reason); =20 memset(&stats, 0, sizeof(stats)); =20 rc_gather =3D migrate_hugetlbs(from, get_new_folio, put_new_folio, privat= e, - mode, reason, &stats, &ret_folios); + &ctl, &stats, &ret_folios); if (rc_gather < 0) goto out; =20 rc =3D migrate_movable_ops_pages(from, get_new_folio, put_new_folio, - private, mode, reason, &stats, + private, &ctl, &stats, &ret_folios); if (rc < 0) { rc_gather =3D rc; @@ -2355,7 +2359,7 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, rc_gather +=3D rc; =20 rc =3D migrate_lru_folios(from, get_new_folio, put_new_folio, - private, mode, reason, &ret_folios, &stats); + private, &ctl, &ret_folios, &stats); if (rc < 0) { rc_gather =3D rc; goto out; @@ -2382,8 +2386,8 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, count_vm_events(THP_MIGRATION_SPLIT, stats.nr_thp_split); trace_mm_migrate_pages(stats.nr_succeeded, stats.nr_failed_pages, stats.nr_thp_succeeded, stats.nr_thp_failed, - stats.nr_thp_split, stats.nr_split, mode, - reason); + stats.nr_thp_split, stats.nr_split, ctl.mode, + ctl.reason); =20 if (ret_succeeded) *ret_succeeded =3D stats.nr_succeeded; --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012020.outbound.protection.outlook.com [40.93.195.20]) (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 5E82B477282; Wed, 2 Sep 2026 10:55:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346516; cv=fail; b=Rkg2A/pIcxCPTJwzrtbK1fjeHFAWMKjnw0XJGfKe1hVsDRQeKluMWvCCEg2muy7EhE8W45KmcsD7y/yuOoy6EWFOVhm46C6uBAX8mURbjYe1ylx7rgtOl246KzX1enf7UNDUrIZd2xxlyZ+SL5KPjixCa2lfjckioYeKWFbNJro= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346516; c=relaxed/simple; bh=LOl5eHjXADiF7hlMUDqzz5G/3F85i/QS9x6XGQEzTjk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=Vj6WIxgBiyBy9CuAKwCBnbbk/GyzSds0CjEPYeCLqpvldGb/L+gmfXiCNRVOTSykvVnTzgo4midIIq9xG+WHgy8jiJRzPRl4j9fTOO9DU3B2KGm2//W2XNToAK4rbjjkZd/+3rXtqMkHxGtlWiV4T11tIRSIwdJk4qXmFRK3eus= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=eXtCgG6P; arc=fail smtp.client-ip=40.93.195.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="eXtCgG6P" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PHWY6r+JZ+F/6AQhV+g6EKFQ1CcD+0TUtazQkYs3PODDhRR/ZixEkinI23aKDzf8K4HPJ32NPFOLmQZULoOR5D/IWFQZQhloL/ZGr7alQW57c4RXn40q9sTO6+isGUH5JfFRze/L4P0DG1uYloiMYuzUXvQu33xBguP48q0eltSbN9iUZ6hdRW32/48gfltjih0kXQObKpo3ETIKnWuTtlLQuHjBz/l0xw7EEQmyMHfJ0icinBcaXTiahZhbERvgvEu2e81rdwB90WNo3jWAHHWVPI7mz6UBrG+lc8JlfMvVRxSMc8s3ZMi8GFPiSLuVS+ptXlcGSQitwvpl/Ce47w== 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=zXdSE/kpzWbUy94HZbr2kS6pvG2nMVFr4ppud2knmyQ=; b=RXcn8jsk4AU7SgaK1K/i3Td6BqrZIppRXcJzMoQDV1EDcTjbjQk+QK4nOVHBLORidefUK46Ow2aLA6Lxa0tesRIZZo+BKvP6YTnRX+mF4TY1pI/Ce5KHdm8piHKI/uWnPupEhDGvRnMFIKToRI5fbZ7js6kltBMnzZYF8BJwr/z5MCSWrO7B3gTGRWFmQymrhSYytYGWQZaWe+qD4Ps/Nt6XNh1ATmLOfyPDcNRtulAkHKKpcNXO6H0Ah9Dvjz2D/DzpRxYN2IkX0HFwZYmItkV8QEWfJBbi6E+AknQcPLkfLkXrDhK/M0kZxjHAwF34YX01n/EZRXGv0sCgblwl6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zXdSE/kpzWbUy94HZbr2kS6pvG2nMVFr4ppud2knmyQ=; b=eXtCgG6PFzVo3oRU14ip8RfUJVzTQNOYqiuL/ouGqAE3vilGVPldaCJ1dSFRiUE1cM322ZJT/rbV6ZYb88wkUH+CY1O9v3kwdpQLsKJe128frTP9aiuJg2ic7Cb/52vEt/ATPsVV5ygTxGJ96MGROnBcyD2AxPN5MFJ6ns0BOhA= Received: from BN9P222CA0001.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::6) by DM4PR12MB7671.namprd12.prod.outlook.com (2603:10b6:8:104::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.10; Wed, 2 Sep 2026 10:55:04 +0000 Received: from BN5PEPF00046988.namprd02.prod.outlook.com (2603:10b6:408:10c:cafe::58) by BN9P222CA0001.outlook.office365.com (2603:10b6:408:10c::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.10 via Frontend Transport; Wed, 2 Sep 2026 10:55:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF00046988.mail.protection.outlook.com (10.167.245.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:55:04 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:54:48 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:24 +0000 Subject: [PATCH RFC 10/11] mm/migrate: pass migrate_control to migrate_pages() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-10-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=13649; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=LOl5eHjXADiF7hlMUDqzz5G/3F85i/QS9x6XGQEzTjk=; b=H9JSGPfjW+jdP0WD9kqP4t5MqC/arI8ecfrpaobnLmNWKDJK0yNI/ZubGwy+IU3KCS+BtCKiX O6hyMNlw/tZDUhpene2oN7UPwgprxMl4fnlGCD342IXoQ9RY9Pk8QMt X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF00046988:EE_|DM4PR12MB7671:EE_ X-MS-Office365-Filtering-Correlation-Id: 99cb2392-3fb3-47ea-876d-08df08e0a51c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|82310400026|7416014|36860700016|376014|10067099003|3023799007|18002099003|22082099003|11063799006|56012099006|921020; X-Microsoft-Antispam-Message-Info: KnHTQZl48xc7Kdzv5SFB/TPUEzWWzT2gKOsC6E2nJNgPHQj3/FadTkcMLXXjeSBxw7bSVKpWUFujM7TLu2RzsMOJVbM4ZB9Yj2jwTd5XTbHKyDuOrGL+47QJV9jg0vIcLpqHmle54CdHCFMN/ijHTHIZ1c9ChwCQff4aIDgVlumgYIvBVjuRawT38RuEQZo2frcgaQYw4SBpmQqJF69YTtGm2zn3Ob1nhbJDa4R2W/Ne1a4s5NtZj7Okb0VWqIsjT4v4fuVE0qzXdMpKAzLwyeAREofFs4gIfT8/agl5nghVNLBsfxibDb4sNme6jlPt2YwgudQVJSQpbAWoNaB08s1gut0k8MLwE07mqnoSJvRsfGE1qH/hmzU4AgWw9l7JGAFR+LeOfB6azrsUxuE4mPgDxieGesX17RPFvemJfP5KuDMuCMrGEwPuOcCe40hbImxUFdq1bFag+jKm6QqohozuGDi6pqxlxJ6tbrkb2ZxBo3rPJ9JDBWaxhvx03+S7ibSPxywgvmcF91gD/Va6/y0+hQ+vgK3LfxjrBXUqjiu0zSRAmm2uGFPabQZE+xg4DAct+IA7LLfGFnYnsZzZR6SL6fP2uHEuY0jzwYrukvSg/rNslaAdnn4hjnCBbgRA2OEUftLaMuEWa1n+I1cIfqgeatCC8yy7+tKyoLXaxUMurgnzb2vwZ6UCkU/nY/1jIhBdghQhKveO1cGfzL/AFaWknTMKc0VzlIKvB4RtliD7SisHQjtf+ZBL06EJQT3q X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(82310400026)(7416014)(36860700016)(376014)(10067099003)(3023799007)(18002099003)(22082099003)(11063799006)(56012099006)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cxBtnbSCT3jrQ37WFsYCXMC/AvA0kUAUA8x7k5Ga5/g7PoDM5VNdXzk9dTaPHMBvVBEALLjNs9xfXEWTSK4/kzIKcTfNYhMPlMhBsnQt91i0ml9lsOgl8w5K0VYpqriBZefPNRhKpR+tIQLrk4q7UBDdDjXjtlELbe2uDyhwBbV81Nq4zdM+1t57rd7UqNToTpLzclTq9XaUa148cDeD1xnVvXsBbvxXB4jk1y/bN1/TR/aiU7HVdOlqmBwqHOXGSNkvqLarL5ceCZe4WKSo1yJRtpcc5xmJYC/5H8DgV+ShR8tkPFJYZA9twoJfaPZqw/VWG/sqEvRJi7BdORwc8890QOTQgkbxKmxoQRr1Xmouh1u76eKUJgtfY/sZKGKky7lQn7O5FGU6GHpG7/y1CKyRY2uAbdRzWVcevhtaOgpbG5UHBMTCdPC2fw93Cw5P X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:55:04.5282 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 99cb2392-3fb3-47ea-876d-08df08e0a51c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF00046988.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7671 migrate_pages() still takes mode and reason separately and reconstructs a migrate_control internally. This prevents callers from supplying additional migration policy without extending its argument list. Change migrate_pages() to take a const struct migrate_control pointer and update callers to construct it on the stack. Derive asynchronous controls by copying the caller's control and overriding only the mode, preserving any additional policy fields. No functional change intended. Signed-off-by: Shivank Garg --- include/linux/migrate.h | 5 ++--- mm/compaction.c | 8 ++++++-- mm/damon/ops-common.c | 7 +++++-- mm/gup.c | 7 +++++-- mm/memory-failure.c | 6 +++++- mm/memory_hotplug.c | 6 +++++- mm/mempolicy.c | 13 ++++++++++--- mm/migrate.c | 36 +++++++++++++++++++----------------- mm/page_alloc.c | 6 +++++- mm/vmscan.c | 7 +++++-- 10 files changed, 67 insertions(+), 34 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 78424b3824c2..cec5713944e3 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -57,8 +57,7 @@ void putback_movable_pages(struct list_head *l); int migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, enum migrate_mode mode); int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free, - unsigned long private, enum migrate_mode mode, - enum migrate_reason reason, + unsigned long private, const struct migrate_control *ctl, unsigned int *ret_succeeded); struct folio *alloc_migration_target(struct folio *src, unsigned long priv= ate); bool isolate_movable_ops_page(struct page *page, isolate_mode_t mode); @@ -78,7 +77,7 @@ int set_movable_ops(const struct movable_operations *ops,= enum pagetype type); static inline void putback_movable_pages(struct list_head *l) {} static inline int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free, unsigned long private, - enum migrate_mode mode, enum migrate_reason reason, + const struct migrate_control *ctl, unsigned int *ret_succeeded) { return -ENOSYS; } static inline struct folio *alloc_migration_target(struct folio *src, diff --git a/mm/compaction.c b/mm/compaction.c index a049415512c6..e75fcb0ee007 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2566,6 +2566,10 @@ compact_zone(struct compact_control *cc, struct capt= ure_control *capc) unsigned long end_pfn =3D zone_end_pfn(cc->zone); unsigned long last_migrated_pfn; const bool sync =3D cc->mode !=3D MIGRATE_ASYNC; + const struct migrate_control ctl =3D { + .mode =3D cc->mode, + .reason =3D MR_COMPACTION, + }; bool update_cached; unsigned int nr_succeeded =3D 0, nr_migratepages; int order; @@ -2696,8 +2700,8 @@ compact_zone(struct compact_control *cc, struct captu= re_control *capc) */ nr_migratepages =3D cc->nr_migratepages; err =3D migrate_pages(&cc->migratepages, compaction_alloc, - compaction_free, (unsigned long)cc, cc->mode, - MR_COMPACTION, &nr_succeeded); + compaction_free, (unsigned long)cc, &ctl, + &nr_succeeded); =20 trace_mm_compaction_migratepages(nr_migratepages, nr_succeeded); =20 diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index fbda70d8ea4d..da848561aebb 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -315,6 +315,10 @@ static unsigned int __damon_migrate_folio_list( __GFP_NOMEMALLOC | GFP_NOWAIT | __GFP_THISNODE, .nid =3D target_nid, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_ASYNC, + .reason =3D MR_DAMON, + }; =20 if (pgdat->node_id =3D=3D target_nid || target_nid =3D=3D NUMA_NO_NODE) return 0; @@ -324,8 +328,7 @@ static unsigned int __damon_migrate_folio_list( =20 /* Migration ignores all cpuset and mempolicy settings */ migrate_pages(migrate_folios, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_ASYNC, MR_DAMON, - &nr_succeeded); + (unsigned long)&mtc, &ctl, &nr_succeeded); =20 return nr_succeeded; } diff --git a/mm/gup.c b/mm/gup.c index eb898ea1ee22..73e1e8bfa4c0 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2357,10 +2357,13 @@ migrate_longterm_unpinnable_folios(struct list_head= *movable_folio_list, .gfp_mask =3D GFP_USER | __GFP_NOWARN, .reason =3D MR_LONGTERM_PIN, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_SYNC, + .reason =3D MR_LONGTERM_PIN, + }; =20 if (migrate_pages(movable_folio_list, alloc_migration_target, - NULL, (unsigned long)&mtc, MIGRATE_SYNC, - MR_LONGTERM_PIN, NULL)) { + NULL, (unsigned long)&mtc, &ctl, NULL)) { ret =3D -ENOMEM; goto err; } diff --git a/mm/memory-failure.c b/mm/memory-failure.c index a8b03e2920ba..85d0a69a0844 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2860,6 +2860,10 @@ static int soft_offline_in_use_page(struct page *pag= e) .gfp_mask =3D GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, .reason =3D MR_MEMORY_FAILURE, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_SYNC, + .reason =3D MR_MEMORY_FAILURE, + }; =20 if (!huge && folio_test_large(folio)) { const int new_order =3D min_order_for_split(folio); @@ -2916,7 +2920,7 @@ static int soft_offline_in_use_page(struct page *page) =20 if (isolated) { ret =3D migrate_pages(&pagelist, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_FAILURE, NULL); + (unsigned long)&mtc, &ctl, NULL); if (!ret) { bool release =3D !huge; =20 diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 226ab9cb078a..1250b0d47702 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1901,6 +1901,10 @@ static void do_migrate_range(unsigned long start_pfn= , unsigned long end_pfn) .gfp_mask =3D GFP_KERNEL | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, .reason =3D MR_MEMORY_HOTPLUG, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_SYNC, + .reason =3D MR_MEMORY_HOTPLUG, + }; int ret; =20 /* @@ -1918,7 +1922,7 @@ static void do_migrate_range(unsigned long start_pfn,= unsigned long end_pfn) if (nodes_empty(nmask)) node_set(mtc.nid, nmask); ret =3D migrate_pages(&source, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_HOTPLUG, NULL); + (unsigned long)&mtc, &ctl, NULL); if (ret) { list_for_each_entry(folio, &source, lru) { if (__ratelimit(&migrate_rs)) { diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3498a5651d50..14f3f24a6fad 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1295,6 +1295,10 @@ static long migrate_to_node(struct mm_struct *mm, in= t source, int dest, .gfp_mask =3D GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, .reason =3D MR_SYSCALL, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_SYNC, + .reason =3D MR_SYSCALL, + }; =20 nodes_clear(nmask); node_set(source, nmask); @@ -1320,7 +1324,7 @@ static long migrate_to_node(struct mm_struct *mm, int= source, int dest, =20 if (!list_empty(&pagelist)) { err =3D migrate_pages(&pagelist, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL, NULL); + (unsigned long)&mtc, &ctl, NULL); if (err) putback_movable_pages(&pagelist); } @@ -1499,6 +1503,10 @@ static long do_mbind(unsigned long start, unsigned l= ong len, long err; long nr_failed; LIST_HEAD(pagelist); + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_SYNC, + .reason =3D MR_MEMPOLICY_MBIND, + }; =20 if (flags & ~(unsigned long)MPOL_MF_VALID) return -EINVAL; @@ -1616,8 +1624,7 @@ static long do_mbind(unsigned long start, unsigned lo= ng len, if (!err && !list_empty(&pagelist)) { nr_failed |=3D migrate_pages(&pagelist, alloc_migration_target_by_mpol, NULL, - (unsigned long)&mmpol, MIGRATE_SYNC, - MR_MEMPOLICY_MBIND, NULL); + (unsigned long)&mmpol, &ctl, NULL); } =20 if (nr_failed && (flags & MPOL_MF_STRICT)) diff --git a/mm/migrate.c b/mm/migrate.c index e4bc7122076e..549f8b57092c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2312,9 +2312,8 @@ static int migrate_lru_folios(struct list_head *from,= new_folio_t get_new_folio, * @put_new_folio: The function used to free target folios if migration * fails, or NULL if no special handling is necessary. * @private: Private data to be passed on to get_new_folio() - * @mode: The migration mode that specifies the constraints for - * folio migration, if any. - * @reason: The reason for folio migration. + * @ctl: The policy for this migration: blocking discipline, + * and reason. * @ret_succeeded: Set to the number of folios migrated successfully if * the caller passes a non-NULL pointer. * @@ -2330,27 +2329,23 @@ static int migrate_lru_folios(struct list_head *fro= m, new_folio_t get_new_folio, */ int migrate_pages(struct list_head *from, new_folio_t get_new_folio, free_folio_t put_new_folio, unsigned long private, - enum migrate_mode mode, enum migrate_reason reason, unsigned int *ret_su= cceeded) + const struct migrate_control *ctl, unsigned int *ret_succeeded) { int rc, rc_gather; LIST_HEAD(ret_folios); struct migrate_pages_stats stats; - const struct migrate_control ctl =3D { - .mode =3D mode, - .reason =3D reason, - }; =20 - trace_mm_migrate_pages_start(ctl.mode, ctl.reason); + trace_mm_migrate_pages_start(ctl->mode, ctl->reason); =20 memset(&stats, 0, sizeof(stats)); =20 rc_gather =3D migrate_hugetlbs(from, get_new_folio, put_new_folio, privat= e, - &ctl, &stats, &ret_folios); + ctl, &stats, &ret_folios); if (rc_gather < 0) goto out; =20 rc =3D migrate_movable_ops_pages(from, get_new_folio, put_new_folio, - private, &ctl, &stats, + private, ctl, &stats, &ret_folios); if (rc < 0) { rc_gather =3D rc; @@ -2359,7 +2354,7 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, rc_gather +=3D rc; =20 rc =3D migrate_lru_folios(from, get_new_folio, put_new_folio, - private, &ctl, &ret_folios, &stats); + private, ctl, &ret_folios, &stats); if (rc < 0) { rc_gather =3D rc; goto out; @@ -2386,8 +2381,8 @@ int migrate_pages(struct list_head *from, new_folio_t= get_new_folio, count_vm_events(THP_MIGRATION_SPLIT, stats.nr_thp_split); trace_mm_migrate_pages(stats.nr_succeeded, stats.nr_failed_pages, stats.nr_thp_succeeded, stats.nr_thp_failed, - stats.nr_thp_split, stats.nr_split, ctl.mode, - ctl.reason); + stats.nr_thp_split, stats.nr_split, ctl->mode, + ctl->reason); =20 if (ret_succeeded) *ret_succeeded =3D stats.nr_succeeded; @@ -2454,9 +2449,13 @@ static int do_move_pages_to_node(struct list_head *p= agelist, int node) .gfp_mask =3D GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, .reason =3D MR_SYSCALL, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_SYNC, + .reason =3D MR_SYSCALL, + }; =20 err =3D migrate_pages(pagelist, alloc_migration_target, NULL, - (unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL, NULL); + (unsigned long)&mtc, &ctl, NULL); if (err) putback_movable_pages(pagelist); return err; @@ -2961,11 +2960,14 @@ int migrate_misplaced_folio(struct folio *folio, in= t node) LIST_HEAD(migratepages); struct mem_cgroup *memcg =3D get_mem_cgroup_from_folio(folio); struct lruvec *lruvec =3D mem_cgroup_lruvec(memcg, pgdat); + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_ASYNC, + .reason =3D MR_NUMA_MISPLACED, + }; =20 list_add(&folio->lru, &migratepages); nr_remaining =3D migrate_pages(&migratepages, alloc_misplaced_dst_folio, - NULL, node, MIGRATE_ASYNC, - MR_NUMA_MISPLACED, &nr_succeeded); + NULL, node, &ctl, &nr_succeeded); if (nr_remaining && !list_empty(&migratepages)) putback_movable_pages(&migratepages); if (nr_succeeded) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 12fac9084c48..8a921f6cdc86 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7146,6 +7146,10 @@ static int __alloc_contig_migrate_range(struct compa= ct_control *cc, .gfp_mask =3D cc->gfp_mask, .reason =3D MR_CONTIG_RANGE, }; + const struct migrate_control ctl =3D { + .mode =3D cc->mode, + .reason =3D MR_CONTIG_RANGE, + }; =20 lru_cache_disable(); =20 @@ -7172,7 +7176,7 @@ static int __alloc_contig_migrate_range(struct compac= t_control *cc, cc->nr_migratepages -=3D nr_reclaimed; =20 ret =3D migrate_pages(&cc->migratepages, alloc_migration_target, - NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE, NULL); + NULL, (unsigned long)&mtc, &ctl, NULL); =20 /* * On -ENOMEM, migrate_pages() bails out right away. It is pointless diff --git a/mm/vmscan.c b/mm/vmscan.c index f11491ee9ed5..7e8b04c97342 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1013,6 +1013,10 @@ static unsigned int demote_folio_list(struct list_he= ad *demote_folios, .nmask =3D &allowed_mask, .reason =3D MR_DEMOTION, }; + const struct migrate_control ctl =3D { + .mode =3D MIGRATE_ASYNC, + .reason =3D MR_DEMOTION, + }; =20 if (list_empty(demote_folios)) return 0; @@ -1031,8 +1035,7 @@ static unsigned int demote_folio_list(struct list_hea= d *demote_folios, =20 /* Demotion ignores all cpuset and mempolicy settings */ migrate_pages(demote_folios, alloc_demote_folio, NULL, - (unsigned long)&mtc, MIGRATE_ASYNC, MR_DEMOTION, - &nr_succeeded); + (unsigned long)&mtc, &ctl, &nr_succeeded); =20 return nr_succeeded; } --=20 2.43.0 From nobody Sat Sep 26 10:01:31 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010006.outbound.protection.outlook.com [52.101.61.6]) (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 ED4F547124D; Wed, 2 Sep 2026 10:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.6 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346548; cv=fail; b=r7NpNzq5BWIc+dLfPz7fo6xc+5G+6eGDbv+iJvyGb30nVUqVenGLWPmOsr2qV4envfPBQFdoUEfqedrVWxIqWKcp8BIr0kMIAWwFs6MdTv3YhHxwU5vJEv1nK701GptTCwBP37WT5vWrgc5JH+ONN9HnHQBcvVledLE2+nX7nWg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788346548; c=relaxed/simple; bh=yRTEphkqK1Fis5qo6DvPrfJS5obUvomZv5Ye5/JvcHY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=U7n1KZnwl8crur/K3N7qjUh1dWrynsc3jzsmkFBgA3Fh/r98iRQYkbYUjbnQ3SRRl+G+sqVz7uQeCNfxdCaFcZZMo+OezCuPj1nQc8hVdZNrFAFuzl0c5R2ReyJnt0xH7/kZVvjXnn1M8vD1DORuBnBKi9jnHPfNpVLekbFIPjI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=BdUyQkVR; arc=fail smtp.client-ip=52.101.61.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="BdUyQkVR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kl81BcQll3agYVALOTKHKK8OYxYbuF1YO/4bBsz875PK1zk2JnyOthifBMywkK+DKDhB60l+xqXa4t3b6BvI+wJcSQvt08E380IOlRhDKM4KH7sMDnS3EO4s9CthnyCOGGZFA4JgCoYMHr0G552tmX3c81xSedxtdHX3R5Daha1pUdTMh7aGzXRzCdhqEX7I3gb/43IsruTvRmEM3mVwDf9p52EpiD1LD4vbXq7IRw5PvvkXIyu0Hpc8sLb0Jk0/Uv9g18wwPPaNLJ6AYURGIra1GNuXQH55ISLItyRZQe80gldjqVnmtS7EhSA+nymvXGwLwnLuIHkuGGsGjRi0fg== 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=uqWZjB7KL6Qaq3UbZNEh1+3/BaITN2t6ZfsVDmk6hFY=; b=g5yk2/vxJI4YZ80wzc7mMn0cB47kik7cOdjpIlgpcZ5Vw0+g0L6MnBOlqHsaFfFSzEUwNTk+Ssmmyn+6uynzON62zT+oN1oBLK2MVdHOmr3csDXYMQXEsRFayxEjzhUeCYODaPMCl93pJSY6UTFRnyO3a6EM9Pe3N/RFnNsq1N/VC6JJWaZS28u6+8NyovxOMNopGMFlrqSncUYSS/6ZNsQzXRO4uLnUoTvM0coCak8haS4GdMUl+sVhRhw3xFjkO0drIA6QVMJMLLGnamVZ3tyQAcmxRRXmr6pLorCDlNxDb8lpLp14DlM5m5vTs8zKbnJimvEZxQfPkC5s8X4pTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sk.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uqWZjB7KL6Qaq3UbZNEh1+3/BaITN2t6ZfsVDmk6hFY=; b=BdUyQkVRCdh9wRf1fs8lbdFaQWE/504HdTxsOzk1MEdth9g7x1p3lYib3+ab5UpHwL48lFEVmjPBUcCTYTrBFSxaQPaTEDyN1cnBbRiy2GbYxrriNwIzBSYCUji7nsl1cfADMgIAoSVtMS1TYxR4eoADrVw+Q84n0YkmtRnTzSk= Received: from BN9PR03CA0193.namprd03.prod.outlook.com (2603:10b6:408:f9::18) by CY5PR12MB6153.namprd12.prod.outlook.com (2603:10b6:930:27::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.360.13; Wed, 2 Sep 2026 10:55:33 +0000 Received: from BN5PEPF00046989.namprd02.prod.outlook.com (2603:10b6:408:f9:cafe::19) by BN9PR03CA0193.outlook.office365.com (2603:10b6:408:f9::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.382.11 via Frontend Transport; Wed, 2 Sep 2026 10:55:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN5PEPF00046989.mail.protection.outlook.com (10.167.245.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.382.8 via Frontend Transport; Wed, 2 Sep 2026 10:55:32 +0000 Received: from [127.0.1.1] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 2 Sep 2026 05:55:02 -0500 From: Shivank Garg Date: Wed, 2 Sep 2026 10:52:25 +0000 Subject: [PATCH RFC 11/11] mm/migrate: pass migrate_control to migrate_folio() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260902-migrate-refactor-shivank-v1-11-9dcca87669c4@amd.com> References: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> In-Reply-To: <20260902-migrate-refactor-shivank-v1-0-9dcca87669c4@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Vlastimil Babka , "Suren Baghdasaryan" , Michal Hocko , "Brendan Jackman" , Johannes Weiner , "SJ Park" , Jason Gunthorpe , John Hubbard , Peter Xu , Miaohe Lin , Naoya Horiguchi , "Oscar Salvador" , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , Jan Kara , Jonathan Corbet , Shuah Khan , Randy Dunlap , "Alexander Viro" , Christian Brauner , Benjamin LaHaise , Chris Mason , David Sterba , Muchun Song , Dave Kleikamp , Trond Myklebust , Anna Schumaker , Mike Rapoport , Sean Christopherson , Paolo Bonzini , Bharata B Rao , David Rientjes , "Yiannis Nikolakopoulos" CC: , , , , , , , , , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788346348; l=20575; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=yRTEphkqK1Fis5qo6DvPrfJS5obUvomZv5Ye5/JvcHY=; b=b6CZM0096OLZjss2nbNnoQyz5oHyvtGYtuvC44qQglGaFjWZoGZtsEejeYgR+Gyc8MW7IlgdM xNerLDWBmFOAWwQS9RxH3urLmY3Gzq5ll7q83g4a5TPJK7krZJ2NDY2 X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN5PEPF00046989:EE_|CY5PR12MB6153:EE_ X-MS-Office365-Filtering-Correlation-Id: 60b5232b-0d87-4e5f-3b2f-08df08e0b5cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|7416014|376014|23010399003|36860700016|22082099003|18002099003|56012099006|10067099003|11063799006|921020; X-Microsoft-Antispam-Message-Info: aYGoq5TXkwWEGOnlOtRhGNlqvK+9iM1nqxyZtJQLPJoPMRlFk6cyC/ve0SAV4ABx9JiIkc27DEY0LgYWMeib14ebeYuzLqf0csCWnqVXck+32IYFbk3Jn7Ez7NvcG8NIOdCudfhpoDEY8EZfOZR6rBrETQ44gVOSwnR5dRRgaENxDkDpST9pqJfs1w0dfF5YlkKXRl3+H8NL50SNjg0hxBeyikQA0ABef0bX5L8rEdmnYjoaLsThPrDCvTPmzr3mUpFM5hHDZqzWlvgSzTbNd49ROl/leavwRbxIqObh/COv24SR1KfqW/V+QcEozKIXHt85mvZtZE9/gwAyTKqDkpodq62eZVIT2LTd74qb1iGHRQpw1jhw9XaGlqq0TTSeLmwlyRoZOOhbDcKNZWT+IHGaH7DbVxvoWF+m0bzAceBxeenvoZZLNX0GyuJOAgge99VQaP9AY6JNfyE1t4DCbM6yg7aEIpY1Sqa9RZIp24zHFWLD1df/SQBn2J/KbgZGKW6TEJCJsK8yJaqJQKqY5ABRnpnBDbrkK2XOz/GZwvyYcAXhqMlYe4Gv5R9Adpyne9b9KIstlrNqCmw7SPk4xIah1DPy07zoG8135reeKPdyLO2QIzKv+pAUesQhZuadUxOQa9Je8UwIF+p1DGT7I/uTP+2wU/XcYlVCe5XfXJ1WlR4JjzyLoLVZJvApC8E2NZVigyhyLxvUxiPh5IZlBivMcqp5FyNVJnDmo7uZCAS/G07VyAOijtmIx2urCAJn X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(7416014)(376014)(23010399003)(36860700016)(22082099003)(18002099003)(56012099006)(10067099003)(11063799006)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3EUw9HfngF2nOhdxnG4RvpENE8M01m3DFA3drZUvYUOItAvcTn8lG36usK0D0UjInSLB/B83OkITfL17HXsb1JkIAJa0n71gmnmoRXo/gNtfIBcgD0g/8lHineB4AWRWhBhZ9qH4hwlhiI+a/qoo1djEzfpHAsjOTRQZ/2crNsJ5c4MExgfOY2UYdaNE2mqtZJk3kWf3tK9itN9YJ7OMxSY0626lQ2GfSEipR3a0CVyzYJDCbH7QHaXY3sBEJnHWzBLeTCPdC3/hwAhAztHf5pWeGs6My+wgP6XpklMXtMS/NNGcvfiDx+ywar/EWOJhR1zqK+sJL/IjGQYhksJuvBmQW9j/ab8YQarnhc5dFzTm0a/BkAAq4x3irZDI2M2RbWizi/pbk5Aiehf/15YAHkBtxGJA7BSRyX+MW2UbKHHZ3ICBDmLn81H7uY/zZKWq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2026 10:55:32.5309 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60b5232b-0d87-4e5f-3b2f-08df08e0b5cd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN5PEPF00046989.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6153 The migration core now carries policy in struct migrate_control, but migrate_folio() and the address_space migrate_folio callback still receive only the migration mode. This prevents additional policy, such as copy-cache hints, from reaching folio-specific migration code. Pass the control as const through migrate_folio(), the common migration helpers, and the address_space callback. Update all implementations and documentation accordingly. Existing callbacks continue to make their decisions from ctl->mode only, none changes behavior yet. No functional change intended. Signed-off-by: Shivank Garg Reviewed-by: Jan Kara --- Documentation/filesystems/locking.rst | 2 +- Documentation/filesystems/vfs.rst | 7 +++-- fs/aio.c | 2 +- fs/btrfs/disk-io.c | 5 ++-- fs/btrfs/inode.c | 6 ++--- fs/hugetlbfs/inode.c | 4 +-- fs/jfs/jfs_metapage.c | 14 +++++----- fs/nfs/internal.h | 2 +- fs/nfs/write.c | 8 +++--- include/linux/buffer_head.h | 6 +++-- include/linux/fs.h | 6 ++--- include/linux/migrate.h | 2 +- include/linux/pagemap.h | 2 +- mm/migrate.c | 50 +++++++++++++++++++------------= ---- mm/secretmem.c | 3 ++- virt/kvm/guest_memfd.c | 2 +- 16 files changed, 66 insertions(+), 55 deletions(-) diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesyst= ems/locking.rst index 844d65eb47a5..b406df403b4a 100644 --- a/Documentation/filesystems/locking.rst +++ b/Documentation/filesystems/locking.rst @@ -260,7 +260,7 @@ prototypes:: void (*free_folio)(struct folio *); int (*direct_IO)(struct kiocb *, struct iov_iter *iter); int (*migrate_folio)(struct address_space *, struct folio *dst, - struct folio *src, enum migrate_mode); + struct folio *src, const struct migrate_control *ctl); int (*launder_folio)(struct folio *); bool (*is_partially_uptodate)(struct folio *, size_t from, size_t count); int (*error_remove_folio)(struct address_space *, struct folio *); diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/= vfs.rst index d3a93eec3945..8e1404723db1 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -767,7 +767,8 @@ cache in your filesystem. The following members are de= fined: void (*free_folio)(struct folio *); ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter); int (*migrate_folio)(struct mapping *, struct folio *dst, - struct folio *src, enum migrate_mode); + struct folio *src, + const struct migrate_control *ctl); int (*launder_folio) (struct folio *); =20 bool (*is_partially_uptodate) (struct folio *, size_t from, @@ -939,7 +940,9 @@ cache in your filesystem. The following members are de= fined: wants to relocate a folio (maybe from a memory device that is signalling imminent failure) it will pass a new folio and an old folio to this function. migrate_folio should transfer any private - data across and update any references that it has to the folio. + data across and update any references that it has to the folio. The + control describes the blocking mode and the reason for migration. If + the mode is ``MIGRATE_ASYNC``, the callback must not block. =20 ``launder_folio`` Called before freeing a folio - it writes back the dirty folio. diff --git a/fs/aio.c b/fs/aio.c index d78acc69f487..58ee9d0845dd 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -458,7 +458,7 @@ static const struct file_operations aio_ring_fops =3D { =20 #if IS_ENABLED(CONFIG_MIGRATION) static int aio_migrate_folio(struct address_space *mapping, struct folio *= dst, - struct folio *src, enum migrate_mode mode) + struct folio *src, const struct migrate_control *ctl) { struct kioctx *ctx; struct aio_inode_info *ai =3D AIO_I(mapping->host); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 819727460bcf..509651577a1c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -460,7 +460,8 @@ int btrfs_validate_extent_buffer(struct extent_buffer *= eb, =20 #ifdef CONFIG_MIGRATION static int btree_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { /* * we can't safely write a btree page from here, @@ -475,7 +476,7 @@ static int btree_migrate_folio(struct address_space *ma= pping, if (folio_get_private(src) && !filemap_release_folio(src, GFP_KERNEL)) return -EAGAIN; - return migrate_folio(mapping, dst, src, mode); + return migrate_folio(mapping, dst, src, ctl); } #else #define btree_migrate_folio NULL diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3c10a0ef0002..9f1e567fa5ed 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7653,10 +7653,10 @@ static bool btrfs_release_folio(struct folio *folio= , gfp_t gfp_flags) =20 #ifdef CONFIG_MIGRATION static int btrfs_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, - enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { - int ret =3D filemap_migrate_folio(mapping, dst, src, mode); + int ret =3D filemap_migrate_folio(mapping, dst, src, ctl); =20 if (ret) return ret; diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 7611a8470ea2..367148251689 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1022,8 +1022,8 @@ static int hugetlbfs_symlink(struct mnt_idmap *idmap, =20 #ifdef CONFIG_MIGRATION static int hugetlbfs_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, - enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { int rc; =20 diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c index 41fe12e641ce..7958edacb497 100644 --- a/fs/jfs/jfs_metapage.c +++ b/fs/jfs/jfs_metapage.c @@ -155,7 +155,7 @@ static inline void dec_io(struct folio *folio, blk_stat= us_t status, #ifdef CONFIG_MIGRATION static int __metapage_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, - enum migrate_mode mode) + const struct migrate_control *ctl) { struct meta_anchor *src_anchor =3D src->private; struct metapage *mps[MPS_PER_PAGE] =3D {0}; @@ -168,7 +168,7 @@ static int __metapage_migrate_folio(struct address_spac= e *mapping, return -EAGAIN; } =20 - rc =3D filemap_migrate_folio(mapping, dst, src, mode); + rc =3D filemap_migrate_folio(mapping, dst, src, ctl); if (rc) return rc; =20 @@ -231,7 +231,7 @@ static inline void remove_metapage(struct folio *folio,= struct metapage *mp) #ifdef CONFIG_MIGRATION static int __metapage_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, - enum migrate_mode mode) + const struct migrate_control *ctl) { struct metapage *mp; int page_offset; @@ -241,7 +241,7 @@ static int __metapage_migrate_folio(struct address_spac= e *mapping, if (metapage_locked(mp)) return -EAGAIN; =20 - rc =3D filemap_migrate_folio(mapping, dst, src, mode); + rc =3D filemap_migrate_folio(mapping, dst, src, ctl); if (rc) return rc; =20 @@ -645,18 +645,18 @@ static bool metapage_release_folio(struct folio *foli= o, gfp_t gfp_mask) */ static int metapage_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, - enum migrate_mode mode) + const struct migrate_control *ctl) { int expected_count; =20 if (!src->private) - return filemap_migrate_folio(mapping, dst, src, mode); + return filemap_migrate_folio(mapping, dst, src, ctl); =20 /* Check whether page does not have extra refs before we do more work */ expected_count =3D folio_expected_ref_count(src) + 1; if (folio_ref_count(src) !=3D expected_count) return -EAGAIN; - return __metapage_migrate_folio(mapping, dst, src, mode); + return __metapage_migrate_folio(mapping, dst, src, ctl); } #else #define metapage_migrate_folio NULL diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index abc81f5ae578..e1f366cff2c0 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -673,7 +673,7 @@ void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_= commit_info *cinfo) =20 #ifdef CONFIG_MIGRATION int nfs_migrate_folio(struct address_space *, struct folio *dst, - struct folio *src, enum migrate_mode); + struct folio *src, const struct migrate_control *); #else #define nfs_migrate_folio NULL #endif diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 623e7ef1f73d..159135900399 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -2112,7 +2112,7 @@ int nfs_wb_folio(struct inode *inode, struct folio *f= olio) =20 #ifdef CONFIG_MIGRATION int nfs_migrate_folio(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode) + struct folio *src, const struct migrate_control *ctl) { /* * If the private flag is set, the folio is currently associated with @@ -2123,19 +2123,19 @@ int nfs_migrate_folio(struct address_space *mapping= , struct folio *dst, * the folio lock. */ if (folio_test_private(src)) { - if (mode =3D=3D MIGRATE_SYNC) + if (ctl->mode =3D=3D MIGRATE_SYNC) nfs_wb_folio(src->mapping->host, src); if (folio_test_private(src)) return -EBUSY; } =20 if (folio_test_private_2(src)) { /* [DEPRECATED] */ - if (mode =3D=3D MIGRATE_ASYNC) + if (ctl->mode =3D=3D MIGRATE_ASYNC) return -EBUSY; folio_wait_private_2(src); } =20 - return migrate_folio(mapping, dst, src, mode); + return migrate_folio(mapping, dst, src, ctl); } #endif =20 diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index fd2c7115c054..e4476596c9b6 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -277,9 +277,11 @@ int block_truncate_page(struct address_space *, loff_t= , get_block_t *); =20 #ifdef CONFIG_MIGRATION extern int buffer_migrate_folio(struct address_space *, - struct folio *dst, struct folio *src, enum migrate_mode); + struct folio *dst, struct folio *src, + const struct migrate_control *); extern int buffer_migrate_folio_norefs(struct address_space *, - struct folio *dst, struct folio *src, enum migrate_mode); + struct folio *dst, struct folio *src, + const struct migrate_control *); #else #define buffer_migrate_folio NULL #define buffer_migrate_folio_norefs NULL diff --git a/include/linux/fs.h b/include/linux/fs.h index f9d1e05e8ae6..93ba6054c478 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -423,11 +423,11 @@ struct address_space_operations { void (*free_folio)(struct folio *folio); ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter); /* - * migrate the contents of a folio to the specified target. If - * migrate_mode is MIGRATE_ASYNC, it must not block. + * Migrate the contents of a folio to the specified target. The + * callback must not block when ctl->mode is MIGRATE_ASYNC. */ int (*migrate_folio)(struct address_space *, struct folio *dst, - struct folio *src, enum migrate_mode); + struct folio *src, const struct migrate_control *ctl); int (*launder_folio)(struct folio *); bool (*is_partially_uptodate) (struct folio *, size_t from, size_t count); diff --git a/include/linux/migrate.h b/include/linux/migrate.h index cec5713944e3..123111e7abd3 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -55,7 +55,7 @@ extern const char *migrate_reason_names[MR_TYPES]; =20 void putback_movable_pages(struct list_head *l); int migrate_folio(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode); + struct folio *src, const struct migrate_control *ctl); int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free, unsigned long private, const struct migrate_control *ctl, unsigned int *ret_succeeded); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 0adfa6605653..455d57307f88 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1327,7 +1327,7 @@ bool noop_dirty_folio(struct address_space *mapping, = struct folio *folio); =20 #ifdef CONFIG_MIGRATION int filemap_migrate_folio(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode); + struct folio *src, const struct migrate_control *ctl); #else #define filemap_migrate_folio NULL #endif diff --git a/mm/migrate.c b/mm/migrate.c index 549f8b57092c..731836664a86 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -869,7 +869,7 @@ EXPORT_SYMBOL(folio_migrate_flags); =20 static int __migrate_folio(struct address_space *mapping, struct folio *ds= t, struct folio *src, void *src_private, - enum migrate_mode mode) + const struct migrate_control *ctl) { int rc, expected_count =3D folio_expected_ref_count(src) + 1; =20 @@ -897,7 +897,7 @@ static int __migrate_folio(struct address_space *mappin= g, struct folio *dst, * @mapping: The address_space containing the folio. * @dst: The folio to migrate the data to. * @src: The folio containing the current data. - * @mode: How to migrate the folio. + * @ctl: Migration policy for this folio. * * Common logic to directly migrate a single LRU folio suitable for * folios that do not have private data. @@ -905,10 +905,10 @@ static int __migrate_folio(struct address_space *mapp= ing, struct folio *dst, * Folios are locked upon entry and exit. */ int migrate_folio(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode) + struct folio *src, const struct migrate_control *ctl) { BUG_ON(folio_test_writeback(src)); /* Writeback must be complete */ - return __migrate_folio(mapping, dst, src, NULL, mode); + return __migrate_folio(mapping, dst, src, NULL, ctl); } EXPORT_SYMBOL(migrate_folio); =20 @@ -947,8 +947,8 @@ static bool buffer_migrate_lock_buffers(struct buffer_h= ead *head, } =20 static int __buffer_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode, - bool check_refs) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl, bool check_refs) { struct buffer_head *bh, *head; int rc; @@ -956,14 +956,14 @@ static int __buffer_migrate_folio(struct address_spac= e *mapping, =20 head =3D folio_buffers(src); if (!head) - return migrate_folio(mapping, dst, src, mode); + return migrate_folio(mapping, dst, src, ctl); =20 /* Check whether page does not have extra refs before we do more work */ expected_count =3D folio_expected_ref_count(src) + 1; if (folio_ref_count(src) !=3D expected_count) return -EAGAIN; =20 - if (!buffer_migrate_lock_buffers(head, mode)) + if (!buffer_migrate_lock_buffers(head, ctl->mode)) return -EAGAIN; =20 if (check_refs) { @@ -995,7 +995,7 @@ static int __buffer_migrate_folio(struct address_space = *mapping, } } =20 - rc =3D filemap_migrate_folio(mapping, dst, src, mode); + rc =3D filemap_migrate_folio(mapping, dst, src, ctl); if (rc) goto unlock_buffers; =20 @@ -1022,7 +1022,7 @@ static int __buffer_migrate_folio(struct address_spac= e *mapping, * @mapping: The address space containing @src. * @dst: The folio to migrate to. * @src: The folio to migrate from. - * @mode: How to migrate the folio. + * @ctl: Migration policy for this folio. * * This function can only be used if the underlying filesystem guarantees * that no other references to @src exist. For example attached buffer @@ -1033,9 +1033,10 @@ static int __buffer_migrate_folio(struct address_spa= ce *mapping, * Return: 0 on success or a negative errno on failure. */ int buffer_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { - return __buffer_migrate_folio(mapping, dst, src, mode, false); + return __buffer_migrate_folio(mapping, dst, src, ctl, false); } EXPORT_SYMBOL(buffer_migrate_folio); =20 @@ -1044,7 +1045,7 @@ EXPORT_SYMBOL(buffer_migrate_folio); * @mapping: The address space containing @src. * @dst: The folio to migrate to. * @src: The folio to migrate from. - * @mode: How to migrate the folio. + * @ctl: Migration policy for this folio. * * Like buffer_migrate_folio() except that this variant is more careful * and checks that there are also no buffer head references. This function @@ -1054,17 +1055,19 @@ EXPORT_SYMBOL(buffer_migrate_folio); * Return: 0 on success or a negative errno on failure. */ int buffer_migrate_folio_norefs(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { - return __buffer_migrate_folio(mapping, dst, src, mode, true); + return __buffer_migrate_folio(mapping, dst, src, ctl, true); } EXPORT_SYMBOL_GPL(buffer_migrate_folio_norefs); #endif /* CONFIG_BUFFER_HEAD */ =20 int filemap_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { - return __migrate_folio(mapping, dst, src, folio_get_private(src), mode); + return __migrate_folio(mapping, dst, src, folio_get_private(src), ctl); } EXPORT_SYMBOL_GPL(filemap_migrate_folio); =20 @@ -1072,7 +1075,8 @@ EXPORT_SYMBOL_GPL(filemap_migrate_folio); * Default handling if a filesystem does not provide a migration function. */ static int fallback_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { WARN_ONCE(mapping->a_ops->writepages, "%ps does not implement migrate_folio\n", @@ -1085,9 +1089,9 @@ static int fallback_migrate_folio(struct address_spac= e *mapping, * can't migrate automatically. */ if (!filemap_release_folio(src, GFP_KERNEL)) - return mode =3D=3D MIGRATE_SYNC ? -EAGAIN : -EBUSY; + return ctl->mode =3D=3D MIGRATE_SYNC ? -EAGAIN : -EBUSY; =20 - return migrate_folio(mapping, dst, src, mode); + return migrate_folio(mapping, dst, src, ctl); } =20 /* @@ -1112,7 +1116,7 @@ static int move_to_new_folio(struct folio *dst, struc= t folio *src, VM_BUG_ON_FOLIO(!folio_test_locked(dst), dst); =20 if (!mapping) - rc =3D migrate_folio(mapping, dst, src, ctl->mode); + rc =3D migrate_folio(mapping, dst, src, ctl); else if (mapping_inaccessible(mapping)) rc =3D -EOPNOTSUPP; else if (mapping->a_ops->migrate_folio) @@ -1123,9 +1127,9 @@ static int move_to_new_folio(struct folio *dst, struc= t folio *src, * migrate_folio callback. This is the most common path * for page migration. */ - rc =3D mapping->a_ops->migrate_folio(mapping, dst, src, ctl->mode); + rc =3D mapping->a_ops->migrate_folio(mapping, dst, src, ctl); else - rc =3D fallback_migrate_folio(mapping, dst, src, ctl->mode); + rc =3D fallback_migrate_folio(mapping, dst, src, ctl); =20 if (!rc) { /* diff --git a/mm/secretmem.c b/mm/secretmem.c index d29865075b6e..5c81833981d2 100644 --- a/mm/secretmem.c +++ b/mm/secretmem.c @@ -144,7 +144,8 @@ static const struct file_operations secretmem_fops =3D { }; =20 static int secretmem_migrate_folio(struct address_space *mapping, - struct folio *dst, struct folio *src, enum migrate_mode mode) + struct folio *dst, struct folio *src, + const struct migrate_control *ctl) { return -EBUSY; } diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 625e62e1a031..0a9af8c4768d 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -457,7 +457,7 @@ static struct file_operations kvm_gmem_fops =3D { =20 static int kvm_gmem_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, - enum migrate_mode mode) + const struct migrate_control *ctl) { WARN_ON_ONCE(1); return -EINVAL; --=20 2.43.0