Skip to contentSkip to conversation

mm: pagewalk: huge page cleanups and VMA passing

PATCH In review Dave Hansen 3 participants 20 messages Jun 2, 2014 – Jun 3, 2014 3 messages not in the archive

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

cover mm: pagewalk: huge page cleanups and VMA passing

The hugetlbfs and THP support in the walk_page_range() code was mostly an afterthought.

We also _tried_ to have the pagewalk code be concerned only with page tables and *NOT* VMAs. We lost that battle since 80% of the page walkers just pass the VMA along anyway.

This does a few cleanups and adds a new flavor of walker which can be stupid^Wsimple and not have to be explicitly taught about THP.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 1/10 mm: pagewalk: consolidate vma->vm_start checks

From: Dave Hansen <[email protected]>

We check vma->vm_start against the address being walked twice. Consolidate the locations down to a single one.

---

 b/mm/pagewalk.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
mm/pagewalk.c renamed from mm/pagewalk.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled +3 -5
diff -puN mm/pagewalk.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled mm/pagewalk.c
@@ -192,13 +192,12 @@ int walk_page_range(unsigned long addr,
 		 * - VM_PFNMAP vma's
 		 */
 		vma = find_vma(walk->mm, addr);
-		if (vma) {
+		if (vma && (vma->vm_start <= addr)) {
 			/*
 			 * There are no page structures backing a VM_PFNMAP
 			 * range, so do not allow split_huge_page_pmd().
 			 */
-			if ((vma->vm_start <= addr) &&
-			    (vma->vm_flags & VM_PFNMAP)) {
+			if (vma->vm_flags & VM_PFNMAP) {
 				next = vma->vm_end;
 				pgd = pgd_offset(walk->mm, next);
 				continue;
@@ -209,8 +208,7 @@ int walk_page_range(unsigned long addr,
 			 * architecture and we can't handled it in the same
 			 * manner as non-huge pages.
 			 */
-			if (walk->hugetlb_entry && (vma->vm_start <= addr) &&
-			    is_vm_hugetlb_page(vma)) {
+			if (walk->hugetlb_entry && is_vm_hugetlb_page(vma)) {
 				if (vma->vm_end < next)
 					next = vma->vm_end;
 				/*

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

PATCH 2/10 mm: pagewalk: always skip hugetlbfs except when explicitly handled

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

The short story:

The walk_page_range() code is fragile for hugetlbfs VMAs. Each walker instance must either exclude hugetlbfs from being walked, or add a ->hugetlb_entry handler. If this is not done, the code will go off the rails and start clearing huge page table entries.

This patch removes that requirement on the walkers. They can merrily call walk_page_range() on hugetlbfs areas, and those areas will simply be skipped inside the page walker code if they have not set up a handler.

This makes the code more robust, shorter, and makes it more intuitive to write a page table walker. Yay.

Long story:

I was looking at the page walker code and thought I found a bug. If the walker hits a hugetlbfs VMA where walk->hugetlb_entry was not set, it would hit the if(), and the clear out the pgd thinking it was bad.

This essentially means that *EVERY* page walker has to *KNOW* to either exclude hugetlbfs VMAs, or set a ->hugetlb_entry handler. The good news is that all 9 users of walk_page_range() do this implicitly or explicitly. The bad news is that it took me an hour to convince myself of this, and future walk_page_range() instances are vulnerable to making this mistake. I think the madvise() use was probably just lucky (details below).

Here's the code trimmed down. Note what happens if we have a is_vm_hugetlb_page(), !walk->hugetlb_entry, and a huge page pgd entry in 'pgd' (or any of the lower levels).

int walk_page_range(unsigned long addr, unsigned long end, ... {
...

	vma = find_vma(walk->mm, addr);
        if (vma) {
		if (walk->hugetlb_entry && is_vm_hugetlb_page(vma)) {
			walk_hugetlb_range(vma, addr, next, walk);
			...
			continue;
		}
	}
	if (pgd_none_or_clear_bad(pgd)) {

There are currently 9 users of walk_page_range(). They handle hugetlbfs pages in 5 ways:

/proc/$pid/smaps:
/proc/$pid/clear_refs:
cgroup precharge:
cgroup move charge:
checks VMA explicitly for hugetblfs and skips, does not set ->hugetlb_entry (this patch removes the now unnecessary hugetlbfs checks for these)

openrisc dma alloc:
works on kernel memory, so no hugetlbfs, also arch does not even support hugetlbfs

powerpc subpage protection:
uses arch-specific is_hugepage_only_range() check

/proc/$pid/pagemap:
/proc/$pid/numa_map:

	sets ->hugetlb_entry
	(these are unaffected by this patch)

MADV_WILLNEED:

	does not set ->hugetlb_entry
	only called via:
	madvise_willneed() {
		if (!vma->file)
			force_swapin_readahead(...) {
				walk_page_range(...)
			}
	}
	That !vma->file check just _happens_ to cover hugetlbfs
  	vmas since they are always file-backed (or at least have
	vma->file set as far as I can tell)

	(this case is unaffected by this patch)

---

 b/fs/proc/task_mmu.c |    4 +---
 b/mm/memcontrol.c    |    4 ----
 b/mm/pagewalk.c      |    5 ++++-
 3 files changed, 5 insertions(+), 8 deletions(-)
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled-1 +1 -3
diff -puN fs/proc/task_mmu.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled-1 fs/proc/task_mmu.c
@@ -590,7 +590,7 @@ static int show_smap(struct seq_file *m,
 	memset(&mss, 0, sizeof mss);
 	mss.vma = vma;
 	/* mmap_sem is held in m_start */
-	if (vma->vm_mm && !is_vm_hugetlb_page(vma))
+	if (vma->vm_mm)
 		walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
 
 	show_map_vma(m, vma, is_pid);
@@ -829,8 +829,6 @@ static ssize_t clear_refs_write(struct f
 			mmu_notifier_invalidate_range_start(mm, 0, -1);
 		for (vma = mm->mmap; vma; vma = vma->vm_next) {
 			cp.vma = vma;
-			if (is_vm_hugetlb_page(vma))
-				continue;
 			/*
 			 * Writing 1 to /proc/pid/clear_refs affects all pages.
 			 *
mm/memcontrol.c renamed from mm/memcontrol.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled-1 +0 -4
diff -puN mm/memcontrol.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled-1 mm/memcontrol.c
@@ -6821,8 +6821,6 @@ static unsigned long mem_cgroup_count_pr
 			.mm = mm,
 			.private = vma,
 		};
-		if (is_vm_hugetlb_page(vma))
-			continue;
 		walk_page_range(vma->vm_start, vma->vm_end,
 					&mem_cgroup_count_precharge_walk);
 	}
@@ -7087,8 +7085,6 @@ retry:
 			.mm = mm,
 			.private = vma,
 		};
-		if (is_vm_hugetlb_page(vma))
-			continue;
 		ret = walk_page_range(vma->vm_start, vma->vm_end,
 						&mem_cgroup_move_charge_walk);
 		if (ret)
mm/pagewalk.c renamed from mm/pagewalk.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled-1 +4 -1
diff -puN mm/pagewalk.c~pagewalk-always-skip-hugetlbfs-except-when-explicitly-handled-1 mm/pagewalk.c
@@ -115,6 +115,9 @@ static int walk_hugetlb_range(struct vm_
 	pte_t *pte;
 	int err = 0;
 
+	if (!walk->hugetlb_entry)
+		return 0;
+
 	do {
 		next = hugetlb_entry_end(h, addr, end);
 		pte = huge_pte_offset(walk->mm, addr & hmask);
@@ -208,7 +211,7 @@ int walk_page_range(unsigned long addr,
 			 * architecture and we can't handled it in the same
 			 * manner as non-huge pages.
 			 */
-			if (walk->hugetlb_entry && is_vm_hugetlb_page(vma)) {
+			if (is_vm_hugetlb_page(vma)) {
 				if (vma->vm_end < next)
 					next = vma->vm_end;
 				/*

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

PATCH 3/10 mm: pagewalk: have generic code keep track of VMA

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

7 out of 9 of the page walkers need the VMA and pass it in some way through mm_walk->private. Let's add it in the page walker infrastructure.

This will increase the number of find_vma() calls, but the VMA cache should help us out pretty nicely here. This is also quite easy to optimize if this turns out to be an issue by skipping the find_vma() call if 'addr' is still within our current mm_walk->vma.

/proc/$pid/numa_map:
/proc/$pid/smaps:
lots of stuff including vma (vma is a drop in the bucket) in a struct
/proc/$pid/clear_refs:
passes vma plus an enum in a struct
/proc/$pid/pagemap:
openrisc:
no VMA
MADV_WILLNEED:

	walk->private is set to vma
cgroup precharge:
	walk->private is set to vma
cgroup move charge:
	walk->private is set to vma
powerpc subpages:
	walk->private is set to vma

---

 b/arch/powerpc/mm/subpage-prot.c |    3 --
 b/fs/proc/task_mmu.c             |   25 ++++++---------------
 b/include/linux/mm.h             |    1 
 b/mm/madvise.c                   |    3 --
 b/mm/memcontrol.c                |    4 +--
 b/mm/pagewalk.c                  |   45 ++++++++++++++++++++++++++++++++++-----
 6 files changed, 52 insertions(+), 29 deletions(-)
arch/powerpc/mm/subpage-prot.c renamed from arch/powerpc/mm/subpage-prot.c~page-walker-pass-vma +1 -2
diff -puN arch/powerpc/mm/subpage-prot.c~page-walker-pass-vma arch/powerpc/mm/subpage-prot.c
@@ -134,7 +134,7 @@ static void subpage_prot_clear(unsigned
 static int subpage_walk_pmd_entry(pmd_t *pmd, unsigned long addr,
 				  unsigned long end, struct mm_walk *walk)
 {
-	struct vm_area_struct *vma = walk->private;
+	struct vm_area_struct *vma = walk->vma;
 	split_huge_page_pmd(vma, addr, pmd);
 	return 0;
 }
@@ -163,7 +163,6 @@ static void subpage_mark_vma_nohuge(stru
 		if (vma->vm_start >= (addr + len))
 			break;
 		vma->vm_flags |= VM_NOHUGEPAGE;
-		subpage_proto_walk.private = vma;
 		walk_page_range(vma->vm_start, vma->vm_end,
 				&subpage_proto_walk);
 		vma = vma->vm_next;
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~page-walker-pass-vma +7 -18
diff -puN fs/proc/task_mmu.c~page-walker-pass-vma fs/proc/task_mmu.c
@@ -424,7 +424,6 @@ const struct file_operations proc_tid_ma
 
 #ifdef CONFIG_PROC_PAGE_MONITOR
 struct mem_size_stats {
-	struct vm_area_struct *vma;
 	unsigned long resident;
 	unsigned long shared_clean;
 	unsigned long shared_dirty;
@@ -443,7 +442,7 @@ static void smaps_pte_entry(pte_t ptent,
 		unsigned long ptent_size, struct mm_walk *walk)
 {
 	struct mem_size_stats *mss = walk->private;
-	struct vm_area_struct *vma = mss->vma;
+	struct vm_area_struct *vma = walk->vma;
 	pgoff_t pgoff = linear_page_index(vma, addr);
 	struct page *page = NULL;
 	int mapcount;
@@ -495,7 +494,7 @@ static int smaps_pte_range(pmd_t *pmd, u
 			   struct mm_walk *walk)
 {
 	struct mem_size_stats *mss = walk->private;
-	struct vm_area_struct *vma = mss->vma;
+	struct vm_area_struct *vma = walk->vma;
 	pte_t *pte;
 	spinlock_t *ptl;
 
@@ -588,7 +587,6 @@ static int show_smap(struct seq_file *m,
 	};
 
 	memset(&mss, 0, sizeof mss);
-	mss.vma = vma;
 	/* mmap_sem is held in m_start */
 	if (vma->vm_mm)
 		walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
@@ -712,7 +710,6 @@ enum clear_refs_types {
 };
 
 struct clear_refs_private {
-	struct vm_area_struct *vma;
 	enum clear_refs_types type;
 };
 
@@ -748,7 +745,7 @@ static int clear_refs_pte_range(pmd_t *p
 				unsigned long end, struct mm_walk *walk)
 {
 	struct clear_refs_private *cp = walk->private;
-	struct vm_area_struct *vma = cp->vma;
+	struct vm_area_struct *vma = walk->vma;
 	pte_t *pte, ptent;
 	spinlock_t *ptl;
 	struct page *page;
@@ -828,7 +825,6 @@ static ssize_t clear_refs_write(struct f
 		if (type == CLEAR_REFS_SOFT_DIRTY)
 			mmu_notifier_invalidate_range_start(mm, 0, -1);
 		for (vma = mm->mmap; vma; vma = vma->vm_next) {
-			cp.vma = vma;
 			/*
 			 * Writing 1 to /proc/pid/clear_refs affects all pages.
 			 *
@@ -1073,15 +1069,11 @@ static int pagemap_hugetlb_range(pte_t *
 				 struct mm_walk *walk)
 {
 	struct pagemapread *pm = walk->private;
-	struct vm_area_struct *vma;
 	int err = 0;
 	int flags2;
 	pagemap_entry_t pme;
 
-	vma = find_vma(walk->mm, addr);
-	WARN_ON_ONCE(!vma);
-
-	if (vma && (vma->vm_flags & VM_SOFTDIRTY))
+	if (walk->vma && (walk->vma->vm_flags & VM_SOFTDIRTY))
 		flags2 = __PM_SOFT_DIRTY;
 	else
 		flags2 = 0;
@@ -1241,7 +1233,6 @@ const struct file_operations proc_pagema
 #ifdef CONFIG_NUMA
 
 struct numa_maps {
-	struct vm_area_struct *vma;
 	unsigned long pages;
 	unsigned long anon;
 	unsigned long active;
@@ -1317,11 +1308,11 @@ static int gather_pte_stats(pmd_t *pmd,
 
 	md = walk->private;
 
-	if (pmd_trans_huge_lock(pmd, md->vma, &ptl) == 1) {
+	if (pmd_trans_huge_lock(pmd, walk->vma, &ptl) == 1) {
 		pte_t huge_pte = *(pte_t *)pmd;
 		struct page *page;
 
-		page = can_gather_numa_stats(huge_pte, md->vma, addr);
+		page = can_gather_numa_stats(huge_pte, walk->vma, addr);
 		if (page)
 			gather_stats(page, md, pte_dirty(huge_pte),
 				     HPAGE_PMD_SIZE/PAGE_SIZE);
@@ -1333,7 +1324,7 @@ static int gather_pte_stats(pmd_t *pmd,
 		return 0;
 	orig_pte = pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
 	do {
-		struct page *page = can_gather_numa_stats(*pte, md->vma, addr);
+		struct page *page = can_gather_numa_stats(*pte, walk->vma, addr);
 		if (!page)
 			continue;
 		gather_stats(page, md, pte_dirty(*pte), 1);
@@ -1392,8 +1383,6 @@ static int show_numa_map(struct seq_file
 	/* Ensure we start with an empty set of numa_maps statistics. */
 	memset(md, 0, sizeof(*md));
 
-	md->vma = vma;
-
 	walk.hugetlb_entry = gather_hugetbl_stats;
 	walk.pmd_entry = gather_pte_stats;
 	walk.private = md;
include/linux/mm.h renamed from include/linux/mm.h~page-walker-pass-vma +1 -0
diff -puN include/linux/mm.h~page-walker-pass-vma include/linux/mm.h
@@ -1118,6 +1118,7 @@ struct mm_walk {
 			     unsigned long addr, unsigned long next,
 			     struct mm_walk *walk);
 	struct mm_struct *mm;
+	struct vm_area_struct *vma;
 	void *private;
 };
 
mm/madvise.c renamed from mm/madvise.c~page-walker-pass-vma +1 -2
diff -puN mm/madvise.c~page-walker-pass-vma mm/madvise.c
@@ -139,7 +139,7 @@ static int swapin_walk_pmd_entry(pmd_t *
 	unsigned long end, struct mm_walk *walk)
 {
 	pte_t *orig_pte;
-	struct vm_area_struct *vma = walk->private;
+	struct vm_area_struct *vma = walk->vma;
 	unsigned long index;
 
 	if (pmd_none_or_trans_huge_or_clear_bad(pmd))
@@ -176,7 +176,6 @@ static void force_swapin_readahead(struc
 	struct mm_walk walk = {
 		.mm = vma->vm_mm,
 		.pmd_entry = swapin_walk_pmd_entry,
-		.private = vma,
 	};
 
 	walk_page_range(start, end, &walk);
mm/memcontrol.c renamed from mm/memcontrol.c~page-walker-pass-vma +2 -2
diff -puN mm/memcontrol.c~page-walker-pass-vma mm/memcontrol.c
@@ -6786,7 +6786,7 @@ static int mem_cgroup_count_precharge_pt
 					unsigned long addr, unsigned long end,
 					struct mm_walk *walk)
 {
-	struct vm_area_struct *vma = walk->private;
+	struct vm_area_struct *vma = walk->vma;
 	pte_t *pte;
 	spinlock_t *ptl;
 
@@ -6962,7 +6962,7 @@ static int mem_cgroup_move_charge_pte_ra
 				struct mm_walk *walk)
 {
 	int ret = 0;
-	struct vm_area_struct *vma = walk->private;
+	struct vm_area_struct *vma = walk->vma;
 	pte_t *pte;
 	spinlock_t *ptl;
 	enum mc_target_type target_type;
mm/pagewalk.c renamed from mm/pagewalk.c~page-walker-pass-vma +40 -5

95 lines not on this page · raw message

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

PATCH 4/10 mm: pagewalk: add page walker for mincore()

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

This converts the sys_mincore() code over to use the walk_page_range() infrastructure. This provides some pretty nice code savings.

Note that the (now removed) comment:

/*
* Huge pages are always in RAM for now, but
* theoretically it needs to be checked. */

is bogus and has been for years. We started demand-faulting them long ago. Thank goodness theory matters!

---

 b/mm/mincore.c |  123 +++++++++++++++++----------------------------------------
 1 file changed, 37 insertions(+), 86 deletions(-)
mm/mincore.c renamed from mm/mincore.c~mincore-page-walker-0 +37 -86
diff -puN mm/mincore.c~mincore-page-walker-0 mm/mincore.c
@@ -19,38 +19,29 @@
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 
-static void mincore_hugetlb_page_range(struct vm_area_struct *vma,
-				unsigned long addr, unsigned long end,
-				unsigned char *vec)
+static int mincore_hugetlb_page_range(pte_t *ptep, unsigned long hmask,
+					unsigned long addr, unsigned long end,
+					struct mm_walk *walk)
 {
 #ifdef CONFIG_HUGETLB_PAGE
-	struct hstate *h;
-
-	h = hstate_vma(vma);
+	unsigned char *vec = walk->private;
 	while (1) {
-		unsigned char present;
-		pte_t *ptep;
-		/*
-		 * Huge pages are always in RAM for now, but
-		 * theoretically it needs to be checked.
-		 */
-		ptep = huge_pte_offset(current->mm,
-				       addr & huge_page_mask(h));
-		present = ptep && !huge_pte_none(huge_ptep_get(ptep));
+		int present = !huge_pte_none(huge_ptep_get(ptep));
 		while (1) {
 			*vec = present;
 			vec++;
 			addr += PAGE_SIZE;
 			if (addr == end)
-				return;
+				return 0;
 			/* check hugepage border */
-			if (!(addr & ~huge_page_mask(h)))
+			if (!(addr & hmask))
 				break;
 		}
 	}
 #else
 	BUG();
 #endif
+	return 0;
 }
 
 /*
@@ -94,10 +85,11 @@ static unsigned char mincore_page(struct
 	return present;
 }
 
-static void mincore_unmapped_range(struct vm_area_struct *vma,
-				unsigned long addr, unsigned long end,
-				unsigned char *vec)
+static int mincore_unmapped_range(unsigned long addr, unsigned long end,
+				struct mm_walk *walk)
 {
+	struct vm_area_struct *vma = walk->vma;
+	unsigned char *vec = walk->private;
 	unsigned long nr = (end - addr) >> PAGE_SHIFT;
 	int i;
 
@@ -111,27 +103,35 @@ static void mincore_unmapped_range(struc
 		for (i = 0; i < nr; i++)
 			vec[i] = 0;
 	}
+	return 0;
 }
 
-static void mincore_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
-			unsigned long addr, unsigned long end,
-			unsigned char *vec)
+static int mincore_pte_range(pmd_t *pmd,
+			     unsigned long addr, unsigned long end,
+			     struct mm_walk *walk)
 {
+	struct vm_area_struct *vma = walk->vma;
+	unsigned char *vec = walk->private;
 	unsigned long next;
 	spinlock_t *ptl;
 	pte_t *ptep;
 
+	if (pmd_trans_huge(*pmd)) {
+		int success = mincore_huge_pmd(vma, pmd, addr, end, vec);
+		if (success)
+			return 0;
+		/* the trans huge pmd just split, handle as small */
+	}
+
 	ptep = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
 	do {
 		pte_t pte = *ptep;
 		pgoff_t pgoff;
 
 		next = addr + PAGE_SIZE;
-		if (pte_none(pte))
-			mincore_unmapped_range(vma, addr, next, vec);
-		else if (pte_present(pte))
+		if (pte_present(pte)) {
 			*vec = 1;
-		else if (pte_file(pte)) {
+		} else if (pte_file(pte)) {
 			pgoff = pte_to_pgoff(pte);
 			*vec = mincore_page(vma->vm_file->f_mapping, pgoff);
 		} else { /* pte is a swap entry */
@@ -154,67 +154,21 @@ static void mincore_pte_range(struct vm_
 		vec++;
 	} while (ptep++, addr = next, addr != end);
 	pte_unmap_unlock(ptep - 1, ptl);
-}
-
-static void mincore_pmd_range(struct vm_area_struct *vma, pud_t *pud,
-			unsigned long addr, unsigned long end,
-			unsigned char *vec)
-{
-	unsigned long next;
-	pmd_t *pmd;
-
-	pmd = pmd_offset(pud, addr);
-	do {
-		next = pmd_addr_end(addr, end);
-		if (pmd_trans_huge(*pmd)) {
-			if (mincore_huge_pmd(vma, pmd, addr, next, vec)) {
-				vec += (next - addr) >> PAGE_SHIFT;
-				continue;
-			}
-			/* fall through */
-		}
-		if (pmd_none_or_trans_huge_or_clear_bad(pmd))
-			mincore_unmapped_range(vma, addr, next, vec);
-		else
-			mincore_pte_range(vma, pmd, addr, next, vec);
-		vec += (next - addr) >> PAGE_SHIFT;
-	} while (pmd++, addr = next, addr != end);
-}
-
-static void mincore_pud_range(struct vm_area_struct *vma, pgd_t *pgd,
-			unsigned long addr, unsigned long end,
-			unsigned char *vec)
-{
-	unsigned long next;
-	pud_t *pud;
-
-	pud = pud_offset(pgd, addr);
-	do {
-		next = pud_addr_end(addr, end);
-		if (pud_none_or_clear_bad(pud))
-			mincore_unmapped_range(vma, addr, next, vec);
-		else
-			mincore_pmd_range(vma, pud, addr, next, vec);
-		vec += (next - addr) >> PAGE_SHIFT;
-	} while (pud++, addr = next, addr != end);
+	return 0;
 }
 
 static void mincore_page_range(struct vm_area_struct *vma,
 			unsigned long addr, unsigned long end,
 			unsigned char *vec)
 {
-	unsigned long next;
-	pgd_t *pgd;
-
-	pgd = pgd_offset(vma->vm_mm, addr);
-	do {
-		next = pgd_addr_end(addr, end);
-		if (pgd_none_or_clear_bad(pgd))
-			mincore_unmapped_range(vma, addr, next, vec);
-		else
-			mincore_pud_range(vma, pgd, addr, next, vec);
-		vec += (next - addr) >> PAGE_SHIFT;
-	} while (pgd++, addr = next, addr != end);
+	struct mm_walk mincore_walk = {
+		.pte_hole      = mincore_unmapped_range,
+		.pmd_entry     = mincore_pte_range,
+		.hugetlb_entry = mincore_hugetlb_page_range,
+		.private = vec,
+		.mm = vma->vm_mm,
+	};
+	walk_page_range(vma->vm_start, vma->vm_end, &mincore_walk);
 }
 
 /*
@@ -233,10 +187,7 @@ static long do_mincore(unsigned long add
 
 	end = min(vma->vm_end, addr + (pages << PAGE_SHIFT));
 
-	if (is_vm_hugetlb_page(vma))
-		mincore_hugetlb_page_range(vma, addr, end, vec);
-	else
-		mincore_page_range(vma, addr, end, vec);
+	mincore_page_range(vma, addr, end, vec);
 
 	return (end - addr) >> PAGE_SHIFT;
 }

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

PATCH 5/10 mm: mincore: clean up hugetlbfs handling (part 1)

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

The page walker functions are only called _via_ the page walker. I don't see this changing any time soon. The page walker only calls walk->hugetlb_entry() under an #ifdef CONFIG_HUGETLB_PAGE.

With this in place, I think putting BUG()s in the ->hugetlb_entry handlers is a bit like wearing a belt and suspenders.

This axes the BUG() from the mincore ->hugetlb_entry along with the #ifdef. The compiler is more than smart enough to do the right thing when it sees:

	if (1)
		return;
	// unreachable

The only downside here is that we now need some header stubs for huge_pte_none() / huge_pte_get().

---

 b/include/linux/hugetlb.h |   10 ++++++++++
 b/mm/mincore.c            |    9 +++++----
 2 files changed, 15 insertions(+), 4 deletions(-)
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~cleanup-hugetlbfs-mincore-1 +10 -0
diff -puN include/linux/hugetlb.h~cleanup-hugetlbfs-mincore-1 include/linux/hugetlb.h
@@ -458,6 +458,16 @@ static inline spinlock_t *huge_pte_lockp
 {
 	return &mm->page_table_lock;
 }
+static inline int huge_pte_none(pte_t pte)
+{
+	WARN_ONCE(1, "%s() called when hugetlbfs disabled", __func__);
+	return 1;
+}
+static inline pte_t huge_ptep_get(pte_t *pte)
+{
+	WARN_ONCE(1, "%s() called when hugetlbfs disabled", __func__);
+	return __pte(0);
+}
 #endif	/* CONFIG_HUGETLB_PAGE */
 
 static inline spinlock_t *huge_pte_lock(struct hstate *h,
mm/mincore.c renamed from mm/mincore.c~cleanup-hugetlbfs-mincore-1 +5 -4
diff -puN mm/mincore.c~cleanup-hugetlbfs-mincore-1 mm/mincore.c
@@ -23,8 +23,12 @@ static int mincore_hugetlb_page_range(pt
 					unsigned long addr, unsigned long end,
 					struct mm_walk *walk)
 {
-#ifdef CONFIG_HUGETLB_PAGE
 	unsigned char *vec = walk->private;
+
+	/* This is as good as an explicit ifdef */
+	if (!is_vm_hugetlb_page(walk->vma))
+		return 0;
+
 	while (1) {
 		int present = !huge_pte_none(huge_ptep_get(ptep));
 		while (1) {
@@ -38,9 +42,6 @@ static int mincore_hugetlb_page_range(pt
 				break;
 		}
 	}
-#else
-	BUG();
-#endif
 	return 0;
 }
 

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

PATCH 6/10 mm: mincore: clean up hugetlbfs handler (part 2)

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

The walk_page_range() code calls in to the ->hugetlbfs_entry handler once for each huge page table entry. This means that addr and end are always within the same huge page. (Well, end is not technically _within_ it, because it is exclusive.)

The outer while() loop in mincore_hugetlb_page_range() appears to be designed to work if we crossed a huge page boundary to a new huge pte and 'present' changed. However, that is impossible for two reasons:

1. The above-mentioned walk_page_range() restriction
2. We never move ptep

So the outer while() along with the check for crossing the end of the huge page boundary (which is impossible) make no sense. Once we peel it off, it's clear that we can just make the 'return' in to the loop condition.

---

 b/mm/mincore.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
mm/mincore.c renamed from mm/mincore.c~cleanup-hugetlbfs-mincore-2 +6 -12
diff -puN mm/mincore.c~cleanup-hugetlbfs-mincore-2 mm/mincore.c
@@ -24,23 +24,17 @@ static int mincore_hugetlb_page_range(pt
 					struct mm_walk *walk)
 {
 	unsigned char *vec = walk->private;
+	int present;
 
 	/* This is as good as an explicit ifdef */
 	if (!is_vm_hugetlb_page(walk->vma))
 		return 0;
 
-	while (1) {
-		int present = !huge_pte_none(huge_ptep_get(ptep));
-		while (1) {
-			*vec = present;
-			vec++;
-			addr += PAGE_SIZE;
-			if (addr == end)
-				return 0;
-			/* check hugepage border */
-			if (!(addr & hmask))
-				break;
-		}
+	present = !huge_pte_none(huge_ptep_get(ptep));
+	while (addr < end) {
+		*vec = present;
+		vec++;
+		addr += PAGE_SIZE;
 	}
 	return 0;
 }

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

PATCH 7/10 mm: pagewalk: kill check for hugetlbfs inside /proc pagemap code

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

The page map code does not call the normal handlers for hugetlbfs areas. They are handled by ->hugetlb_entry exclusively, so remove the check for it.

---

 b/fs/proc/task_mmu.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~do-not-check-for-hugetlbfs-inside-pagemap-walker +1 -2
diff -puN fs/proc/task_mmu.c~do-not-check-for-hugetlbfs-inside-pagemap-walker fs/proc/task_mmu.c
@@ -1033,8 +1033,7 @@ static int pagemap_pte_range(pmd_t *pmd,
 
 		/* check that 'vma' actually covers this address,
 		 * and that it isn't a huge page vma */
-		if (vma && (vma->vm_start <= addr) &&
-		    !is_vm_hugetlb_page(vma)) {
+		if (vma && (vma->vm_start <= addr)) {
 			pte = pte_offset_map(pmd, addr);
 			pte_to_pagemap_entry(&pme, pm, vma, addr, *pte);
 			/* unmap before userspace copy */

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

PATCH 8/10 mm: pagewalk: add locked pte walker

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

Neither the locking nor the splitting logic needed for transparent huge pages is trivial. We end up having to teach each of the page walkers about it individually, and have the same pattern copied across several of them.

This patch introduces a new handler: ->locked_single_entry. It does two things: it handles the page table locking, including the difference between pmds and ptes, and it lets you have a single handler for large and small pages.

This greatly simplifies the handlers. I only implemented this for two of the walk_page_range() users for now. I believe this can at least be applied to a few more of them going forward.

---

 b/include/linux/mm.h |    7 +++++++
 b/mm/pagewalk.c      |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
include/linux/mm.h renamed from include/linux/mm.h~mm-pagewalk-add-locked-walker +7 -0
diff -puN include/linux/mm.h~mm-pagewalk-add-locked-walker include/linux/mm.h
@@ -1096,6 +1096,11 @@ void unmap_vmas(struct mmu_gather *tlb,
  *	       pmd_trans_huge() pmds.  They may simply choose to
  *	       split_huge_page() instead of handling it explicitly.
  * @pte_entry: if set, called for each non-empty PTE (4th-level) entry
+ * @locked_pte_entry: if set, called for each pmd or pte entry. The
+ * 		      page table lock for the entry is also acquired
+ * 		      such that the handler does not have to worry
+ * 		      about the entry disappearing (or being split in
+ * 		      the case of a pmd_trans_huge).
  * @pte_hole: if set, called for each hole at all levels
  * @hugetlb_entry: if set, called for each hugetlb entry
  *		   *Caution*: The caller must hold mmap_sem() if @hugetlb_entry
@@ -1112,6 +1117,8 @@ struct mm_walk {
 			 unsigned long next, struct mm_walk *walk);
 	int (*pte_entry)(pte_t *pte, unsigned long addr,
 			 unsigned long next, struct mm_walk *walk);
+	int (*locked_single_entry)(pte_t *pte, unsigned long addr,
+			 unsigned long pte_size, struct mm_walk *walk);
 	int (*pte_hole)(unsigned long addr, unsigned long next,
 			struct mm_walk *walk);
 	int (*hugetlb_entry)(pte_t *pte, unsigned long hmask,
mm/pagewalk.c renamed from mm/pagewalk.c~mm-pagewalk-add-locked-walker +43 -0

55 lines not on this page · raw message

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

PATCH 9/10 mm: pagewalk: use new locked walker for /proc/pid/smaps

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

The diffstat tells the story here. Using the new walker function greatly simplifies the code. One side-effect here is that we'll call cond_resched() more often than we did before. It used to be called once per pte page, but now it's called on every pte.

---

 b/fs/proc/task_mmu.c |   27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~mm-pagewalk-use-locked-walker-smaps +5 -22
diff -puN fs/proc/task_mmu.c~mm-pagewalk-use-locked-walker-smaps fs/proc/task_mmu.c
@@ -490,32 +490,15 @@ static void smaps_pte_entry(pte_t ptent,
 	}
 }
 
-static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
+static int smaps_single_locked(pte_t *pte, unsigned long addr, unsigned long size,
 			   struct mm_walk *walk)
 {
 	struct mem_size_stats *mss = walk->private;
-	struct vm_area_struct *vma = walk->vma;
-	pte_t *pte;
-	spinlock_t *ptl;
-
-	if (pmd_trans_huge_lock(pmd, vma, &ptl) == 1) {
-		smaps_pte_entry(*(pte_t *)pmd, addr, HPAGE_PMD_SIZE, walk);
-		spin_unlock(ptl);
+
+	if (size == HPAGE_PMD_SIZE)
 		mss->anonymous_thp += HPAGE_PMD_SIZE;
-		return 0;
-	}
 
-	if (pmd_trans_unstable(pmd))
-		return 0;
-	/*
-	 * The mmap_sem held all the way back in m_start() is what
-	 * keeps khugepaged out of here and from collapsing things
-	 * in here.
-	 */
-	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
-	for (; addr != end; pte++, addr += PAGE_SIZE)
-		smaps_pte_entry(*pte, addr, PAGE_SIZE, walk);
-	pte_unmap_unlock(pte - 1, ptl);
+	smaps_pte_entry(*pte, addr, size, walk);
 	cond_resched();
 	return 0;
 }
@@ -581,7 +564,7 @@ static int show_smap(struct seq_file *m,
 	struct vm_area_struct *vma = v;
 	struct mem_size_stats mss;
 	struct mm_walk smaps_walk = {
-		.pmd_entry = smaps_pte_range,
+		.locked_single_entry = smaps_single_locked,
 		.mm = vma->vm_mm,
 		.private = &mss,
 	};

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

PATCH 10/10 mm: pagewalk: use locked walker for /proc/pid/numa_maps

In reply to Dave Hansen

From: Dave Hansen <[email protected]>

Same deal as the last one. Lots of code savings using the new walker function.

---

 b/fs/proc/task_mmu.c |   39 ++++++++-------------------------------
 1 file changed, 8 insertions(+), 31 deletions(-)
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~mm-pagewalk-use-locked-walker-numa_maps +8 -31
diff -puN fs/proc/task_mmu.c~mm-pagewalk-use-locked-walker-numa_maps fs/proc/task_mmu.c
@@ -1280,41 +1280,18 @@ static struct page *can_gather_numa_stat
 	return page;
 }
 
-static int gather_pte_stats(pmd_t *pmd, unsigned long addr,
-		unsigned long end, struct mm_walk *walk)
+static int gather_stats_locked(pte_t *pte, unsigned long addr,
+		unsigned long size, struct mm_walk *walk)
 {
-	struct numa_maps *md;
-	spinlock_t *ptl;
-	pte_t *orig_pte;
-	pte_t *pte;
-
-	md = walk->private;
+	struct numa_maps *md = walk->private;
+	struct page *page = can_gather_numa_stats(*pte, walk->vma, addr);
 
-	if (pmd_trans_huge_lock(pmd, walk->vma, &ptl) == 1) {
-		pte_t huge_pte = *(pte_t *)pmd;
-		struct page *page;
-
-		page = can_gather_numa_stats(huge_pte, walk->vma, addr);
-		if (page)
-			gather_stats(page, md, pte_dirty(huge_pte),
-				     HPAGE_PMD_SIZE/PAGE_SIZE);
-		spin_unlock(ptl);
-		return 0;
-	}
+	if (page)
+		gather_stats(page, md, pte_dirty(*pte), size/PAGE_SIZE);
 
-	if (pmd_trans_unstable(pmd))
-		return 0;
-	orig_pte = pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
-	do {
-		struct page *page = can_gather_numa_stats(*pte, walk->vma, addr);
-		if (!page)
-			continue;
-		gather_stats(page, md, pte_dirty(*pte), 1);
-
-	} while (pte++, addr += PAGE_SIZE, addr != end);
-	pte_unmap_unlock(orig_pte, ptl);
 	return 0;
 }
+
 #ifdef CONFIG_HUGETLB_PAGE
 static int gather_hugetbl_stats(pte_t *pte, unsigned long hmask,
 		unsigned long addr, unsigned long end, struct mm_walk *walk)
@@ -1366,7 +1343,7 @@ static int show_numa_map(struct seq_file
 	memset(md, 0, sizeof(*md));
 
 	walk.hugetlb_entry = gather_hugetbl_stats;
-	walk.pmd_entry = gather_pte_stats;
+	walk.locked_single_entry = gather_stats_locked;
 	walk.private = md;
 	walk.mm = mm;
 

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw
In reply to Dave Hansen

Hello Dave,

Quoted 10 lines · Dave Hansen

The hugetlbfs and THP support in the walk_page_range() code was mostly an afterthought.

We also _tried_ to have the pagewalk code be concerned only with page tables and *NOT* VMAs. We lost that battle since 80% of the page walkers just pass the VMA along anyway.

This does a few cleanups and adds a new flavor of walker which can be stupid^Wsimple and not have to be explicitly taught about THP.

What version is this patchset based on?
Recently I comprehensively rewrote page table walker (from the same motivation as yours) and the patchset is now in linux-mm. I guess most of your patchset (I've not read them yet) conflict with this patchset.
So could you take a look on it?

Thanks,
Naoya Horiguchi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

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

#13 lore raw
Quoted 5 lines · Naoya Horiguchi

What version is this patchset based on?
Recently I comprehensively rewrote page table walker (from the same motivation as yours) and the patchset is now in linux-mm. I guess most of your patchset (I've not read them yet) conflict with this patchset.
So could you take a look on it?

It's on top of a version of Linus's from the last week. I'll take a look at how it sits on top of -mm.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

PATCH 1/1 mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

Quoted 9 lines · Dave Hansen
Quoted 5 lines · Naoya Horiguchi

What version is this patchset based on?
Recently I comprehensively rewrote page table walker (from the same motivation as yours) and the patchset is now in linux-mm. I guess most of your patchset (I've not read them yet) conflict with this patchset.
So could you take a look on it?

It's on top of a version of Linus's from the last week. I'll take a look at how it sits on top of -mm.

I've looked over your series, but unfortunately most of works (patch 1, 2, 3, 5, 6, 7) were already done or we don't have to do it in current linux-mm code. Problems you try to handle in these patches come from current code's poor design of page table walker, worst thing is that we do vma-loop inside pgd loop. I know you tried harder to make things better, but I don't think it make sense to maintain current bad base code for long.

As for patch 4, yes, we can apply page table walker do_mincore() and I have a patch applicable onto linux-mm code (attached). And for other potential page walk users, I'm investigating whether we can really apply page table walker (some caller doesn't hold mmap_sem, so can't simply apply it.)

And for patch 8, 9, and 10, I don't think it's good idea to add a new callback which can handle both pmd and pte (because they are essentially differnt thing). But the underneath idea of doing pmd_trans_huge_lock() in the common code in walk_single_entry_locked() looks nice to me. So it would be great if we can do the same thing in walk_pmd_range() (of linux-mm) to reduce code in callbacks.

Thanks,
Naoya Horiguchi
---

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

#16 lore raw

Re: [PATCH -mm] mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

Quoted 5 lines · Naoya Horiguchi

And for patch 8, 9, and 10, I don't think it's good idea to add a new callback which can handle both pmd and pte (because they are essentially differnt thing). But the underneath idea of doing pmd_trans_huge_lock() in the common code in walk_single_entry_locked() looks nice to me. So it would be great if we can do the same thing in walk_pmd_range() (of linux-mm) to reduce code in callbacks.

You think they are different, I think they're the same. :)

What the walkers *really* care about is getting a leaf node in the page tables. They generally don't *care* whether it is a pmd or pte, they just want to know what its value is and how large it is.

I'd argue that they don't really ever need to actually know at which level they are in the page tables, just if they are at the bottom or not. Note that *NOBODY* sets a pud or pgd entry. That's because the walkers are 100% concerned about leaf nodes (pte's) at this point.

Take a look at my version of gather_stats_locked():

Quoted 11 lines

static int gather_stats_locked(pte_t *pte, unsigned long addr,
unsigned long size, struct mm_walk *walk)

 {
        struct numa_maps *md = walk->private;
        struct page *page = can_gather_numa_stats(*pte, walk->vma, addr);
 
        if (page)
                gather_stats(page, md, pte_dirty(*pte), size/PAGE_SIZE);
 
        return 0;

}

The mmotm version looks _very_ similar to that, *BUT* the mmotm version needs to have an entire *EXTRA* 22-line gather_pmd_stats() dealing with THP locking, while mine doesn't.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

Re: [PATCH -mm] mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

Quoted 7 lines · Dave Hansen
Quoted 5 lines · Naoya Horiguchi

And for patch 8, 9, and 10, I don't think it's good idea to add a new callback which can handle both pmd and pte (because they are essentially differnt thing). But the underneath idea of doing pmd_trans_huge_lock() in the common code in walk_single_entry_locked() looks nice to me. So it would be great if we can do the same thing in walk_pmd_range() (of linux-mm) to reduce code in callbacks.

Quoted 5 lines

You think they are different, I think they're the same. :)

What the walkers *really* care about is getting a leaf node in the page tables. They generally don't *care* whether it is a pmd or pte, they just want to know what its value is and how large it is.

OK, I see your idea, so I think that we could go to the direction to unify all p(gd|ud|md|te)_entry() callbacks.
And if we find the leaf entry in whatever level, we call the common entry handler on the entry, right?
It would takes some time and effort to make all users to fit to this new scheme, so my suggestion is:
1. move pmd locking to walk_pmd_range() (then, your locked_single_entry() callback is equal to pmd_entry())
2. let each existing user have its common entry handler, and connect it to its pmd_entry() and/or pte_entry() to keep compatibility
3. apply page table walker to potential users.
I'd like to keep pmd/pte_entry() until we complete phase 2., because we could find something which let us change core code,
4. and finaly replace all p(gd|ud|md|te)_entry() with a unified callback.

Could you let me have a few days to work on 1.?
I think that it means your patch 8 is effectively merged on top of mine. So your current problem will be solved.

Quoted 4 lines

I'd argue that they don't really ever need to actually know at which level they are in the page tables, just if they are at the bottom or not. Note that *NOBODY* sets a pud or pgd entry. That's because the walkers are 100% concerned about leaf nodes (pte's) at this point.

Yes. BTW do you think we should pud_entry() and pgd_entry() immediately? We can do it and it reduces some trivial evaluations, so it's optimized a little.

Quoted 11 lines

Take a look at my version of gather_stats_locked():

Quoted 9 lines

static int gather_stats_locked(pte_t *pte, unsigned long addr,
unsigned long size, struct mm_walk *walk)

 {
        struct numa_maps *md = walk->private;
        struct page *page = can_gather_numa_stats(*pte, walk->vma, addr);
 
        if (page)
                gather_stats(page, md, pte_dirty(*pte), size/PAGE_SIZE);
Quoted 6 lines
Quoted 2 lines
        return 0;

}

The mmotm version looks _very_ similar to that, *BUT* the mmotm version needs to have an entire *EXTRA* 22-line gather_pmd_stats() dealing with THP locking, while mine doesn't.

OK, my objection was just on adding a new callback because it introduces some duplication (3 callbacks for 2 types of entries.) But I agree to do pmd locking in the common code. It should make both of us happy :)

Thanks,
Naoya Horiguchi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

Re: [PATCH -mm] mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

Sorry, I've dropped one important word :(

On Tue, Jun 03, 2014 at 04:01:17PM -0400, Naoya Horiguchi wrote:
...

Quoted 6 lines
Quoted 4 lines

I'd argue that they don't really ever need to actually know at which level they are in the page tables, just if they are at the bottom or not. Note that *NOBODY* sets a pud or pgd entry. That's because the walkers are 100% concerned about leaf nodes (pte's) at this point.

Yes. BTW do you think we should pud_entry() and pgd_entry() immediately?

^remove

Quoted 2 lines

We can do it and it reduces some trivial evaluations, so it's optimized a little.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

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

#20 lore raw

Re: [PATCH -mm] mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

Quoted 10 lines · Naoya Horiguchi
Quoted 9 lines · Dave Hansen
Quoted 5 lines · Naoya Horiguchi

And for patch 8, 9, and 10, I don't think it's good idea to add a new callback which can handle both pmd and pte (because they are essentially differnt thing). But the underneath idea of doing pmd_trans_huge_lock() in the common code in walk_single_entry_locked() looks nice to me. So it would be great if we can do the same thing in walk_pmd_range() (of linux-mm) to reduce code in callbacks.

You think they are different, I think they're the same. :)

Quoted 8 lines
Quoted 3 lines

What the walkers *really* care about is getting a leaf node in the page tables. They generally don't *care* whether it is a pmd or pte, they just want to know what its value is and how large it is.

OK, I see your idea, so I think that we could go to the direction to unify all p(gd|ud|md|te)_entry() callbacks.
And if we find the leaf entry in whatever level, we call the common entry handler on the entry, right?

That's a level farther than I took it, but I think it makes sense. Nobody is using the walkers for the purposes of looking at anything but leaf nodes.

Quoted 4 lines

It would takes some time and effort to make all users to fit to this new scheme, so my suggestion is:
1. move pmd locking to walk_pmd_range() (then, your locked_single_entry() callback is equal to pmd_entry())

Yes, except that still means that each walker needs separate code for regular _and_ transparent huge pages. It would be nice to be able to have a single handler which handles both.

Quoted 10 lines

2. let each existing user have its common entry handler, and connect it to its pmd_entry() and/or pte_entry() to keep compatibility
3. apply page table walker to potential users.
I'd like to keep pmd/pte_entry() until we complete phase 2., because we could find something which let us change core code,
4. and finaly replace all p(gd|ud|md|te)_entry() with a unified callback.

Could you let me have a few days to work on 1.?
I think that it means your patch 8 is effectively merged on top of mine. So your current problem will be solved.

That sounds quite nice.

Quoted 8 lines
Quoted 4 lines

I'd argue that they don't really ever need to actually know at which level they are in the page tables, just if they are at the bottom or not. Note that *NOBODY* sets a pud or pgd entry. That's because the walkers are 100% concerned about leaf nodes (pte's) at this point.

Yes. BTW do you think we should pud_entry() and pgd_entry() immediately? We can do it and it reduces some trivial evaluations, so it's optimized a little.

Yeah, we might as well. They're just wasted space at the moment.

#21 lore raw

Re: [PATCH -mm] mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

In reply to a message not in the archive

Review

Quoted 9 lines · Naoya Horiguchi
(quoted diff) +9 -0
+	/*
+	 * Huge pages are always in RAM for now, but
+	 * theoretically it needs to be checked.
+	 */
+	present = pte && !huge_pte_none(huge_ptep_get(pte));
+	for (; addr != end; vec++, addr += PAGE_SIZE)
+		*vec = present;
+	cond_resched();
+	walk->private += (end - addr) >> PAGE_SHIFT;

That comment is bogus, fwiw. Huge pages are demand-faulted and it's quite possible that they are not present.

#22 lore raw

Re: [PATCH -mm] mincore: apply page table walker on do_mincore() (Re: [PATCH 00/10] mm: pagewalk: huge page cleanups and VMA passing)

Quoted 13 lines · Dave Hansen

Review

Quoted 9 lines · Naoya Horiguchi
(quoted diff) +9 -0
+	/*
+	 * Huge pages are always in RAM for now, but
+	 * theoretically it needs to be checked.
+	 */
+	present = pte && !huge_pte_none(huge_ptep_get(pte));
+	for (; addr != end; vec++, addr += PAGE_SIZE)
+		*vec = present;
+	cond_resched();
+	walk->private += (end - addr) >> PAGE_SHIFT;

That comment is bogus, fwiw. Huge pages are demand-faulted and it's quite possible that they are not present.

No. hugetlbfs adopts prefault mechanism, which creates free hugepage pool in advance and hugepage allocation is done from the pool, The above comment claims this. But if we want to comment more precisely, it should be like "Hugepages under user process are always in RAM and never swapped out, but ...".

Thanks,
Naoya Horiguchi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>