mm: huge_memory: move file_thp_enabled() into huge_memory.c
authorKefeng Wang <wangkefeng.wang@huawei.com>
Thu, 17 Oct 2024 14:14:56 +0000 (22:14 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 7 Nov 2024 04:11:15 +0000 (20:11 -0800)
file_thp_enabled() is only used in __thp_vma_allowable_orders(), so move
it into huge_memory.c, also check READ_ONLY_THP_FOR_FS ahead to avoid
unnecessary code if config disabled.

Link: https://lkml.kernel.org/r/20241017141457.1169092-1-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/huge_mm.h
mm/huge_memory.c

index 8afe09a2cf03b0531da34eb67497cedf67276e6f..006f730545c2a97d9b3064788443ff22c6519951 100644 (file)
@@ -252,19 +252,6 @@ static inline unsigned long thp_vma_suitable_orders(struct vm_area_struct *vma,
        return orders;
 }
 
-static inline bool file_thp_enabled(struct vm_area_struct *vma)
-{
-       struct inode *inode;
-
-       if (!vma->vm_file)
-               return false;
-
-       inode = vma->vm_file->f_inode;
-
-       return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) &&
-              !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
-}
-
 unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
                                         unsigned long vm_flags,
                                         unsigned long tva_flags,
index 73194aa0544cec00d43f3d91c1b4f02dbaac51f6..492c16eaf147ac98336ad9539c486ada5c9f0e0f 100644 (file)
@@ -83,6 +83,21 @@ unsigned long huge_anon_orders_madvise __read_mostly;
 unsigned long huge_anon_orders_inherit __read_mostly;
 static bool anon_orders_configured __initdata;
 
+static inline bool file_thp_enabled(struct vm_area_struct *vma)
+{
+       struct inode *inode;
+
+       if (!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS))
+               return false;
+
+       if (!vma->vm_file)
+               return false;
+
+       inode = file_inode(vma->vm_file);
+
+       return !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
+}
+
 unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
                                         unsigned long vm_flags,
                                         unsigned long tva_flags,