[PATCH] shmem: optimize shmem_huge_enabled() and shmem_is_huge() when !CONFIG_TRANSPARENT_HUGEPAGE

From: Yann Droneaud
Date: Thu Jan 05 2023 - 18:05:00 EST


When CONFIG_TRANSPARENT_HUGEPAGE is not set, shmem_is_huge() is not needed
outside of shmem.c.

Signed-off-by: Yann Droneaud <ydroneaud@xxxxxxxxxx>
---
include/linux/shmem_fs.h | 9 +++++++++
mm/shmem.c | 4 ++--
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
index d500ea967dc7..18a4968ded73 100644
--- a/include/linux/shmem_fs.h
+++ b/include/linux/shmem_fs.h
@@ -92,6 +92,7 @@ extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
int shmem_unuse(unsigned int type);

+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
extern bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode,
pgoff_t index, bool shmem_huge_force);
static inline bool shmem_huge_enabled(struct vm_area_struct *vma,
@@ -100,6 +101,14 @@ static inline bool shmem_huge_enabled(struct vm_area_struct *vma,
return shmem_is_huge(vma, file_inode(vma->vm_file), vma->vm_pgoff,
shmem_huge_force);
}
+#else /* !CONFIG_TRANSPARENT_HUGEPAGE */
+static inline bool shmem_huge_enabled(struct vm_area_struct *vma,
+ bool shmem_huge_force)
+{
+ return false;
+}
+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
+
extern unsigned long shmem_swap_usage(struct vm_area_struct *vma);
extern unsigned long shmem_partial_swap_usage(struct address_space *mapping,
pgoff_t start, pgoff_t end);
diff --git a/mm/shmem.c b/mm/shmem.c
index c301487be5fb..9437c200a311 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -678,8 +678,8 @@ static long shmem_unused_huge_count(struct super_block *sb,

#define shmem_huge SHMEM_HUGE_DENY

-bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode,
- pgoff_t index, bool shmem_huge_force)
+static inline bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode,
+ pgoff_t index, bool shmem_huge_force)
{
return false;
}
--
2.37.2