Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] remove hugetlb_clean_stale_pgtable() and fix huge_pte_alloc()

I don't think we need to call hugetlb_clean_stale_pgtable() anymore
in 2.6.13 because of the rework with free_pgtables(). It now collect
all the pte page at the time of munmap. It used to only collect page
table pages when entire one pgd can be freed and left with staled pte
pages. Not anymore with 2.6.13. This function will never be called
and We should turn it into a BUG_ON.

I also spotted two problems here, not Adam's fault :-)
(1) in huge_pte_alloc(), it looks like a bug to me that pud is not
checked before calling pmd_alloc()
(2) in hugetlb_clean_stale_pgtable(), it also missed a call to
pmd_free_tlb. I think a tlb flush is required to flush the mapping
for the page table itself when we clear out the pmd pointing to a
pte page. However, since hugetlb_clean_stale_pgtable() is never
called, so it won't trigger the bug.

Signed-off-by: Ken Chen <kenneth.w.chen@intel.com>
Cc: Adam Litke <agl@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Chen, Kenneth W and committed by
Linus Torvalds
0e5c9f39 02b0ccef

+3 -28
+3 -20
arch/i386/mm/hugetlbpage.c
··· 22 22 { 23 23 pgd_t *pgd; 24 24 pud_t *pud; 25 - pmd_t *pmd; 26 25 pte_t *pte = NULL; 27 26 28 27 pgd = pgd_offset(mm, addr); 29 28 pud = pud_alloc(mm, pgd, addr); 30 - pmd = pmd_alloc(mm, pud, addr); 29 + if (pud) 30 + pte = (pte_t *) pmd_alloc(mm, pud, addr); 31 + BUG_ON(pte && !pte_none(*pte) && !pte_huge(*pte)); 31 32 32 - if (!pmd) 33 - goto out; 34 - 35 - pte = (pte_t *) pmd; 36 - if (!pte_none(*pte) && !pte_huge(*pte)) 37 - hugetlb_clean_stale_pgtable(pte); 38 - out: 39 33 return pte; 40 34 } 41 35 ··· 123 129 return page; 124 130 } 125 131 #endif 126 - 127 - void hugetlb_clean_stale_pgtable(pte_t *pte) 128 - { 129 - pmd_t *pmd = (pmd_t *) pte; 130 - struct page *page; 131 - 132 - page = pmd_page(*pmd); 133 - pmd_clear(pmd); 134 - dec_page_state(nr_page_table_pages); 135 - page_cache_release(page); 136 - } 137 132 138 133 /* x86_64 also uses this file */ 139 134
-1
include/asm-i386/page.h
··· 68 68 #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 69 69 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 70 70 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA 71 - #define ARCH_HAS_HUGETLB_CLEAN_STALE_PGTABLE 72 71 #endif 73 72 74 73 #define pgd_val(x) ((x).pgd)
-1
include/asm-x86_64/page.h
··· 28 28 #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) 29 29 #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 30 30 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 31 - #define ARCH_HAS_HUGETLB_CLEAN_STALE_PGTABLE 32 31 33 32 #ifdef __KERNEL__ 34 33 #ifndef __ASSEMBLY__
-6
include/linux/hugetlb.h
··· 70 70 void hugetlb_prefault_arch_hook(struct mm_struct *mm); 71 71 #endif 72 72 73 - #ifndef ARCH_HAS_HUGETLB_CLEAN_STALE_PGTABLE 74 - #define hugetlb_clean_stale_pgtable(pte) BUG() 75 - #else 76 - void hugetlb_clean_stale_pgtable(pte_t *pte); 77 - #endif 78 - 79 73 #else /* !CONFIG_HUGETLB_PAGE */ 80 74 81 75 static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)