Skip to contentSkip to conversation

mm: introduce pud_is_huge() helper

PATCH New David Hildenbrand (Arm) 2 participants 6 messages Jul 20 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

David Hildenbrand (Arm)

author Acked-by
#2 lore raw
Quoted 8 lines · Kefeng Wang

Introduce the pud_is_huge() helper function to check whether a PUD is a huge PUD or a software leaf entry. Note that, unlike PMD, PUD currently does not support transparent migration entries or device private entries. However, the function still includes !pud_none() branches to accommodate potential future implementations.

---

One day we'll probably clean all this up (once we figure out how :) ), for now this matches pmd_is_huge().

Signature · 3 lines
Cheers,

David

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Acked-by
#4 lore raw

Re: [PATCH v3 2/6] mm: mincore: remove special handling for VM_PFNMAP

Quoted 20 lines · Kefeng Wang

As David pointed out, "it’s hard to believe that someone depends on pages in VM_PFNMAP to *not* be present", so remove the historical behavior that always reports VM_PFNMAP pages as non-resident.

Adding mincore_pud_range() allows the page table walker to traverse the full page table hierarchy without splitting a huge PUD, enabling much more precise identification of resident pages in PFNMAP VMAs.

---
 mm/mincore.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
mm/mincore.c +0 -0
index 53b982803771..3fccaa5c96f8 100644

mm/mincore.c static int mincore_unmapped_range(unsigned long addr, unsigned long end, · line 163

Quoted 4 lines
mm/mincore.c +1 -0
@@ -160,6 +160,21 @@ static int mincore_unmapped_range(unsigned long addr, unsigned long end,
 	return 0;
 }
 
+static int mincore_pud_range(pud_t *pudp, unsigned long addr, unsigned long end,

s/mincore_pud_range/mincore_pud_entry/

mm/mincore.c static int mincore_unmapped_range(unsigned long addr, unsigned long end, · line 167

Quoted 4 lines
mm/mincore.c +4 -0
+		struct mm_walk *walk)
+{
+	if (pud_is_huge(pudp_get(pudp))) {
+		int nr = (end - addr) >> PAGE_SHIFT;

Could be const.

mm/mincore.c static int mincore_unmapped_range(unsigned long addr, unsigned long end, · line 168

Quoted 1 line
mm/mincore.c +1 -0
+		unsigned char *vec = walk->private;

Might be able to just cast that as part of the memset.

mm/mincore.c static int mincore_unmapped_range(unsigned long addr, unsigned long end, · line 176

Quoted 8 lines
mm/mincore.c +8 -0
+
+		memset(vec, 1, nr);
+		walk->action = ACTION_CONTINUE;
+		walk->private += nr;
+	}
+
+	return 0;
+}

With the rename

Signature · 3 lines
Cheers,

David
#5 lore raw

Re: [PATCH v3 2/6] mm: mincore: remove special handling for VM_PFNMAP

In reply to a message not in the archive
Quoted 20 lines · Kefeng Wang

As David pointed out, "it’s hard to believe that someone depends on pages in VM_PFNMAP to *not* be present", so remove the historical behavior that always reports VM_PFNMAP pages as non-resident.

Adding mincore_pud_range() allows the page table walker to traverse the full page table hierarchy without splitting a huge PUD, enabling much more precise identification of resident pages in PFNMAP VMAs.

---
 mm/mincore.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
mm/mincore.c +0 -0
index 53b982803771..3fccaa5c96f8 100644

mm/mincore.c static int mincore_unmapped_range(unsigned long addr, unsigned long end, · line 167

Quoted 8 lines
mm/mincore.c +5 -0
@@ -160,6 +160,21 @@ static int mincore_unmapped_range(unsigned long addr, unsigned long end,
 	return 0;
 }
 
+static int mincore_pud_range(pud_t *pudp, unsigned long addr, unsigned long end,
+		struct mm_walk *walk)
+{
+	if (pud_is_huge(pudp_get(pudp))) {
+		int nr = (end - addr) >> PAGE_SHIFT;

Ah, and best to use an unsigned long here for consistency.

Signature · 3 lines
Cheers,

David
#6 lore raw

PATCH 2/6 mm: mincore: fixup for remove special handling for VM_PFNMAP

In reply to a message not in the archive

Address David's comments
- rename mincore_pud_range to mincore_pud_entry
- change int nr to const unsigned long
- remove a local vec variable

---
 mm/mincore.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
mm/mincore.c +5 -6
index d7841a38b54a..9ea81638d09f 100644
@@ -146,16 +146,15 @@ static int mincore_unmapped_range(unsigned long addr, unsigned long end,
 	return 0;
 }
 
-static int mincore_pud_range(pud_t *pudp, unsigned long addr, unsigned long end,
+static int mincore_pud_entry(pud_t *pudp, unsigned long addr, unsigned long end,
 		struct mm_walk *walk)
 {
 	if (pud_is_huge(pudp_get(pudp))) {
-		int nr = (end - addr) >> PAGE_SHIFT;
-		unsigned char *vec = walk->private;
+		const unsigned long nr = (end - addr) >> PAGE_SHIFT;
 
-		memset(vec, 1, nr);
-		walk->action = ACTION_CONTINUE;
+		memset(walk->private, 1, nr);
 		walk->private += nr;
+		walk->action = ACTION_CONTINUE;
 	}
 
 	return 0;
@@ -233,7 +232,7 @@ static inline bool can_do_mincore(struct vm_area_struct *vma)
 }
 
 static const struct mm_walk_ops mincore_walk_ops = {
-	.pud_entry		= mincore_pud_range,
+	.pud_entry		= mincore_pud_entry,
 	.pmd_entry		= mincore_pte_range,
 	.pte_hole		= mincore_unmapped_range,
 	.hugetlb_entry		= mincore_hugetlb,
Signature · 1 line
2.55.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Acked-by
#8 lore raw

Re: [PATCH v3 5/6] mm: mincore: improve mincore_hugetlb()

Quoted 15 lines · Kefeng Wang

The 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.

---
 mm/mincore.c | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)
mm/mincore.c +0 -0
index ba7d1fc320a3..e825d11a7c7e 100644

mm/mincore.c static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, · line 31

Quoted 5 lines
mm/mincore.c +1 -1
@@ -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;

Can be const.

Signature · 3 lines
Cheers,

David
#9 lore raw

PATCH 5/6 mm: mincore: fixup improve mincore_hugetlb()

In reply to a message not in the archive

- change unsigned long nr to const
- remove a local vec variable

---
 mm/mincore.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/mincore.c +2 -3
index 9ea81638d09f..ff4ac8281768 100644
@@ -28,8 +28,7 @@ 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 long nr = (end - addr) >> PAGE_SHIFT;
-	unsigned char *vec = walk->private;
+	const unsigned long nr = (end - addr) >> PAGE_SHIFT;
 	unsigned char resident;
 	spinlock_t *ptl;
 	pte_t ptep;
@@ -37,7 +36,7 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr,
 	ptl = huge_pte_lock(hstate_vma(walk->vma), walk->mm, pte);
 	ptep = huge_ptep_get(walk->mm, addr, pte);
 	resident = !huge_pte_none(ptep) && !pte_is_marker(ptep);
-	memset(vec, resident, nr);
+	memset(walk->private, resident, nr);
 	walk->private += nr;
 	spin_unlock(ptl);
 #else
Signature · 1 line
2.55.0