[PATCH v2 2/2] smaps: set THPeligible if file mapping supports large folios

From: Zach O'Keefe
Date: Fri Aug 18 2023 - 17:16:23 EST


File-backed memory can be backed by THPs either through collapse, when
CONFIG_READ_ONLY_THP_FOR_FS is enabled, or through fault, when the
filesystem supports large folio mappings.

Currently, smaps only knows about the former, so teach it about the
latter.

Signed-off-by: Zach O'Keefe <zokeefe@xxxxxxxxxx>
Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
---
mm/huge_memory.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index cd379b2c077b..d8d6e83820f3 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -136,7 +136,16 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags,
*/
!!vma->vm_ops->huge_fault :
/* Only regular file is valid in collapse path */
- file_thp_enabled(vma);
+ file_thp_enabled(vma) ||
+ /*
+ * THPeligible bit of smaps should surface the
+ * possibility of THP through fault if the filesystem
+ * supports it. We don't check this in fault path,
+ * because we want to fallback to the actual ->fault()
+ * handler to make the decision.
+ */
+ (smaps && vma->vm_file &&
+ mapping_large_folio_support(vma->vm_file->f_mapping));

if (vma_is_temporary_stack(vma))
return false;
--
2.42.0.rc1.204.g551eb34607-goog