From: Yury Norov <ynorov@caviumnetworks.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Dan Williams <dan.j.williams@intel.com>,
Huang Ying <ying.huang@intel.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Michel Lespinasse <walken@google.com>,
Souptick Joarder <jrdr.linux@gmail.com>, Willy Tarreau <w@1wt.eu>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: Yury Norov <ynorov@caviumnetworks.com>
Subject: [PATCH] mm: fix COW faults after mlock()
Date: Mon, 24 Sep 2018 16:08:52 +0300 [thread overview]
Message-ID: <20180924130852.12996-1-ynorov@caviumnetworks.com> (raw)
After mlock() on newly mmap()ed shared memory I observe page faults.
The problem is that populate_vma_page_range() doesn't set FOLL_WRITE
flag for writable shared memory in mlock() path, arguing that like:
/*
* We want to touch writable mappings with a write fault in order
* to break COW, except for shared mappings because these don't COW
* and we would not want to dirty them for nothing.
*/
But they are actually COWed. The most straightforward way to avoid it
is to set FOLL_WRITE flag for shared mappings as well as for private ones.
This is the partial revert of commit 5ecfda041e4b4 ("mlock: avoid
dirtying pages and triggering writeback"). So it re-enables dirtying.
The fix works for me (arm64, kernel v4.19-rc4 and v4.9), but after digging
into the code I still don't understand why we need to do copy-on-write on
shared memory. If comment above was correct when 5ecfda041e4b4 became
upstreamed (2011), shared mappings were not COWed back in 2011, but are
COWed now. If so, this is another issue to be fixed.
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
mm/gup.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index 1abc8b4afff6..1899e8bac06b 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1202,10 +1202,9 @@ long populate_vma_page_range(struct vm_area_struct *vma,
gup_flags &= ~FOLL_POPULATE;
/*
* We want to touch writable mappings with a write fault in order
- * to break COW, except for shared mappings because these don't COW
- * and we would not want to dirty them for nothing.
+ * to break COW.
*/
- if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE)
+ if (vma->vm_flags & VM_WRITE)
gup_flags |= FOLL_WRITE;
/*
--
2.17.1
next reply other threads:[~2018-09-24 13:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-24 13:08 Yury Norov [this message]
2018-09-24 21:22 ` Kirill A. Shutemov
2018-09-24 23:48 ` Yury Norov
2018-09-25 10:48 ` Kirill A. Shutemov
2018-10-11 5:37 ` [LKP] [mm] dd12385915: vm-scalability.median 18.6% improvement kernel test robot
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=20180924130852.12996-1-ynorov@caviumnetworks.com \
--to=ynorov@caviumnetworks.com \
--cc=akpm@linux-foundation.org \
--cc=dan.j.williams@intel.com \
--cc=jrdr.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mst@redhat.com \
--cc=viro@zeniv.linux.org.uk \
--cc=w@1wt.eu \
--cc=walken@google.com \
--cc=ying.huang@intel.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