From patchwork Thu Nov 21 18:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13882249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62D31E64004 for ; Thu, 21 Nov 2024 18:52:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C10A86B0085; Thu, 21 Nov 2024 13:52:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC02A6B0088; Thu, 21 Nov 2024 13:52:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3A436B0089; Thu, 21 Nov 2024 13:52:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 81DC86B0085 for ; Thu, 21 Nov 2024 13:52:52 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46DFEC016B for ; Thu, 21 Nov 2024 18:52:52 +0000 (UTC) X-FDA: 82810996254.03.C197212 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2059.outbound.protection.outlook.com [40.107.244.59]) by imf13.hostedemail.com (Postfix) with ESMTP id D8F4A2000D for ; Thu, 21 Nov 2024 18:51:51 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="A3/06sLp"; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.59 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1732215033; a=rsa-sha256; cv=pass; b=H2ihWe54HlIz0zfGqXOtikgOsamOung13NCYI5BNJQk8l12KkOnhVoQBoDyfyvUvLTnvr4 zkzIhqZMe1Mk0RX89AslFQcojVwm9DtAxSfHP4tN+o3HdLPqAaUPGP5BSLtN+aDcAAGoYB wlegucR1OpCk2LZIDJEVFh707THISgA= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="A3/06sLp"; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.59 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732215033; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W0CJZaAm63MVG5+J1rG+OLe2VO73aCelqREx4pG3Mto=; b=2OyxhWpKK4bojSowcGySnZLAGvo4xCsrX27H/zmSvI2k0HfSusXkixmqf1clfeh6W7HLNt IE+UYBmu5dV3MocwdclGHNNxronq/seUx8+zNdsRPLw1cEexUTjclnnIFXAq39x6xHZfAp Uu0DmiSoc30Sl68LbioA8eKfu8S2jes= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AmALoBOBwuJXwFsYxXtrj73eSaJGhhqIl2AYd+2rgOzBP4h4IlOaHyzWAZn0nRciR06JQna9VourxylGHurVQG/iTkuG5OAc+NN5tV58WNt4fP7v8lq+m0af232zZc8B40Hd57cEKD1T06y4N4YBh5ZiUEDAXcyQ0mYwwKIArD1rCxSu9XEHmhekh11rubT1Wtyza7T/42LPBTIViamTwW6yX3PUnlyMYV++XjSeTkI9D/Fmjp5Hmfe2cMfvrHYxo2kJuM2JXyB9atmlRjq+ag1ziXuOf70rmfiMANFawEnwIxb+t8tF3UYaBdYCBOjsQhZdj/6RKCen2/oANTgE5A== 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=W0CJZaAm63MVG5+J1rG+OLe2VO73aCelqREx4pG3Mto=; b=CyDgbN6NBjRA+3XW5/dxRMm9HxKHqPr1lL38M+W+u/0aUNia9sjn15dZQbXcIHP5sSCvoVrv5bz08hwBqaodTEMfPZLbYTulj5BhgK/Y9xLdV/Lbclw7GT9fKmHh2G2yp0Cj5CFwAXQykSf++FNv9zt5Y/quKertnsm9rkQzn5phpPNh2MxiJHfZzqEyWmALIXSu+PkzPf/7+5wNNR0TXP5QX2qKnr6QkJ51NE1VcpgjWnqVhSTyvHuphNs6yBXycaxnLc40Huugv+gkSMyNDNP3LpUb0PUgkPVgYO8yqKD9JyJPY3PKhBwNF17lmkljtRhVmOHYaHAFvNLPlC4AlQ== 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=W0CJZaAm63MVG5+J1rG+OLe2VO73aCelqREx4pG3Mto=; b=A3/06sLpINui42nZaVyXDbXMQj/U/ejC4kqDlDn2M5x5nCq1a1GkhtQolfHg2vw7q7fvDQfIKlA+lJzfwrGpyLf4Z4ebhd0gvVJcfjDE32kPwgeXBd0DBhgcMed6khQT8K3FxhwfKXWFM4qFvJmFgQIggGcX9r6tuiEmZdC267MNaIjBDW/gZ58pUHJm243dYrnrSUnlcRTZAZX3IzX/s/OQNPdxl71CcNyeM9duiFbJYQOcAr5eUHrgEhO5jvgG5bXUHp9Esl/HdjrH9HaLc5RFSMOfTSLlDTDgj2/zrB9UH2UeC479sQQPO8xsHA9Fd6vIqOQtZqAF+TalWxIXaQ== Received: from BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) by MW6PR12MB8834.namprd12.prod.outlook.com (2603:10b6:303:23c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.17; Thu, 21 Nov 2024 18:52:34 +0000 Received: from BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9]) by BL4PR12MB9478.namprd12.prod.outlook.com ([fe80::b90:212f:996:6eb9%5]) with mapi id 15.20.8158.024; Thu, 21 Nov 2024 18:52:34 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v3 2/9] mm/huge_memory: move folio split common code to __folio_split() Date: Thu, 21 Nov 2024 13:52:13 -0500 Message-ID: <20241121185220.2271520-3-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241121185220.2271520-1-ziy@nvidia.com> References: <20241121185220.2271520-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0223.namprd13.prod.outlook.com (2603:10b6:208:2bf::18) To BL4PR12MB9478.namprd12.prod.outlook.com (2603:10b6:208:58e::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR12MB9478:EE_|MW6PR12MB8834:EE_ X-MS-Office365-Filtering-Correlation-Id: 270fb2ca-224e-4c6f-a130-08dd0a5da8ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: IsXydhsNooxn9h5at1A1xmgeswTKANPPvUdk/r69MEhU7lyRShEWJPAPL9MIXRbM8/pFEhZYV4rBVz6O0gDwwGHhGmmXSrSeZBxRaK4JfTNp8uCPwQptOmqxfJVCLEPbwoZnrH9FLVky0aHMXafQB22uPQvp2aCIhEsnZ+dia3suSKaEQzboStNsoU56sMYif9X0wXsBPkTQ0KbmFNUuJLNwPM7kpkowDdfI1RFmFi+EZ3XxJ54tpSAoXH7q39JFQtZVs+HojuyuJmltS5CyFce8726vapaXiQ/aFU6zrIFP2WmbEecYMU8kFlv+hLYE0lKYjr6XdAsBHZDGOP4wEZB6Un+4PMzoeqnZ5SffOwR5n+arpQ00NyjufE9m2UsWtspaqg6UalobiaFXce+YiueATp/lFSB/0jeGfhmRbMz/9ZUtvF2aZJezbVIQdsQjQU7CJLaDg5R4c1xOTF7glbNp8U948T6RhkbOW7R+jidprcDiwYVHnxRutqt6rt3DIDvqFltwOcXQp6EVKJWW/WMDGKUSzSBUauwPdeyMpdjZk/qQ2ry3/czQ2U/tB/7PGwM9kFqMRMYHFEp5jYHykuE3tljTiIZezexb0JXVIZ9cElAHB49ankNON07cwCgiZ1Bd3dpbYaa/H9Cnv6Souyxu2u75cqfP/1lAeokjsR8WZ3hf+dHeNTr+pAwXl93I7ARGXbFo7/kXwJhMC6HIJdpjWNH8L0F6VdU5TsuBUERFGZsX26BL+O49W9Dcq9c5Qqv0b+4kdM+lJNontc4DQNdvpJCpvKCFOvEpeObqyfMCl8Lks0acFj64i+utZHOvFtC8CjROOb1NoATaDTL+spyZ1Uzk56km3z2EneDMJ+GrWSexqyjb/5uWLYb3C/fk2wJKBxBrtXHRoaX+6LpEsL6Oc05a42Vnd2slabY7nwGleteRNQ4m1MCiOALzkhBn8Gbf0phAil2SaRsfkT8ehKX28ig9nc8FWlsbn3mP2nfioxkMKtpj3anxNpVgtVdKKK0wiPmIYHgvKy30SRWBUwjFqJfqE/Zx2ZgMkQWhOYoNUWd7AYL1gXPo3/w68GAZaAB/ilBNdoYc05WA0NcMgeThxpgusLcwHOHR9l+42g+zWEcdkMXqB5CMPJBwL9OUXKbBLC3YRU6xWxuQu7soBlu+iHPkY6ksFoxGitDhD/L0IoCeG9dPjHm0mzzQi9cHNhMX3ktRHnUpdq8oX3/2l+8h6SDkwjkQH2oKN/6BKBAfd2CIH+4JAi4+V8mjEziuP20Jaqlb96gP98NzAEKnKPDSRHrhy38jdODI7o0e/2wZWwcX4BA+xpFF2A3qOKC2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR12MB9478.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TLxyvPAbo0JHzTWkFI0Eut8ThgF0klLBl8Q7ymJ0EYGo+wEexjomTgidppq3/Xg/JHsyiAqS6QbhlDuBO07IedEaKOZe4a77G/Iq6GS3uI95hW9mevBy6mHYM5jxxCVXhTHGPKlYabdVmv5zc0ktx9CjYKn/RlESiRpX3fV4+i6kcIk2J6032BG0AKrI4aPpehK31uuEv5usnF2TACSxiNvFASpn9kmaNIklxh8wjFGU5ZF48bhV87ofxBQ2RImAaI+iV0xhWdjQHRMgGMDwvzlSrcuFrmm8/OHOxi7CgJwwaGJX9xdUfB+X06ZqBfRNAxDZpJJ3Le9/+3G6iy/X+mzJOmZjQxovt060Xm28phIwoMr6eVZiG2c5Bf77fRysDDFwihX70UczFIXTIQNpBlHhibJuhQQ42bIhCC8qQB4hkjoDUxx2RfvPKWk5j0vm3xpKQNbhux09sOBNfaV9II8mBkYzUucXberPGM1xZbjGzTcHzt0xGVURDf2S6inhts55mObfb/TRYMBpggRJ0ro8TzlM+znNpqXzlenH1C9q+NA6xUAnEroEeiSkHI+f9srzs+PLvXGaz5l1wk1L31erwPlRQySI4rAUXiqoYlDHkc09cnoG9GaH/HQNyI3irZjMxRZ8kKaEd19puz2IPs2KUi/zw+RMqNk0Ip4TIjmWrruQdB3pYEt9CWghvcxDtRlw8W/cx+lXkbtHP4iTwKTy1fpjDX9CduTMN3JsLtsFZJzI50XZ9WsDfi5/KJPVl4x0GVTZkUsfbzxpiUQNIR2JfzRm/nXQ069ufRC59HMahmGcqsMXrJAhggeYsW/0lhGwr66cqDws1+NVIEIW1uM3mMlwaZIAzjTReW42K4pr9y/XnJTtguK2Xplfref4sFl7pFDIQD6gD2kt+HOPp9AOsNCTbHO6QXZj2MN8QcLRRoagZTNkmBkV74z2lpq5rIadTD/CxFvJHsURZb/O/fl0DAAK+lvBh98yxh1jjVUqrOojuiuupTuOX/phVmHQwVtbwR9tQ/iykiitesMFBpR4848d+COb0Q1JqVOfhmjwvH4I7RQ7nwatTndYYaCT5M3NblnIid55PmgnogwYK6VVID2VjmQGhiFW6xS0nS6P+l/NWYU4K8JLfaBvHx+of6k6SP41xleqcEXlnYLz/yKQteRx1mQLlGRtidsyouEqTMkAvSlYPvnxGHUsWsXRkp+KrjFcN+N4oH3CNTeNIQAHgmE4XRAgm+6bN/2tEGq/k3D12Ts5L/xrDfxxVa+kVh6Yg1lgLTof/s2u2uZh6TlDRhlWgEO+peJl+6RbZiTxbGg88tHPi2/OWQoFBDaXLSjrJkuHDBhoGIlr9y69bzf/vNwqUYG+GHw108hYy8rV4DzfmaR8lhhwkLGH+yDZOX5nfvfaRsvJkXqn+qe+7TfUzGDISrAHwpe6M26QD/1OTinY/6q1Lf+5cpxWx3bkKCaVZbflXIUMkTlu1Z51WFQcavoAK9TwP+We3MGusewqhK8H/d7cMaRnankNiKPzJHV6w8stnaCcmMrISnVBY7iGQy0rklZOE/N+0RNFiOWsS6SwSI98PC2sIN/Y2xvt X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 270fb2ca-224e-4c6f-a130-08dd0a5da8ea X-MS-Exchange-CrossTenant-AuthSource: BL4PR12MB9478.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2024 18:52:33.9765 (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: owOOkHLeKAoXCOvfnwkVxHK6+w0sXl5ofZ28Ieg0zUKY54Nwr/UWzIkpfXfZ0w+c X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8834 X-Rspamd-Queue-Id: D8F4A2000D X-Stat-Signature: 31h9jg9bcdrdna9ydsh8iz8o9z8hpdcq X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732215111-855757 X-HE-Meta: U2FsdGVkX1/wfpKQ+8gK5Z7gfGtch0pVyz0+Xzvy3zHrMfapeontLsXtrb9+9PlmC3ENvfK8GGivxxqxCFbJpgDNObL1ZRvqsUtNbgiG4gkVq3vIiKX3vSm2++4rY5feAM4/Fq0E5+PAkL7jMAfjwS0rzR2A+b+cNpVWWMzPCuWaqTL1Zv3Q507cyqdzzMrSrIn8brIxENvJLOAm7PMk2Sb9hbzOLkzxejb3bszzGwOCUflTbQPnJLOU3I1EX38oAwUYSYfZAEbYae3S7pEuXfbfDi8ff3MP0KiAg/oXUpFjWUSiGTtCGR1J+cjoVIbybG6YvfMwq/zSFS7wTl717nXDC5xXTjcSkcTDNlgb40HzcLEQbDZ4EP70BE9egcv0EpERnK8pTLkB+0+bgPVZH2ItTwIFbGriccZK8Ht08Uv/KX7zBS2tpSEsYEX7uhA+DnYGn7LovkIbQMMFDdbKKTy5aCiWwsussU+i7NgeW2TERfbEO+UzBdXmcX7NvJu2aa4NqIjY/OwC7APSi5XFk620qbf9R3HzOK83UW4rFHRIHO2E0ov0wwwCtfONDIcYk24aTWDaU5/EShPO+aUY/eymJujbMCTDxpJMTFs/yViYICO+T/30vkcxuVU/YXAdJOj4uAT4vB8CxLYZI40lwtfisSQJisBA47qp2jPebroWcSyOkrE+hQhmxlcj7NjGf83JeEIKTmDXzcoWDUXpoFXM1koAYUt8tWQySgVDRPhuMFN23Nr4GTrWP+OaVHCy+RnJWn0HPuI5ehpRwwaqCKsev/icP3GT8w0rcelKZWAin8f0vmb8GzMwOLgpGAyyMpsmH+whc2kqYKa1fozTvTcOGC/CY26cHzuDuwTNUw1bPKQGYRxRUwMIMFnjgrLRBqVA/mZTLTsQ+J/hP5l4NgClCRf7Adt0RnlQeLuNseD5DXYfmZt52mApVV2978iaNdfHtz6DQlk6m3dMAwZ wucb5Q5b 9dqB/aJa3wognCkXwtjMjjndPPDxpj5DMOUDci1uxSG/LylyJ/sHzbzsWHS96HZvpyMGqqAfw7SDzfHWK7sngRQs9hH9DdDyyxrOAWZLg/KQYSI2dP2Q+LWTXHpgi1hRW4EnqKRQBx64SpLxDzKJUseDlYOrb4C6UlV9qwDQLhGbfL0vz+qA4C+1Egr9JMJmPsbq+eoirwYQRjPE6ZM2Z/X6QSlfdvk6moEz0/AAUi1TN/ayP0tXBodyBq9TRAQTp/IXkhoD1MdExEBsIL1yve4kKD7ktnnXqsUo6tCWsZbvDDFV0CGBzLSoOvhXupp40r3im/cR+BT7Vj7H5M890OVhIaLRCR21DhnHxZB7jIqAHoPF8Wk02G1bzeoHhXHgjHtZQbdFFbfqkZS4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This is a preparation patch for folio_split(). In the upcoming patch folio_split() will share folio unmapping and remapping code with split_huge_page_to_list_to_order(), so move the code to a common function __folio_split() first. Signed-off-by: Zi Yan --- mm/huge_memory.c | 107 +++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5ebacb08996c..65dd2a383e29 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3730,57 +3730,9 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, return ret; } -/* - * This function splits a large folio into smaller folios of order @new_order. - * @page can point to any page of the large folio to split. The split operation - * does not change the position of @page. - * - * Prerequisites: - * - * 1) The caller must hold a reference on the @page's owning folio, also known - * as the large folio. - * - * 2) The large folio must be locked. - * - * 3) The folio must not be pinned. Any unexpected folio references, including - * GUP pins, will result in the folio not getting split; instead, the caller - * will receive an -EAGAIN. - * - * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not - * supported for non-file-backed folios, because folio->_deferred_list, which - * is used by partially mapped folios, is stored in subpage 2, but an order-1 - * folio only has subpages 0 and 1. File-backed order-1 folios are supported, - * since they do not use _deferred_list. - * - * After splitting, the caller's folio reference will be transferred to @page, - * resulting in a raised refcount of @page after this call. The other pages may - * be freed if they are not mapped. - * - * If @list is null, tail pages will be added to LRU list, otherwise, to @list. - * - * Pages in @new_order will inherit the mapping, flags, and so on from the - * huge page. - * - * Returns 0 if the huge page was split successfully. - * - * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if - * the folio was concurrently removed from the page cache. - * - * Returns -EBUSY when trying to split the huge zeropage, if the folio is - * under writeback, if fs-specific folio metadata cannot currently be - * released, or if some unexpected race happened (e.g., anon VMA disappeared, - * truncation). - * - * Callers should ensure that the order respects the address space mapping - * min-order if one is set for non-anonymous folios. - * - * Returns -EINVAL when trying to split to an order that is incompatible - * with the folio. Splitting to order 0 is compatible with all folios. - */ -int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, - unsigned int new_order) +static int __folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) { - struct folio *folio = page_folio(page); struct deferred_split *ds_queue = get_deferred_split_queue(folio); /* reset xarray order to new order after split */ XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); @@ -3996,6 +3948,61 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, return ret; } +/* + * This function splits a large folio into smaller folios of order @new_order. + * @page can point to any page of the large folio to split. The split operation + * does not change the position of @page. + * + * Prerequisites: + * + * 1) The caller must hold a reference on the @page's owning folio, also known + * as the large folio. + * + * 2) The large folio must be locked. + * + * 3) The folio must not be pinned. Any unexpected folio references, including + * GUP pins, will result in the folio not getting split; instead, the caller + * will receive an -EAGAIN. + * + * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not + * supported for non-file-backed folios, because folio->_deferred_list, which + * is used by partially mapped folios, is stored in subpage 2, but an order-1 + * folio only has subpages 0 and 1. File-backed order-1 folios are supported, + * since they do not use _deferred_list. + * + * After splitting, the caller's folio reference will be transferred to @page, + * resulting in a raised refcount of @page after this call. The other pages may + * be freed if they are not mapped. + * + * If @list is null, tail pages will be added to LRU list, otherwise, to @list. + * + * Pages in @new_order will inherit the mapping, flags, and so on from the + * huge page. + * + * Returns 0 if the huge page was split successfully. + * + * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if + * the folio was concurrently removed from the page cache. + * + * Returns -EBUSY when trying to split the huge zeropage, if the folio is + * under writeback, if fs-specific folio metadata cannot currently be + * released, or if some unexpected race happened (e.g., anon VMA disappeared, + * truncation). + * + * Callers should ensure that the order respects the address space mapping + * min-order if one is set for non-anonymous folios. + * + * Returns -EINVAL when trying to split to an order that is incompatible + * with the folio. Splitting to order 0 is compatible with all folios. + */ +int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, + unsigned int new_order) +{ + struct folio *folio = page_folio(page); + + return __folio_split(folio, new_order, page, list); +} + int min_order_for_split(struct folio *folio) { if (folio_test_anon(folio))