From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011030.outbound.protection.outlook.com [52.101.57.30]) (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 720DF314B63 for ; Fri, 10 Apr 2026 03:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.30 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775791429; cv=fail; b=YZ6FnbmA4u/BQLKqCIBsyqG76k1buuv4WBs2rhCfjjF+aP5HLn/6YizuAqJ7s2FmNF0cKvZmjIYpUkDNWM/OZh32DwwDEkazHgCL3Kucehu81QbNEHFY82/Hug9SGv6F8KNNekh4WVNmWyMTYzaGwVSpb0CqrFMGhXDxN4yka6s= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775791429; c=relaxed/simple; bh=Yz8GjNNGwp/uN+JBJyjFg+4SYAaQ+IhY6t6j9z1iW08=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=ba03BD65U0/JImc4UucYvvFFdA6e1nJa6haw3LwZF0nSbfrky/lohUixSJ9UcSbvbMgn8XZsSasni0BcJmQI2TQlriVSkDLw632nenVXJ2XdKf5xC9cJnmNAyt52ZUWnmHGXd6icg7J5wCZqwHTw8Vy+8QSUtt5UE4tR7nqWsng= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=S68G9wHQ; arc=fail smtp.client-ip=52.101.57.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="S68G9wHQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P16u1yw8+fQ2SmoKUF3fVgqjt1UqY+b/mkfRDJuPaEyDttTdTzBhJfDNnxSL7VmeU2oIF9lzrbfQeamnHO/ySkA/Mbs16xCGgiKQ/2FzkqCF7nR2+ILwSXWhIabW6JJfvlloHHni7XZU6sFY6N1b6yK9VtkAOIJhIOuNzqQ5m+tZ6HukZQvDd8N6Zqy+cgmUZWUhDBded/BoSEdb6xP6TXdOVPN5aDg8mNZDYJogQjKaqs90GBb9/fIR1pV3w8/KG2lKqe3rJgtX8RgsOQJDplkZN8parQczlaSlrgyduRlxfrIPohv10yETBERv4yBWBrCilATDhdl9pbF71u6YfQ== 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=ywfFR5zYQTMTN2u68wXONnU1rW4L/0c0JjM29ZLB0pA=; b=P1JxBt7Ea2YlVesLyzaUkHEv3znEydX09vXT0X9Sk2UM5T/i1wgIKkWAeRr6rH0XbeftlKH7JjObngc1aEek+STIvnVHrzOafD6x3g35Gblw2CYGzIdt++tEZl+by1R4cKueYHzJSfsuQ3BuRXz+wrDzKT5dG10rm+m3vurbD/C61P/sFaxw7pisf/K7LKmQR8YINMvuYVbWDcO7EFvx4ItUwNXPj/R0mYv7aKO+Y10mJ+qbs7+n0dSoZ4IZ5wOkp4O6B4Q0bNNMn+K+c3L52QnyHiDRsklxTBirW0yufaKEz1l7a+7QQ8DOQ1uRksIVz8X1RowsTtNXtWp/xxHoUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ywfFR5zYQTMTN2u68wXONnU1rW4L/0c0JjM29ZLB0pA=; b=S68G9wHQXy2tkl9O/l3PKqZVaACvwBnj3hm0vx4umVqvH9z4tLygFKZrkE7Vix9CEM64wwkreGCsUZPVSMHBA5sOLbCJWyQD/ojDiMp39aillOcM12BYPm2i6sGWsrGVPcAhBxbYQAFnuguF+xXFoE+/IbuFOYL35O7iZJ/7qEQ3QmJPZ4CjASn9A058CcbScD4cAXNxR+aQWzrRzaV+7LOVNcBExzy+uetBy39tGG9c3Q9JkyEBUtKprWe4MYaBlU2m23q2BRKyX7wRy9yA3FiYNx82bHDmOOhJlx1/0/qRLRFe1r1pJr7gzI/JkmF5aijF44BVADp4Y2IZ0OfwOg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) by MN6PR12MB8472.namprd12.prod.outlook.com (2603:10b6:208:46c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.21; Fri, 10 Apr 2026 03:23:35 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%5]) with mapi id 15.20.9769.020; Fri, 10 Apr 2026 03:23:35 +0000 From: John Hubbard To: Andrew Morton Cc: David Hildenbrand , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , LKML , linux-mm@kvack.org, John Hubbard Subject: [RFC PATCH 0/2] mm/migrate: wait for folio refcount during longterm pin migration Date: Thu, 9 Apr 2026 20:23:31 -0700 Message-ID: <20260410032333.400406-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.53.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BYAPR08CA0070.namprd08.prod.outlook.com (2603:10b6:a03:117::47) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM3PR12MB9416:EE_|MN6PR12MB8472:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a08c36a-17be-499b-233a-08de96b08cab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: oHQlrSRACNyoWqz2oNg/KHjixeRwqs2RKFwkpMolmJNDbTKebSRdw3pHUbU0Ra8OKAhaUD8+1Iand5MpsEYn33fKuur3DUaPrSLuRH2lZE8WgqCu+WJKuE3miZKDcynsTrM52BUoybDl9mnr4YeeUNd4U/faE67LI/i1240RavQk7FDkhUpj5Na+d7RsFCjV3AfsxpdH/Hl6A68GquQEY5kd7e8sTEDmyMkmXZL35A7M/a4KsMSAapORamY8uGUGntzyk/wqgWmzCnkFa/C3QkqJuRISPPJA2z+I+NhNZhlbmqA5aQ//zeSQzRLQ/ZwVHN1f5XnGqLAIdkQ5vvSeFzFIteX2G9ChTWkCSOgy375MuWh61vQ9J4H/b30+qQX/Hwe2KcLSvjeDUICpY1kOJoofvXZ2jUXmFGf03DrbgtmnW+hKup7065244bXng0iE28oRl1q4NdNy5H4ZMhOzu9VHjbO1LE5PtMmrFMA36zhg+HvlWa5fL1KZ/33liY1iTcl2fKUFRPcMn8FlbP1TKS3Xak1biF0ZR5+xCt1k5TRyPzVIU9UVjl6xtP0XtY2X4MRuOZ8vRWrJ8013du5/t/d8/jF+YOC5BicgHWzL/zBgBM/oqVcGYrOp5KvL5GETtvdV+uRJ3y+q9VVyXTCd5klDXCPMkboRwZLvZ4vy0THZtFqBsv4rSOHDb+HrKECqnKB75N8tn66mrMxvFciC/m31ONBebOuVLGagsPp4iS4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM3PR12MB9416.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?xh0wLTYqlE0bgZDd01LY1Ij+1QJH3E+11dqqjaAnVDbuzk7V4yyRxPBhZUND?= =?us-ascii?Q?9FBncxTsE7eMO1H+bEz52JTQ0CFAZNyRNRm3EBk4IWKcbV8kiM+1MFBc4kxX?= =?us-ascii?Q?fD8gWpWsKJHP1AyG9DYI8OIKVTH+gGs7gcwtB4aIngGJkkbymAYcjetoRi5a?= =?us-ascii?Q?d19fdzpIOMau9RLNt8NOX5r0dz4J1HTUoau2AUyvmHOZv3dFL1FcH6+GRW+Z?= =?us-ascii?Q?v27Om2IqWS3rgtpimCFzAJ4CSvXaFlv/v5PrgMIiCcA1bTXtNVbIEJJn2T6A?= =?us-ascii?Q?NYadR8PxhFm/B0zPPj3JmK1kiGXPOMf0vuLgqsj8cZbLbJr5+RB4srOwlaJ4?= =?us-ascii?Q?zl/l1x2t48WxRwbdiTguLhduVwpx9CKihzQFcxTvRs1lKlWG0+FYARCP2ifV?= =?us-ascii?Q?zwZFZw0q+e7ZI1l2GWONk7OEzXwwZtt8sOyviomQnAqV/rmt9z80CRSg50fV?= =?us-ascii?Q?pwDjnMmJZ6hs3jCVjXoq0cxraVA6onY1C/33DTIRFDuy9zUDR00awsc2bXK1?= =?us-ascii?Q?bAmWZ45fQgMd7EaMG/Ba8jxanjzu1i6ApfizbW8lRMWtyvtlryRfgDnFbFYl?= =?us-ascii?Q?TyANHh5IJ3B26ORzzkaiNaMz5aUW2qYj1pweOS3+Eck8DrbtsJFR4qrKHcyd?= =?us-ascii?Q?09DYZNccHKoxOhEXB7vnVzuNdueI3ioEUkMRjfN/8c1u8KNbYU0xG9URHGAE?= =?us-ascii?Q?P5Sw4qSCv2mOD3UJ9KbQutydbLfWUgk/gS3aTJlSFukp/PVTCykae4PBrfeC?= =?us-ascii?Q?z1WhjwzJosMKslrXByhlHLXGm9YC5SVTQjS8LVW2dOS7uBxsXktlRMu1OpVd?= =?us-ascii?Q?OkblcVk6tS5UriPk9X7yq+FEscJaOg36z5qUdlhPB/raAlmavx+vxo4/hRNr?= =?us-ascii?Q?Zxr15Wyq5VJn3txcfGvp1f2D55RavEukUerT1cq0lCc1b7zu6be9gpQxh0xd?= =?us-ascii?Q?W1Cj+ClgHCMitmlWvRBljDUcGwcusloB1HEH/VXThEqh9iPmsU6z1tzFSTbz?= =?us-ascii?Q?joZwnzrMV95Jsl0APA/6WJcmmRKJMHdALa92J+lgoBHYQ3qY8cObMvt0meUX?= =?us-ascii?Q?uFmuQmVhL6OUlX/qxL/UQV1uR6xzo/0+PhgvBewoEs4748qxj40cuYce4vUk?= =?us-ascii?Q?z/rQtpVdVdkT0HDOK6YOBfgMaLCbLZA6QCPQnoLImPxol7h5phrYv4RNDYHq?= =?us-ascii?Q?LFBIvtnSqweqyYY8aBsQgaBewtez1gpLf/l7I9mfj+mIPhAo7YmAlF+v8uh+?= =?us-ascii?Q?nXYpOOoGECz4P230dk4mc451gSbIjbWep7I6r7EjbtYK4dBF+viOoGoO5hrF?= =?us-ascii?Q?HiPKcX1uC1oZC9ym9B1F91js+L4w7g2eg5mycNxixHkWYBbodcnkHosfW2+3?= =?us-ascii?Q?EX1maLeSvhhr7PPAvUS689VtpqdyDi7UPZMw46QeLsa2SpyGBWW0vySt8K4e?= =?us-ascii?Q?B2Ra2Kt1h0lyGPLQHYBfpNWiMois7v9gumHY/ReGLaDxG/Ll2wpKNmbKZOZp?= =?us-ascii?Q?5XxzC8IRq+3uHmmVw2k/Jg/+SZ3qOi4KFBf00oOvZcQ0AeGllZTuOH0+Fp5k?= =?us-ascii?Q?SG+xYaJrlptequr+xYbkanWyZ1rTcvXimL1t7ewkYPXIahMIGc1DLu8pWykp?= =?us-ascii?Q?+PNb1vfeeia8QuZgB2I+R5IpDrMafolj03/nffv79nvPbAiOWI4n8644jAvs?= =?us-ascii?Q?5h4a+pwcvMJpDL49u2e/auYp4AY4Uy/Wraft5fo7/j9YYY/rZ7/v6Su/1p4r?= =?us-ascii?Q?MI4Qs3kp1g=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a08c36a-17be-499b-233a-08de96b08cab X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2026 03:23:35.3411 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +GkqzJ6a/nPCZb2ToEwZoTJTVuXYBJraw0oyKEPryN0cFhDJwUyPQGleSiGJmxwyqpRZnGxtAua/Z5/KAfFEqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8472 Hi, This adds a bounded sleep to migration so that FOLL_LONGTERM pinning can wait for transient folio references to drain, instead of failing after a fixed number of retries. The wait uses a one-second timeout. An alternative approach would be to call wait_var_event_killable() with no timeout, but that doesn't match as well with migration's "this will probably work" API. In other words, a short sleeping wait is more appropriate here. When migrating pages for FOLL_LONGTERM pinning, migration can fail with -EAGAIN if a folio has unexpected references. These references are often transient, but the current retry loop gives up too quickly. This series adds wait_var_event_timeout() at the retry points, paired with wake_up_var() in folio_put() to wake the sleeper as soon as the refcount drops. The wake_up_var() calls in folio_put() are gated behind a static key, disabled by default, so non-migration workloads pay zero cost. migrate_pages() enables the key on entry when the reason is MR_LONGTERM_PIN, and disables it on exit. Toggling the key is not free. folio_put() is static inline, so every compilation unit that calls it gets its own patch site (roughly 500 in vmlinux, plus modules). On x86, jump label patching is batched (256 sites per batch, 3 IPI rounds per batch), so enabling the key costs 6-9 IPI broadcasts, a few hundred microseconds on a large machine. That cost is paid twice per migrate_pages() call. Migration itself spends several milliseconds per batch on LRU isolation, TLB flushes, and page copies. Concurrent longterm-pin migrations after the first just do an atomic_inc (no patching). Matthew Brost offered to performance-test this series [1], as Intel has tests that stress migration and good metrics to catch regressions. [1] https://lore.kernel.org/all/aX+oUorOWPt1xbgw@lstrano-desk.jf.intel.com/ John Hubbard (2): mm: wake up folio refcount waiters on folio_put() mm/migrate: wait for folio refcount during longterm pin migration include/linux/mm.h | 8 ++++++++ mm/migrate.c | 30 ++++++++++++++++++++++++++++++ mm/swap.c | 10 +++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) base-commit: 9a9c8ce300cd3859cc87b408ef552cd697cc2ab7 -- 2.53.0