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: 858033 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+CpV7E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; 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: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: 858032 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/JeKRo/dQqXfw+6JARdY+Pdk+UPEvlNpyWNPTjdjEf5l+dhmBAQLbnB9Td1y68ewOfsIBCelyBvR2/OVvr93MIrk1V76Q3Wd/8iKx4ePVqwgteohIs7vglRD9nfXoQoRsLtol5vZx93KotNsmrnpt7nn/9CcdlVhXrjAabbjFnZ+/iBUpiEVbdo4eylNImOnJV4MGCuG55OsM2aRktAtO/P7C8inMf3oCRZ1QkgVx9Vup+8+6dmT8x2KpSpKEEGdr/II47NL78WqtloHCeU0MseGIMFjIUh0Kufq++e0ao30Xrn2ZGe0U9z90WmQC0nLIFSUNMwfWHCffHTF701f+Sreslz9xsxY3z/kpAxodig87Q/rBsL0DwcWnEqABnc7D9zT4VbaS4BBLiYsaRExf8QItEsJErqUg9fIpEkKzb//W+C7bV9WjyEKPUw2yY6L7sj3t/AaYGYW16iqAsjpdR+u+xXlz8Wup7nGnVx63Blk+NiyVM2VP7OY8pn4ZpgzwB8aTacv+nWaWbOQFP69jhK23G3wxwsYnZV85IWqb1zl8hQHQEvPRHhKK1eOR+3qmP7ampwo9dxVqe9EIUkKTvU8PpeUpBVSr1YU2CUwsrEZDw0ax9PWPtLKhaL8m7pMCv9jVotFnGiJ39AXmsENn55blqqkTeKD3Kq48F59zF7UFMu9VYgI+WjsdJjSRqA8de5+UjARpK0P4V2t72qnaSdBNIuN3l3kUQOP5YGC59OX4Mu5Amn1bQQ78z3vhLFu/NSYqASye8xeHIxjo8YU+v95Jl1F75xQPhuagZWaIH0peKvKxlOqCH2eY6QvdXWPVIRbYSgZMLu0OirAvNqyXUNO0d+IzZqQjBcco1JnR3JHrQb7mTvxlK0PoW0Q9j8euMmynotJzWUM8r0tztI/p1IifeEWFBH7b+Y85nXRZBPZtjW7OSykaV08WbJaX+Qm3Z4bdgG1yBb38ZJO5SBbC7DCxqzdpBOybMzvcxfqPT7BPjbD/pQWXraZ+p1PVlN5wF+Nf9fNMqfuIJjhqMfdKvn+dHxgFfZeXH/dbMYopF4p4S1haxOJXhScf2VTKUMhmnc8E2bBFEBP9gbvX6vf3OE5yWgiIdNoKK+Zafpx48tqEu88bGHkPdnivWxLugQLbWsDzBtptjcCcTk6iZXwZdhTr6jSs4VvRzeKXGQ0rwRMi X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR12MB9473.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HOQtCadabhr339CSzlKXDF8yEX9FJsAiNlGR6FP+rBM3rIYUuUtq7xcBkSrBWn5jv2quFEXajYhBeoM9W+MU04g1gJ3nFBvSgZifMplytwOutKU+b1ATTIGMdXtYkae9vGVSGJH0IbAnA3JgKGt3KBmlG+KCNv0IM6W93kHBCDtWXN3am0GZKFDhsEDAIJPfaZI90g/9/pk1oTXsWHLyZg9YJ04kTL/8LKf8/JcW0itoF09i8EkqpbzaS0svtpMp6oRHA6zjFkAcODCVl1Lf7jbg/GL+jCkK/K+fqV9fAEKyIrPGAMcms2pRSgValM/QAIMZB1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y9EiT30sShYAMTgFfx2025nKtBORZ6UQ5ceNuET5O324uyoor093uTpYhXhkGeKVmVtN50awRFkH3RMuhA6PHXW/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: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: 858031 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+YxML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CL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR12MB9473.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ME+dIDvH7UfmRFe0GjEVjq7FHSTha1DiKrqjV8Eu5ATZbrveLtHbETV1waaMEE8OrJ/NxzQYvzCH3CYmfvIxrx1j2bwvjpoBZ/8zGqLa2K/W7KjGZz+OxJCU1CaQKzYkS6afpTK176Q7Hq5PpSq4ZLc0deSbCD675Fv75aheBdIjhv8I21fR4QcfvviWh50FMrKz3V8X7EjWvDLrSjYzu8YHBuaTyYz5HdMH1HzFRL+92+aYVIGBLxqiiF54ZfG5u2qcdyC0U2VxnBSZX1YU5b9kar4rBqgj18f3VBhwBmzGDseHUG9uwdkJRRToMuuVbI/cineUu6joS+LkvUnM/j0XT6yT10SqVSfT2m28SvDnY/3tm6dPvd42PheT7gmjMSfXRYlpYGeWgUXJv6ccaQn3BmEEZxk+tF3fWtN+Q5itJ2/W/lST9rbZE3xRAvy1LoMuCYj0GXVihICbTpkaITT5dZTQ1E4CUdJd/29cF4qLllg7O2Ln8XG8LZGJz3F/u2LCqRr79lR2OjuNg2/oLrfKah3wrZ4QK4kAvoGKeLTJ5bE2HhddexVc/NS78gkNOdV78wnR/7F5e2m3xukq4YP4UIKWOI8w3FJZXfc9GyLzWFbrzvzT2JTnqj+POVo8IcBFyscSGnSNxinFshSucBQh0QzTeWTkeOjV08/+wEInvyqW9Nh9Ur4CODCKGZGnRlJ0U67H97wkvThAa+jYL6ZGeFK0Y5qgMJJbwuGDo4jpcsYVMilF3lFwF3wYGvrCqVuDtqy6reZE2I4QV+sEVA7JyBOt5cqhOQKs2gM6K8YDZAwd/BJtoPAcfuJX0RfH6tBmZ43HwUl6jz/uPrQFkqItJ1Mk1ioL1OkXrAQzRsL9LV//evSU3j8bCuxT8KKcEHsq5NYcp5IdtjDV0SUXh/cyrozLL/amT2WJx4Zmsdo+w3YVKHeLmlgmb4lgb4ArVONJEmn9i2kSej1VrYir2NmIUNMwcZBw7GRgs+Qv8gvEpUsVRreo27FpPGm9dPyGZK1mByaTNyU7SzPjAGQaLZu9BHDamRsmLb+o8gM5Vxi7mEhZ1v+XS8QEZuB/8T5mpffqXtDuK13i29m/tJIuwNCIqmeKofh/M7V+981CMmrLrTbnKeQ8paLgK4jqn3F0pMyxgvgjjYs6HEyL6drX6qfH7euZqUzOr/9U4v8MFsghfxZy5vG6PMl6wM9gwIJ1SwxuGhWTsAw39/TgOaTgjA66vbZjAj227JQzN5M0YqfK+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: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: 858030 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+0cF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BVI5dDX+rf+58cIV0IbnweMRnsQYtah9O9iLm33hg24W+PMuiWP X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR12MB9473.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fEOikwA2HHd58CXC+r3iDUhtrou7NjE0y+W3u56Jk6++vcgOMGo7E7RJFiV2ZHefpZncSXJzxN/lnZelSr5mUmoZ+z8SpAyyUzRBq5GVC4Nvk0OTAmvEeqGz/9llWQM9P/VcxVKxa3GHZnOvn3qo/BZp2BjVKLMcgenHaE5sPsNqUO7FF9UaQyo7/jdmYi3do6E21P0hIATTYqamJ/Xxe+BqHXSzg4WQKJEUGV+Iq1si3hvV0mPAu6YMlv7YS7YSkYrPA+ApL/NXY4bC8JmBb1CjID4yD/C1CpNvBQVd8gEtBODL82UnmBq0chg9ddwEoGD7jnsAWXIrOjQj/hiLu7bU7Ge3p0/d0DWezESilMRAap2ZghF9k9c2us0ePCeDPqOwqYtadLyOXUiF5SNM7tAJm7bpNP62CCui+01FMgOO7C/kIDZ34QPZBxCH/4RAu2FCaKYpx5MC9ew82Ui92ExK++yaA7SXqinwbQmas0F0bw+FudwG+D5vRLCCIwton6RJAkuXC6LattfqPSGsZJYAahNJIfgmra2VxFMruEGdyUSh7xHdSLRmsn5hWFolWQcGyZSMqGtamE5y1EAmg49gD1/nO275T7JBFUT6qge24N71hOEBsJfYoVI45SjIiOtqEsKfcE6ds4IQ1nzKsab/ffhFYuBBa7pZm4HvSYyJb+Kpaja5aM2O0itOw/OcvKbmovz095SuD6K2Wq9N6FEFm8uidY+/Wp+ajSj5Dq+gROSe1zDq4Na5RIvSJ2+3LjOrBbeYIpz1Zh/Q72io1isCKw9MmBJnbn75R40r7tGCe5PQg6HQ8cpV7vhL9sxKD/eGQtGr6v4HTCN/m+EgcYRLsrJ9vnzFXrbQvO2Of3vF3+LHM2qXqCcSKCOH7a/+H0Suyt0hFA1Isp9lGjB8/vgeiS1kTYE5DH2hmJlpw9vh+/MFaFBlTPSop/k9TB83xwkBEZzGsun+DcXp4DXv2yGcM2XHhPB+tZTdEAOeEGCW75IOJpwqDTSd+o5AbpwVliKFSKzeT6RtkX9fiQ8EPuPqiBRl4Tsfp8G6+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: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: 858029 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/EPi33s6kP9vQQTajDInrIWgWxB1v0CaY2H5AjVWMUVUokAt8kIIY2FJXosRUdqya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7OZF8tlq7eMysSSpR0i4UF5yX7JR1HwE9ubz7doYkHulBxUXrSyEBEiY1BaIsULkVtMjn7tjGT4SAy0k0Fq/hJECd++0v7kCK3Bh5i+5kVJDgkU8ejozNNno+bS3V64XKnofP9EJgdgY8njVc/iwcW4GSoowKuusFBNzKU2uiA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR12MB9473.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Aj+37zTQXbfX5cLSDo2GVm3uQSh8cQiKvCV2JMjP8Zi+5oL+XcFijwzckiP7M4wlgvsLwv9Z30Qsr+YmP87hbaZ+YauT93J1z5C7JPVmecnldyU/nSbN0Djmn8qdOqRsRpeIuL1p/l7m/9lCQsnTR8UnRFIiZe1KFHGywMyMbR4G1XLO5kquxGklCpwZpueJu6lmOBwPeKGslstdOt/9KbwS4Opck4Wq7B9xMUFy64QMMYTbpLLR8Pbu9wRf7WFqLDLgUmp4L8rLCt7r70aJ/n0RynBT7FOvrXJilOZh/ZVyVKOVZclv4eK3aCiZSuLe2V48KGHbU0sdXWyIxdrp/l1PDD0P8KGDZR3For9A//drC6q2Gjsyq75m4DU4+Bw3jIxpposylx5gkxpuqJgdK/tAwWLjCBhNA/2k2x6YsM4zI3yLPE+2Mw5BNW/X/MOC2tWhv7I32K7XEfGyT5VD3DeI5EzQVkwK5PPiScv3adPiekV4QK9s1kMm3BYQC5mtNvqXVk+Oz4DvZ2Q3xgim5jPC6lDXRGlIUI7/wt8zealtYLMXpB9DF1fKpCL/Gp0YIcR0NYv2eWNDb3x0BVzyIvn7yyWRnaPT2s24x3bM3VU4WLdPyEdvZMUYp9Tf6MBCiPkvclBzV8ebx/FobxnKDyweAAJRvs393sG0VN8Wl7/l2h4eXi5XEo01hcNpaoNbohPRnnXX/CoVbk65lw9j21BS7+0WekQmAJlif6WZdRKjt+HmLyoE0qLW9Eatjgo6Uy99QDqQaVyU8+nLwNvJrqGstNDPuhQ/1P6CszzsVImofJQr3CctOk/1u6iJUWbe+wo4xpmLbrwIsuU+4PmV8UyecNBHyU/WGuPNIUKV4tFdeyyWpcsNWTx/PIOU2m2sFQnOmtpT38Vol2fjcdcMxtOWZEYxcUSmNcstJ2kJGp47E6+eFGU37jqpI5orVtqOqjz+xJEZsiH+HVDxvUp+DKPEQgR//oQy5PjAtyyeWxaX1xbLyWNMPi/dWbnVLgbLvF5zBwSlYfnAEG61FnjEgG6coUTBPGHnCH591m+qB6G9fkDtzrsjjh4aM/Vh9xbke6VG8teuHo9vq7IR1+9phZaf4ZXXsQ68gnzDYxTzThAwFDQv5uBjV84qjJH25CFHi1pT9OU4Fund4JxF67AKAVn7u4pj2PqLh1Dl4vyZVtB7NF4z0bYgOTwSq1+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);