linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Hugh Dickins <hughd@google.com>,
	David Hildenbrand <david@redhat.com>,
	Barry Song <baohua@kernel.org>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Matthew Wilcox <willy@infradead.org>, <linux-mm@kvack.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH 2/3] mm: huge_memory: add thp_vma_disabled()
Date: Thu, 10 Oct 2024 14:10:23 +0800	[thread overview]
Message-ID: <20241010061024.1846220-3-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20241010061024.1846220-1-wangkefeng.wang@huawei.com>

Add thp_vma_disabled() helper to shared by shmem_allowable_huge_orders()
and __thp_vma_allowable_orders().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/huge_mm.h | 19 +++++++++++++++++++
 mm/huge_memory.c        | 13 +------------
 mm/shmem.c              |  7 +------
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 795df660efa5..d77891332b35 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -309,6 +309,25 @@ struct thpsize {
 	(transparent_hugepage_flags &					\
 	 (1<<TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG))
 
+static inline bool thp_vma_disabled(struct vm_area_struct *vma,
+				    unsigned long vm_flags)
+{
+	/*
+	 * Explicitly disabled through madvise or prctl, or some
+	 * architectures may disable THP for some mappings, for
+	 * example, s390 kvm.
+	 */
+	if (vma && ((vm_flags & VM_NOHUGEPAGE) ||
+	     test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)))
+		return true;
+
+	/* If the hardware/firmware marked hugepage support disabled. */
+	if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED))
+		return true;
+
+	return false;
+}
+
 unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr,
 		unsigned long len, unsigned long pgoff, unsigned long flags);
 unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr,
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index d23e4aab7511..30912a93f7dc 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -123,18 +123,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma,
 	if (!vma->vm_mm)		/* vdso */
 		return 0;
 
-	/*
-	 * Explicitly disabled through madvise or prctl, or some
-	 * architectures may disable THP for some mappings, for
-	 * example, s390 kvm.
-	 * */
-	if ((vm_flags & VM_NOHUGEPAGE) ||
-	    test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))
-		return 0;
-	/*
-	 * If the hardware/firmware marked hugepage support disabled.
-	 */
-	if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED))
+	if (thp_vma_disabled(vma, vm_flags))
 		return 0;
 
 	/* khugepaged doesn't collapse DAX vma, but page fault is fine. */
diff --git a/mm/shmem.c b/mm/shmem.c
index 0a2f78c2b919..34a31e7e527c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1683,12 +1683,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,
 	loff_t i_size;
 	int order;
 
-	if (vma && ((vm_flags & VM_NOHUGEPAGE) ||
-	    test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)))
-		return 0;
-
-	/* If the hardware/firmware marked hugepage support disabled. */
-	if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED))
+	if (thp_vma_disabled(vma, vm_flags))
 		return 0;
 
 	global_huge = shmem_huge_global_enabled(inode, index, write_end,
-- 
2.27.0



  parent reply	other threads:[~2024-10-10  6:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10  6:10 [PATCH 0/3] mm: cleanup thp and shmem allowable order check Kefeng Wang
2024-10-10  6:10 ` [PATCH 1/3] mm: huge_memory: move file_thp_enabled() into huge_memory.c Kefeng Wang
2024-10-10 12:56   ` David Hildenbrand
2024-10-12  3:27   ` Baolin Wang
2024-10-10  6:10 ` Kefeng Wang [this message]
2024-10-10 12:58   ` [PATCH 2/3] mm: huge_memory: add thp_vma_disabled() David Hildenbrand
2024-10-10 14:41   ` David Hildenbrand
2024-10-10 14:53     ` David Hildenbrand
2024-10-11  0:40       ` Kefeng Wang
2024-10-11 10:00         ` David Hildenbrand
2024-10-10  6:10 ` [PATCH 3/3] mm: shmem: remove __shmem_huge_global_enabled() Kefeng Wang
2024-10-12  3:38   ` Baolin Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241010061024.1846220-3-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox