mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* + mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch added to -mm tree
@ 2021-06-01 20:22 akpm
  2021-06-14 20:58 ` Peter Collingbourne
  0 siblings, 1 reply; 3+ messages in thread
From: akpm @ 2021-06-01 20:22 UTC (permalink / raw)
  To: aarcange, eugenis, kostyak, mm-commits, pcc, peterx


The patch titled
     Subject: mm: improve mprotect(R|W) efficiency on pages referenced once
has been added to the -mm tree.  Its filename is
     mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch

This patch should soon appear at
    https://ozlabs.org/~akpm/mmots/broken-out/mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch
and later at
    https://ozlabs.org/~akpm/mmotm/broken-out/mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Peter Collingbourne <pcc@google.com>
Subject: mm: improve mprotect(R|W) efficiency on pages referenced once

add comments, prohibit optimization for NUMA pages

Link: https://lkml.kernel.org/r/20210601185926.2623183-1-pcc@google.com
Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I98d75ef90e20330c578871c87494d64b1df3f1b8
Link: [1] https://source.android.com/devices/tech/debug/scudo
Link: [2] https://cs.android.com/android/platform/superproject/+/master:bionic/benchmarks/stdlib_benchmark.cpp;l=53;drc=e8693e78711e8f45ccd2b610e4dbe0b94d551cc9
Link: [3] https://github.com/pcc/llvm-project/commit/scudo-mprotect-secondary2
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Kostya Kortchinsky <kostyak@google.com>
Cc: Peter Xu <peterx@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/mprotect.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

--- a/mm/mprotect.c~mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5
+++ a/mm/mprotect.c
@@ -35,10 +35,16 @@
 
 #include "internal.h"
 
+/* Determine whether we can avoid taking write faults for known dirty pages. */
 static bool may_avoid_write_fault(pte_t pte, struct vm_area_struct *vma,
 				  unsigned long cp_flags)
 {
+	/*
+	 * The dirty accountable bit indicates that we can always make the page
+	 * writable regardless of the number of references.
+	 */
 	if (!(cp_flags & MM_CP_DIRTY_ACCT)) {
+		/* Otherwise, we must have exclusive access to the page. */
 		if (!(vma_is_anonymous(vma) && (vma->vm_flags & VM_WRITE)))
 			return false;
 
@@ -46,15 +52,31 @@ static bool may_avoid_write_fault(pte_t
 			return false;
 	}
 
+	/*
+	 * Don't do this optimization for clean pages as we need to be notified
+	 * of the transition from clean to dirty.
+	 */
 	if (!pte_dirty(pte))
 		return false;
 
+	/* Same for softdirty. */
 	if (!pte_soft_dirty(pte) && (vma->vm_flags & VM_SOFTDIRTY))
 		return false;
 
+	/*
+	 * For userfaultfd the user program needs to monitor write faults so we
+	 * can't do this optimization.
+	 */
 	if (pte_uffd_wp(pte))
 		return false;
 
+	/*
+	 * It is unclear whether this optimization can be done safely for NUMA
+	 * pages.
+	 */
+	if (cp_flags & MM_CP_PROT_NUMA)
+		return false;
+
 	return true;
 }
 
@@ -153,7 +175,6 @@ static unsigned long change_pte_range(st
 				ptent = pte_clear_uffd_wp(ptent);
 			}
 
-			/* Avoid taking write faults for known dirty pages */
 			if (may_avoid_write_fault(ptent, vma, cp_flags))
 				ptent = pte_mkwrite(ptent);
 			ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent);
_

Patches currently in -mm which might be from pcc@google.com are

mm-improve-mprotectrw-efficiency-on-pages-referenced-once.patch
mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: + mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch added to -mm tree
  2021-06-01 20:22 + mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch added to -mm tree akpm
@ 2021-06-14 20:58 ` Peter Collingbourne
  2021-06-14 22:03   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Collingbourne @ 2021-06-14 20:58 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Andrea Arcangeli, Evgenii Stepanov, Kostya Kortchinsky,
	mm-commits, Peter Xu, Hridya Valsaraju

On Tue, Jun 1, 2021 at 1:23 PM <akpm@linux-foundation.org> wrote:
>
>
> The patch titled
>      Subject: mm: improve mprotect(R|W) efficiency on pages referenced once
> has been added to the -mm tree.  Its filename is
>      mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch
>
> This patch should soon appear at
>     https://ozlabs.org/~akpm/mmots/broken-out/mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch
> and later at
>     https://ozlabs.org/~akpm/mmotm/broken-out/mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch
>
> Before you just go and hit "reply", please:
>    a) Consider who else should be cc'ed
>    b) Prefer to cc a suitable mailing list as well
>    c) Ideally: find the original patch on the mailing list and do a
>       reply-to-all to that, adding suitable additional cc's
>
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
>
> The -mm tree is included into linux-next and is updated
> there every 3-4 working days
>
> ------------------------------------------------------
> From: Peter Collingbourne <pcc@google.com>
> Subject: mm: improve mprotect(R|W) efficiency on pages referenced once
>
> add comments, prohibit optimization for NUMA pages

Hi Andrew,

I was wondering why this was added as a separate patch instead of
being combined into the previous one. It seems like combining the
patches will be less likely to cause issues in the future (e.g.
someone cherry-picks the v4 patch but not the v4->v5 patch and ends up
breaking NUMA).

Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: + mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch added to -mm tree
  2021-06-14 20:58 ` Peter Collingbourne
@ 2021-06-14 22:03   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2021-06-14 22:03 UTC (permalink / raw)
  To: Peter Collingbourne
  Cc: Andrea Arcangeli, Evgenii Stepanov, Kostya Kortchinsky,
	mm-commits, Peter Xu, Hridya Valsaraju

On Mon, 14 Jun 2021 13:58:09 -0700 Peter Collingbourne <pcc@google.com> wrote:

> > The -mm tree is included into linux-next and is updated
> > there every 3-4 working days
> >
> > ------------------------------------------------------
> > From: Peter Collingbourne <pcc@google.com>
> > Subject: mm: improve mprotect(R|W) efficiency on pages referenced once
> >
> > add comments, prohibit optimization for NUMA pages
> 
> Hi Andrew,
> 
> I was wondering why this was added as a separate patch instead of
> being combined into the previous one. It seems like combining the
> patches will be less likely to cause issues in the future (e.g.
> someone cherry-picks the v4 patch but not the v4->v5 patch and ends up
> breaking NUMA).

I usually do this when sent a replacement patch.  So that I and others
can see what changed, so that bisection can determine whether the new
version caused problems, etc, etc.

I'll collapse the follow-on patches back into the base patch (with
suitable metadata in the changelog to show what happened) prior to
sending to Linus.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-14 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 20:22 + mm-improve-mprotectrw-efficiency-on-pages-referenced-once-v5.patch added to -mm tree akpm
2021-06-14 20:58 ` Peter Collingbourne
2021-06-14 22:03   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).