Message ID | 20241010061024.1846220-2-wangkefeng.wang@huawei.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: cleanup thp and shmem allowable order check | expand |
On 10.10.24 08:10, Kefeng Wang wrote: > The file_thp_enabled() 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. I would hope the compiler is smart enough. But this way is clearer Acked-by: David Hildenbrand <david@redhat.com>
On 2024/10/10 14:10, Kefeng Wang wrote: > The file_thp_enabled() 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. > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> LGTM. Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> > --- > include/linux/huge_mm.h | 13 ------------- > mm/huge_memory.c | 15 +++++++++++++++ > 2 files changed, 15 insertions(+), 13 deletions(-) > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > index 3eca60f3d512..795df660efa5 100644 > --- a/include/linux/huge_mm.h > +++ b/include/linux/huge_mm.h > @@ -253,19 +253,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, > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index cc346c771921..d23e4aab7511 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -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,
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 3eca60f3d512..795df660efa5 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -253,19 +253,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, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index cc346c771921..d23e4aab7511 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -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,
The file_thp_enabled() 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. Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> --- include/linux/huge_mm.h | 13 ------------- mm/huge_memory.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-)