Skip to contentSkip to conversation

mm: huge_memory: move file_thp_enabled() into huge_memory.c

PATCH Applied Kefeng Wang 2 participants 5 messages Oct 17, 2024 – Nov 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm: huge_memory: move file_thp_enabled() into huge_memory.c

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.

---
v2:
- Add ACK/RB and send separately

 include/linux/huge_mm.h | 13 -------------
 mm/huge_memory.c        | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 13 deletions(-)
include/linux/huge_mm.h +0 -13
index d5f824d5e1c5..c59e5aa9b081 100644
@@ -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,
mm/huge_memory.c +15 -0
index 589876d14bb8..830d6aa5bf97 100644
@@ -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,
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/1 mm: shmem: remove __shmem_huge_global_enabled()

Remove __shmem_huge_global_enabled() since only one caller, and remove repeated check of VM_NOHUGEPAGE/MMF_DISABLE_THP as they are checked in shmem_allowable_huge_orders(), also remove unnecessary vma parameter.

---
v2:
- Add RB and send separately

 mm/shmem.c | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)
mm/shmem.c +10 -23
index 247c0403af83..e933327d8dac 100644
@@ -548,17 +548,15 @@ static bool shmem_confirm_swap(struct address_space *mapping,
 
 static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER;
 
-static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
-					loff_t write_end, bool shmem_huge_force,
-					struct vm_area_struct *vma,
-					unsigned long vm_flags)
+static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
+				      loff_t write_end, bool shmem_huge_force,
+				      unsigned long vm_flags)
 {
-	struct mm_struct *mm = vma ? vma->vm_mm : NULL;
 	loff_t i_size;
 
-	if (!S_ISREG(inode->i_mode))
+	if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER)
 		return false;
-	if (mm && ((vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &mm->flags)))
+	if (!S_ISREG(inode->i_mode))
 		return false;
 	if (shmem_huge == SHMEM_HUGE_DENY)
 		return false;
@@ -576,7 +574,7 @@ static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
 			return true;
 		fallthrough;
 	case SHMEM_HUGE_ADVISE:
-		if (mm && (vm_flags & VM_HUGEPAGE))
+		if (vm_flags & VM_HUGEPAGE)
 			return true;
 		fallthrough;
 	default:
@@ -584,17 +582,6 @@ static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
 	}
 }
 
-static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
-		   loff_t write_end, bool shmem_huge_force,
-		   struct vm_area_struct *vma, unsigned long vm_flags)
-{
-	if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER)
-		return false;
-
-	return __shmem_huge_global_enabled(inode, index, write_end,
-					   shmem_huge_force, vma, vm_flags);
-}
-
 #if defined(CONFIG_SYSFS)
 static int shmem_parse_huge(const char *str)
 {
@@ -772,8 +759,8 @@ static unsigned long shmem_unused_huge_shrink(struct shmem_sb_info *sbinfo,
 }
 
 static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
-		loff_t write_end, bool shmem_huge_force,
-		struct vm_area_struct *vma, unsigned long vm_flags)
+				      loff_t write_end, bool shmem_huge_force,
+				      unsigned long vm_flags)
 {
 	return false;
 }
@@ -1170,7 +1157,7 @@ static int shmem_getattr(struct mnt_idmap *idmap,
 	generic_fillattr(idmap, request_mask, inode, stat);
 	inode_unlock_shared(inode);
 
-	if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0))
+	if (shmem_huge_global_enabled(inode, 0, 0, false, 0))
 		stat->blksize = HPAGE_PMD_SIZE;
 
 	if (request_mask & STATX_BTIME) {
@@ -1686,7 +1673,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
 		return 0;
 
 	global_huge = shmem_huge_global_enabled(inode, index, write_end,
-					shmem_huge_force, vma, vm_flags);
+						shmem_huge_force, vm_flags);
 	if (!vma || !vma_is_anon_shmem(vma)) {
 		/*
 		 * For tmpfs, we now only support PMD sized THP if huge page
Signature · 1 line
2.27.0
#2 lore raw

Re: [PATCH v2] mm: shmem: remove __shmem_huge_global_enabled()

Quoted 19 lines · Kefeng Wang

Remove __shmem_huge_global_enabled() since only one caller, and remove repeated check of VM_NOHUGEPAGE/MMF_DISABLE_THP as they are checked in shmem_allowable_huge_orders(), also remove unnecessary vma parameter.

---
v2:
- Add RB and send separately

  mm/shmem.c | 33 ++++++++++-----------------------
  1 file changed, 10 insertions(+), 23 deletions(-)
mm/shmem.c +0 -0
index 247c0403af83..e933327d8dac 100644

mm/shmem.c static bool shmem_confirm_swap(struct address_space *mapping, · line 553

Quoted 10 lines
mm/shmem.c +3 -4
@@ -548,17 +548,15 @@ static bool shmem_confirm_swap(struct address_space *mapping,
 
  static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER;
 
-static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
-					loff_t write_end, bool shmem_huge_force,
-					struct vm_area_struct *vma,
-					unsigned long vm_flags)
+static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t index,
+				      loff_t write_end, bool shmem_huge_force,
+				      unsigned long vm_flags)

Please use double tabs on the second+ parameter list.

mm/shmem.c static bool shmem_confirm_swap(struct address_space *mapping, · line 561

Quoted 8 lines
mm/shmem.c +1 -3
  {
-	struct mm_struct *mm = vma ? vma->vm_mm : NULL;
  	loff_t i_size;
 
-	if (!S_ISREG(inode->i_mode))
+	if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER)
  		return false;
-	if (mm && ((vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &mm->flags)))

But where is this check for shmem_getattr()?

Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw

Re: [PATCH v2] mm: shmem: remove __shmem_huge_global_enabled()

Quoted 25 lines · David Hildenbrand
Quoted 24 lines · Kefeng Wang

Remove __shmem_huge_global_enabled() since only one caller, and remove repeated check of VM_NOHUGEPAGE/MMF_DISABLE_THP as they are checked in shmem_allowable_huge_orders(), also remove unnecessary vma parameter.

---
v2:
- Add RB and send separately

  mm/shmem.c | 33 ++++++++++-----------------------

  1 file changed, 10 insertions(+), 23 deletions(-)
mm/shmem.c +0 -2
index 247c0403af83..e933327d8dac 100644
@@ -548,17 +548,15 @@ static bool shmem_confirm_swap(struct 
 address_space *mapping,
   static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER;
-static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t 
 index,
-                    loff_t write_end, bool shmem_huge_force,
Quoted 8 lines

mm/shmem.c static bool shmem_confirm_swap(struct address_space *mapping, · line 553

Quoted 6 lines
mm/shmem.c +3 -2
-                    struct vm_area_struct *vma,
-                    unsigned long vm_flags)
+static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t 
 index,
+                      loff_t write_end, bool shmem_huge_force,
+                      unsigned long vm_flags)

Please use double tabs on the second+ parameter list.

Ok, I will send a tab fix patch.

Quoted 11 lines

mm/shmem.c static bool shmem_confirm_swap(struct address_space *mapping,

Quoted 9 lines
mm/shmem.c +1 -3
   {
-    struct mm_struct *mm = vma ? vma->vm_mm : NULL;
       loff_t i_size;
-    if (!S_ISREG(inode->i_mode))
+    if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER)
           return false;
-    if (mm && ((vm_flags & VM_NOHUGEPAGE) || 
 test_bit(MMF_DISABLE_THP, &mm->flags)))

But where is this check for shmem_getattr()?

In shmem_getattr(), the vma=NULL/vm_flags=0, so only vm_flags check is enough.

- if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0))
+ if (shmem_huge_global_enabled(inode, 0, 0, false, 0))

#4 lore raw

Re: [PATCH v2] mm: shmem: remove __shmem_huge_global_enabled()

Quoted 56 lines · Kefeng Wang
Quoted 25 lines · David Hildenbrand
Quoted 24 lines · Kefeng Wang

Remove __shmem_huge_global_enabled() since only one caller, and remove repeated check of VM_NOHUGEPAGE/MMF_DISABLE_THP as they are checked in shmem_allowable_huge_orders(), also remove unnecessary vma parameter.

---
v2:
- Add RB and send separately

   mm/shmem.c | 33 ++++++++++-----------------------
   1 file changed, 10 insertions(+), 23 deletions(-)
mm/shmem.c +0 -2
index 247c0403af83..e933327d8dac 100644
@@ -548,17 +548,15 @@ static bool shmem_confirm_swap(struct
 address_space *mapping,
   static int shmem_huge __read_mostly = SHMEM_HUGE_NEVER;
-static bool __shmem_huge_global_enabled(struct inode *inode, pgoff_t
 index,
-                    loff_t write_end, bool shmem_huge_force,
Quoted 8 lines

mm/shmem.c static bool shmem_confirm_swap(struct address_space *mapping, · line 553

Quoted 6 lines
mm/shmem.c +3 -2
-                    struct vm_area_struct *vma,
-                    unsigned long vm_flags)
+static bool shmem_huge_global_enabled(struct inode *inode, pgoff_t
 index,
+                      loff_t write_end, bool shmem_huge_force,
+                      unsigned long vm_flags)

Please use double tabs on the second+ parameter list.

Ok, I will send a tab fix patch.

Quoted 11 lines

mm/shmem.c static bool shmem_confirm_swap(struct address_space *mapping,

Quoted 9 lines
mm/shmem.c +1 -3
   {
-    struct mm_struct *mm = vma ? vma->vm_mm : NULL;
       loff_t i_size;
-    if (!S_ISREG(inode->i_mode))
+    if (HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER)
           return false;
-    if (mm && ((vm_flags & VM_NOHUGEPAGE) ||
 test_bit(MMF_DISABLE_THP, &mm->flags)))

But where is this check for shmem_getattr()?

In shmem_getattr(), the vma=NULL/vm_flags=0, so only vm_flags check is enough.

mm/shmem.c static int shmem_getattr(struct mnt_idmap *idmap, · line 1160

Quoted 2 lines
mm/shmem.c +1 -1
-	if (shmem_huge_global_enabled(inode, 0, 0, false, NULL, 0))
+	if (shmem_huge_global_enabled(inode, 0, 0, false, 0))

Ah, missed that, makes perfect sense!

Signature · 3 lines
Cheers,

David / dhildenb