From patchwork Thu Jan 16 21:10:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942311 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 0EED2C02183 for ; Thu, 16 Jan 2025 21:11:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 813A7280007; Thu, 16 Jan 2025 16:11:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C395280001; Thu, 16 Jan 2025 16:11:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63D10280007; Thu, 16 Jan 2025 16:11:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3F79B280001 for ; Thu, 16 Jan 2025 16:11:51 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E8A7DC1252 for ; Thu, 16 Jan 2025 21:11:50 +0000 (UTC) X-FDA: 83014561980.18.9A02C9A Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) by imf04.hostedemail.com (Postfix) with ESMTP id 1EE6F40007 for ; Thu, 16 Jan 2025 21:11:47 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=kIV2QDRI; spf=pass (imf04.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.69 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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=1737061908; 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=ajaS7n+WGXRJAvfkeoaZ8Tj/oSeMGu2/SX0yKVpH5HU=; b=TGazACoo9fJYwPC4a6Ym57qSD8JO6Wo1zEjlHQ66VQYnTNwFPvvcjLqvZ1bWnStIkI+Bm1 1ghCAuH56f0ZyLYidUSeB9YoR+WygT6yFWw9WAXvbbG/JeeLzURUbI5hBu8GSyJJ6S2ExH HGh7L7Jq0wA0dFk3Bzj9ictLA2VFIaY= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737061908; a=rsa-sha256; cv=pass; b=Ro9JT4nfo4yk7uOzhKxu66P0JpACtjU+T8cxZKrtmXR/wq0+/LoODUQGjY4nLLRAd1JIMh 5HNeuewfAMnCCx98DmEggHqfpPXl4lzFet4vHxd0F5PxfMc33OeIpKnwivD9fO4GMdcl53 rptqJKCAUBeep9EaXlMsy/h0OwjpLZg= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=kIV2QDRI; spf=pass (imf04.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.69 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bja2NtGRmqmEKLFsECucxH04TW5i0OwOv+S9K0nAU5SPrfRkmjTdvOuqaZalkI22FHUMuYCPi9aY26HBiloGqSAtJJbpNisF1JrOj8ehBcJZgv3hsr/+snSNYoyVwSeyVsaOP54Xh9yhDFtM7OWLjjAagTjX7EfXTgCOXInFYJCTqvFnFI6iG7tGSYdnA/1SlmAUPJ9dChFjm6wPxeEYrLzkbJjaVUTeloWhNNv3q06DCkmkFI7ORb8TwuWh+w1RpoTxR/Dxa2BETl8FTLUckm1KKA7JXY1SS+pz9Q39FuARyvNER0fw7UvXQNd9DnxCSezCXXHtSXTg031AZHp1Jg== 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=ajaS7n+WGXRJAvfkeoaZ8Tj/oSeMGu2/SX0yKVpH5HU=; b=rUP1TcdOjP+IweaPbjuLGfsFgVzCUlq/1nMKtsdXdVZkEzmEVv0HTsAcrwvnOoZu/VrhFkFfHhp1FEepf1WFSsh4NJcjmlqpoelSPZT1oW2uAVvVH5BvF462HZNynuQlbxToS/qpEs8XoPuG9eolGwDI12ujuHluBco/RO+P63Oo/HpE2aY40uY5pzsCDEeGWatAMdPB+VQjxsU2BjNmqCN85GIkFr/raAnGtjtNfpCIzaj2l5G05kUBM565alJdLst48iFo1eNEZ0ojG3woNGXGXpbkAXUy7SGIW0aHGINSVEaaYqXCYFkjszhAn2mhyTaP3aTRAA9bChgUoUI04A== 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=ajaS7n+WGXRJAvfkeoaZ8Tj/oSeMGu2/SX0yKVpH5HU=; b=kIV2QDRIUb/ArRiobVUMJjqpmEA2LY0lptmasyaF4JhHSi4ZiI6lT8BlS4xjdxmBdnZzF11xOgbOr84ZKdimAS9+Wxzkuo7p7ZeKGF2LRff6DAWQ+kgZM36OB1GofiXhmYMxR1paSJ0O5LQzbRLxsLHH+PUP3L9fFbmMo9CFaK9KT8o2HdeNliGDb7bIx2Pp2OPLH4eMI//OLsCntYDOOZTaLGOc+Y6baCqOrcskV3jZ0m73Oe4ayx2FXb1kuez0DwCPnNm6qYVFjq3TX3gsvYubN2FxTpPr9lnkbBRxgkG33/ZjwvuRlfqKzhnCNRoyeQhcRZ5e0cDtZUsOsMOx9A== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:10:53 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:10:53 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 01/10] selftests/mm: make file-backed THP split work by setting force option Date: Thu, 16 Jan 2025 16:10:33 -0500 Message-ID: <20250116211042.741543-2-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: MN0PR05CA0030.namprd05.prod.outlook.com (2603:10b6:208:52c::27) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: e2f4f078-c1c7-41cc-3187-08dd367242a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: ZLq7XbLqEM5gwUs2GyGEdZTP3/u7/XK2a5IDAMTC6G84U8Qb3yJlLCrgWAdXAWO6RJ/aEDwWP1mz1G4Iyas6ERcTak6eM5RfEVVlQGt/HakdW9ncYnpcTQhU36O5yx1yVBe6Ii/EaqeqNbLZDWbJPg699a9c3Go3J+evUZVLCePihT/Z1zQgziRfXKVM6Q5lGwlw2zVfM49JWHy9jj7Nri8qU6xhw4W7e/UMD4dMZ6qpth8ALtobVeil7txLMv/B1npZEBWINzPocd6lk8kHHmkolBt2SRJT50lp38seywV3WFwSysUF5zH7ZSxBgpmal/wVuxcYhJjnv8afTPWjcbg3hKrEhUt2R+jefMzC8+CpV7EBB+Ac0i2EwmtE4qrhMlYYzOGQTOl4mUTy9d7MD/Q1ya7xECS/pFtnJyG3ky6OtRbXL0vVxDTnxnJDrFZzM98WSUN40bynbgpjPOqF2zWZi1V0SmD8CEDYUiT2Xu2tXzXcZrAAHdJ/cEVqlmElLqvG/WUyt3CeauwEXzWhzzQRNQwDE9voRPxEDKES1zq+SJc/W02caQALO3D7v8OCnWWygq4hoJrkk0CoFaPPZVOkJzOCoPPEj4B/Q8vH4iJq/xUpUe/9upsx9i075Vj0SqN5iYtZmeGyRy1psALh2mkngApBjy/CAQ6RHmB0c1RIhqydONoTyoIS+8CqHa6RHqtP7QcDT+Zv8LqxtdmzpjOR6otq41RtLDaUMDwf3iTKCg3+qRuhJJmK0XihxqRtfaSIEm3jMPf2YB1A62KXsvIB/AuUgQWBFTEa4VWyZYwg/J3+DpJ48WCTrhnLweeabOyAq3xlL2RASLVZdoUiqsw+FJlOD40zdcED+E3qzBKLgwEyqY3w1LjVs4eKFdFfwf3P5GqqoJfpif9VjBgE1+K1phPFaW97219dbFk9IFLx76yzAH0kvKaJ4gWNNoBIKOqQUggvLqncfG53DN6piyOFmyyESDWVbGGWUBOeR5kZcD0GucV3jTQER8SdGMuDSFXxANWzwMreWm38vSEABf8SsQPW2/6vpYNB9/V9m1+1WpKko2s0RCLfGUgUXnC3sHa6MBBtQabJIEa4R/i66jj9W/ZsQzgkfMcH/dcFytxF1hSELsbQg5+TgGY2BDhEq/slx802jtXwK5pJ0gkB2OSeoSx5kDCOF7pE3F0YkpGE6BjPhQxw+mGq3Ntf2gAcvMfxajxxu0pA0hf4zIAVOxqeERiEQVwNtGZ5yEzEImFQgJPjsObTkc4NZkqkqJMtZjHBJoTn1m2VHezC0PHIDjQjN8VFmR62e/8yzwXNjVeG9YvrkzsL3InVjFKFOUOm45blTWkUajJOxb5g7jyI+hZ6gOIVUgjKREcyzFKS0klbng0nxGfDlF6svZhG9uUn 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GsRxZI65YgwyT5BXyVJO0ePq7zfdchmV+N7P/QnaDaXms3jb4LdPOfbUk67mhdO9YQoqZpKadRHLbxgVNydU3qnrHsIu0fgYIVlW+zoWa5SoxH5oTtGbtwsTcXtU8K915rZR1RrR7VHGsRYTRCYzok87S01KK4ccpfkiBjVyMrvWgRp0dkj2Z8MBr/TLmCEL0MQjQNTYAi7K6Efyj8sri1ANA1IXSY4ED7anlnCeGPCfcNi7Xycb1/X5uC877fJp76/xWcIAfYwCqJaQv4FZwoaRt977hCirnpHoyGAl+/kgN5v/gE6KfkD8rUPV+hLDS7j1fLr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M49c869gpKmNzMCqfI3hejPDZDxwYQXQ6otDzNEpt+/RiwNJSJQ5PckphoGnwhqbU7Sj2K1oad7N2HOz0ex3XB19zWVqmbjSFFNv0JdYWzUP3RcwcD+n6Znuk5kYd5Ko+CRa6k0++LO52p5q+r4jc/PLpN7qQRB9ZGWsy92DR4rZr8Gprx80/PZsRn1AwjA6ZRftzDnupuLTY6aY1SRU X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2f4f078-c1c7-41cc-3187-08dd367242a0 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:10:52.9414 (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: K1Rqm+UaP25xAkZiyWD7h5yiGVhfWla55v4hLF4nueoEG7WDe+lWWvjg5puIpoOZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Stat-Signature: foma1jjss1u3czxtk5y5ougscib7yxd7 X-Rspam-User: X-Rspamd-Queue-Id: 1EE6F40007 X-Rspamd-Server: rspam03 X-HE-Tag: 1737061907-408954 X-HE-Meta: U2FsdGVkX19xrMMYSE8aAKkUrgWRmMg3NWo40oREiwyclp9K4VQ8w6uASh+uPsx5/cgvhQg0jKgv2olIvACd9wq0E/PCDqJh8JF8m/siTxxGAgmqTp3RdjgKjJHUZk99zAL+Hjvnxa/etfh4UkFzn4t6d3MnAG+JzMnTq1bm0CgG66yTDidqJ4mza+UNJQLN3nKB/qZhmfuf1lDxwE5JJz3xgs7uQBDlZixiHZoEM0VphvDfbBrkxGHjPBaClu2Z0V3ACvI714pA1G4/0PkiCnmfch/lu/z/wPaZ4VY2a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, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Commit acd7ccb284b8 ("mm: shmem: add large folio support for tmpfs") changes huge=always to allocate THP/mTHP based on write size and split_huge_page_test does not write PMD size data, so file-back THP is not created during the test. Set /sys/kernel/mm/transparent_hugepage/shmem_enabled to "force" to force THP allocation. Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 47 +++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 3f353f3d070f..eccaa347140b 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -264,15 +264,46 @@ void split_pte_mapped_thp(void) void split_file_backed_thp(void) { int status; - int fd; - ssize_t num_written; + int fd, shmem_sysctl_fd; + ssize_t num_written, num_read; char tmpfs_template[] = "/tmp/thp_split_XXXXXX"; const char *tmpfs_loc = mkdtemp(tmpfs_template); - char testfile[INPUT_MAX]; + char testfile[INPUT_MAX], sysctl_buf[INPUT_MAX] = {0}; uint64_t pgoff_start = 0, pgoff_end = 1024; + const char *shmem_sysctl = "/sys/kernel/mm/transparent_hugepage/shmem_enabled"; + char *opt1, *opt2; ksft_print_msg("Please enable pr_debug in split_huge_pages_in_file() for more info.\n"); + shmem_sysctl_fd = open(shmem_sysctl, O_RDWR); + if (shmem_sysctl_fd == -1) { + ksft_perror("cannot open shmem sysctl"); + goto out; + } + + num_read = read(shmem_sysctl_fd, sysctl_buf, INPUT_MAX); + if (num_read < 1) { + ksft_perror("Failed to read shmem sysctl"); + goto out; + } + + opt1 = strchr(sysctl_buf, '['); + opt2 = strchr(sysctl_buf, ']'); + if (!opt1 || !opt2) { + ksft_perror("cannot read shmem sysctl config"); + goto out; + } + + /* get existing shmem sysctl config into sysctl_buf */ + strncpy(sysctl_buf, opt1 + 1, opt2 - opt1 - 1); + memset(sysctl_buf + (opt2 - opt1 - 1), 0, INPUT_MAX); + + num_written = write(shmem_sysctl_fd, "force", sizeof("force")); + if (num_written < 1) { + ksft_perror("Fail to write force to shmem sysctl"); + goto out; + } + status = mount("tmpfs", tmpfs_loc, "tmpfs", 0, "huge=always,size=4m"); if (status) @@ -317,13 +348,21 @@ void split_file_backed_thp(void) if (status) ksft_exit_fail_msg("cannot remove tmp dir: %s\n", strerror(errno)); + num_written = write(shmem_sysctl_fd, sysctl_buf, strlen(sysctl_buf) + 1); + if (num_written < 1) + ksft_perror("Fail to restore shmem sysctl"); + ksft_print_msg("Please check dmesg for more information\n"); - ksft_test_result_pass("File-backed THP split test done\n"); + ksft_test_result_pass("File-backed THP split to order %d test done\n", order); return; cleanup: + num_written = write(shmem_sysctl_fd, sysctl_buf, strlen(sysctl_buf) + 1); + if (num_written < 1) + ksft_perror("Fail to restore shmem sysctl"); umount(tmpfs_loc); rmdir(tmpfs_loc); +out: ksft_exit_fail_msg("Error occurred\n"); } From patchwork Thu Jan 16 21:10:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942305 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 51A08C02188 for ; Thu, 16 Jan 2025 21:11:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E7DB6B0085; Thu, 16 Jan 2025 16:11:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 997AF6B0088; Thu, 16 Jan 2025 16:11:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 838C66B0089; Thu, 16 Jan 2025 16:11:07 -0500 (EST) 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 653E46B0085 for ; Thu, 16 Jan 2025 16:11:07 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C4D30C1217 for ; Thu, 16 Jan 2025 21:11:06 +0000 (UTC) X-FDA: 83014560132.14.85882E9 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2046.outbound.protection.outlook.com [40.107.244.46]) by imf30.hostedemail.com (Postfix) with ESMTP id D411E8000E for ; Thu, 16 Jan 2025 21:11:03 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mnyfl1v0; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.46 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=1737061864; 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=3071ObV6LLc9U2n4A4HNDAeWGiw4e+9oj47G1aIi6QM=; b=Iapu9SYcHDPO5YY8H8pZQBk6qB11pU28/cA+nZ9BmnyIjtOS3yvlqoXXJESiI2o3dvcnrP 5kn9tTaAI0hX6yksQhFtbT2IHrhPCO8s/727iECoWwLWapJQep9FpUkpYa4Dvxod4dbmN0 rwnj+oj+MTe08kXRSkIg2FHLjrxlF4k= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mnyfl1v0; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.244.46 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=1737061864; a=rsa-sha256; cv=pass; b=mbzrzcqGtW53YSZvfQDJnAm75pZy55YDcP3NUdSlzs6/HciyNpNFYN2YUnTnDlppQaIe98 S2oBhZ7gFN0Lc6CK4wwPRvTnul4YT2OCB8Y6Yl9csOr2PC07KAxvf+z9vE3Q7466WBALD6 NoWjK+zTrDecPsBP3/yz0zgCLOhpwa4= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dJvVKWCd2pk397RlFfxag1pf2HLc18EzWNOd/eIiZzw1G0dikOw4EGkovXDcK9YOYhZ8Nrg8vkA9lvLIaQUsOzHCaXAAoaGHkqTc8Rx1j9TC27AOQofio+s4/KN+TsuTQIHPp8WVVXla4L8Dcb+iHK/GRiFR+pO6hFI9wgUDz3u+fjHwtm+9ou4+fxpDvmtbS4R72EQYCtpAx6kFkHnHfcyFkgkfnm7NfsaeGpNoh0+ee/i/hMjeJK352dMAT8sx5Qyi2hLl1PsXpRLoW4zHqT81zsBuSBap/QkpyI7NJasej/JdHiTY8z9ZqpzNykq/UFKEZ3RVmmvay69h50xfIw== 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=3071ObV6LLc9U2n4A4HNDAeWGiw4e+9oj47G1aIi6QM=; b=Rn7mD6TgsOjEMJ4lrelAf3JQXPIJEuwm9c9NL+nzs15op+l/Aw20KjNPLsCfKrMLowkVvOqLfhKUcFRc/LSJ6Pqk6CT58dsRMFpNyv4k6XbOdsqnmM9xFDFAlFtjqMteYjFLZWGyKlUkTGx8REfoozZMjPHZFzvN61OLsXH1C5ABLKkraTHYAn6NyFsCzNGzQiC4fOn9t/WpIwdT0JDPtRBCPXHocL2FuBFGROoY8Jea+AsoToEJ7Z0VUCPwOOzCXs0+aXu5cur3KInwr4j8SqulXoWGB3nkOI2OglGzK1pY/tMEWjo/qwUQteTGa6QOI+NTbDuC78vNat/kmZ10WQ== 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=3071ObV6LLc9U2n4A4HNDAeWGiw4e+9oj47G1aIi6QM=; b=mnyfl1v0NwRCYLPfI+YWv0guSMrLTKdsXpylyX2Qjl6RQnm57KQd2XzpmXR8cBpM7uytZ/wqHgfhjLai1zkkM7mtcMxLJmVGOYlm43M1agyVpMJojYrI4iMWQmpwfJtRBOLz9EKrFIDbUK5ARMP5SzPHea2XNx+KwC4K2raRzLcVPR/Gu/nD48q6cIPLRMIMDNx0DZR/hQvCO/QlC04deu90AJn+hdl8hFAjzVO8PQWDQi94z8Z1xIOvm1hUnT58s9Rax2TNV2y81f1n/wUbe8emq+S0l3tULjRqa0Mqy1NztqcAwY8FP1/3hvXbZ3dIX9vwgvq6HorX9Px4G/QF/Q== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:10:54 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:10:54 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 02/10] mm/huge_memory: allow split shmem large folio to any lower order Date: Thu, 16 Jan 2025 16:10:34 -0500 Message-ID: <20250116211042.741543-3-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0027.namprd04.prod.outlook.com (2603:10b6:408:ee::32) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: f12e5b71-44cd-47a4-72a1-08dd3672436b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: tZQYn1aM4/lPi5k8hOsgidyCiH+tkMJXtw5Oihff+tOiye1Dr1RZx4M2y4Vofn0ZFcUt7Xd004e7LqX+KFbROPR8ZYGDeSqUDLYgT+DPwx/72TUeLNt6VRYpGP3xZr4qP2NnJnRXA8IffG+IT4hwioMwDCPlM/oM28nhF8d7t22lsd5ajDTzr242zdT4o3MaVUyoAs4pBEL97nH9iG7O1kgeMlQCcOzDi2voQruQAuEc+hRlGzPbOfxFpZQcC3lOjPcjOw6YDMshu13/E/wzPCzTWyzidT/mHQIAhBe/3Np3SZTR1bGEVzgGR4J4n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3FrqvsIjUv 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mr0a6ZkBwTwWIN4Lx1sAsIOWcobGzJEUfjau2OjYne9FvdwGiiYHM22E+Ca/cyJdpVcpBOxOt47Mohw7K7ywKhHIkx28hIzisBvxu4jfJYUhHGGRAgKVE65HG1BictkIPGBJPkc9dqd4yOMS/twcCguL0n+mePZYweQLaXzBTUxDi7ux+2U3L8k2HrtG1Ih7TuwmIYA0QAGhE8lY0B4JQAaSEYLOVbO+CRMYBsSLL7t4y2ahEIhNbUJ3Uu2+4PEAbHliknhsvoKbeBTyEtxZcLq8zQpG2qsmVD0k91CGN44ybqQOpFxPcHRPbOxu5M53dcEFlmR2K8MqDzyyGKocjO5tjweaxrUa1zDCL1Rly5sXu+19dYGoIdMdCICJ3vKhlMtVmViHivpqnHLQCnZMLAGCljpHMhnRDj+e0DmZgEN7DkBeAhUdVYHIJAqvxW64ILtx8bx/R3n2hOvHhR0qvQno86Tis3Xzlnp9QvUrXh79JoO/vWutBkhhUg8U0kkT7HD69YDrhMAacC8EvxPQyAnkeB1yg+bJzu3zE9MNoR4WveMEm+OoD3eDc5yzJvPTKpJwE+IfIHh+cxXvPg6dWgqT6i1tBBngRqtcpXPiDVu+N6UZFMzojxTjm9GkIPxEqZzQlUwai3wIbTWELWdnx3C6udAVodYvHaDrXI03+a2Gr5s5lupBUhcJcu8Ri6q0MpiZsKi9aqH7ceDE5bxax6Fpoi3DNv544KYwyd1TWNDqrhoiF1PrKsUTDhpgZCtM2+eCQf8VShjecGyrUK21zsd4qvvGvh6daDA54v2tD4c7t3iCDaOej6WMUv8gE608DV/9n7BVsQ0Ct3Z6VaZdyLnXRRDgL/Mp77JBG3mwGf8VeUBj94FNItrO9mG1JjYNd/ijKRPE30aqeptqvKsTn6bLW/TgKsFmt/gFxJclnrwwhqkNg7ckNeP2ATxcAVCQ8lF6KD77y1hDuAI2XxkHOe470NyIIkPbNQP80W2XoBKHQqg2vr0I1MIghc+s3LTB/3roUNQKNj0ogvj8ZUXuY9kh/y7WBUX4GUR9UU79cMmXlm7kgOksgnNte58WMjiykGHJG5veHljBgs0c/oiRmw5rT2QqqePNVmQOr2Zk3uv0WALdJiX5JKG+LakAQeoQkUNdXuIPs3vtfFR9WD1az9+h2wwvwPSqKg6OMzSda47ehN7Vm+8Ntf3Ub1lbAzcgptmuRsFcJASxac+xwogh8caBVGMGJzvkbISC261mQbgOnXiHSnWVwwm6xKB/nSAf3fyNeyY/NxmJTP386OefJTVcHCLVqJcidUwdJklsVVbyGkPV10Foi2Nxw2RySJcH7JnYjql9TiU7II3SIpvhiFqMVfDObz1yxy/1eMyim9rjgA30kazC8SMUNbpW1caL2LOizCJ9ajyxedMITsA6TohKtpvDeOSeCyxNj3k3JaY2YOAl7+E8IG8p8ZqAxgz3hJCEyEOAMRH/l9x62biRHRounZlLaV1NVFwC43TefgKYjOxWorPiPn9tGZP2qQ6swOH8lW3wUsl9trrX7KcZieDR2YOIr8jvx8lXw9wKTwTEDHBnA30pKjKp9yXHDXXI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f12e5b71-44cd-47a4-72a1-08dd3672436b X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:10:54.2811 (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: wsfY/K6+5DPNB6QjWp3xpL6o4MQU5T9op2I7WLu4bIXD8mFF+qlycRzkdZCEVCHx X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D411E8000E X-Stat-Signature: hk3sfxrg5zbnpre5y53t5nkqew8f9sbr X-Rspam-User: X-HE-Tag: 1737061863-684926 X-HE-Meta: U2FsdGVkX19UXeI8lMc2djz6jvz9mtSKogRNpEEHMS5DcKd1XLE4Qo8Vvj4SVs+C7SeANJ1N+ScDy5pKWCD8SdpfK2xoJqMABsxvRL0AeIxtBJrFWX8NCJYq7DNxDidxt8Z0w3doQBZaifxUVqTDV9FjZfJf6h0/iMfdbA/dw19gXSs4WHQEgWe3AivwdDhdYdLty7VQ1pGvAOo+j6IUxTc2+ZssVyYyeXMb43+9CnAqhRa7cQRmUktBQn2ohSlq9myeDvHTLlhQhbNm/KLEylNMbyPpJjckl3z+Dzw95RpQihp2TLx0Aj2IhX3gAwOvLQTcqKng1wtRfSiWVFHna/mrwvfc9DQrDBEKsJFBdqJ/2kbTX4U8nSH5OyfI/EN8v2HAprvv4DiTStvx6gMm15D0kS8oqT++13MocxMhI0LoUvjHr+gP5n+1DrrmXd+v6U2/ZSLcqGaNFxS0XVF2YdykW5ZjyonlmwIbzO4ekgT+4LeFaUvyRha/ZJF5mUjGi9zU1JLrLUbu8rS3GsX9P55WcAaeQS0HQAoF0zihvU+2Sf73Y2pzhoqe5mF3fKKfaE8p14Ts6Hg1jdxaxRAV/5gUmTVPT/a/CcBkU/0h7caY4BywIsWPA7/FpT7ZtMoRhwaS/+3qOcEOdLUvBB4skIyYYcomJOY0wWQI+H9QeyHio6vWeWV/6WyYQGoEUNe5r/wgwGGyalM57s3qh4MS45XAJTkBnukDGYYXnkovrx8+V3/EZtoJiRsMS90y2Vq27vzokxLZrhyjZpAMM+UmOQJ1EguI1kSw2ZEao1t+hVQCZh/QzpAsQzBdYD2vLHI6D54eQDRMz1sJBt4xb5bx+HkvXofJAmjBY4PHi//R/XlcdYyFrDrHLju0SkBHPpDeX8xSdSCxxhIMdGN64TAMszuab+wvINwh1N6XiKbsidW6z8qCFYEYEAO92+L6OarwUdTL1+N40j6/SQxYpcy InawiY8A 2LCDOaMAyLvQ4OzoRqP37KC/vEQiK9yjXSH4vUoqoBbr8gu4vh0vm7DCnY5BMg0kfW7xLn2dLw14e599FcQxGmkpuo0oHCtI92p3ntepzZBbtVsfPT+iobmtBVos3d0/+vFJ6itFlgZ4TkwGZtrOWYAYyXERd68KzHDR9FEGj+lgOMAzpBSzniJI5T96uuOh7wyr+ito1izuAmJ3pF5u32W9iKlvfBP5Mwjb20qglzcZdbaft85DoxLqIRsg5NTqtUZGoNifV4LE9yyx/2+hJ75NFzNiNb6DT6nZFqvUbmkNb06p36CPgUjXJpUaIySx4/grKM6ixSi8qzN762mz3gW3kA/5wNSHrqhpoClYBcug+aPIUuds1C1iy9LSLsmx+iVc2s1KMCIow9LM= 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: Commit 4d684b5f92ba ("mm: shmem: add large folio support for tmpfs") has added large folio support to shmem. Remove the restriction in split_huge_page*(). Signed-off-by: Zi Yan --- mm/huge_memory.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3d3ebdc002d5..deb4e72daeb9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3299,7 +3299,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, /* Some pages can be beyond EOF: drop them from page cache */ if (tail->index >= end) { if (shmem_mapping(folio->mapping)) - nr_dropped++; + nr_dropped += new_nr; else if (folio_test_clear_dirty(tail)) folio_account_cleaned(tail, inode_to_wb(folio->mapping->host)); @@ -3465,12 +3465,6 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, return -EINVAL; } } else if (new_order) { - /* Split shmem folio to non-zero order not supported */ - if (shmem_mapping(folio->mapping)) { - VM_WARN_ONCE(1, - "Cannot split shmem folio to non-0 order"); - return -EINVAL; - } /* * No split if the file system does not support large folio. * Note that we might still have THPs in such mappings due to From patchwork Thu Jan 16 21:10:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942312 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 7EE33C02183 for ; Thu, 16 Jan 2025 21:13:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F4037280008; Thu, 16 Jan 2025 16:13:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF142280001; Thu, 16 Jan 2025 16:13:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D42F6280008; Thu, 16 Jan 2025 16:13:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B5B0B280001 for ; Thu, 16 Jan 2025 16:13:04 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 70DAD121351 for ; Thu, 16 Jan 2025 21:13:04 +0000 (UTC) X-FDA: 83014565088.07.EC0C873 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2064.outbound.protection.outlook.com [40.107.237.64]) by imf27.hostedemail.com (Postfix) with ESMTP id BA0584001C for ; Thu, 16 Jan 2025 21:13:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RaMV0+l4; spf=pass (imf27.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.64 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=1737061981; 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=+VIhU8kstbeGfQ+N4xdwZUJPMEuC70nkJxjLzw3k2yY=; b=7VbluR5qMcHPwUF4vqIvwrnda/0z/Rl4WSPxmyI5erpCJGSQWRF0tAC32TWI+9eyCrIfWN 8Fj61FTtXL8K19nLXCje5RkAb1xg5XaSJKiDPbl6ojIPMWQ9nJnDWW+RF6FQSH7DPkXNUy x56aKYHcnpE6lttmexJ6mAeiUPRlYKk= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=RaMV0+l4; spf=pass (imf27.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.64 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=1737061981; a=rsa-sha256; cv=pass; b=hH6T8wcH8fgc51ByHUOjl378f2bUx3FS+4kEhfVPnmzrDzqiCvD5FH4h7QfRqNSFHzGSjR jgDbiGxNrAot2x3IPlgcUMAhMuxwckalM/DpxbLZjKMNQCeM3nfnBOMtzNNlhYAM91ysm4 NFvrf2Nsgu9ysV56wM5sV7Bdk16Els4= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bpqn9zmGuYAueUF4Vk3dgNEC8wv5qXsokM2RMtDqPt/ttqlZLEMU8bEPtNJc0pxvdF+KwHbKT1WWDtB4FUL3LWg7ej0tnTZGV0qrShK+0XIvtgGw4kJ0x+0XWvv8J1CnU0CqFoC33wmpPri6qBy1FjeJtDw0L3KP4GZz28/Cs0IEVeGJvqNP0pi5tnWAo+T/5B9ycHzY7M9hdyqW98Dp8kTL9oLWMTBhfpttYAwhkRWGEmX65zpnK+fcrIA3UiEBWATpXQmj0uKxJAxUnUelJ01m/MTmbUhUKnLT3Z690OujbNxRLMouqECmI1lMqUW9DLWd78r6eiHuF0esZRMTbA== 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=+VIhU8kstbeGfQ+N4xdwZUJPMEuC70nkJxjLzw3k2yY=; b=sTzqa87pBEDs73CZVkOOehODSsvT3azYzKP2C/j7ybYm8ZrIfS3qyJ2lHlf7GqOOVdqk8SMBX8YCJQJn4pXESS3UFehnWYHMtmC1zSr04Vs8ePMtIqI9LHzbO5QHYjzOSiVLUKfSYPBSDQ6YcKzCHFlGEIfMuQ8UdDTZ4XZLQaNux9YkbURSrW4Sjbzh7O0ChIWvhadmCQgIx05iWQSBgYnoloCQr5PjR/nkX7H7mVBKD1Wqj+KeWdJMoa26ipW2NRRINFOKEc8HeRjH4CpQVrPo78PWfSyL9xRF8sO7daZqps1msmU0NGdWnkMa7vDukjrJgAUTiZkf9ROYAKWdLw== 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=+VIhU8kstbeGfQ+N4xdwZUJPMEuC70nkJxjLzw3k2yY=; b=RaMV0+l4G6K70kxdYm8R8INUYHRarKVp8VKdLKeKr7qURlSllrGDcCVORP8P+Q4gzJhpdoQLrsRQ9HY8mC9JvhPXuuEJdniulxsAvkUd4Ik/6zYdOv/0yKFLAnUpZjoQLoSAu9g0WJ1lZa5ztVR/U9JIpJ7TNcmi4czys5XhA3Qj/ra534xez5mE4DdwWF/lSPs1udS7AprKxUN4oO/icWrPgbXvR90CNCSJrzGdjF6Ewy+Z3PTNTO08V9ZGSKbddRQJTJS1DOzdlrQG1YtkrVO2UtZcf+8dp0iRWqluFPNNjebGWa3oo3IY59zggq0Lp75qaCfwkw007Gr1BCwCPA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:10:55 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:10:55 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 03/10] selftests/mm: test splitting file-backed THP to any lower order. Date: Thu, 16 Jan 2025 16:10:35 -0500 Message-ID: <20250116211042.741543-4-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0005.namprd04.prod.outlook.com (2603:10b6:408:ee::10) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: b26881d1-45c9-4c7d-35b5-08dd3672442b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: FPrWHfWQnODQlsdt7aLk9yFitewQCtB8H21TXjnOGEUa54CIsH5TSarsM+E8Z6SrtMrwoU9LkZz4cQCO3YGJ0QfROCcmncXEvBi6tAkqsfHZtwO1YvDOAFRgRrbow8cCrVYFnPVP3dOLDeL07opIgappk/rEEzm7uXEsSUD4EDDZs2N+FPAcLxRMHt7Yy+3lb9ZA5PEZGIHfG/wgeyc/JeKRo/dQqXfw+6JARdY+Pdk+UPEvlNpyWNPTjdjEf5l+dhmBAQLbnB9Td1y68ewOfsIBCelyBvR2/OVvr93MIrk1V76Q3Wd/8iKx4ePVqwgteohIs7vglRD9nfXoQoRsLtol5vZx93KotNsmrnpt7nn/9CcdlVhXrjAabbjFnZ+/iBUpiEVbdo4eylNImOnJV4MGCuG55OsM2aRktAtO/P7C8inMf3oCRZ1QkgVx9Vup+8+6dmT8x2KpSpKEEGdr/II47NL78WqtloHCeU0MseGIMFjIUh0Kufq++e0ao30Xrn2ZGe0U9z90WmQC0nLIFSUNMwfWHCffHTF701f+Sreslz9xsxY3z/kpAxodig87Q/rBsL0DwcWnEqABnc7D9zT4VbaS4BBLiYsaRExf8QItEsJErqUg9fIpEkKzb//W+C7bV9WjyEKPUw2yY6L7sj3t/AaYGYW16iqAsjpdR+u+xXlz8Wup7nGnVx63Blk+NiyVM2VP7OY8pn4ZpgzwB8aTacv+nWaWbOQFP69jhK23G3wxwsYnZV85IWqb1zl8hQHQEvPRHhKK1eOR+3qmP7ampwo9dxVqe9EIUkKTvU8PpeUpBVSr1YU2CUwsrEZDw0ax9PWPtLKhaL8m7pMCv9jVotFnGiJ39AXmsENn55blqqkTeKD3Kq48F59zF7UFMu9VYgI+WjsdJjSRqA8de5+UjARpK0P4V2t72qnaSdBNIuN3l3kUQOP5YGC59OX4Mu5Amn1bQQ78z3vhLFu/NSYqASye8xeHIxjo8YU+v95Jl1F75xQPhuagZWaIH0peKvKxlOqCH2eY6QvdXWPVIRbYSgZMLu0OirAvNqyXUNO0d+IzZqQjBcco1JnR3JHrQb7mTvxlK0PoW0Q9j8euMmynotJzWUM8r0tztI/p1IifeEWFBH7b+Y85nXRZBPZtjW7OSykaV08WbJaX+Qm3Z4bdgG1yBb38ZJO5SBbC7DCxqzdpBOybMzvcxfqPT7BPjbD/pQWXraZ+p1PVlN5wF+Nf9fNMqfuIJjhqMfdKvn+dHxgFfZeXH/dbMYopF4p4S1haxOJXhScf2VTKUMhmnc8E2bBFEBP9gbvX6vf3OE5yWgiIdNoKK+Zafpx48tqEu88bGHkPdnivWxLugQLbWsDzBtptjcCcTk6iZXwZdhTr6jSs4VvRzeKXGQ0rwRMi 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HOQtCadabhr339CSzlKXDF8yEX9FJsAiNlGR6FP+rBM3rIYUuUtq7xcBkSrBWn5jv2quFEXajYhBeoM9W+MU04g1gJ3nFBvSgZifMplytwOutKU+b1ATTIGMdXtYkae9vGVSGJH0IbAnA3JgKGt3KBmlG+KCNv0IM6W93kHBCDt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g0AcRuB87xkvlHq9yTFQ/vivT4s4KE+9FZBcxj2vF3UuCOpnIlZR9T2jAU7hhR99+MjH2IQSNXenb4kTZV48fzA00W5kcfksFpyv8cUV091TJczpmzS1dHLntB0XiwP+006DM0Xa2Txm2edDG1n3wd0Gmi2L/zy9EiT30sShYAMTgFfx2025nKtBORZ6UQ5ceNuET5O324uyoor093uTpYhXhkGeKVmVtN50awRFkH3RMuhA6PHXW/Xi/95ZUh7ivEvsbmxSqr4oCd4B1tGwKlYU9JbZd62eXW5lyHzZ5wfaIMX7jxcmmwnnnK7w7h6lyuzT3X/i7+Kk+/HS X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b26881d1-45c9-4c7d-35b5-08dd3672442b X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:10:55.5474 (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: rngwo7Z6YsINEmckS615TUsDviz/jGjsF6FZjIreGaWyTi//mQi1/0MYpzToRHde X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BA0584001C X-Stat-Signature: jijku5rzg6jaywedzt5xdxgrg8sb4tb3 X-Rspam-User: X-HE-Tag: 1737061981-491581 X-HE-Meta: U2FsdGVkX197eiEQS3+MTxAjmBKJHVGI8ObHTKd5uWG2FpNz6dtsz4Otke+8H9a2FKpYQMLuKJfExGTSws7Mxby4HC7aZ7dCZZxLpvr2SAOkhuutuXBMv+9Y8J3nAtNc8lcv2kAPkHj3B0XUfyVH2fjLyfww2akaJ1u37Sgg/aAy+CYmzPVPtog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MsnyaV3QKxhDd/Rgg+9C21Wvwcc7qmebfjGV7ezCSS21z82FKVrLbTGicgVksF90jHvTKkJ4B/Aam+x1TbU5jWy1E1w== 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*() supports shmem THP split to any lower order. Test it. The test now reads file content out after split to check if the split corrupts the file data. Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index eccaa347140b..766c1f3a1d78 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -261,14 +261,16 @@ void split_pte_mapped_thp(void) close(kpageflags_fd); } -void split_file_backed_thp(void) +void split_file_backed_thp(int order) { int status; int fd, shmem_sysctl_fd; ssize_t num_written, num_read; char tmpfs_template[] = "/tmp/thp_split_XXXXXX"; const char *tmpfs_loc = mkdtemp(tmpfs_template); - char testfile[INPUT_MAX], sysctl_buf[INPUT_MAX] = {0}; + char testfile[INPUT_MAX]; + char sysctl_buf[INPUT_MAX] = {0}; + char file_buf[INPUT_MAX] = {0}; uint64_t pgoff_start = 0, pgoff_end = 1024; const char *shmem_sysctl = "/sys/kernel/mm/transparent_hugepage/shmem_enabled"; char *opt1, *opt2; @@ -314,7 +316,7 @@ void split_file_backed_thp(void) ksft_exit_fail_msg("Fail to create file-backed THP split testing file\n"); } - fd = open(testfile, O_CREAT|O_WRONLY, 0664); + fd = open(testfile, O_CREAT|O_RDWR, 0664); if (fd == -1) { ksft_perror("Cannot open testing file"); goto cleanup; @@ -322,7 +324,6 @@ void split_file_backed_thp(void) /* write something to the file, so a file-backed THP can be allocated */ num_written = write(fd, tmpfs_loc, strlen(tmpfs_loc) + 1); - close(fd); if (num_written < 1) { ksft_perror("Fail to write data to testing file"); @@ -330,8 +331,22 @@ void split_file_backed_thp(void) } /* split the file-backed THP */ - write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end, 0); + write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end, order); + + /* check file content after split */ + num_read = lseek(fd, 0, SEEK_SET); + if (num_read == -1) { + ksft_perror("Cannot lseek file"); + goto cleanup; + } + num_read = read(fd, file_buf, num_written); + if (num_read < 1 || strncmp(file_buf, tmpfs_loc, num_read)) { + ksft_print_msg("File content changed, origin: %s, now: %s\n", tmpfs_loc, file_buf); + goto cleanup; + } + + close(fd); status = unlink(testfile); if (status) { ksft_perror("Cannot remove testing file"); @@ -520,7 +535,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(1+8+2+9); + ksft_set_plan(1+8+1+9+9); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -537,7 +552,8 @@ int main(int argc, char **argv) split_pmd_thp_to_order(i); split_pte_mapped_thp(); - split_file_backed_thp(); + for (i = 0; i < 9; i++) + split_file_backed_thp(i); created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template, &fs_loc); From patchwork Thu Jan 16 21:10:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942306 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 9B361C02187 for ; Thu, 16 Jan 2025 21:11:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E460280002; Thu, 16 Jan 2025 16:11:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2926C280001; Thu, 16 Jan 2025 16:11:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A380280002; Thu, 16 Jan 2025 16:11:12 -0500 (EST) 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 D7A5A280001 for ; Thu, 16 Jan 2025 16:11:11 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5A408C1272 for ; Thu, 16 Jan 2025 21:11:11 +0000 (UTC) X-FDA: 83014560342.06.7F0B1BE Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2082.outbound.protection.outlook.com [40.107.237.82]) by imf27.hostedemail.com (Postfix) with ESMTP id 8E29C40014 for ; Thu, 16 Jan 2025 21:11:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=f9vTHFkx; spf=pass (imf27.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.82 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=1737061868; 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=woUOmSHTfo6rwe2ZYwHaUuWygR5g64CLBIZHqefs/90=; b=O4v2kDE8efZlErvFQa741KOxgSRlMG/8qDmUY5a6Md9Z8c+NayuN/EjqYDzODhvp/zfB8c vAJu1Pd68gVBahfRQYNoIt6MnHtpjcL3hOt7AJFGZF5Wrh4qN0bNaKPnJpTPOQxF7vjTHI IfA7z8JTkFiOlOG/Yst8VWu2f9CjGkA= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=f9vTHFkx; spf=pass (imf27.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.82 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=1737061868; a=rsa-sha256; cv=pass; b=Y2bD3zkIvUnDVTzX3y8D4sk8I5CSIeuBY83PplCloOxzdt1C38MZCrv5ZCQK5zcQfQskG2 yU/m8n3WdHC9idLFNkVr0Fb1vTddVT6Ye1+RnXTNPb6PLFg+1lMYT/iqOHUu75qB+bMsGC BtcixgQUn+coyXKvTNGLJggf3iDR2tc= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tR/a5Z3BnIOtPAgFdoKRWGoAoDqY/Ph98RqLZ8URzeEXUz4JyP2HrkijMZfhT3z5JWqX6vvVmFnJlW5lD4Y5pJJWpuqTisluewY7+FcTVtB5wvWbV8N2jm9BJsJyYo2UoLHazIjHP0eq0qYsmpVgmo93xUDL05XJ5Wl9mQ+ypYwDS7p2/BsNyeKy8hcWVcNAK6R7o3NHcMj6zCssbLzZP38J8dd/aQWIrPhcsVmhMgGIaE5ZGMokR6vInGKdVxPYS9oHFDs8aulkh/eh8xSAM4v9bnI8kAEeTUQkd4pSrhUM/loYyNMhtkQcWc6lsGEQi0FM1czLis1ECPXQ1KsHPw== 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=woUOmSHTfo6rwe2ZYwHaUuWygR5g64CLBIZHqefs/90=; b=FPoaiEpU5NZ1FP+uSwbM5A0CQVcWvIOzebf6WPQAAogjzoKs4ujjdQcSYq9k+ac4FiDqQ7OGEXR9Gk9M2MEJ9BED2kxq5kzgB21KTadbMqlLV+iZ3o+6GOSorAsbs/tpgbzlWlM3wjARBJzpzS3gXjGe6QZNV0aF5udxmSQLOdBqdhP8IlgRvrnp7EkXo7XeJGaTFEFhiJi/Ngl5/JH+dp9WAU7Bfh26dc8ulC00fM/IHrYzkEPlRY8wrHOTuT6NjzLrte4GlBq4GrforaEX8RGlxwy28rApYvMVa+GvqTf12PKpWmqj74DCp1NDj3/PL26bYdmSOCXl7fcZbjN9bA== 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=woUOmSHTfo6rwe2ZYwHaUuWygR5g64CLBIZHqefs/90=; b=f9vTHFkxGPrKj/nMk8zedjDbDyQBLFwKJkrSTlIwXbsdmrBCM06EsRvf4kKwsLQL/AhTDlfG1V94wj/bRbdTJJgc1/m461sEi95rf+HsMtQwZ1ImL+NK6zHYyDfExn3V0QWTvgTpoYNLFpqfTeqYUdG6H2irmZ/2XVxxoEsaF0j6zoPxKbirjjYgmkMPb8mgn0hCNv486f9A8MSUxAXNRBBnh1GdZo3QWgyV8LE9wZMzBhnGIl5hbhlYpK82LGyKEVnXeHx2oFK389COH4I0PZttNe+VvKzdnBM/cMfhFzBmkR8kDI3m8CiaRgC+paNKeoDTeWbrva59ZaLbkBSLlA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:10:57 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:10:57 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 04/10] mm/huge_memory: add two new (not yet used) functions for folio_split() Date: Thu, 16 Jan 2025 16:10:36 -0500 Message-ID: <20250116211042.741543-5-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0008.namprd04.prod.outlook.com (2603:10b6:408:ee::13) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: 09ed7870-ce76-4342-9393-08dd3672452f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: A8tJR2ljMmihnm0zGPLaLzQ7hcskx+oivjhCnMG9NYV609pU8XyGDp+dvhnQl22AxNEMe54v7AFHK0pafwy0nl40wC90/ve+/6W0VFEOuzrntv4bFGjfJEGteL2uFxPYELGtdXEtPfgaKJnJK+I61geklL19R2fOyGis8TJ1YKCsklyO6vrwavQ+r58gAlhLW7j3N+nkkuT2bZ5GNI3FhJ44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mZna/pRMEcQEduX1jMatqCobo2GDOLbTDTxfU49wGu4ZbhuRlguRei9uQsPs/kpZ1kiQaAa8Ozifd4UTtEnwN7bUHd5HymN+5aEL6oIaTUFgl91eH 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z5sFlWh5dfVdcTkbswITpCzfkfkhkt7mYRFICVZp5vYNiiyyuEG5v8fSLpVusrpV7CGouF4gNhUdo8fQws5cajFi+jFKO8Cu2or+xjSn+Pains5JL9LGgqEGzErRQzVNesBCcK15hozYpX/q8XI046ilcfv1slprpNkB5NgZyYeNC2C1lHVwbmqDXlFddLJvnn0EgDUiJlky2vQs+Z9HkwA1wntcrIjdpOTNL1MAWBWGurry2Zt9vpUwFIWaSP/+RSmU6Fv9Xjpu+j4ZS0dPUdkLOnso7kXSVMZfEiwx+Mdh17qOjhL5eGk29b+FmB7lF+fgidQxyZ+vzJvIfQs7nxzSyksTIkxOFb3eZwCgf85WO+AaZ0Vxcj4xV6j+9zdED4Ou5n5E26UtPS9VNuPZ+w9M/sO+QKqLinawVeu/cqKfmaQC3RD0O3vg0i8PWXNtuOEhRv/t99VoyM+drQqU1fVoBeYrqUAA/zgqwnQKKzc19iIb/OuOB0MClUTYi6AFceOXiJc+m1M2Enox9I227D/8XcKUvWZK4ATaJv8cOTURTztoXK/s8BDMrTn6uNf6yWUxwecG9tQiutiA6ICT1imtZxy7Xo3jrjupVNuZyYbMFF3t3XcphU0r/+iuAtmY4ZXpzprocwiVgfFs6qzrZIOmlzo9W2xkdECIPu9NCEQmO2qkSPPRxIxCSILjPVwRY9SV2rJM5P8CX2JLaohPYf0YovkopC6gvU2yHkfyM43GxmOIoZMEZ8xv/ML8iehFztvlARoMjyntGh3ucBZO86pX9tv9GsmWzkx0hp6QMA0RlIWo0MwIgwhTNTvmWIZ9I/xOOxvVEUvVS6msZOIZk1mwqM2eeoe7TYPwtU23Jf7isi7LprRTDp1wS+kSA+c2WSz/KgyVYissg/U1sdxrVWNbIE7f1jrQs8nmHmkkUHs3RgkThkNJAYJD38Ckj1Zi0GXxp1AcF4AoH3XPb+wJDrAEGa3/AX4IfBw4lx+fHJGxTz+rKHoiZMyubsGY/aM1qC6GSVpmxibCyGadmiXJ9PCOc3lp7unsMcwPWtJ+Q+B3fl+qEN53ZzLKc6+ozlgersOTe/WcEuITOToflitpT39yYQ8trsukfE8OS8dlJcGOH/AB7bWlLk3h9y+ONqDf5TTKtBONKBmEaYJ0myrQ1n4UnYK7i65cPBfdlztpzi+J+D9iwwQQZ0nsDDdEnyHZActZPMBWIL+rv/E6zpOYWdRVHZ2FiNp6pWiDhlGCDjbnQ9irPdVkopJ9P5H05bHuYMqlfv5JkRmRiDe3OYXKBCaahQH2OYk3AbSAbQL7wiJ1wcDRANmYBmhw244q3AwI7kNoOLnU3ILx6DPo+MPY/PDb/whq8YNtTgVwALKuNccejitVEY6IJyviOdenMjUbrKNDnjfmJxRK6KrPHUhPubSC3xdNfUIOBWQrZ+CDrBQpkia//xQxJcEDg0xR3ieNCrXb+Frlo7HAAyeAezokPoIe2ef5AhBC/AA2lMAaioCsOf4kLP719uPpQ4hQB/aslV5P+K7MfZw8EKv66AE3ODALBKRf3Sux8RhUhaf9xo/5iVfY1F3yphxk39XTn+9y X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09ed7870-ce76-4342-9393-08dd3672452f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:10:57.2446 (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: PZuqwzM8C8/kL9a+3eyD9o+0LzTzQtLBxuawEfO9Df3TA779mgDWGSaemiIkGAjj X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Queue-Id: 8E29C40014 X-Stat-Signature: e7uwdd97eby3h9hq4k9mz5184b779ezr X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737061868-193749 X-HE-Meta: U2FsdGVkX19oELY8iLUt4L9BBDCcYbpKioPdm1gjUpyIlzXKECkYvYTwKD2yJciediMI3QXkO8EjZ72kq4TPMIxtSVVvKnCRBIQZM4F3kYZXrz0CSGu/pE1rNUZ+B3DFqlYf4mx94eHy78gchx7hRs9zRIrmKlY22gUlXxSyrfo8xvu3sDQCYhvrpKGpFPt+KsEanuvOFrZXmg+dIgP6Zu3am8BMkHPeGOYjA5/P3daqsuSGE4QZD2LQomV3VEmyF/5N5t1ITE9yBMAIWJa5oc9YMlvepnk33JmeKNE/XsquTBlRVHZVPXgmq2EHK9slM4x5S0InavJgQTZ0MyGuQ3m0SqW2NTM1rwXaXU7lIOzBsaHjl3fB20hEO5QsUhGgCj7wM3LBQA+XcFOTLSgymD8xgDqSa04hIZUxNyZPdPbFmxXTt4gDFLzFftmBGuCl5cz/LjKBfGk0z5kKIFUmiWkfKByYPPAORomDWwXSo3Q2dN0hFtbs9buUK0rcWf8wYGqgtPP3ENM3Eay3UJuXiCK6BxYpGAzAzaWraXqgpqMuY76Lpyu0niVW3/CPrpDW0BzaXRTm/N3r8FqaLG5zvGlvSN+oDDozvX1OvYwAs+VfQ2J6XIPG6jKOCaTyoskhrnDGCbjhvgJkzEpNqlMvUP3aoU3X8ItfR4Hc1LyqfKFAZfMOD5GTu3RUwLOdqw0epaJj3JLchL88SXSsNX2LXien0i3BjsNLHHjpxdXaQ4SZHWuT1irR9CqYhdPIdiEbrdOxrooSoE9NqTkrToSLeg9jjtzj+BUymhcktFcUE1P789M7RaC4NIJY2v6KY4nOfo1hBsqjhoZFgFvzky9D6NM6jNylY9yjxvQbrXMhc9iabuT8X7Uxt7PyubLqMzecWt2ZwUCURKLUc7t7F6wIuLe3q24ZtfmH214Reza8OjxXIu/je5RNXpnBX7FMFCFkf1xuqR70UW6bTB1RSX3 d1m2YMKs 43OSMAEeGTHPw7oc4+VJbnwoSW6IgTBXRu7bKKL5CYwL0nRFnJkSn2rKHJarYpwt93Kq+sTJ3TkPEZjAYkBBq7QXI8+Ce/pvhL21wwdLWrnVttNHuMUddpvleA+QDST8mzMSDxI8AZsv8lWbouFxOc3/+xIvu36F8Vs2cs3fGZOa+CdIX3LDToMGZZ1PxNA4N2rTEV0Jd3PBcm5Y+iGY49kVnggjgkIKjmLgF3KASJG2Puo6ON9OFIkRCtaTM9QhZ00mT38fPsO2L5k/ekiN2aRYVOPw224bh76Zn+WimIknsebsQkXYAasm7tN2yjqTdMAwI7YUMfWIoXKM7y6dGNmslXiFWtATAZh3uweN85TLORMuXHsaEHOU0lTg/aBOzABykZ5pp0cnrB08= 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 __split_unmapped_folio() 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, __split_unmapped_folio() calls it once to split the given folio to the new order. For buddy allocator split, __split_unmapped_folio() 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 | 350 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 349 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index deb4e72daeb9..c98a373babbb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3146,7 +3146,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); @@ -3390,6 +3389,355 @@ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) caller_pins; } +/* + * 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; + + /* + * Skip the first new_nr_pages, since the new folio from them have all + * the flags from the original folio. + */ + for (index = new_nr_pages; index < nr_pages; index += new_nr_pages) { + struct page *head = &folio->page; + struct page *new_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 *)new_head; + + VM_BUG_ON_PAGE(atomic_read(&new_head->_mapcount) != -1, new_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. + */ + new_head->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; + new_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 && new_head->mapping != TAIL_MAPPING, + new_head); + new_head->mapping = head->mapping; + new_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(new_head->private)) { + VM_WARN_ON_ONCE_PAGE(true, new_head); + new_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(new_head); + if (new_order) { + prep_compound_page(new_head, new_order); + folio_set_large_rmappable(new_folio); + + folio_set_order(folio, new_order); + } + + 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)); + } + + if (!new_order) + ClearPageCompound(&folio->page); + + return 0; +} + +/* + * It splits an unmapped @folio to lower order smaller folios in two ways. + * @folio: the to-be-split folio + * @new_order: the smallest order of the after split folios (since buddy + * allocator like split generates folios with orders from @folio's + * order - 1 to new_order). + * @page: in buddy allocator like split, the folio containing @page will be + * split until its order becomes @new_order. + * @list: the after split folios will be added to @list if it is not NULL, + * otherwise to LRU lists. + * @end: the end of the file @folio maps to. -1 if @folio is anonymous memory. + * @xas: xa_state pointing to folio->mapping->i_pages and locked by caller + * @mapping: @folio->mapping + * @uniform_split: if the split is uniform or not (buddy allocator like split) + * + * + * 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. + * + * + * For !uniform_split, when -ENOMEM is returned, the original folio might be + * split. The caller needs to check the input folio. + */ +static int __split_unmapped_folio(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; + int start_order = uniform_split ? new_order : order - 1; + int nr_dropped = 0; + int ret = 0; + bool stop_split = false; + + if (folio_test_anon(folio) && folio_test_swapcache(folio)) { + /* a swapcache folio can only be uniformly split to order-0 */ + if (!uniform_split || new_order != 0) + 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); + + folio_clear_has_hwpoisoned(folio); + + /* + * split to new_order one order at a time. For uniform split, + * folio is split to new_order directly. + */ + for (split_order = start_order; + split_order >= new_order && !stop_split; + split_order--) { + int old_order = folio_order(folio); + struct folio *release; + struct folio *end_folio = folio_next(folio); + int status; + + /* order-1 anonymous folio is not supported */ + 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_split_alloc(xas, folio, folio_order(folio), + GFP_NOWAIT); + if (xas_error(xas)) { + ret = xas_error(xas); + stop_split = true; + goto after_split; + } + xas_split(xas, folio, old_order); + } + } + + /* complete memcg works before add pages to LRU */ + 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) { + stop_split = true; + ret = -EINVAL; + } + +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 (release = folio, next = folio_next(folio); + release != end_folio; + release = next, next = folio_next(next)) { + /* + * for buddy allocator like split, the folio containing + * page will be split next and should not be released, + * until the folio's order is new_order or stop_split + * is set to true by the above xas_split() failure. + */ + if (release == page_folio(page)) { + 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 += folio_nr_pages(release); + 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); + } + } + } + + 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. + * For uniform split, it is left for caller to unlock. + * For buddy allocator like split, the first after-split folio is left + * for caller to unlock. + */ + for (new_folio = origin_folio, next = folio_next(origin_folio); + new_folio != next_folio; + new_folio = next, next = folio_next(next)) { + 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 Thu Jan 16 21:10:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942309 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 07B9AC02183 for ; Thu, 16 Jan 2025 21:11:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94B98280005; Thu, 16 Jan 2025 16:11:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FBE6280001; Thu, 16 Jan 2025 16:11:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74E40280005; Thu, 16 Jan 2025 16:11:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 57DB8280001 for ; Thu, 16 Jan 2025 16:11:37 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F0B4D418D0 for ; Thu, 16 Jan 2025 21:11:36 +0000 (UTC) X-FDA: 83014561392.29.2DECB3F Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2086.outbound.protection.outlook.com [40.107.237.86]) by imf30.hostedemail.com (Postfix) with ESMTP id 3448180012 for ; Thu, 16 Jan 2025 21:11:34 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=GxpHvIUu; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.86 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=1737061894; 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=7pPFUg6rNWV6UdEno3cFBDu9+zQhqBh8bUtDTehyLM8=; b=YU7FNTfCugCWzfZH/rGacnsSdqvuV/Jf4znAzfyYNRKXCO/yWLfAKI7pygGgJyFjV6v0dA C1eFWJb1Tk0px3WVS072F7x4+hR0aGoYOXqgbtmpNEXzwTdwBQi+hjAEdrUGEolMT76Cio 3PC2iChB2zuswWyjYanFnyFVycSLFnI= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=GxpHvIUu; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.86 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=1737061894; a=rsa-sha256; cv=pass; b=wgvKI9OtS7ml4t5203MI+6BUs4Lyi89vW8/Dd0BiM03xRR2mbiAbulHvmc0c5TPLME/eC7 BCJ4EuCz6cu5myRJjttOgUgun+OCg/jg69P2nt/o59DJxyJopF4ZcGBqeuE6yRP6LL4G65 HpVWMItEPp0AL6IWsYWAGjLdgqZycxc= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FD8kVHZ4htzMejmWUL9H9ybI3yveJSBtYqx+Q03CKv2TLr83nqGds89exMQ4pTN37K3OjRQqXe6sNpaKABfMBAq43QskKCa8daFMeiJfcTslTp4TzHKQrkSO5GbP7qTa7SXdjHGy2cmQd1hXcFHvEWemnzT1gtV4XcobUHROx8M082HnvelPf1gUOyiGlLvLX/+zfWRJER3gzkTuIRxFTfpf27v6tQwKRKgzVnntYL6lNHrIxN+T1En9Ovpb3NZq3NQC8BtcE5bmoabteb/xMO2yIDT3TTX7LrdbIo22/dxvewyKGFzALq5UalVw6TjNYa2RtSYqUBHnztqjpbOkMw== 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=7pPFUg6rNWV6UdEno3cFBDu9+zQhqBh8bUtDTehyLM8=; b=TZZTQ/4ROV6giNL2SpIlZFOpocWJEogIMiLZ1TDLjJZSL7FR52ebWxZWXTYZTjSZ0OTnTLuMxKb1NobXhEORpw3CjdCpoqx6FQOh/3I3ZdFHohTZf3Si+FLY0BdyQI0a1sk0JwMwkUbnuEFh5L5994Qzv3qR5Q7JtcEiuSiG+QZHYZZsJwF5RaJERXH9vQWsKy3HSo+WmLK1VddxHHwepNsP0LtKvNhSf0lPgjM5eU33AGS92xtXNMvm+kPj9NbqPEz/hdmoYq3ybt7+mRgysWQJHjRvpjrSyxW3sKHQRI/JnDXW+HOf5RINkbXsQehffYD7o++eGTuD8+xPzH+3Cw== 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=7pPFUg6rNWV6UdEno3cFBDu9+zQhqBh8bUtDTehyLM8=; b=GxpHvIUukfz31nxX7Q8XuBC1yvAqDueKZOqbZqKoVCJ5vREWclxiwmV47Rg609q/i5Lqn4TFJPo6aEOJSChQJ832MKAbX9qEtFWcbabaKJ5msnOSwPBcP2+0fBVEsNxyuLMeVKVIOp2Rik339rKksg5CH+ebVUmaL35QiFr+7oFy1vrupjCMY7YZaD3Y2umZ7GHBeCUlLO/XqhQuj6z/Cdpr5Pk8OYzWBHotQhyRk05Ahr+1/gOcXHV3v77Ef/NeGuxgego6iWvMbWO6kj9hfViQbHgzCT7JZnR4N9TsFLwcw2ocFRLidj1fbuwtJQ3QaNHRAJ57axowGe383er2YQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:10:58 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:10:58 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 05/10] mm/huge_memory: move folio split common code to __folio_split() Date: Thu, 16 Jan 2025 16:10:37 -0500 Message-ID: <20250116211042.741543-6-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0007.namprd04.prod.outlook.com (2603:10b6:408:ee::12) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a53e528-d0e3-4056-e7a5-08dd36724607 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 9z4k0xAT+YKR52S7SYg4w5vW0C53hnj5KNtpitxNIF5wfqQvOhqbNtahpmlTxo9PWyvNuXWN/bl28OEmy23Ej0uKjM08j0d8ZEwgixEc8O8dMVOg8qTYBlPTnV9CUltc7x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uGgqDj3DvjH9OTHR0E2of9+RecmnDUmE0IdjeqapIEi9zUktLsDnku+pu5UeZmAX06Zhb7VyGH8M0JdjN8o1CGbrby/XJFTklN2YFVKkz0jvHXRq0AItR5A8yReQp/uFbbLZ/BQvze+YfC2DVtm/4rDbexpSWy6Qkp77kpoOaEBtKl2dB8M68iLSfUqgUo9bRLOHKGeWL6fFd3J3wT 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ME+dIDvH7UfmRFe0GjEVjq7FHSTha1DiKrqjV8Eu5ATZbrveLtHbETV1waaMEE8OrJ/NxzQYvzCH3CYmfvIxrx1j2bwvjpoBZ/8zGqLa2K/W7KjGZz+OxJCU1CaQKzYkS6afpTK176Q7Hq5PpSq4ZLc0deSbCD675Fv75aheBdIjhv8I21fR4QcfvviWh50FMrKz3V8X7EjWvDLrSjYzu8YHBuaTyYz5HdMH1HzFRL+92+aYVIGBLxqiiF54ZfG5u2qcdyC0U2VxnBSZX1YU5b9kar4rBqgj18f3VBhwBmzGDseHUG9uwdkJRRToMuuVbI/cineUu6joS+LkvUnM/j0XT6yT10SqVSfT2m28SvDnY/3tm6dPvd42PheT7gmjMSfXRYlpYGeWgUXJv6ccaQn3BmEEZxk+tF3fWtN+Q5itJ2/W/lST9rbZE3xRAvy1LoMuCYj0GXVihICbTpkaITT5dZTQ1E4CUdJd/29cF4qLllg7O2Ln8XG8LZGJz3F/u2LCqRr79lR2OjuNg2/oLrfKah3wrZ4QK4kAvoGKeLTJ5bE2HhddexVc/NS78gkNOdV78wnR/7F5e2m3xukq4YP4UIKWOI8w3FJZXfc9GyLzWFbrzvzT2JTnqj+POVo8IcBFyscSG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.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:10:58.6680 (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: /A8AGZIE9xTmQyq7q14YpO3i9WPQ8B5Oe5Fvy04vKOixePE+FrkgDRvF2WTE08hn X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Queue-Id: 3448180012 X-Stat-Signature: 4o6wswq9z3g3wgszcnha3umjte68k6rz X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737061894-733391 X-HE-Meta: U2FsdGVkX19HHmuY/W0eUBIhnIBesOAydAgzZlFhGRk6ydSmvlPtUrJ4ip0FfryikX2lqKjy7KO4p6RtrCS9HgGzLu657kj20FXDCHAvQSB8Mh+vXls4N3XrtJMSgrNpuIWSZ9uFZrzBSgFG+34aDnM95NKJdAzVSmwkbPlCuH5l12AdibJUEu3plYzMIQu/na/6OIg9jMuI/LX+CP6HfS5U7sIkkrqI6rPlYMc6ae7HqE/hUrEhzyerPvcynKiiBeMjL4kXk0q+p8P4dwpbLy0GY6t37DJJ09yrq+j4s7dF/KUgFxOVFcz12EGfT9tL8n65YLELzFgKDRCdF/Dy/1SicRBW/t6ieollHKo4rYlcHyLi5eSr2y909KAbVDNj8InzAYgtkoZzq1acgc15jHaCwA9+0A8mWsb8fSXr7UufhLcvayKtW1PXb2n2yNLEpCNQ+fGxjCefjg11tgK9qltx+5sTYtDk6jn3qDmVTcDsHZ+wBkG7YQkhMEYWIQp5ILrn90cTwnZFBTHKRaFwvI78m5jrdK98DuU/v15AED4nyfnzLGm3S5M3HUu/01v5ucJWT+68dw1cZF3FGZWTgiggRO+cIc8jCCGVXV7xuQqZ0trdsvRyEkCOxtDa/4U42rf/KuC1O2h+l1YpeHze8bp0/Cx6CJB06vG24u5A6NoerpJX0gzQY6Aee8dOPf5t3XzwO86/TxYHA39DYQKYjmnDJJFFVVsWIXKj2JOQ9IMgQbt3rvLIZQk3D1JHa588LwH0zGW1h54SvsL2lW2wvJncB+fYqIZFyofSPY7KvwZ3+pcI0nJnv77J0j+CYKpNPqUo605jJMe3knRluiTy0vEPu08A5Gc6fB5xHM/vGPAG78ow/1U71OdxQmepxeLQ3PBikbEWhoHWNPURZwK3y/Avjuuw+V1Tklx7fR3v5LHonOuE7mF0scmlVb6j+KQF2t0wyxEBrDBKUplMdLd qWf8CyE4 p/NIFZZAmSVxGAUVMkw/Vq0SYYYO7G55mpQD6a3DEz0J6Lu0dzUqsEX+3z6A1gtjjugZnUYs1T3K/OMGQBAK2O6wS9q/imk48EW+sdv03QtpLkF+vLcjeMDhjWHmwMrYKv68JqS9le2vhBzbdOhfMBtyMP0N9mj3cMwrr+k27tWu/hh805nuZTMhHKJ7lYvzvdgM5q4UsvaBpSaZew7+yeNIdM+CIUSnkQZBMWOm3Ps5X2XF99fYt4F775/WXNCOQFblcuZpS8QAG+bl56ykXEv1iapBH8CfKjyagGMpLed+JblXyVgFAVM3wPZcuZRhXDUVqo00gT2YCSoF4iCet1vbPYZsTp1hgxb0eIWS1JIJ4VJksY/E8Q9pK08c69ROh36i9H7eMwJ5Ds3g= 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 c98a373babbb..6c0089a0bcdb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3738,57 +3738,9 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, return ret; } -/* - * This function splits a large folio into smaller folios of order @new_order. - * @page can point to any page of the large folio to split. The split operation - * does not change the position of @page. - * - * Prerequisites: - * - * 1) The caller must hold a reference on the @page's owning folio, also known - * as the large folio. - * - * 2) The large folio must be locked. - * - * 3) The folio must not be pinned. Any unexpected folio references, including - * GUP pins, will result in the folio not getting split; instead, the caller - * will receive an -EAGAIN. - * - * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not - * supported for non-file-backed folios, because folio->_deferred_list, which - * is used by partially mapped folios, is stored in subpage 2, but an order-1 - * folio only has subpages 0 and 1. File-backed order-1 folios are supported, - * since they do not use _deferred_list. - * - * After splitting, the caller's folio reference will be transferred to @page, - * resulting in a raised refcount of @page after this call. The other pages may - * be freed if they are not mapped. - * - * If @list is null, tail pages will be added to LRU list, otherwise, to @list. - * - * Pages in @new_order will inherit the mapping, flags, and so on from the - * huge page. - * - * Returns 0 if the huge page was split successfully. - * - * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if - * the folio was concurrently removed from the page cache. - * - * Returns -EBUSY when trying to split the huge zeropage, if the folio is - * under writeback, if fs-specific folio metadata cannot currently be - * released, or if some unexpected race happened (e.g., anon VMA disappeared, - * truncation). - * - * Callers should ensure that the order respects the address space mapping - * min-order if one is set for non-anonymous folios. - * - * Returns -EINVAL when trying to split to an order that is incompatible - * with the folio. Splitting to order 0 is compatible with all folios. - */ -int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, - unsigned int new_order) +static int __folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) { - struct folio *folio = page_folio(page); struct deferred_split *ds_queue = get_deferred_split_queue(folio); /* reset xarray order to new order after split */ XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); @@ -3998,6 +3950,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 Thu Jan 16 21:10:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942307 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 5B8C4C02187 for ; Thu, 16 Jan 2025 21:11:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E072D280003; Thu, 16 Jan 2025 16:11:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB669280001; Thu, 16 Jan 2025 16:11:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C302E280003; Thu, 16 Jan 2025 16:11:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9FADD280001 for ; Thu, 16 Jan 2025 16:11:20 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 524F71C84F6 for ; Thu, 16 Jan 2025 21:11:20 +0000 (UTC) X-FDA: 83014560720.08.16B7243 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2056.outbound.protection.outlook.com [40.107.237.56]) by imf13.hostedemail.com (Postfix) with ESMTP id 899D220006 for ; Thu, 16 Jan 2025 21:11:17 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="R/1mNyhL"; spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.56 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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=1737061877; 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=nL+wY28kI76n9e+G1XMx3CKgrNgqEsGZq21/wECx+Fo=; b=P8HzWPO8jouHKGQi4HfpN3flQu+aYss8XluI/Q5QXh6SyYAV52EdjeKhwmd5QTwuxwgBvl iDvh+7vz1qP34PfQTf8CY8Kp7KHopN9YMOC6IRBfZ0Ty6/nWruWfybRJ+v1YN39KC0JKWP nr03jLhl9bOD8oU/KitEJVumN3g8Uu4= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b="R/1mNyhL"; spf=pass (imf13.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.56 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737061877; a=rsa-sha256; cv=pass; b=0+A2DtReKkIFL18wvK6uAsm/Si0FKIF+o1yzo8bIhWaHOmhSVHaP5Uurpzeq5VyqnCdcOu P8VDSQlZSEPjyzkDNq+rCgW6FFmF4Vo446REondUV10V1FY2rJghN5kUrOcYrWKmSUMC93 m9Y74iFtcWVbsdnvXRZLW4I84BEq4DQ= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ay7lUGLeRWvTh1PkT045t0eatNce96z/x2VWfYKRPtWJMY6HedwxCOK/i9DOLBxlzXnlVkKiVo0R7nk9Kp6HJXHa6IkmXYgBmQzE4bDPC+uPzEDPyNYZkwzx2ek+7h+FnwVc7EiNDnBC+XIkF2DnZjVLRuNdMQsmmRH0XQ2I1pOWC6vnJx+RvE+HB2hM+LerAvbBfnQL/TT34UAjua+ISkye2OVAdNPjS47hCutdE+994HR0v9A5sDjZ3UY0H7WtywZRUSBkbvpJMGjF9h0Wj3FSOpSZmg6dOKdJ7YfV2aGMxaI2R9nDoJd4C3NoJjF7+bLPcsYgW0GJu4pVVZOTsA== 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=nL+wY28kI76n9e+G1XMx3CKgrNgqEsGZq21/wECx+Fo=; b=skRYi/DTQBlWY5h5JGrdoMbxJOvKciNxXoHy+/tGqHFzPEITMWYPcO1UfsuqWw0QATh9s2n5DYKPavRYZ0kKKE/56iIh42mzDLikmllcXP7JULKd/hNrVza2NhOe0CB2blxYoIzMR2Ip+mQQy6qzN0Bm82CQMwyFVqjvK6aS2P9c6e8cv4WRSJgblKWWy9XmujYYehphqqyEy/xBzPVkLVRyfLQi4JAAnDERq5GwXGb0N5whqYFNQx1y/Ie5xQvTrxDIOFdtftm2wwtLlISJ3C3E/AtGcr2wih5l6z2Hu+kwkTV4v6VPDDo7rbFApk5T+2OoDE+DRBCnYx2cXd129w== 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=nL+wY28kI76n9e+G1XMx3CKgrNgqEsGZq21/wECx+Fo=; b=R/1mNyhLHlAginPplFUBV61BKTlwGDMNLNgh0wubYcwV3t3Kkbba8a8YBYTkBKQ4Uk354tlP6NTTFKWrgu53Nq/OXFkcj2tEfNQlWfGAD2x7UOh9A9VpEjP3jP4umK24IRlHQrK1iYdfaFG5uGA28QfNYq6FWE2JHlsjAVHNSZQMqhyU4yG+pRdc6gsGa+/yCU/RPOmWQwfWPL2ZoZIo0DGi42cZWyVU1glFECPLjeDT934upF7W1ynNq2HDk9/AHzIoe2OnAic8loEr9uGqRhPGZOMZCOeNmIogUJ92SGt1V2G921GYQp+J+RUbx7ie/wbX8MauzPfeHWswur23lw== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:11:00 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:11:00 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 06/10] mm/huge_memory: add buddy allocator like folio_split() Date: Thu, 16 Jan 2025 16:10:38 -0500 Message-ID: <20250116211042.741543-7-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0006.namprd04.prod.outlook.com (2603:10b6:408:ee::11) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: 31e6b3a8-889c-463b-0a4b-08dd367246e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: ZIyvVs2kQg+k0BtVNPjo9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Pa7EpMG7ufZXqC0Z2eLTfb9xghPE1JHmW4cH+8DF7WJ7OzmFq7mRGX20/10vCrLujmgVCXsanAl9Yfsh80fNLqhN9moUWiY8SJzbYsS9GHCiMeJUm74q1gIkEc+tJwwlHlh0BXFu6SXWPeKqN0Kg5g8/sgy43oRqxWnArFu6dJVjj3jke/HvbAGA8PVlbNscau7tdwq6jT17JzDTV1QUlr5QRXqELPMvNH1OHv9sZRIKQ1yKH8wb6ftQsntdVXaTlvvE+4R7aBRoP8KYJpp1MoQZryyMTNsn0ASMqL1oluTz1 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: H6zJzgpUHKBHy94nHFVv1WvHU98VOJrvjF3CAP/v6rs6E+OTbc3dPukIFJraiG+l/GvghpCOJP7ywyArHDkAwO2/Dn2SpwzOmNTLH8ywjtg3k0iBey+xXlz8GRFviqS4ZypakirakwO5Zj2t8j3faF7qpnzrbvRIpJkS5MkW2jGTa/GLWJ9vs9fSShBbNBGGKGocxmF8cBmkCsJhmnDUuJ1WUeL9dR2DLTVdRQCBRBKtKM1eJ2m8kTCBi5OfGQTLa1MlGH6TyPc0su/WyDBan4kpa8jJNWr/ctLfCG9clzuxdNNsjngFQwU1QzCjSUKr/viYAqLTjJ6CcUGFO+yhyGeyIt6Y2eBPouCX4OW4ww+H1x+Ni2lHafgRJLXjVeBqo+mFbD4M/vPA78UDF1YbBMVVXn1ADUByRSHnsp6w+rhj+QkSvAUEkPj9OGNZ3thuwW5VWE3+1NMfMEQI2wfRrOsk+ZP/jLTzW3bnqADWBzvNAuVGSU8SgGqoTekUmkiCP4E5RJwimnr3uuDvYsIrQm8AGHrZl0Eby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vidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31e6b3a8-889c-463b-0a4b-08dd367246e3 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:11:00.1005 (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: em1+x8C4SFFz/yyuD8jhgd0irSpTwR5G0K665SkkIHG6MQ3Yholj7IB1QPn1gAKE X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 899D220006 X-Stat-Signature: 5w1rfkkdcrzx5nn1e8hrfj9hr3fu3rcr X-Rspam-User: X-HE-Tag: 1737061877-863566 X-HE-Meta: U2FsdGVkX1+LzjgjpYKvY70YIG4adP+rEBb3VSU/gwzk6okrJaGYS92xzoc6hZujebxTzSr6pPGHwJgsMPVQaKkKE9Ihf2B8w2+v5i8uvunHmTs3BrkB+6MRaV9xL7i6t2QovmNnI+bLzM2Fc8c/fIKmZMm2siAaXH/Ea8buxSRPHKJtynkgg6Pf6xlcHMrIW/XuiViLlML+6+PdVBwLeKxEXBeqo91tJh3RhOUea0/zqc7LETCSdIGnmCiRdAxXuYN+ydJMZJDxzTu6nJAUgJylgkSlV4hOtc41lCAC9iSUoVW7/n9jBIYqjBxPMwA5jKKynwFMg4+9BoEcpMW0TSkXbhHrFlYOwqvUho9MsS6eC4fLrGJvEJ1x+V3vtOQBIFNkK/Iogr8fS8975EoJ/PfHcxHXIZhCJ6eSadG8NxAnTk0+sGZjUF1DI9EUoLBXHjhQi2vBAh/QWLd0jRirUHiosljH8BaNa901QSrAxj2168zNsbQeM5FVAia2GIMtLXiLxtc83Iq+UqpqUXnhLFOq6NttbfRi+eG9bewd/5d1YsHlxNwQdgkP57caDt+ioYBtLuXahTToEMLb66hukeIZ8lNPP7TECphid7bm8eUIOmlw5fxcZdSX4QdfD/noIzBc2b3Q7v+9V80J0iv9nbSSTQdkABXAdbbwEb6oJblPfQm0M8QMExI5Z1S7TSJcEvbZi2Ihx6tbWM4Iq+Ws3uSNLED5S7385x2mnLMvBWwjuu5O9Jp/zFtUOR2ZjrMLWsXBR2cltRBjMl+Af1zIYAR6a4/8dGsGyXVSonjfMuGvMGPYkfu7LUS99UKxdmABM3c1JCVO3ffze2JfDq2g694YFa5f7ZtnmPhsKUrXRJbsdDytPvtm0OZSSAKO5HTGTn6z6k6Y2oTuy4f3P5fqsJvGyvedNpvDg/PyOkaNhzE4dRssxGilkqRNR8jvvb/iBhQ3lD0xo4kxrApyLlo u3EoqjRu 7w24V2oSiBss1XCKXkopi3Fqub1vsOFnUkuBeHgi4+wiRZZzNurbDCGR9VngY/Awy45plrTuqSWxbHLt33CnmCQXWShdEGm3A2B/+rM5GPB8XvBUCPy2NVmbshqlIYaheatHj8qYqaYC3MqQ9Dv14LnXS5w4U9C4W7eLVw3VES77KRclw4hOoywVXAtxHlbW0I5JQwI9N8av6uvuV00/1I6YsIKZmjOAkeGD9TWk6qB7mqwHPwFfwSvrVJyxcf+MDdNj+FFAEigG7puODlenegRKeObMoK4ZdnN8YnFjHfglOKkNs61dFtN3d5aybGShQUPxerl1oDiA80CKO58qXndigDr7XwDeEUxEOIQswRZQ5+sPVaWNKrx5/2dI+LKsljt8QVBacom5RavU= 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 __split_unmapped_folio() using uniform_split variable to distinguish their operations. uniform_split_supported() and non_uniform_split_supported() are added to factor out check code and will be used outside __folio_split() in the following commit. Signed-off-by: Zi Yan --- mm/huge_memory.c | 134 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 37 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 6c0089a0bcdb..d9f5ca61d78c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3738,12 +3738,68 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, return ret; } +static bool non_uniform_split_supported(struct folio *folio, unsigned int new_order, + bool warns) +{ + /* order-1 is not supported for anonymous THP. */ + if (folio_test_anon(folio) && new_order == 1) { + VM_WARN_ONCE(warns, "Cannot split to order-1 folio"); + return false; + } + + /* + * No split if the file system does not support large folio. + * Note that we might still have THPs in such mappings due to + * 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) && + !mapping_large_folio_support(folio->mapping)) { + VM_WARN_ONCE(warns, + "Cannot split file folio to non-0 order"); + return false; + } + + /* Only swapping a whole PMD-mapped folio is supported */ + if (folio_test_swapcache(folio)) { + VM_WARN_ONCE(warns, + "Cannot split swapcache folio to non-0 order"); + return false; + } + + return true; +} + +/* See comments in non_uniform_split_supported() */ +static bool uniform_split_supported(struct folio *folio, unsigned int new_order, + bool warns) +{ + if (folio_test_anon(folio) && new_order == 1) { + VM_WARN_ONCE(warns, "Cannot split to order-1 folio"); + return false; + } + + if (new_order) { + if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + !mapping_large_folio_support(folio->mapping)) { + VM_WARN_ONCE(warns, + "Cannot split file folio to non-0 order"); + return false; + } + if (folio_test_swapcache(folio)) { + VM_WARN_ONCE(warns, + "Cannot split swapcache folio to non-0 order"); + return false; + } + } + return true; +} + 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; @@ -3758,29 +3814,11 @@ static int __folio_split(struct folio *folio, unsigned int new_order, if (new_order >= folio_order(folio)) return -EINVAL; - if (is_anon) { - /* order-1 is not supported for anonymous THP. */ - if (new_order == 1) { - VM_WARN_ONCE(1, "Cannot split to order-1 folio"); - return -EINVAL; - } - } else if (new_order) { - /* - * No split if the file system does not support large folio. - * Note that we might still have THPs in such mappings due to - * 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) && - !mapping_large_folio_support(folio->mapping)) { - VM_WARN_ONCE(1, - "Cannot split file folio to non-0 order"); - return -EINVAL; - } - } + if (uniform_split && !uniform_split_supported(folio, new_order, true)) + return -EINVAL; - /* Only swapping a whole PMD-mapped folio is supported */ - if (folio_test_swapcache(folio) && new_order) + if (!uniform_split && + !non_uniform_split_supported(folio, new_order, true)) return -EINVAL; is_hzp = is_huge_zero_folio(folio); @@ -3837,10 +3875,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; @@ -3905,7 +3946,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)) { @@ -3919,12 +3959,8 @@ static int __folio_split(struct folio *folio, unsigned int new_order, } } - if (is_anon) { - 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 = __split_unmapped_folio(page_folio(page), new_order, + page, list, end, &xas, mapping, uniform_split); } else { spin_unlock(&ds_queue->split_queue_lock); fail: @@ -4002,7 +4038,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 Thu Jan 16 21:10:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942313 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 3A922C02183 for ; Thu, 16 Jan 2025 21:13:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0C9D280009; Thu, 16 Jan 2025 16:13:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BBD08280001; Thu, 16 Jan 2025 16:13:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0ED1280009; Thu, 16 Jan 2025 16:13:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7E298280001 for ; Thu, 16 Jan 2025 16:13:18 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05F20C1222 for ; Thu, 16 Jan 2025 21:13:18 +0000 (UTC) X-FDA: 83014565676.15.72FD8F2 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062.outbound.protection.outlook.com [40.107.243.62]) by imf06.hostedemail.com (Postfix) with ESMTP id 353A218000B for ; Thu, 16 Jan 2025 21:13:15 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=iJhc1Wsq; spf=pass (imf06.hostedemail.com: domain of ziy@nvidia.com designates 40.107.243.62 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=1737061995; 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=dOqylMIuudUNGPgU0fB6u1DImPM4IOntSMTYtCzMeCs=; b=p23OYKj43BdEFxuaeJr1465KYuNqz0VmKVsA4UrLJ/9RYqWSvvEnri05ZHQ+Vw9hO2Rt/M y55zqateuorMdXaskCTEQXWFdwgrQ+IaO7KY7RaEcLO/NZ+93AlBfmsbc1R8tHmkVHPEJ3 xbm8bAHChVJHbsv7tdwvyC504hRfZwQ= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=iJhc1Wsq; spf=pass (imf06.hostedemail.com: domain of ziy@nvidia.com designates 40.107.243.62 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=1737061995; a=rsa-sha256; cv=pass; b=62kpssUIs6MZsSkCIFg9PY75gF1zQJzlq0AKz6yiZBnjkO3LO9XAfaMlIl3miDP/Bd1xxD 7Lic/j87UVrqKU2QBbsGuEi9TM470dkenxVqIu5RTFC3TngGRldDK3qHYU+3C7hYBVSf6L tDW1J1hbflmJUELdcZUasnjmg+dYOes= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f1A+g/Cyfm3Fo/aTnxoUqtuIalPPP7LkL6fmrZ60snSzGjCRmxnD8RiEkmudre2fR+FBhX71saUdjRIvypN/K0NBZswSZ+WvKCeH4IMicpbnom/eDOpNGQ6WrHaSmEs3jMa8nanIbvVYgDDfa0exg5q+HKL6CSLwTofc16v9VM2iA6kdV/XT2Y13ySyoAzTzkOKaelu/7TosBQJT0kOyV63dgBEgtmv0MjiR26VD1Pllt2NZZTXWQ0+4cHUk59URKniZcitXcUrdUup51nrG0XaxhAG6Bapo/1hIT0MzQzAqU1LSg7PoUgFKwo/dAohyUgn5R1wUdAXuPOTpcrAcBA== 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=dOqylMIuudUNGPgU0fB6u1DImPM4IOntSMTYtCzMeCs=; b=SNFRVRpPCpxTg7KRylbNKLPqE+xxpS0QDsvohkHo196Xi40edFw+IqZsTmKfOnszaC8DwJKYBWib6MMyxVsrBb5ZfwTKRn6WxTcBmUu5WvkHQLvIgtG2ihSu31b3YStyw9yiC20tx9iXBayUcDJhsCEkfQhs+ol/rcWq7Ot/6YQ8yCZXv6kl1HstMe0be1oL45XKx7ILUH4ct/gXUMri91JasqSHXvQdCRIQwAOUCEsL3HdbIazK81f6Qd0+KcZbOG4iUNo7dmibK2hGRetp1ek3ShKX6bgKiJEGczn+HSehg8kIfxRhv9VR61uJRyXbQ8iDeeRUFXjPzD71DlU/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=dOqylMIuudUNGPgU0fB6u1DImPM4IOntSMTYtCzMeCs=; b=iJhc1WsqGJl3QUeUE9KPJYoyhqBiOJmMWOsgBzo4fj+aKrq+WpQx8Z5Xq+t7xccFbqY0KoNpb0x+KumOLP/nJi0dEvbGqmk5Pfq8bTmTe9BzSF4UJb/iBmeyZkULjLctdfLAGGATzzXtJY4COpQduN87KR6pQRrThN18jhQJhemj12oM9dvIMfGnRBKHRYJO+wQbe1EBN0Y8xFMpzvcYDnKA6YLWynWCU0NbvTnRPr1T+KM4pn2NkNfHCrl7Ve3wVgSLwS3UBDxqUPFHl6yp/jcjQhC1u+7SUPLPoVXEEgfaqJvg7U3KTLK11KbNnYJQ/4u3tnjiZCxmAZj5gEfOZQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:11:01 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:11:01 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 07/10] mm/huge_memory: remove the old, unused __split_huge_page() Date: Thu, 16 Jan 2025 16:10:39 -0500 Message-ID: <20250116211042.741543-8-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: BN0PR04CA0022.namprd04.prod.outlook.com (2603:10b6:408:ee::27) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: 0887114e-ab42-414c-bc27-08dd367247df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 7wz4c+IEnmhMm0/HWlAeVoInSzarIXxxIVi5okZg403MXOJXDcQyXmAu5+BF8gpCHWuYOnmkCgBuNxnTLPT2Nd/hx1ey10eyfRkgIfVcAjm/DXNpVQPEahT1zPXzw3UmjhDBdsI+jHQhiG/i2EqpLq43Hgkel+cxuJdLq6+w09JyXMxGy8D1KdfVGptArXi71nxt5o3qq55TfL9rm9Atf2j7JOAS81YnqQG95FxU2+QjLcs4Gq2ONw/FI9ePveacznlwgVEv4cU93+0cFqHf9Mi8oDAqNA8BuuKAxoYD/azkN5HjIve4D/L82pc5jl7eNCPyL9U3nEtrSBaoEsk087XeMdyM7nkeDbJQerLjde2lp9XaDBn7LWaP+bSmUTp0oW7AU3VxQWozcarXfi+TzHYm75szQJwaUdJ2TcBmRrr4pbSfTFqsSsDC3+YcwRnKa1EJIuHjEiryK3QhQK24jOWj9TvopYtpo7UfnJwKBqar5/j0Y9t25ZxEoo+bs3HbZ9FtcovrnoCW3vUVodVLyOCMJBoDJyQebWryltViOPxH6EQRMRb/kngIWyogpG8DtFBeDetVKtXilltz2ypnx583mW/AergdA0D9+0RHaisFFReQ+nB0ZhQ0fAVcJQdsUONKMpI9YkvM584tw0TULe4reVGpTNQ29dhFYjkBjohe4maHmC8qNFG+7HepvwHSlrxfJePrXUKq/PP13ysIH9psz9wr0QcfVSeptS1wn3+GJIwBQlrv/r15AvfbJQey3uNTm3NxhXjIJHLkzYM/IWrVJQE/OOIvmrzVVGv6+qiYzWQ2SMvxXjzd30ldqnh5PkXwKpJ7tM8e3dN+2fQFriP7wJHiUiUS6kfa/Sgb82uqaWD3KFRoXfdn0mD4G5G6fgL7WlSRumdpWhpJsZUDQC9pRnstCYmaQn4R4PVU189l+qPf8dAdSrxJ7qxV2EAWe407w0s8wwT9ZKOCZRn3J5C48HpKaebDxngMtRxtQxtnL96y/tWOEbfZq4hh35oQN57dRg0G2cKhIIMZUviY19PfwvYMeT3RddrahwcPD5eQKq2n5/0tWwyB4dauCRwtWddeZc0eaa2YFUJDDpl3BZcZ6YToRnBkkq02PD2oybrZ25JQlu6HOcrM0XWhF0hueu7GKWlxaGR0D5pjs86t7K9MKNNtdcnhSk+1Bl+dkwyt57cF3D1OuTkbmJoUlbrLrMaBV4hDEFrqVm5RgvnZHrJh7Q+bJoPpdjTzyrUXieE8LY9qdgwL1UL9tWyocY3JjftrA3LF6pa5Ng0mQ1Am/YfHjwJ9MO5BSTitdNRTPlE5/dZE9lc+MPJ72iliFf7yUZ2F0JJKorLR6BVI5dDX+rf+58cIV0IbnweMRnsQYtah9O9iLm33hg24W+PMuiWP 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fEOikwA2HHd58CXC+r3iDUhtrou7NjE0y+W3u56Jk6++vcgOMGo7E7RJFiV2ZHefpZncSXJzxN/lnZelSr5mUmoZ+z8SpAyyUzRBq5GVC4Nvk0OTAmvEeqGz/9llWQM9P/VcxVKxa3GHZnOvn3qo/BZp2BjVKLMcgenHaE5sPsNqUO7FF9UaQyo7/jdmYi3do6E21P0hIATTYqamJ/Xxe+BqHXSzg4WQKJEUGV+Iq1si3hvV0mPAu6YMlv7YS7YSkYrPA+ApL/NXY4bC8JmBb1CjID4yD/C1CpNvBQVd8gEtBODL82UnmBq0chg9ddwEoGD7jnsAWXIrOjQj/hiLu7bU7Ge3p0/d0DWezESilMRAap2ZghF9k9c2us0ePCeDPqOwqYtadLyOXUiF5SNM7tAJm7bpNP62CCui+01FMgOO7C/kIDZ34QPZBxCH/4RAu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WTcsxNqCQq7ZQELbgj3XWPOYK6R71en23SkJUkfbADNCsqgAe2HrLQbyVjMw9ktHbPvihF X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0887114e-ab42-414c-bc27-08dd367247df X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:11:01.7617 (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: d2vr0WTdj5VVU9RQDfYQT3p+iQmZ3G7GW/Wm6lqbivi7B1nEKDBTCGBbNvokaYPT X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Queue-Id: 353A218000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pz9a51yykax53fehuzqu3i7jbp8i93gw X-HE-Tag: 1737061995-890796 X-HE-Meta: U2FsdGVkX1/C0wYVYmvE2rgYs8jbQ7byHY75TlNzwwMgChSB8igCg90Cdl4XaQUbHY37XejOTsIOvzg32xfK9mzJarAZA1++s1Q5AwKK4pRl0P/z445t5HRSS1CZ+7dyggh+ttK3nBcMB80Vzi9rrEWM06elgHluqDfacG1mzJ5a29by/PhnfraIeiztkcKJPR7Wq6IqEPBLpXHsXP6rPcTSU6p4Q9GhSU2ISVe7+u0UTo2XAws9DSg6HrhS/fJEXBJm4Qj5aFa3HFvMooYvBZLvJ24iMDv9+QTuaiceSQ//IqI1aVGHXdNo6xCc/prRRxo+vVECdOXPnBmrWIUZQmjN3w7+C+Xp2YkV4W9xPIJlkS7U2WtFTwE38YAqMEmNTppjp3+YeHnCR/Mv8pYcmLs4D4cevToJRCSZV+hmfuPoD4/gbCtIEeu3Z3VBvtuW2iZ+wx+QXTGjMtditVptb94LJBB3VXGh0B6ZK+WqZz0NeGUlW5HqJ7ohVLzo91+2OEJro3v+xTWZria2mf5Rh9vuxnybKTj/D6DqkJvbiso43qmnh2o3zAoR7Oc5v74S8ZkOtJPeA91tl9LdJ4gtUV49nAxdSlUzsomLCFML6oil+7EztsMh8NDTzNXWSDO26gI53nfM6AGGTBYUeDkm5k5u8oSDfVsjfdOKrHRxrGIra7mE+rx70jSa1ZWU/G309tlEbGAi301r5lxOP4ZLa31LSLSM9//RKD0xsVmeqfBU2rVs+3IJBIk2RJ2z3bw13+Q+4S+9jCGXr/9jZyWiLKQr45R1mJkcPymtXlRro0+XU7/JmVP2/OUtlAtfv6meHj/GbQKkbdJC0Xfjd3eOH80VqzumKxopAfLlnBTlk4SQWnnau99awIinVc/f6zPxrPgvYwUIUOqGEm9iNn2+SurJeSTpFE4xvzlsnYGqGuyK6+FvBG1b4YHV6vfW9ItJ6BNe8k6YWqTDg7MctJC SkLXKHEt dtcez+o2o0gAukW0X3r2Iplezbq6UwBAxeIkS1fvMevk21Gzy5cf73osDHbPA22fSJzFiZaaJvX3eaZI40Ssf4e4CWsBA4mbtzmoXNeJdkti80TC8rmvC2cegU1YC8dTcpQp0fvj36HaEwHPPhtmsFvwciKf5yZQ46L3YSjOG+k5y/sRUD8vctV7qqICNODwiCCFTDWsktLyDjPENEYWaJE3Yyx9iB27dauyOari3L+C81BFrXAp2R43SPSlaQ5L501tQb7cgJgHIFc1WECTZZReUBRDKtASNQc9pHgrHU+rN1xEkZd8E1m1AnYvAA0Q9fULC5MwPYL2brKgVRda9Z3Ka+C2OkncOtTCw/LimNOuUfwuaoFOY/Xpc5Hu/NlF+ysqjuTTthtdbYoc= 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 d9f5ca61d78c..2fead9586e34 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3165,213 +3165,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); - - folio_clear_has_hwpoisoned(folio); - - 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 += new_nr; - 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 Thu Jan 16 21:10:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942310 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 22E8DC02188 for ; Thu, 16 Jan 2025 21:11:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3A3D280006; Thu, 16 Jan 2025 16:11:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E748280001; Thu, 16 Jan 2025 16:11:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C42D280006; Thu, 16 Jan 2025 16:11:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5D606280001 for ; Thu, 16 Jan 2025 16:11:39 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2143F1A136A for ; Thu, 16 Jan 2025 21:11:39 +0000 (UTC) X-FDA: 83014561518.07.8EB6DE0 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2058.outbound.protection.outlook.com [40.107.237.58]) by imf12.hostedemail.com (Postfix) with ESMTP id 54FFF4000B for ; Thu, 16 Jan 2025 21:11:36 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=TbPjbINV; spf=pass (imf12.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.58 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=1737061896; 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=h01OhGP49lQnm769uOiJuw7L8Wzui4j6wehMLlbisoE=; b=8cT3iDepq9hUnvRFglU+LbOoJCqlU+n16NRMCcaO1veOhUuEhUaf2ai9Uyqi+fPCDP2Q9l xIr+38LCfuoZMiOfz6sBLhXf2P3tQetLLzq0KbXE3wrLNEwaJrQLc3AdRJ4/UnHHp3cvIw gR+RKJhmcjsf1Nx+DeBHx0ASa0ItRNk= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=TbPjbINV; spf=pass (imf12.hostedemail.com: domain of ziy@nvidia.com designates 40.107.237.58 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=1737061896; a=rsa-sha256; cv=pass; b=rA3YJxbrSt4kQmQz98G7ElpcYLFWdmYq024dKjpADNLKi8qq9pYzT5YB9+DqM/wv/ETgll Jd28osXjtKRp2BcRHhbJNzIVotIpMzuFN4fJIUUUjs/bbtOnlWKpkMb4C9TAyLKLvbpKJc moTT8N/DYKbmksHXG7t5Z4XvCahsgXU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qvq98UVtYpJaRAUzrtb1kMwVA8DDp/iHBzX0GZsQ5l/NoVM4HLlKZeMWbpU1SbOZRLrBd15yVIRxl9JITcRzVvTuCDZYf+wuTqn4XZw8OUfE4Ni9K6sKTDxt97c4PhA3Dxo9k5FPzSetzuXWovuEFmUv6ANtV85wiDT5s3BzkARo4UhPhSa61MaY/Y9aHSNGyieakU+CjSWoAbLnTCGFVbq3y0zJvViXEInmttKkwjBOkPBnCiSU3LS8A6SCWW4ed1+zutiv5zFbprfbRWVN+nyNtJALMIU0WW2F82qdss2jKMj+8wueB/e72WtZMjzktOG7FijiEA8hbmnX4NxZaA== 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=h01OhGP49lQnm769uOiJuw7L8Wzui4j6wehMLlbisoE=; b=H20IKBnl9klOvFZDz9AN5O08ym2DvMlVVMhJiB/w14/yTVg2G5aIudsAxvSLSJ4FKKaP0nCbRMB3RB6CnR/nzNP1XFmN34OicQ9b5qPzGPj/TKLzMe77pJV200j3VJE25+S0qCiJi8Yo395VUEk7x4N4qeDTLWFNYXU7SeSUAjf8kjteHvGlrIcpjIgfgSEOrlLdPeWzpdG4lR0lDkFxDkhJzg1/LpjuaBtrfWCdCUOv+lpdREDY+NAl3zbpM/0YPCouV2AJ74TqvKXr73FymqJfyeY3ke0222GOC1iePL7fMgvpdMnZ3bP0BLyk/JXTQQv+dmTshyGoJeJB4rmRXQ== 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=h01OhGP49lQnm769uOiJuw7L8Wzui4j6wehMLlbisoE=; b=TbPjbINV9rOQcTfwXBtgHX10TDxVpjDksG9hWRZVXTmqk/2cpBEVUpd04N6CMnzvJHh6lxQ4g6JGtPUpLvifdtudB4+en/jkettXrnzuNfnKcpN0lKOrulsP5zlqIGcPolyyo094/VNlI22MuXi4nnY2PiNQhvQnOqLsaFk04EmpWWyTeuvI02fgnvQdNov69g1AGBe/ZkXCUGjIsG+kT4dz0PFq77uJ8gJ+anGY0iCTNpQPZjqHgLAmXYl9IIfK9AjPc2mvVRBM10dn+zB2rx6pQRBASUwI1ylqAvNDwSGS9pESZ8scCrA5QaugZ9FZSYmHxVrv0GY4TRGwY+OhFg== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:11:03 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:11:03 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 08/10] mm/huge_memory: add folio_split() to debugfs testing interface. Date: Thu, 16 Jan 2025 16:10:40 -0500 Message-ID: <20250116211042.741543-9-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: MN0P220CA0030.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:52e::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_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: 755fba17-0045-4fd5-ea6c-08dd3672488f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: tcO3ixMNRM75MPDvE40o2lCnuFSMYL+EUCsif9Y1qsGYu18eME+JhcY3ht6QYaa1Nc7rkmKgiGMtPtsYzqAOnwBN/mCL73aRSODE/isL+acULyRvGU1j1mGLnlW1t3bDP5wFm3u0/zso39JAN8OmB2EJPfz4lz4djf80VaSshzPzvM2Kh/e1oPIIcLcteyLCQADGsvDNAJLxFscYUo76RKo+pKeVjGDh4/LKfw60L56vz6JecGO5RLKyMdI5xJ+tkl9952D38fnJep+yjXZvWhPGOOf5bxhQ7CSzvxHBnL+kPC6Gmg0P8Yi0tDh53pwU5pgihuosA4cX/aB9uFDrc2DrFVe0Y/5QTvgMzJs3YB6CduSe33tFKghHvHpgrhBg3+khJ4WWpZeqr1YXP8wAdF0XQ3FuWCs1tra5eh0YhTZPaYAOpo7aaGoFLKwLzbDZ/7tYzzTQGco4Z8VJ6eGFaXmkiRBBr/Oo41TuiAAYyBw0LTC4YLNvpmzNZkjBQV1pqR8QABgRzazPVgZnPJlS3wGAC6fo0Q7sKeXpcP9vuPYb0Jdn6zT5aqJXdbqj0vTD2r3NOIFGeJT9UjApQWLs7kU5QhfHww63a4SabJHsPnhpGcdX7ISw6pp2QeAFDJ/Nj+CJDM6J52CfUzwcyLlS+a8dTiv2Edhz4oePpwJvxFvKpSk+aJxVqLHCAZZg3yogrp0v5T4D/I+rxC+suxdQYSFnTw7cIKYm72gKNYByGmXSqEsNEM610lf+ZGb2fOd7w40Ka9yzlgXttAuu+8YfNSiZLfPe9WuUuCPgA1abAxncG4yBcFxqQwOikBiIL6PO7+FzanujXdnoZTOT5kuNplKU/sYgDzj/L/93UckIs8bJtOMV5N534Ylmzk3C1MmS88+3NpEAXKO4xWiuYK97cpdPSed8QWQ4+7q6Q0f32YK3X1lpu3Rd/fFqec3m4kfGlBKASMTlmGv9V7nfN5MVMTizJHQIWA96rDs8g7N7hpeklskk93NPym8MYMe54jkSFjq1O5FEtQVMIuBNFrgiliOAgb7rw2QjyeIBTWd8NJ0rAVL6wZevucw2cCDtU4EIv8x/OEOXvqzt9x4OVd4umVEz9K0PyU7b19QbEb/CwEr/SSYAc8ke/OZSU7R7Hj54/pIdm3Gm/qymPWh5HvGlPKe6cuZ96cuk2ZMvEUaOlvO8vY3ZS+UdRIhyFCsMSxdSduRTi04ZgrI/8wNQsbnOYWbQ4MrJooSmIDITpn0so4U7xNPD1Shgp7OrlATxFthUXoM6N5TJUgL0Udxlxa0hHvATaSxY7k/qzXp6IFldJFnEuAq7jvbNi3Lk2Rlr0KouiPLmZ2ONLG27P34yuv8pqUWQoLQQjq/g5biEx6mYb4Bkv1ib843kwMNNvxto8bDB 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ty1uiS/pYo92UUx0gsdBNfg+/NU05IIRLoVbVJS4lTDFIS23PlVMpxq7kiOENCSxYAOLaknzSqYKhBJKNDHp8ggUCRcmIjVT7n03ywwhzcaaLYMf0AqVx5/GkLz3OjKaW+BNxZpZUuYhrBRlFQU0OB7yCl6HrUKj9H2lyR/0VAIk9Rg80NeFfh+K5xFblnrejpirrAyjApDQ1yq4WhJGligCFM2AWJAAtCLpLaYP0HsqIe1xtDp+ly014ZRuJnVENT5XV/4D92sOxYf1GiyVjrhQkSg9QS+FzoYiQ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TjGIt2EkIXMXqrQ6JUvUu/x6K6LqEhAfzNoCRXclShyottl1HpFBFK9BZ1Szj1LCvrC9IMdtGzxNsMyKPB3eSm3J2F1a5Ljjc9JFsZYiNBayo/iHcUXkPkmP1D/4g0Od7tpwnSAZGClJqGHd/g5UU19LNbwwYnx1+zfdsdZDt5x9JEL3bHuWQYwRl7ZOmS4joYh77LuKPJUGB7rX9xj7ZXxw3UBpDngOtdNMST X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 755fba17-0045-4fd5-ea6c-08dd3672488f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:11:02.9270 (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: nZBE+N9JfeNqM3Meio58wx+0mWTBWw7tJDWMZeLwqxe9Gay6SQcNKJffVnCGol2o X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspamd-Queue-Id: 54FFF4000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5zgd33kqxbqs1wzfxeo7pxziihw144q1 X-HE-Tag: 1737061896-904651 X-HE-Meta: U2FsdGVkX19zfxsrvQ/DkRXya3xGd3crxv80N5jiihrJyDwNwfDeMndoZsL17HFpE6kwJy1B0WAbOH45T8mQ0ItstrReAuWqeeafi7JuV18MSeu5ccA/fMzA9dJn6WWkrtGRuywsP2UNV0vExJuSRW2IBP4PKz9njo9ECNhfD2xsWTIk297v1cy6okIYlsjOOa+MO9L/HsAhVBm5cDImH07UjfLz26uCSBD5NCRnIrmY+XiiwFs2v67cDaXQvf8hAEwHnizn461wo+PW5vWKNnSCZTogJR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ED8af2djcbC4WqLp3JVTP8M2DOVJUA5NOU= 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 | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2fead9586e34..ddba3e36b46b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4177,7 +4177,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; @@ -4261,8 +4262,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: @@ -4285,7 +4294,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; @@ -4334,8 +4344,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); @@ -4368,6 +4385,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) @@ -4396,30 +4414,33 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, goto out; } - ret = sscanf(tok_buf, "0x%lx,0x%lx,%d", &off_start, - &off_end, &new_order); - if (ret != 2 && ret != 3) { + ret = sscanf(tok_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 Thu Jan 16 21:10:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942308 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 51B46C02187 for ; Thu, 16 Jan 2025 21:11:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBD15280004; Thu, 16 Jan 2025 16:11:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6CE6280001; Thu, 16 Jan 2025 16:11:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E624280004; Thu, 16 Jan 2025 16:11:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 80786280001 for ; Thu, 16 Jan 2025 16:11:26 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0E3BE16129E for ; Thu, 16 Jan 2025 21:11:26 +0000 (UTC) X-FDA: 83014560972.17.5B713D8 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2064.outbound.protection.outlook.com [40.107.236.64]) by imf11.hostedemail.com (Postfix) with ESMTP id 3AFF440014 for ; Thu, 16 Jan 2025 21:11:23 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=duZMO+BB; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf11.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.64 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737061883; a=rsa-sha256; cv=pass; b=mLU9e2mzJkgKmoPpFxVrquXQy51e16Z4jouBUlwgtjzDOAgv6anwH0NXXDiCev4FW1zTqG 0Cfs0DCu5sE7vuK6TQdyUQL9cqqN7UE6JmL131kURuXY0ZSLhYQPs31XZZ805aNjPwNjhg P7XW4sk5mdSYGo5Hctt3HNqEqwhA0A0= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=duZMO+BB; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf11.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.64 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=1737061883; 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=T6dN5S3nRphg4c7HTWzXe7uTKVAHTiFZ5ttyec/A78c=; b=6rt6aPOQTdiGVkFK7PdER/SR7t03RfBuYpQMs/15ZvjxvtoYanj0/v0td9FBXkYFwxKUi5 QE6jGnouOoOOXL4QttdH/WVRZtKT32mhIpNJjhFqh/snYdwq4AqMEwQhLqVPSqk3vMpEoc CXB7mrZ7xiOmB2qcVg5nc+bkjha9BRM= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lGhSGYmThYrb20lplfb3yep17uY/QbVcEUMA6QX3ES+G/yfrMtG6u8TRrbiZsc3pzF63tHYJZVRCCJ7/uFKBZg6UWJqtLYmk78dMj3rlCnKfkeH7Ox9nYhXd2Xk76Aj1iZjxt/swhNnVJbjm635Jn78rLJIylhGEx4kItzw7lxnzyfWvRIAS/zEoSGhD6ZlaGHACJuMj6ReNRvdzVZr8lI6/rKz7LKv5X2/021NLHAXEdZLv3LVa3iZ38Vtivsxe63pMYgieJRyN3o4c5lXxJzhBu9e6NbYVDeQUDF08Y+PCu+V0p1yszPrc32kyn1SS/NPnSn6CJq5cYZojvuOOcw== 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=T6dN5S3nRphg4c7HTWzXe7uTKVAHTiFZ5ttyec/A78c=; b=y+o0OGtYpeUdwa7CkVECq8DTxlQ92J9Qi4K4clUjaDH7NjXXRXGYgwsZJdIYlPVt6yQjSDhauY872JMPLzBa+Sr2ZEEUXL8udyh+loOATo0IMRTX7LgzzHeELfvKFEK82wu39mLYq5zlCFfyeXV0K2Lp+fwxZ8+OQ+uG4GJk6sAQfzbFqRquSPN+UlZFd65yKSqKIzZSfJWzyfGf5ip6umUqIKjOZLN9ShXyJgmyXQeM3ZEF/VsIu9w0HPfr6PnrSwBVn/vO8vv4yX36Eq30xiuwPe0gIRKZb80pRAThiszvrzCQ9HJpHl5jmLxM18V+KvEZWTWOXvl8/pN5GV/XkA== 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=T6dN5S3nRphg4c7HTWzXe7uTKVAHTiFZ5ttyec/A78c=; b=duZMO+BBlKLq3b8HHljzmXtjV1oaI0XJ9jCCoX40YHcnhWcjmwNd/6ekLMGeeDD+65rkWu5Yy6xsL+8+YXNIARD/4BWKh1pOeFPGQE3xe+lMemgRs2yDgN+XRLkG7/Z23b1bHDHkwQHx0dON1T84VvWT4TAzwG14JXFI55JFJx74fPa9T10uLUgj/gRfSEiWMbOm8iycSlIvgrFcazmGsClnZnu/tBa00DjFEkqME+jeQg41uHjMrEX7bTwxMdzxpRpmIwTR1hYsd+903DDH9BH5ZxJS40KLjt2aIxCgiWlsm+K+GHkpFW2LrOqLLhVNpviKataInM7gAFr5wdhIrA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:11:04 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:11:04 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 09/10] mm/truncate: use folio_split() for truncate operation. Date: Thu, 16 Jan 2025 16:10:41 -0500 Message-ID: <20250116211042.741543-10-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: MN0P220CA0025.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:52e::33) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: ff17b66b-d95b-445d-6d81-08dd36724954 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 12IiEFxlki9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FBN7X0EghTfWwP2UsENzDc5fkekqwJnih1QdOeiPS7CsXRi9evBtQ2jCq0PrPlmSpn0DKmuxFSiSQNzq4gLaphAk5YWp6yCs35Ugt7GYsFCSeSWzHU7OZF8tlq7eMysSSpR0i4UF5yX7JR1HwE9ubz7doYkHulBxUXrSyEBEiY1BaIsULkVtMjn7tjGT4SAy0k0Fq/hJECd++0v7kCK3Bh5i+5kVJDgkU8ejozNNno+bS3V64XKnofP9EJgdgY8njVc/iwcW4GSoowKuusFBNzKU2uiA 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Aj+37zTQXbfX5cLSDo2GVm3uQSh8cQiKvCV2JMjP8Zi+5oL+XcFijwzckiP7M4wlgvsLwv9Z30Qsr+YmP87hbaZ+YauT93J1z5C7JPVmecnldyU/nSbN0Djmn8qdOqRsRpeIuL1p/l7m/9lCQsnTR8UnRFIiZe1KFHGywMyMbR4G1XLO5kquxGklCpwZpueJu6lmOBwPeKGslstdOt/9KbwS4Opck4Wq7B9xMUFy64QMMYTbpLLR8Pbu9wRf7WFqLDLgUmp4L8rLCt7r70aJ/n0RynBT7FOvrXJilOZh/ZVyVKOVZclv4eK3aCiZSuLe2V48KGHbU0sdXWyIxdrp/l1PDD0P8KGDZR3For9A//drC6q2Gjsyq75m4DU4+Bw3jIxpposylx5gkxpuqJgdK/tAwWLjCBhNA/2k2x6YsM4zI3yLPE+2Mw5BNW/X/MOC2tWhv7I32K7XEfGyT5VD3DeI5EzQVkwK5PPiScv3adPiekV4QK9s1kMm3BYQC5mtNvqXVk+Oz4DvZ2Q3xgim5jPC6lDXRGlIUI7/wt8zealtYLMXpB9DF1fKpCL/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17b66b-d95b-445d-6d81-08dd36724954 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:11:04.2194 (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: cFM1RMLo1XIDCs1olJjtZhE0c/D92WD+Cr+phcvGTRfLO+8EoCX18NUkkyyr1dHS X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3AFF440014 X-Stat-Signature: yr7xpb9itnicrmswpyahxhouc68ze576 X-HE-Tag: 1737061883-875937 X-HE-Meta: U2FsdGVkX1908pxQZNCSZFNNtmiAxvtv8pZNgJkyreT6kCffGnuxS/CXR7ysWZ9sZpB5GkHWdTB4brZzB7DlhArjoXRahbGEqq3iTM5d/HVeVsc8OuadWfN4jrKmXZVsZSlMR1pu2ULqeIGFuMAR5Mpv8vSFGO+GSGCaH9zXfdjGY2kKt+YO+drTFbIyBMBMNFXVCgpZiLtVoBPmfvt7LNk1fhwJMQmPoIFAGhEesgYB+GJt+0BA+wiRPsDmwf+usl8oyYyPaz/D88OX3CKH0GPqAUrpDc86sg05vE8NFuyD7qmbhjdrrG77MDIKgw+0OR0SQVYNhtJD1vBHHI5kx+SGAiTqNX0VVDPQUlKExf+4esAAMPrhOU2xWXsx56zpwZXalX04oNEnij01rXegMfSx/1tNi5Yv2Pb+4uvt7cOKvjuiHLo+rJaWcmRVd216ekpzsHpDIoKWMfUdaq/McPI3QsMK13G4LbPxQ4jyxEQRfwhDsi+0bRbmuD4g9RDYybKkCtO/FsqZmGdhjsAZ3f8W+bk7R8GvdDlMhJl1WyFOVThTbhlZjxjrG2gH/KY7XZLXSWSbwqgeCT+eWP7bMsGBuQSHDP96GZ7aUFwK4rT4zwAA8qFyuJTWMjlLQGbCK4eXm1oS8xpKfRhxB+DkLhY18zpG5aOUvohgbTSJH11XjlOysAtuSFFKWuCXQurelZWbk8oHLMfjVVOc6b55qTDGEH3jR+nhHasaAHGsSKhSIBZ0wwMTOW1QiBmrWVIAYw8wM8QMsnKz/0BEO8cnQY4v+CK9cGW9ACpGKoiThsrNHpKsBuzCoJgneNDM84icmfzOWeHIn/94EUdBWt2SZd4Fx6bQqnh63AQYB0koLxMwMnUketqTHvTQm9cP1ecMdByzDGUrM7X9K/IUJIx9zbT7GF+GBqKNWdSMX2cC1A2faaGfn2mLxo4KQ8jKh2/KWTxRNmoRqr2NFRXxfas in1zx5Ur AOEFS6ywiICx/pQDRfJnjA45zIu8VDKQLHj6x8r4ZbcPUcwsgaXh1UHCzoHLrfK7G0c0VptZZvbiQoWSSyvLYeLuwe6LM3GBVXubdmbBmdbwnvvEaQxmuWV+WZmrFwzyE4oP0v0BmppCxpPpD/j3CDVb1gBsXGwlg7FXzAGGyHSZutFrxPpzNzoTzBi4EAV1A9UH3ueOQPnwgiRaFIeuUm0B3m2Lnpp4cWbO3Ri/U59e1+EQiaC+JdjK/81OJL1YskpZgVyx7Ow4AqLCQPRALv9Oj1d2WGNtV1K1/ubcWC9I9ZqenHxeCLoLBIOF8DloJsiAzeQ3dGeAB0zQOcFle2HGTiXr1QB6w3U1n0qhc2aRO2847WRk55L3biUi2UXGLFkKNKc1FFl8xob8= 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, try to use buddy allocator like split at the start of truncation range to minimize the number of resulting folios if it is supported. 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], then another folio_split() is done at 10, so [8..10] can be dropped. One 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 be investigated when necessary. Signed-off-by: Zi Yan --- include/linux/huge_mm.h | 24 ++++++++++++++++++++++++ mm/huge_memory.c | 4 ++-- mm/truncate.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 93e509b6c00e..2bdb4959a00f 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -341,6 +341,24 @@ 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); +bool uniform_split_supported(struct folio *folio, unsigned int new_order, + bool warns); +bool non_uniform_split_supported(struct folio *folio, unsigned int new_order, + bool warns); +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; + + if (!non_uniform_split_supported(folio, 0, false)) + return split_folio(folio); + return folio_split(folio, ret, page, list); +} static inline int split_huge_page(struct page *page) { struct folio *folio = page_folio(page); @@ -533,6 +551,12 @@ static inline int split_folio_to_list(struct folio *folio, struct list_head *lis return 0; } +static inline int split_folio_at(struct folio *folio, struct page *page, + struct list_head *list) +{ + return 0; +} + static inline void deferred_split_folio(struct folio *folio, bool partially_mapped) {} #define split_huge_pmd(__vma, __pmd, __address) \ do { } while (0) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ddba3e36b46b..67642c716de1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3531,7 +3531,7 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, return ret; } -static bool non_uniform_split_supported(struct folio *folio, unsigned int new_order, +bool non_uniform_split_supported(struct folio *folio, unsigned int new_order, bool warns) { /* order-1 is not supported for anonymous THP. */ @@ -3564,7 +3564,7 @@ static bool non_uniform_split_supported(struct folio *folio, unsigned int new_or } /* See comments in non_uniform_split_supported() */ -static bool uniform_split_supported(struct folio *folio, unsigned int new_order, +bool uniform_split_supported(struct folio *folio, unsigned int new_order, bool warns) { if (folio_test_anon(folio) && new_order == 1) { diff --git a/mm/truncate.c b/mm/truncate.c index e2e115adfbc5..a9679696fb93 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -178,6 +178,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; + struct page *split_at, *split_at2; if (pos < start) offset = start - pos; @@ -207,8 +208,36 @@ 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) + + split_at = folio_page(folio, PAGE_ALIGN_DOWN(offset) / PAGE_SIZE); + split_at2 = folio_page(folio, + PAGE_ALIGN_DOWN(offset + length) / PAGE_SIZE); + + if (!split_folio_at(folio, split_at, NULL)) { + /* + * try to split at offset + length to make sure folios within + * the range can be dropped, especially to avoid memory waste + * for shmem truncate + */ + struct folio *folio2 = page_folio(split_at2); + + if (!folio_try_get(folio2)) + goto no_split; + + if (!folio_test_large(folio2)) + goto out; + + if (!folio_trylock(folio2)) + goto out; + + /* split result does not matter here */ + split_folio_at(folio2, split_at2, NULL); + folio_unlock(folio2); +out: + folio_put(folio2); +no_split: return true; + } if (folio_test_dirty(folio)) return false; truncate_inode_folio(folio->mapping, folio); From patchwork Thu Jan 16 21:10:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13942316 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 59EF1C02183 for ; Thu, 16 Jan 2025 21:14:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5B1E28000A; Thu, 16 Jan 2025 16:14:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C0C2D280001; Thu, 16 Jan 2025 16:14:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A851F28000A; Thu, 16 Jan 2025 16:14:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8A215280001 for ; Thu, 16 Jan 2025 16:14:32 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 419B314086E for ; Thu, 16 Jan 2025 21:14:32 +0000 (UTC) X-FDA: 83014568784.25.FCE05A2 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2049.outbound.protection.outlook.com [40.107.243.49]) by imf30.hostedemail.com (Postfix) with ESMTP id 7AF3880014 for ; Thu, 16 Jan 2025 21:14:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ZPZfRt35; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.243.49 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=1737062069; 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=sOP6cfEHCGqXZ+l3ZzVwerXuZKCP7nJJu/MyQzTkN0Q=; b=a5dLZQoZYZkNISwxrQAKGzZDIM5fAO9+SN2DQ6rMbtw2btVifzAwbBj5uL59t5v8Wls7Z+ 0AwV/T3ZjVwQ+XHxketzE7UrQh0E6HIwvc2K4tFluFK+9f9jElCPJ4DEgzDXcLhxgaNxtN iNni362CN/zoxMd2q66BM/7sdaSWGdY= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=ZPZfRt35; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.243.49 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=1737062069; a=rsa-sha256; cv=pass; b=M/MhWMJhn1cQFNTfnp/tRuomBjFHurOMj7VkiIJuaS8qNHx4nHbyAXKFJ+UClt+zKeXwka qKOK6L442BBeA7NBy+XQHvaVAy9HM+PIvviIVCTjbLJf8v+QxHxQYG0ISKks9mnDUDuU5x aXKuBjQawexXbVNYNJJb1Iehs4cMc8I= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pZMFaKvcC8CTnFSqvdG8Y9J5hJF2+gIQTMGG9FONKwn2aqNgIMdPWO93K6sDZfk3LlJe36pTWbH3ljaq75ZPyOzc39lRYc1goLMZ0V+ocZ/NH/Wt1ywOb1lszmRC2yDqS63lHk+WoLs9usVqT9A+GIARNWsKgeedYmwoMqk+OPaYcSzM2n5JpwuqkKGepKGA2gksPUvF9XI6x1Vi3YyocYbJJrIKBeCGprR34X6klFNbmuDZ3NrrJafMjYOk8BWvlFGU5lIUYM3unnVR8LyLgFk1k/a2T8c8opG8DyuKHIDJXQuYYzEgxLc/LDFGIcJRhrnm1usiS6Tb7CgrWoPHAw== 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=sOP6cfEHCGqXZ+l3ZzVwerXuZKCP7nJJu/MyQzTkN0Q=; b=uvA4uiyKU0H3weiZWZ5tE5WfCEImip/oERZgqs1uD3f2Sokgfvf9KctKgfp6OqMLYhPoOFgiWjUnM6yz+8EZ7oj/LpvdPqZsUGZjv4lAckD82fO0uXTG8FgK7MHEaw65I+mjmWG4fpTFkd7y5xAfJLPNIfubRXUfPwU7+m+9Op2+Z+OoV6xsnzFtgpQWzdj6lprNIjf5dYssCqY6+2cGm/cYphxtQWRl2wi5XfOiBZaw0GqgCyQ5NK1hKFjho+WVpUpdt86dryDfS32HGB6CUd6BIGCemdWe1qddvsXqRjTJZC8+1D8cUqa1hxRejZCorGnSreSnSHXS1VN1Q5TDkA== 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=sOP6cfEHCGqXZ+l3ZzVwerXuZKCP7nJJu/MyQzTkN0Q=; b=ZPZfRt35RKHL8v3GK1EEevLgFZIix4h7SOso0O8bHKk2lh4gKCwklHAm+Me6A8e/D+5yPAOpxRrIjJBwV58xud0fdzt6eTFYR7sYhS8y/7fbRUNJQU49FU5+u1yS/UfjjReAqhYyZcRDdnF/4lBHZU7w/2bTpCGbBMCgcJiaHs0oJrP2Fcu9Afy1FkEPr/CIcXvB0nOpxIgz49YC3GYyPeL4tDIxIPWyUtgD95rAyZJFvO6HARjpNz/fwPS4f6dX0gq33OjTpXhrcF1qW+atLQTwZfQ9W4sdMBjlM2x6KNF2lvVsbFTeze1DMektgVbbWX0XlVIunRC8ekjMWhuObA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by LV8PR12MB9232.namprd12.prod.outlook.com (2603:10b6:408:182::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.15; Thu, 16 Jan 2025 21:11:05 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8356.014; Thu, 16 Jan 2025 21:11:05 +0000 From: Zi Yan To: linux-mm@kvack.org, Andrew Morton , "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , Baolin Wang , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 10/10] selftests/mm: add tests for folio_split(), buddy allocator like split. Date: Thu, 16 Jan 2025 16:10:42 -0500 Message-ID: <20250116211042.741543-11-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250116211042.741543-1-ziy@nvidia.com> References: <20250116211042.741543-1-ziy@nvidia.com> X-ClientProxiedBy: MN0P220CA0018.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:52e::16) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|LV8PR12MB9232:EE_ X-MS-Office365-Filtering-Correlation-Id: 50bafa8e-1846-4aec-f716-08dd36724a04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL: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mQeTUlLsoWvBO+JWZMvo3Z+PKrk25bPtYU53DWEIZJKDqEROFE0QSZWVY/7JBmXwDdJQNlmGRclXyMi8Q+50unqKgEglf8Y8X9yLi5ZSM75pNNkqBVPQTgJITTFIeSCHFmqkmpzux6uqimiEX+hfj80RUtQVjNbzv2m3Uwa6amhI3c3xSzSA8+REVgrKZp/x27SXSdCzYag80qIRJj4IrLIzI5wetR9xMIs22312AyIElqgzoubt/q2hZAOzIEsdFfKDMd+am4iCYwRJY+hQWFNSpaXcyLF6ml94XBqSinlf6E/ENW3Nq3+8DVORjEpAm1BPJPi79ZSAFgpoGMDD4pAOk+YAQL6Hy5pMoFwCmn89eK 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)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FrSg8o0wYhe33+ke0jSNc92xCElBEbk+/zQsL/alBmbI1x4B3r21zTQgWWU6lvQ94T69MOkK/2jvxSK3+93z2rRL9Hi7M+5o3pMlAAV4laLbAygPR2oHenWmrfFN20mEzCbE9EEqF4FhL+uUquOZ5+pqs15oVBmfmw5T/gW8WKvnRW//WP+i9ukj5ao6Mf2EyA60gIFUbJ9H1zv0bZcs0jgqeSiXkMT/bFuO1F/JmDg0tSHVgeGT0ESx18o5fQ0xkVRP7n1D7E4wOi/Tm3TOa1kIbnyqseKekafmKyPCApnLp3G+bJy30G9OjZ6wLnYs/7Y4Bf57HZbHAjQ96B5R3ONz48TkrJqiLbNfgM+ud/E/0XRxHR+vC0TGOzJqVqRYeuHQ3zz1vdhx+uCGnXx2QwBRgixHZfEgyvuomBkIdAt+8wC12OyGewzT8e1T5bCVbXEXr+CTVL7pnvWMKfQjEP46mGh8Obku5QXwqgbLxhnk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sB/t9fXmQCrBwJ+mdkWf2csYkqed/Bv3YBA5daeC X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50bafa8e-1846-4aec-f716-08dd36724a04 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2025 21:11:05.3442 (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: zN8ny5HbwPfUARtXhYNe0dXwUZJzk7CO50hSaRwtsgT2xP6ApmN7BvhKo9LBZ/Yc X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9232 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7AF3880014 X-Stat-Signature: opemjo6hm1ybwnxepbyidomd7et7brdp X-HE-Tag: 1737062069-677777 X-HE-Meta: U2FsdGVkX1/VtQc5GDEuoKQmnqoPT/979GgRYWkEbm2gZQuzIQpF9BQ2smqioA4obyC9OgazzQAeUZKz+eB6VG/052w9aFCfE0+lfmeLU+KbaxFUbZ6kTjil/WFychKsd6IqIh5xeXLpvw2vtfZNaR5A6DsHUZShO2zA8Q1HjZiUs94vs0Ol3/4Eb2WR3DG8RFz8s/G/84+pfyDpnQ8+QXWF27cOqdAxUCkGY+A9mmHpKZo2CkyaD3oUBRHpifp6Mrk9UGlwaqVuoxvRUO8gLMbpCRSWS+7oZhvDciYs6GhukxjnZlrI3g7fSUK3775ab41De+tl/hEL4Oa+chuuhKgGSt5bzS1ZATefW30Qz1dPnvjs+L/0+w6o3ijchvpPGBNnrHTbOSFKvYTMHL0UmsC2ORPjLh+E/15wzLa6+zjC/96Tu/Z5PRuOEI56FJjxk5gngwDLz4dTrMHzUDGypKkSRtDI4c8dvfMbaQ68Z0evlNAvFaF5OBs1X74iwUqn86HBp8ttnbFVEiP9B9M9HDAyakrZV7i2MP+jbKgNqRxxs2KvQQwF/pWwUhSOUIkHx4q8+XcbzsevQngOVZV6IqrINqr5qtSdJyh96fLF4VhDGZI3zt5lUDXnm0koGdilX5Kk7hWixOQ0Mr5iB/QWDD8E6eDuwvwxZkw1xQRLn/Mt4BNIYE7dzF5lLUce3+bkhBWCUv5tuRdN2VMvGqaqQncJv/QKnOlGbPz+GIFwmFsRdxlEsesGCAsQTbc4Wi6S3RK4dk8RQ+jTDe9VofKQ/hrgFuKCGm8y7juGbdiq0CJp+TubTUNYZBrHzo70WsBPKLN2KLBLhBmrXaJN5UeZtld5TonqvEI6WkG5wBxQ8Mv2FufH/XTeZMf0llUwwB6HFO8i7SB0WOadcQfac5VuClnkgL8wMeuCfDFnLAZ8KxCq9PqKEN+/W3bADpVLLg2CVbwd4oJzDJtAHaqqUl8 Rh40Uhdd cYwR8HAzQMxtt8pXhTpNBzQAwTuxzQd0qCUg0Wc3yZqnGq25kijKgih07uFB2IbuYCmfvFjf0Qfozbb8F5LXVWetjujpL2lHy+8wzdYjLSbsOeYTl+IdayPjHQ1pVQX6PgQO7qAtfOV7APzajvrM+LYv4PEYEUw66/Lhtz5HLz5DtosotMqpDM5R7XkesTeRPeL/V4jZu1aesjPwwx+1cuUgR21u7fz42BswZyhucTEho74W875xMM6yn0q+9jvZYBEFxqODGEbifpBycdoXYiLeGBzqNZm0ap57HQReP4opWobiWGG85dn9C3SHE2PaXTCMy2apvOw7ZQrkC7aBeEtEEyg/etlCY33KAT3rrSxsgZsIoaLNwlenv5o3NF81JyAFFYFUWanWihXo= 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: It splits page cache folios to orders from 0 to 8 at different in-folio offset. Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 766c1f3a1d78..070813b9e04a 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -474,7 +475,8 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, return -1; } -void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_loc) +void split_thp_in_pagecache_to_order_at(size_t fd_size, const char *fs_loc, + int order, int offset) { int fd; char *addr; @@ -492,7 +494,12 @@ void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_l return; err = 0; - write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order); + if (offset == -1) + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, + (uint64_t)addr + fd_size, order); + else + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, + (uint64_t)addr + fd_size, order, offset); for (i = 0; i < fd_size; i++) if (*(addr + i) != (char)i) { @@ -511,9 +518,15 @@ void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_l munmap(addr, fd_size); close(fd); unlink(testfile); - if (err) - ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d failed\n", order); - ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d passed\n", order); + if (offset == -1) { + if (err) + ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d failed\n", order); + ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d passed\n", order); + } else { + if (err) + ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d at in-folio offset %d failed\n", order, offset); + ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d at in-folio offset %d passed\n", order, offset); + } } int main(int argc, char **argv) @@ -524,6 +537,7 @@ int main(int argc, char **argv) char fs_loc_template[] = "/tmp/thp_fs_XXXXXX"; const char *fs_loc; bool created_tmp; + int offset; ksft_print_header(); @@ -535,7 +549,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(1+8+1+9+9); + ksft_set_plan(1+8+1+9+9+8*4+2); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -558,7 +572,13 @@ int main(int argc, char **argv) created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template, &fs_loc); for (i = 8; i >= 0; i--) - split_thp_in_pagecache_to_order(fd_size, i, fs_loc); + split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, -1); + + for (i = 0; i < 9; i++) + for (offset = 0; + offset < pmd_pagesize / pagesize; + offset += MAX(pmd_pagesize / pagesize / 4, 1 << i)) + split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, offset); cleanup_thp_fs(fs_loc, created_tmp); ksft_finished();