Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1659998

[RFC][PATCH 1/5] mm: Rework {set,clear,mm}_tlb_flush_pending()

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject [RFC][PATCH 1/5] mm: Rework {set,clear,mm}_tlb_flush_pending()
Date 2017-06-07 18:30 +0200
Message-ID <tPM0j-zo-31@gated-at.bofh.it> (permalink)
References <tPM0i-zo-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Commit:

  af2c1401e6f9 ("mm: numa: guarantee that tlb_flush_pending updates are visible before page table updates")

added smp_mb__before_spinlock() to set_tlb_flush_pending(). I think we
can solve the same problem without this barrier.

If instead we mandate that mm_tlb_flush_pending() is used while
holding the PTL we're guaranteed to observe prior
set_tlb_flush_pending() instances.

For this to work we need to rework migrate_misplaced_transhuge_page()
a little and move the test up into do_huge_pmd_numa_page().

Cc: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -527,18 +527,16 @@ static inline cpumask_t *mm_cpumask(stru
  */
 static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
 {
-	barrier();
+	/*
+	 * Must be called with PTL held; such that our PTL acquire will have
+	 * observed the store from set_tlb_flush_pending().
+	 */
 	return mm->tlb_flush_pending;
 }
 static inline void set_tlb_flush_pending(struct mm_struct *mm)
 {
 	mm->tlb_flush_pending = true;
-
-	/*
-	 * Guarantee that the tlb_flush_pending store does not leak into the
-	 * critical section updating the page tables
-	 */
-	smp_mb__before_spinlock();
+	barrier();
 }
 /* Clearing is done after a TLB flush, which also provides a barrier. */
 static inline void clear_tlb_flush_pending(struct mm_struct *mm)
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1410,6 +1410,7 @@ int do_huge_pmd_numa_page(struct vm_faul
 	unsigned long haddr = vmf->address & HPAGE_PMD_MASK;
 	int page_nid = -1, this_nid = numa_node_id();
 	int target_nid, last_cpupid = -1;
+	bool need_flush = false;
 	bool page_locked;
 	bool migrated = false;
 	bool was_writable;
@@ -1490,10 +1491,29 @@ int do_huge_pmd_numa_page(struct vm_faul
 	}
 
 	/*
+	 * Since we took the NUMA fault, we must have observed the !accessible
+	 * bit. Make sure all other CPUs agree with that, to avoid them
+	 * modifying the page we're about to migrate.
+	 *
+	 * Must be done under PTL such that we'll observe the relevant
+	 * set_tlb_flush_pending().
+	 */
+	if (mm_tlb_flush_pending(mm))
+		need_flush = true;
+
+	/*
 	 * Migrate the THP to the requested node, returns with page unlocked
 	 * and access rights restored.
 	 */
 	spin_unlock(vmf->ptl);
+
+	/*
+	 * We are not sure a pending tlb flush here is for a huge page
+	 * mapping or not. Hence use the tlb range variant
+	 */
+	if (need_flush)
+		flush_tlb_range(vma, haddr, haddr + HPAGE_PMD_SIZE);
+
 	migrated = migrate_misplaced_transhuge_page(vma->vm_mm, vma,
 				vmf->pmd, pmd, vmf->address, page, target_nid);
 	if (migrated) {
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1935,12 +1935,6 @@ int migrate_misplaced_transhuge_page(str
 		put_page(new_page);
 		goto out_fail;
 	}
-	/*
-	 * We are not sure a pending tlb flush here is for a huge page
-	 * mapping or not. Hence use the tlb range variant
-	 */
-	if (mm_tlb_flush_pending(mm))
-		flush_tlb_range(vma, mmun_start, mmun_end);
 
 	/* Prepare a page as a migration target */
 	__SetPageLocked(new_page);

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC][PATCH 0/5] Getting rid of smp_mb__before_spinlock Peter Zijlstra <peterz@infradead.org> - 2017-06-07 18:30 +0200
  [RFC][PATCH 2/5] locking: Introduce smp_mb__after_spinlock(). Peter Zijlstra <peterz@infradead.org> - 2017-06-07 18:30 +0200
  [RFC][PATCH 1/5] mm: Rework {set,clear,mm}_tlb_flush_pending() Peter Zijlstra <peterz@infradead.org> - 2017-06-07 18:30 +0200
    Re: [RFC][PATCH 1/5] mm: Rework {set,clear,mm}_tlb_flush_pending() Will Deacon <will.deacon@arm.com> - 2017-06-09 16:50 +0200
      Re: [RFC][PATCH 1/5] mm: Rework {set,clear,mm}_tlb_flush_pending() Peter Zijlstra <peterz@infradead.org> - 2017-06-09 20:50 +0200
  [RFC][PATCH 3/5] overlayfs: Remove smp_mb__before_spinlock() usage Peter Zijlstra <peterz@infradead.org> - 2017-06-07 18:30 +0200
  [RFC][PATCH 4/5] locking: Remove smp_mb__before_spinlock() Peter Zijlstra <peterz@infradead.org> - 2017-06-07 18:30 +0200
  [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Peter Zijlstra <peterz@infradead.org> - 2017-06-07 18:30 +0200
    Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Nicholas Piggin <npiggin@gmail.com> - 2017-06-08 02:40 +0200
      Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Peter Zijlstra <peterz@infradead.org> - 2017-06-08 09:00 +0200
        Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Nicholas Piggin <npiggin@gmail.com> - 2017-06-08 09:40 +0200
          Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Peter Zijlstra <peterz@infradead.org> - 2017-06-08 10:00 +0200
            Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Nicholas Piggin <npiggin@gmail.com> - 2017-06-08 10:30 +0200
            Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Michael Ellerman <mpe@ellerman.id.au> - 2017-06-08 12:00 +0200
              Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Nicholas Piggin <npiggin@gmail.com> - 2017-06-08 12:10 +0200
                Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Peter Zijlstra <peterz@infradead.org> - 2017-06-08 14:50 +0200
                Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Nicholas Piggin <npiggin@gmail.com> - 2017-06-08 15:20 +0200
                Re: [RFC][PATCH 5/5] powerpc: Remove SYNC from _switch Peter Zijlstra <peterz@infradead.org> - 2017-06-08 15:50 +0200
  Re: [RFC][PATCH 0/5] Getting rid of smp_mb__before_spinlock Will Deacon <will.deacon@arm.com> - 2017-06-09 17:00 +0200

csiph-web