From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7ADA1302CD5 for ; Mon, 18 May 2026 21:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779141559; cv=none; b=l2ZycrtHO3ZT9QU48fmaFGWqN5F7UHfI1sG4bGsG1YdZD7LUBU1cW/lzzDDYNqeUC3Z/RIeuCzecqveGHpzwrVMw4M33RX84QSULE7aIkn+nhCBjTHMQXq2ElnxDxJ/0QZFCd8aDKyN01fy1i7Kb0/ZbIK9VsDuF01Kwu9s+Bnk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779141559; c=relaxed/simple; bh=w+gVdrPhpdUrGYws+dIOQVxZbZQoYO7JBu+wYInuh4A=; h=Date:To:From:Subject:Message-Id; b=tde8PmkPjwQqzY9gI/OxbXBcTu0eYNLkXFn05Ew0aAgxWQkmE7tipyP6iwYA/LMv+n7utgZxgx4QCStQOL7aghTjhCLKi5zulrgtc64Y2ppfk4VK9oShQyf7QdvDmnPe7NKvVrt8rEGaE54kSv2B4eQzAoeWiFx9N6VEs/LoDoc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=0rJuQG5V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="0rJuQG5V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05187C2BCB7; Mon, 18 May 2026 21:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1779141559; bh=w+gVdrPhpdUrGYws+dIOQVxZbZQoYO7JBu+wYInuh4A=; h=Date:To:From:Subject:From; b=0rJuQG5VKgoW+mTqLVIE7verA1j7AYxjy1X047aSFIMMQutAx79JgzUdtlVF3qTD6 6sU/szKJIOkAhXu+ZPEGSII3Pn6fSs2EKjQlkCHyvsqxq+YJLAeFsjLNiI3zYECy/w txQYcApdkcRzpFlwQobXOJUpvNB5j1p+0l1Vc4mU= Date: Mon, 18 May 2026 14:59:18 -0700 To: mm-commits@vger.kernel.org,ziy@nvidia.com,akpm@linux-foundation.org From: Andrew Morton Subject: [to-be-updated] mm-khugepaged-remove-read_only_thp_for_fs-check.patch removed from -mm tree Message-Id: <20260518215919.05187C2BCB7@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The quilt patch titled Subject: mm/khugepaged: remove READ_ONLY_THP_FOR_FS check has been removed from the -mm tree. Its filename was mm-khugepaged-remove-read_only_thp_for_fs-check.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ From: Zi Yan Subject: mm/khugepaged: remove READ_ONLY_THP_FOR_FS check Date: Wed, 29 Apr 2026 11:29:11 -0400 Patch series "Remove CONFIG_READ_ONLY_THP_FOR_FS and enable file THP for writable files", v5. This patchset removes READ_ONLY_THP_FOR_FS Kconfig and enables creating file-backed THPs for FSes with large folio support (the supported orders need to include PMD_ORDER) by default, including for writable files. This patch (of 14): Before the patchset, the status of creating read-only THPs is below: | PF | MADV_COLLAPSE | khugepaged | |-----------|---------------|------------| large folio FSes only | ✓ | x | x | READ_ONLY_THP_FOR_FS only | x | ✓ | ✓ | both | ✓ | ✓ | ✓ | where READ_ONLY_THP_FOR_FS implies no large folio FSes. Now without READ_ONLY_THP_FOR_FS: | PF | MADV_COLLAPSE | khugepaged | |-----------|---------------|------------| large folio FSes (read-only fd) | ✓ | ✓ | ✓ | large folio FSes (read-write fd) | ✓ | ✓ | ✓* | no large folio FSes | x | x | x | * khugepaged only collapses clean folios from writable files. Userspace must flush dirty folios explicitly before khugepaged can collapse them. MADV_COLLAPSE handles the flush automatically via its writeback-and-retry path. Collapsing writable MAP_PRIVATE pagecache folios is still not supported, since PMD THP CoW only faults in at PTE level to avoid long CoW latency, and file_backed_vma_is_retractable() prevents it. This means no-large-folio FSes need to add large folio support (the supported orders need to include PMD_ORDER), so that they can leverage file THP creation. To prevent breaking file THP support for large folio FSes, 1. first 4 patches enable the support, so that without READ_ONLY_THP_FOR_FS, file THP still works for large folio FSes, 2. Patch 5 removes READ_ONLY_THP_FOR_FS Kconfig, 3. patches 6-12 remove code related to READ_ONLY_THP_FOR_FS, 4. patches 13-14 enable clean pagecache folio collapse for writable files. NOTE: collapsing writable MAP_PRIVATE pagecache folios is not supported, since: 1. PMD THP CoW only faults in at PTE level to avoid long CoW latency, 2. the first check, due to 1, in file_backed_vma_is_retractable() prevents it. Overview ======== 1. collapse_file() checks for to-be-collapsed folio dirtiness after they are locked and unmapped to make sure no new write happens. Before, mapping->nr_thps and inode->i_writecount were used to cause read-only THP truncation before a fd becomes writable. 2. hugepage_enabled() is true for anon, shmem, and file-backed cases if the global khugepaged control is on, otherwise, khugepaged for file-backed case is turned off and anon and shmem depend on per-size control knobs. 3. collapse_file() from mm/khugepaged.c, instead of checking CONFIG_READ_ONLY_THP_FOR_FS, makes sure the mapping_max_folio_order() of struct address_space of the file is at least PMD_ORDER. 4. file_thp_enabled() checks mapping_max_folio_order() instead of CONFIG_READ_ONLY_THP_FOR_FS and no longer checks if the file is opened read-only. The dirty folio check after try_to_unmap() (Change 1) handles writable files correctly. 5. truncate_inode_partial_folio() calls folio_split() directly instead of the removed try_folio_split_to_order(), since large folios can only show up on a FS with large folio support. 6. nr_thps is removed from struct address_space, since it is no longer needed to drop all read-only THPs from a FS without large folio support when the fd becomes writable. Its related filemap_nr_thps*() are removed too. 7. folio_check_splittable() no longer checks READ_ONLY_THP_FOR_FS. 8. collapse_file() only calls filemap_flush() for read-only files. Blindly flushing dirty folios from writable files would cause undesirable system-wide writeback; userspace is expected to flush explicitly, or use MADV_COLLAPSE which handles it via its retry path. 9. Updated comments and selftests in various places. This patch (of 14): collapse_file() requires FSes supporting large folio with at least PMD_ORDER, so replace the READ_ONLY_THP_FOR_FS check with that. MADV_COLLAPSE ignores shmem huge config, so exclude the check for shmem. While at it, replace VM_BUG_ON with VM_WARN_ON_ONCE. Add a helper function mapping_pmd_folio_support() for FSes supporting large folio with at least PMD_ORDER. Link: https://lore.kernel.org/20260429152924.727124-1-ziy@nvidia.com Link: https://lore.kernel.org/20260429152924.727124-2-ziy@nvidia.com Link: https://lore.kernel.org/all/20260323190644.1714379-1-ziy@nvidia.com/ [1] Link: https://lore.kernel.org/all/20260327014255.2058916-1-ziy@nvidia.com/ [2] Link: https://lore.kernel.org/all/20260413192030.3275825-1-ziy@nvidia.com/ [3] Link: https://lore.kernel.org/all/20260418024429.4055056-1-ziy@nvidia.com/ [4] Link: https://lore.kernel.org/all/20260424024915.28758-1-ziy@nvidia.com/ [5] Signed-off-by: Zi Yan Reviewed-by: Lance Yang Reviewed-by: Baolin Wang Acked-by: David Hildenbrand (Arm) Reviewed-by: Nico Pache Cc: Al Viro Cc: Barry Song Cc: Chris Mason Cc: Christian Brauner Cc: David Sterba Cc: Dev Jain Cc: Jan Kara Cc: Liam Howlett Cc: Lorenzo Stoakes Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Mike Rapoport Cc: Ryan Roberts Cc: Shuah Khan Cc: Song Liu Cc: Suren Baghdasaryan Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- include/linux/pagemap.h | 26 ++++++++++++++++++++++++++ mm/khugepaged.c | 10 ++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) --- a/include/linux/pagemap.h~mm-khugepaged-remove-read_only_thp_for_fs-check +++ a/include/linux/pagemap.h @@ -513,6 +513,32 @@ static inline bool mapping_large_folio_s return mapping_max_folio_order(mapping) > 0; } +/** + * mapping_pmd_folio_support() - Check if a mapping support PMD-sized folio + * @mapping: The address_space + * + * Some file supports large folio but does not support as large as PMD order. + * If a PMD-sized pagecache folio is attempted to be created on a filesystem, + * this check needs to be performed first. + * + * Return: true - PMD-sized folio is supported, false - PMD-sized folio is not + * supported. + */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline bool mapping_pmd_folio_support(const struct address_space *mapping) +{ + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */ + VM_WARN_ON_ONCE((unsigned long)mapping & FOLIO_MAPPING_ANON); + + return mapping_max_folio_order(mapping) >= PMD_ORDER; +} +#else +static inline bool mapping_pmd_folio_support(const struct address_space *mapping) +{ + return false; +} +#endif + /* Return the maximum folio size for this pagecache mapping, in bytes. */ static inline size_t mapping_max_folio_size(const struct address_space *mapping) { --- a/mm/khugepaged.c~mm-khugepaged-remove-read_only_thp_for_fs-check +++ a/mm/khugepaged.c @@ -2243,8 +2243,14 @@ static enum scan_result collapse_file(st int nr_none = 0; bool is_shmem = shmem_file(file); - VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem); - VM_BUG_ON(start & (HPAGE_PMD_NR - 1)); + /* + * MADV_COLLAPSE ignores shmem huge config, so do not check shmem + * + * TODO: once shmem always calls mapping_set_large_folios() on its + * mapping, the shmem check can be removed. + */ + VM_WARN_ON_ONCE(!is_shmem && !mapping_pmd_folio_support(mapping)); + VM_WARN_ON_ONCE(start & (HPAGE_PMD_NR - 1)); result = alloc_charge_folio(&new_folio, mm, cc, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) _ Patches currently in -mm which might be from ziy@nvidia.com are mm-khugepaged-remove-read_only_thp_for_fs-check-fix.patch mm-khugepaged-add-folio-dirty-check-after-try_to_unmap.patch mm-huge_memory-remove-read_only_thp_for_fs-from-file_thp_enabled.patch mm-khugepaged-remove-read_only_thp_for_fs-check-in-hugepage_enabled.patch mm-remove-read_only_thp_for_fs-kconfig-option.patch mm-fs-remove-filemap_nr_thps-functions-and-their-users.patch fs-remove-nr_thps-from-struct-address_space.patch mm-huge_memory-remove-folio-split-check-for-read_only_thp_for_fs.patch mm-truncate-use-folio_split-in-truncate_inode_partial_folio.patch fs-btrfs-remove-a-comment-referring-to-read_only_thp_for_fs.patch selftests-mm-remove-read_only_thp_for_fs-in-khugepaged.patch selftests-mm-remove-read_only_thp_for_fs-in-khugepaged-fix.patch selftests-mm-remove-read_only_thp_for_fs-in-khugepaged-fix-2.patch selftests-mm-remove-read_only_thp_for_fs-code-from-guard-regions.patch mm-khugepaged-enable-clean-pagecache-folio-collapse-for-writable-files.patch selftests-mm-add-writable-file-collapse-tests-for-khugepaged.patch