[PATCH 04 of 11] free-pgtables

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>
Cc: Christoph Lameter <clameter@...>, Jack Steiner <steiner@...>, Robin Holt <holt@...>, Nick Piggin <npiggin@...>, Peter Zijlstra <a.p.zijlstra@...>, <kvm-devel@...>, Kanoj Sarcar <kanojsarcar@...>, Roland Dreier <rdreier@...>, Steve Wise <swise@...>, <linux-kernel@...>, Avi Kivity <avi@...>, <linux-mm@...>, <general@...>, Hugh Dickins <hugh@...>, <akpm@...>, Rusty Russell <rusty@...>, Anthony Liguori <aliguori@...>, Chris Wright <chrisw@...>, Marcelo Tosatti <marcelo@...>, Eric Dumazet <dada1@...>, Paul E. McKenney <paulmck@...>
Date: Friday, May 2, 2008 - 11:05 am

# HG changeset patch
# User Andrea Arcangeli <andrea@qumranet.com>
# Date 1209740185 -7200
# Node ID 14e9f5a12bb1657fa6756e18d5dac71d4ad1a55e
# Parent  ea8fc9187b6d3ef2742061b4f62598afe55281cf
free-pgtables

Move the tlb flushing into free_pgtables. The conversion of the locks
taken for reverse map scanning would require taking sleeping locks
in free_pgtables() and we cannot sleep while gathering pages for a tlb
flush.

Move the tlb_gather/tlb_finish call to free_pgtables() to be done
for each vma. This may add a number of tlb flushes depending on the
number of vmas that cannot be coalesced into one.

The first pointer argument to free_pgtables() can then be dropped.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>

diff --git a/include/linux/mm.h b/include/linux/mm.h
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -772,8 +772,8 @@ int walk_page_range(const struct mm_stru
 		    void *private);
 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);
+void free_pgtables(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);
 void unmap_mapping_range(struct address_space *mapping,
diff --git a/mm/memory.c b/mm/memory.c
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -272,9 +272,11 @@ void free_pgd_range(struct mmu_gather **
 	} while (pgd++, addr = next, addr != end);
 }
 
-void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *vma,
-		unsigned long floor, unsigned long ceiling)
+void free_pgtables(struct vm_area_struct *vma, unsigned long floor,
+							unsigned long ceiling)
 {
+	struct mmu_gather *tlb;
+
 	while (vma) {
 		struct vm_area_struct *next = vma->vm_next;
 		unsigned long addr = vma->vm_start;
@@ -286,7 +288,8 @@ void free_pgtables(struct mmu_gather **t
 		unlink_file_vma(vma);
 
 		if (is_vm_hugetlb_page(vma)) {
-			hugetlb_free_pgd_range(tlb, addr, vma->vm_end,
+			tlb = tlb_gather_mmu(vma->vm_mm, 0);
+			hugetlb_free_pgd_range(&tlb, addr, vma->vm_end,
 				floor, next? next->vm_start: ceiling);
 		} else {
 			/*
@@ -299,9 +302,11 @@ void free_pgtables(struct mmu_gather **t
 				anon_vma_unlink(vma);
 				unlink_file_vma(vma);
 			}
-			free_pgd_range(tlb, addr, vma->vm_end,
+			tlb = tlb_gather_mmu(vma->vm_mm, 0);
+			free_pgd_range(&tlb, addr, vma->vm_end,
 				floor, next? next->vm_start: ceiling);
 		}
+		tlb_finish_mmu(tlb, addr, vma->vm_end);
 		vma = next;
 	}
 }
diff --git a/mm/mmap.c b/mm/mmap.c
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1759,9 +1759,9 @@ static void unmap_region(struct mm_struc
 	update_hiwater_rss(mm);
 	unmap_vmas(&tlb, vma, start, end, &nr_accounted, NULL);
 	vm_unacct_memory(nr_accounted);
-	free_pgtables(&tlb, vma, prev? prev->vm_end: FIRST_USER_ADDRESS,
+	tlb_finish_mmu(tlb, start, end);
+	free_pgtables(vma, prev? prev->vm_end: FIRST_USER_ADDRESS,
 				 next? next->vm_start: 0);
-	tlb_finish_mmu(tlb, start, end);
 }
 
 /*
@@ -2060,8 +2060,8 @@ void exit_mmap(struct mm_struct *mm)
 	/* Use -1 here to ensure all VMAs in the mm are unmapped */
 	end = unmap_vmas(&tlb, vma, 0, -1, &nr_accounted, NULL);
 	vm_unacct_memory(nr_accounted);
-	free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
 	tlb_finish_mmu(tlb, 0, end);
+	free_pgtables(vma, FIRST_USER_ADDRESS, 0);
 
 	/*
 	 * Walk the list again, actually closing and freeing it,
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00 of 11] mmu notifier #v15, Andrea Arcangeli, (Fri May 2, 11:05 am)
Re: [PATCH 00 of 11] mmu notifier #v15, Jack Steiner, (Sat May 3, 7:09 am)
[PATCH 11 of 11] mmap sems, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 10 of 11] export zap_page_range for XPMEM, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 09 of 11] mm_lock-rwsem, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 08 of 11] anon-vma-rwsem, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 07 of 11] i_mmap_rwsem, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 06 of 11] rwsem contended, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 05 of 11] unmap vmas tlb flushing, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 04 of 11] free-pgtables, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 03 of 11] invalidate_page outside PT lock, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 02 of 11] get_task_mm, Andrea Arcangeli, (Fri May 2, 11:05 am)
[PATCH 01 of 11] mmu-notifier-core, Andrea Arcangeli, (Fri May 2, 11:05 am)
Re: [PATCH 01 of 11] mmu-notifier-core, Jack Steiner, (Mon May 5, 12:21 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Andrea Arcangeli, (Mon May 5, 1:14 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Jack Steiner, (Mon May 5, 1:25 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Andrea Arcangeli, (Mon May 5, 2:34 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Jack Steiner, (Mon May 5, 3:46 pm)
mmu notifier v15 -&gt; v16 diff, Andrea Arcangeli, (Tue May 6, 1:53 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Andrea Arcangeli, (Tue May 6, 10:46 am)
Re: [PATCH 01 of 11] mmu-notifier-core, Robin Holt, (Sun May 4, 3:13 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Andrea Arcangeli, (Sun May 4, 6:08 pm)
Re: [PATCH 01 of 11] mmu-notifier-core, Robin Holt, (Sun May 4, 10:25 pm)