From patchwork Fri Nov 1 15:03:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13859513 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 F2995E6F063 for ; Fri, 1 Nov 2024 15:04:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 198866B0088; Fri, 1 Nov 2024 11:04:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D7306B0095; Fri, 1 Nov 2024 11:04:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAB1C6B0098; Fri, 1 Nov 2024 11:04:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A119C6B0088 for ; Fri, 1 Nov 2024 11:04:21 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 571BB160731 for ; Fri, 1 Nov 2024 15:04:21 +0000 (UTC) X-FDA: 82737846240.10.C14C691 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061.outbound.protection.outlook.com [40.107.220.61]) by imf11.hostedemail.com (Postfix) with ESMTP id 9534940035 for ; Fri, 1 Nov 2024 15:03:43 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=LSccG+AY; spf=pass (imf11.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.61 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730473279; 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=eJ7mtvl5+aRqSZmDpJAAE0enIUlEdEtuMZ5VoenL7co=; b=G1aW9QrCIVt+hQ8ZyDWVw2z/UpERiWxljZLDFwFGto37C0YNO66Ji+y0d4JaeqjlgWw7T2 20gjjntW+0IazqISggqSTPuiqfcFPa6pozqzv9jzRgL9IKFxgKf7QZSn3KUXUTy9cx5jZr CBJWOAQApv+FsCQzE/unqLdNFJkNxwQ= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=LSccG+AY; spf=pass (imf11.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.61 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730473279; a=rsa-sha256; cv=pass; b=6boEXBadF/00sYIHi06OCDoepRUnY9uY+dRp7mJakyonov9I9BaD8tzW4TtGnRufRWy+zK gjmk0q+zv+fdq9qFRZvYffWFJ9311GzFCmXkblepmsAeSFfJyMCPvU5Co8/QF+6vZ2UcPx M9oD93SbKjcU3xSDuWaBpgDKkPtYkZw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oHVz29DmmK6auSY3sMz9Qh+l8gmdgEDZKlgfVhikODDLaoNPWE3k7WHJekV4hSYTZuE864ZhEDc6mqlaCwFPRh/x9oZvDKLPKmQFzCc6ufydaQW4XTT5mlQ8Kz8k/sg/jlHKHoJIhCM8sxbFsVmGWj8LPmU01zLg75GmMdybJs+lBnuAzPRjvwmV6GMizC0QhxxOz6c9Gk3my97guqN0ki7FF4ugojSqwHAGOS6KxAhByZU7QVFy7O3KjPQtCLRM0y2jaTKD7YITPZtXBX7IKxSN+hC3pwMHAU0bNsXUtJRv+DOgMzbiIFY9OkQDTNjbfZ+9fxdmI/yndZTinyTtVA== 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=eJ7mtvl5+aRqSZmDpJAAE0enIUlEdEtuMZ5VoenL7co=; b=fWzUWqZRQnqTQHDe85hGeqtyp1TRjT4G69iPXVRQOkn3ahq7AopW7j5lHoQlF63/TJs/YdzK2SyIuRYdj7Y4k/QzaowQBEqbe/davsjIirZcwQIVA34xqE2zIw+Q+9YCA4yBHOT+Pq5q94kTGFmSU7N6I+JwJdUgaH0JaZ2ezHvM7I+WwrpxO4c8uGMabztfVaHUfyNyMfwoREuzjuONKKOj6q60zBGoZR7Z2mtIlGv8/QZzPPDvJMYGfgK0FlrNK4XkP9x4epIgQUiJPCAtqX+ylJ58NwZSMDufIxnexBSN8glWs+LxR39SeFu1Uu0MYRyqo/X37dT7On7eaSiI8g== 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=eJ7mtvl5+aRqSZmDpJAAE0enIUlEdEtuMZ5VoenL7co=; b=LSccG+AYEttToFeO0f+mF13iWqqGGEQj0x2F8D1elSMexwrfO9RuzKzPCNKKVlRgoPZGcdj6yd9GqeryQQCNIdddKdQT3arH7Kab0NgEXUE8EF6IO3BcdmHKOeULrPBStpbp/f/xeCinytKYUXZABj5WsQmZ5Yk5Q+4xstI+MJK91NQgNmtpeWkRPCE5UmbZUfB7qpGruLTn2JzgIX9QTck7byYQ/kkUlLxFZVvzqGO/bYgFFJYJCI7tN4hMTkgcFkpEYbIEGrgDXULeQhya7XEU8O6GINNwTOj2bkqaS0S85ogzzBaHL5hbW8qOucgwNX9DnJ7n73TRGv0GJMqIWQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CH3PR12MB9453.namprd12.prod.outlook.com (2603:10b6:610:1c9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.18; Fri, 1 Nov 2024 15:04:08 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%7]) with mapi id 15.20.8114.015; Fri, 1 Nov 2024 15:04:08 +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 v2 1/6] mm/huge_memory: add two new (yet used) functions for folio_split() Date: Fri, 1 Nov 2024 11:03:52 -0400 Message-ID: <20241101150357.1752726-2-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101150357.1752726-1-ziy@nvidia.com> References: <20241101150357.1752726-1-ziy@nvidia.com> X-ClientProxiedBy: BN9PR03CA0109.namprd03.prod.outlook.com (2603:10b6:408:fd::24) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CH3PR12MB9453:EE_ X-MS-Office365-Filtering-Correlation-Id: 681b0ca5-bfe9-42c1-9813-08dcfa866f9f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: SkIMXVg5P3jbKaLprVOdyJ+Y2Z0AMp+iAnXsp83b2L5381qlPrcm3TXbxBfRfR66ZgC+Jjpt6YQ5qZq7r4Sq2Lyvw/hWW5axeC8KmTgIfVySd7WjeMSY215eLPi7fJR1V2StsYgnlLKNRP9wLmCOogcQ7hYI90p+pKk7FQxzFmUK/0/h0TYn3rsiG9rHjUlCGwaOs7RZQip7POlP8C4AFIm1/0qS9UalLadnCsR6KyJKuUqmpYlYQgugOmkFFUVgvcmYHNWEB769cosimwdPgelNlWAKFhLH2YwD6vZF/3/rPOTzzlHBnsKYTFI4zTQQFGhgIo6ehQ+dvkykbw5k+GUWEdVL6Cbtirx3bDbc1oHVUuBqD+FFQHUZ+xQhJ0eLAc3mrSEZgmuXhwy6/abmkQarBbgPpu28EJgWbb7l4XtT+pYFFoF9zEiY6EjXTgAeWT4WyrBa/ZwuW3az8IgD+7Noe4E6dbWRBtdi7MoivSD+7XYIW0ARSCBzXd6Bqv8zk0mB5JGgF4wIvMQyuopEDXn9uOlJDbBeAOmxVQiXpT7GrPlv9XUG+FLZ8KineiFabwqThpRMB5S1SAD5VqmpH04yHZtu3akR3xp36tKSi7vfFjTyFMrhZs381MjZY0/V6whsauiBhbeOWMWrQM8C7mjLtoEIuBhmtBSDWwpREiDfh+h8Hu0T3L3CjQyl289+PwnGVg9URUJRIivR3qqChyAuXhQMZArNIojl6BRbDlJYAB0iq2kExa86kNmlF93vwvNzIrrOOWYOp2tJPe9iudC8uZftvVdgj3YON8dnHEimaValUyGN1BLpC52uB11pJQDcAPsQu2Uy5Bz31/IZWCxkNTWpRLYb37fjoOElM1lw3Yix2QchoYLFVaPjWll92mhWt5djYZnirUPHaIXKwVJNC4TTkm+0Tf5k3pfE8ZolwQXf1zBeK6mp9O0/zZoIiSx9aL+zFS/uydxgSraJkVem2DVY7mswB1gFAAlcSdyLlUYw8CXsF9oS0c4hF2zuY/OjuwTwa4saTH+6Mkmc8em+KJkKSrec8JCmj2SQ9Am7M8t1WgArfvzeyWc0RgufdKPFWfj3pn3B5zGPMlggLkwVU+dJuZD/HZjNeU6okROdpEJu/N9vFMNrwJPqnXcFM03imgjuJ1WEoA5u+K7NzyL0djVoaq++ZktAtp88GNKl+t77EPRET/uSHVF1vGUxwULpcuKdLmhWyv6ULqkIgta0hkNR9iyp9tkqd0LdTgqDnA+BZPMFoiegnTzPduCTzFhz3boHXpNRjBvteWOGX1LracXKGCyn++oe1gxyezsKyEJHBXnCw2wACiY/7WsM X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qnp1EXSvt4oAOH81UHBiKlnSm8eZJSN29g6q73v6oUv8jtHHKVfmJGYR/ZnaOWh43nLtoO1zdExsd7JfAMYeS3ZTPonJoDXIdcX1/WtaE7YbCw+w8CAUFVvRf6S5viXxuKveOrbWaDLiZP+XBp/QvQ+X2YSMs79NxOBT3b+S0vgBxda2RFAZM83kthAzMTFx4F79IBQ4OpQZnr9zctfOJ3guDDMq1YlvGLjAxOrKtQWh+CePBvhSqMmWH3cdispeP6DFcPsbgcFIV1e7j6fYLfhfv005JpLt5f3d7BMe6EGUmrhC/RceFQq/Dc/tYVjNdlCTXVUlzQBvMikv0ApP9QX7LRlRqvtnaJT0HWBfRk6XPKr/5ATAgcijQO7q3O+2WfFC8oYcS+tcBUXkIBq9r8/ynXGsl/qDLIyZfKXSpPTAoyuWP5vkpCRldht0vpqDbw+cf+SPwYFuJU5UbHiqlEZKmkqdnguSdMsNrh3l3KpMHvU7i3nMyaEm6eBGoOsI4S6W6bCPqtMBHmm9JraAX0IIyUQrABIwi2ip0l5FY3TfCkAnqx2Exldqwsq8rRV9b6ewOwRr7adsKuQ8ERmgrHqwacRNOc7TrNM4oK09171qKxXgkzSXipMA/Cii4SHcL8hAExoKdJQ9+nNd3uGfgWg49hL07FXEnkSD/GIjkfgwIZI/NaPFnvb5SIX9KcTyx1lAFlyH5TV6yJ6vxBwOW6b+oRiUnN/qFEzX3y2ZZ5cNEB/d2rmX7qqz6tnXvS4A1MZtlTUO3FaC8tKem99Ps8AKl27iBm1iJU4IIEdeJIbv+1/TQSzK8MOGouMb2I1feikWol1KSpdDkLTMFPPDVHJwOOHZ5BJRJzOyhm4vh23ifaMWUD0w/logbGap6NSyhVrb6fDcXp+sCTFKx72uNmXuw2F9laBHLF85G7yeSPcqrONPir4HgSWuurdyq9lCGn3/jDwZg6Mnl5f1hdSHQhp+DfwMtsjm10ClgOZzxczxYa7/dXpG7ccDEaPOHG5ZNBSeOuhdoiNuL9/qdh0Wwwa0RbLO+ILUFOVVxWxVWwN7rsz72An+D+PInJXAaroMS8C6bC4wWpOBymAwoSaJ0/hFmtONeSh1SpA+We/Fm9Qivl31wUvSZGlBoZy9avZSHA0kjAs0j6xCVXRGZYotxUq5BFEN7dN7oFWPzLdT7bg0yMDp81oSkGhSsmcZEPSFxV0Ehjt4F3FYAzrkH0Opw1SDtXVfpa4+RKAbG4QQDCjFfPJXlefZDF0xIsMitVhkLa1ZYTXtDggVDAUSU368HHFajFcj0C4rC1hj7B58QE7LHaplwW9Pb9h5Lto1mIVuJolL0Dnz5/clfH5f99OTdl3HHLgN5ohVWHYJpJStEuO1XmzA8h4FRCgBekjLU31WEQiqu5R/Q/geDaGJodD8oUIhnADWV2/FwNBAcV9OBRxYo+xbp1CPUvxdfAqqNpi5UMmD78x70iVTyyBHJQzOneHgdY8cF3f63j5zoiDIwUqC6LhZmPS7supr8LPynq3Ayh++cOyAgpRUBrTMg7GUoWsNO79Om6usN/m2LzHrrKv9Klv8kC/1aLaah2BewqZR X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 681b0ca5-bfe9-42c1-9813-08dcfa866f9f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 15:04:08.6370 (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: PD/jTcoBynkQMgMF/tkvN8EHQdzLdfxV5C/XloNNzL+OaNZJKniqep0GnGEleZcu X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9453 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9534940035 X-Stat-Signature: swj4pearfbxwg19pwe86wqbf4fkde6cf X-Rspam-User: X-HE-Tag: 1730473423-30546 X-HE-Meta: U2FsdGVkX1+O1oQ5KKc1VO3Heo9eiBGSC89qxifotf9glwawZy7vVJCc7LEUMSZRE54N/XfGYyEUJ7Vqd1gvIP/4b25ZpZUtGseF/VLbaWZEgwEyEHS8MMPqaZF8Sn6QEmvn8gzdDg3MQvjwrl3ThfMIG+iM+0+u1QyPg/YqqpJBZq40vo1JE5DxFjzOvGT81yf5n23Dv8UPZBRNd2JUMCmeOYFQEyooUPO8DfdoDln0B9BeEi/e/kbgHBXakOjtlJlbKwSOji9R337vWqujdPPUbhbq1hYGg6BFPOSPyC3MG6XE7aXD5VQxrmQiJTKrdi3zlnT1CKXFvj4i6UAOVHjv73BgXIKCM1GwQ6/T0ERsrr3P7hlV+j6K6Nvk3bLs9p3QHXl3wnMYTSjopwAKkeIIZv2nNtsAxZFn8iQgHnerMTOCCmAQjb2xxIHgTFYYjwLQepVb+7mCeOKcMM1aytow6iLV8UUB4fFRfqBn4xnhdCGi02jMQH0mg7XzS1UPmpbA4dSEQaCHb5NysAboJwzcGuB0oSHONDFrHhzmch5BUZx5T+7z7pAoMjYhNOjQfxQc8gKBKA3WHU9hQDr4oBfk+nZnttaDe5gRTK/H6hd78qhJbSzRR3IJ8Y9+WWKWvAFn8Uhzhyk15V1/90WeqiQNghBT1UYanRxLbZ6vbYq3zFm4HcTNKkN+C8KOowKxU75WuSggCwEo3X66nepAClXBqM+OcpEPpGoaroemmwrtvor9TAegBGB1tHoO+K3GjxjGpQOnyaAa5eJAiORXS5eqqhDP9Y3MIG1kskDuHVMkeQc5sDH3w+m0eqL7moovyHRjfus9gizKu5xqKBimojeoOweklKgKYCSZgKANk4woli9eRjlNVwbcjwk2SUlH1GdzgXOdUF28AdF9NAE21Eb1i263nv/zjmEnT/ldMUnOssWF9ikx6mNcFocGBBOoMAxYx89kcIo9tYKG5WP afbHD1B3 uXrQyhMuitEZ7zntk4jsnZEVQx8u8sChh2XGlKwD+5Nny8oYSDzwsBYV7MaT6cDL265qqw2EvuF6noPN58RVx1iAeJb2wdUaGgnrNMqTQRlJwZGQivJWvot+r9ZvQbIfb9czcEcObUubmZQK3e7pNXMi9qBUxR7ZUDtXfqmpRzDwfYw54HM2Th9w4omdJD/xc7f3wVKCptykgJDnuviOcPOiAeEZjO/EyvOyKVv8fm0ZpfKHY3OOVQQWWeuzOrLgpYXlAcie4MNZ5/cTEM5hDFk+idLGf1SD7fi/s/n6UmB3b7c9/3o7rCv0b7zGupPAQEMnLnb0e4fYIztRZG9Zcgux0cw== 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, both added functions are not used yet. The added __folio_split_without_mapping() is able to split a folio with its mapping removed in two manners: 1) uniform split (the existing way), and 2) buddy allocator like split. The added __split_folio_to_order() can split a folio into any lower order. For uniform split, __folio_split_without_mapping() calls it once to split the given folio to the new order. For buddy allocator split, __folio_split_without_mapping() calls it (folio_order - new_order) times and each time splits the folio containing the given page to one lower order. Signed-off-by: Zi Yan --- mm/huge_memory.c | 328 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 327 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f92068864469..f7649043ddb7 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3135,7 +3135,6 @@ static void remap_page(struct folio *folio, unsigned long nr, int flags) static void lru_add_page_tail(struct folio *folio, struct page *tail, struct lruvec *lruvec, struct list_head *list) { - VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); VM_BUG_ON_FOLIO(PageLRU(tail), folio); lockdep_assert_held(&lruvec->lru_lock); @@ -3379,6 +3378,333 @@ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) caller_pins; } +static long page_in_folio_offset(struct page *page, struct folio *folio) +{ + long nr_pages = folio_nr_pages(folio); + unsigned long pages_pfn = page_to_pfn(page); + unsigned long folios_pfn = folio_pfn(folio); + + if (pages_pfn >= folios_pfn && pages_pfn < (folios_pfn + nr_pages)) + return pages_pfn - folios_pfn; + + return -EINVAL; +} + +/* + * It splits @folio into @new_order folios and copies the @folio metadata to + * all the resulting folios. + */ +static int __split_folio_to_order(struct folio *folio, int new_order) +{ + int curr_order = folio_order(folio); + long nr_pages = folio_nr_pages(folio); + long new_nr_pages = 1 << new_order; + long index; + + if (curr_order <= new_order) + return -EINVAL; + + for (index = new_nr_pages; index < nr_pages; index += new_nr_pages) { + struct page *head = &folio->page; + struct page *second_head = head + index; + + /* + * Careful: new_folio is not a "real" folio before we cleared PageTail. + * Don't pass it around before clear_compound_head(). + */ + struct folio *new_folio = (struct folio *)second_head; + + VM_BUG_ON_PAGE(atomic_read(&second_head->_mapcount) != -1, second_head); + + /* + * Clone page flags before unfreezing refcount. + * + * After successful get_page_unless_zero() might follow flags change, + * for example lock_page() which set PG_waiters. + * + * Note that for mapped sub-pages of an anonymous THP, + * PG_anon_exclusive has been cleared in unmap_folio() and is stored in + * the migration entry instead from where remap_page() will restore it. + * We can still have PG_anon_exclusive set on effectively unmapped and + * unreferenced sub-pages of an anonymous THP: we can simply drop + * PG_anon_exclusive (-> PG_mappedtodisk) for these here. + */ + second_head->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; + second_head->flags |= (head->flags & + ((1L << PG_referenced) | + (1L << PG_swapbacked) | + (1L << PG_swapcache) | + (1L << PG_mlocked) | + (1L << PG_uptodate) | + (1L << PG_active) | + (1L << PG_workingset) | + (1L << PG_locked) | + (1L << PG_unevictable) | +#ifdef CONFIG_ARCH_USES_PG_ARCH_2 + (1L << PG_arch_2) | +#endif +#ifdef CONFIG_ARCH_USES_PG_ARCH_3 + (1L << PG_arch_3) | +#endif + (1L << PG_dirty) | + LRU_GEN_MASK | LRU_REFS_MASK)); + + /* ->mapping in first and second tail page is replaced by other uses */ + VM_BUG_ON_PAGE(new_nr_pages > 2 && second_head->mapping != TAIL_MAPPING, + second_head); + second_head->mapping = head->mapping; + second_head->index = head->index + index; + + /* + * page->private should not be set in tail pages. Fix up and warn once + * if private is unexpectedly set. + */ + if (unlikely(second_head->private)) { + VM_WARN_ON_ONCE_PAGE(true, second_head); + second_head->private = 0; + } + if (folio_test_swapcache(folio)) + new_folio->swap.val = folio->swap.val + index; + + /* Page flags must be visible before we make the page non-compound. */ + smp_wmb(); + + /* + * Clear PageTail before unfreezing page refcount. + * + * After successful get_page_unless_zero() might follow put_page() + * which needs correct compound_head(). + */ + clear_compound_head(second_head); + if (new_order) { + prep_compound_page(second_head, new_order); + folio_set_large_rmappable(new_folio); + + folio_set_order(folio, new_order); + } else { + if (PageHead(head)) + ClearPageCompound(head); + } + + if (folio_test_young(folio)) + folio_set_young(new_folio); + if (folio_test_idle(folio)) + folio_set_idle(new_folio); + + folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); + } + + return 0; +} + +#define for_each_folio_until_end_safe(iter, iter2, start, end) \ + for (iter = start, iter2 = folio_next(start); \ + iter != end; \ + iter = iter2, iter2 = folio_next(iter2)) + +/* + * It splits a @folio (without mapping) to lower order smaller folios in two + * ways. + * 1. uniform split: the given @folio into multiple @new_order small folios, + * where all small folios have the same order. This is done when + * uniform_split is true. + * 2. buddy allocator like split: the given @folio is split into half and one + * of the half (containing the given page) is split into half until the + * given @page's order becomes @new_order. This is done when uniform_split is + * false. + * + * The high level flow for these two methods are: + * 1. uniform split: a single __split_folio_to_order() is called to split the + * @folio into @new_order, then we traverse all the resulting folios one by + * one in PFN ascending order and perform stats, unfreeze, adding to list, + * and file mapping index operations. + * 2. buddy allocator like split: in general, folio_order - @new_order calls to + * __split_folio_to_order() are called in the for loop to split the @folio + * to one lower order at a time. The resulting small folios are processed + * like what is done during the traversal in 1, except the one containing + * @page, which is split in next for loop. + * + * After splitting, the caller's folio reference will be transferred to the + * folio containing @page. The other folios may be freed if they are not mapped. + * + * In terms of locking, after splitting, + * 1. uniform split leaves @page (or the folio contains it) locked; + * 2. buddy allocator like split leaves @folio locked. + * + * If @list is null, tail pages will be added to LRU list, otherwise, to @list. + * + * For !uniform_split, when -ENOMEM is returned, the original folio might be + * split. The caller needs to check the input folio. + */ +static int __folio_split_without_mapping(struct folio *folio, int new_order, + struct page *page, struct list_head *list, pgoff_t end, + struct xa_state *xas, struct address_space *mapping, + bool uniform_split) +{ + struct lruvec *lruvec; + struct address_space *swap_cache = NULL; + struct folio *origin_folio = folio; + struct folio *next_folio = folio_next(folio); + struct folio *new_folio; + struct folio *next; + int order = folio_order(folio); + int split_order = order - 1; + int nr_dropped = 0; + int ret = 0; + + if (folio_test_anon(folio) && folio_test_swapcache(folio)) { + if (!uniform_split) + return -EINVAL; + + swap_cache = swap_address_space(folio->swap); + xa_lock(&swap_cache->i_pages); + } + + if (folio_test_anon(folio)) + mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); + + /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ + lruvec = folio_lruvec_lock(folio); + + /* + * split to new_order one order at a time. For uniform split, + * intermediate orders are skipped + */ + for (split_order = order - 1; split_order >= new_order; split_order--) { + int old_order = folio_order(folio); + struct folio *release; + struct folio *end_folio = folio_next(folio); + int status; + bool stop_split = false; + + if (folio_test_anon(folio) && split_order == 1) + continue; + if (uniform_split && split_order != new_order) + continue; + + if (mapping) { + /* + * uniform split has xas_split_alloc() called before + * irq is disabled, since xas_nomem() might not be + * able to allocate enough memory. + */ + if (uniform_split) + xas_split(xas, folio, old_order); + else { + xas_set_order(xas, folio->index, split_order); + xas_set_err(xas, -ENOMEM); + if (xas_nomem(xas, 0)) + xas_split(xas, folio, old_order); + else { + stop_split = true; + ret = -ENOMEM; + goto after_split; + } + } + } + + split_page_memcg(&folio->page, old_order, split_order); + split_page_owner(&folio->page, old_order, split_order); + pgalloc_tag_split(folio, old_order, split_order); + + status = __split_folio_to_order(folio, split_order); + + if (status < 0) + return status; + +after_split: + /* + * Iterate through after-split folios and perform related + * operations. But in buddy allocator like split, the folio + * containing the specified page is skipped until its order + * is new_order, since the folio will be worked on in next + * iteration. + */ + for_each_folio_until_end_safe(release, next, folio, end_folio) { + if (page_in_folio_offset(page, release) >= 0) { + folio = release; + if (split_order != new_order && !stop_split) + continue; + } + if (folio_test_anon(release)) + mod_mthp_stat(folio_order(release), + MTHP_STAT_NR_ANON, 1); + + /* + * Unfreeze refcount first. Additional reference from + * page cache. + */ + folio_ref_unfreeze(release, + 1 + ((!folio_test_anon(origin_folio) || + folio_test_swapcache(origin_folio)) ? + folio_nr_pages(release) : 0)); + + if (release != origin_folio) + lru_add_page_tail(origin_folio, &release->page, + lruvec, list); + + /* Some pages can be beyond EOF: drop them from page cache */ + if (release->index >= end) { + if (shmem_mapping(origin_folio->mapping)) + nr_dropped++; + else if (folio_test_clear_dirty(release)) + folio_account_cleaned(release, + inode_to_wb(origin_folio->mapping->host)); + __filemap_remove_folio(release, NULL); + folio_put(release); + } else if (!folio_test_anon(release)) { + __xa_store(&origin_folio->mapping->i_pages, + release->index, &release->page, 0); + } else if (swap_cache) { + __xa_store(&swap_cache->i_pages, + swap_cache_index(release->swap), + &release->page, 0); + } + } + xas_destroy(xas); + } + + unlock_page_lruvec(lruvec); + + if (folio_test_anon(origin_folio)) { + if (folio_test_swapcache(origin_folio)) + xa_unlock(&swap_cache->i_pages); + } else + xa_unlock(&mapping->i_pages); + + /* Caller disabled irqs, so they are still disabled here */ + local_irq_enable(); + + if (nr_dropped) + shmem_uncharge(mapping->host, nr_dropped); + + remap_page(origin_folio, 1 << order, + folio_test_anon(origin_folio) ? + RMP_USE_SHARED_ZEROPAGE : 0); + + /* + * At this point, folio should contain the specified page, so that it + * will be left to the caller to unlock it. + */ + for_each_folio_until_end_safe(new_folio, next, origin_folio, next_folio) { + if (uniform_split && new_folio == folio) + continue; + if (!uniform_split && new_folio == origin_folio) + continue; + + folio_unlock(new_folio); + /* + * Subpages may be freed if there wasn't any mapping + * like if add_to_swap() is running on a lru page that + * had its mapping zapped. And freeing these pages + * requires taking the lru_lock so we do the put_page + * of the tail pages after the split is complete. + */ + free_page_and_swap_cache(&new_folio->page); + } + 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 From patchwork Fri Nov 1 15:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13859512 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 3D57CE6F066 for ; Fri, 1 Nov 2024 15:04:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C21C06B0089; Fri, 1 Nov 2024 11:04:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD4036B0096; Fri, 1 Nov 2024 11:04:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 938076B0095; Fri, 1 Nov 2024 11:04:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 624426B0088 for ; Fri, 1 Nov 2024 11:04:21 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EBE281A069A for ; Fri, 1 Nov 2024 15:04:20 +0000 (UTC) X-FDA: 82737845190.20.4DF90FD Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2088.outbound.protection.outlook.com [40.107.93.88]) by imf04.hostedemail.com (Postfix) with ESMTP id 082B140029 for ; Fri, 1 Nov 2024 15:03:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ljC0i1Hy; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf04.hostedemail.com: domain of ziy@nvidia.com designates 40.107.93.88 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730473401; a=rsa-sha256; cv=pass; b=JMX8gQRCdLrN9Cc9EOiKMU+CgPNoDo1G3hB6krjdhZwFYBf1cZ2bm+pQusKpBRD5TQ9M8w tnwHZM0V+hGQI5rzn0qqsFwX3qoPqrHB4UVRpG2GTCvcQNkLQpiBQX+vgheg7jYWyecpTV OMUOwbsrU+LV2GUZPit5szNt6CueGfQ= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ljC0i1Hy; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf04.hostedemail.com: domain of ziy@nvidia.com designates 40.107.93.88 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=1730473401; 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=Ls+U6Awbsximkn/QkNJbncmd3R1uDypxcexS3nCzLLo=; b=uPf4SvCpwbWn33ysEObgTxQBT0/U9dDnSUZce2Y7YK/IwhfCsboOtOdpuVOz+QBNQeGgyZ gaY8aW5onmB2Ob6/VoLwL3nF5jR+UJmxwiy4IEqqU+PdCA5PCF5nvThEQqeif+Fo8ajTUh IuM/oxH4+WVBMG0Slt70USHMpCiqMn0= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k62DSH0vuRFqfyFHGdTrWLaZSUXJ1466kLuBPxbT88gv2Z33SqBmKew1KRAkykXF4hquWGpbP6hSoBiP1cCwUIGr7YIjIIrlWJiESkfp9AHYQfkkO3dK/mNw0auXsG39QuuDJU7XZzfhfmgtg2HTlyc40Ad0c8gUsfCK5ERbUQBqVeiMh8IusVWDLcY+ZfE0EbJOaEH1jYU314DUxe7CzsFUDOlBddfFUP33q/TMfHuIKciS+cgcDnC8jnZNrqxy3RB4MTMa0NKq2TKg/VieX8Y6SPiYfalOnlcqNwgz6Qc1U9ThLrymxNs19VjQZDHNheJ7xJgLQ3rQQdSl9DkB/g== 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=Ls+U6Awbsximkn/QkNJbncmd3R1uDypxcexS3nCzLLo=; b=Sk/Hq+TdD3UjwlQMsfgZQ8PKa6L4PH0yBKT3aIOuiz0ykG15hHmuvFqEoX21e1z57NN7bwC7lB/javorK1sVtFFGMeOkDx7D/jrZkB8oGe09usbXwdiR0ImrkuFODmTbpSqILFzQmVC8mmJdjqQznuIPY3+v4xVTMGXMQ2fF6kaUhpmAwv2k+HeGtgQyXLMV0RZaSPjcOJdReSPrU8oaSbID85PtWzxcEwmsqTN6heAPxqJ9zb3fkrs8q1j43U+X8HjWfy4bWiuP/6wvBO7M7GavjD0h8tUwDgqDjkNik0eMOrWRri6Ohh+KMgOPGTrggffcZfDBnpwjdIgoV5q/ZQ== 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=Ls+U6Awbsximkn/QkNJbncmd3R1uDypxcexS3nCzLLo=; b=ljC0i1Hy/4ewI3gN5e1vPV3z7v643B/I2beBTgWDvjeiLL+kesfIl0Vf9CxO6iszqvyCFFeEoh8bgBwlhmBwzHqcYH73CT9NK5EvYqSVTnIRbYX4R/dXM32rqYmvaU0HJvEBjaUWxgJ31tXG44sHDUj5aXN7nGR39tWSoESbBeUhJELW4kLQmvpk2DeNUn6TOdmRNuWOdOFqzRce9LadUtXCDFW3/qajX7NUk0jxRZtfldhNYdFXNVLZUXOvpKnvIs8T5h1HAEgKaMNqxJzCOHwfAKIigZifOBifcTVdyk3FoUXEUnG2eDez9HA86YSq5UG+s0hxEvcM9PfPL/SIYQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CY5PR12MB6621.namprd12.prod.outlook.com (2603:10b6:930:43::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 15:04:14 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%7]) with mapi id 15.20.8114.015; Fri, 1 Nov 2024 15:04:14 +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 v2 2/6] mm/huge_memory: move folio split common code to __folio_split() Date: Fri, 1 Nov 2024 11:03:53 -0400 Message-ID: <20241101150357.1752726-3-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101150357.1752726-1-ziy@nvidia.com> References: <20241101150357.1752726-1-ziy@nvidia.com> X-ClientProxiedBy: BN9PR03CA0107.namprd03.prod.outlook.com (2603:10b6:408:fd::22) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CY5PR12MB6621:EE_ X-MS-Office365-Filtering-Correlation-Id: cffa0d44-24cb-4c23-5a11-08dcfa8670a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: tgLLugnwwLJWq5ZOuj+yJsrQskDyptgQNrsb7qZu1kIw6jkOYfKID955bXyNXdUUFDGmxpUe/j0wUi+V8N8WM3iKjH/1TwJ9OQRGUgzDbplovu+MiM62q9TPHUFiGxfWfwngyQlLDAkFm/9hZ3jnfUTguzjujNfaHkCvLFuDe35V2XKBzQqrn1ja3v5Q42EInXoEgnbUXll6vi3xkVUNPs8pRX+9uN+vG5/QFrSQZUzjFQueZ76eg/bhSVsD+kTOXPN9mgXJl06KDNLM9KH/z/Knaxgy6yJxUUGLWpN2ioK7VO1qP7fDXyF6unp2mzbqarJj/nObh4hFpZfHHlN8SAqMiEiH853a6j6Mp4RP/fQsC2oNzKVFv5nTvGamhpmL848fCwHfaUhwGuUCC6eJD0Gi7WnXDZKcDqRSWnmqv3GFLrZwwv8jMNIseddSPV1pAOZKMfjdeAmPxM1ECRb5fLYh2m6HEZbXXLDfdrTcTis/E4uMMFW9B0FXw6ShFWJuDdHb/vWuAQ31+Ny9RHQEs/ai7BfmCnkHhjWUsR+M7S20kmsdVMmiqWmoPOqwl6A3+o7HsQDvEodNTKNz+vjK1Zr09hexyRngoOk0wWgS1MUrvoN8UoWDhPX2iTFv1HaArml3PjhxoIQc8RKGGHOrai43ojeHqsIZNUFluW2u657lD9esDpVVUy0FQJtZdUDwPiWLreiXRlTKoeN/jblQmTvPoncYyHGm5AKKuH0AHtPpub2qJ5arQHLpFqwz9k6XNb9sicaRKtYDDRUU73jaLz6/PBWebJhiW2B59g1kUKD/Ztqssczh/rEKoLzsoZD9n2XrAHnNlAOkUlrXUtKwQ5lRIdxsOA2R9GXaXvXkszpwTUVw6MuxJufj+YQu1p3zJ9lV9wOQBFDsOvo4oSjOpnxs7YtbAb0pE8PiUALpgJNbgygJuKNnfvLi5hvh/iqM59eKKYtCXa60VPy5hnsMO/6sHRFI0grrXWsj7zT1a+0IBPlzY805aeHWmQdH0zUyb1srRjfObtg3ltVA8zUZZlNaHgQolHZ035mCx6Op9XiSuOKMjyvf03sGZ/zCtY4qreEWVBL2QCT+MECNrUXt+nCmwCo34lFy367ndB6XS8L4HF9kaKpLxadQvTualBuYTpbs0B//+B3/074aL0zLt+g16b+uvKNIfPdPKf9CutwB6+HwxZsYEskLKpMTT91H7oKHssqwf7WWK4B1R8zGQdb8DXuxBDIG7cRaLPQNywJOj2+9NIfgTd9urEBp0EpcW7FJkIwPsBvATVkEgXkdsNPdXnXx7/HekPPmru4FoUwGHfj2dp6MZiKx0RK20yJI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mVY18KV+DRA891tghXeycdKct+BoHR8C60T+yFDI0rGQtkvH8qlZILGphxaoPvMnUAb4b6IVKs0UE+imN5YkKG9w9yp3aG0zjS8/PtTCNZrri/V4J8+efwRIQoWM6hbW1wi9mqK8dIIALutY8w+ziTwZ97YYoI6tT0XLWXDmf2cMaTCs2Q8KK5CDVkqit3KF15lddt+2KyjvtyuHLLDYCugm4jaJMKT8Td3zbJFMSVZk69/u0rBhgjbNtdtREDe0jvc51fn8M+7FWXgeky9rif/7EZp9aSdyYAbx8Ma+U8Hfc2926etIpxd35FUJG8cz3pgUXsY7Z10biWSBr/6VwHMbp5TuFgS2nSRgELAeNQXCuL23N3CkRoSG5pKW1WCfqJdjCZyvilSENhTvfM/UzHdSevdsJXzS50WrYZLyiMYV9de1cISX9uPBIZLGGQ2/cN9kYKoV/K499ZC8vnpmPT+cHbacY0H5Aj4sPSuc3SQyqdwxm4x1jhFpPFsbjl4IgFS3VG7f8PoHiXLtzOnWv/K7/9RBy+yoRmPJj3vFs2f4kLrzKAaKwqzUXIN/dR7Ux1xzXaEbs5p0yPyUbb7p8eoHsspm2I5O08R30fDz/f20AMkSdusRCD+AMYSMCEwfTDXeTla0kvMPfPCqDGRn7EpA2Tr8NWP9pAiMADL0dXNqg6AK5mhFFvjk+52maR4zwv91d9xef6350B75SELaRb2E1EVl+x2liUDIYdgvKZiUP/gnMYq5d9FwsPnru5cBBh2EpAIaTbcm9HM+Q+Uq2TTYhK2dhrqiP3VJ//r19gb39aoG0Ks/3byIt2WKaqVIwH+j3bU+wsUsXV+6ilL92nmLeLbm4mLXbwB0sG3QRJZHsg4b4+lgoSy2uBz7p2aQaZw9Mu3T1SUPbkZ2J6x//ZroVbB+rvPNyipbHiXX1PYL18sD/70EgieBNWYmVLAiQoQ3GUqv8MpNheyhi14mDrDx93Spd5qLIlQtacKQ3iBTXJxlSw/tHivN8NarjN7VFXUPmokNnZLVlQpLa7GTHJ3W6QMprXnE4PoKPkcSaQnbASYCbUHiO4fq4/EJ12vBmSydvyi32SQ9LK1tfPWf/gxZp3j0tKABYg6ThRuom0tQRoUNv7MJJvJiF6ebpfSUzbt8l65fF/EU8ZdmKoVyQDkGH531fYQUbK6ZkWTwdXG+7pEHBYVoEzxYtwIQQ60fMCM2ljb9FA6TzGlmai7wPZ+aZE0vQrbeb1L8LmvnWoWTcMeeQdITsNjMY0pj4n8BATShzTuvgttcZ9iZoUS2M9rAHnY14333HOuFl27ZsbD8p7Wiqxd9HBy6dW4WMjnjst3ej8FFDWY4Id9hJu65dpLsD6oiZqqwrdVYzgTUpJQAabpialqADbDbEtvj/zQhiJht7OQtw0l0LqifYDI4Noq+TAV75WSX+R2g9S7YXuhkAFF+ZDwzUlNHlmCHwnWJooXCw6UsQ7M0Eovr7O/gRtdZ+iHAI3gcx8UPnoncY9pugYfANAUAUMGySdWNUUmDXCDrQiDgoPnDu3l9bc5nc/vIwIwCGbozd3Vf/d8AiFLXCWY+YNxmQDpGu6uG786U X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cffa0d44-24cb-4c23-5a11-08dcfa8670a4 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 15:04:10.3552 (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: D96vuK6PyP89Br657QAtqqCpL5tDdEtTOGLmkS0IRjWi3L0E1gs8Kppa4MBA4Vs9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6621 X-Rspam-User: X-Rspamd-Queue-Id: 082B140029 X-Rspamd-Server: rspam01 X-Stat-Signature: 35hyg6fp457pp4rs44dwjzaxxq85k4ww X-HE-Tag: 1730473421-120692 X-HE-Meta: U2FsdGVkX19Qk25BhH6kasaA/A2rU7nouJHCyM4oJoxxQsFK1yOjnn7BnPE5JRht9i+sY66EBaWWibuT4fDzjB/94zC/OMVbaxyU92NqCEb/hpSQkGtSxWFOrCfuIx8025mfdbLbOD8xZZRnLF5ObBweIZwsltkCajBBgRhzgG4b9N6pwGYu4UYsvIJbZvU1zEwvgKKQNaIbq7n9oDAUleilxxZaLa6CjKLQ0t5hOxg7bOEhGTlBgn1rmGSQaw/fqdB58aL0zgCbaEGsePgJ0vnz8xgyT9IPC339/N2Jb5LJSE0REZpuqEcTC1IzG5yk65ZSrJDjkkrzOmccDk8uqgBH1B7YUutLSLhBxCrAAceaewg1hv9m2TPXpXJwt/Ui3ChA4RSk0xXZF28Gz8Q8gWW4C1ypNveNPa5Tc/ekc4IPDUPo5bJo3Z4nh0RsGVqlwOt/YT43xgIEpKtvUU25vwiMaXhiBqSOEpIxHxte2HUOLch3rCYkT0F0YrxdacjHk7vbOSo1RU+MKttxxysqQl2SM+3dukLR6TF//+9ywTgggF6+UQpucGcPnUMqOQm4M6A/lrmq+/uXVg3PKpr1o5wRnuRK1y/8jt9w20Fs6+Zuf5Xtg4r83ot6MZoPtV39ntut5CFXWn1c+SKOJk/zQWe9QfnK2BvTT9hSu9VTl/da2zR8/XvW9qJESfjgUScuC6qcDhxtZLGz/9jngvV4dgZCbQkykW56v8LOhwztKOecwjUPzzDOYF+uTCzysaqOve0OKdFVHR1nyMTDIW2J/pLFrdqhpoDaELIPZI9AsVd+PKjWSiZGQhW+sIPo5ahaxGsnj7sqVbNhq0dCUO9RdlF6V92D2swVHGjnHsqDnsDvVGOk511dawK3OrZT8NaCc6cFO3KhT4QDWy679Z4OryZ3ehuKOKB/Psz0r+bgh8PPxLapcqaESqhHQsa1rqF2g43A1gDpBeqH3HN8bvE 2Si1/1Kr a+yO/rGltQOCvMuFKvA204gy/jemfTDbPnbWR4j1wJ9sNF+yBZue3xDpaVLztn45SBintBE0F7tnF2+cWtM907tALJF6sgufF5aLNQluT4rd7LNVGKztPH+IVgnDwYkKybKZ0wOR+XfcSxkVUXLh+Hzf2Mk7yEQ8H/lAS+RtOvnKtvpXUgXRk0T0VFSh+hsZvUWPI2EqJKwohg7SzGeRqb+utNMZBcGVYVIS3vENmHmOizqm+PC+3GxNxZqMunU4BXa+0cPqPCIg6xDUHcU7OtoKbU2S3F7U0d/nOUAxDPRA8CyNzronIFtqmt0j++1QNrHZ7MCgpWrmun8BB3fd1dEMkgA== 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 f7649043ddb7..63ca870ca3fb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3705,57 +3705,9 @@ static int __folio_split_without_mapping(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); @@ -3971,6 +3923,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)) From patchwork Fri Nov 1 15:03:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13859517 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 13E80E6F069 for ; Fri, 1 Nov 2024 15:06:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AF526B009E; Fri, 1 Nov 2024 11:06:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95EBA6B009F; Fri, 1 Nov 2024 11:06:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D8CF6B00A0; Fri, 1 Nov 2024 11:06:04 -0400 (EDT) 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 5C6136B009E for ; Fri, 1 Nov 2024 11:06:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 13AEA1C5580 for ; Fri, 1 Nov 2024 15:06:04 +0000 (UTC) X-FDA: 82737850608.24.776AA4D Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2076.outbound.protection.outlook.com [40.107.92.76]) by imf17.hostedemail.com (Postfix) with ESMTP id 1E5EE40033 for ; Fri, 1 Nov 2024 15:05:38 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Eo2gG95e; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of ziy@nvidia.com designates 40.107.92.76 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730473504; a=rsa-sha256; cv=pass; b=bukAYCrl//sZ11hJE6pmHk5r08KvVgHk6Dtdn0Dd/xPjXwILytSDe2mI5c1gK/6CrlNdAM UgIZYlndKczpUp3a0SlDVrratpEJrOc0hKPSpepumevFplYFmVOPVOrdPO7kL0G26l9lon raIaBf5agTzw/6G3KsowCHHh/NffISY= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Eo2gG95e; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of ziy@nvidia.com designates 40.107.92.76 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=1730473504; 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=wKioLr1HycFarfrZhAg1ByCjDsmUJhCDoEV444XxKIE=; b=ZbUHV3LO/Hm7KdbVQaUpUQ6IBBCXv51336haMlRgUy7mUSV3w4VQhw03uxrbXyGH5SZsMy 8mnbAG9NYq6k5aRuRvVYOyaVobjWIv4uXJ3pYFHTVSvkdxoGl4UikiZZTokZNOPLersraX d5N9QpMbIF5xcKCg0T+R7BvMkmGARkA= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i+3dZDJYJTsFXi9IjFNOva9oVaYsqWUklTS8atRzfxKEtDPWplFaK1j11CjkgkkYitLDkj4rU1w6O10iIKxuPlQvJVWMP3O704zJbv6QsHkxR1yzcsJZbwCQNR+xves89uMMA64LbyGxjraPKWS1PQm9f6FQ77NkgRY0FQQu9y6rjUHx6Vmw/Bm4tLcuuR1RrMCmwDMhVig2c4qPUcTLFrApw79unqTXdApYhrD+lTkkIH5CKt4ZmykjcF3TpPEzURleodkBFs/OFCyS6fnrq3ytNiYpkEJUaBNaJOrJk5/oXGYyy3re/L4FvrTMyuHKEzWNARKFRJavT4KiwioHIw== 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=wKioLr1HycFarfrZhAg1ByCjDsmUJhCDoEV444XxKIE=; b=MZRlOAbGcbwGp9du39Pm12CdH2fmLgkQs97foLeWcHrTiCj8rXj72exvHlwTb7UkgZ9fm/BzsKkJs53+rTzeeVUmnW6Yf1V2hjr30HImlkiLJ6SlA/mc2JkkcGY73Ga0YOAWr8pguOBzVJWJr3TPzpHo/58UWH4qBivwDpuPZwvaMkfC2mU56tb0iI2B8ox5PzITx8NcWD43+S0hCQkkJjRUIi3o8G58GWiv4q6dx20x2VZLhdzNbtg9E1YZnCrQE6wWUzP3hoioNO/sZIY4BgGi/YZx7fD5voqiBHHSMOpFN21BAI/nhbxEO9RPbMjQFUrxU0YGka75Spx215a4kA== 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=wKioLr1HycFarfrZhAg1ByCjDsmUJhCDoEV444XxKIE=; b=Eo2gG95e23JftwobdxP9NxR0XvbDR7F191JuyHUjKUdZIDNjf3MZFK0fZYLKjFL3X04/Qz7gJBUmcTJ0Png1kR2mYwNfC1Mi153c0KgmiOXYNm/FkhrXDkFYm+fIzbrCz5SpsnoYSA3dx38aqHNatgI+qzao5DerHfi0pyIpLKuyDkIbBcsyCTktjll2Z3PsVI4BMUTXWpr3oqBfK+1PRqs3NNEPP99B8naB1HTxkBXYjnDyGgyXbvwydf15Vq5pZzWZvM2V1k1QeBopfLI6DQHCzfLQf8buuhDdcgr2UyG95/WxXMF8iTTMz2SR84nh7XHWkDH8hpJWGsBh6Nl5bA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CY5PR12MB6621.namprd12.prod.outlook.com (2603:10b6:930:43::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 15:04:14 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%7]) with mapi id 15.20.8114.015; Fri, 1 Nov 2024 15:04:14 +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 v2 3/6] mm/huge_memory: add buddy allocator like folio_split() Date: Fri, 1 Nov 2024 11:03:54 -0400 Message-ID: <20241101150357.1752726-4-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101150357.1752726-1-ziy@nvidia.com> References: <20241101150357.1752726-1-ziy@nvidia.com> X-ClientProxiedBy: BN9PR03CA0104.namprd03.prod.outlook.com (2603:10b6:408:fd::19) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CY5PR12MB6621:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f806450-3353-41e3-a9b0-08dcfa867195 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 2xLtUKd59diCwbYnvUE1rCj9K5pkd6OHA+BwvnMsSwf0rPYwzuVQT584elsL/WnyE4Wqtj1A/Wvs9Lgb/UPD0p+1eQ7G1ZCPuc/Gelgrm/l2lGhzH55sQOrfEU5A8kBQOTpSymrx+Dxh6RW7OpQk5bithpI66SZ7XO0+k/srY+T2Pzibgbi7QVUHfSEy+Xpe9XPHKVOBNfsEhbmAOz3FE1DYgQcJHO9snUlwCzPqQX6JhV/ycdDDV7jZ0jROpres4ya7JEFIWgXRl9GKA0THAZesSAg3ncoeNTU57i3hBwauuo/0+/RSSX/oZwPYokIk86sK+/KI7QmXrdkQBYB9v90WUs0nGpS1I/6aSGs+HpR1T/15DyNY3dFmj8npqYljZOnzW3lpLRH6ocwrEKGXPXmNbm13J2MHl3ywRgkq6HSqRbZbJDijonh4NGFmyLB75h07GXYGjbXcPVm61x39k83iopeiqF8KJ1/Xk1Hx9oQwHud5OZxtcmeUQYQiM0K8KTYTnlO01Cqq2DsdCG6cuwPOShXcT1byDGNe+yfWBVvDkH9yPJ4AieZI+8hW5Zw1YfL1aXUKRyyWDg+KOROJPtbwpCPIZyPnXQwAFHo7c7g5VCvSJt3N8G5h7WiqyOTRUaEOhLJfu5jFOeLe2oOaDGCr8fXf3LitmeOvlim3b7H0bejY3yLmAJIC6BbUUjJ515TsVjeEa5MKaYBGjf5m0uARLFhKkPn9ZplcM88bu/57vVnSrGOjaLelTLZcmNyZf/xKZR0LO4wRg4N2FyS52pryN+kQyD3dIp4UwY5JAJqyPgIFax7UIYk2vAI01/GweQeL5h2IoHsweUVSr5rExoSQk1vkAkBviJ7ti4ZuesrxZ6g5L9We64kfXmdCR8BLlvRTXYKdB6VHl30AOjoHSs12aMoqOu8QY0vF+H4oMPSDz3sl+bdWWwxKOn/pBHQ2woTpfHV9a6bgBgfMndd8Dny/me/AJ0gFilHdVuZ7ziSKkKkXuYIkLGF7QP0fi5KkS5cJDc90fGqfdIw+eURdBmRHDNCFIrllcl+R6AjaTolQEjeg1aGbzgbq3klO1DmCezujTy680vaoJu6y/qB5At46AJRHDViTZvXr2HAmOdnp0RiRBM76U8GZJRUzlhU+NxOkFZfmTBdbs/XJVvnla9YZwiDSCyMD3pz4i56mNccISekyRsRBp5OZXTiTHZaHjQaAFyKFZXyg6zh1Hb/6b/5Bv9EQGwGNPvazFI8M+JMqLSRDr5mvB3H6MQSaUOnK5hD0Q9ocQiipx4A4cd24fswboepYIo3FVcjllelGsvXjvXcAp0hHAPYN5cgF045h X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +uYK1geha0o2VRJocO2907wiRjG6hNi1tdzSGb4a+k7SWA8qRq0BNj0+IJ0xG48smVVbH7rlo1ZS0N48jqD7GbHPz5xOebEr8A0KQTolUET6eRMNO34ooVB+2/0yrx3/s+Q4fze+Blsu9KmHVuysLa8q/I3aZDrSox+0pF0glfc8G9qlEjjXv+ZzHK72kTr+602CrAV5LStC20lcq3n67l4xffjcBH2xyEQjaCbNS3JzthbVqIWI6fWGGOSHgp7ciE/kMBN+vQpHCqdOR1PSM4dD64Stlc4r6hee0ZnxDKcqHTuC540+ZrOfaEQHPRwcbHgds+w7W0Xsp1+wwpSHjPeeAtFLOPTOgsd76axwp3HEfTQyTNHSEu1/Gdy+rn6D2q3J1Qxq87149PASUOoUUJsxOR7UETNjXfjFAGnN+20W+xOPiQnOBIEQADoj8a/AJDpwT/uiQRw2k20VF46Zn/8TXGpVM8NvY4DYfR/8IskLuUmhT16QxNp+Qz0LhaPIVjlufhhrtbmdaRQwf9t3anT/nxOmyen2/lYtkKLmsevpwA9NoTvCIAqSsSrVSODKcK3GGkLC7pDxTMF7wCvIta8RyHtPJ27kfemY2/bOJ9Dy/7Qf5eLfMXy+VVFEbofhIalzf6ezEYxKDX1miYX315uGZxP1x9QdiCgtMWqH0IEbBulgXPvKqCsrz9oN4cw9ZeVAjt/k7fdT9aSC6Z27QrZbvF9cQlJSn6richBMalHhtm/JOpZrsNThy/MVA/L1TACCFYwc6UN4kz+wqwTqpLQ3L1VBGNCeletXn4sDK74IPnzAjLhfdVzqXYrwytITOHFHreBnKEs9N5OGT6/LthCdVkjv6IRYrlevkf07fOdh9iOF8eSIAyCO4znxvYxKf8VKy9fVcHaVkVSA1ZL7tEib9ankGruJV4WnO4QX4IMLqVSLw2jPp1DJO0gSV1QAru59W9l/IcdWWcf/ZL2a0h+yalV/xtoE4qOaL7v3qk3m5Wya+C0ohPw6BjH55eM4Q+MriahsoRP2uaBOluAIjYlHbQamMGxfU/tA/wcZJ4hrdWW3t/mNM8hxH1+b155Y3xoG1ctN0CfSTAebLbyJLIR8Nn5Yy4o05c7HK6sB0LVMRpjmH/Ldz5bCNVKQRY6QAAj8FJEYhbxoBIse0XXaDERqT6LUID5r5IC9SCTm/28DWW7QYAC0Y9vPftIr+f2ULLV7mdHdyEWNldjknPsOjrOe6F1uyYmvsI+t+00hwbeKfnwidhpJ2FNhAmBcWcE1Lb1J0/JgfGG7WhtuIdF/Go856HVrwA1qrjRPujOyDj2XIHvPzTjwZuRCn33IXqI7d7B1CE7lK7H911GWPO6LHZ1bdzCddu4dc3axwP/1kwYR8zJSLQpEYSpGdVEFdlunFAj8lIB8koesZDmBAdK9PzW5P4fvk34FRm0Za77qVBquJ3cpHBIKgxmddn5csQgZTef9eaFoFyiXuRYCK1x51OvzNCtsJkvCRJSeuIlVIQCn6TcCAAkhQz+oHq6Lod/akUN0SFpLB7T+TJzLqiUSFDw80pXH1grj3VHxLIx8kkl/Yt6UBhxTNT5vepWOb0Iv X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f806450-3353-41e3-a9b0-08dcfa867195 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 15:04:11.9369 (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: gWhB/mhHh1S3cKk54Ffm4G7e0O59KhunT/Sq8f1zmTpfByb/sskKmI2gVP/xkEal X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6621 X-Rspam-User: X-Rspamd-Queue-Id: 1E5EE40033 X-Rspamd-Server: rspam11 X-Stat-Signature: o4hm3br8tnwogyw7ncdn1tud8ojmbyuy X-HE-Tag: 1730473538-127116 X-HE-Meta: U2FsdGVkX18Yczq1j6SksBIM8tHjOV4p2sudviwdAFfpGBbDrW1f+oe13ctWdobuor4hqVD2d1WIMr832u+XVWJJsK3Z2Y1aN+060bMejKWDbFViZ9S+RIcxxopLJn15P6nkadmfSsRm7m5IzfOh8q/E9is06wkvNrvTQ3P6z4aLh8Angc6YG2l5HxFXNlkxHm5R6ldgXQvvjUaUAJPOqGnZFC23AuA0F+b2FmiMGxbA1OzlpQCr7oCAJmS5vBedno/lt2zLOcXE6P5TvgYoHbN/ktWSxrW/jvNtfA4xTevbcD4OaD/qOz5JnCPYONg6W1hBb+NH5hufos8ZcCKZ1Iqh1ZmJazqQCkrIvXg1d4NvacTe6OWaaeQgfKJ8NHhdQO6r99lXhf+C8ioSAViXaLdpCWfOfaXUl+zI7GIHTegbmbna6Cs2Llj+UMqCpBgZFWY1iy9ZY1oZASrDKp3uWfuo8mwSZF6XnKyO4M8yg/Vkn6HfYZKUhYZZyZtLZ2ceeJd+L+JHrxti0eQpUPOeQAHOvFxs5BwxZ0tsfNvEvuTkeOPMITruX5rl0ynt01h3JUR347JOnobzSL/VPJWJEtWeeDXtpbZy44jopqObd4OfoIZPt9/LGSoU4kC8BSOIGyNgt4x1bXPDc/woqNQVrcXMQxdbWZCZrfdARrMQwoUTGVrYKDxrymsucSjT4C6p4nHyLx4dQ07C6KLIlgT4iVuFos17DIK4WH1vy7vpa0othaxQw1xcDSig+LxjZ5Don3MLx8Elqmsf3/oH5XEcC8lcn11EQ6bpTAy747mah9kb1+C81t7mfk6jv+p1zUp3MwV5O61YnIU8DoXOeZRtuciBfghOPR0HIVaxMU06wdIpbS/U5I/ujtwSrKGMpAZLRbQdHT5N9TNRq0w4TXAteXHnrwkwocT3EGqfLqGaJfG+ABIL4BZKmCViG8cUNZIWKRcSVzORGY340BGXOgP nDc81wnW MmuUDVCeUARaI9KDC2Bt9hEW2ihraMqQYZM23im7MPJZPVjMh9FClVrQH5agpEuLzIKK03boWskrZ0V/bpjofUtGC/bIa1AWknZR4tjesoRCJkF1QKVLro9bcmHnbeSkVdAgaB3t092iBToXb1Vy2zz5tx57Ul0llZ2YNqSO5vbSYHr/fL5yhrfjmWML1P7bQ3jJyNdgcY2SZPcj9WZon8xzdz7JnbxxGcud9lmLodO6shRGJXVcsWZhUlkyTHSYhbTfDeVKakkOVGJ1gP6ZOOgfuF2Py+oCtHbIM7/dzRWtabuqLQ20dq3kOR6Dx5k4iUPB3Fs6baxDehVAQAPnBi8tV0g== 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: folio_split() splits a large folio in the same way as buddy allocator splits a large free page for allocation. The purpose is to minimize the number of folios after the split. For example, if user wants to free the 3rd subpage in a order-9 folio, folio_split() will split the order-9 folio as: O-0, O-0, O-0, O-0, O-2, O-3, O-4, O-5, O-6, O-7, O-8 if it is anon O-1, O-0, O-0, O-2, O-3, O-4, O-5, O-6, O-7, O-9 if it is pagecache Since anon folio does not support order-1 yet. It generates fewer folios than existing page split approach, which splits the order-9 to 512 order-0 folios. folio_split() and existing split_huge_page_to_list_to_order() share the folio unmapping and remapping code in __folio_split() and the common backend split code in __folio_split_without_mapping() using uniform_split variable to distinguish their operations. Signed-off-by: Zi Yan --- mm/huge_memory.c | 56 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 63ca870ca3fb..4f227d246ac5 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3706,11 +3706,10 @@ static int __folio_split_without_mapping(struct folio *folio, int new_order, } static int __folio_split(struct folio *folio, unsigned int new_order, - struct page *page, struct list_head *list) + struct page *page, struct list_head *list, bool uniform_split) { 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); + XA_STATE(xas, &folio->mapping->i_pages, folio->index); bool is_anon = folio_test_anon(folio); struct address_space *mapping = NULL; struct anon_vma *anon_vma = NULL; @@ -3731,9 +3730,10 @@ static int __folio_split(struct folio *folio, unsigned int new_order, VM_WARN_ONCE(1, "Cannot split to order-1 folio"); return -EINVAL; } - } else if (new_order) { + } else { /* Split shmem folio to non-zero order not supported */ - if (shmem_mapping(folio->mapping)) { + if ((!uniform_split || new_order) && + shmem_mapping(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split shmem folio to non-0 order"); return -EINVAL; @@ -3744,7 +3744,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order, * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping * does not actually support large folios properly. */ - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + if (new_order && IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !mapping_large_folio_support(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split file folio to non-0 order"); @@ -3753,7 +3753,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order, } /* Only swapping a whole PMD-mapped folio is supported */ - if (folio_test_swapcache(folio) && new_order) + if (folio_test_swapcache(folio) && (!uniform_split || new_order)) return -EINVAL; is_hzp = is_huge_zero_folio(folio); @@ -3810,10 +3810,13 @@ static int __folio_split(struct folio *folio, unsigned int new_order, goto out; } - xas_split_alloc(&xas, folio, folio_order(folio), gfp); - if (xas_error(&xas)) { - ret = xas_error(&xas); - goto out; + if (uniform_split) { + xas_set_order(&xas, folio->index, new_order); + xas_split_alloc(&xas, folio, folio_order(folio), gfp); + if (xas_error(&xas)) { + ret = xas_error(&xas); + goto out; + } } anon_vma = NULL; @@ -3878,7 +3881,6 @@ static int __folio_split(struct folio *folio, unsigned int new_order, if (mapping) { int nr = folio_nr_pages(folio); - xas_split(&xas, folio, folio_order(folio)); if (folio_test_pmd_mappable(folio) && new_order < HPAGE_PMD_ORDER) { if (folio_test_swapbacked(folio)) { @@ -3896,8 +3898,8 @@ static int __folio_split(struct folio *folio, unsigned int new_order, mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); mod_mthp_stat(new_order, MTHP_STAT_NR_ANON, 1 << (order - new_order)); } - __split_huge_page(page, list, end, new_order); - ret = 0; + ret = __folio_split_without_mapping(page_folio(page), new_order, + page, list, end, &xas, mapping, uniform_split); } else { spin_unlock(&ds_queue->split_queue_lock); fail: @@ -3975,7 +3977,31 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, { struct folio *folio = page_folio(page); - return __folio_split(folio, new_order, page, list); + return __folio_split(folio, new_order, page, list, true); +} + +/* + * folio_split: split a folio at offset_in_new_order to a new_order folio + * @folio: folio to split + * @new_order: the order of the new folio + * @page: a page within the new folio + * + * return: 0: successful, <0 failed (if -ENOMEM is returned, @folio might be + * split but not to @new_order, the caller needs to check) + * + * Split a folio at offset_in_new_order to a new_order folio, leave the + * remaining subpages of the original folio as large as possible. For example, + * split an order-9 folio at its third order-3 subpages to an order-3 folio. + * There are 2^6=64 order-3 subpages in an order-9 folio and the result will be + * a set of folios with different order and the new folio is in bracket: + * [order-4, {order-3}, order-3, order-5, order-6, order-7, order-8]. + * + * After split, folio is left locked for caller. + */ +int folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) +{ + return __folio_split(folio, new_order, page, list, false); } int min_order_for_split(struct folio *folio) From patchwork Fri Nov 1 15:03:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13859515 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 EE372E6F066 for ; Fri, 1 Nov 2024 15:04:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D8176B0099; Fri, 1 Nov 2024 11:04:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25B1D6B009A; Fri, 1 Nov 2024 11:04:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC016B009B; Fri, 1 Nov 2024 11:04:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CB97E6B0099 for ; Fri, 1 Nov 2024 11:04:36 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 781D11C5463 for ; Fri, 1 Nov 2024 15:04:36 +0000 (UTC) X-FDA: 82737845820.20.4C76EE2 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2047.outbound.protection.outlook.com [40.107.94.47]) by imf26.hostedemail.com (Postfix) with ESMTP id 24A56140027 for ; Fri, 1 Nov 2024 15:04:11 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=l4OYe1+0; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf26.hostedemail.com: domain of ziy@nvidia.com designates 40.107.94.47 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730473417; a=rsa-sha256; cv=pass; b=e0/Cr4N0ZXeZ88oWqdbeAS2HKv3BUSEZwlUuiEYhd2nJavl003thPuZF2IhEB+a6lhsF+B hEdLyTzlUWON78Q/+vFY0ZRGW4WpgEfoNZCbh6Yu0W34yQf6QuHnolirjHfBKiGsGqrHN9 BCbsuHVZfuv/JPkx20tgkPyE7pNZecs= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=l4OYe1+0; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf26.hostedemail.com: domain of ziy@nvidia.com designates 40.107.94.47 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=1730473417; 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=suGnhTcndxZ9XndQoK2ebKftv0rgruxD+X4FouvzF9c=; b=Capmmqdva+Ah23dK46EIcN6lq04oBAvSYNabeer2anRThiFA6EM739aE2YI+eShUwPpzAv qNCWfbvs7dQkCfhOlj7Cu/BWWkd+zO5F+CO7REYCZeTBW+X37lJM60wmyk6z61qPdDkjdF Qt5B6nMljUPNg8hyg7FTBPXQnBVzAwI= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AZlRRYN70X2vT2olV8qJKpPEvrbACTgC7ac1YX3T2T7PjOK4Qj/19trLjsc9ngQwOdv188OIHSaKtwG2PFh4WVl2myOwANQCHFmmqu8sMJ5k7Spge7CxRGP1ygOM7aR/4sEPbOn51J6k+XJeOeYQQgawsmgySXk5oPpv+bVBhNsbqub5ABExyPEDvGakWNd1yQm3fORDNfD6HvyB2QB0PuVO0l3gXi1dy2FjN68yQ9SI83PHP2EFcC0tiN2QLVp/w6DRVMJdv+osgfpWqHwkbuLoHpKCJ/FzBbgszj8TBgfrZBmrbMCpXWP/B4m4f9Ec/7pjKwm0Sx/6wgZjLiey/Q== 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=suGnhTcndxZ9XndQoK2ebKftv0rgruxD+X4FouvzF9c=; b=CdM1W1g8jXCKqKU841PkUewl6/czv1xW8JnEz5IXgqog5nVl9tpmwuL3gIZdmYapwlXlt6Q7aCLrll1CEhK9UdDR7JIcIRIFeLoG9/dOprAx25hENOEFW+zPC+rswFPSAO3J5MV43x1+3WHIz1ghdEX0PzP9dCFTvtmRp/GR1d0oiJSOw3ExczvrlBqlQPqaDmApkfvrUGFhwCtNBUkJ43ZmD4Z6qx/H4waOis1hAfCfOCTI3NR/PtPeqXn2g/PZXXJ1ZZV1N5mUx+Z2WSeU73lWfzYYjbAdNMEVPfsj6SjP8LKIl6PNX9kMvTPnoQq8ZmX64LNXPUDEMH8/UU8JMQ== 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=suGnhTcndxZ9XndQoK2ebKftv0rgruxD+X4FouvzF9c=; b=l4OYe1+0RpmXoQxhZ4LoAV/5/23E1WGMrIhO8IDZpVdgIDcy4s40ON4XZ5oojkEascDWqhMPPakLgBTRUCNhbGInHczUG0/V/Cr/N81SJ2uKwOD81dtt4YYLlXsr7aGB/ORuX4lLJ8oU3lFjNpyL6q1cqKCHjEgIsG0IWv4aniWoeRQaHEGaC1pQRsjDn7uxbn3iT0tcQsp7u2yOhRWn10GGd3WS4yEkY8NEusfKrEAN3BloIHyNErL1suI2KGx317Ls3bxyGBnPZuaAxYCpzMLu6nd9rASK0WQx0VqF0o0y7PMKp6txmb3m4ssPPmcPKF0lwsSNbQ9ztHSX1H/zFA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CY5PR12MB6621.namprd12.prod.outlook.com (2603:10b6:930:43::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 15:04:15 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%7]) with mapi id 15.20.8114.015; Fri, 1 Nov 2024 15:04:15 +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 v2 4/6] mm/huge_memory: remove the old, unused __split_huge_page() Date: Fri, 1 Nov 2024 11:03:55 -0400 Message-ID: <20241101150357.1752726-5-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101150357.1752726-1-ziy@nvidia.com> References: <20241101150357.1752726-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0134.namprd04.prod.outlook.com (2603:10b6:408:ed::19) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CY5PR12MB6621:EE_ X-MS-Office365-Filtering-Correlation-Id: f2b5bfad-d154-4ba6-0c20-08dcfa867283 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: KODxz14H2Z+04WtnCRS86SP8e1cgftFdKIpf4i7flPSneg38dPYqkHJp1kGknd91pt+kJRKjr+XSIz0dMUwUE1+0kHFfJaYnaMqxs7fn+1jidOQjPPitpyakC8taqBtRKtmxB8z2iRQ9GEWPRnlNjZ1d9lkkGKFr/PP9dv34ILYWWXkEPpAbkrtLWfMW8CENd3vgsREFb+8nK0+JoSyHm0DEzni2YO4I72g1zdfn/OX6yyDdo+3ZIfFMQdfqDgBw++6riPaZDGKyQBeYxZsOSne5kDfAzlyX6VVvo67fy3hgL1pNtVLk/1tSc2xkFBRlp69BRLJU82hyrxi0m5LCwPEqwpdnc8mOkZYEtWonsAvrdXX6D4heXVDuRzCOp8svRvrSBAgZksHOknYWIWMUwkx5qa72XMVzPhTT7vlYwbDN/Q9I26D122e9YHKFkA8Vr/c9jsiPmsP9xMV08DP0EzTVi/CKGh6xSXsWWvlaI9bKbm0HGaW5pfDvXNAOCSvvO9iIAHEZCqD+yZL6VaOnPF2oGKJ0o8RPjfygVdOQ51zqnYAphPe2eVYm44Vk6TDTVNEX7ewKirVlJsv2Xf/BhUzBTf7NwwxNBvO0pAXpcYsLw+7bUAAVqCJNBNokh903HEOPzTL2DwECK8CvlUir5iWuNqeix3Mps0akUL7EIJrei48icXqYdljKm8AqnUW0ulC9FgyTheGQsfyW0tFIJ83csjhxQDvhivJxzP7M7rDsyqS/90YxnkJvqaQfsuWFfPqCdmg019Eol5i2wGszjoJJN73iN6dGDiOPlwqxTBZJKmRM1WSIjI2rcFqcffl0nNlnMjdl68wCQzqUp4GFCUTi+pPVOYIPC297tcmgX75R1gpi4b2yp74GbsLPoRnnxuV+Ha6Kq5Ed66dLrQrZGCYwDaURrokTjAW3mxLYVKFd/igP7g8vBEv+807E0BPnSOQvXwMPmDEow1uI6IBPIDrrsvw0zq5EHmeCXawMlgdHyxotTcXPD9xikg/sgZl752J0tL7OnmC+WfYCudOWga0QfJ1YzPrH3fQ4DGWnepnFPUMfOYdWhMw3Lh4LJoJP/sdY/D0ysdkQcxqDAWdBBIXYDuXJbPmmrNBdm//YcXIOnUn2ed+5DYN/MdOdVfvhYrJLWB5gBMLgqHEg4Q2CatQHEv3yTTYe7qaqx3IBp9XQ7sdAq/rBu/yd0Gbj8KzXH/FqwyiE9+XL+BVtEcY3Jp0tsycagEzhIOLVlJeGGuniM0ykuX8VumndIBR8T+lFSkbaSVsX6Qu4Q8ZuMHmwzthCIat5P0VP80ZGt08tYBN3+yTDr1AKBuHTa1xMKdI2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yec7W7Z+gHe7zdlQHiexxmyyfpYRIIHe+i1r0Gf0xYf7hkwtTsGCI01vpTT2j9txV0KD38Y9DdH2N9sGF5RXBXFKlZ6xIXNjOYVDUThl55FWuGusYwwbI6eg4WPHMQJUMmF4KeVzp8Gym9Gnryf/K3rY05kDzJMG9xqbyXvu6B4JHYST8usP/j1/TlS1CrgTn9b0l5eMTiNYfJNZ39jpZBYk6GcERaqsb2ml9Orsd3ok3yMpvdZb6XaUYYot+lYPj79Dc06yjtMBCQEVauz4Ydmo1XB1G5HLMuk1wNJqP/CHg1ohPsu5qcjx3+cbw0v+vxyDuJeqvLsm0z/yKaOP+X7gC0CiUQCW6oWUJFfSnmnK7CsPClJ+upvLx1FTlcl6cX94iTt0DJ6Rp7R54GXYPHGDH6P8kdbudIcdtdRWFZDcFHICwRKPUDNNklKgpmedHIxLlnS2pgJKaktByKTaVFz1RxmIcvGau0lOPP295rkopWqUa/E+yJ4lfwHDkEb+qJZjC0QOoTITFRbkVgrI0GUv73f9H8qi8M5ZqS839f7kUb4hqnQUwtbMk3RfplIyD+kam0AuAUSfjA0G7l3WDJInxKH0clXqQB+LcznesXb01DbrTwcvurw8A/ljjpskDDtVM/3Fuoi7TiF41CdRGuNjCGDDd4a7V0ZyzwmuaDqImm3SxYF9vE4qLAVLW5BeN25u6Wml2fA0nNB1jJyQWj0M9zIeECru0KUlzEmuI5+T1hsp2LDgI7WORR6HtbONl41Foi4NBNWxOMjg+lT4MzqtV75iWCi1fGK3fVcn4rGaQDSGZ+CAPNnIT3TflA+1D8+pMeG9MMpJ2dKLHt3dsFbdpZWYYLGoGUTe+1M7xVdyGZ9k4nBu/EkzCFPDFFAA4WYE7uv5Pq4txt5zqjKc8dDUYzbfIVgDKtK0/0xuIXFIPGMbBfuoiixHn710UQjZR/LxntCH/vEOLrprlOfmv2KfSWt6+dn+07jp4VjNe9UNOQK+VbYmiJFSDdgZS5zi35g5U01ybZyf+71zTa+wZsoWUbzD+qGVWQjTyb561Ysc7XHKurJr8ls6t6G76uKpmHZrxy4uQYGnFyNItmbt2z7KhTiZP1sYHEC1yF80uT/9yCShErHtAqdJXVVtiZXMb8kfmDzbMvs9mSZbH3Oznub3YjFe5/JmDp3cQ7H58R0bI4RXBTjy+p+eEmiTuMG+jfJUMRUvCQpjiMAErwA4nlwtn41KTksJ8ZzpN2nJSXEcRZgIEb0A4lym5HTfoLm5cBB0mVoAn+3+u32pbTWgnX41H83YxyoOLBdEOd2t4Rzj7ar42m5VftERUAo4iHqsiyIMTAZUN1pJxjgRN6WCmtpueryXfPTbcsfDoksl3OLh4bKLFG4zlUGb53i1SMzC74XlPfSBPLfY5pOz48Tedoo5iCql4ravWakKzuQjjCGQ30ARbLGe60PWC+jomkm24T76NQlF6KyexWmYdr4s+Etkp6eBmjv2BqVKB5e7KdrSs9GbyltEDaaNdm9VIYbp0k9DUvNB3Njh4DqIACqaHG6CG+jdg9XUqZwjl+hZvFi3zpFA/ZVVfNY77K1zLsNW X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2b5bfad-d154-4ba6-0c20-08dcfa867283 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 15:04:13.4858 (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: lqibmb7cZzV3h34dzGD9OwOJR0D6vQs1p1EIJjCro09XO1IaUwX8UsAQLY0MlVA8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6621 X-Rspam-User: X-Rspamd-Queue-Id: 24A56140027 X-Rspamd-Server: rspam11 X-Stat-Signature: xactua6qrt193x8ityjfjmf5pd3t97e3 X-HE-Tag: 1730473451-447793 X-HE-Meta: U2FsdGVkX1+6kF+tltbbJgc387JDzFhG1j8WVVxNQ4SAi0pzIXi29CILIcsMu5FS55IY8CYjN/xRn2VCLhRRUw4AEKNKI8dameuWC7qZ5JH55DQFg38bc5H1GX/XoDh/SHRZMV/8KqyCjAaTIZvS6DkLrBqpuSd769P9pXJgOdW/wIXbU5nEJ8Xxl6JlS9va2ZoljEDypXNSaCxy2h8EeXAUapOo+PNU16rOSEM9PMyaZTL3qr9fx+GkAu+YAfa/pZhcnJJ0RkbHwq0Hghgj9+++NvjUoo/XMoZf4yDcpjckXMk/BSne2VqIqKk9N7qV6KwItVWipxEloosp1wum/BS63u8RA/wHrWwuMpK+PTqmqeS7g57WiBQAySrYHR00Q6Ah5HCgja6qJDdZNna1rj7JLAjL91xjQQ2ihOHm0ytT0fP6ms1+3LqXnN5G0zk3LKMjrGJ6PBz+aJhK1CnBZhWLsjSXM4gAeSqHC+9c57sunFqWUZcTcVug3W7QQByVc6CmNtCKgS9Cuq+quypRdhAxsF7fsih0240wzdjYNIpy7jlmGycrNb0LQNm2sQtVTtQOT+RbuE/z6INjAgbqM2O4mtWRebRuTzdG5o7usbiKatRbV+UYsgEzvPqLAl0N1PvlSqGJQYWPtVSWmABwu0sHZjByvsZm16mBzEYu/pPvh6kELtYPZaDMsVyCnbS6sDG/8JUR/Wear0RLNVq7i8+ZwRU+R+S2AmCqMACABGhAdPOj/3hX2omUES5SKrDGcvDnP3n19zz7vTc+uMREPC43P6WqLIGBVsSxkPGb+rOLbUSUlMhbdNax/w5mPVypCp6lpjv452mgZSVSRktkh02f5YAnR0jNhcZ48ZRz2zgLDRauaTaN+rcxgmIPlwF2EfijUpFaEcYqExCSmEuYEmf5bJwoBJf/vrjXLAGeNUlWXUwqjmoQQ8irSwpfQGBzaYDSygGZCrDqO2OFpRo htP5LmVh 0UkSby3mK6rzP+tthbLBQk2ykYM+KABw4st1WH9Pge4e2f4QOFDw+9jSSodYjbM9lIZZH3NdHDipApJ4rzZgZ6QSy3wLtSFcFS4hObqEPC7yM7KXRtIfAbUzS5oD8lLUss/+AaMUvAutMpntfICI1E+zAzzWc98+5TP73GB+4BZrZXvf7UYwyDumZ5b9s6aWfTgX9aZo2uYk1exZcPSaTi6Ar1oYzuNIAcMWwfqvxIwDAJ0vXFyjRENrKeFZN07F19vyfbA0x3wXDyi+aaEP5uMcyJq/x8qquCefchD2wGN+ekp/ohjQIqKgLHppIAGPZ96DQS61AwNYtfxJhByv41+t+dA== 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: Now split_huge_page_to_list_to_order() uses the new backend split code in __folio_split_without_mapping(), the old __split_huge_page() and __split_huge_page_tail() can be removed. Signed-off-by: Zi Yan --- mm/huge_memory.c | 207 ----------------------------------------------- 1 file changed, 207 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4f227d246ac5..f5094b677bb8 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3154,213 +3154,6 @@ static void lru_add_page_tail(struct folio *folio, struct page *tail, } } -static void __split_huge_page_tail(struct folio *folio, int tail, - struct lruvec *lruvec, struct list_head *list, - unsigned int new_order) -{ - struct page *head = &folio->page; - struct page *page_tail = head + tail; - /* - * Careful: new_folio is not a "real" folio before we cleared PageTail. - * Don't pass it around before clear_compound_head(). - */ - struct folio *new_folio = (struct folio *)page_tail; - - VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) != -1, page_tail); - - /* - * Clone page flags before unfreezing refcount. - * - * After successful get_page_unless_zero() might follow flags change, - * for example lock_page() which set PG_waiters. - * - * Note that for mapped sub-pages of an anonymous THP, - * PG_anon_exclusive has been cleared in unmap_folio() and is stored in - * the migration entry instead from where remap_page() will restore it. - * We can still have PG_anon_exclusive set on effectively unmapped and - * unreferenced sub-pages of an anonymous THP: we can simply drop - * PG_anon_exclusive (-> PG_mappedtodisk) for these here. - */ - page_tail->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; - page_tail->flags |= (head->flags & - ((1L << PG_referenced) | - (1L << PG_swapbacked) | - (1L << PG_swapcache) | - (1L << PG_mlocked) | - (1L << PG_uptodate) | - (1L << PG_active) | - (1L << PG_workingset) | - (1L << PG_locked) | - (1L << PG_unevictable) | -#ifdef CONFIG_ARCH_USES_PG_ARCH_2 - (1L << PG_arch_2) | -#endif -#ifdef CONFIG_ARCH_USES_PG_ARCH_3 - (1L << PG_arch_3) | -#endif - (1L << PG_dirty) | - LRU_GEN_MASK | LRU_REFS_MASK)); - - /* ->mapping in first and second tail page is replaced by other uses */ - VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING, - page_tail); - new_folio->mapping = folio->mapping; - new_folio->index = folio->index + tail; - - /* - * page->private should not be set in tail pages. Fix up and warn once - * if private is unexpectedly set. - */ - if (unlikely(page_tail->private)) { - VM_WARN_ON_ONCE_PAGE(true, page_tail); - page_tail->private = 0; - } - if (folio_test_swapcache(folio)) - new_folio->swap.val = folio->swap.val + tail; - - /* Page flags must be visible before we make the page non-compound. */ - smp_wmb(); - - /* - * Clear PageTail before unfreezing page refcount. - * - * After successful get_page_unless_zero() might follow put_page() - * which needs correct compound_head(). - */ - clear_compound_head(page_tail); - if (new_order) { - prep_compound_page(page_tail, new_order); - folio_set_large_rmappable(new_folio); - } - - /* Finally unfreeze refcount. Additional reference from page cache. */ - page_ref_unfreeze(page_tail, - 1 + ((!folio_test_anon(folio) || folio_test_swapcache(folio)) ? - folio_nr_pages(new_folio) : 0)); - - if (folio_test_young(folio)) - folio_set_young(new_folio); - if (folio_test_idle(folio)) - folio_set_idle(new_folio); - - folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); - - /* - * always add to the tail because some iterators expect new - * pages to show after the currently processed elements - e.g. - * migrate_pages - */ - lru_add_page_tail(folio, page_tail, lruvec, list); -} - -static void __split_huge_page(struct page *page, struct list_head *list, - pgoff_t end, unsigned int new_order) -{ - struct folio *folio = page_folio(page); - struct page *head = &folio->page; - struct lruvec *lruvec; - struct address_space *swap_cache = NULL; - unsigned long offset = 0; - int i, nr_dropped = 0; - unsigned int new_nr = 1 << new_order; - int order = folio_order(folio); - unsigned int nr = 1 << order; - - /* complete memcg works before add pages to LRU */ - split_page_memcg(head, order, new_order); - - if (folio_test_anon(folio) && folio_test_swapcache(folio)) { - offset = swap_cache_index(folio->swap); - swap_cache = swap_address_space(folio->swap); - xa_lock(&swap_cache->i_pages); - } - - /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ - lruvec = folio_lruvec_lock(folio); - - ClearPageHasHWPoisoned(head); - - for (i = nr - new_nr; i >= new_nr; i -= new_nr) { - struct folio *tail; - __split_huge_page_tail(folio, i, lruvec, list, new_order); - tail = page_folio(head + i); - /* Some pages can be beyond EOF: drop them from page cache */ - if (tail->index >= end) { - if (shmem_mapping(folio->mapping)) - nr_dropped++; - else if (folio_test_clear_dirty(tail)) - folio_account_cleaned(tail, - inode_to_wb(folio->mapping->host)); - __filemap_remove_folio(tail, NULL); - folio_put(tail); - } else if (!folio_test_anon(folio)) { - __xa_store(&folio->mapping->i_pages, tail->index, - tail, 0); - } else if (swap_cache) { - __xa_store(&swap_cache->i_pages, offset + i, - tail, 0); - } - } - - if (!new_order) - ClearPageCompound(head); - else { - struct folio *new_folio = (struct folio *)head; - - folio_set_order(new_folio, new_order); - } - unlock_page_lruvec(lruvec); - /* Caller disabled irqs, so they are still disabled here */ - - split_page_owner(head, order, new_order); - pgalloc_tag_split(folio, order, new_order); - - /* See comment in __split_huge_page_tail() */ - if (folio_test_anon(folio)) { - /* Additional pin to swap cache */ - if (folio_test_swapcache(folio)) { - folio_ref_add(folio, 1 + new_nr); - xa_unlock(&swap_cache->i_pages); - } else { - folio_ref_inc(folio); - } - } else { - /* Additional pin to page cache */ - folio_ref_add(folio, 1 + new_nr); - xa_unlock(&folio->mapping->i_pages); - } - local_irq_enable(); - - if (nr_dropped) - shmem_uncharge(folio->mapping->host, nr_dropped); - remap_page(folio, nr, PageAnon(head) ? RMP_USE_SHARED_ZEROPAGE : 0); - - /* - * set page to its compound_head when split to non order-0 pages, so - * we can skip unlocking it below, since PG_locked is transferred to - * the compound_head of the page and the caller will unlock it. - */ - if (new_order) - page = compound_head(page); - - for (i = 0; i < nr; i += new_nr) { - struct page *subpage = head + i; - struct folio *new_folio = page_folio(subpage); - if (subpage == page) - continue; - folio_unlock(new_folio); - - /* - * Subpages may be freed if there wasn't any mapping - * like if add_to_swap() is running on a lru page that - * had its mapping zapped. And freeing these pages - * requires taking the lru_lock so we do the put_page - * of the tail pages after the split is complete. - */ - free_page_and_swap_cache(subpage); - } -} - /* Racy check whether the huge page can be split */ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) { From patchwork Fri Nov 1 15:03:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13859516 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 76270E6F069 for ; Fri, 1 Nov 2024 15:05:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D5436B009C; Fri, 1 Nov 2024 11:05:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 085CB6B009D; Fri, 1 Nov 2024 11:05:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E19FF6B009E; Fri, 1 Nov 2024 11:05:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C23246B009C for ; Fri, 1 Nov 2024 11:05:50 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5EFEF14092E for ; Fri, 1 Nov 2024 15:05:50 +0000 (UTC) X-FDA: 82737850062.12.8FCA42C Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2054.outbound.protection.outlook.com [40.107.93.54]) by imf13.hostedemail.com (Postfix) with ESMTP id 38E5C2003E for ; Fri, 1 Nov 2024 15:05:18 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Dz1dhLtT; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.93.54 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730473415; 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=gBVeuolEa+O1KRTMeV6OyPyYPynOukZYFHHM5jLMtFU=; b=TG0a2BOHSZU9wzEvXffsBVkABKotoPwtPJQqZXGlOXG8k6lhKoE6hreh451hLTQcVIGKP6 Hv3sXjioPd9a766pMvNPXOFGW1xRr7LUE4xD12XUhmsJNaE5G85nbMKVociMo9GTTwHnWH Wf3/rt9j2YbqzvPvRcayDd5YuVA4vEw= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730473415; a=rsa-sha256; cv=pass; b=KyArtYPuu4d95Midj8bisZ/ODmpRh9ImXsdz/SXVxpMyDJyRtQAgn9TlZHdkEQVFj9OYOt EmyyNSEmtz54Kryk3hxjOlSDgUtHVpe1pX5KQoCE6WUc1wDKFlI73IWmBXgzV4Udwlg+7W ZSWXxjMv996RX0HgPkrue9L6XU1EE3k= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Dz1dhLtT; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.93.54 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tQnj7ZDygmp8h/mj30v6Qy/0m6tlq8r6v/4BZ8XjbbtAYKiAfGpKajX+wXRRqvnnKse4xdlZGnmyoYgHC9Wb8m2zsKKEqlU5HXq9Uy2E7uyntXpZwq0WLluuW22X55xImD5K6kb8Pr7RcQwq0cyFS8uxTCeaYB4CB5KcjGSwxWoOPpMCIg6cAMBAcbcyfsBGyGrUm2hhkDMQfa691KAUfO1FeuRhxU2526OD1HOmBk6H2oTM6QAXCO4exS6x3EhqunlsBDD2aJ9lo/0/UB4sMFr1/tPA7ab/h8nBA1bBYHwmuuX2Q/KKxtwVSS919Qcz18E93Fel5RlIKY+CJLiwdw== 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=gBVeuolEa+O1KRTMeV6OyPyYPynOukZYFHHM5jLMtFU=; b=StTe88+Mr2y/W0vPEVCmqgleHduGRs66ry10bcatjFC4leLamxrSforYxZlJ97Z7OS/G0picClmlhNHfHimibNI0nEJvJQyPTM0tv9S3GkJPI63Yl3ilpLIebsvbtDjxe9JVS6T2v7OFWyq96bvi+ycz+lkiLqV0CMX+oNFYqadT8zxk54pqjrF1PI8031eMnQKgJnq5BapdT8JgXgvRhPXNl7FkGxgqZOz1tTxsQEePrrtLuboC6t5OhJYoimlMP3KVmrsS82W8m2XUvCGujwRyt1FfH5obw2P+N/Kd04s4W9hhakDiv0Y9zq8dxu7qZTL/iJ+y4qhhx2SQ/Mg/nA== 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=gBVeuolEa+O1KRTMeV6OyPyYPynOukZYFHHM5jLMtFU=; b=Dz1dhLtTXAQTk/dmWI7mA5nFyXAxjI4Q1aouSFwJH4mjE8RjGdzyAPbYEbm91+6yPy7ag3rWpG+U1xegZY8VsKEB8PxXEUixV9IhtGVtDfPsbu/UAfLiIoFI17aMGawHORCURscXNlbW0gIM+j+EIr/Nh5P28f8W39a4827bcdmXJjS/FgjIfkaCghjecGnfs5fTtpa1S7ZNu3dXyemDxz7gadSQOVSUWQ3VSIx/qDz56btcO8VXrJckk6evXaKcPv8yAHBfsqXa42SG9H+eQLIDN6kN3i81Pbe3YlelIGRE/X9Q7xXpAGElMvAoDtXBN+xLYy4d7XH91cOYCeAvGQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CY5PR12MB6621.namprd12.prod.outlook.com (2603:10b6:930:43::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Fri, 1 Nov 2024 15:04:15 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%7]) with mapi id 15.20.8114.015; Fri, 1 Nov 2024 15:04:15 +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 v2 5/6] mm/huge_memory: add folio_split() to debugfs testing interface. Date: Fri, 1 Nov 2024 11:03:56 -0400 Message-ID: <20241101150357.1752726-6-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101150357.1752726-1-ziy@nvidia.com> References: <20241101150357.1752726-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0135.namprd04.prod.outlook.com (2603:10b6:408:ed::20) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CY5PR12MB6621:EE_ X-MS-Office365-Filtering-Correlation-Id: ce708f5e-7615-4d8c-a958-08dcfa86734f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: FoyIBZDO7BdEpcDp0twe0uAbBbGRkp874e0tWn9d93XX+qmURgiB9DNT6W60qduPSGb3lrhR+e8U9Cndr3tvpXwee1csazRWSYLhBQy8IUlAXCDYhbK9ohYOHeLim/m772OQ1GSQ3atN3gAQ/FvfC4SkL/FALoSMJ35fNH1OCgQXafpiPgL/0ZRcWLKrNwx9emfW2NWZ+L0I0cme/sf2mRlyOclHgXLfV2ZYWQ+B/dD8aARNDfL11ckK9WRoEH37UVvZAaQ0YJotK+d1O0jVPblYoXxHaPMcM/RGVv2N+pu7uiZ/0gO8PwzYqOC7PhZg2CNzZ1csfsVHDAH91BUxxizymnJ4f7ththtWEd3cHbs2u0rQ2b5lNI0qjXWCre9a4VoIbuxKtUGnBH/pwh8ksmNCmfITGHz+Y3MkEMFz7s3ALL1oMj5rL2nRnWayqJIwqFiDOzNXzh6JK9ZYG8WPNSKRp1r2mZoJ2hD/9Kl2G6fkPADqFdbpNsi9JqCDIFAaLOxAx/3UTPKBx/jwDooeJPKhns+CrExXXCnswXGnTHwfylYSO17ai5o1us5fRQD2F2qXmlTAWJXjWWQoPS0RL6GCeEgR2QSI7uj013Pb6n9IYHHKaRcW6tEtC5AT83ks/YX+s7gjRp8+Oen7+59U9Glt8744zuDtT527unnbm2KkIosjUgeOklPZrv64v4dhCaK1/VFYhek+8+GWz5MWi5jJ39z9iQLjjiwpaLeFoECWP0A1NwCRyu0rwAIBQYqoPendOJl/0prHS09AB4AslKhsyZA3l1fJ7wlIVi/+Gc9t1SlmEhWfSHAxTkCoBO6/JEAHPgLJKd72v7gPzvYSJnA7elGOBGuat5fMr2tptNDWfoukKA1tOkN6hUo56Gz4yocLFjwqTnDk8UEmZYNIlI+Tt/mwPQhR7Pv54XwC5rXfhWOXgTQx8Bgryg4Cg7LxsALmVUOmcbL7baBldKm18K511W3Rl2IQhU2NIGO8QosM7yncK1vMyeyhvTD1WErIHmak27Yc1GUZMtY1dut5QPMveoJ9N46rWH4idxqe1UjqvCIVNhCp1PAmzaauN5Rl3DUF6yiJ1r9rFMP1Nnpqyg+BIB9IxkLJIOr2svmXIaX5BaIwB3WjoUB0aSAxO4CovYvNPDG4VBURphCY0B/4P+nw0irhAGmsFFrfg/GEqHVCZQXf5JwzM2ShQz1zLNmVoHp8LwAHk6U0q96mtgT9wLiAZKgW1ji/nKkmSqAZfHJxgKpm+lz1nUFNXRKac/bH4RsuKcgNdkewPIqPMDxJWYPze9hRb5x8z6blvmJ4xZs2wjpZCMMZjywj9Oe6Dgc9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e+vAXa4ZygGn6rI7M5GWRwVTi+CpxKcUInyzqpuWNy84isFGxmK1W7JYW3u5mEU46+Nd+JXRglpSyQzQz6ZN9Kgb/pkkwB7EZdRSrBJ2jiDsaWueSwAOuEJFLjLyYNGg/Kb7qMs/6AWxpGMRyIq7tMYxXMLLzPuCwA67zVnLbjfSEVnJtFDrlGj5Q1Oo0NmHeBXgZQOVOtUN/MJ86ww+Ue7VjYXFJEbSsnGHTFgvBw5VOVQfKkLdSMCd0ze2BfDGGQPU2vqKlCg3cR7dDSLa+sU6djvG9lxYVyeRlqw3NP6UOseXCndiv5Q37enkLL1wtMAG4x1Me30kqfq49xONjpOgKZj6LkCHY+alEkA6Yy8cbq3rGQb2sP6TpHHZdmChoF1mr2+UQHxMh5owEHMaxOj3k666BS0AAf3VNkI+0n4Pz8EFM0LRypnOSDY+0w3RIqJojwN34ySww4cl7ZCghK+pXlrvPHARLcfOdwa//5MiCG05+C8dKk39QHFu5grgT+pxE10BZq3ugVbr8v44Qv/wYO6iCuEnD0bEY9WJfvdEqf/gRQExxs/wcNlbFKetFpkx/+FiUpJzsn+zinh7wItJ6P9mYHIwLzHd/Dp8LBo2NU/yyW3OSkr4dD2e+JQE36jemQfpFV4etWrLbkEB/wjlJvvoSsj2MWQzu1w/f8nxtpNrNHSvXH3ilcJb+X9UWv+g17AuAGDVINiJyI6F2c3okRF/2uo3QASZ8Bo2DEZBc+KSyy4MWhJMLL99LqkCbuwZNYlJw8sXHEKb8+7rLcq/I7ycaExIMS/c+Xu45z228rF7rqMFkw9f9eXV4BexwKNCszUdaWcWZ6cSq4+uOOMxi/Y1O+oQ7qXczI5Y4GXHoB8bDyBBSPwBvyLrnqrt8EJNVv+Z8TcC4Bdrueo7XasM4/Wq+uG+DpQ2qYUp3zh/wjpPTs7YhtjcZNBEcUb6/NXVP760hoS/jlChUIby69vl+r0WuzVNJ8Uezul67duCQZvG1d35fVtoCxylES5R+zXjDETC+/Ketn4W692kWq1iPVu8E/4lFM8riZaGsruziw698Iar34Fl4P7KYoLjsbKk2xawR1WOuyCCDfZwq2f5lUW46fp66ezzdn9teH7nwRELccDz4I9LJhQFc7YFMcSuzuqBOBBO2fUy40huSD/Jr6ZYy9Wl2QURjFrpJtZp0aYYhYSQggvIh+Vz9W5VikBXdlsdB088JF5bZLGViAzcY7bRwOtDAw1mqoXOt9hGEmvsuKIEOQsJMdnjjAdBf7s1A498UhIiT1TnxW5mqtjwO8OYT62Ub6FNPw2LhQOW2MpwXlKHFazF35I1Jfm7nPMtJlginA7tEb0Rxs+36T+dbX23bSyH6Wewbyl5AnHC9EevgUKEf+IJLCVJXmPwAzkJ9orntRMUyK3Vv6vfUdmBg2OeT/b2LqwkUqIjP5ks6nixHW6KqdielAihtnaOUzOq+m3kZAHHitquvL8uDiSXGpudH9GG2cJnVCUcOsrnOjwjvJ6z/DluxssHOBlHt/Mc2JbODyATTgZFPB7909nwsjK7SqvUQQQc6wtvqKyXq85lZC/rMwXnyYCTwS3s X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce708f5e-7615-4d8c-a958-08dcfa86734f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 15:04:14.8298 (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: ugqISsVnHsr9ItUxg7u1BX/sPEzvHbo3DjH/+B5fhpjUvLTCTY+C8XkOioM3pCQe X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6621 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 38E5C2003E X-Stat-Signature: dd8qq9gekmaqh816qwbrtx7393d8uyy8 X-HE-Tag: 1730473518-99678 X-HE-Meta: U2FsdGVkX1/EZoJ6URwugP+v1u6b/NgHFADUW0EKTOD9TSxP74Wkpw4ISRWKNYTSse5bAxAMqUmS0zXynyN7bwbVCMAbzpQFth2Cdht089MjAmTtRyp18I8tRe8agQxE7v86L+wqRGKYByUYHnQPjUKWmmybnFD1krftlWbT799aAJ408WjM4oiOAt92IZ94fBDPe5AknJH7zOkufLu3hnfpHUCBCCnJgbxayJtXR91la5OHrfkPb9eXN+m9O9hwBFGGLNH+cSmOrgiZZZoDmbFf5cS86cwXo0lEFaz5w4psAWwRy8S8npFgrE/E9J7KGmPXL8UM+edBM2wfO2uehoR9kEEo4AZeXGU1MF1bCpOeGe1G7UQH5eKv8xMsDBB0QCAUrtE1MNidgL5z5Uhib4ejicADRuUoasaNx7xjm27BZYBuNYQXIeSe3zlgJVAX7LxOjgsFmePo2p6zuG1Lp5i2THsvPsq+/UCmgi8EMA4cXnlwJZuXYyPTRqUhuuXgnmP88s8i84/PNk6hcxecFR20pMSz++gQlM1qkT/xO7dIh1KLZduzVmcGfpopOcUZ1wgun+cbmfdhrBgwbCzq8zJYZil/ltrKhNf/xFcFkrU6qQgv3HXFsYg416djp8KidgwXjbCBXddml9oAH6tWWKzDIXUu+MWMHQBYFe4MGP/asAJ14NIy/cWdir4WX2lS6g8rxY7FTgU/MVo0DjhYlqg0y9yY43qZQv829jKg3HJFTjrYaYR/z7DZwsmRA70y9j3L29cK9BGqBx+hHI0Dw7XbOnOKPeTQBHatE7EEN/Oo3KmCeAJQ1U7UUQz4DFUbnHr2fJj6LtU0e63PQawKRIuwVH1UbOgeMQazRCWgMNdg471Z85/FF/Fmwx9m3yLO4bEMD9/+6pgF/20Dr4fvsKAmx0d9kowmOm0ce/C8CVaXxn21rF70WrVqvy5oP1wuKsg2bfj9zK4e9qRqrnp B0hYSLeu QRV5+e7lo4mXL9MtnT/EaN3/pLu/qX1mNmnOMMssHdQCLMTNreXWSFv9fS6VnsbpvsEexJ5uuuUlXq8yhxz1ptsXU56s9+sk6ciAX5z8juHGlJW3V5UR96thjjvefb8El0K8ZCkqCKH2+QGGD4W7az9ah8sLdYytL7S/lsy64HRgybO9ym0uqO7/bqZs9eSXs5KnBVoED0WJ/U4HGNr/4KxN8yK6seTcyANNwGzOOvv2FLl9wPk0pXk/nhrBnRHRmeyez7kU7Xjoce8Cd5jjmIcGrEVPzw4ZAlXB3Q7ul/bhl8mRtRs9ollJdEsTJyQTeh2FmFzATxrSFHyiGRqYeLonVYw== 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 allows to test folio_split() by specifying an additional in folio page offset parameter to split_huge_page debugfs interface. Signed-off-by: Zi Yan --- mm/huge_memory.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f5094b677bb8..1a2619324736 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4114,7 +4114,8 @@ static inline bool vma_not_suitable_for_thp_split(struct vm_area_struct *vma) } static int split_huge_pages_pid(int pid, unsigned long vaddr_start, - unsigned long vaddr_end, unsigned int new_order) + unsigned long vaddr_end, unsigned int new_order, + long in_folio_offset) { int ret = 0; struct task_struct *task; @@ -4198,8 +4199,16 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, if (!folio_test_anon(folio) && folio->mapping != mapping) goto unlock; - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || + in_folio_offset >= folio_nr_pages(folio)) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at = folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } unlock: @@ -4222,7 +4231,8 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, } static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, - pgoff_t off_end, unsigned int new_order) + pgoff_t off_end, unsigned int new_order, + long in_folio_offset) { struct filename *file; struct file *candidate; @@ -4271,8 +4281,15 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, if (folio->mapping != mapping) goto unlock; - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || in_folio_offset >= nr_pages) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at = folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } unlock: folio_unlock(folio); @@ -4305,6 +4322,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, int pid; unsigned long vaddr_start, vaddr_end; unsigned int new_order = 0; + long in_folio_offset = -1; ret = mutex_lock_interruptible(&split_debug_mutex); if (ret) @@ -4333,29 +4351,33 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, goto out; } - ret = sscanf(buf, "0x%lx,0x%lx,%d", &off_start, &off_end, &new_order); - if (ret != 2 && ret != 3) { + ret = sscanf(buf, "0x%lx,0x%lx,%d,%ld", &off_start, &off_end, + &new_order, &in_folio_offset); + if (ret != 2 && ret != 3 && ret != 4) { ret = -EINVAL; goto out; } - ret = split_huge_pages_in_file(file_path, off_start, off_end, new_order); + ret = split_huge_pages_in_file(file_path, off_start, off_end, + new_order, in_folio_offset); if (!ret) ret = input_len; goto out; } - ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d", &pid, &vaddr_start, &vaddr_end, &new_order); + ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d,%ld", &pid, &vaddr_start, + &vaddr_end, &new_order, &in_folio_offset); if (ret == 1 && pid == 1) { split_huge_pages_all(); ret = strlen(input_buf); goto out; - } else if (ret != 3 && ret != 4) { + } else if (ret != 3 && ret != 4 && ret != 5) { ret = -EINVAL; goto out; } - ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order); + ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order, + in_folio_offset); if (!ret) ret = strlen(input_buf); out: From patchwork Fri Nov 1 15:03:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13859514 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 BA0B7E6F069 for ; Fri, 1 Nov 2024 15:04:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A62B6B0098; Fri, 1 Nov 2024 11:04:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 455346B0099; Fri, 1 Nov 2024 11:04:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A77F6B009A; Fri, 1 Nov 2024 11:04:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 060E06B0098 for ; Fri, 1 Nov 2024 11:04:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7CBC71A06C1 for ; Fri, 1 Nov 2024 15:04:35 +0000 (UTC) X-FDA: 82737847164.04.79B57BF Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2078.outbound.protection.outlook.com [40.107.220.78]) by imf09.hostedemail.com (Postfix) with ESMTP id BB13E140029 for ; Fri, 1 Nov 2024 15:04:12 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=oFJuAa+K; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.78 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730473309; a=rsa-sha256; cv=pass; b=56csqhpm0HdqLYELPznNhWssdIM3lu52BfcR4h1jlDUmVnhTAU+si2xN0Y/hw/gtNIRQZx nDM02unv2/iY2zqBFdX3Qsn/mL1ObUdQgEywsQNEv55Fi2unbQp8Y+cuGZSL3YGvXCxq6r 0SpZbt3p/Vf/mOjH8aWWOePIvAZqiwY= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=oFJuAa+K; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of ziy@nvidia.com designates 40.107.220.78 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=1730473309; 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=lI+AH28x7kVbKn6FgZA82KmuNv3qy1tf+VlP9HU+4jY=; b=OuYhtXztn43NrxPBYLYZD1u6fXh+kUUvIWkDf2Naq23ub2s4l8WXDG2J6DFNx/9/Vi7cJf X1SbmB++wyQDI/GzPichU0sXFQR+BNxsvoeJipwxigWwVsCLsSWe5FQs0DUKoH7IUC8dXq rOjKkxEaAe2cbj559eQrwYY1MGGL+1Y= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jjUBhVB4kJdF27GMJG0+tDiN1sMLXJraRLU5N5J/8NBuchCYwlMv27ctu1YhQ3udxO220zOkHdGQ5bhPRdqlnrceZqR3eo6JRCz5VppNI3c6RAnL2GfXVTMZakr7RDaY3NXb8X84IoAcV0FpVnhpMAgrxhaEGD8USDm8yNEFRWTSpz8jx1PzUV/rD6H9z8OZz6XOz7NiHQuR/9+y2ePgp9wxPmjoJaomL9+IIi6gY6ZzzvigoP0yntOq49MfeC501LoJmSct34z4P0hNaNwOkelaVudj+ITQgetZjyBOHQL65qn9x5bX/Mv2LYmWJYvqy6jVZdud4gEGPB0oZDc5tQ== 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=lI+AH28x7kVbKn6FgZA82KmuNv3qy1tf+VlP9HU+4jY=; b=rQA7kRukg0BB7HhdXxeT1jJSvloOCvW2MIEii1pw+Rh1wNPbLuQw5FhMW2inop2m3Fpw55IV2s1UAIYwtGlKCToK6tYBMDynN8FcWXThLvBy78Th1ux6WrKsHfbH3uQfH/I/T/4QjMhvYic3tKGfVMySqZPD0J/FWYwSU1ngbyOB4OiadS1J+oZDs3iw3TRzHI2+eQbDENsMeeDV5TXj/V0Li1J6V7dhTA9Hwgx3yuJno/bh/vsUTz+Js71NdsMaKBXT+2ykjRt55gGl6WTJKXT4M1zwvJ8XimWmdteK+KL8kVf0gNVDgRCrL9iTxyjnoIDUWRNFkcIzvG8yIsysFw== 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=lI+AH28x7kVbKn6FgZA82KmuNv3qy1tf+VlP9HU+4jY=; b=oFJuAa+KNelwsqXgZ2POTq0xuAs+q6SOqKPX8ZX63jBts5BOq1hl8gxl+w5v7nn5a9hs1o3EPtvs5TEeCsOMe4HeSB8oFNKC9zdNf+X6brZM48B1j+3FIGyRcXBbwm959vTREOnc6CurtrvVo8kZkhkHtrw4sz8fTMFg+la8qvkep6IcXazlZztiY/RkOksq7qvqmKho3B3kWJiZ9bygoputHr32jzTSGcQbE/Xz76gSx6dt43pnURAMom+peaZObk861ta+p40Ke/Ts2D+xhV2YknB878B8Qky9OGovY83bbVzUBm7bLQ7tgOwbDesJkx6vruB/CgfGJld+S6HvrQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by CH3PR12MB9453.namprd12.prod.outlook.com (2603:10b6:610:1c9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.18; Fri, 1 Nov 2024 15:04:16 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%7]) with mapi id 15.20.8114.015; Fri, 1 Nov 2024 15:04:16 +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 v2 6/6] mm/truncate: use folio_split() for truncate operation. Date: Fri, 1 Nov 2024 11:03:57 -0400 Message-ID: <20241101150357.1752726-7-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241101150357.1752726-1-ziy@nvidia.com> References: <20241101150357.1752726-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0130.namprd04.prod.outlook.com (2603:10b6:408:ed::15) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|CH3PR12MB9453:EE_ X-MS-Office365-Filtering-Correlation-Id: 7cd5493d-1c37-43c5-c054-08dcfa867438 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: E7+tN4QhvbR50Mn6ojl/YYLw4YEa1wxSEem39qSRpT2cOjQKYhtCM1wqbSCI6+shx1MyNs/SfKRX+gdnu2ZxQpItHOLPtsDCxkLO1SFPDEAH7zJIRqONDjViyTJktxnCinViSTZgkJX9ZnyvpWF6phV9XkWd8TbKfK8s0SFyplly8iARO8KDuXL3gwl4aGs9EYNeiUVdWrORX3kSNoGtXBz3LkAOOctQRWsizqp7r/PHZd50h5uE9hDenMg/YCcdnZtrqZJa+OJ4rMJ/2NKu/MlexR/NpuqWQBk+9nb+kxYYSkEns6rZ91I61KPA2qmJVipxWtT2fMtW/k/lIY9MAk/RAZ7+RjTDzfhsj3VbpXghAEFInm8aj9llzATrQiAnUbOMDDbrLno1V6nEEk9B3w3XselfVIrwO6LFWn4M0nnfA+aKvmXktQGNrQNMiUcV/izFdRUvkkhEaUmhy2tD+ZYs6b3KS+JpM2rV1nvO5hCUmFKn90LtNiD2MRJUYR3F7LC6TWG9jBuF7LULLkKkExtwn6xIkl5iNu4vfzGeMkz+lm7c4x5r+SdFcbEhBpxD2GmDJSUG7txZs6ljeYaKpUnCL+SJoPwtPqwx9TlCTjM5P5TIXzg9tQvFY9p5uw5oxjJWo2JtsBdId6IosYPDE2snLNwbunbY09J0bdimXVn930Z+puq0MQyhpuPenbOEmf0pwEh+G4VcB6K+lTIw1KFyxLFM2zwBuyteueTkF+/rYiRSbyeoDf9h6DsYkk+4pnZFyfvFEXf40hzhvgq4hWFGcxSX/Cc6jAwAew16DHOhPPVa1indkaqyYr2JBSdgutMwWkO2rSmb1yKEdahfKBjK6tDcYOW/nuv8yGtFYOHoYqjRG6jVUetD9jkGLFGL1vIyk8TzMM/UOP2vICh6vNP73EJaoajLKn3+X5rWN8Gd4ZKy8a5Oq7RmnwitXUfX2kOeMWCVF2crm3suOPuXbC4VZMLPEaQZK0bMJiQ/l/BYe5b8w2CRfjqZHeMYkxTsIi5tyfuczIGcI+OXqktjQdDUnpz5/ngfYygzvr7N3Kv0pklJMl6Hys6Oajm81feF323sbTDBhk27puKrCpPC9a4N3ajnHtIdGOyiHi9qBzDjhpflCBYHZw/ZuPgMFlpK3oBGzE2WVrkkZfzTwcuiJHaE023lYcgFwzInjBE9jzfXzof9OOrpPyupI7ErUayD+Nh66UXOWRB78KpeOOD8mXM/DvkKN+8SRLZxmdd+YhmexRwQWfoQWj8LOHANlohXI9ePArTQXcap1e/RZGU8vOk5+zp9USlfIktEl8d3/mjnnB1n3ZftkhyLiE+D9xnV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bm70WWlL0Zgu9Y8GJvMkTLecZhz8T+Cnc/o7YJuonvewZGHmSN4QmKrO/0KGOFWcmQZCPSIP9K/19xPrQVh2HZt5mSrIeokIL8YAuenM1K9hDBLgPl4E0m54kAHHtirTRWltECQ+tE5rLuWhYPMu1EmaDfKSnHcOkg23JYSDj/zOTGEqs4oifK/Ejx2Gntbt7kuJ/DImCSMmVz4SOM+bFyIOvgTfgDMCf4nS0tg7AXmltC7gC4WqzusQF4txrj+adTgA9qQ3gsmGbib+NBi5SEqU5qTHZBIiZWui04sG70uRBanjpsg4W89ldl5/Gp0E7VCGzCfbJjTj6jfvNGJIqr5Ao8iOZzjMpCJk/JefL9DxpNv2VSdtldjEjuKUQBDB6V9hYuxhXV3GMtCvJl8m0PHNs6U4kisZHUH3uybA26ReDhaiZCCE0PCKsaGFLu6aXVj5eg1l8O2Oc08uvbutCoZC0cLkoEsklcS51nvWquAfQbiqMLFsTnqx5MPfn4rSAeCVqrx4uq2IMlXuu7HVPZDOti/A/TPcNYAH4EYqqIUFp1YksjAMPd8krBSjPO/IWrtd8QTe97/RSK2XGw+2oBKLzE/EKvAgmJcmTDeFqu8bpLvCY18j6oUkFK5LMuEvW9mPtdzfveq7uQ2wL4AWzEHS/oQcl9FL8nHSKlaeInSorNz9xeCKlVexNtx1W+xfrpW7A+XGonNg8kVKhPYeGjdl0lgYBWtMdzDPcQRoNlEIu+8mj4l+mYvkX4GNfxbNKj32V4Gunzwo0vy+pGVBEWKHZ0Nem4fcftRUxyKnmunZpPxmaA17zyi+Bv05AeFeLALtDOdL66gO/ai3Fl85SQ2gmdzi5grV17sw0eHVABjChzJs8LErnsO7dRlgML2vjpaAnRijoCTo6T2CTcxXBBMZbOppiBig4wTXw5NCt1LFkNZ/zjyjp454emPCpLbCJCgaIFOmCc1K1oHIduZ+8eJJVvPW6An1at2AiVYxfG8znwbk2B7r53SegJVDHlHaj9rCmmTmY74TM4THVkTKxJkzd8P/JyAf0hWYQAvn5Rnl81OQXMEZZOB7VfGMAyM1wllw6mCxa4H/hifCQ3A8xfkwmFndcD+3uS3WOd91+lu5yyyCIsm9cPR0iNIodboaBD5jKVdDPwsflfKM4huOJ9RTtjPN6M47Ict5gslsX+/TuA1K2Ef+NEkQvmYLdSpfcYD2QSHLnTZJ12j/oI3/rRNALwt7h+p7Qm7mPNGUqkgieyzqiv0iaAaaRPKxr85B/KmEBMxu0x4+p2pGIGz3YIi+HlDAi2SRqrN9u5RIsUTCC8IXHYiN5OKW6OJFdR5vL/AermKI8LX4p3CEd/hg4RuBv6JDoz4nbrhYzon68+FLxXZebjsINOYkwmNHj0I/czd4/jrUG7g0GCCkdU0Ikkub7WS9ihaqrlLcdkbVlCbHU8t6hJVgjHKC6xN2PhBBnqt7nARHlnfyFqSh5AiQPWzTcw6RWI/tIWYJ6002GAWPHsAoXthCob+MXm+qIJC1+WlZhxEpPFDIwIP1sN1XDYb8Qe8dHIGt+x9vfppp+k+t0bym8cbp4xCuwh7kpnHw X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7cd5493d-1c37-43c5-c054-08dcfa867438 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 15:04:16.3650 (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: OljR/ToYuKDg40rgbQSGjP8Y2qY204OfODaQ+qkAJkU27A9HCVIn0V8hrVHqWyAK X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9453 X-Stat-Signature: b7tgqw6n7kwb8dnx5crbf7rantrrz6jd X-Rspamd-Queue-Id: BB13E140029 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1730473452-644297 X-HE-Meta: U2FsdGVkX1+vYgyg2yj4jBecTLe8Vl0sJ/LnTxKaO+ZDFEzhjpnyCtNlM40OIW5I36ts7AhOXxTCmYdp/09T0jJ3RHsYRjtw77Rca7WognQinRKcMzOAKBeONYi4NnmTcLP31hqa9pfhzyGSpEEN2W1QkaynfQlV9aP1OvvNOSrk5wlpyplrwhV5XsiIdFHsT14IVf8oivZwHoQdTopIXPwnUnhelETHHKlm3DQNemDYGwuaGW7uSQxAcp+B0FYSKZjT9UbMtbfw0UdLLXY9MXC3lBBjgX82ACVHTT/yry0kfpavB8YBkJJkSkw4xIqtUyniVcvMveApMBRi40geYEc6Db0ELAW1PLwAAfmu4eBHBOn7PPRlPPyf5q6Pt+Wvqbri00Ift5Vo5nnJwxKDW53W9+SZWxU7g0kfYa14pMByjpQjEmoa5PpD0TZGDIIQGibACvrVglazoPqSQoWDJDCNcoX4FhaA1Qh3iCW2RtYgg64hHrBQNuNS3AIDpHNfiEHPGOPLZ1zGSNTP8zUhknHnF+qWs3RhODW/YqT+U2iawIua12SWodlXre2heRMjqVn0WAWEDkDWCzZoMdmD3WAql1/GUJnwMjNykvW/emLx4G3kxxtFH2plBmm/UaXdIvgwyb30yXRCnQxZUZaVCPBh2a7sY6LlGCmZMaVqvtwmY+jTLB3c0FIHh22xlLTWiHhMu092Hh1GabkwDD/kQQdSr05cMuYO7n4hP2LHIaLJzA14vc49MZeXgEXU9INIQ/LlP+xkrRGnQeRcdmT6M7InGeI8l/smjtgtv9fJagfXMQcReT48YG4sNOxTaDEjt+1Eqs1yimmQCZbEgWJF/IuLEHt4ZmDq/0F3mxghRAJhO8pv9H3JzjYkszUY8RsgbLFCmKGfjF3wjQRHvBVLCsPWyOuF2vvOyzKv3v3D1t13nuXQXXGzZSfi7cx0nqZZaOwnlgtixuh5gndjq1R 5xv1b2Zr i4nF7C/dNmcfYMMMXBa3lJop6haOPzPW8tCbnj49OWD8RgY08Inaohg7oiF+vXyHSzljrRb2TPw+DVr7dmsJNtx+ue47rwzyDvoL77C71JoxDcONrp+mA6eOXYr0QGkF1Hw9CRPcCRs0nWee4UagAci4PMyEZrZtY60zh98jerYrj86HiTZLUQth74o2HgdU2XViEg1MKp47Wo1MGFbHCSuIrM0Hzs4jGXxaOaZyDvJhWD+m0AsVMagZ2emeal/YfRXawgy6Y74pmsv+0Xb70Qk5dD9EDIQUBIvFSabi0ruVlIIxGPfItqHW9MMKHQowK9xSIsYBVPg1FD+A9qTPGVGCd3w== 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: Instead of splitting the large folio uniformly during truncation, use buddy allocator like split at the start of truncation range to minimize the number of resulting folios. For example, to truncate a order-4 folio [0, 1, 2, 3, 4, 5, ..., 15] between [3, 10] (inclusive), folio_split() splits the folio to [0,1], [2], [3], [4..7], [8..15] and [3], [4..7] can be dropped and [8..15] is kept with zeros in [8..10]. It is possible to further do a folio_split() at 10, so more resulting folios can be dropped. But it is left as future possible optimization if needed. Another possible optimization is to make folio_split() to split a folio based on a given range, like [3..10] above. But that complicates folio_split(), so it will investigated when necessary. Signed-off-by: Zi Yan --- include/linux/huge_mm.h | 12 ++++++++++++ mm/truncate.c | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index b94c2e8ee918..8048500e7bc2 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -339,6 +339,18 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, unsigned int new_order); int min_order_for_split(struct folio *folio); int split_folio_to_list(struct folio *folio, struct list_head *list); +int folio_split(struct folio *folio, unsigned int new_order, struct page *page, + struct list_head *list); +static inline int split_folio_at(struct folio *folio, struct page *page, + struct list_head *list) +{ + int ret = min_order_for_split(folio); + + if (ret < 0) + return ret; + + return folio_split(folio, ret, page, list); +} static inline int split_huge_page(struct page *page) { struct folio *folio = page_folio(page); diff --git a/mm/truncate.c b/mm/truncate.c index e5151703ba04..dbd81c21b460 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -179,6 +179,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) { loff_t pos = folio_pos(folio); unsigned int offset, length; + long in_folio_offset; if (pos < start) offset = start - pos; @@ -208,7 +209,9 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) folio_invalidate(folio, offset, length); if (!folio_test_large(folio)) return true; - if (split_folio(folio) == 0) + + in_folio_offset = PAGE_ALIGN_DOWN(offset) / PAGE_SIZE; + if (split_folio_at(folio, folio_page(folio, in_folio_offset), NULL) == 0) return true; if (folio_test_dirty(folio)) return false;