aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShaohua Li <shaohua.li@intel.com>2012-01-12 20:19:16 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-12 23:13:08 -0500
commitf21760b15dcd091e5afd38d0b97197b45f7ef2ea (patch)
tree84dd0f9016b46630d6b67e48ff0382b78a1bc519
parente5591307f0c1eb733d280a0b72473e01d7f88530 (diff)
thp: add tlb_remove_pmd_tlb_entry
We have tlb_remove_tlb_entry to indicate a pte tlb flush entry should be flushed, but not a corresponding API for pmd entry. This isn't a problem so far because THP is only for x86 currently and tlb_flush() under x86 will flush entire TLB. But this is confusion and could be missed if thp is ported to other arch. Also convert tlb->need_flush = 1 to a VM_BUG_ON(!tlb->need_flush) in __tlb_remove_page() as suggested by Andrea Arcangeli. The __tlb_remove_page() function is supposed to be called after tlb_remove_xxx_tlb_entry() and we can catch any misuse. Signed-off-by: Shaohua Li <shaohua.li@intel.com> Reviewed-by: Andrea Arcangeli <aarcange@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: Johannes Weiner <jweiner@redhat.com> Cc: Minchan Kim <minchan.kim@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/asm-generic/tlb.h14
-rw-r--r--include/linux/huge_mm.h2
-rw-r--r--mm/huge_memory.c3
-rw-r--r--mm/memory.c4
4 files changed, 19 insertions, 4 deletions
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index e58fa777fa09..f96a5b58a975 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -139,6 +139,20 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
139 __tlb_remove_tlb_entry(tlb, ptep, address); \ 139 __tlb_remove_tlb_entry(tlb, ptep, address); \
140 } while (0) 140 } while (0)
141 141
142/**
143 * tlb_remove_pmd_tlb_entry - remember a pmd mapping for later tlb invalidation
144 * This is a nop so far, because only x86 needs it.
145 */
146#ifndef __tlb_remove_pmd_tlb_entry
147#define __tlb_remove_pmd_tlb_entry(tlb, pmdp, address) do {} while (0)
148#endif
149
150#define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \
151 do { \
152 tlb->need_flush = 1; \
153 __tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \
154 } while (0)
155
142#define pte_free_tlb(tlb, ptep, address) \ 156#define pte_free_tlb(tlb, ptep, address) \
143 do { \ 157 do { \
144 tlb->need_flush = 1; \ 158 tlb->need_flush = 1; \
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index a9ace9c32507..1b921299abc4 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -18,7 +18,7 @@ extern struct page *follow_trans_huge_pmd(struct mm_struct *mm,
18 unsigned int flags); 18 unsigned int flags);
19extern int zap_huge_pmd(struct mmu_gather *tlb, 19extern int zap_huge_pmd(struct mmu_gather *tlb,
20 struct vm_area_struct *vma, 20 struct vm_area_struct *vma,
21 pmd_t *pmd); 21 pmd_t *pmd, unsigned long addr);
22extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, 22extern int mincore_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
23 unsigned long addr, unsigned long end, 23 unsigned long addr, unsigned long end,
24 unsigned char *vec); 24 unsigned char *vec);
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 964fc5a2edd2..5a595554bd8c 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1026,7 +1026,7 @@ out:
1026} 1026}
1027 1027
1028int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, 1028int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
1029 pmd_t *pmd) 1029 pmd_t *pmd, unsigned long addr)
1030{ 1030{
1031 int ret = 0; 1031 int ret = 0;
1032 1032
@@ -1042,6 +1042,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
1042 pgtable = get_pmd_huge_pte(tlb->mm); 1042 pgtable = get_pmd_huge_pte(tlb->mm);
1043 page = pmd_page(*pmd); 1043 page = pmd_page(*pmd);
1044 pmd_clear(pmd); 1044 pmd_clear(pmd);
1045 tlb_remove_pmd_tlb_entry(tlb, pmd, addr);
1045 page_remove_rmap(page); 1046 page_remove_rmap(page);
1046 VM_BUG_ON(page_mapcount(page) < 0); 1047 VM_BUG_ON(page_mapcount(page) < 0);
1047 add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR); 1048 add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
diff --git a/mm/memory.c b/mm/memory.c
index 829d43735402..5e30583c2605 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -293,7 +293,7 @@ int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
293{ 293{
294 struct mmu_gather_batch *batch; 294 struct mmu_gather_batch *batch;
295 295
296 tlb->need_flush = 1; 296 VM_BUG_ON(!tlb->need_flush);
297 297
298 if (tlb_fast_mode(tlb)) { 298 if (tlb_fast_mode(tlb)) {
299 free_page_and_swap_cache(page); 299 free_page_and_swap_cache(page);
@@ -1231,7 +1231,7 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb,
1231 if (next-addr != HPAGE_PMD_SIZE) { 1231 if (next-addr != HPAGE_PMD_SIZE) {
1232 VM_BUG_ON(!rwsem_is_locked(&tlb->mm->mmap_sem)); 1232 VM_BUG_ON(!rwsem_is_locked(&tlb->mm->mmap_sem));
1233 split_huge_page_pmd(vma->vm_mm, pmd); 1233 split_huge_page_pmd(vma->vm_mm, pmd);
1234 } else if (zap_huge_pmd(tlb, vma, pmd)) 1234 } else if (zap_huge_pmd(tlb, vma, pmd, addr))
1235 continue; 1235 continue;
1236 /* fall through */ 1236 /* fall through */
1237 } 1237 }