Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.201.63 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796113844; b=gUqgM8R3jwllQx5qIos8Atx0rrkD3nH4OqEEv2WyUMQVOP6TRtgjyfDk270cN89zPuc6 r85isKzSDFb1A1aB7nRllGE4fw/u3WMS4lTx4HtNW5XDShz8wTRovm+GNdhE66toRCw5D DlBN3D7CRyisrSQbc25fkKYshSVQxIu4OkQn2wcdEjA0tialcdgIY/7m2sBb9yhPftCaG xnjv/Pl2yGfT6X9YKDbFWHtwz0XYspfan7jn4EYTauu/Isw52Vj0D6diHYnG5Dr79s3+1 kNZ/uMDvvACVidkaTCAgp32qu/So13oHfSqfLuz5Sm7HC7WavgO+5xPMrq9YNX6w/1A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796113844; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:Subject:Date:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To:CC:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=RwAXaamOhALWC2YRL9bdL9dXhHLnWWlv1rzzZ7m4ePw=; b=OfvCCERpV5ukAZFUXerdm/kwY2cYVtWQ63ASDURB0lWJAm+O8hypITMADtZtztfsuTmA tOo6GhuQUIMzkbsTHERb+up2f43Nos472OGdBmNn3thYaKNp/b5S6X3d4L1Sri3tcfPzZ JDo3SXPO1sXPEdVIte0exUSSgDa0efOECbiYGqQxbUB9V4Wtlzau1IjZYWAByd46ckyjg IecwbdRI9bi5CVpadsogc5095iSCujQR52wPk4ar+J1wH1W5fURAsV2O2tpIEyktnKZJP TnBsPB354xeMG//4uzgdhJrgkq1+74Enqr3y7r8OyhuFuy4isQmclOXht/AjKHW6mBw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Tdgn+v36; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.201.63 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010063.outbound.protection.outlook.com [52.101.201.63]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16101606A327 for ; Tue, 1 Dec 2026 08:30:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16101606A327 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=Tdgn+v36 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fxjGRswP/eUNEzPt0iiHMt6KCTMdCTJyzqkX11OT8CxjGvUe6eNCyeM5Bu36+a9T6c82LRCps0Zb1I63IDBaQjH5wNRUAY/MGDzEiDgOoz6mbAv3WizJMYvYws2/lNYr3NOt1yWnx8n51+BhCegzeu422CNpbznfMZCVeFRnVr43hrzryDI9n8jO+X5kI2apL6cg7u8KnmJbpIhsxToE7yKxWywxfsAVBMT7QrlREVvWzvMTLfWI3ClqvHBOiq5nc+y1qMW2o6Q3FZt13BdHCrUzxkbcu1bmksa8UP8Oba0DaP7SwAPqAgeyIAin8Mc8tCqe2Ko8IdIjBy9E29bPOA== 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=RwAXaamOhALWC2YRL9bdL9dXhHLnWWlv1rzzZ7m4ePw=; b=kQp0NnFED58pcZil+aa9FEweVsAmJJGMaqvdz563iXNsgUziE6J7MTCW2JmPKOB/Q3qCV6eP+hzNAyt++f2fJjlvgF0CRJOK+AB2yGxyx/RwSlIikKjmeyytnUpiNtqSgGnDlRyLkpovPH/1qT4HoLS9pxcBdKy78Uc6Boj0QCmq13RMKQun44aAToFRoHCDpSw+oPAex0cSL80+Vbm36u4Y/Ti3k7NeGahj/o/X+KI6+NjQyU6wNs24Nq9vlUKy5oA5iARTTgejprXWVKwKR4uDn8w8WGWhIRPtInVASjzJFX0VvNo3YiLhjsLogHI9OruOFOVTko7hoImRtADU9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=oracle.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=RwAXaamOhALWC2YRL9bdL9dXhHLnWWlv1rzzZ7m4ePw=; b=Tdgn+v36n5MZpXNT6Pz/R/CTREl2G4FhEpnHLMxn0s3SCgDNhmRM/IAxjshRrMO2348Lu8uqfZqK8oGNqdSAUiarTgi8sSexBiILC7w6+y2SKIwTgcYUZMgN1BuG4dm69fI8q82UuEU8YnyNbyn1wrVdfN3piA7sbm0qqwM6PzQ= Received: from MN2PR13CA0020.namprd13.prod.outlook.com (2603:10b6:208:160::20) by IA0PR12MB8984.namprd12.prod.outlook.com (2603:10b6:208:492::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 08:30:37 +0000 Received: from BL4PEPF000003EE.namprd04.prod.outlook.com (2603:10b6:208:160:cafe::69) by MN2PR13CA0020.outlook.office365.com (2603:10b6:208:160::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 08:30:37 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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 BL4PEPF000003EE.mail.protection.outlook.com (10.167.249.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 08:30:37 +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.57; Tue, 1 Dec 2026 02:30:28 -0600 From: Shivank Garg Subject: [PATCH v4 0/6] mm: copy page ranges with one copy_mc_to_kernel() call Date: Tue, 1 Dec 2026 08:29:46 +0000 Message-ID: <20261201-batpagecopy-v4-0-dd82a573e573@amd.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/1XMQQ6DIBCF4asY1qWBUUrtqvdouhhlUBaKAUNqj Hcvumldvpf838oiBUeRPYqVBUouOj/mUV0K1vY4dsSdyZuBgJvQsuINzhN21Ppp4QqhqVQtBSn DcjEFsu5zaK933r2Lsw/LgSfY38ORQtYnJwGX3GhF2ghjEemJg7m2fmC7kspfKWV5LstcQq2ta sAauP+V27Z9AStme2TeAAAA X-Change-ID: 20260714-batpagecopy-5a2b45910e5d To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Borislav Petkov , Ankur Arora , Dave Hansen , "Thomas Gleixner" , Bharata B Rao , "Hrushikesh Salunke" , Ingo Molnar , "H . Peter Anvin" , David Laight , David Rientjes , Linus Torvalds , "Teja Vojjala" , Huan Nguyen , "Pedro Falcato" , Peter Zijlstra , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Ying Huang CC: , , , Shivank Garg X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1796113822; l=5932; i=shivankg@amd.com; s=20260518; h=from:subject:message-id; bh=6h8SSDk9xCAxQUah25WhzP3oux3CIrZhUifcRZrWMDw=; b=+za1rlsi+pR1Jr5oOpmu15MUm13RDKeQ1C7WYUvrGF8dDaPIFNU8kRg7+t45oAxWUuZtUQ9u6 nvxJKJ2U+pcBE0YAX4XqIrNVV/b+KQxzrCp7Y1zks9Cugtp36s8XMnU 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: BL4PEPF000003EE:EE_|IA0PR12MB8984:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d053bb2-9f66-48bd-1442-08df4f856020 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|36860700016|376014|1800799024|7416014|11063799006|5023799004|261009223027099003|18002099003|13003099007|921020|56012099006|10067099003|261102123227099003|261022105027099003|261022075727099003|261022113327099003|261026121527099003|261028144727099003|261021123027099003|261026140227099003|261021121427099003; X-Microsoft-Antispam-Message-Info: JT00aX7QWBMycGt4lEmVLf4jCH/sfzjK1QykjWwNE6WuBb402a+Gt1CwUINPaNlR/X2HUzG2CZ8j0S9FvQ60x1TrBLj+vSWe/qQPX/HbPlT8FlXb3lug/yO+3ntlE3Gbhe/zHbYYX+Rc2+AhTtR5Q/X6clmNEf7SwV0rhfIw73S+h2vyNaFVdi8AVNkZ6TqRv/Be42xjRG720nAkLvrWzJnWyEfBVJCs0ye21i6BTdUhzJhC/A/WcgjOylQGJoRMqDZPG6vKG+DTmQ/x0jIRCvJzdG6Bt/kgOQI2y+KVqA90nnYJPR4yodXmVMWjyKq+gGATpG7iJ2yXnGVz2dvpn5qDew3uCkNTa1Yv0ey3pu9cINM7dr4TyiRtRS28in8cr5Eb78fTLKGD+h4PHt+Ox8dNGZzYqcFj6AGfBaK6XDiLJpAe5KBaMAfpGU6M+QMyCsiAQO4T+A3bLOEZhC2VafOoV/hVSc2L4q8ejPh3skS+Kngdv3QBUOnGRZRPoPQTajCEaEkCxCXERl/BTIYFVwrP0JeCBcyFN8H7lBQvZkXo9dnQmu4aXUi/UZ6CHyVhGMyfnVg0acAE06M+fFtj0GIzaAa7j4X3LuSCyqAz1XMBkV4HLb6z5ZOYUFPatsb0S3fXBxLdsYgmLejtM86Qb7VClpuSdVlZFFL+AGcfNuQdhKQ+YSqqygMku8L0QFQXCEDUEoBjm6UdBS9gdctr3g== 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)(82310400026)(36860700016)(376014)(1800799024)(7416014)(11063799006)(5023799004)(261009223027099003)(18002099003)(13003099007)(921020)(56012099006)(10067099003)(261102123227099003)(261022105027099003)(261022075727099003)(261022113327099003)(261026121527099003)(261028144727099003)(261021123027099003)(261026140227099003)(261021121427099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BwaSsTUKzWbZBeyDjftHvaMnjGXah02AGogwv89yIs9DNFDETkUBswviqbl/2Nfbjtc6ql4k77+5d7Kbq+6SAXbGCiXdElyJi8eNwqLuUNfVHSjozyuzCOUUnBhBoh81gg+Dj55ibi1fLVhSHiZvTTq3iZ06FPCkGNfaVPVCG6PmepswVBYmmnMfxJOMkT7jr3MupkgFYmo167njypxsztoD2rXF/QXfSEYkj5JkgOENDY9nbqkpsPMZ9a55A00yiXciiNoG4UQ28sILtxmpvKHRPALluML0YLhi4VybVBjxkxrmaAtuUSBLcCRhEuY2Iig1Ymja5mUR2pwF/Ilu+rTEtGClDZeallQD4AmHAz/1xNN6tlAv8/0DvfcQocygNyxpFYx4sefzGChmujN9l/huMRK4Aoy8gs/iu36RkEsvO5dPiiDpV/uQHrYPg/go X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 08:30:37.1424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d053bb2-9f66-48bd-1442-08df4f856020 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: BL4PEPF000003EE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8984 On a Zen 6 system with CXL memory, move_pages() gets ~1.4x faster for 2MB THPs and up to ~2.8x faster for 1GB hugetlb pages, and when demoting to CXL, kswapd uses ~31% less CPU per GB demoted. Hugetlb copy on write gets ~1.5x faster for 2MB pages and ~2x faster for 1GB pages, and MADV_COLLAPSE of a tmpfs file made of large folios gets ~11% faster (numbers below). Copying a folio with machine check handling makes one copy_mc_to_kernel() call per page. This series copies a page range with a single call where possible (x86-64 and ppc64), for folio migration, hugetlb copy on write and khugepaged file collapse. Test setup: AMD EPYC Zen 6, single socket, NPS2 (nodes 0 and 1 are DRAM, node 2 is CXL), base (mm/core.git for-next) vs the whole series. move_pages() throughput ----------------------- A single move_pages() call migrates 1GB of anonymous memory, as 512 2MB THPs or as four 1GB hugetlb pages. Mean ± stddev, GiB/s: 2MB THP: direction base patched speedup DRAM0 -> DRAM1 19.57 ± 0.17 27.51 ± 0.78 1.41x DRAM1 -> DRAM0 19.44 ± 0.12 27.33 ± 0.27 1.41x DRAM0 -> CXL 18.66 ± 0.18 26.90 ± 0.51 1.44x CXL -> DRAM0 15.38 ± 0.59 16.60 ± 0.24 1.08x 1GB hugetlb: direction base patched speedup DRAM0 -> DRAM1 20.34 ± 0.13 53.88 ± 1.48 2.65x DRAM1 -> DRAM0 19.10 ± 2.65 53.78 ± 0.55 2.82x DRAM0 -> CXL 19.53 ± 0.08 44.10 ± 0.19 2.26x CXL -> DRAM0 16.41 ± 0.07 20.89 ± 0.06 1.27x kswapd demotion --------------- Node 0 is limited to 16GB of free memory and demotion is enabled. A single thread bound to node 0 writes 96GB of anonymous THP memory, so ~80GB has to be demoted to CXL. base patched kswapd CPU time 4.25 s 3.44 s (-19%) kswapd CPU per GB demoted 63.6 ms 44.1 ms (-31%) demoted by direct reclaim 14.1 GB 0.46 GB allocstall 7427 370 With the patch, kswapd keeps up with the writer, so the writer rarely falls back to direct reclaim. MADV_COLLAPSE ------------- The thread runs MADV_COLLAPSE on a 1GB tmpfs file (huge=within_size) whose page cache is made of folios of one size. Time per 2MB collapse in microseconds, mean ± stddev of 30 runs over three boots: folio size base patched 4KB 234.0 ± 2.7 237.0 ± 2.3 (noise) 64KB 95.2 ± 1.8 89.0 ± 0.8 (-6%) 256KB 69.1 ± 1.6 62.7 ± 0.5 (-9%) 1MB 68.2 ± 1.5 60.6 ± 0.3 (-11%) hugetlb copy on write --------------------- The thread writes to each hugetlb page of a MAP_PRIVATE mapping of a populated hugetlb memfd, so each write takes a copy on write fault, at the first or at the middle page of the folio. Copy throughput (GB/s, mean ± stddev): page size fault at base patched speedup 2MB first 22.40 ± 0.23 33.46 ± 0.65 1.49x 2MB middle 22.76 ± 0.31 33.37 ± 0.64 1.47x 1GB first 27.10 ± 0.03 53.25 ± 0.59 1.96x 1GB middle 27.10 ± 0.03 53.35 ± 0.57 1.97x The new copy order alone gives ~15% for 2MB pages and nothing for 1GB pages; the rest comes from the single-call copy. Changes in v4: - Convert copy_user_large_folio() to copy page ranges with the new copy_mc_user_highpages(), and drop process_huge_page() and copy_user_gigantic_page() (David). - Copy each folio with copy_mc_highpages() in collapse_file(). - Move the batching check and the single-call copy into copy_mc_can_batch() and __copy_mc_pages() (for copy_mc_user_highpages cleanups). - Link to v3: https://lore.kernel.org/r/20261113-batpagecopy-v3-1-297f5b2fd28e@amd.com Changes in v3: - Copy the whole range with one copy_mc_to_kernel() call only when CONFIG_PREEMPTION is set, otherwise copy page by page with cond_resched(), following clear_contig_highpages() [1] (Pedro, David). - Handle the machine check first in copy_mc_highpages() (Pedro). - Rebase onto mm/core.git for-next. - Link to v2: https://lore.kernel.org/r/20261019-batpagecopy-v2-1-d75e7d0dfaae@amd.com [1] https://lore.kernel.org/r/20261109-clear-pages-batch-v3-1-6693efe18dff@amd.com Changes in v2: - Drop the folio_copy() changes as there is little to gain here. On architectures without copy_mc_to_kernel(), copy_mc_highpages() falls back to the per-page copy_mc_highpage(), which ends up in copy_highpage(). A batched copy_highpages() could help there too, but I haven't tested it on those architectures, so that is left for a follow-up. - Add COPY_MC_PAGES_NON_PREEMPT_BATCH to limit how much is copied between cond_resched() calls on non-preemptible kernels. - Rebase onto mm-new (2887e63d2e8e). - v1: https://lore.kernel.org/all/20260427142036.111940-2-shivankg@amd.com --- Shivank Garg (6): mm/highmem: introduce copy_mc_can_batch() and __copy_mc_pages() mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy() mm/khugepaged: copy each folio with copy_mc_highpages() in collapse_file() mm/highmem: introduce copy_mc_user_highpages() mm: factor out the locality range computation from folio_zero_user() mm: copy_user_large_folio(): copy page ranges include/linux/highmem.h | 105 +++++++++++++++++++++++++++ mm/khugepaged.c | 14 ++-- mm/memory.c | 183 +++++++++++++++++------------------------------- mm/util.c | 14 +--- 4 files changed, 176 insertions(+), 140 deletions(-) --- base-commit: 89b4b2b15b2063e1bf593e609c3c63313b7ff160 base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next change-id: 20260714-batpagecopy-5a2b45910e5d Best regards, -- Shivank Garg