From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011019.outbound.protection.outlook.com [40.107.208.19]) (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 D0A092F3C18 for ; Thu, 13 Aug 2026 04:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.19 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786595052; cv=fail; b=CrScwg3ix75c2jSnAgNShQy0tN1w8KPkAaYV6ft/cnLQgrD2Ktzrmx3Sd/tqp5fuN9IYcFZ/LF9X/DBwd5/3QlMc/ezk7prXlvE53k5m5P7E3w6fdEFIo1hSZYi2yBMAzAxJkOTeKWb3XXHkFkcdX1ndaezDvywRbSdfyn4S7E0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786595052; c=relaxed/simple; bh=xe4BZIjXZM9ZhoVG0Eqce2EArkF6gFItyVhSAUWvPhc=; h=From:Subject:Date:Message-ID:MIME-Version:Content-Type:To:CC; b=PWxbFEJ5pD0xTfWp52HTiPFANCN1upekLatZ+fJ6c7Z9L3BFlkne3hSmbf0XRFw0s8db2VVYVbRe30Rk6gjk16GqK+7/fHTlOD3nc9Gf8AqE9WP23QPMXMP+abJxNjkoBJv5/C1W2wQKTJe8z3iMdZv7thOJniH4q3asPYeBhlM= 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=JvQJhrB+; arc=fail smtp.client-ip=40.107.208.19 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="JvQJhrB+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HIqFMMtBABNmJzmM5cdl8FJJoKwtFTQZ27+wol8ugYVAEK8WNdh2F0CL15gST9o9iCV5eRIZPYMIBlqpDPaW4ZyWSTTL6tTzQ+6PTWjEOKkEFXklQh6Gyn3kzSfhzaX15hSNpfGzyS+GUkUmssGotgW3K1CIlOOHM4iriNXvxyBqQHLnpFoIhcq2Gn5VdGJfNv787tzgb9zGj1a9ogSLGpoRLDQGaXIFqq60yfeVAhyNtfYDxDpF/gpEnWrm+AzuVdVkhlnLeHvrIMvRCZhjw+JXty8SFIUlJL3L4fmmV7QRz9df2470Mx9+RXAvZ8FHTs2Z3bdY2etrj8euExCY4Q== 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=Eu9GFJTQwVksG0ljZo5TRaZJVYXxADbehGMutWJQUuI=; b=JcTFbtJbCy9MiZW8T1wsd/wqYISN3eiP4fWWl4Gdgxh7XpLL2Xa2LcA8RwsCpVBp4tokQ4SD4Mn5La9kYFgsEW/WNK7hC5GnLd4utvUcbbW+K+EjEQuU2gZBh/TLasMg79eCzLulIhK772MkUGfIXj8vGwy15YRTwXFkHMGN/+Z7sIoq/JzO1BIlZb1GDP4t7nPFu42kp5CAkf2U7YIdZbVtqxlbqIaG0IxrZyPSHuRFqeIs4VepRFJNJoaQ6VfC9uKsTCUHqs+5cOmsgYwfDeUCsjRrwGnUGlcurPRFJfzuHlCsPibdHBZ/3AV6+NSWRUkQAyyN2T02vjaonhMpVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=surriel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Eu9GFJTQwVksG0ljZo5TRaZJVYXxADbehGMutWJQUuI=; b=JvQJhrB+bWgu2sAatQcsdQ3q1gE67xP+ABiHj77Sv6e5AgU4DWpC9hnl8RyG5ZYqO79JHbdkAXRKN6KZYqnaXfzCk4cjI5TMAHDM/iTt7lotOFWLOx9HQWF+re9I2YH7odtGR4dzHgM1ecZds6MF9j2jPpV3oq1O6Vp/J+JxUX8= Received: from LV3P220CA0014.NAMP220.PROD.OUTLOOK.COM (2603:10b6:408:234::14) by PH8PR12MB7205.namprd12.prod.outlook.com (2603:10b6:510:227::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.315.11; Thu, 13 Aug 2026 04:24:03 +0000 Received: from BN3PEPF0000B373.namprd21.prod.outlook.com (2603:10b6:408:234:cafe::3e) by LV3P220CA0014.outlook.office365.com (2603:10b6:408:234::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.315.14 via Frontend Transport; Thu, 13 Aug 2026 04:24:03 +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 BN3PEPF0000B373.mail.protection.outlook.com (10.167.243.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.339.0 via Frontend Transport; Thu, 13 Aug 2026 04:24:02 +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.45; Wed, 12 Aug 2026 23:23:54 -0500 From: Shivank Garg Subject: [PATCH v2 0/7] mm: batch rmap walks during large folio migration Date: Thu, 13 Aug 2026 04:23:11 +0000 Message-ID: <20260813-migrate-rmap-batch-v2-0-3c5424c555c7@amd.com> 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: 8bit X-B4-Tracking: v=1; b=H4sIALBGfWoC/22PQXLCMAxFr5LxukptJRBgxT06LIStErejJLVNg GFyd4yz7U5fM/896akiB89RHaqnCjz76MchB/yolO1puDB4l7NCjVvdaQPiL4ESQxCa4EzJ9rB ja3Xr2Oz1RuXiFPjb3wv067TmwH/XzE7rUgnHSIWdVYWMTabnft20iNhtwYDjuf4hPxwpSG1He aPPFBnyLD4dKvqdBEQ+RWDgm3qreh/TGB7lndkU18o3+N/lswENuw6pa9q2Mc4cSVxxnZZleQE zr3MfHQEAAA== X-Change-ID: 20260701-migrate-rmap-batch-8ecc04de1905 To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Rik van Riel , "Liam R. Howlett" , Vlastimil Babka , Harry Yoo , Jann Horn , Lance Yang , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , "Alistair Popple" CC: Karim Manaouil , Frank van der Linden , Kinsey Ho , Wei Xu , Bharata B Rao , David Rientjes , Dev Jain , , , Shivank Garg X-Mailer: b4 0.15-dev-47d62 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786595034; l=5059; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=xe4BZIjXZM9ZhoVG0Eqce2EArkF6gFItyVhSAUWvPhc=; b=xQO2vyhrB4clraVC7Y/TJnDwQX3ykIpqN9KBxyp3HX+1N6AEfPFkkrH0XLfveTVXZVqKWjI8f tD6uZccbbupCswo++MsH/I9KxaEM2qLW5UIHlldDw/SaqO8FnpCBStm X-Developer-Key: i=shivankg@amd.com; a=ed25519; pk=2l2QGTeXuGkZTtfmx0nPQU8iFZfjYmX/ymMojitevx4= X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B373:EE_|PH8PR12MB7205:EE_ X-MS-Office365-Filtering-Correlation-Id: 108731c7-ac0f-4775-948b-08def8f2b49c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|1800799024|7416014|376014|36860700016|82310400026|13003099007|921020|10067099003|11063799006|18002099003|56012099006; X-Microsoft-Antispam-Message-Info: PsycChmP3FSW5DEsI0AMaMCTSRDOhx2D5c5KfF4GMKetKOJVM9eK4sE/toL2E+Fl0MNY72VKonMHbGfgl0WCcNNHEZVTwWFXEu0QjW2ldMWxY9f1XA74UPgYZTJlaZPILVQ1K39X5WzMd1I4/f86/1pskc0RKzKcOwQigIDxsQXN/AvbU3VdKU5nLZ5WYNevhMXVOC5t+hOSZlZz08tfh0NgZwVK2iDV66z6eTEO8Hb2YBmYdElkOXkNAFHU5uaiQvAnUSgJAZgFzXG9hIKIj86fyc2pOvLpGJhtlh9BEJXzuF0gtYyP6j3dbzs0IbWDnSGch9p56R/FSuNC7/44kbW0ZPP+fMSe96kfxWUzi6bLjYx0v6XGVmo2JdrgGbzXujkrR0NKC2c6tJHX4bFoTO+c3zVMYZoHUgoUNGJ0BPUZIZOb5C50OhvaSMy4CMp9Y/7qlJTDBPweMuKzbjz3gigtkwAHcjSVrUb46B0HsQYg+/Pe4/Gi+LsoGVqc+yKXcQlQgvIQus5whDtYk5+JkNfCrEdc9MWOA6LRqgbAQV9H6RLQ7p8QPpl08EkToDNHCbaArv8QGXZ1e9aPuICXyhyiBNGrqMCXvkxQFxTFJ2N/cEZuy4Ty+FmazU58IiAZYmhFTpdlTYMtH01k9EGg6qXyTZW0C6dhI5OBWWyWVz+wnr0S7nC5ou+xb/VZWiuk6HwUENxxRfyLAeCzpJkQvD7BL8CDcINjLEN8iYJTuchJA8GD4sEOFkDtlFiwzIZZ X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(1800799024)(7416014)(376014)(36860700016)(82310400026)(13003099007)(921020)(10067099003)(11063799006)(18002099003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6xESeZUaesSXqvEynUXbpGgo/au0UzpfJsVo22bJS1i9zh7RkutOfCR+bDHjkwLew2g8uy1709uTjJ74E8zbVdINk9X5rB3btEoEN5ITaof8ufXhV+EtxbfYhK0LTPo56t8bRsAaSjA5jUIhaG8ZJYO/gceJp59k15D57e9/yUjCWgzFk4H2tqLSH2ncr938LtWejIEkZprSeoxTpJugi5HGB+O3Qw+KYBlXZJQeCbKwAU0KwwzYEphQewTf+42NCri5FfumXl1JX0To0Y8jrdfauEKUrbO7qBWMm4j6O342gryJseETzACOGljAETLYi2X8gxBjouIb8rXIRVjowsNwphnWGMu45PxWKlGGKDL2Nldr23HDe210Oc64q+6BKStzpzQh+D4owAXwjz3ABEn6pVbhkhLtLKpQ0VMYpigA5PxcpfY7CNLOBnp40I7H X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2026 04:24:02.8738 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 108731c7-ac0f-4775-948b-08def8f2b49c 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: BN3PEPF0000B373.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7205 Migrating a PTE-mapped large folio currently walks the folio's rmap one page at a time. It does so twice per migration: 1. try_to_migrate_one(): Replace present PTEs with migration entries 2. remove_migration_pte(): Restore migration entries to working PTEs. For a folio with N contiguous PTEs, each walk repeats page_vma_mapped_walk() and the associated operation per subpage of the folio. (256 iterations for 1M folio). This series enables both walks to process a batch of consecutive PTEs that map the same large folio and do some refactoring and clean up on the way. Performance: AMD EPYC ZEN 3, 2-socket system (1 node per socket). move_pages() migrating 1 GB from node 0 -> node 1, throughput in GB/s: batch- batch-restore folio vanilla restore-only + unmap restore% restore+unmap% 4K 2.96±0.15 3.02±0.14 2.99±0.17 +2.2% +1.0% 64K 5.99±0.10 6.12±0.08 7.65±0.16 +2.2% +27.7% 256K 6.48±0.09 6.67±0.08 9.23±0.14 +2.9% +42.4% 1M 6.76±0.10 6.98±0.10 9.74±0.19 +3.1% +44.0% 2M 10.50±0.20 10.44±0.16 10.67±0.21 -0.5% +1.6% In plain migration, the folio copy itself dominates the cost, so these rmap walk savings are only partly visible end-to-end. When the folio copy is batched-copy and offloaded to DMA engine [1], the copy is no longer the bottleneck and rmap-walk batching translates into much larger gains: This series + [1], DMA Offload on PTDMA (DCBM), 16 channels: batch-copy dcbm+restore folio vanilla -offload(dcbm) dcbm+restore +unmap (rmap batch impact) 4K 3.05±0.13 2.76±0.11 2.77±0.12 2.74±0.09 64K 5.85±0.11 10.66±0.27 11.56±1.45 17.55±0.56 256K 6.26±0.08 13.64±2.73 13.68±0.16 34.76±0.57 (2.54x) 1M 6.58±0.08 14.25±0.07 15.27±0.77 44.28±0.27 (3.11x) 2M 10.61±0.24 65.26±0.96 65.25±1.65 65.66±0.87 Applies cleanly on mm-new+[2]. [1] https://lore.kernel.org/linux-mm/20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com [2] https://lore.kernel.org/linux-mm/20260723070905.3422276-1-dev.jain@arm.com Signed-off-by: Shivank Garg --- Changes in v2: - Rebase onto mm-new, drop the borrowed folio_try_share_anon_rmap_ptes() patch and add it as dependency on Dev's series and adapt to recent migrate/rmap changes. - Switch to recently added batched helpers - finish_folio_unmap, set_softleaf_ptes, and page_anon_exclusive_batch. - Rename migration_softleaf_entry_to_pte() to migration_entry_to_pte(). (David) - Split PTE construction from hugetlb handling into separate patch. (David) Mirror the split in mm/rmap.c patch as well. - Rename make_migration_swp_pte() to make_migration_pte(). - Early exit the single-entry hugetlb page_vma_mapped_walk() paths - removes unnecessary nesting. - Add the missing page_vma_mapped_walk_done() in remove_migration_pte_hugetlb(), which leaked the huge-PTE lock. (syzbot ci, Sashiko) - Fix handling of hwpoisoned subpages in the batched unmap. Read PageHWPoison() once and skip batching when mapped page is poisoned, and use same result for hwpoison handling. (Sashiko) - Remove the pte_unused(pteval) handling from try_to_migrate_hugetlb_one() (Sashiko). - Link to v1: https://lore.kernel.org/r/20260712-migrate-rmap-batch-v1-0-872a734431d1@amd.com --- Shivank Garg (7): mm: factor out generic PTE batch detection from swap_pte_batch() mm/migrate: factor out migration PTE construction mm/migrate: split remove_migration_pte_hugetlb() out of remove_migration_pte() mm/migrate: batch the restore-side migration rmap walk mm/rmap: factor out migration PTE construction mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one() mm/rmap: batch the unmap of large folios in try_to_migrate_one() mm/internal.h | 36 ++--- mm/migrate.c | 191 ++++++++++++++++++-------- mm/rmap.c | 419 ++++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 416 insertions(+), 230 deletions(-) --- base-commit: 480a31230b426efb005b6e71a14ef80f405f18b6 change-id: 20260701-migrate-rmap-batch-8ecc04de1905 prerequisite-message-id: 20260723070905.3422276-1-dev.jain@arm.com prerequisite-patch-id: 5fdb03c3ea4a037f66fbd1c9b5d04e24e86406eb prerequisite-patch-id: 033980575a1ef89d70e43a67c5530e2cf6cf97aa prerequisite-patch-id: 6f7508334fc2bfc0df104ac50d36ed88072487e4 prerequisite-patch-id: 3f1aaae36e02d8b9343f7e719f732f10c1767572 prerequisite-patch-id: 98bc99c6bc274594946d022b3998f5f1dc70012f prerequisite-patch-id: dd35ec00b82bf235f2e41e286d16eab6a3fd1e9e prerequisite-patch-id: 552ee939dc6a7b3cce51373f4e75fa01a9d2b979 prerequisite-patch-id: 485cdbbe4e65b13494dc5104d4b8b7d0d23911a4 Best regards, -- Shivank Garg