linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Peter Collingbourne <pcc@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kostya Kortchinsky <kostyak@google.com>,
	Evgenii Stepanov <eugenis@google.com>,
	linux-mm@kvack.org, Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH v3] mm: improve mprotect(R|W) efficiency on pages referenced once
Date: Fri, 21 May 2021 14:57:54 -0400	[thread overview]
Message-ID: <YKgCsmMVp3wNLLBB@t490s> (raw)
In-Reply-To: <20210429214801.2583336-1-pcc@google.com>

On Thu, Apr 29, 2021 at 02:48:01PM -0700, Peter Collingbourne wrote:
> @@ -132,9 +134,12 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  			}
>  
>  			/* Avoid taking write faults for known dirty pages */
> -			if (dirty_accountable && pte_dirty(ptent) &&
> -					(pte_soft_dirty(ptent) ||
> -					 !(vma->vm_flags & VM_SOFTDIRTY))) {
> +			if ((dirty_accountable ||
> +			     (anon_writable &&
> +			      page_mapcount(pte_page(ptent)) == 1)) &&
> +			    pte_dirty(ptent) &&
> +			    (pte_soft_dirty(ptent) ||
> +			     !(vma->vm_flags & VM_SOFTDIRTY))) {
>  				ptent = pte_mkwrite(ptent);
>  			}
>  			ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent);

This breaks uffd-wp anonymous page.  I think we'd at least need below to be
squashed:

diff --git a/mm/mprotect.c b/mm/mprotect.c
index ed10a790933e..6cb531eab811 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -139,6 +139,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                             (anon_writable &&
                              page_mapcount(pte_page(ptent)) == 1)) &&
                            pte_dirty(ptent) &&
+                           !pte_uffd_wp(ptent) &&
                            (pte_soft_dirty(ptent) ||
                             !(vma->vm_flags & VM_SOFTDIRTY))) {
                                ptent = pte_mkwrite(ptent);

It'll be good to start thinking about how to not continue growing this if
clause condition, though..

-- 
Peter Xu



      reply	other threads:[~2021-05-21 18:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 21:48 Peter Collingbourne
2021-05-21 18:57 ` Peter Xu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YKgCsmMVp3wNLLBB@t490s \
    --to=peterx@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=eugenis@google.com \
    --cc=kostyak@google.com \
    --cc=linux-mm@kvack.org \
    --cc=pcc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox