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: 13942294 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78B9D19E97C; Thu, 16 Jan 2025 21:10:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061859; cv=fail; b=o8wPgAR+ehoAPJ+LUscphxCPWTXOFd0Q90XW8Jc8h05SkA7+qj2NS1pck1tOHenCD12y//U61FwEx5yUwwuZkbqlBSa47gBLEwvUbiGUX8mY6qBk+0EZ1SezOyTPmvo86/sRP1jUSI95Pfe+35d9Zj4EixIIiftmZtDbd3YsUn8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061859; c=relaxed/simple; bh=d/lCstPp7EOJ/jE2ClefAlg/qguR26Uo32vLSHP8m7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=pcTemO76Vp7csMUuIuT4KjX1j4oheHGOb2mUqfrl+mF8V/7K76o0PJBkLHfJkkCiUHBhntfGda+FJ7/1rQvd1DrS5qHdclSt3l1TvDDIxo2GoqIF492EBHiNAiu8OcA9RisphCxySLIF25AFISjydHji5NaMi6HgeQ23ZWV7xmw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=kIV2QDRI; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="kIV2QDRI" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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+CpV7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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+hLDS7j1fLrTvIyVB+2Xm7lAKH4h6rExpFEIAYYQGBE56E2DW2eqdz5J1nlunkAgPx+EcbT7Qz8aT/7LeilQFoysCMYb0sXpvHD2xJL/qHucJZ3TY4iAUriDZD8GcSuQ6cx49JqaYCF4/JkzkQ8aHrQpJr9Pv22hPf0i83W/UxXmkrcbPISPTWsuPdSqfZRjgtr/u+B/HFJXQLuQ1nDaeASE8Er6Z37+lsGzk0yDen4DrgK4Wo16Af+rycWDVwkL2pgltT3vT9C9J91EmTO+VjK6w1fujQJOM5Fp1Cn6wT3m4diTvlhaSpR4GdylI3zsovg92Mbtf5PfSJX1DRDVayNhe2ApsnT9Qrcn4P0Te8DZBgp4GyLQK3ANvl5MYwXIUhC0etFZUvzgJHPHKfQGhW44rDhoBeyYV/vcHN8IPs6q9hTm9fSMV+4W64aqUFhaKuyoXWi6JtyT1g0q4d/iFg1e/Yt+/4+YsgVOT+IlO5LfU8EX93vJSZDK4KrA5Lh39lPnl49maciSg0C3zlZmZDAL00ID2ub0thkmK2Zndiy9aGfzUbFdZN/WLsI1JUBJ8xDXIyIWbjVu2qzTMa/F2a6RgOkaxNADJlHvxBinR1+4cdP27OrVEgo3EdEZHQIbrm7Ljz/uF08TYpFeSI3Dhq+P21S47ZwNh8Rfes90VmwigOKlKh1VkTIB9Fi0QRUunri/poLSfAW4oNlzW2SP7dCHC36mm3NCbHzt7hLAeUhx7cVqCHSLUsd+Z0Xw5ew/Vd/iFIZ6UIzDP+EReJDybJ37fRtiVM7wqqpJcZIKOdZMMt/5wqqtfh4KhQzxCDPMKQYbfsxomvwausiwmqQDUR1taiGlGCKTnVuZ8B1Vx+V6luelqmWLO6SXDL7SES1eluCgjlICUbvNVBfoIrGLLehKdTw5w71UM4R0XihO2k6UL0AMF2NFi8OOCKbYp1Rg9vNAaZs3PSvNhnLkpGYFjx59F/YtqfcKTPllc4M5nKrmilLTB2KqpoJrFGSySM6nhCy3jSNeA4Uw9yRiRFDbVei0jEdDPB1G3vvcT2vsfpdKV/i+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 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: 13942295 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 459C91D61AC; Thu, 16 Jan 2025 21:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061860; cv=fail; b=Kz1sukwC25jLORzMkNuYYqJgbyKYf+ZdHwCHK3FwfphvCXiFRe/13j3xOt2kC9Gr7KJ9ubbMQ7oowhVdpovLooMm0h2GEWFDl1HJnmQXAJeH6xa0gV+c+g+7KznlSZS0EOX04RQT1+DowpzZc2eL6sZxAe8k1czot597Y68Mkrc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061860; c=relaxed/simple; bh=ohiCuA3Py0JetU8gAtYQOiTzAMsNBy9/ujazVI/GD/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=hxcbvi5MSmPNYkYi3UxrWWFkYg31tENiW4OL+q3AtviXNSVNAUerASpg6hZbfF00+FiB3QR9xl24Uf3d6w33qN4zUU4rJXzkFYFzl4TyO7N67KUP31+EG1DJNmCz+BENkzjxnnwyHFWiUToBmMLVBNyC0WdVl8cKD6psKhWHHEE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=mnyfl1v0; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="mnyfl1v0" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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/3Np3SZTR1bGEVzgGR4J4n9p8A1khC8ZsKwJ63/Yy1liMBbrUu/myzrJUEhGzCbbeyvXRJpSEgjZuEHI6chzlIhIrx66XnMZEHJlY1sf+CEFGskbxw5wAv3wS+OShmPBbtkvwtOy9cpqHFBtZBSB9Yi9mJyMREdclzxzNQXYUzIDksYi3F/tt7CYaoqgd7dzefOXtXodS0CUDoihRjyG9hxm5WUQ7GjbEtGA3jREftYoL6Ty27TDCUGAtJqh7/fBk7H1zGRZ7I5CySNBH3pOPsucxlO6BaK0sIR6WnqD9lLE9hXEfJZgjD/OB0qQySfVUmC5kG1lYE02H+ZaC64b1yGsH1yxBkzjLZ6hSeM8K7w148G1jUrH4j154iac6aLyUYjHM0bTkyqoifQ9JGgt9molnFsxnfgIi0RivAy3gcehcwz9T5sCGMXZMBo5Yw+45JO40yzfZM4IBVeNKQv4fHUf+zRnkcEKeKWTbJGVYi8lQJdF8zMbk0C3/l0tX0MybZJ5fc72voYITNkgtbOCQmxkQKp3S9BxBidRM7vSntJ0AyUmdJaVMPv0fVzVhbqC9TJaLDdyuOmH6TPFELjK8GhxFWWXwS4++ib+mcI/gZtKADPrSngCnh2iTi6yZlFH+DHjaQTDR2ALw3xJUdzo4AboEeXJcR8kMj/GUT4PhyYTtOqyAbfodNvYsbWQyNDRiNUjTt9PjOShmcLjB4VSH2nm32ZqewFhC5MQSpCsRJq8F+beOnsMJrSB8W4F2S+aSgqGlJMG6EjJpEhUGY656BDz2M/PJEjtDMnLNeluT2Mo8QFHx+HudmOIGwIcIVNcsT4QQh2b2hSwQx0KuxXtCuZg1vGavm/p+m79Zv9URABdEdn6hYYissS8JYJyUtRoRK8m+kWFP02KyxCH4WUEe7j8FUmobrF+8L0K7hAncTbZAQyRiwEbQdfthG2rDlH50CpyflWS6iC1LDm8J4iTZzitSHxmIMW5x9dhuNIu56aqvAriCMR3rHDFuE1T+1Jk2S++RuwFUNMcrwMa78n7M6ureKK9pt9IfMAP2Azbjszwo7iKAT5Ya+roFTRniXJsPNLSaSlSWsgJhBQ3FrqvsIjUv 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+4PEAbHliknhsvoKbeBTyEtxZcLq8zQpG2qsmVD0k91CGN44ybqQOpFxPcHRPbOxu5M53dcEFl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9ajyxedMITsA6TohKtpvDeOSeCyxNj3k3JaY2YOAl7+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 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: 13942296 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 010B7233531; Thu, 16 Jan 2025 21:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061862; cv=fail; b=XTLJuatuFSkj+Z3/ZI+sAVeZHUic6Lp0zMfa7koXXY/nsGpxNIhTOcBeh25yKSydSZIcaSwcLVs/fA3y59244gIku1WGRleV9GPQ+hgAShcfvA+4KvzEbpRBkXenoXZoYRJRyaw6Ja3VBnGIF9sPoknsQJaiSN6z5l1FxkchZNI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061862; c=relaxed/simple; bh=T4KOVk3YmZRr56rb+N4ojQl/KcthCGWqoc/XmqpifPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=MmMGqKVfrVYKNrNKdrcSmTY2PYkfq/XC2u6lLqBe/5fYbO3kOQKg4FZ+b2vieLePaB8nbxWAAwoFikIOgFupBhgmkYRnv8xh5rUODx+AHTuhVsULAseSPAwV/QvDeDWJ7ag9z/PErGfBIsZJNHrTVIVBZUCXNErj+qkmM+mBZVE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RaMV0+l4; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RaMV0+l4" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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/J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TKUMhmnc8E2bBFEBP9gbvX6vf3OE5yWgiIdNoKK+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+KCNv0IM6W93kHBCDtWXN3am0GZKFDhsEDAIJPfaZI90g/9/pk1oTXsWHLyZg9YJ04kTL/8LKf8/JcW0itoF09i8EkqpbzaS0svtpMp6oRHA6zjFkAcODCVl1Lf7jbg/GL+jCkK/K+fqV9fAEKyIrPGAMcms2pRSgValM/QAIMZB1E+ycQboMXqEUdBG8pnV3BPLC175+kid4zndgB7SAlPhGWu9kjNErFsiZjYw5HvR/hqscZaKHcj0JjPlNoXpqogOGpzosJqmyUkrQ7CdbrvEjp5bYa0SkxdBW7Akz62//pASqABesUOD6MFGlXQ5Oaz4E1b3PSe3tejry1VNHDcRyW35fTXBku/PY52Y7lMPD66y4W7kRGAGHNxEJ7SPpsQRSkEceUMNqc2xOq2rAu9Ah6crCpPKH7ovqOl6HjFv5PbtCmXaAJ506Ie9VFwgUeXJd6+Eg1Xhf6Ze0fztdum94nz1xcsXtK2QDjDaVHdw0H6SCl4ZIaMUg6X9E2FpVT3BI17ZFhw7Xqbl3SbxD/pga2p3BBY3H0pTU/fDsJW7/VeasnxoQIyeQfnwRsqnnLrEgEge23xZYzZ10rsRyDuXGnkc1LRVZQLlOgJ82lu1GynyFs75fvcelxUIG052ZUqHS84ujARFqeOtAtvmlz0l6AsqfwcYi1IEwJCb075deHckMBD21AGcJ79yim6NuLFClsWuWfH8F21n8fTvWO8NkGTqyxBidWu6chNpiD0jx/7TnGK5E/OLUvxcKKy4qEvO8evvV2kV6RINSzP90T75r7sIFqwdCiO+nmIzoGdyeGeYAOYDe6dubyiQzoGzH2jugOjHL0F0F/qsjcSo3oEixToBL8QstX2CfG3t2ZYAANqzK/dIGtKYA04xdXUZ2ujBnYBH6VXU84Gs+yb6plno65/DigorB5c+A5iAEGms3NDx2IeYAPg0OR0Aao08EhNz4WAZB497I+pVaem/rhRFpcSMPGJeYYRGf8M0xdawCZiJVykwS1B3BIDGuJCt647LRMVE7WKlXWouX0p9NI83CExxze1MmdmeYCIUPJi05kwzOiVJ+YK5tdbZyGJILtfJ4pa5/n/8nu2jVZmpSR5g0AcRuB87xkvlHq9yTFQ/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 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: 13942297 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6F4E2361E9; Thu, 16 Jan 2025 21:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061864; cv=fail; b=lwGJbp640umaeOrcR7CKYpgVY9ndaJVzopWh5AjcDmASKy9yGNIrJd2/tedjgz2sc4uBSGC3QOjMjUnXoSqbkkdQCzGjGbj5F8DikbJyT51/Tx8up6unbic6ZAeF1eCM8YlZb0dkgvn1ZL0VzbxKMz3EN/8t+cJWiG2Z0bvaros= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061864; c=relaxed/simple; bh=SG4zDvETg1F4aORMLvCFUUCitdwd3XrNJPMppt22MnM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=XCJNpzKy4DrSM4QMBaH3vF0G14nxtV+aYs5u/eJ+QHA8CniZez5dK12eUNiV2lYw0RQVvFyfou2F03M6klExUPwdN8zIn0F/wyyxUdPa6A2WJvi7P/DUGrqGzjNQCSgZnVXKvez/VDM8tBXpuIDvKNNoQZui92a6iwtQxyqpttA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=f9vTHFkx; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="f9vTHFkx" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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+nkkuT2bZ5GNI3FhJ44gRWEH5vx3d+7453jVljM2BBFzJTQxX8KR8UTsDRQguEzhSGyT8n0lvmd1ambiTw8nB6UXD4Zhte5zO6+hzr3oCSG91NXkVHcNAWsdykm3B1b6/toW4ZtGwLKCS+yxkMCf1Vgrs6ES+Qjq3qrNaCIcTKCbiyvAcuP8kQm7x8k4UmP60zlGpbJUfBSC8dhZFogeK3rUNkjW7Dn1aF2WhDW/epvY7fuQgHfcj/vCxBpPXLiurOscBj0NrTPeySLH2HDZnDed4NtQsSsHYNumxzRtrdDQIAUZMR9UwzSqz6KIlGOENmcMrEC+GfKG6EE/Ruj+u943vMMfCq+fe4llXOIN/BwAKQQIlKOqB00ImH2v4g0Sel7o975UAARLWw3HRMEJQkEt0tFVbGE6FOnjvnFOuP/qT9jq1Sm+XfDvcq3PkRlIVvhpFVqfQQBN4R1JT11VP5I8m1GR45QpgSrjqKGlv3fXLgJwp5ioBGpPBArPPv/xuXu0OLpRehbatj3R1g4+bAugoUNY4SBX9rZfq5inwt+L0JUaii07/p9X+yjwMo4fW37/SsZfMj1ZqeIKPwuqX096iOp+Pz3bIJVLM/QfU5Dp9ym5s2+RI/lnmSRzt4p6oqBnUS6vck8zekU3KoQ7y9EbgSBYkRpGpznN+rOSFQFbebHYo1fcK2TUqsXqT+YsD//087YUIHTCOVuYR2qYHp3KLwCcMNHsag9x8YG8VxBDErHdjOxj+p9X+JI6+iWZHnbBr4P2UZvPIyf4aDvanXHP+gpKEINEx5++84o41thT6RRUnB3S5rKiK1cGdWQcqHEnpnrvgHnIV+nVhfm9Gzg+7SaWBQC359llMhkEIynfKo+3uzG2qW3eLLK2YPGDTxQt8a9BjjRph5PqEIt+iwqH6r/MdzVzwLia3SpNSHDMglbQBPYTtdBuYLgbZXr70sfqed7sVnBKJ6uMcCUowCO4n6wx4GlrWyNFDxm4YIHszhH8kRbdnOMmCkbHRu3knLcfNqEDwx0oMC8qnUhUwWp2YyOtd4aBtofxzZUiUij0vtEKS/TcCf1xFX60DltMNjLcgTEmx0mZna/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+Z9HkwA1wntcrIjdpOTNL1MAWBWGurry2Zt9vpUwFIW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L7wiJ1wcDRANmYBmhw244q3AwI7kNoOLnU3ILx6DPo+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 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: 13942298 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1E0E24225A; Thu, 16 Jan 2025 21:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061866; cv=fail; b=JxEAbdDv8+Z429rY6fGwffPxPQ57QPb3+OpDkmt2nL/1Ite5zYSLxg5REVVnks+V0A6B31ljQ4akjftrpBThhXCw5KXuLj7rtrpBcmgZrghFdbxu5EYoNJ0zkIdN09o5oW5qofvCtDGa1juUnPRKpHIfRDr3W/KrppxHlJrbjA8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061866; c=relaxed/simple; bh=c6nSlzVzli4DPdceVwuuMMiI86KWcDFiYsCFn44hdkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=umtfxU7GpOjUlHcSf2U5MYFfKP763+L735PksT3qDdhpEvoxeG/C2YqpOkkxsaqL5g2trW6y+etZug5E69X5S+EsYJHLym1qLx23Z8LDg4EiJj4ClfY8zkw6OXr4r2JXg5AWk6YDOI6Eg3afM8cdPbq2nn5okW3nnhCKc32jJMk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=GxpHvIUu; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="GxpHvIUu" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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/bl28OEmy23Ej0uKjM08j0d8ZEwgixEc8O8dMVOg8qTYBlPTnV9CUltc7xDD0ZxCLjGEhP3vZMN5iPljBMZ/vf6FbQPWm/wcUQKx0PqMsaAPM/NQVdYDyP+8sd7zTVOel0L1NoW7P5LNQZIpvgpn6lkMVk/HR5Pwov8hXT/v1eanq2xHF8/7sZaKfLSSWO4LMYnPolz+SDbR+nLZgyP1vXr+uEJUgEFbvr49kFvJyupvM5tIhKejZehDtQ55BolI/QLnwmALnD4VjyqG1syJ66EmES++nAE5XmTxuQr7tZ0Fli+YxMLNNhU7tCPI8jekOTh3clmeqXY9dWTrrZA9tkCr3IgjEXRZtcwfPZXdRmcQ48ljewDbwJlRfjmXKjr08LZnf1fLKL+VaIY6Gg/dAZ5B9zw3hYh5I2bHQ6PsyvHTJgxNGAIERVbkPYLFJmeWoFJWal7vrHMJVT2n3t4uoYVaJmOPWwpCUGTNI41AFemQ88HLDv8WcBjqe5On9eUfUeiZQXuu9tyWZ5OuzJ0XFufMag9JPGXXDWkQdvprJ/9Ct6rO11FT4iD40RBhqLtxQ6fzyoa0fHNniRVPmDIPEUy709ZpG/dOaBBd9t4uKOjJklIEmwEhdAg/B68duW+kO2bMuVfiLWUJEGh4zlCRhVrpzLaWhYp4Z89Pxu2qPPQsjsUd9HURVirbEKxh23BmgjtuD8Q8OTMJZpuwqJrAg3evFR8f1gO7iBFVzxX/dueY4sg1gg2wMY3/2r07Sm8HR3B/UqFLbqUqLFnICxJElKfT9kPUS0nVwXtOHdFWD2/VngtjCiYJzi7c+4QHMqzrBOXuVhHCo5ndyDmPG3YI7U0tanv6cjdXAGMdgVyDfrW2nZzQ/cTw7Y+E88bzOroluKz9ELw60M+ueqIeBVfSkFwDNKiGd3T8dyU365deAYp+cVYaUbz/rrB2pIoktmFXDAwxP+UtJu/kQFJmJIPaq8M166LnyUPkUQKz7al+ZJxSXYiErBqHUEE9SiRx6EKl10ML7j4BD6nwH0s453u+9AlhzVEUIWf6WylASKVy5hHMkzvc10SUyNhRxYvQA2PYIqYLCxkBSuqNVdELJMvfc4YAQmrxNWv9dhSJVxuGgqDj3DvjH9OTHR0E2of9+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+OxJCU1CaQKzYkS6afpTK176Q7Hq5PpSq4ZLc0deSbCD675Fv75aheB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vbZjAj227JQzN5M0YqfK+pAP3IyAZXe/+3zlMAKuC6fNMwwFszMc1o/IMDU0NKtCKIAV3FQbocC52Ai0Ed1sjwwZ0aADHcwFlURRrE9MdKoALidLnjBlzeSjBOv7uZLpzhwSxuHeUa7cZwoDHa7A2r3gQ8FxAx97s4ZRDiMU87nDjCXgNvVMRnmocd0bF1WfyLRJBI+qkcACqfHaOHZQS2hIcCFM7JdnJS7cvLBkq6ddOn372XebXkrmIAp3J/v+WB0ROeZ2ErjoEl9BghHsTT1X5aJcKX5Xc2Mfzb8f4c5kFsRJpVVnCMqO2roPV0FHAE32kdy078HG8nQ8hwhLjmmxURD0xN5qhCoWHyig X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a53e528-d0e3-4056-e7a5-08dd36724607 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: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 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: 13942299 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9553242259; Thu, 16 Jan 2025 21:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061868; cv=fail; b=kxLU77vklHJS9WKwblfTRMTT90WlhjXgSW+wfou1O1JrFdtlFdEWjOoGA3/MhCCyGaBcdcakyhC7TNK0Je/e91GtLA7BFv1QvsH5rH+lARm9fKKChDsvv8cRAK4FRQcpxuZP3fZwiZDzsKDjpCn4ju5sut0qII+9ddNJfzTxy44= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061868; c=relaxed/simple; bh=7kOMxMCtgxyC78YXkWiNo3lxtgLDDr2eNzDnfpmJDBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=bA8Kn11I79o51uqClFeQT1UewPBxRkJNOOu2juuYhJK+9rP2ssTps0Rs5MQMg9Iuot2sr5k0qjEEsQwBv9wee2CGKBBesvMSN6X4tjbcfZF51npZgcZIo7CtD0qIeLAQF/xuS4/2VSUwIRG+BjnwmnRgjDkpr4jCQ/L7sEf8HTs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=R/1mNyhL; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="R/1mNyhL" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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+k0BtVNPjo9mJ42tklWxeKXQ/cMAImukdBXLplvFCKIXb2ubCQI5gDUldu55Zb8z8npn3NRFMqsuO2vPr4bD08IrPzfXatMorKvp2gx9osU1PQw6GqByl23F9lD1c8ccBl/Hfw6Utp7lvJlyXb/jiC3mE7QzOKwTkCOWZ13b0KvSwqm7Gz+Buyl7Zpah0op9Elq/4CSSBDvtzNUENVLYFtFrZMQCfPdU2tkLp/8ktUt4bJnT7755jdLo+dCQAO/T5ikN7OgtI+z7kml3wrlbAXjFpeisu3ggrlhx77Rwou39yV78Zr6G6xh93RhwflqsrKxaGFZbUknvW+X0J0GRqY1/zJ4BYmWkBnbV+gN8HCjDD6+O3ZHFNhmP7m44UFBlo1gtwV1QAJkvDbWzrwpJCssmAUfiC+0IKglEqo0AA+S4u3fz9OX6sHo731vQvnodQz6EHb/ItdmRa55TDJB96b8VVwM5N1/Oq0dCnbofE/ckNSZwM0m1jdVrpKn3/jNzda+lKjvFItPGnCBnYNE/MhzC76eSYL+/iDcSGFK77d8DC8vTi4E1riPZV46rHeJHdTige6tvpYqNMYELu8gEcXkB43B+JogaGJBIAEqLzilSiE/9pXXCiQT5yXCTE5+CSg515HgGBu6e+2C3worY2MHX3d9ondmwgBEXnwhl8OnI3omnsrF7RXP8UG5zbrZmxBe3V3DjJPHmuckJ3SvmTDN9WafiUV46wLDRgwwIinCL1sdBQEs/Bd7f8STYJSgoSDmNOdWpGiLS1awev8D0i+yC7MsymO4e3a2jhOJSfnWZ+4ViGJNImnPKkJjJHMKtaToyoULH47LlOGD3WyiqtD5kJETrOOSNr6G+ZUQMthcTKou49r5KRgTlKf1Z+SkVaPQ4Gt4HraHxm56L1WTvbpnjrPDE4gyrswlZbsFXziegBwO0YrgWV5xNhH0TBlaxpXhYTkBVqrQ7hY8zK1rRGI+pnRnEN3j+DVx8ccqF21RdFivV2Xy4BEu5uqfDcdQMTBKfFhKMrazFLrh+22nv99y1PkSKqKVDUhCDAhUvUDV3Ng0VKHMBRg0iCokXmLDmVBINmCeqFPa7EpMG7ufZXqC0Z2eLTfb9xghPE1JHmW4cH+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/Dn2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zR1JlkQIRNGB/RP3IgGrAmrWZwvy7rWFuFUCpvmwDdu7KQ4sHuzpnod4kxXlybFblSeFDGtGv/18VRm6VTKMeH6ph+9Kj9vRFcKNueCgbGs2fNGySpmbmZZ4aZvHsFLjPu0iH5oo8Z9AHnxtU/5kWpedUbcJl4JjB6iURGQyaawyevfveF8F5OCeQkI//vfJYAhJbLvgNPVX+/FlYZJ0kfLLLTewdE4zwII9pSETfhweDkpeAgLzp7ePg6R9Mi8AuEQmjgzryegFaGtH201/2Os0H2LtFiiBx5lPD6u9F+EDuaFmgY3S0vaI5FsnL5FmownyWawJmevFhr6y3rOoeo9SdFzuvRO+YhLBf3PwAWttiQWfDkSVPruqX7dMBCNjDmk1j53K+8qMSzQjxa3pIxiykhdfSSatIwbJqHcZcq5nPnEt/ln8d4UVgSqxcoPBc8tmD X-OriginatorOrg: Nvidia.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 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: 13942300 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE1F2243851; Thu, 16 Jan 2025 21:11:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061870; cv=fail; b=CH5QhvE7lwhFOd8RPXYpN4vfyMkfxC/SFPcgH4w2gKFph1At6B+QPiHx+FotQXq06s0N0VmnSKugL8tlndXVvtpAxzymk2CbzGEdlScQaR6PO4khzUSeUUwDGySeDYo1KdGkqfhaeRQ/IxaKCJMgi7HjMODz4qaVRNz4g5EgNSA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061870; c=relaxed/simple; bh=m4yuyB/UMwaiFVRQIm/Zk9rlKdWvUvFmBfnAaJgW8qY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jYPo3gqE6HZNoJ1Txa4PpQg5LnJJD7K1hhBAroUi6NXKZNPs8mUzXsrVshyw6s6lx/jEz1jfc2Xr0mTZUq0wQO5J3nmS8gewJRQ4vsrQ7rJPWFYsZ+ORqfTnrAa74KVKzMPCZg9H6/CJNhYSdGTTpSfVyOBvsv0O/aKc3ccP6p0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=iJhc1Wsq; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="iJhc1Wsq" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-Ex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sfp8G6+rT/iPcu+3Ne6lXG9Jt9PN5U80Hn28WkajA7MpdsfSVEAm4J9UvLec25FbQyiCgATsflzYKedsrCCw9LkcfRWqMxDI4I77LafUq+OFxJa9ZOva5LHGnTCqaVrA8kztN6D1DPW8bkgIVyUDmPlvsiIPXpA3qxHgkjPlpCzY5utiLkKyPkjskx4v8BMQcDiRKWqTfWvdaezsvy+48H+HaJ5ruefi4hrcFWX/AQNjvK0/ZmyDquE5i/LvWcpHLswtl0rfi6IMYUgAgvOuqS0jMZLivqDVg4j34XItg2eD3QH3kMFipVhGpEBRyz9NObYRzABX2xJqgZb9KOk6xsW27SsskGz9InpFIIMssNEDZ2pBrDawOPA2KSvJwBdjyc4TcIuk6dsYS46Y+XlVgdx/8aFQoF00HIJL57g0a+34EIrOeRm16po799epBTSW4C1dlFEuQ/6+P6ulJnoKI6O/E9ApWTcsxNqCQq7ZQELbgj3XWPOYK6R71en23SkJUkfbADNCsqgAe2HrLQbyVjMw9ktHbPvihF 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 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: 13942301 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C00E5243870; Thu, 16 Jan 2025 21:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061872; cv=fail; b=XGTqbEI5C7+9r6Tr3oN8nySj8bzGysWXhK+U5QAKcFhGIJwc/8ZRuZTboc0mQVeNgccZAjK2Kifi5da3IYSNBuu5THNPF7w44ClBDwSd2wH7//J7bktQsnXWuN2po5wHeLFAKIdwGSv5WWnzo2gMgfi60hI0EYEbQxBKbAaJFvs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061872; c=relaxed/simple; bh=z4BEJqjZQvhJk0Tk2kAY9Zs3C7Y5eyNsv/ji1H0CeUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=XuZ8rrLG+idbn4U0G15CsuExeQJuUD7Yhqe7luiwHk9Hg+XtioTEEIhsvD7b0wKKVA+kP5ZmsTFJ7Rle1HltSXEpmaM8Vj3ZzFbYD2c3bSDuf7txgzlQNKAWHoymWWGWOGtB3yD5QA9vY1dAcgegl0QPPR3cdoxz7c/+8aeJgZo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=TbPjbINV; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="TbPjbINV" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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+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L: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+FzoYiQfaMuFqBO+Kc97PflGYAGL+qlCv17ZI3Cx2vCn1HECfM9oa4zYPIbzol/gTkppXPcbwmSsnH88v0wlJq7n3bMJ08E9WQ/7aF3GGTgOw67Y0AeqBX6eWQY6t1JNjf2E7zAXrn7T2MwD80pomxLOW+bxC26BFWxBAonzC9FjzzhyDiETVCZMWnaDaPlXmz2ix/BBIogQGCVvozX7lextCaMAiZqY/WHR+ixPahAXYHHW1YzAfqmZA/M6aM/SXyaszp43Stqig3srDsXckE+F1CRzBoaOFD9IA/pgPtw5lT+jMRkV7AnrIzkHvKttQFIEUrBSs9goBfxYw1v2gHCpoYBTsnjgZqXeFhwFzqawIx6gYU9XejdfVKGkk3rISMygIYx7pVlJ0wsOve6z3eN6CLUqu+MBt4NhOmYtp3IrFWt/KUA51IhIgRsi5kKkbZDt2IPxmv9L4KpQnrfLX+489CwuxdfirhZWVynBFuZk+uVnXhg3Bxz/X0upIevlfDgCt+f4FevFkvwiMhBPDcFXpnIVZbKJ8uQqMw6ZB5+hWsbOtccE8m6U3ZWqSg6nGEuJ6wdG2xo7TJt81kM0m7RGwvSpyEuN8YrcoK1UtaXht9/Lp1UuL/7NJf7iOwO4zR9Zaz6j6in0eq3DhJtnOFuzq9s3mRII7oqurRwRC+2pJdUk9et/e5fPgYqn4fTPPqwokqcsBG+/sOq4XFguw4OJPMh3yMbEH3Ct/2pEgvWuKWtN8vW5xXbFo8EJn5WcBHDZnuhT+E01icG9oIpcUwX1JujtqlJLW66blsqAqF4Wkmksfb/yAjatLi1tOI3y2zF9MqEO7C6XuU4xLt6T89NnXCEv3vs113Tp4q24uWOc4XfptUrSUP3kxXSJmVlGo1Dex6vmVngBxoOsZKO4HWa3esgLIV8X+s/i4gO6nhkPgo3s0fWZKAjE5IVI0dKIJk+DwvgKNsjCq/qiC2UkQa20rcrKbLp9SE3swb3dJo430UqDsZKJLMsQUci+mH6sWR2DDjbUMXHjFtFUMZVmbYn5n6Zk04OmNn0ZOjZl54LBWyVyeet9OTna3znRTjGIt2EkIXMXqrQ6JUvUu/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 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: 13942302 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F1022442D0; Thu, 16 Jan 2025 21:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061874; cv=fail; b=mJ/DKhB9ZrCx5ncZWLw6yt6VfuQ17zTSKp2Jo+YD2ytQJVB2ly5oKTNgoH6EyOBFrP0DqZyrfLfJQA7vK6jxhwfnM+h6g3VakFk1I9WO5ZYzduHKfC3kZfxV8zszitjQYh8nbBYbdLqdr/f57y0hlt5tscuCndhLIvDgPdSYYx4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061874; c=relaxed/simple; bh=glsB2MPdVu/FnwswW3Mt+eUYN2nGdILbyNBnFhTuOyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Ps22Um2ix0W7RNaJuZajkLJCt2jW6mY2ZPdE2H9eUfWTwEjjW3Cfvm2FMNnNbzQQP3H1uKggbuP36k1q7DBBpI+WAWFuGU0dicYzivJ96mA3WgkxAiBdnizYR7Wp8rVpGBjy7wq/KOOyH2+TmQ4rVE9kdT/gqOgWO24i14Kvwf0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=duZMO+BB; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="duZMO+BB" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: 12IiEFxlki9MviFmFafuO5P5+vXaB8G+eMDUqmjsma/ZiLCLNPJ7nbqeNtOspx/EPi33s6kP9vQQTajDInrIWgWxB1v0CaY2H5AjVWMUVUokAt8kIIY2FJXosRUdqyaGvorZhzLUkl5Jzso/UV35TccbvinP+8z9EAaObCCBy/g73bmUFijNgsgt3SCxojBCnp3QiG656kpIOs2oPTKVowdzVNo3A609HreG4QFnIrdEu5Rtnw/KwtUhyFtktQ0uyh/N4Naow5Wmp0HiG0vbJVP/ArE8aTxXhTOToE+LaQvycvE+VULRVgdw77KedrQR5SILS63SAzgb4wBP246/Hcli8s3ww9UyZZu+u/Bka3GnA/8XsI1aAhfkmXyhqygVig1g0ykmvErIG3QtZ+reMX45bjsROMMGTnCznvVTZJTkv2W4Os07ceGYxdbu3PyeGUu5iLFFS2OUqXOuYhaIGa3QDVBRGTSh8h24ukXkTSJTfTGYNCVtrH+SZgSYQNM5bgCW8PX2wqhxcDhbD2TsJtyjkT6aOyHGsuByip03WiRoGbTw2Y7RzE9UjQRnux6bv59cH4l63f3l9UAr10fhurchMAfPzl8KPAhxtr8Xe986cqr53mtVc2tB0f/Sy+dSV8GSSCvW2N0pBvKH1CLWpHL1Ahu92dRig45HA7GLyHOutI5wiC3JYfr26lXovLOL2X289VU3JlkDTuWRRGICqhwMjqzjxNfd5XD40H3lTvBvLTaPnNLr0BNJgORisIUzLSt5kcMLbug1HEjch7kQBYdUTABjo5FS4JopvC5r6LEre4UbaZxnKU7A3DAd9VWMa0XIX1OWjQbsLbiWdB+FZXDIL88AqnVvP2lvJJMeCvkJgQLrPyVnY3/snQz9DEf7lCf986RkUKtg9z4dsnKhmlYbRFufBJ14x8m9oVjc5Lak5zBBOld6/jAslwJppZd4wJJpVYs1fG300Z6BELasvz2TzSp79EXhnsHrrwWpcftP46DTc1SD5s712guUGWNoggBQjPg3vAasDMBGCW8u+gplbyDl3z6OXIegch79Ph0nn64hoeMTFmJPXGCVtqMTePaoL+GQGVTpWo5onBABF49kGqy6rpWnOs2hFBN7X0EghTfWwP2UsENzDc5fkekqwJnih1QdOeiPS7CsXRi9evBtQ2jCq0PrPlmSpn0DKmuxFSiSQNzq4gLaphAk5YWp6yCs35Ugt7GYsFCSeSWzHU7OZF8tlq7eMysSSpR0i4UF5yX7JR1HwE9ubz7doYkHulBxUXrSyEBEiY1BaIsULkVtMjn7tjGT4SAy0k0Fq/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/nSbN0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l4vyZVtB7NF4z0bYgOTwSq1+L0P+5XwGnOQOsWFE1LdR4CAgr8PRVwaBtv4nLJwnFenbH+rZwqztP75xlPHkwZYLEDaCTfrpq9IomGZe0Ri2CRUFCwbtJKzRx41NZQUc15wgnSO7uqbv5i/yROBI7RRrUTQvR3w6QTTBUsCPO0keVyVlpqhbSAdmRwgdtYUute2GVh6d8ptVIzUjOU02dC+KvxjVLfQ93EiqR2yLlBflwGd88U+N0UPCuAeJkiG7KrW3JbM7ysRSE/uMmyhTA4iuTINY5n90mRXYODefddUmQLFcow8ImRDwUWqmvhgD0YLAJXxWoZ4ukcnn7MDLr1EHk91S4BjRB/g2b73RMXLvN76yCr8V9AM2mMUgqN1gYzoj1gHUCt6BdW+c+329IdTqNS2LM X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff17b66b-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 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: 13942303 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83D67232364; Thu, 16 Jan 2025 21:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061876; cv=fail; b=qBv6J1IyFbJrOMVeyJ5aE9bmjPZ6mNb/kk8LsS8RFbx7pywT/KEVfr3yJdSBZTcz1SUAK/2oGhlPdCP8Gwol6tLbiDY5LQ5+nEH44mCM4hpu3vnnOWRo5o/dNhKNoLP64lh7WVIZLlV/aqnyRYxkslvZa5swK/zvF8wmXHjws+Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737061876; c=relaxed/simple; bh=mG+r7wIvm6iSgwaqSfaWBN3zl44eahKVhx72foTGs28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Jh7uo/TY3sq3w+xNIJ4q6wh3XvffOTk60YLAR48cnPCU/VoaOb1Ki50xukdPYPAII2IoSZyH+fcyAa8QNOHRXrrq/r4HuPpCrELrsYwtGGZU9MBLP3u0J2bjDzVJm3qDG7OF4PoDCAN5erCk7yZFhA7wqd4uOh2IYidJxXg3T98= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ZPZfRt35; arc=fail smtp.client-ip=40.107.237.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ZPZfRt35" 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== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; 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) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: JGZy8xx+aOcqBewk6GQrrY//XYpb8NjA56i7m5VX6th/dSgbaFg2tdiSQ2mtM5wJpEJhyID0e5C3KKlYfbvryUNwhjLW5YoCXRgqHwG+3Q7EX76U70n6dOsBGw67jxWYDRFd96Eu3IUHgF0sjLW2MS58DfbUh4wUl9UJRhZ+ABZzLWwXffzk9XPNd117HfywF5OKik+kUHKQyfQqrijVVnCUJBfFnvNN57avKVUvtuz27vxBXP3bnSKraLCslgAiSB0yCBYHAaigAWZ9T8HEe9G44u+1+diNp2QbbhoD7EYVkcoppCyPfM1pN8a05zHIkFguHhGxRm/7kxM//wCVGDKM2UjWiVKK87bwUAdWGNHDIml5InWzyQfR2t6Nr9gGfbBkgWhowCfFibjbNljbrTaDGM+ZfLe/egQYv2J7CbCBRxN1GSzTjptl7inrXdkgv+3jUBoRghFv/vrXnx8huKTpvtqs7cLhnKyFxJj9MnyuZDr9zBe8iB67G1M40MzYIOuyC2pu1Og3qFIiniUrL33R6pk/GdRbRZFirSsFMBbg2MEAF/+Sathyha3NV/ZG8zEJK8MfHqFeVsCTwIRoOuvRRQhA8L3ek3X1Vuix5ZRFI4tVF3QF53ypC89RPZSpBwXkB8fvtcF4sLEiK9XLJTqDy2SKiN+JPTJlcXmTZQ9FPAJKxsaSKkvXvJ2F5RykYWmbkXtdwVWUfSO4QDITQtASuWJX9IfKv7QuZeewvEZ63uCVHJtxBdRVRCqQQTVEMFeusHAo1GcrTEMXm7de5kAYdo9kP6PuMJWzez1WMz5kDNmso5BvA2CJzBMA/jeFM6lmUn16DSwCuRgAp3UFAoATwsVN1c5E2OMaJD+XnXVLmH+H4RzpcULjYqjD1c3VVDaMIFqcJo2qPANDUOuSsxjiHxr76XstSpzXGAQJ6Sp0bVriJhAMga4/7Bb12KwhhJpuISYJv+XRPhYedZzBAiCzUAVqfS/dy2V55jWhFm16diJcSIRF5SYMIHZovKxvgjBUTL567f0RhuY838mQeTUlLsoWvBO+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/2jvxS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Q/LfAg/TKoD4NslPrpbn+Qr44oQ+Ggrnp/O/j7JLgI9Yg1RvKFognrZxA5IjmgOZhgNgcS/5QPBAbg+DxEjX4NNXeyDaLVQTdShJXi1nYZwjbIOMwdKOz0e/tm/kGqdgcExF4UMDCRfvMmopJ5bIXsKjUzby0jVdKXUEV4VCo1qGJ/sDYic5v06DU9g9GpeN/J7jO8n8RWnuLoq1oyXgtEH7dGP7pEm+gHLVs0XlRVBj31odIxBASW1zZAj/hxjvPPUIN1tmtA0qv47ivxIduqUlODDThTcKgx9OBIRdDaB0zqdb2FSq/iUafPMs4HJaTVFJ8hFkddr8CeUvc+mZ7KEP1Oik0RO4SEQ2AJapL7UXJOpKbK9SazIjaEduzbc1Vy7vSxPsEVAk9ex9Augmtrz8ebH7RsB/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 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();