Skip to contentSkip to conversation

mm/shmem: restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE

PATCH In review Zach O'Keefe 2 participants 2 messages Dec 23, 2022 – Jan 2, 2023

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

PATCH 1/1 mm/shmem: restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE

SHMEM_HUGE_DENY is for emergency use by the admin, to disable allocation of shmem huge pages if, for example, a dangerous bug is found in their
usage: see "deny" in Documentation/mm/transhuge.rst. An app using madvise(,,MADV_COLLAPSE) should not be allowed to override it: restore its precedence over shmem_huge_force.

Fixes 7c6c6cc4d3a2 ("mm/shmem: add flag to enforce shmem THP in hugepage_vma_check()")
Cc Yang Shi <[email protected]>
---
 mm/shmem.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/shmem.c +2 -4
index c301487be5fb..0005ab2c29af 100644
@@ -478,12 +478,10 @@ bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode,
 	if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) ||
 	    test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)))
 		return false;
-	if (shmem_huge_force)
-		return true;
-	if (shmem_huge == SHMEM_HUGE_FORCE)
-		return true;
 	if (shmem_huge == SHMEM_HUGE_DENY)
 		return false;
+	if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE)
+		return true;
 
 	switch (SHMEM_SB(inode->i_sb)->huge) {
 	case SHMEM_HUGE_ALWAYS:
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Zach O'Keefe

SHMEM_HUGE_DENY is for emergency use by the admin, to disable allocation of shmem huge pages if, for example, a dangerous bug is found in their
usage: see "deny" in Documentation/mm/transhuge.rst. An app using madvise(,,MADV_COLLAPSE) should not be allowed to override it: restore its precedence over shmem_huge_force.

Fixes 7c6c6cc4d3a2 ("mm/shmem: add flag to enforce shmem THP in hugepage_vma_check()")
Cc Yang Shi <[email protected]>
---
  mm/shmem.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
mm/shmem.c +0 -1
index c301487be5fb..0005ab2c29af 100644
@@ -478,12 +478,10 @@ bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode,
  	if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) ||
  	    test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)))
  		return false;
-	if (shmem_huge_force)

mm/shmem.c bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, · line 487

Quoted 10 lines
mm/shmem.c +2 -3
-		return true;
-	if (shmem_huge == SHMEM_HUGE_FORCE)
-		return true;
  	if (shmem_huge == SHMEM_HUGE_DENY)
  		return false;
+	if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE)
+		return true;
 
  	switch (SHMEM_SB(inode->i_sb)->huge) {
  	case SHMEM_HUGE_ALWAYS:

Looks sane to me

Signature · 3 lines
Thanks,

David / dhildenb