summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorKefeng Wang <wangkefeng.wang@huawei.com>2026-07-17 17:13:46 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-07-27 18:33:27 -0700
commit514c0a3a6d2ddae200677b6a3a8c1ba9f8afe8f0 (patch)
tree878b55f8b4284a2d541b84d7fca09409db02a988 /mm
parentc9639155269d69d0cd2ecdd4c97a031087bf760f (diff)
downloadlinux-next-514c0a3a6d2ddae200677b6a3a8c1ba9f8afe8f0.tar.gz
linux-next-514c0a3a6d2ddae200677b6a3a8c1ba9f8afe8f0.zip
mm: mincore: improve mincore_hugetlb()
walk_hugetlb_range() always passes a non-NULL pte, so remove the dead NULL check. Replace the per-page iteration loop with memset() for better performance. Link: https://lore.kernel.org/20260717091347.1144789-6-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: Pedro Falcato <pfalcato@suse.de> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Cc: Jann Horn <jannh@google.com> Cc: Liam R. Howlett <liam@infradead.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/mincore.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/mm/mincore.c b/mm/mincore.c
index 16059ed47711..5b37317429fc 100644
--- a/mm/mincore.c
+++ b/mm/mincore.c
@@ -28,30 +28,17 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr,
unsigned long end, struct mm_walk *walk)
{
#ifdef CONFIG_HUGETLB_PAGE
- unsigned char present;
+ unsigned long nr = (end - addr) >> PAGE_SHIFT;
unsigned char *vec = walk->private;
+ unsigned char resident;
spinlock_t *ptl;
+ pte_t ptep;
ptl = huge_pte_lock(hstate_vma(walk->vma), walk->mm, pte);
-
- /*
- * Hugepages under user process are always in RAM and never
- * swapped out, but theoretically it needs to be checked.
- */
- if (!pte) {
- present = 0;
- } else {
- const pte_t ptep = huge_ptep_get(walk->mm, addr, pte);
-
- if (huge_pte_none(ptep) || pte_is_marker(ptep))
- present = 0;
- else
- present = 1;
- }
-
- for (; addr != end; vec++, addr += PAGE_SIZE)
- *vec = present;
- walk->private = vec;
+ ptep = huge_ptep_get(walk->mm, addr, pte);
+ resident = !huge_pte_none(ptep) && !pte_is_marker(ptep);
+ memset(vec, resident, nr);
+ walk->private += nr;
spin_unlock(ptl);
#else
BUG();