Skip to contentSkip to conversation

hugetlb demand paging patch part [3/3]

PATCH Chen, Kenneth W 2 participants 5 messages Apr 13, 2004 – Apr 16, 2004 SuperH

lore
Share & tools
lore
#0 lore raw

Part 3 of 3

3. hugetlb_demand_arch.patch - this adds additional arch specific fixes for x86 and ia64 when generic demand paging is turned on. Also bulk of the patch is to clean up with functions that no longer needed.

 i386/mm/hugetlbpage.c    |  148 +----------------------------------------------
 ia64/mm/hugetlbpage.c    |   93 -----------------------------
 sh/mm/hugetlbpage.c      |   94 -----------------------------
 sparc64/mm/hugetlbpage.c |   94 -----------------------------
 4 files changed, 10 insertions(+), 419 deletions(-)
arch/i386/mm/hugetlbpage.c +4 -144
diff -Nurp linux-2.6.5/arch/i386/mm/hugetlbpage.c linux-2.6.5.htlb/arch/i386/mm/hugetlbpage.c
@@ -9,18 +9,14 @@
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/hugetlb.h>
-#include <linux/pagemap.h>
-#include <linux/smp_lock.h>
-#include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/err.h>
-#include <linux/sysctl.h>
 #include <asm/mman.h>
 #include <asm/pgalloc.h>
 #include <asm/tlb.h>
 #include <asm/tlbflush.h>
 
-static pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
+pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
 {
 	pgd_t *pgd;
 	pmd_t *pmd = NULL;
@@ -41,7 +37,8 @@ static pte_t *huge_pte_offset(struct mm_
 	return (pte_t *) pmd;
 }
 
-static void set_huge_pte(struct mm_struct *mm, struct vm_area_struct *vma, struct page *page, pte_t * page_table, int write_access)
+void set_huge_pte(struct mm_struct *mm, struct vm_area_struct *vma, struct page *page,
+		  pte_t * page_table, int write_access)
 {
 	pte_t entry;
 
@@ -96,95 +93,6 @@ nomem:
 	return -ENOMEM;
 }
 
-int
-follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
-		    struct page **pages, struct vm_area_struct **vmas,
-		    unsigned long *position, int *length, int i)
-{
-	unsigned long vpfn, vaddr = *position;
-	int remainder = *length;
-
-	WARN_ON(!is_vm_hugetlb_page(vma));
-
-	vpfn = vaddr/PAGE_SIZE;
-	while (vaddr < vma->vm_end && remainder) {
-
-		if (pages) {
-			pte_t *pte;
-			struct page *page;
-
-			pte = huge_pte_offset(mm, vaddr);
-
-			/* hugetlb should be locked, and hence, prefaulted */
-			WARN_ON(!pte || pte_none(*pte));
-
-			page = &pte_page(*pte)[vpfn % (HPAGE_SIZE/PAGE_SIZE)];
-
-			WARN_ON(!PageCompound(page));
-
-			get_page(page);
-			pages[i] = page;
-		}
-
-		if (vmas)
-			vmas[i] = vma;
-
-		vaddr += PAGE_SIZE;
-		++vpfn;
-		--remainder;
-		++i;
-	}
-
-	*length = remainder;
-	*position = vaddr;
-
-	return i;
-}
-
-#if 0	/* This is just for testing */
-struct page *
-follow_huge_addr(struct mm_struct *mm,
-	struct vm_area_struct *vma, unsigned long address, int write)
-{
-	unsigned long start = address;
-	int length = 1;
-	int nr;
-	struct page *page;
-
-	nr = follow_hugetlb_page(mm, vma, &page, NULL, &start, &length, 0);
-	if (nr = 1)
-		return page;
-	return NULL;
-}
-
-/*
- * If virtual address `addr' lies within a huge page, return its controlling
- * VMA, else NULL.
- */
-struct vm_area_struct *hugepage_vma(struct mm_struct *mm, unsigned long addr)
-{
-	if (mm->used_hugetlb) {
-		struct vm_area_struct *vma = find_vma(mm, addr);
-		if (vma && is_vm_hugetlb_page(vma))
-			return vma;
-	}
-	return NULL;
-}
-
-int pmd_huge(pmd_t pmd)
-{
-	return 0;
-}
-
-struct page *
-follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-		pmd_t *pmd, int write)
-{
-	return NULL;
-}
-
-#else
-
 struct page *
 follow_huge_addr(struct mm_struct *mm,
 	struct vm_area_struct *vma, unsigned long address, int write)
@@ -209,13 +117,10 @@ follow_huge_pmd(struct mm_struct *mm, un
 	struct page *page;
 
 	page = pte_page(*(pte_t *)pmd);
-	if (page) {
+	if (page)
 		page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
-		get_page(page);
-	}
 	return page;
 }
-#endif
 
 void unmap_hugepage_range(struct vm_area_struct *vma,
 		unsigned long start, unsigned long end)
@@ -239,48 +144,3 @@ void unmap_hugepage_range(struct vm_area
 	mm->rss -= (end - start) >> PAGE_SHIFT;
 	flush_tlb_range(vma, start, end);
 }
-
-int hugetlb_prefault(struct address_space *mapping, struct vm_area_struct *vma)
-{
-	struct mm_struct *mm = current->mm;
-	unsigned long addr;
-	int ret = 0;
-
-	BUG_ON(vma->vm_start & ~HPAGE_MASK);
-	BUG_ON(vma->vm_end & ~HPAGE_MASK);
-
-	spin_lock(&mm->page_table_lock);
-	for (addr = vma->vm_start; addr < vma->vm_end; addr += HPAGE_SIZE) {
-		unsigned long idx;
-		pte_t *pte = huge_pte_alloc(mm, addr);
-		struct page *page;
-
-		if (!pte) {
-			ret = -ENOMEM;
-			goto out;
-		}
-		if (!pte_none(*pte))
-			continue;
-
-		idx = ((addr - vma->vm_start) >> HPAGE_SHIFT)
-			+ (vma->vm_pgoff >> (HPAGE_SHIFT - PAGE_SHIFT));
-		page = find_get_page(mapping, idx);
-		if (!page) {
-			page = alloc_huge_page();
-			if (!page) {
-				ret = -ENOMEM;
-				goto out;
-			}
-			ret = add_to_page_cache(page, mapping, idx, GFP_ATOMIC);
-			unlock_page(page);
-			if (ret) {
-				free_huge_page(page);
-				goto out;
-			}
-		}
-		set_huge_pte(mm, vma, page, pte, vma->vm_flags & VM_WRITE);
-	}
-out:
-	spin_unlock(&mm->page_table_lock);
-	return ret;
-}
arch/ia64/mm/hugetlbpage.c +2 -91

129 lines not on this page · raw message

arch/sh/mm/hugetlbpage.c +2 -92

121 lines not on this page · raw message

arch/sparc64/mm/hugetlbpage.c +2 -92

121 lines not on this page · raw message

#1 lore raw

[snip]

Quoted 12 lines
(quoted diff) +1 -4
@@ -209,13 +117,10 @@ follow_huge_pmd(struct mm_struct *mm, un
 	struct page *page;
 
 	page = pte_page(*(pte_t *)pmd);
-	if (page) {
+	if (page)
 		page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
-		get_page(page);
-	}
 	return page;
 }
-#endif

[snip]

Review struct page *follow_huge_addr(struct mm_ · line 136

Quoted 7 lines
(quoted diff) +0 -1
@@ -175,7 +132,6 @@ struct page *follow_huge_addr(struct mm_
 		return NULL;
 	page = pte_page(*ptep);
 	page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
-	get_page(page);
 	return page;
 }

As far as I can tell, the removal of these get_page()s is also unrelated to the demand paging per se. But afaict removing them is correct - the corresponding logic in follow_page() for normal pages doesn't appear to do a get_page(), nor do all archs do a get_page().

Does that sound right to you?

If so, the patch below ought to be safe (and indeed a bugfix) to apply now:

Index: working-2.6/arch/ppc64/mm/hugetlbpage.c
=================================--- working-2.6.orig/arch/ppc64/mm/hugetlbpage.c 2004-04-15 17:03:43.052825264 +1000
+++ working-2.6/arch/ppc64/mm/hugetlbpage.c 2004-04-15 17:25:11.450920656 +1000
@@ -314,10 +314,8 @@
BUG_ON(! pmd_hugepage(*pmd));

page = hugepte_page(*(hugepte_t *)pmd);
- if (page) {
+ if (page)
page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
- get_page(page);
- }
return page;
}

Index: working-2.6/arch/i386/mm/hugetlbpage.c
=================================--- working-2.6.orig/arch/i386/mm/hugetlbpage.c 2004-04-15 17:07:42.813857792 +1000
+++ working-2.6/arch/i386/mm/hugetlbpage.c 2004-04-15 17:25:40.837847480 +1000
@@ -111,7 +111,6 @@

WARN_ON(!PageCompound(page));

- get_page(page);
return page;
}

@@ -167,10 +166,8 @@
struct page *page;

page = pte_page(*(pte_t *)pmd);
- if (page) {
+ if (page)
page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
- get_page(page);
- }
return page;
}
#endif
Index: working-2.6/arch/ia64/mm/hugetlbpage.c
=================================--- working-2.6.orig/arch/ia64/mm/hugetlbpage.c 2004-04-15 17:08:30.667905672 +1000
+++ working-2.6/arch/ia64/mm/hugetlbpage.c 2004-04-15 17:26:02.309910776 +1000
@@ -133,7 +133,6 @@
ptep = huge_pte_offset(mm, addr);
page = pte_page(*ptep);
page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
- get_page(page);
return page;
}
int pmd_huge(pmd_t pmd)

Signature · 4 lines
David Gibson			| For every complex problem there is a
david AT gibson.dropbear.id.au	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson
#2 lore raw
Quoted 15 lines

Review struct page *follow_huge_addr(struct mm_ · line 136

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

David Gibson wrote on Thursday, April 15, 2004 12:26 AM

(quoted diff) +0 -1
@@ -175,7 +132,6 @@ struct page *follow_huge_addr(struct mm_
 		return NULL;
 	page = pte_page(*ptep);
 	page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
-	get_page(page);
 	return page;
 }

As far as I can tell, the removal of these get_page()s is also unrelated to the demand paging per se. But afaict removing them is correct - the corresponding logic in follow_page() for normal pages doesn't appear to do a get_page(), nor do all archs do a get_page().

Quoted 1 line

Does that sound right to you?

It's a bug in the code that was never exercised with prefaulting. See get_user_pages() that short circuits the rest of faulting code with is_vm_hugetlb_page() test.

Quoted 2 lines

If so, the patch below ought to be safe (and indeed a bugfix) to apply now:

Yep, that's correct, I already did x86 and ia64 in one of the three patches posted. ;-)

#3 lore raw
Quoted 15 lines · Kenneth W
Quoted 15 lines

Review struct page *follow_huge_addr(struct mm_ · line 136

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

David Gibson wrote on Thursday, April 15, 2004 12:26 AM

(quoted diff) +0 -1
@@ -175,7 +132,6 @@ struct page *follow_huge_addr(struct mm_
 		return NULL;
 	page = pte_page(*ptep);
 	page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
-	get_page(page);
 	return page;
 }

As far as I can tell, the removal of these get_page()s is also unrelated to the demand paging per se. But afaict removing them is correct - the corresponding logic in follow_page() for normal pages doesn't appear to do a get_page(), nor do all archs do a get_page().

Quoted 5 lines
Quoted 1 line

Does that sound right to you?

It's a bug in the code that was never exercised with prefaulting. See get_user_pages() that short circuits the rest of faulting code with is_vm_hugetlb_page() test.

Erm.. it's not clear to me that it could never be exercise:
get_user_pages() is not the only caller of follow_page().

Quoted 5 lines
Quoted 2 lines

If so, the patch below ought to be safe (and indeed a bugfix) to apply now:

Yep, that's correct, I already did x86 and ia64 in one of the three patches posted. ;-)

Yes, I know, but I'm trying to separate which parts of your patches are fixes/cleanups for pre-existing problems, and which are genuinely new for demand paging.

Signature · 4 lines
David Gibson			| For every complex problem there is a
david AT gibson.dropbear.id.au	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson
#4 lore raw
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Review struct page *follow_huge_addr(struct mm_ · line 136

Quoted 8 lines

David Gibson wrote on Thursday, April 15, 2004 6:41 PM

(quoted diff) +0 -1
@@ -175,7 +132,6 @@ struct page *follow_huge_addr(struct mm_
 		return NULL;
 	page = pte_page(*ptep);
 	page += ((addr & ~HPAGE_MASK) >> PAGE_SHIFT);
-	get_page(page);
 	return page;
 }

As far as I can tell, the removal of these get_page()s is also unrelated to the demand paging per se. But afaict removing them is correct - the corresponding logic in follow_page() for normal pages doesn't appear to do a get_page(), nor do all archs do a get_page().

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Does that sound right to you?

It's a bug in the code that was never exercised with prefaulting. See get_user_pages() that short circuits the rest of faulting code with is_vm_hugetlb_page() test.

Erm.. it's not clear to me that it could never be exercise:
get_user_pages() is not the only caller of follow_page().

At least we all agree it's a bug :-)

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

If so, the patch below ought to be safe (and indeed a bugfix) to apply now:

Yep, that's correct, I already did x86 and ia64 in one of the three patches posted. ;-)

Yes, I know, but I'm trying to separate which parts of your patches are fixes/cleanups for pre-existing problems, and which are genuinely new for demand paging.

The only part I know that is bug fix is the extra get_page() reference in follow_huge_addr(). All others are for demand paging.

- Ken