public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Suleiman Souhlal <ssouhlal@FreeBSD.org>,
	linux-kernel@vger.kernel.org,
	Suleiman Souhlal <suleiman@google.com>
Subject: Re: [PATCH] Don't needlessly dirty mlocked pages when initially faulting them in.
Date: Fri, 27 Jul 2007 08:33:30 +0200	[thread overview]
Message-ID: <1185518010.15205.36.camel@lappy> (raw)
In-Reply-To: <20070726172330.d3409b57.akpm@linux-foundation.org>

On Thu, 2007-07-26 at 17:23 -0700, Andrew Morton wrote:
> On Thu, 26 Jul 2007 16:52:44 -0700 Suleiman Souhlal <ssouhlal@FreeBSD.org> wrote:
> 
> > make_pages_present() is dirtying mlocked pages if the VMA is writable, even
> > though it shouldn't, by telling get_user_pages() to simulate a write fault.
> > 
> > A simple way to test this is to mlock a multi-GB file, and then sync.
> > The sync will take a long time.
> 
> ugh, how bad of us.
> 
> > As far as I can see, it should be safe to just not simulate a write fault.
> 
> We pass in "write=1" to force a COW.  This is because we want to do all
> that memory allocation at mlock()-time, not later on, when the app writes
> to the page.

<snip patch>

> So something sterner will need to be done.  I guess the write_access arg to
> handle_mm_fault() would need to become a three-value thing.

That would be most painfull. Can't we simply set write=0 for shared
mappings? Those won't have COW to break and are the onces that do
requires writeback. Anonymous and private mappings do COW but will never
writeback and are thus save to touch with write=1.

How about something like this:

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 mm/memory.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6/mm/memory.c
===================================================================
--- linux-2.6.orig/mm/memory.c
+++ linux-2.6/mm/memory.c
@@ -2716,7 +2716,12 @@ int make_pages_present(unsigned long add
 	vma = find_vma(current->mm, addr);
 	if (!vma)
 		return -1;
-	write = (vma->vm_flags & VM_WRITE) != 0;
+	/*
+	 * We want to touch writable mappings with a write fault in otder
+	 * to break COW, except for shared mappings because these don't COW
+	 * and we would not want to dirty them for nothing.
+	 */
+	write = (vma->vm_flags & VM_WRITE|VM_SHARED) == VM_WRITE;
 	BUG_ON(addr >= end);
 	BUG_ON(end > vma->vm_end);
 	len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE;



  reply	other threads:[~2007-07-27  6:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-26 23:52 [PATCH] Don't needlessly dirty mlocked pages when initially faulting them in Suleiman Souhlal
2007-07-27  0:23 ` Andrew Morton
2007-07-27  6:33   ` Peter Zijlstra [this message]
2007-10-12  6:50     ` Suleiman Souhlal
2007-10-12  9:03       ` [PATCH] mm: avoid dirtying shared mappings on mlock Peter Zijlstra
2007-10-11 16:57         ` Nick Piggin
2007-10-11 17:07           ` Nick Piggin
2007-10-12 10:37           ` Peter Zijlstra
2007-10-11 18:14             ` Nick Piggin
2007-10-12 10:50               ` Peter Zijlstra
2007-10-12 12:23                 ` Nick Piggin
2007-10-12 14:53                 ` Arjan van de Ven
2007-10-12 14:58                   ` Peter Zijlstra
2007-10-12 17:45                     ` Suleiman Souhlal
2007-10-12 17:53                       ` Arjan van de Ven
2007-10-12 18:02                       ` Peter Zijlstra
2007-10-12 13:10     ` [PATCH] Don't needlessly dirty mlocked pages when initially faulting them in Mauro Giachero

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=1185518010.15205.36.camel@lappy \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ssouhlal@FreeBSD.org \
    --cc=suleiman@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