tree 9430e6e4f4c3d586ecb7375cd780fd17694888c7
parent ee39b37b23da0b6ec53a8ebe90ff41c016f8ae27
author Hugh Dickins <[EMAIL PROTECTED]> Wed, 20 Apr 2005 03:29:16 -0700
committer Linus Torvalds <[EMAIL PROTECTED](none)> Wed, 20 Apr 2005 03:29:16 
-0700

[PATCH] freepgt: hugetlb_free_pgd_range

ia64 and ppc64 had hugetlb_free_pgtables functions which were no longer being
called, and it wasn't obvious what to do about them.

The ppc64 case turns out to be easy: the associated tables are noted elsewhere
and freed later, safe to either skip its hugetlb areas or go through the
motions of freeing nothing.  Since ia64 does need a special case, restore to
ppc64 the special case of skipping them.

The ia64 hugetlb case has been broken since pgd_addr_end went in, though it
probably appeared to work okay if you just had one such area; in fact it's
been broken much longer if you consider a long munmap spanning from another
region into the hugetlb region.

In the ia64 hugetlb region, more virtual address bits are available than in
the other regions, yet the page tables are structured the same way: the page
at the bottom is larger.  Here we need to scale down each addr before passing
it to the standard free_pgd_range.  Was about to write a hugely_scaled_down
macro, but found htlbpage_to_page already exists for just this purpose.  Fixed
off-by-one in ia64 is_hugepage_only_range.

Uninline free_pgd_range to make it available to ia64.  Make sure the
vma-gathering loop in free_pgtables cannot join a hugepage_only_range to any
other (safe to join huges?  probably but don't bother).

Signed-off-by: Hugh Dickins <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 ia64/mm/hugetlbpage.c  |   29 +++++++++++++++++++++++------
 ppc64/mm/hugetlbpage.c |   10 ----------
 asm-ia64/page.h        |    2 +-
 asm-ia64/pgtable.h     |    4 ++--
 asm-ppc64/pgtable.h    |   12 +++++++++---
 linux/hugetlb.h        |    6 ++++--
 linux/mm.h             |    4 +++-
 memory.c               |   36 +++++++++++++++++++++++-------------
 8 files changed, 65 insertions(+), 38 deletions(-)

Index: arch/ia64/mm/hugetlbpage.c
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/arch/ia64/mm/hugetlbpage.c  
(mode:100644 sha1:626258ae974290d354c5384b725ffac8647f55c2)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/arch/ia64/mm/hugetlbpage.c  
(mode:100644 sha1:df08ae7634b61d2efadf065e246c4bfb7f342b2c)
@@ -186,13 +186,30 @@
        return NULL;
 }
 
-/*
- * Do nothing, until we've worked out what to do!  To allow build, we
- * must remove reference to clear_page_range since it no longer exists.
- */
-void hugetlb_free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *prev,
-       unsigned long start, unsigned long end)
+void hugetlb_free_pgd_range(struct mmu_gather **tlb,
+                       unsigned long addr, unsigned long end,
+                       unsigned long floor, unsigned long ceiling)
 {
+       /*
+        * This is called only when is_hugepage_only_range(addr,),
+        * and it follows that is_hugepage_only_range(end,) also.
+        *
+        * The offset of these addresses from the base of the hugetlb
+        * region must be scaled down by HPAGE_SIZE/PAGE_SIZE so that
+        * the standard free_pgd_range will free the right page tables.
+        *
+        * If floor and ceiling are also in the hugetlb region, they
+        * must likewise be scaled down; but if outside, left unchanged.
+        */
+
+       addr = htlbpage_to_page(addr);
+       end  = htlbpage_to_page(end);
+       if (is_hugepage_only_range(tlb->mm, floor, HPAGE_SIZE))
+               floor = htlbpage_to_page(floor);
+       if (is_hugepage_only_range(tlb->mm, ceiling, HPAGE_SIZE))
+               ceiling = htlbpage_to_page(ceiling);
+
+       free_pgd_range(tlb, addr, end, floor, ceiling);
 }
 
 void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, 
unsigned long end)
Index: arch/ppc64/mm/hugetlbpage.c
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/arch/ppc64/mm/hugetlbpage.c  
(mode:100644 sha1:c62ddaff07209efb6d099d5d94f9306be5d70f72)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/arch/ppc64/mm/hugetlbpage.c  
(mode:100644 sha1:8665bb57e42bb77349276a36ce82b98e13ea3fac)
@@ -430,16 +430,6 @@
        flush_tlb_pending();
 }
 
-void hugetlb_free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *prev,
-                          unsigned long start, unsigned long end)
-{
-       /* Because the huge pgtables are only 2 level, they can take
-        * at most around 4M, much less than one hugepage which the
-        * process is presumably entitled to use.  So we don't bother
-        * freeing up the pagetables on unmap, and wait until
-        * destroy_context() to clean up the lot. */
-}
-
 int hugetlb_prefault(struct address_space *mapping, struct vm_area_struct *vma)
 {
        struct mm_struct *mm = current->mm;
Index: include/asm-ia64/page.h
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/include/asm-ia64/page.h  
(mode:100644 sha1:24aab801a8caa60db0a48eb86c7cc5a2caeb03be)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/include/asm-ia64/page.h  
(mode:100644 sha1:08894f73abf0384df70d33888228ee389be33bcb)
@@ -139,7 +139,7 @@
 # define HUGETLB_PAGE_ORDER    (HPAGE_SHIFT - PAGE_SHIFT)
 # define is_hugepage_only_range(mm, addr, len)         \
         (REGION_NUMBER(addr) == REGION_HPAGE &&        \
-         REGION_NUMBER((addr)+(len)) == REGION_HPAGE)
+         REGION_NUMBER((addr)+(len)-1) == REGION_HPAGE)
 extern unsigned int hpage_shift;
 #endif
 
Index: include/asm-ia64/pgtable.h
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/include/asm-ia64/pgtable.h  
(mode:100644 sha1:1757a811f4361590cca5475e8e89c5fea6d25d1a)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/include/asm-ia64/pgtable.h  
(mode:100644 sha1:bbf6dd7570038e2d26f135fd52ee9f33c0c9f69d)
@@ -472,8 +472,8 @@
 #define HUGETLB_PGDIR_SIZE     (__IA64_UL(1) << HUGETLB_PGDIR_SHIFT)
 #define HUGETLB_PGDIR_MASK     (~(HUGETLB_PGDIR_SIZE-1))
 struct mmu_gather;
-extern void hugetlb_free_pgtables(struct mmu_gather *tlb,
-       struct vm_area_struct * prev, unsigned long start, unsigned long end);
+void hugetlb_free_pgd_range(struct mmu_gather **tlb, unsigned long addr,
+               unsigned long end, unsigned long floor, unsigned long ceiling);
 #endif
 
 /*
Index: include/asm-ppc64/pgtable.h
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/include/asm-ppc64/pgtable.h  
(mode:100644 sha1:4c4824653e80944f8d48d3b9b3ce201cfc8390e3)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/include/asm-ppc64/pgtable.h  
(mode:100644 sha1:33b90e2aa47d88074ea8d32bbd2d4872642aa783)
@@ -500,9 +500,15 @@
 
 extern void paging_init(void);
 
-struct mmu_gather;
-void hugetlb_free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *prev,
-                          unsigned long start, unsigned long end);
+/*
+ * Because the huge pgtables are only 2 level, they can take
+ * at most around 4M, much less than one hugepage which the
+ * process is presumably entitled to use.  So we don't bother
+ * freeing up the pagetables on unmap, and wait until
+ * destroy_context() to clean up the lot.
+ */
+#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \
+                                               do { } while (0)
 
 /*
  * This gets called at the end of handling a page fault, when
Index: include/linux/hugetlb.h
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/include/linux/hugetlb.h  
(mode:100644 sha1:ae45676d27baf3cae11310a88e56cca610747875)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/include/linux/hugetlb.h  
(mode:100644 sha1:6af1ae4a821196a54981887cecc2fe32c0e18241)
@@ -37,7 +37,8 @@
 
 #ifndef ARCH_HAS_HUGEPAGE_ONLY_RANGE
 #define is_hugepage_only_range(mm, addr, len)  0
-#define hugetlb_free_pgtables(tlb, prev, start, end) do { } while (0)
+#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \
+                                               do { } while (0)
 #endif
 
 #ifndef ARCH_HAS_PREPARE_HUGEPAGE_RANGE
@@ -72,7 +73,8 @@
 #define prepare_hugepage_range(addr, len)      (-EINVAL)
 #define pmd_huge(x)    0
 #define is_hugepage_only_range(mm, addr, len)  0
-#define hugetlb_free_pgtables(tlb, prev, start, end) do { } while (0)
+#define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \
+                                               do { } while (0)
 #define alloc_huge_page()                      ({ NULL; })
 #define free_huge_page(p)                      ({ (void)(p); BUG(); })
 
Index: include/linux/mm.h
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/include/linux/mm.h  (mode:100644 
sha1:59eca28b5ae2d64d9d21a2b0cff152b47ca36152)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/include/linux/mm.h  (mode:100644 
sha1:c74a74ca401dbeae3752e9f201f331505f4f9b48)
@@ -587,7 +587,9 @@
                struct vm_area_struct *start_vma, unsigned long start_addr,
                unsigned long end_addr, unsigned long *nr_accounted,
                struct zap_details *);
-void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *vma,
+void free_pgd_range(struct mmu_gather **tlb, unsigned long addr,
+               unsigned long end, unsigned long floor, unsigned long ceiling);
+void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *start_vma,
                unsigned long floor, unsigned long ceiling);
 int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
                        struct vm_area_struct *vma);
Index: mm/memory.c
===================================================================
--- 4af606913ab8f95551623b788c0c66c1f5902229/mm/memory.c  (mode:100644 
sha1:854bd90eeca1928b15dfb61088dd3d13360cb373)
+++ 9430e6e4f4c3d586ecb7375cd780fd17694888c7/mm/memory.c  (mode:100644 
sha1:6bad4c4064e7e0bae9886d976ccd7fbde8ccf753)
@@ -190,7 +190,7 @@
  *
  * Must be called with pagetable lock held.
  */
-static inline void free_pgd_range(struct mmu_gather *tlb,
+void free_pgd_range(struct mmu_gather **tlb,
                        unsigned long addr, unsigned long end,
                        unsigned long floor, unsigned long ceiling)
 {
@@ -241,37 +241,47 @@
                return;
 
        start = addr;
-       pgd = pgd_offset(tlb->mm, addr);
+       pgd = pgd_offset((*tlb)->mm, addr);
        do {
                next = pgd_addr_end(addr, end);
                if (pgd_none_or_clear_bad(pgd))
                        continue;
-               free_pud_range(tlb, pgd, addr, next, floor, ceiling);
+               free_pud_range(*tlb, pgd, addr, next, floor, ceiling);
        } while (pgd++, addr = next, addr != end);
 
-       if (!tlb_is_full_mm(tlb))
-               flush_tlb_pgtables(tlb->mm, start, end);
+       if (!tlb_is_full_mm(*tlb))
+               flush_tlb_pgtables((*tlb)->mm, start, end);
 }
 
 void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *vma,
-                               unsigned long floor, unsigned long ceiling)
+               unsigned long floor, unsigned long ceiling)
 {
        while (vma) {
                struct vm_area_struct *next = vma->vm_next;
                unsigned long addr = vma->vm_start;
 
-               /* Optimization: gather nearby vmas into a single call down */
-               while (next && next->vm_start <= vma->vm_end + PMD_SIZE) {
-                       vma = next;
-                       next = vma->vm_next;
-               }
-               free_pgd_range(*tlb, addr, vma->vm_end,
+               if (is_hugepage_only_range(vma->vm_mm, addr, HPAGE_SIZE)) {
+                       hugetlb_free_pgd_range(tlb, addr, vma->vm_end,
                                floor, next? next->vm_start: ceiling);
+               } else {
+                       /*
+                        * Optimization: gather nearby vmas into one call down
+                        */
+                       while (next && next->vm_start <= vma->vm_end + PMD_SIZE
+                         && !is_hugepage_only_range(vma->vm_mm, next->vm_start,
+                                                       HPAGE_SIZE)) {
+                               vma = next;
+                               next = vma->vm_next;
+                       }
+                       free_pgd_range(tlb, addr, vma->vm_end,
+                               floor, next? next->vm_start: ceiling);
+               }
                vma = next;
        }
 }
 
-pte_t fastcall * pte_alloc_map(struct mm_struct *mm, pmd_t *pmd, unsigned long 
address)
+pte_t fastcall *pte_alloc_map(struct mm_struct *mm, pmd_t *pmd,
+                               unsigned long address)
 {
        if (!pmd_present(*pmd)) {
                struct page *new;
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to