From nobody Tue Jul 7 22:59:11 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011055.outbound.protection.outlook.com [40.93.194.55]) (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 5647939B96A for ; Tue, 30 Jun 2026 07:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804558; cv=fail; b=g8ROt0BjQ4yaU24CoP9TB0WFJgylyayCH80FkTDffPiXp3J4VnP4ZkFDxOMVPs7V0iQh5/YGFYCrO8dMdDsCY5SuqfjNcoFc+0y2SusGR/jTZzNeEYWUPdhR7ZvCC5rtSuAtnaO0jRKk8XRGQWlB3Pt8rFEdgnWkT2RZtBjJXfc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804558; c=relaxed/simple; bh=1Kn4lFOmGuKFQBugICRVZHnjWPKJ+aEEJ9AyyNX9T1M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=X8itFI07lHMoHDWM9iBJN9lu8UV52lP1B0z+Ye6P/5rSOGuP4HaJBYB9FKmxGfHr4RGybWfi+VMJFxK3G5TJqr1VMBkWJ43tGlTSdRTnSC/YvLreYfvg9GRM36WxHmiToJBLypiGEvlPQjo0BPzkcgd67FNYtW7KSyXsNz7vGx8= 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=OG0nyvf4; arc=fail smtp.client-ip=40.93.194.55 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="OG0nyvf4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P6aRy7/UZK7Jgn+QQZLec3FRpQ3s6enn26aAc13K5FX32hOVEytQx01cjU1LyGHWqujabp/l9wuI5JrSovVGV5gSYshm6SF2p/GzsqgknyB4BxDviLjNCOdsYt/dcAiewT4+Cgm80rZCwyPycoyNYDf4Arx1cQ9iknyOUMgGTPhR1x8foS86jDxZzC2MngjUj1nE5jOt+PSeVY9n3Q8RInpihMDve13Myzpq07p5a60Y+dLFfa3ecl59TV1bQTOgW0YIY27FNAc4nAFBfGL27F6l6UMIAXuOq76p6nEzR2UPRGo5Wi0qQo6Qai7rAhpp4N+/c+0jcaxEO87JBwlGUA== 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=HX3jhuNNy4i94tZMziuRlhLEz3C2r+Pm/L1TBQr02do=; b=FYMSW9IWsGtRNaTOCWiJ4tpQFPpo0inDTRbuQ+lCbcjBG9BrAlQ8V8DMhZKyPoYQlb9bwv608dhapR9lCxIhEEWoLhIyfCc7yh4s/WkP9Djxh7Mg+BYTc1BU8v5lejY/aXLgI8BhkfvxLmYJfQC2p/AH6TzsPIwisSkFBVSJevjC6+JoLYqYjMAHop7Fi//DiUz64dPMYofLYiCeMqzYOUts7etHQ3oepabtMuAI0I54yb7uqod1m1oiwg3g8f7t0cJrClJBTidOUgX6qG3E/cddus5VHOyadLxetyrI/ZgEmQ0cDOzWTNT+6vhlvFknyoMtN1nLBakTPKqBwQCA/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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=HX3jhuNNy4i94tZMziuRlhLEz3C2r+Pm/L1TBQr02do=; b=OG0nyvf4RX9RZ69KxsoxqQZBvgNlu4cK5+z7KN4eXpBk02AJQdGXZkXIl/j9rVarHk4DXtRhSQdnxiHZ6RMiYsdYSLgSiVUP2sihfmyAeknQukHWvkBKArrMNEA7QhZzoEN3IYOf39k+zROmPS2PmZLSIP4nJMiwlVE0bOs9zEo= Received: from BL1PR13CA0366.namprd13.prod.outlook.com (2603:10b6:208:2c0::11) by SN7PR12MB7882.namprd12.prod.outlook.com (2603:10b6:806:348::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Tue, 30 Jun 2026 07:29:08 +0000 Received: from MN1PEPF0000F0E0.namprd04.prod.outlook.com (2603:10b6:208:2c0:cafe::2d) by BL1PR13CA0366.outlook.office365.com (2603:10b6:208:2c0::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.8 via Frontend Transport; Tue, 30 Jun 2026 07:29:08 +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 MN1PEPF0000F0E0.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Tue, 30 Jun 2026 07:29:07 +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.41; Tue, 30 Jun 2026 02:28:57 -0500 From: Shivank Garg Date: Tue, 30 Jun 2026 07:28:37 +0000 Subject: [PATCH RFC v6 1/5] mm/migrate: skip data copy for already-copied 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: <20260630-shivank-batch-migrate-offload-v6-1-da95d7e8b8a2@amd.com> References: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> In-Reply-To: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , "Mike Rapoport" , Suren Baghdasaryan , "Michal Hocko" CC: Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , "Yiannis Nikolakopoulos" , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , Aneesh Kumar K.V , Nathan Lynch , Frank Li , Dan Williams , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782804526; l=4281; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=1Kn4lFOmGuKFQBugICRVZHnjWPKJ+aEEJ9AyyNX9T1M=; b=0efkU7z0y7I+aroe5np4YuomuMXS0bdZ3szPiheII6t3tuPF14kU6JOuNgxp/8HTt4dN/09mn NnseAf5B2sxA7xG6IEGz0niXKmrQ1TxReYfpPctwQW5N/MuvynDP+gO X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E0:EE_|SN7PR12MB7882:EE_ X-MS-Office365-Filtering-Correlation-Id: c3e15687-8c82-492c-fbd1-08ded6794597 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|23010399003|36860700016|376014|7416014|1800799024|921020|22082099003|18002099003|3023799007|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: PAx2dlGKEi5VDTfulhDUifGzgtXjxkulaInRDeYoqRw2+KjAaI9MfG+VrMvvtG6pnDS+q54YCr43mqXU0ol098lCHot6Lhoul3dmGE97LyvrD3jBHy2Xny3yhTapT/ZfM7BzfwiT05s4uN63l39MHFcOvJeaqv3UqEBukwESU4/biAxxhJeKQriXlC3IYKTEyXsWXxRQBww3NsDdr+abKAsZcSGt//KNRdRswhPfdulefF/wPOIfr6FmkE9sVHwAJsA0fVEfLGnJW1qynjNzXSoX4xYbUgfR2uZDvfPIB3Frcz6sRqdx2axN140oWZKQPZMxkBzrzy/cOoiw0M8N2v88VaP2sQ05OBgytKu9kFqDPRPkm4tBZzoS4d1rKx6O/9vNCoiyIVHj22S8Bdui0lFgGlOHbPcv16HQmgeabC2oCpFfhe7pLnSnfnQc7jJtM+FDGAlzVLPS7C578+1EyfJ19ZnV/6hrkDnB3ABXGQukNaiQK7VChThHDhdX3zqqEBdPfhEVPXmiYEqlwiOGrk+YiwFAwmJoKIXpvSKckyojm1p6Pqbbj6hsHSlxx0zEdsOObzF7qB5EF3iz7ZddzKOHRFrio8wUkHr7EeFrC3GkO88YTC5QzZi0DkjDXiOq/ibUcverNTOqyHvwfeqWai0NtLN5AeoGHdtN9W+2BF9TPC+KdwrPdhg8JhINqrm/YWqQU3K32lnyqeLfEyB73ODfpiy2ZfegKLoocBO+NCIlnIP6Uoun4Qo8FiSSBzn/ 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)(376014)(7416014)(1800799024)(921020)(22082099003)(18002099003)(3023799007)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wWaL0SEWUpsJR7VqUIH+w4fyzxNkyvCPhMlWEVYP2KSSL1KOcFU29izSPcXcXYKJ934n0iIAGe7I8Fgd1ZJQ1/o22SWfp9dAevODuD5DOVlWbTD3OHqMJI4nhs9nlDaY3lFcJTkZTa1tYUc1J7jYaGQ60chNQCJ2RGkGblZ76wzO3yr0jq/7+fqXNMFtUMn5GAFzLTPPAiR9tBvH7NCcF/adNfe9JB05jUE3XQB5NhFJk8Jg3BGBPtNzqYPm3an3AbKpjynFRV9aQTQeIeJ+mAbp2Ythb/wgy/bB0L+c/tpW42rECKq7ws3mWMkCgJkZkWTeESK27tbzJy5BVZDWTQLpz7CYE2gaGXs1I9tT3StsNf8/W+4P82S+PfI5xcu7dU6aHzXtgnJV2VcxIxpFZPiU3PLuJ0tMHMgk/ydkm16KO7O5YDO1x4DTzPLQ6WlH X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 07:29:07.9730 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3e15687-8c82-492c-fbd1-08ded6794597 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: MN1PEPF0000F0E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7882 Add FOLIO_CONTENT_COPIED marker to the dst->migrate_info migration state. When set, it tells __migrate_folio() to skip folio_mc_copy() and perform metadata-only migration. This bit is not set yet, the batch-copy path enables it later in a subsequent patch. Update __migrate_folio_extract() to preserve FOLIO_CONTENT_COPIED while it consumes old states of src folio. Move the dst->migrate_info state enum to migrate.h header file so offload drivers can see FOLIO_CONTENT_COPIED. On 32Bit, we do not have spare bit to store FOLIO_CONTENT_COPIED info, migration copy offload is disabled for them. Signed-off-by: Shivank Garg --- include/linux/migrate.h | 25 +++++++++++++++++++++++++ mm/migrate.c | 29 +++++++++++++---------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index d5af2b7f577b..876035df2fdc 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -72,6 +72,31 @@ int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int extra_count); int set_movable_ops(const struct movable_operations *ops, enum pagetype ty= pe); =20 +/* + * To record some information during migration, we use the migrate_info + * field of struct folio of the newly allocated destination folio, + * together with the anon_vma pointer. The state is encoded in the + * unused low bits of the pointer. + * This is safe because nobody is using it except us. + * + * FOLIO_WAS_MAPPED and FOLIO_WAS_MLOCKED record the src folios's state + * at unmap time and are consumed during the move/undo phase. + * FOLIO_CONTENT_COPIED tells __migrate_folio() that the folio contents + * have already been copied, so the per-folio copy can be skipped. A + * driver must set this bit on each dst folio it copied. + */ +enum { + FOLIO_WAS_MAPPED =3D BIT(0), + FOLIO_WAS_MLOCKED =3D BIT(1), + FOLIO_OLD_STATES =3D FOLIO_WAS_MAPPED | FOLIO_WAS_MLOCKED, +#ifdef CONFIG_64BIT + FOLIO_CONTENT_COPIED =3D BIT(2), +#else + /* On 32bit we do not have a spare bit, migration-copy offload is disable= d. */ + FOLIO_CONTENT_COPIED =3D 0, +#endif +}; + #else =20 static inline void putback_movable_pages(struct list_head *l) {} diff --git a/mm/migrate.c b/mm/migrate.c index 7a83032a14b5..b3f632575c82 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -859,14 +859,21 @@ static int __migrate_folio(struct address_space *mapp= ing, struct folio *dst, enum migrate_mode mode) { int rc, expected_count =3D folio_expected_ref_count(src) + 1; + const bool already_copied =3D dst->migrate_info & FOLIO_CONTENT_COPIED; + + /* Consume the content copied marker */ + if (already_copied) + dst->migrate_info &=3D ~FOLIO_CONTENT_COPIED; =20 /* Check whether src does not have extra refs before we do more work */ if (folio_ref_count(src) !=3D expected_count) return -EAGAIN; =20 - rc =3D folio_mc_copy(dst, src); - if (unlikely(rc)) - return rc; + if (!already_copied) { + rc =3D folio_mc_copy(dst, src); + if (unlikely(rc)) + return rc; + } =20 rc =3D __folio_migrate_mapping(mapping, dst, src, expected_count); if (rc) @@ -1129,17 +1136,6 @@ static int move_to_new_folio(struct folio *dst, stru= ct folio *src, return rc; } =20 -/* - * To record some information during migration, we use the migrate_info - * field of struct folio of the newly allocated destination folio. - * This is safe because nobody is using it except us. - */ -enum { - FOLIO_WAS_MAPPED =3D BIT(0), - FOLIO_WAS_MLOCKED =3D BIT(1), - FOLIO_OLD_STATES =3D FOLIO_WAS_MAPPED | FOLIO_WAS_MLOCKED, -}; - static void __migrate_folio_record(struct folio *dst, int old_folio_state, struct anon_vma *anon_vma) { @@ -1151,9 +1147,10 @@ static void __migrate_folio_extract(struct folio *ds= t, { unsigned long info =3D dst->migrate_info; =20 - *anon_vmap =3D (struct anon_vma *)(info & ~FOLIO_OLD_STATES); + *anon_vmap =3D (struct anon_vma *)(info & ~(FOLIO_OLD_STATES | + FOLIO_CONTENT_COPIED)); *old_folio_state =3D info & FOLIO_OLD_STATES; - dst->migrate_info =3D 0; + dst->migrate_info &=3D FOLIO_CONTENT_COPIED; } =20 /* Restore the source folio to the original state upon failure */ --=20 2.43.0 From nobody Tue Jul 7 22:59:11 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012031.outbound.protection.outlook.com [40.93.195.31]) (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 010AE39E175 for ; Tue, 30 Jun 2026 07:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.31 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804565; cv=fail; b=TcoLusJaohqJ4SuIL8W3Rleu1u+Cq6s5tU4qmUwHV4ebr/BJ5iuTav1pUUBXEB4BLWsBVpteGFfJ4t0ZgmygJPK6gZQn/XagmumXT/s5STxfIXxqN8mpgXFxtLIAfADldZrMLby1COCEVuLXkykX21D3hbjt/FgsAZ4MS6zY3uc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804565; c=relaxed/simple; bh=8C7g10RFPyzYzAfUxPcrNVYkvx5/MEoSLQXRbVB3Soc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=AhSnenBgtBBFZXH2+kozMAYxXrvOc0Oe50/y8qjhFYOKGaHTdJBHyh9m5vq5cjDE5DR8dNKaqtxXZWfpwWmi+lrsd9hJcc01zewuyYjBQwgoecvazY8xGo659fzV7jvsaOtCW8l9LVlSs7dC8fa91mh2L3nuWwtvNPuCR+BNoKo= 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=IZkIKJcn; arc=fail smtp.client-ip=40.93.195.31 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="IZkIKJcn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P5+LHHuRJF6k6uiJU6aP8kLmd1hPVE/YencHQfgPAnh0w5B4NaFSrT3/vHs/6dmatjmdIXhXh9wYmYW7i4KShmRpYiQaUbJSSbj4WSjh1eLVYUubzcjR/+9TsXEYShZvg9S20B97qV2dBn1bYnzuXjUYuQEyCssRLA3l607zfvf1ASXI1dnS9i5q2xNxEBv0PXD9YoIfbMN7bvhFeAUwvs22acAFxF+KlApIgRoYdEsB6F5KW7qQb5AH6yuJ/NQoreoof0/Kif6Z0FbDLD88AU8HtgJhFKasGq4ZGGR7ORwr+LoIYzS3dvT0NW6BBPsz4vKD5M5dfR+wEVRdSuVFXw== 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=qOzxY0YymOrNOLIyUo3fX7VnGjAr9WEUGQwF1rsBSaA=; b=W10Ke4/3t98RNqBxBwQmxoaMG6aJf8psI+Sl0tXOhWxFQuVMuBssFXoWMbgCQNMxiWT5EbMN/DsFOoTyNV+PHX1+diLJ9gEZaicBsIpars32bNpp6s6gx6MCKtfgU+vdr0IlaY9dNbhowcdG9zdiWE6H73eHJXsh9i6HOv/W0YskMB2XHXQFdFiGpa/a3k0XgNG7JvKbYajgS+/1p84m0LOPN8N9xuiImzxRBoJdndfALjxElAsE5YNDeBYg6IKEFjQAt6A0ULt9fHr5gfjMtvE5sR+OL+c1Ae3SIhlrshrIYsHsFhepB5V1s7hF/qElilsHFCtF7eBKpCsO4ewu8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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=qOzxY0YymOrNOLIyUo3fX7VnGjAr9WEUGQwF1rsBSaA=; b=IZkIKJcn3ECLzH29fF/4mMnZ+haNdLYr2VazCEKiaSYY51sZ1gGi1ba8IVrBUFbwmnve4DB284fEJbT1J9bH84TwpnztK1TcjMri6+OglREwG9BWx5YEJimFaYZnxefR9VkRlldJ6Z7iJ3yR4iZk3UM+DOqjlxbVJIdz8z54Ynw= Received: from MN2PR15CA0045.namprd15.prod.outlook.com (2603:10b6:208:237::14) by DS0PR12MB7804.namprd12.prod.outlook.com (2603:10b6:8:142::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.8; Tue, 30 Jun 2026 07:29:18 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:237:cafe::a6) by MN2PR15CA0045.outlook.office365.com (2603:10b6:208:237::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.159.19 via Frontend Transport; Tue, 30 Jun 2026 07:29:18 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Tue, 30 Jun 2026 07:29:18 +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.41; Tue, 30 Jun 2026 02:29:07 -0500 From: Shivank Garg Date: Tue, 30 Jun 2026 07:28:38 +0000 Subject: [PATCH RFC v6 2/5] mm/migrate: add batch-copy path in migrate_pages_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: <20260630-shivank-batch-migrate-offload-v6-2-da95d7e8b8a2@amd.com> References: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> In-Reply-To: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , "Mike Rapoport" , Suren Baghdasaryan , "Michal Hocko" CC: Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , "Yiannis Nikolakopoulos" , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , Aneesh Kumar K.V , Nathan Lynch , Frank Li , Dan Williams , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782804526; l=7792; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=8C7g10RFPyzYzAfUxPcrNVYkvx5/MEoSLQXRbVB3Soc=; b=78QuvfZbFaApjYWZ4bqW9eN9T1Std1pZ5X+dmvGgzHNEJaHkbBvcjAdxO/2Er35RKPso2FJm7 49kUdpc/R2QCaSQTplNyJKh8AYB6DF3BLeq7aLzZE4LXPNJ8Pn8ebIf X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|DS0PR12MB7804:EE_ X-MS-Office365-Filtering-Correlation-Id: 47594dd5-fbe7-4453-71cc-08ded6794ba8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|82310400026|23010399003|376014|7416014|921020|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: Zl1sPqWxQt9lXm1Ne9CsNVYaFCfWyhblw9hk/j9mk0UvIm4DIrAJH8NznJEJESnPeUNTIn4da5MD+Uz21lTIZB9HVrmJ9K2vN7UIHeXKiqCR3woGdLPWdGv55wQvDgvwF0o+aq782lUseeCSifoPQE6EhAoqe0tpcO1Y5qWqgvqHyFSmg439Wk883XoIfXgu3jLCSFFbF9iUNAyQw0IkD1UJ/WHSnCwJxroVO7yyeCcttOSw2kxEz1DY22XRYHNdOb/dk5mzCYhD2pZgS3VqD8ri0Bu1HOERxhL4ML0Pn/AOgMLEZTBj4MuZhIRVoKBVaiaCB192GZHV6i1pnqVO5NZ4usty/hksfcn8fF5XePJL5VNeJUJQY0ZAQNSM329ly48AzYP7ZygJddtxMpKAys9Rl6UjFs3RqbmQkzMD4Wpg+wvKXXDr8wI/Mvj7545qoZ+bP/twVtgaAQ98ELqDRcMl8Td37qfMQ6siefQZM2LBPMTY8IpJVkSvfyyoarddBjANdE4ex7bnscsEJhjrzxnvz/tLRPPf43cz6H4RtCOzbCk/KMZspWr6LtToGBchWwr1OIcxvNhmk2LVIV43Db1cHxxrHXUgKT5EM6vyjhIcFSY6LqRFobWUk77eGp7q/8vh3FfpFm/MI9HNlR9kCTpUMrBGo0bIey9ZCo82puF+Ez9H9Bru0zwVboyCbwCinNUg8cKI3WWffETigYsAoC1EVmkUsBWemcmTcU9zB1Rs09Fjy1zMOd8vDCShp2TL 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)(1800799024)(82310400026)(23010399003)(376014)(7416014)(921020)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jp2ALsP5URr/SdTH4FUsV3mZte5nbOCBXiwVxlpzNrGITNyPJbhqr6SDV7BbGSLk9bn2YhnN0SF7pjgcPrkA1onhwEzzO5bux3hvF7reIwyDfiYQZu+TKUUPIlY6ZDG1v1G8I2B2KQa+Rif78RgLahWCJxz/yl4/4v/Mn6OpXykseABeFXXgimuQJiJm7CuIKXbBfXmwL62mrZpAYdGnyGnCdCdb3rtimDp2GciPCZWbHW/NvPWJNkSMZQtf9QyeXDzVpNoi3hlkxj5Xb+IJhVQWjp6u3V1Wd/krZZdnZHJPRhpqnip/GKFYVaoKdNLFvgmlWepS+axkhHd0bl91/ovAHe73io/OeODoha1pdVVTjX8Xy8RbElQuTci4fl2rq7ZeBjfaJPmRz+ead7RVok6QUiutc3FQRhUAcjYbPAsddC4oiygCkvIREhliaZpU X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 07:29:18.1487 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47594dd5-fbe7-4453-71cc-08ded6794ba8 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7804 Add migrate_folios_mc_copy() which walks src/dst folio lists in lockstep, copies folio content via folio_mc_copy() and marks the dst with FOLIO_CONTENT_COPIED so the move phase in __migrate_folio() can skip the per-folio copy. The folios_cnt parameter is unused here, present for the offload_copy callback signature compatibility used by later patches in the series. Split unmapped folios into batch-eligible (unmap_batch/dst_batch) and standard (unmap_single/dst_single) lists. A folio is batch-eligible when the migration reason is allowed by the driver, refcount equals expected and it's not a movable_ops page. After TLB flush, batch copy the eligible folios via migrate_folios_mc_copy(), then run the move phase. The FOLIO_CONTENT_COPIED marker is consumed on first read in the __migrate_folio, so a -EAGAIN retry falls back to fresh per-folio copy. Signed-off-by: Shivank Garg --- include/linux/migrate.h | 3 ++ mm/migrate.c | 107 ++++++++++++++++++++++++++++++++++++++++++--= ---- 2 files changed, 97 insertions(+), 13 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 876035df2fdc..e62c974b81d5 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -71,6 +71,9 @@ void folio_migrate_flags(struct folio *newfolio, struct f= olio *folio); int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int extra_count); int set_movable_ops(const struct movable_operations *ops, enum pagetype ty= pe); +int migrate_folios_mc_copy(struct list_head *dst_list, + struct list_head *src_list, + unsigned int __always_unused folios_cnt); =20 /* * To record some information during migration, we use the migrate_info diff --git a/mm/migrate.c b/mm/migrate.c index b3f632575c82..41b732e78a67 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -51,6 +51,12 @@ #include "internal.h" #include "swap.h" =20 +/* For now, never offload. Wired up in later patch. */ +static bool migrate_should_offload(int reason) +{ + return false; +} + static const struct movable_operations *offline_movable_ops; static const struct movable_operations *zsmalloc_movable_ops; =20 @@ -1707,6 +1713,60 @@ static int migrate_hugetlbs(struct list_head *from, = new_folio_t get_new_folio, return nr_failed; } =20 +static bool folio_can_batch_copy(struct folio *folio) +{ + /* movable_ops pages have a separate migration path */ + if (unlikely(page_has_movable_ops(&folio->page))) + return false; + + /* + * Only batch when refcount matches the expected refcount. + * Otherwise a GUP holder could modify src between the + * batch copy and the move-phase refcount check, leaving the + * dst folio with a stale copy. + */ + return folio_ref_count(folio) =3D=3D folio_expected_ref_count(folio) + 1; +} + +/** + * migrate_folios_mc_copy - Copy the contents of a list of folios. + * @dst_list: destination folio list. + * @src_list: source folio list. + * @folios_cnt: unused here, present for callback signature compatibility. + * + * Walk src and dst folio lists in lockstep, copy each folio via + * folio_mc_copy(), and mark the dst with FOLIO_CONTENT_COPIED so the + * move phase in __migrate_folio() skips the per-folio copy. The caller + * must ensure both lists have the same number of entries. + * + * On error, dst folios already copied keep their FOLIO_CONTENT_COPIED + * marker, while the remaining folios fallback to per-folio CPU copy in + * the move phase. + * + * This function may sleep. + * + * Return: 0 on success, negative errno on failure. + */ +int migrate_folios_mc_copy(struct list_head *dst_list, + struct list_head *src_list, + unsigned int __always_unused folios_cnt) +{ + struct folio *src, *dst; + int ret; + + dst =3D list_first_entry(dst_list, struct folio, lru); + list_for_each_entry(src, src_list, lru) { + ret =3D folio_mc_copy(dst, src); + if (ret) + return ret; + dst->migrate_info |=3D FOLIO_CONTENT_COPIED; + dst =3D list_next_entry(dst, lru); + cond_resched(); + } + + return 0; +} + static void migrate_folios_move(struct list_head *src_folios, struct list_head *dst_folios, free_folio_t put_new_folio, unsigned long private, @@ -1806,9 +1866,13 @@ static int migrate_pages_batch(struct list_head *fro= m, 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); + unsigned int nr_batch =3D 0; + LIST_HEAD(unmap_batch); + LIST_HEAD(dst_batch); + LIST_HEAD(unmap_single); + LIST_HEAD(dst_single); bool nosplit =3D (reason =3D=3D MR_NUMA_MISPLACED); + bool offload =3D migrate_should_offload(reason); =20 VM_WARN_ON_ONCE(mode !=3D MIGRATE_ASYNC && !list_empty(from) && !list_is_singular(from)); @@ -1902,8 +1966,8 @@ static int migrate_pages_batch(struct list_head *from, private, folio, &dst, mode, ret_folios); /* * The rules are: - * 0: folio will be put on unmap_folios list, - * dst folio put on dst_folios list + * 0: folio put on unmap_batch or unmap_single, + * dst folio put on dst_batch or dst_single * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * Other errno: put on ret_folios list @@ -1944,7 +2008,7 @@ static int migrate_pages_batch(struct list_head *from, /* nr_failed isn't updated for not used */ stats->nr_thp_failed +=3D thp_retry; rc_saved =3D rc; - if (list_empty(&unmap_folios)) + if (list_empty(&unmap_batch) && list_empty(&unmap_single)) goto out; else goto move; @@ -1954,8 +2018,14 @@ static int migrate_pages_batch(struct list_head *fro= m, nr_retry_pages +=3D nr_pages; break; case 0: - list_move_tail(&folio->lru, &unmap_folios); - list_add_tail(&dst->lru, &dst_folios); + if (offload && folio_can_batch_copy(folio)) { + list_move_tail(&folio->lru, &unmap_batch); + list_add_tail(&dst->lru, &dst_batch); + nr_batch++; + } else { + list_move_tail(&folio->lru, &unmap_single); + list_add_tail(&dst->lru, &dst_single); + } break; default: /* @@ -1978,17 +2048,26 @@ static int migrate_pages_batch(struct list_head *fr= om, /* Flush TLBs for all unmapped folios */ try_to_unmap_flush(); =20 + /* Batch-copy eligible folios before the move phase */ + if (!list_empty(&unmap_batch)) + migrate_folios_mc_copy(&dst_batch, &unmap_batch, nr_batch); + retry =3D 1; for (pass =3D 0; pass < nr_pass && retry; pass++) { retry =3D 0; thp_retry =3D 0; nr_retry_pages =3D 0; =20 - /* 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); + if (!list_empty(&unmap_batch)) + migrate_folios_move(&unmap_batch, &dst_batch, put_new_folio, + private, mode, reason, ret_folios, stats, + &retry, &thp_retry, &nr_failed, + &nr_retry_pages); + if (!list_empty(&unmap_single)) + migrate_folios_move(&unmap_single, &dst_single, 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; @@ -1997,7 +2076,9 @@ static int migrate_pages_batch(struct list_head *from, rc =3D rc_saved ? : nr_failed; out: /* Cleanup remaining folios */ - migrate_folios_undo(&unmap_folios, &dst_folios, + migrate_folios_undo(&unmap_batch, &dst_batch, + put_new_folio, private, ret_folios); + migrate_folios_undo(&unmap_single, &dst_single, put_new_folio, private, ret_folios); =20 return rc; --=20 2.43.0 From nobody Tue Jul 7 22:59:11 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010012.outbound.protection.outlook.com [52.101.201.12]) (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 417AE39B96A for ; Tue, 30 Jun 2026 07:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.12 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804578; cv=fail; b=dKlBkmTd18lpWkskNMH9TRl8G9T0lgqV1KBQ+kEM1bCu4a+g+lRGKALPZDdLjbHesRZqj48Vfnggo7FxxEhm/KXtLza70m1a5Ll6xPjaFqGcZLwmnP8klQsyvTcvc9InaPzFaBh3D7qd+HKRSd3i/dcrU9XYhEmSuUfZmsBzBAU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804578; c=relaxed/simple; bh=1+75rFp8P4TNy5kmh5orGDwqX1QofIKYgT85I2xSHkg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=GMFW4uM+GwwQ3reoOsHtKyLplF/T763TV470kjHeuBuoJX3YpYaxLmbP0odPcpUpQ3TESTAEw0ssjLUZZIVRcLKfBR1vr+wuS0OxxsFZT76rqFZWIANCQthdlH21RL/sDVJSHRdOb/Q55Jeov977ar81dlXQ64tuqR4fhnkN1GE= 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=PQWu0mrl; arc=fail smtp.client-ip=52.101.201.12 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="PQWu0mrl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LJNvn5RWGjDDy4ZfupMr1MQ4Ltida+v8g82FZWGAOWM3hlI531CJNbDCOZkQXXw/HpAmVpDPj5/UYlJl2DWkjKsELj2fIosvyOM6pODS++1RqRyn4AeE9NbA9eFE2hVDJfkwQHMJ7hr0DuHOR7LL/dQRpN/2iy8eCX35c8a5BmQ1Mfc8SzlKSZ5GJEJAuMwy906JMykGMwvLgQWyOV26HYPNCnDXWRPS26tq+CjcmAjsFvC9RACo/YbYfdbBIeypIf8boqDX09OJt9mAIJpv8bfyWTrvjUzU2mPKrRnU+R3gEq8dvfBnd/ceWdvXAEZN5fLq9/qOLWuiBG+ugKprrw== 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=XIHzBds/7rkPGaqG9Crad0Mqh7FjjnjzqNE9NlBsHz8=; b=PgQ5Zg4ds27U7vCANtiifqbmJS0kGllawpCdKf38U+Kkz5bCaEpzPgrVTLGG66wGs8+9ELrWoQN6ktQSqhpycJrZxTPWx9sfSFbr5rwameJG6pdHAKLOC0hrvWFimg21FvIAv7020j1XinYsF02R+Av98/jFIiM0ipJ8UjI7QzXBE/BU0yaGJgj+rKpXgQ+4by3FynNB+cRqf5ElBfDwgTwgAjIYOCv2YLJlouLf0TUON4DLJc4Z9eXYWYFCSzLGKpgsoSiuA3yep5hJpVvIwFVigeIihwcrXu7eeUhpyow336iMIgpMsimt6WfblJWqoOV6KeHlWVk6a/Heg/cjQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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=XIHzBds/7rkPGaqG9Crad0Mqh7FjjnjzqNE9NlBsHz8=; b=PQWu0mrlfTaaI7cMDs9AnH6GIDTVjwOGvuOfQ+RyIp2HaIXTep+YlJaU8JQ9jYPD9B4kLe4lnrGw1qnGAvf9cl9aKGkjK0LzVuS2ylPGYPNQXIJ8yJOApt5ILdJOXQg1TkNc2lKnDge0wbsKnDYPkOkvca1z6XbDnN4GNpiFttM= Received: from MN2PR15CA0044.namprd15.prod.outlook.com (2603:10b6:208:237::13) by LV2PR12MB5823.namprd12.prod.outlook.com (2603:10b6:408:178::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Tue, 30 Jun 2026 07:29:29 +0000 Received: from MN1PEPF0000F0E5.namprd04.prod.outlook.com (2603:10b6:208:237:cafe::32) by MN2PR15CA0044.outlook.office365.com (2603:10b6:208:237::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.159.19 via Frontend Transport; Tue, 30 Jun 2026 07:29:29 +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 MN1PEPF0000F0E5.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Tue, 30 Jun 2026 07:29:28 +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.41; Tue, 30 Jun 2026 02:29:18 -0500 From: Shivank Garg Date: Tue, 30 Jun 2026 07:28:39 +0000 Subject: [PATCH RFC v6 3/5] mm/migrate: add copy offload registration infrastructure 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: <20260630-shivank-batch-migrate-offload-v6-3-da95d7e8b8a2@amd.com> References: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> In-Reply-To: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , "Mike Rapoport" , Suren Baghdasaryan , "Michal Hocko" CC: Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , "Yiannis Nikolakopoulos" , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , Aneesh Kumar K.V , Nathan Lynch , Frank Li , Dan Williams , , , Shivank Garg , Mike Day X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782804526; l=14859; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=1+75rFp8P4TNy5kmh5orGDwqX1QofIKYgT85I2xSHkg=; b=awhGcIZCOYJgIr1vcOvaw0iZxCULyrYwAi0ulLd+vCxS5ufRydOFahzSMzThmfylBV/cyxr5b mxbU7oiYI8uBA4aUFtBTOldIJU0JSwggKh5Qjcp7aLaoPNDRnnsUu3J X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E5:EE_|LV2PR12MB5823:EE_ X-MS-Office365-Filtering-Correlation-Id: bfcf3357-b400-40d3-6557-08ded67951fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|7416014|376014|82310400026|1800799024|921020|18002099003|22082099003|11063799006|5023799004|56012099006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: S4tuANOgDtB6l3mKOeVmHvhtqGwMltCYoHLTa2ooOjVxhMdWVKdFroS7q1gxGUjFr74FltZtW//6oGhUldomvmuU3qkrrOil7Ke6F3FUcHYh9H2e9xlrR6/aBuF3G6clspEk0tMrOwQedC+bR8hP84MSbx4CJVIwNyPanE3g1jWze40bFCdKif0v1e43BoxHv2zSjd7/ILNJ9S/k8zxCcFZl9xBp7sehH4echADIxJP9icrn8dYyNab7F7naHTJ9tBxbBqItYg+UoO88PdotCteYM9Hn37dXfdYgSAkZ/1yszwfIz9AZYVpIWzZ9eCLmELFRDFnPVYE/QlqrnvHL1KW2KxY8aT4Kem/U/pkmzMexyfoOqXGXELDxYI7pusngM6IFcIMuysjDSJgohQnCCExzSfGJjWgDcfQHWDR7ScxT+gpq1kWaVjaiURELzUogmfW/JIG+Ya/NmlxfcD6cvDihrqr0p9GX7cH51jmxiCR+MfJ3V4iPcXnTtlL5dgidfPi48JlttFy2p5i2zgfwOPZhdaGEGE50TZgXNIcCU0WTPzTa63qEdv39k3gz+YBGjS1635fnfyXmMCo/2cJCL3Uz7tCac3IEyi49H+x5YB0ady6DC6HRZsbWpLNRBDeZxa9T9Sb0DX3Tm/Agmn+A3NvVOGwDgH/bkBzlECZJ/ojLx31gGD814mbdh27fIvdBsE7e3k0/y6ReUb7hjhbBdem3jYPa4PnEicLcgiZh4ZJr9fGhjFvz1GMbxlPRuLxX 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)(23010399003)(7416014)(376014)(82310400026)(1800799024)(921020)(18002099003)(22082099003)(11063799006)(5023799004)(56012099006)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aeplwpce71+WEL6DfVaTfQz2jMFirDQ5+9B9n2nFaa8HDnCEHzH4G/oCFVMax6e/tYoRdzu8266oQehOs/MLWW3oQCqo9CppKLsoY263b2aMOjYfRcfScCPFZlx21XOTjaMnQ5m9e7EbirViqUpgl2tdgbzEgg/FqobtW7k0wGTnfeDXCxwFzHsA7+vLIy2Ld5J73NskbZjKJoZB1XI8Ig28irDRYbJrxQ9dDrDI6aN0+92kjBplm3TgAItNmfKN062FXyzREehebzWm/jczo4Ar7dDDlCwJXD3SNeXpH9rHk4cyWPTWXPVIlWtQqmUfUfDjjthGPqDFJuJDrkPFeeoLbhrziHMPidErwRN8sPjhvV8zgYC90d44yqvukAi0Dri/hkTOU24zs11uCS3sf/CFmluvbIv2qE6TDOnxhm+mcswHBEp/18xTCeI1lYyf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 07:29:28.7644 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bfcf3357-b400-40d3-6557-08ded67951fc 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: MN1PEPF0000F0E5.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5823 Add a registration interface that lets a single offload provider (DMA, multi-threaded CPU copy, etc) take over the batch folio copy performed by migrate_pages_batch(). The provider fills in a struct migrator with an offload_copy() callback and calls migrate_offload_register(), passing the set of migration reasons it wants to handle. Registration updates the migrate_offload_batch_copy_fn() static_call and enables the migrate_offload_enabled static branch. migrate_offload_unregister() reverts both. The active_reason_mask is the single source of truth for which migration reasons are eligible for batched copy and offload. This is checked with the migrate_should_offload(). The active reason mask can be changed at runtime via migrate_offload_set_reason_mask(). Also, add migrate_offload_reason_mask_parse() and migrate_offload_reason_mask_format() so a provider can expose its reason mask using migrate_reason_names[] (e.g. "compaction,demotion", "all", "none"). Only one migrator can be active at a time. A second registration gets -EBUSY, and only the active migrator can unregister itself. The static_call dispatch is protected by SRCU so that the synchronize_srcu() in unregister waits for all in-flight copy before the module reference is dropped. Callbacks must set FOLIO_CONTENT_COPIED on each successfully copied dst folio so __migrate_folio() skips the per-folio copy; folios without the marker fall back to CPU copy in the move phase. Co-developed-by: Mike Day Signed-off-by: Mike Day Signed-off-by: Shivank Garg --- MAINTAINERS | 2 + include/linux/migrate_copy_offload.h | 69 ++++++++++ mm/Kconfig | 6 + mm/Makefile | 1 + mm/migrate.c | 9 +- mm/migrate_copy_offload.c | 249 +++++++++++++++++++++++++++++++= ++++ 6 files changed, 329 insertions(+), 7 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 762355b62d54..fa32b447f3e5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17065,9 +17065,11 @@ F: Documentation/ABI/testing/sysfs-kernel-mm-mempo= licy-weighted-interleave F: include/linux/mempolicy.h F: include/uapi/linux/mempolicy.h F: include/linux/migrate.h +F: include/linux/migrate_copy_offload.h F: include/linux/migrate_mode.h F: mm/mempolicy.c F: mm/migrate.c +F: mm/migrate_copy_offload.c F: mm/migrate_device.c =20 MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU) diff --git a/include/linux/migrate_copy_offload.h b/include/linux/migrate_c= opy_offload.h new file mode 100644 index 000000000000..97941ebd4979 --- /dev/null +++ b/include/linux/migrate_copy_offload.h @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MIGRATE_COPY_OFFLOAD_H +#define _LINUX_MIGRATE_COPY_OFFLOAD_H + +#include +#include +#include + +struct list_head; +struct module; + +#define MIGRATOR_NAME_LEN 32 + +/* + * Reasons that may ever be offloaded. A driver's mask is clamped to this. + * Allow all reasons by default. + */ +#define MIGRATE_OFFLOAD_REASONS_ALLOWED (BIT(MR_TYPES) - 1) + +/** + * struct migrator - batch-copy provider for page migration. + * @name: name of the provider. + * @offload_copy: copy @folio_cnt folios from @src_list to @dst_list. + * + * The migrator may inspect @folio_cnt to decide whether the batch + * is worth offloading, e.g. skip when the batch is too small to + * amortize setup cost. + * The callback must set FOLIO_CONTENT_COPIED in dst->migrate_info + * for each successfully copied destination folio. + * Folios without this marker are copied via per-folio CPU copy in + * the move phase. + * + * @owner: module providing the migrator. NULL for built-in (=3Dy) drivers. + */ +struct migrator { + char name[MIGRATOR_NAME_LEN]; + int (*offload_copy)(struct list_head *dst_list, struct list_head *src_lis= t, + unsigned int folio_cnt); + struct module *owner; +}; + +#ifdef CONFIG_MIGRATION_COPY_OFFLOAD +int migrate_offload_register(const struct migrator *m, unsigned long reaso= n_mask); +int migrate_offload_unregister(const struct migrator *m); +int migrate_offload_set_reason_mask(const struct migrator *m, unsigned lon= g mask); +int migrate_offload_reason_mask_parse(const char *buf, unsigned long *mask= p); +int migrate_offload_reason_mask_format(char *buf, unsigned long mask); +bool migrate_should_offload(int reason); +int migrate_offload_batch_copy(struct list_head *dst_batch, + struct list_head *src_batch, unsigned int nr_batch); +#else +static inline int migrate_offload_register(const struct migrator *m, + unsigned long reason_mask) { return -EOPNOTSUPP; } +static inline int migrate_offload_unregister(const struct migrator *m) { r= eturn -EOPNOTSUPP; } +static inline int migrate_offload_set_reason_mask(const struct migrator *m, + unsigned long mask) { return -EOPNOTSUPP; } +static inline int migrate_offload_reason_mask_parse(const char *buf, + unsigned long *maskp) { return -EOPNOTSUPP; } +static inline int migrate_offload_reason_mask_format(char *buf, + unsigned long mask) { return -EOPNOTSUPP; } +static inline bool migrate_should_offload(int reason) { return false; } +static inline int migrate_offload_batch_copy(struct list_head *dst_batch, + struct list_head *src_batch, unsigned int nr_batch) +{ + return -EOPNOTSUPP; +} +#endif + +#endif /* _LINUX_MIGRATE_COPY_OFFLOAD_H */ diff --git a/mm/Kconfig b/mm/Kconfig index 9e0ca4824905..c65639bae268 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -700,6 +700,12 @@ config MIGRATION config DEVICE_MIGRATION def_bool MIGRATION && ZONE_DEVICE =20 +# Page-migration batch-copy offload infrastructure. +# Selected by migrator drivers (e.g. CONFIG_DCBM_DMA). +config MIGRATION_COPY_OFFLOAD + bool + depends on MIGRATION && 64BIT + config ARCH_ENABLE_HUGEPAGE_MIGRATION bool =20 diff --git a/mm/Makefile b/mm/Makefile index eff9f9e7e061..256fb532b672 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -96,6 +96,7 @@ obj-$(CONFIG_FAILSLAB) +=3D failslab.o obj-$(CONFIG_FAIL_PAGE_ALLOC) +=3D fail_page_alloc.o obj-$(CONFIG_MEMTEST) +=3D memtest.o obj-$(CONFIG_MIGRATION) +=3D migrate.o +obj-$(CONFIG_MIGRATION_COPY_OFFLOAD) +=3D migrate_copy_offload.o obj-$(CONFIG_NUMA) +=3D memory-tiers.o obj-$(CONFIG_DEVICE_MIGRATION) +=3D migrate_device.o obj-$(CONFIG_TRANSPARENT_HUGEPAGE) +=3D huge_memory.o khugepaged.o diff --git a/mm/migrate.c b/mm/migrate.c index 41b732e78a67..4fed3110ca0a 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -43,6 +43,7 @@ #include #include #include +#include =20 #include =20 @@ -51,12 +52,6 @@ #include "internal.h" #include "swap.h" =20 -/* For now, never offload. Wired up in later patch. */ -static bool migrate_should_offload(int reason) -{ - return false; -} - static const struct movable_operations *offline_movable_ops; static const struct movable_operations *zsmalloc_movable_ops; =20 @@ -2050,7 +2045,7 @@ static int migrate_pages_batch(struct list_head *from, =20 /* Batch-copy eligible folios before the move phase */ if (!list_empty(&unmap_batch)) - migrate_folios_mc_copy(&dst_batch, &unmap_batch, nr_batch); + migrate_offload_batch_copy(&dst_batch, &unmap_batch, nr_batch); =20 retry =3D 1; for (pass =3D 0; pass < nr_pass && retry; pass++) { diff --git a/mm/migrate_copy_offload.c b/mm/migrate_copy_offload.c new file mode 100644 index 000000000000..335db8e80556 --- /dev/null +++ b/mm/migrate_copy_offload.c @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DEFINE_STATIC_KEY_FALSE(migrate_offload_enabled); +DEFINE_SRCU(migrate_offload_srcu); +DEFINE_STATIC_CALL(migrate_offload_batch_copy_fn, migrate_folios_mc_copy); + +static DEFINE_MUTEX(migrator_mutex); +static const struct migrator *active_migrator; + +/* + * The active migrator's reason mask. This is the single source of truth + * for which reasons are offloaded. + */ +static unsigned long active_reason_mask; + +bool migrate_should_offload(int reason) +{ + if (!static_branch_unlikely(&migrate_offload_enabled)) + return false; + + return READ_ONCE(active_reason_mask) & BIT(reason); +} + +/** + * migrate_offload_reason_mask_parse - parse migration reason mask. + * @buf: input string, either a number (hex/decimal, e.g. "0x101") or a + * comma-separated list of reason names (see migrate_reason_names[]), + * e.g. "compaction,demotion". The tokens "all" and "none" select + * every or no reason. + * @maskp: parsed mask, clamped to MIGRATE_OFFLOAD_REASONS_ALLOWED. + * + * Return: 0 on success, -EINVAL on an unknown name, -ENOMEM on OOM. + */ +int migrate_offload_reason_mask_parse(const char *buf, unsigned long *mask= p) +{ + unsigned long mask; + char *copy, *p, *tok; + int ret =3D 0; + + /* A plain number is treated as a raw mask. */ + if (!kstrtoul(buf, 0, &mask)) + goto done; + + copy =3D kstrdup(buf, GFP_KERNEL); + if (!copy) + return -ENOMEM; + mask =3D 0; + p =3D strim(copy); + + while ((tok =3D strsep(&p, ",")) !=3D NULL) { + int i; + + tok =3D strim(tok); + if (!*tok) + continue; + if (!strcmp(tok, "none")) { + mask =3D 0; + continue; + } + if (!strcmp(tok, "all")) { + mask =3D MIGRATE_OFFLOAD_REASONS_ALLOWED; + continue; + } + i =3D match_string(migrate_reason_names, MR_TYPES, tok); + if (i < 0) { + ret =3D -EINVAL; + break; + } + mask |=3D BIT(i); + } + kfree(copy); + if (ret) + return ret; +done: + *maskp =3D mask & MIGRATE_OFFLOAD_REASONS_ALLOWED; + return 0; +} +EXPORT_SYMBOL_GPL(migrate_offload_reason_mask_parse); + +/** + * migrate_offload_reason_mask_format - render a reason mask as names. + * @buf: output buffer from kernel_param_ops get. + * @mask: reason mask to render. + * + * Emits a comma-separated list of reason names, or "none". + * + * Return: number of bytes written to @buf. + */ +int migrate_offload_reason_mask_format(char *buf, unsigned long mask) +{ + int len =3D 0, i; + + for_each_set_bit(i, &mask, MR_TYPES) + len +=3D sysfs_emit_at(buf, len, "%s%s", + len ? "," : "", migrate_reason_names[i]); + if (!len) + return sysfs_emit(buf, "none\n"); + + len +=3D sysfs_emit_at(buf, len, "\n"); + return len; +} +EXPORT_SYMBOL_GPL(migrate_offload_reason_mask_format); + +/* + * Hand the batch to the registered migrator. The migrator may decline + * (typically based on batch size), in which case the move phase falls + * back to per-folio CPU copy. + */ +int migrate_offload_batch_copy(struct list_head *dst_batch, + struct list_head *src_batch, unsigned int nr_batch) +{ + int idx, rc; + + idx =3D srcu_read_lock(&migrate_offload_srcu); + rc =3D static_call(migrate_offload_batch_copy_fn)(dst_batch, src_batch, n= r_batch); + srcu_read_unlock(&migrate_offload_srcu, idx); + return rc; +} + +/** + * migrate_offload_set_reason_mask - update the active migrator's reason m= ask. + * @m: migrator (must be the currently active one). + * @mask: new reason mask. + * + * Return: 0 on success, -EINVAL if @m is NULL or not the active migrator. + */ +int migrate_offload_set_reason_mask(const struct migrator *m, unsigned lon= g mask) +{ + if (!m) + return -EINVAL; + + mask &=3D MIGRATE_OFFLOAD_REASONS_ALLOWED; + + mutex_lock(&migrator_mutex); + if (active_migrator !=3D m) { + mutex_unlock(&migrator_mutex); + return -EINVAL; + } + WRITE_ONCE(active_reason_mask, mask); + mutex_unlock(&migrator_mutex); + return 0; +} +EXPORT_SYMBOL_GPL(migrate_offload_set_reason_mask); + +/** + * migrate_offload_register - register a batch-copy provider for page migr= ation. + * @m: migrator to install. + * @reason_mask: initial set of BIT(MR_*) reasons to offload, can be chang= ed + * later via migrate_offload_set_reason_mask(). + * + * Only one provider can be active at a time, returns -EBUSY if another mi= grator + * is already registered. + * + * Return: 0 on success, negative errno on failure. + */ +int migrate_offload_register(const struct migrator *m, unsigned long reaso= n_mask) +{ + unsigned long mask; + int ret =3D 0; + + if (!m || !m->offload_copy) + return -EINVAL; + + mask =3D reason_mask & MIGRATE_OFFLOAD_REASONS_ALLOWED; + + mutex_lock(&migrator_mutex); + if (active_migrator) { + ret =3D -EBUSY; + goto unlock; + } + + /* @owner is NULL for built-in (=3Dy) drivers; nothing to ref. */ + if (m->owner && !try_module_get(m->owner)) { + ret =3D -ENODEV; + goto unlock; + } + + WRITE_ONCE(active_reason_mask, mask); + static_call_update(migrate_offload_batch_copy_fn, m->offload_copy); + active_migrator =3D m; + static_branch_enable(&migrate_offload_enabled); + +unlock: + mutex_unlock(&migrator_mutex); + + if (ret) + pr_err("migrate_offload: %s: failed to register (%d)\n", m->name, ret); + else + pr_info("migrate_offload: enabled by %s (reason_mask=3D0x%lx)\n", + m->name, mask); + return ret; +} +EXPORT_SYMBOL_GPL(migrate_offload_register); + +/** + * migrate_offload_unregister - unregister the active batch-copy provider. + * @m: migrator to remove (must be the currently active one). + * + * Reverts static_call targets and waits for SRCU grace period so that + * no in-flight migration is still calling the driver functions before + * releasing the module. + * + * Return: 0 on success, negative errno on failure. + */ +int migrate_offload_unregister(const struct migrator *m) +{ + struct module *owner; + + if (!m) + return -EINVAL; + + mutex_lock(&migrator_mutex); + if (active_migrator !=3D m) { + mutex_unlock(&migrator_mutex); + return -EINVAL; + } + + /* + * Disable the static branch first so new migrate_pages_batch() calls + * cannot enter the batch path. + */ + static_branch_disable(&migrate_offload_enabled); + WRITE_ONCE(active_reason_mask, 0); + static_call_update(migrate_offload_batch_copy_fn, migrate_folios_mc_copy); + owner =3D active_migrator->owner; + active_migrator =3D NULL; + mutex_unlock(&migrator_mutex); + + /* Wait for all in-flight callers to finish before module_put(). */ + synchronize_srcu(&migrate_offload_srcu); + if (owner) + module_put(owner); + + pr_info("migrate_offload: disabled by %s\n", m->name); + return 0; +} +EXPORT_SYMBOL_GPL(migrate_offload_unregister); --=20 2.43.0 From nobody Tue Jul 7 22:59:11 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013053.outbound.protection.outlook.com [40.93.196.53]) (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 37C95344D86 for ; Tue, 30 Jun 2026 07:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804587; cv=fail; b=tnqXPu07h36fSa/G35tfTfU5lek6sWdLufpadRJ53bacE+wmH9r7PUFGoJb+2dPkJzUUKD4PZ0gPxc5cVj7P1rw0kCdLR/uXQDLp5U5GPJ34aymLwaumblFa0rT0LgPtdsEV/IhtevBGjJSz/U7hvsdsLoKkunvtsZ0QOR5o1EA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804587; c=relaxed/simple; bh=slS65rgIlB5eytgKz5oEceZYKCMBATb7d3dSKNrGEzc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=GxR7Y0iwyVC9sVrSBIKm6KRBO/Vu3tdQvEYDL7OmM/g9INl1rO1AKqJQiffQmlVUsl59s47nDhG/yXQViYVSu/JWKe4C2kU0Shz1KT7gwcjYZzOc9rzbwNDOKJ4pdmBXzTpVnkfJkJ7eXAC1IZHmL3VfLwCSOSWzrneVlEE7iyg= 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=ZVn08Eda; arc=fail smtp.client-ip=40.93.196.53 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="ZVn08Eda" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MpPvmUeckbEWg67gSEskCn4tpoziXai6ZKdR7kBf6M/IdkS+HAF/jIydQKgFB1qkB/CmOyfIJbuWe/Wld77WbU+is9RlRRcGhDXPHJaYQwuD5K/oOtpv39m9u/XXo9M/uB57qyFtOEgw5IGan+uzmm4gUbNWjw4jHdQKxrRAV5Ru5Wu5H6sOlcTN7yul9WiOQHygeu2z6/Xtwmf4KqLDPDOHyBDdxo9LZe9A3z4WCa/HivOmM2EivuwH1cNcjC1HGwI4vmZUplljtxHm5vIhkIyRE3d/3jbaZHtPTFmI/fnZTyJsAcMVq5bFGTwOhopmimzPgVmoj1Sn9+44+5iFOA== 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=ejtVnlH8iz5PO4bS0HPGoIKn5VpJDvbvOnHH9m9ec/s=; b=bVqPHn7FBidBIFLK6vxrcoegjqsKrPVoMOQ9Jnxy9570Mabc441Uq1bfEv8QwZAlHJzykSXfzrfOIsUHLs/6CuHSLJfe2fFlhCvoa0AvD4sVsnNeVr/BmEdQe4XFThPPekC8g9PtKff4RxZdUxpjgWnKkqT/1Xs29TvuBAAY3aoDFFjDsSfZr3vzVFmjteiN+9Z6Q0DW3fPpf7dB0j4c6fTK0hcGiHm6AkRnFMKCm1+6limnPUY0WwiU/pA3HK6YiLfonDKQMW6HDeoWac8i4wYOnnzWuFJqwAhOBjWXKrrtmtgbseiK5iQII5FnNUPy6zzB4Qpac1ebww7C3cC7hw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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=ejtVnlH8iz5PO4bS0HPGoIKn5VpJDvbvOnHH9m9ec/s=; b=ZVn08EdazfIjUYT2GSxYvWimizp8Tb90iLo9EIRbx+gx+yvrFg28yhKULUZoGQoDCB7cqq2OKMMTfJpYbql4vccLITjXpglaObR0201ZjUjhlqQbADyDitXSF/fvmKltNaZvZuJnesujsE1LXYbWT4U+hCWINI6pBOxfxSnJuKY= Received: from MN0PR04CA0019.namprd04.prod.outlook.com (2603:10b6:208:52d::33) by CY5PR12MB6575.namprd12.prod.outlook.com (2603:10b6:930:41::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.18; Tue, 30 Jun 2026 07:29:39 +0000 Received: from MN1PEPF0000F0E1.namprd04.prod.outlook.com (2603:10b6:208:52d:cafe::8a) by MN0PR04CA0019.outlook.office365.com (2603:10b6:208:52d::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.8 via Frontend Transport; Tue, 30 Jun 2026 07:29:39 +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 MN1PEPF0000F0E1.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.21.181.6 via Frontend Transport; Tue, 30 Jun 2026 07:29: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.41; Tue, 30 Jun 2026 02:29:28 -0500 From: Shivank Garg Date: Tue, 30 Jun 2026 07:28:40 +0000 Subject: [PATCH RFC v6 4/5] drivers/migrate_offload: add DMA batch copy driver (dcbm) 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: <20260630-shivank-batch-migrate-offload-v6-4-da95d7e8b8a2@amd.com> References: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> In-Reply-To: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , "Mike Rapoport" , Suren Baghdasaryan , "Michal Hocko" CC: Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , "Yiannis Nikolakopoulos" , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , Aneesh Kumar K.V , Nathan Lynch , Frank Li , Dan Williams , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782804526; l=17627; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=slS65rgIlB5eytgKz5oEceZYKCMBATb7d3dSKNrGEzc=; b=3g3WBxTfgIAGae10nFvFaK1uXS6woAHtuiQRN1Ocik+Tt0pyT2KLUvxWt5VNKNACIbacUmeOV gK3S7BOsjskCXb09+V83F8LH1X1uT+YXQS+DvCY+S/HG0E08WxZcwoJ X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E1:EE_|CY5PR12MB6575:EE_ X-MS-Office365-Filtering-Correlation-Id: dee72db1-2dea-4219-cbc0-08ded6795812 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700016|82310400026|7416014|23010399003|3023799007|18002099003|6133799003|11063799006|22082099003|56012099006|13003099007|921020; X-Microsoft-Antispam-Message-Info: dvcX9iXxQyikEigeRtxZtuiusSuQO7TAy8rp4CpbWufQvkiWg6/2hRd7Sr1+H1BNzARqWBi8srVnRj8BzHL2d0B6g6RDPuXcxrcaQQ7soiospWFnZbRD8xG9ZZ9PVqzMx9IhJiqA7oxA1XsWFns5RhCSU7Sa4MlaB1BI4nDDeuLf7S/Q0AQz4i1fzjZy1Rzl3BSJ493mW/C18KBaQQyKJa3tFMBlqfOggUkY1gBWNv0qLyn3+TrW/pHW/nJi0TdPeWuU+Zk8GrGRUQNf0VpJhhfqQgJbrpZU5uVcCAIGZ3P7hRhxJP12HDYK8Ym3U7v/VfmlI8hZEw05em5sf0XTDCGg2TiHteiLXbbA+N31DT7BNY+WkaCgidYeiQA4eSKdNSU5A4p3VaUzqWZrpXSUTsOFL2F+T69Z1F8UUj4REnUno5Vc7gITauaCUVWQeN+Wds9/S/mYpHJNif/I8R8jCGiBZmv/lumgscrZ6F94Smxp1kXJZCfi0Tvn15uNZZolSo5dSqBV0E9rgVBsYkMFhTO766Ttp2XuaoolY5+dO0R8CMnu9D0FiKIjYbtCyg0W2Iha0U5yvLwCIUoMe2hryaI8EyvGQWstdY7l33CqAReB/xisReQXDgQQtTI5EFsupdZHotGUEdLDXbLBwsCES3ZgzlcPBOA9RgqU4xPgSw7efa6VcJXyDw27G/y9Cidm5Nxcdyc+gv7x5S6zK2ea7c0DdD06U7IaHgC6Htt6+6eZDs7Dm2bergp+xB4kGqoT 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)(376014)(36860700016)(82310400026)(7416014)(23010399003)(3023799007)(18002099003)(6133799003)(11063799006)(22082099003)(56012099006)(13003099007)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5t2UaiD4XZ2081zWXtboEkd+HEKNp2Pc4uibeVirwbXkDW6WHgB6PvobERGiIwVeE6kn81hDuWbeJFL+0hQ25s3sXc3ymVasfoQTusCvHI02/lT2I9ZiQU/cM8pRBPwCBQHUe5GGMl8oJr4F6181PxRN+misxVM3CzWmlZouSK48LwVLvqcitwTYXaaxFiDu0i2sWsR3heRTutTCPVI3k60Sjm/fEW7ZYkM9bAlZjaa3P5CUH9krFnFCVkYQCWlcGYZhtSSJSJnasOL4y4sdSOuALEk6+0IIAPIUkRxsnLFDjlcuPWVTZg7Xt2VMURQrPOb9WKWyGt7kCRh2D99raSW/V0YqeMOT+VuYF5QuKJ3a7aD+GCHqhxewZAS3jDdGriHlilKK6I/dRt9RGLyPltQdG/0OkqN12YtxlSrXTt1M4O6LjQS/uLFxJG9EP84P X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 07:29:38.9760 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dee72db1-2dea-4219-cbc0-08ded6795812 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: MN1PEPF0000F0E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6575 Add a simple DMAEngine-based migrator that plugs into the page migration copy-offload infrastructure and batch-copies folios via DMA memcpy channels. It is intended for testing the offload plumbing and as a template for future migrators (SDXI, multi-threaded CPU copy, etc.). On success, the dst folios are marked with FOLIO_CONTENT_COPIED so __migrate_folio skips the per-folio copy. On any DMA error, FOLIO_CONTENT_COPIED market is not set and the migration falls back to per-folio CPU copy. dcbm registers with reason mask with reason mask MIGRATE_OFFLOAD_REASONS_ALLOWED, this set can be narrowed at runtime via the reason_mask parameter. Runtime controls are under /sys/module/dcbm/parameters/: offloading - enable/disable DMA offload (0/1) nr_dma_chan - max DMA channels to use (1..N) reason_mask - reasons to offload: names (e.g. "compaction,demotion"), "all"/"none" or raw numerical mask. folios_migrated - folios DMA-copied (write to reset) folios_failures - fallback count (write to reset) CONFIG_DCBM_DMA selects MIGRATION_COPY_OFFLOAD so enabling the driver pulls in the infrastructure automatically. Channel acquisition uses dma_request_chan_by_mask(DMA_MEMCPY), which works for providers that set DMA_PRIVATE (e.g. AMD PTDMA). Generic mem-to-mem engines that do not set DMA_PRIVATE (e.g. SDXI) should acquire channels via dma_find_channel(DMA_MEMCPY) or the async_tx APIs, which can be added in a follow-up. [Correctness Note: Karim: Descriptor can complete out of order for some dmaengines. so descriptor chaining may yield incorrect results. For correctness we need to add callback to every descriptor https://lore.kernel.org/all/20260619160725.lfcxrbj5go67qy6u@wrangler Shivank: device_prep_dma_memcpy_sg() would solve this. ] Reviewed-by: Karim Manaouil Signed-off-by: Shivank Garg --- drivers/Kconfig | 2 + drivers/Makefile | 2 + drivers/migrate_offload/Kconfig | 9 + drivers/migrate_offload/Makefile | 1 + drivers/migrate_offload/dcbm/Makefile | 1 + drivers/migrate_offload/dcbm/dcbm.c | 481 ++++++++++++++++++++++++++++++= ++++ 6 files changed, 496 insertions(+) diff --git a/drivers/Kconfig b/drivers/Kconfig index f2bed2ddeb66..3e83a1475cbc 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -253,4 +253,6 @@ source "drivers/cdx/Kconfig" =20 source "drivers/resctrl/Kconfig" =20 +source "drivers/migrate_offload/Kconfig" + endmenu diff --git a/drivers/Makefile b/drivers/Makefile index 0841ea851847..88cb8e3e88df 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -42,6 +42,8 @@ obj-y +=3D clk/ # really early. obj-$(CONFIG_DMADEVICES) +=3D dma/ =20 +obj-$(CONFIG_MIGRATION_COPY_OFFLOAD) +=3D migrate_offload/ + # SOC specific infrastructure drivers. obj-y +=3D soc/ obj-$(CONFIG_PM_GENERIC_DOMAINS) +=3D pmdomain/ diff --git a/drivers/migrate_offload/Kconfig b/drivers/migrate_offload/Kcon= fig new file mode 100644 index 000000000000..c9f2e21a95cf --- /dev/null +++ b/drivers/migrate_offload/Kconfig @@ -0,0 +1,9 @@ +config DCBM_DMA + tristate "DMA Core Batch Migrator" + depends on MIGRATION && DMA_ENGINE && 64BIT + select MIGRATION_COPY_OFFLOAD + help + DMA-based batch copy engine for page migration. Uses + DMAEngine memcpy channels to offload folio data copies + during migration. Primarily intended for testing the copy + offload infrastructure. diff --git a/drivers/migrate_offload/Makefile b/drivers/migrate_offload/Mak= efile new file mode 100644 index 000000000000..9e16018beb15 --- /dev/null +++ b/drivers/migrate_offload/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_DCBM_DMA) +=3D dcbm/ diff --git a/drivers/migrate_offload/dcbm/Makefile b/drivers/migrate_offloa= d/dcbm/Makefile new file mode 100644 index 000000000000..56ba47cce0f1 --- /dev/null +++ b/drivers/migrate_offload/dcbm/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_DCBM_DMA) +=3D dcbm.o diff --git a/drivers/migrate_offload/dcbm/dcbm.c b/drivers/migrate_offload/= dcbm/dcbm.c new file mode 100644 index 000000000000..bacbcc689171 --- /dev/null +++ b/drivers/migrate_offload/dcbm/dcbm.c @@ -0,0 +1,481 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * DMA Core Batch Migrator (DCBM) + * + * Uses DMAEngine memcpy channels to offload batch folio copies during + * page migration. Reference driver meant for testing the offload + * infrastructure. + * + * Copyright (C) 2024-26 Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include + +#define MAX_DMA_CHANNELS 16 + +static atomic_long_t folios_migrated; +static atomic_long_t folios_failures; + +static bool offloading_enabled; +static unsigned int nr_dma_channels =3D 1; +static DEFINE_MUTEX(dcbm_mutex); + +struct dma_work { + struct dma_chan *chan; + struct completion done; + atomic_t pending; + struct sg_table *src_sgt; + struct sg_table *dst_sgt; + bool mapped; +}; + +static void dma_completion_callback(void *data) +{ + struct dma_work *work =3D data; + + if (atomic_dec_and_test(&work->pending)) + complete(&work->done); +} + +static int setup_sg_tables(struct dma_work *work, struct list_head **src_p= os, + struct list_head **dst_pos, int nr) +{ + struct scatterlist *sg_src, *sg_dst; + struct device *dev; + int i, ret; + + work->src_sgt =3D kmalloc_obj(*work->src_sgt, GFP_KERNEL); + if (!work->src_sgt) + return -ENOMEM; + work->dst_sgt =3D kmalloc_obj(*work->dst_sgt, GFP_KERNEL); + if (!work->dst_sgt) { + ret =3D -ENOMEM; + goto err_free_src; + } + + ret =3D sg_alloc_table(work->src_sgt, nr, GFP_KERNEL); + if (ret) + goto err_free_dst; + ret =3D sg_alloc_table(work->dst_sgt, nr, GFP_KERNEL); + if (ret) + goto err_free_src_table; + + sg_src =3D work->src_sgt->sgl; + sg_dst =3D work->dst_sgt->sgl; + for (i =3D 0; i < nr; i++) { + struct folio *src =3D list_entry(*src_pos, struct folio, lru); + struct folio *dst =3D list_entry(*dst_pos, struct folio, lru); + + sg_set_folio(sg_src, src, folio_size(src), 0); + sg_set_folio(sg_dst, dst, folio_size(dst), 0); + + *src_pos =3D (*src_pos)->next; + *dst_pos =3D (*dst_pos)->next; + + if (i < nr - 1) { + sg_src =3D sg_next(sg_src); + sg_dst =3D sg_next(sg_dst); + } + } + + dev =3D dmaengine_get_dma_device(work->chan); + if (!dev) { + ret =3D -ENODEV; + goto err_free_dst_table; + } + ret =3D dma_map_sgtable(dev, work->src_sgt, DMA_TO_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_NO_KERNEL_MAPPING); + if (ret) + goto err_free_dst_table; + ret =3D dma_map_sgtable(dev, work->dst_sgt, DMA_FROM_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_NO_KERNEL_MAPPING); + if (ret) + goto err_unmap_src; + + /* + * TODO: IOMMU may merge segments unevenly on the two sides, fall back + * bail to CPU copy. In practice, I have not observed merging in tests. + * Handling unequal nents is left for follow-up. + */ + if (work->src_sgt->nents !=3D work->dst_sgt->nents) { + ret =3D -EINVAL; + goto err_unmap_dst; + } + work->mapped =3D true; + return 0; + +err_unmap_dst: + dma_unmap_sgtable(dev, work->dst_sgt, DMA_FROM_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_NO_KERNEL_MAPPING); +err_unmap_src: + dma_unmap_sgtable(dev, work->src_sgt, DMA_TO_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_NO_KERNEL_MAPPING); +err_free_dst_table: + sg_free_table(work->dst_sgt); +err_free_src_table: + sg_free_table(work->src_sgt); +err_free_dst: + kfree(work->dst_sgt); + work->dst_sgt =3D NULL; +err_free_src: + kfree(work->src_sgt); + work->src_sgt =3D NULL; + return ret; +} + +static void cleanup_dma_work(struct dma_work *works, int actual_channels) +{ + struct device *dev; + int i; + + if (!works) + return; + + for (i =3D 0; i < actual_channels; i++) { + if (!works[i].chan) + continue; + + dev =3D dmaengine_get_dma_device(works[i].chan); + + if (works[i].mapped) + dmaengine_terminate_sync(works[i].chan); + + if (dev && works[i].mapped) { + if (works[i].src_sgt) { + dma_unmap_sgtable(dev, works[i].src_sgt, + DMA_TO_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC | + DMA_ATTR_NO_KERNEL_MAPPING); + sg_free_table(works[i].src_sgt); + kfree(works[i].src_sgt); + } + if (works[i].dst_sgt) { + dma_unmap_sgtable(dev, works[i].dst_sgt, + DMA_FROM_DEVICE, + DMA_ATTR_SKIP_CPU_SYNC | + DMA_ATTR_NO_KERNEL_MAPPING); + sg_free_table(works[i].dst_sgt); + kfree(works[i].dst_sgt); + } + } + dma_release_channel(works[i].chan); + } + kfree(works); +} + +static int submit_dma_transfers(struct dma_work *work) +{ + struct scatterlist *sg_src, *sg_dst; + struct dma_async_tx_descriptor *tx; + unsigned long flags =3D DMA_CTRL_ACK; + dma_cookie_t cookie; + int i; + + atomic_set(&work->pending, 1); + + sg_src =3D work->src_sgt->sgl; + sg_dst =3D work->dst_sgt->sgl; + for_each_sgtable_dma_sg(work->src_sgt, sg_src, i) { + if (i =3D=3D work->src_sgt->nents - 1) + flags |=3D DMA_PREP_INTERRUPT; + + tx =3D dmaengine_prep_dma_memcpy(work->chan, + sg_dma_address(sg_dst), + sg_dma_address(sg_src), + sg_dma_len(sg_src), flags); + if (!tx) { + atomic_set(&work->pending, 0); + return -EIO; + } + + if (i =3D=3D work->src_sgt->nents - 1) { + tx->callback =3D dma_completion_callback; + tx->callback_param =3D work; + } + + cookie =3D dmaengine_submit(tx); + if (dma_submit_error(cookie)) { + atomic_set(&work->pending, 0); + return -EIO; + } + sg_dst =3D sg_next(sg_dst); + } + return 0; +} + +/** + * folios_copy_dma - copy a batch of folios via DMA memcpy + * @dst_list: destination folio list + * @src_list: source folio list + * @nr_folios: number of folios in each list + * + * Return: 0 on success, negative errno on failure. + */ +static int folios_copy_dma(struct list_head *dst_list, + struct list_head *src_list, unsigned int nr_folios) +{ + struct folio *dst; + struct dma_work *works; + struct list_head *src_pos =3D src_list->next; + struct list_head *dst_pos =3D dst_list->next; + int i, folios_per_chan, ret; + dma_cap_mask_t mask; + int actual_channels =3D 0; + unsigned int max_channels; + + max_channels =3D min3(READ_ONCE(nr_dma_channels), nr_folios, + (unsigned int)MAX_DMA_CHANNELS); + + works =3D kcalloc(max_channels, sizeof(*works), GFP_KERNEL); + if (!works) + return -ENOMEM; + + dma_cap_zero(mask); + dma_cap_set(DMA_MEMCPY, mask); + + for (i =3D 0; i < max_channels; i++) { + works[actual_channels].chan =3D dma_request_chan_by_mask(&mask); + if (IS_ERR(works[actual_channels].chan)) + break; + init_completion(&works[actual_channels].done); + actual_channels++; + } + + if (actual_channels =3D=3D 0) { + kfree(works); + return -ENODEV; + } + + for (i =3D 0; i < actual_channels; i++) { + folios_per_chan =3D nr_folios * (i + 1) / actual_channels - + (nr_folios * i) / actual_channels; + if (folios_per_chan =3D=3D 0) + continue; + + ret =3D setup_sg_tables(&works[i], &src_pos, &dst_pos, + folios_per_chan); + if (ret) + goto err_cleanup; + } + + for (i =3D 0; i < actual_channels; i++) { + if (!works[i].mapped) + continue; + ret =3D submit_dma_transfers(&works[i]); + if (ret) + goto err_cleanup; + } + + for (i =3D 0; i < actual_channels; i++) { + if (atomic_read(&works[i].pending) > 0) + dma_async_issue_pending(works[i].chan); + } + + for (i =3D 0; i < actual_channels; i++) { + if (atomic_read(&works[i].pending) =3D=3D 0) + continue; + if (!wait_for_completion_timeout(&works[i].done, + msecs_to_jiffies(10000))) { + ret =3D -ETIMEDOUT; + goto err_cleanup; + } + } + + /* + * All folios copied; mark each dst with FOLIO_CONTENT_COPIED so + * __migrate_folio() skips the per-folio copy in the move phase. + */ + list_for_each_entry(dst, dst_list, lru) + dst->migrate_info |=3D FOLIO_CONTENT_COPIED; + + cleanup_dma_work(works, actual_channels); + + atomic_long_add(nr_folios, &folios_migrated); + return 0; + +err_cleanup: + pr_warn_ratelimited("dcbm: DMA copy failed (%d), falling back to CPU\n", + ret); + cleanup_dma_work(works, actual_channels); + + atomic_long_add(nr_folios, &folios_failures); + return ret; +} + +static const struct migrator dma_migrator =3D { + .name =3D "DCBM", + .offload_copy =3D folios_copy_dma, + .owner =3D THIS_MODULE, +}; + +static unsigned long dcbm_reason_mask =3D MIGRATE_OFFLOAD_REASONS_ALLOWED; + +/* offloading: enable/disable DMA migration offload */ +static int offloading_param_set(const char *val, const struct kernel_param= *kp) +{ + bool enable; + int ret; + + ret =3D kstrtobool(val, &enable); + if (ret) + return ret; + + mutex_lock(&dcbm_mutex); + if (enable =3D=3D offloading_enabled) { + mutex_unlock(&dcbm_mutex); + return 0; + } + if (enable) { + ret =3D migrate_offload_register(&dma_migrator, + READ_ONCE(dcbm_reason_mask)); + if (ret) { + mutex_unlock(&dcbm_mutex); + return ret; + } + WRITE_ONCE(offloading_enabled, true); + } else { + migrate_offload_unregister(&dma_migrator); + WRITE_ONCE(offloading_enabled, false); + } + mutex_unlock(&dcbm_mutex); + return 0; +} + +static int offloading_param_get(char *buffer, const struct kernel_param *k= p) +{ + return sysfs_emit(buffer, "%d\n", READ_ONCE(offloading_enabled)); +} + +static const struct kernel_param_ops offloading_param_ops =3D { + .set =3D offloading_param_set, + .get =3D offloading_param_get, +}; +module_param_cb(offloading, &offloading_param_ops, NULL, 0644); +MODULE_PARM_DESC(offloading, "Enable DMA migration offload (0/1)"); + +/* nr_dma_chan: max DMA channels to use per batch */ +static int nr_dma_chan_param_set(const char *val, const struct kernel_para= m *kp) +{ + unsigned int new_val; + int ret; + + ret =3D kstrtouint(val, 0, &new_val); + if (ret) + return ret; + if (new_val < 1 || new_val > MAX_DMA_CHANNELS) + return -EINVAL; + + mutex_lock(&dcbm_mutex); + WRITE_ONCE(nr_dma_channels, new_val); + mutex_unlock(&dcbm_mutex); + return 0; +} + +static int nr_dma_chan_param_get(char *buffer, const struct kernel_param *= kp) +{ + return sysfs_emit(buffer, "%u\n", READ_ONCE(nr_dma_channels)); +} + +static const struct kernel_param_ops nr_dma_chan_param_ops =3D { + .set =3D nr_dma_chan_param_set, + .get =3D nr_dma_chan_param_get, +}; +module_param_cb(nr_dma_chan, &nr_dma_chan_param_ops, NULL, 0644); +MODULE_PARM_DESC(nr_dma_chan, "Max DMA channels to use (1..16)"); + +/* reason_mask: set of MR_* reasons this migrator handles */ +static int reason_mask_param_set(const char *val, const struct kernel_para= m *kp) +{ + unsigned long mask; + int ret; + + ret =3D migrate_offload_reason_mask_parse(val, &mask); + if (ret) + return ret; + + mutex_lock(&dcbm_mutex); + WRITE_ONCE(dcbm_reason_mask, mask); + if (offloading_enabled) + migrate_offload_set_reason_mask(&dma_migrator, mask); + mutex_unlock(&dcbm_mutex); + return 0; +} + +static int reason_mask_param_get(char *buffer, const struct kernel_param *= kp) +{ + return migrate_offload_reason_mask_format(buffer, READ_ONCE(dcbm_reason_m= ask)); +} + +static const struct kernel_param_ops reason_mask_param_ops =3D { + .set =3D reason_mask_param_set, + .get =3D reason_mask_param_get, +}; +module_param_cb(reason_mask, &reason_mask_param_ops, NULL, 0644); +MODULE_PARM_DESC(reason_mask, + "Reasons to offload: comma-separated names (e.g. compaction,demotion), = 'all', 'none', or a raw hex mask"); + +/* folios_migrated / folios_failures: counters; any write resets to 0 */ +static int folios_migrated_param_set(const char *val, const struct kernel_= param *kp) +{ + atomic_long_set(&folios_migrated, 0); + return 0; +} + +static int folios_migrated_param_get(char *buffer, const struct kernel_par= am *kp) +{ + return sysfs_emit(buffer, "%ld\n", atomic_long_read(&folios_migrated)); +} + +static const struct kernel_param_ops folios_migrated_param_ops =3D { + .set =3D folios_migrated_param_set, + .get =3D folios_migrated_param_get, +}; +module_param_cb(folios_migrated, &folios_migrated_param_ops, NULL, 0644); +MODULE_PARM_DESC(folios_migrated, "Folios DMA-copied (write to reset)"); + +static int folios_failures_param_set(const char *val, const struct kernel_= param *kp) +{ + atomic_long_set(&folios_failures, 0); + return 0; +} + +static int folios_failures_param_get(char *buffer, const struct kernel_par= am *kp) +{ + return sysfs_emit(buffer, "%ld\n", atomic_long_read(&folios_failures)); +} + +static const struct kernel_param_ops folios_failures_param_ops =3D { + .set =3D folios_failures_param_set, + .get =3D folios_failures_param_get, +}; +module_param_cb(folios_failures, &folios_failures_param_ops, NULL, 0644); +MODULE_PARM_DESC(folios_failures, "DMA-copy failure count (write to reset)= "); + +static int __init dcbm_init(void) +{ + pr_info("dcbm: DMA Core Batch Migrator initialized\n"); + return 0; +} + +static void __exit dcbm_exit(void) +{ + mutex_lock(&dcbm_mutex); + if (offloading_enabled) { + migrate_offload_unregister(&dma_migrator); + offloading_enabled =3D false; + } + mutex_unlock(&dcbm_mutex); + + pr_info("dcbm: DMA Core Batch Migrator unloaded\n"); +} + +module_init(dcbm_init); +module_exit(dcbm_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Shivank Garg"); +MODULE_DESCRIPTION("DMA Core Batch Migrator"); --=20 2.43.0 From nobody Tue Jul 7 22:59:11 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010032.outbound.protection.outlook.com [52.101.201.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 DEDE6394797 for ; Tue, 30 Jun 2026 07:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804597; cv=fail; b=bMHljM9ClyvptSC01oS4iOv+2ZAEt4ynx3jlVVUSxhoBxx3b01OVTQ16FB/iEexGQMAtJgVP9NBoh5cIto+38x1jpuAblwBgFogxHzj3pB9GXttBMwjXie38sj1JR2q00Cs+AGs1evGH3vf8KpGpfWijTrthYa55PbCKabCAp5U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782804597; c=relaxed/simple; bh=vT6kSHzpsLNSLPaAt80OX/OkrVu1sUWAOso+R4uQZ8Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=bZxs+RBsApU+44NllM0xWARqnl8guCG2vKlq9MRYfTRKCFuD9F3RDKHOEk3hPV+ewU7UEQrG4pP3fDHuK7isLoukaR6sL/ZjuqfCC427fQ7S66aQALudn4u6MCJotryGC4GaF/fuIetjGcOgIxZmeYWMKkjfe5hra6Q4GYN9+44= 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=I+QmAqWB; arc=fail smtp.client-ip=52.101.201.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="I+QmAqWB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cgh+LSIE1aZEfrsmxjQtBIXELsPmmgTuvzmfDuAjtfIz6ZK7KuHhCi2ZrxYQKlgWLRRWajqrItHATTGZwpC0J5CsE3JBjDvzdQTYRKmAJCdSzc+VR5WxN21bGe9vpIPwfXvLp+B25u0XPNhOoZFLz51PWd9lmhCdXLy+tQLCvvJp3u9ePbzqd6OZBdB0uB29f3oc9uvPKpITgTF/jQr6upU3WDtnXIueZ+OdsJMgDqjr/zhRGDAcYOKJSdsUbuTsiYLf1nx7N9kFGI2EVriQXP8d3JE76qc2zex9D/NkDTXtiABdJA1Apq3TuoXpfFijKP6BD3I4o0RNW+52bmsAtg== 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=yr7EN25FGHy2WNXJ2WFtyz68nDJht+RoVhPaCGfdrMI=; b=n7neJH/SgTK1i2BGiHcx06WcsfwNT+XU0FHXnQ4CLjf9u1tB1iMq0Cse4SDB7JHxkMYC6fNSdXX9/jZngMjjL+z+vWMRhxA3Oa1nMQbGTD9bwI7c4s5njlsg2IZQ4qKv9DQhJx+lw9W0HV8EdEgl6ujsJxQRRMuFmEZAOIWNQLWFARHzXiBdYAMlC/B5x5rHcp9TCdBGSWMGGMYKubUtzc6S8EdSvzADq3WG+LXQmJ2ob2wiASGeQVE8lEAMjDRNDUVGTPqlCzQbOIsft6sXk9nlUn05sSvS2vJxsx188ySmJln+mN+1y1dV6ksZBzhMxM05f2z+Jas1jnX40ocHug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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=yr7EN25FGHy2WNXJ2WFtyz68nDJht+RoVhPaCGfdrMI=; b=I+QmAqWBr2jso1rXMw9zvEXLsPSai5oeLIKOv7BqHIH7mQ1KqVVkvme6xC762pv6lEeDwmtoC1Z4d/dd36JjZGJaqM6iPIKA5aYMyUL6S3QCHqhVk3JRHqV99fFg6G/zY5t8O5FcNzcvZZlDK3JewmnZNnlxl1oEUVnzfFVNg5Y= Received: from BLAPR03CA0017.namprd03.prod.outlook.com (2603:10b6:208:32b::22) by DSVPR12MB999124.namprd12.prod.outlook.com (2603:10b6:8:38b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Tue, 30 Jun 2026 07:29:49 +0000 Received: from MN1PEPF0000F0DF.namprd04.prod.outlook.com (2603:10b6:208:32b:cafe::20) by BLAPR03CA0017.outlook.office365.com (2603:10b6:208:32b::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.181.8 via Frontend Transport; Tue, 30 Jun 2026 07:29:49 +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 MN1PEPF0000F0DF.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Tue, 30 Jun 2026 07:29:49 +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.41; Tue, 30 Jun 2026 02:29:38 -0500 From: Shivank Garg Date: Tue, 30 Jun 2026 07:28:41 +0000 Subject: [PATCH RFC v6 5/5] mm/migrate: adjust NR_MAX_BATCHED_MIGRATION for testing 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: <20260630-shivank-batch-migrate-offload-v6-5-da95d7e8b8a2@amd.com> References: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> In-Reply-To: <20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com> To: Andrew Morton , David Hildenbrand , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , "Mike Rapoport" , Suren Baghdasaryan , "Michal Hocko" CC: Karim Manaouil , Frank van der Linden , Teja Vojjala , Pravin Tamkhane , Kinsey Ho , Wei Xu , Matthew Wilcox , Davidlohr Bueso , Vinod Koul , Bharata B Rao , SeongJae Park , David Rientjes , Xuezheng Chu , "Yiannis Nikolakopoulos" , Dave Hansen , Johannes Weiner , John Hubbard , Peter Xu , Rik van Riel , Shakeel Butt , Tejun Heo , Fan Ni , Jonathan Cameron , Aneesh Kumar K.V , Nathan Lynch , Frank Li , Dan Williams , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782804526; l=724; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=louhjrGsTxx8XuTEJjLwJVyFsv1SqYtF0BLxW9jEzW8=; b=YGTxxInII2RV9KKaO26F2QO52DCGpBWZN4bLeFOZ8PyXLoBL+UwekFJl79DxF0sqLvSqSbtvF Rpl6b92AaS5CXfmlAe2rhhPppaIwUI3DcVMHAw9akd7roy/ZZdGAl8x X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0DF:EE_|DSVPR12MB999124:EE_ X-MS-Office365-Filtering-Correlation-Id: 22278ff8-e138-4179-d38c-08ded6795e26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|23010399003|1800799024|36860700016|7416014|376014|921020|56012099006|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: +Xr19c5ulriDUeE5a1kvU5PIrPUFmsD5l6BCfZ0gmxUTyPGguKNxxR1vOIzD9MNyagIc5jkWLaCFIeuiJLUJkvaKpBRhme+CjfNrQUjQVlbNLuqO1u5psqRobT3050z2+oTAdUQTTDxIvCDe8if6SurZEVDOwLiezqX78Wij13b+DisRJDUCq6BkPPf7Z2mQOMjbRY/bI2nZO3MaLT+EiHZmbSn6UF4tzR4BKmxRb73PpafgKoPcB+/P7jEAVgy20QJ4LZA/PQNq6CSDW70fyCeMj0zDQVps21xX6lAICS8WeM9tcFT9woY0APKqp7tvliW43gc6m5qFswHdjTziUfZrfW5ET8d4mNtzJQr3vqmr5lW9PZ+/jbB40khPHZhDbUthdwcTjlsfT3C0EELl+TJfKW04zmV3dFzmV+uiPuVuX09c07XOUJjKrR5+c8+t4p5inNNZBCqsbWykn6TSi9NVWIqlGhlSKMln5aFQEaUmd/TgMS+ZJ9k0HXlH5Q61muHBCpF+n/wzu/Ys8OCt7gTXQTBOTS9zaLIWhXXRhN93RGA9qda1J41PyMOHoPNPexhuC7yeIwBZhj5+/ZdU0Igo/IfA6yKL33q0oxPgVJ3BCiEKm32H34cXGlby8l0UKTmCWbut+lcHB7H9s6aK8VCGJ3aEMxUNWTa0TmL3SuZTZCbRO0lEapqw7mV9hubUU4eifgJZCOQXngbRbAlYyZLjd2MPHrKJuYguKDylaCNc3nte7aNMoFBxR7X7Fnmc 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)(1800799024)(36860700016)(7416014)(376014)(921020)(56012099006)(11063799006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zv0Ys+2pwUCwIVS6OBz4ufaKblVvO5YIFSiJ7428SOXML6X3pNRBxkz357P5Z5loHfP7oka+3+H+Ei78++uHlQzlGRORI9iIM9rurU9VDOV35cit5Otw0FX4h7wEgXZWMQSLtCH8jR5XCfahyRX4+oV2MT9svCJvVyPSnDFPt7PMzHEFRJODLwCeIf60xN4xMfJEaIFhS2FHEfiQW0v4Y2cEGYlOje5MojUSUsgnpZacDVumWmow2t92kEnS4rtrT70p+nYYvKRn+LqAWkdt77ZmQ/Kpv+AhZdgWGzO88lL4q/lUZcg4q/RVSIin/+kIqvnusdoi/xPNlUPMV8L6fwX4lLQaody8ABKTarN6p5zc9sb0EVYlHI5sFwTWNuIhXojMcFdEEdmm5fVzTiT4TBvCjvDjUc6kb1rGAwPfhWTQ+xj1HY3mtNiy6OGoVW2O X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 07:29:49.1738 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22278ff8-e138-4179-d38c-08ded6795e26 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: MN1PEPF0000F0DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DSVPR12MB999124 From: Zi Yan Change NR_MAX_BATCHED_MIGRATION to HPAGE_PUD_NR to allow batching THP copies. These are for testing purpose only. Signed-off-by: Zi Yan Signed-off-by: Shivank Garg --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 4fed3110ca0a..4be1f3dc1603 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1592,7 +1592,7 @@ static inline int try_split_folio(struct folio *folio= , struct list_head *split_f } =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define NR_MAX_BATCHED_MIGRATION HPAGE_PMD_NR +#define NR_MAX_BATCHED_MIGRATION HPAGE_PUD_NR #else #define NR_MAX_BATCHED_MIGRATION 512 #endif --=20 2.43.0