mm/mmu_gather: Track page size with mmu gather and force flush if page size change
Subsystems (6)
RFC PATCH 1/1 mm/mmu_gather: Track page size with mmu gather and force flush if page size change
This allows arch which need to do special handing with respect to different page size when flushing tlb to implement the same in mmu gather
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- include/asm-generic/tlb.h | 11 +++++++--- mm/huge_memory.c | 2 +- mm/hugetlb.c | 54 ++++++++++++++++++----------------------------- mm/memory.c | 38 +++++++++++++++++++++++++++------ 4 files changed, 61 insertions(+), 44 deletions(-)
include/asm-generic/tlb.h +8 -3
@@ -107,6 +107,7 @@ struct mmu_gather {struct mmu_gather_batch local;struct page *__pages[MMU_GATHER_BUNDLE ];unsigned int batch_count; +int page_size; };#define HAVE_GENERIC_MMU_GATHER
@@ -115,16 +116,20 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned longvoid tlb_flush_mmu (struct mmu_gather *tlb);void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); -int __tlb_remove_page (struct mmu_gather *tlb,struct page *page); +bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page,int page_size);/* tlb_remove_page * Similar to __tlb_remove_page but will call tlb_flush_mmu() itself when * required. */ -static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page) +static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page, +int page_size) { -if (!__tlb_remove_page (tlb, page)) +if (__tlb_remove_page (tlb, page, page_size)) {tlb_flush_mmu (tlb); + tlb->page_size = page_size; +__tlb_remove_page (tlb, page, page_size); + } } static inline void __tlb_adjust_range(struct mmu_gather *tlb,
mm/huge_memory.c +1 -1
@@ -1669,7 +1669,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,pte_free (tlb->mm,pgtable_trans_huge_withdraw (tlb->mm, pmd));atomic_long_dec (&tlb->mm->nr_ptes);spin_unlock (ptl); -tlb_remove_page (tlb, page); +tlb_remove_page (tlb, page,HPAGE_PMD_SIZE ); }return 1 ; }
mm/hugetlb.c +21 -33
93 lines not on this page · raw message
mm/memory.c +31 -7
@@ -231,6 +231,7 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long#ifdef CONFIG_HAVE_RCU_TABLE_FREE tlb->batch =NULL ;#endif + tlb->page_size =0 ;__tlb_reset_range (tlb); }
@@ -290,23 +291,39 @@ void tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long e* handling the additional races in SMP caused by other CPUs caching valid * mappings in their TLBs. Returns the number of free page slots left. * When out of page slots we must call tlb_flush_mmu(). +*returns true if the caller should flush. */ -int __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page,int page_size) {struct mmu_gather_batch *batch;VM_BUG_ON (!tlb->end); +if (!tlb->page_size) + tlb->page_size = page_size; +else { +if (page_size != tlb->page_size) +return true; + } + batch = tlb->active; - batch->pages[batch->nr++] = page;if (batch->nr == batch->max) {if (!tlb_next_batch (tlb)) -return 0 ; +return true; batch = tlb->active; }VM_BUG_ON_PAGE (batch->nr > batch->max, page); -return batch->max - batch->nr; + batch->pages[batch->nr++] = page; +return false; +} + +int __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) +{ +/* active->nr should be zero when we call this */ +VM_BUG_ON_PAGE (tlb->active->nr, page); + tlb->page_size =PAGE_SIZE ; +return __tlb_remove_page (tlb, page,PAGE_SIZE ); }#endif /* HAVE_GENERIC_MMU_GATHER */
@@ -1071,6 +1088,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,pte_t *start_pte;pte_t *pte;swp_entry_t entry; +struct page *delayed_page =NULL ; again:init_rss_vec (rss);
@@ -1116,8 +1134,9 @@ again:page_remove_rmap (page, false);if (unlikely (page_mapcount (page) <0 ))print_bad_pte (vma, addr, ptent, page); -if (unlikely (!__tlb_remove_page (tlb, page))) { +if (unlikely (__tlb_remove_page (tlb, page,PAGE_SIZE ))) { force_flush =1 ; + delayed_page = page; addr +=PAGE_SIZE ;break ; }
@@ -1158,9 +1177,14 @@ again:if (force_flush) { force_flush =0 ;tlb_flush_mmu_free (tlb); - -if (addr != end) +if (delayed_page) { +/* remove the page with new size */ +__tlb_remove_pte_page (tlb, delayed_page); + delayed_page =NULL ; + } +if (addr != end) { goto again; + } }return addr;
Signature · 7 lines
2.5.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>