From nobody Fri Dec 19 15:01:59 2025 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013060.outbound.protection.outlook.com [40.93.201.60]) (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 53DB6238176 for ; Sat, 6 Dec 2025 10:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765016153; cv=fail; b=jHx4UKj6lYef/DfwuFS3VeXcGbWX/PtZtDzXpNmxGoLfzZsBzGWCcpVSIYFCpIjp2qBSdl8O8ZEoi+VSL8WEWXq7P2zFe2seSQ1CzVCCP78+qD1EPRc913DfQjm1nbcfLMh0Q0IBC4c0Hwq3+Omk+aDgpwz74Kv2Eq24g1Dn5IE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765016153; c=relaxed/simple; bh=ZJE/poBMu5qBUizqUb8y8zkcB3W3GExzHro4heNtxp8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K4KY//Vq8RrmHFCQt64wLI9uz2RLnOax6BV0x8+Ux17PwYn65nF/izAsdgJxoJec2m5hf88OVOkUtcBtJ+6UwlTFIQRvsH0SlxO2/0FVx1lEoHkM9ur+XwOqQZqIsasWLgkblvDpEA2Q3jSk04iu67xAgpGIO9pEGWgM7/upQf0= 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=tV6HrGwH; arc=fail smtp.client-ip=40.93.201.60 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="tV6HrGwH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Sn6L6D7Xm98jWPVaTdcFeJRnFQSWWI32PJ9PFg4nLOFxTi2ezJ/nIjIbQVfIqj1hBhOTPc+UD+qe0brCwUFQRjZPoQMmMxtE7XRsvM+BcEKMpjEvaj0ehA6qcdknfKRPzEYjujw9W20j7s4MRzO6I0MpGA3JOj8ax99CaFF0IdO4qGhPgWcqt0TNTNhowKP674hmwBAK80brYwel2h0PfgtCKh2O+xCWm3uaxsbGWRatIUQeezljujj0ZXlteJm2VVWqEP8FBaknfUQlzbj28F0Hq+A98OBLs/e/sXkg9T3N4uCHtcZbAclK9bH2VXo01SU3/j0cU0ZBAUHm/sMtDg== 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=APJ2OXax1hQPassOHE0tcpLEA8Zqjjba4D4+g0pB+l4=; b=TtPKVCRs0WTJV5BVBPiAuWscFsoUAJvxPX2uwv1YorlOL5nLQhKUI1+5COFS6kvkiwbl34HqPNovRuGYmieIj2g1RG/+/0AucGrGxcXg+piCfKif9LTvZi9ONIVuv8qMWO8F41+3mxCECt1NFMr+/PYykMeJJM0J4Sd/4EuxuYoU0eUx8aorSAoZXXEshPsnL3im02Ufqkb7b8v4+IYPIfqbAvmDgj0zpUd9A4UhMSmZMG6iriLn0xReNsHrNeY2SA/+ZnAdQxxxw8gY8WKMMEwKEd518xIDzbMdybFMUndVhwLqo/qu8qCn/XNRrEBzlQPECMyOPsr1Qj03DnISUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=APJ2OXax1hQPassOHE0tcpLEA8Zqjjba4D4+g0pB+l4=; b=tV6HrGwHo8O1HKSC+C6dLukZ91K4nMTt0j8mDF5MFsYTvwTg1lzggi+o6TE4Wav4nBEjHez05Wlx3+J64EXOtrGRJNOSCkN8ACYwmSGQOjFZwcBU79FzCitVJEIC49S+pLP1elYeC+RT8B3Vkb99/cJwHx/q5XyZsyK9nFuwuxQ= Received: from CY8P220CA0014.NAMP220.PROD.OUTLOOK.COM (2603:10b6:930:46::25) by MW4PR12MB6976.namprd12.prod.outlook.com (2603:10b6:303:20a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.17; Sat, 6 Dec 2025 10:15:49 +0000 Received: from CY4PEPF0000EE33.namprd05.prod.outlook.com (2603:10b6:930:46:cafe::eb) by CY8P220CA0014.outlook.office365.com (2603:10b6:930:46::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9388.13 via Frontend Transport; Sat, 6 Dec 2025 10:15:45 +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 CY4PEPF0000EE33.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9412.4 via Frontend Transport; Sat, 6 Dec 2025 10:15:48 +0000 Received: from BLR-L-BHARARAO.amd.com (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.17; Sat, 6 Dec 2025 04:15:41 -0600 From: Bharata B Rao To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Bharata B Rao Subject: [RFC PATCH v4 2/9] migrate: implement migrate_misplaced_folios_batch Date: Sat, 6 Dec 2025 15:44:16 +0530 Message-ID: <20251206101423.5004-3-bharata@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251206101423.5004-1-bharata@amd.com> References: <20251206101423.5004-1-bharata@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CY4PEPF0000EE33:EE_|MW4PR12MB6976:EE_ X-MS-Office365-Filtering-Correlation-Id: a27b8b1e-c0a9-435c-1eb9-08de34b06d6a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?h9MXT82cnYWeN7sve2GDoxga+QXZelZ7XpIQTrLf+Wjkwmlfu8g+V9LCOgHR?= =?us-ascii?Q?6a8ikfbOnvDjpCQsJXFoAOLe3pY8Gq8PM6QLh8uO7G1F8u4nayPKnKZXTGMN?= =?us-ascii?Q?0BBv1aGyAYgHwZg8rQ6Jjt/j8jpZdozHmsAhph3eKo+PZVeBg3hIe4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j8cLMq1vUcQDDjUaoo2j+zvHkR3sUdLmtfmAOuZwl37hhP?= =?us-ascii?Q?5OXwBe++eiGcoabI2UygjxW9Z2NKukw19kk2ru+p5MROhT+JI264NOylyNuV?= =?us-ascii?Q?7tdivn+/XJUHDkwsiFvz9cL4EC6GHXGUooIt0fFdRxpuywjYzUP+rHFfRw4q?= =?us-ascii?Q?Hm93rLSxDhwWrWWcgurdi6kNb33DDf/kC64usv03EeiUkCc/6DEJSgULZr2C?= =?us-ascii?Q?ArzrsA+7qURKGTQGFm2C5B0w/Rm3Oa9ZgPZdwDSuTRjwEMpAs0zdzde1vi8u?= =?us-ascii?Q?7yAeCFsYF8dQq0k4d7jVA6oPH4EXQQaDxs0PVMAWG4AQXkN4qL4h3pgAzX1r?= =?us-ascii?Q?P2BHvz69M2TYa+mPHDhv0AYkOY7chW+nDl8u7CaG+BQYqjL08+EIuKqd/eOu?= =?us-ascii?Q?8BjQqQwfZaxaTj+ltrfKl2OdcbGOuGkjzWAN9Ja7NwRw6BcrGw/0kUqFIeWF?= =?us-ascii?Q?P7QnahAsjwDKbeZSaJ+Fd6NBrvUxV0UvY5uX0QIpHbooygSKX1bBPhTCJsqy?= =?us-ascii?Q?myBa3BLvmfSY7NKBbJU=3D?= 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)(7416014)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2025 10:15:48.6880 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a27b8b1e-c0a9-435c-1eb9-08de34b06d6a 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: CY4PEPF0000EE33.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6976 Content-Type: text/plain; charset="utf-8" From: Gregory Price Tiered memory systems often require migrating multiple folios at once. Currently, migrate_misplaced_folio() handles only one folio per call, which is inefficient for batch operations. This patch introduces migrate_misplaced_folios_batch(), a batch variant that leverages migrate_pages() internally for improved performance. The caller must isolate folios beforehand using migrate_misplaced_folio_prepare(). On return, the folio list will be empty regardless of success or failure. Signed-off-by: Gregory Price [Rewrote commit description] Signed-off-by: Bharata B Rao --- include/linux/migrate.h | 6 ++++++ mm/migrate.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 1f0ac122c3bf..2ace66772c16 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -103,6 +103,7 @@ static inline int set_movable_ops(const struct movable_= operations *ops, enum pag int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node); int migrate_misplaced_folio(struct folio *folio, int node); +int migrate_misplaced_folios_batch(struct list_head *foliolist, int node); #else static inline int migrate_misplaced_folio_prepare(struct folio *folio, struct vm_area_struct *vma, int node) @@ -113,6 +114,11 @@ static inline int migrate_misplaced_folio(struct folio= *folio, int node) { return -EAGAIN; /* can't migrate now */ } +static inline int migrate_misplaced_folios_batch(struct list_head *folioli= st, + int node) +{ + return -EAGAIN; /* can't migrate now */ +} #endif /* CONFIG_NUMA_BALANCING */ =20 #ifdef CONFIG_MIGRATION diff --git a/mm/migrate.c b/mm/migrate.c index 189d0548d4ce..2bf756123d55 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2739,5 +2739,41 @@ int migrate_misplaced_folio(struct folio *folio, int= node) BUG_ON(!list_empty(&migratepages)); return nr_remaining ? -EAGAIN : 0; } + +/** + * migrate_misplaced_folios_batch - Batch variant of migrate_misplaced_fol= io. + * Attempts to migrate a folio list to the specified destination. + * @folio_list - Isolated list of folios to be batch-migrated. + * @node - The NUMA node ID to where the folios should be migrated. + * + * Caller is expected to have isolated the folios by calling + * migrate_misplaced_folio_prepare(), which will result in an + * elevated reference count on the folio. + * + * This function will un-isolate the folios, dereference them, and + * remove them from the list before returning. + * + * Return: 0 on success and -EAGAIN on failure or partial migration. + * On return, @folio_list will be empty regardless of success/fail= ure. + */ +int migrate_misplaced_folios_batch(struct list_head *folio_list, int node) +{ + pg_data_t *pgdat =3D NODE_DATA(node); + unsigned int nr_succeeded; + int nr_remaining; + + nr_remaining =3D migrate_pages(folio_list, alloc_misplaced_dst_folio, + NULL, node, MIGRATE_ASYNC, + MR_NUMA_MISPLACED, &nr_succeeded); + if (nr_remaining) + putback_movable_pages(folio_list); + + if (nr_succeeded) { + count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded); + mod_node_page_state(pgdat, PGPROMOTE_SUCCESS, nr_succeeded); + } + BUG_ON(!list_empty(folio_list)); + return nr_remaining ? -EAGAIN : 0; +} #endif /* CONFIG_NUMA_BALANCING */ #endif /* CONFIG_NUMA */ --=20 2.34.1