public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Hugh Dickins <hugh@veritas.com>, Greg KH <gregkh@suse.de>,
	Maksim Yevmenkin <maksim.yevmenkin@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Nick Piggin <npiggin@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	will@crowder-design.com, Rik van Riel <riel@redhat.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Subject: Re: [PATCH] Fix OOPS in mmap_region() when merging adjacent VM_LOCKED file segments
Date: Fri, 30 Jan 2009 14:53:10 -0500	[thread overview]
Message-ID: <1233345190.908.36.camel@lts-notebook> (raw)
In-Reply-To: <alpine.LFD.2.00.0901300946360.3150@localhost.localdomain>

On Fri, 2009-01-30 at 10:14 -0800, Linus Torvalds wrote:
> 
> On Fri, 30 Jan 2009, Hugh Dickins wrote:
> > 
> > ... what I think you have done is break the vma merging on
> > ordinary files: because of that irritating VM_CAN_NONLINEAR
> > flag which generic_file_mmap() and some others add in.
> 
> Ahh. Yes. VM_CAN_NONLINEAR is a "reverse flag", ie unlike the other flags 
> it's to some degree about being extra _normal_, not about being odd. Most 
> special flags tend to disable the VM from doing some clever thing, this 
> one enables it.
> 
> > To break the merging won't cause anyone much trouble,
> > but is a slight regression we should fix.
> 
> Yeah. Just masking it off when comparing is probably the simplest option. 
> Make it a separate #define just for readability. There might be other 
> flags like this in the future.
> 
> > I'd have been very upset not to find something ;)
> 
> Yay for you ;)
> 
> And yes, this is the kind of thing that probably does mean that we're 
> better off with the no-semantic-changes patches in -stable.
> 
> 		Linus
> 
> ---
>  mm/mmap.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d3fa10a..c581df1 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -658,6 +658,9 @@ again:			remove_next = 1 + (end > next->vm_end);
>  	validate_mm(mm);
>  }
>  
> +/* Flags that can be inherited from an existing mapping when merging */
> +#define VM_MERGEABLE_FLAGS (VM_CAN_NONLINEAR)
> +
>  /*
>   * If the vma has a ->close operation then the driver probably needs to release
>   * per-vma resources, so we don't attempt to merge those.
> @@ -665,7 +668,7 @@ again:			remove_next = 1 + (end > next->vm_end);
>  static inline int is_mergeable_vma(struct vm_area_struct *vma,
>  			struct file *file, unsigned long vm_flags)
>  {
> -	if (vma->vm_flags != vm_flags)
> +	if ((vma->vm_flags ^ vm_flags) & ~VM_MERGEABLE_FLAGS)
>  		return 0;
>  	if (vma->vm_file != file)
>  		return 0;

I tried this patch atop 29-rc3 + your patch from yesterday with my
simple test program at http://free.linux/hp.com/~lts/Tests/mmap_lock.c. 

The test program shows the /proc/<pid>/maps before and after the mmap
and attempted merge.  It's not merging:

7fd20a668000-7fd20a66a000 rw-p 7fd20a668000 00:00 0 
7fd20a68a000-7fd20a68b000 r--s 00000000 68:23 6608852                    /tmp/tmpfVx1SFL (deleted)
7fd20a68b000-7fd20a68c000 r--s 00001000 68:23 6608852                    /tmp/tmpfVx1SFL (deleted)
7fd20a68c000-7fd20a690000 rw-p 7fd20a68c000 00:00 0 

Ad hoc instrumentation shows that it's the VM_ACCOUNT flag that is
different between the existing file segment and the one attempting the
merge:

is_mergeable_vma: !mergable: vma flags:  0x80020f9:0x1020f9
                                           |         |-VM_ACCOUNT
                                           +-----------VM_CAN_NONLINEAR

So happens, I'm mapping with MAP_SHARED, so the VM_ACCOUNT flag gets
cleared later in mmap_region().  Comments say that this is for checking
memory availability during shmem_file_setup().  Maybe we can move the
temporary setting of VM_ACCOUNT until just before the call to
shmem_zero_setup()?

Lee


  parent reply	other threads:[~2009-01-30 19:53 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bb4a86c70901281151w4300605r3882461cd6e9774a@mail.gmail.com>
     [not found] ` <alpine.LFD.2.00.0901281316450.3123@localhost.localdomain>
2009-01-29 20:03   ` [PATCH] Fix OOPS in mmap_region() when merging adjacent VM_LOCKED file segments Lee Schermerhorn
2009-01-29 20:33     ` Linus Torvalds
2009-01-29 20:48       ` Linus Torvalds
2009-01-29 22:32         ` Hugh Dickins
2009-01-29 23:02           ` Linus Torvalds
2009-01-30  4:43             ` Lee Schermerhorn
2009-01-30  4:49               ` Linus Torvalds
2009-01-29 22:47         ` Maksim Yevmenkin
2009-01-29 22:48           ` Randy Dunlap
2009-01-29 23:31             ` Maksim Yevmenkin
2009-01-30  2:08           ` Linus Torvalds
2009-01-30  5:56             ` Greg KH
2009-01-30 16:36               ` Linus Torvalds
2009-01-30 17:40                 ` Hugh Dickins
2009-01-30 18:14                   ` Linus Torvalds
2009-01-30 18:30                     ` Hugh Dickins
2009-01-30 19:53                     ` Lee Schermerhorn [this message]
2009-01-30 20:31                       ` Linus Torvalds
2009-01-30 21:12                         ` Hugh Dickins
2009-01-30 21:25                           ` Linus Torvalds
2009-01-30 21:36                           ` Lee Schermerhorn
2009-01-30 22:27                             ` Linus Torvalds
2009-01-31 12:35                               ` Hugh Dickins
2009-01-31 18:34                                 ` Linus Torvalds
2009-02-02 11:59                                   ` KOSAKI Motohiro
2009-02-02 12:54                                     ` Hugh Dickins
2009-02-02 14:10                                       ` KOSAKI Motohiro
2009-02-02 18:58                                         ` Mel Gorman
2009-02-02 19:23                                           ` Linus Torvalds
2009-02-02 21:50                                             ` Mel Gorman
2009-02-02 22:12                                               ` Linus Torvalds
2009-02-02 22:35                                                 ` Mel Gorman
2009-02-02 18:33                                       ` Mel Gorman
2009-02-03 16:13                                 ` Lee Schermerhorn
2009-02-03 16:40                                   ` Linus Torvalds
2009-02-03 17:10                                   ` Hugh Dickins
2009-02-03 21:50                                     ` Lee Schermerhorn
2009-01-30 21:37                           ` Linus Torvalds
2009-01-31 12:16                             ` Hugh Dickins
2009-01-30 20:33                       ` Hugh Dickins
2009-01-30 20:53                       ` Randy Dunlap
2009-01-30 20:59                         ` Lee Schermerhorn
2009-01-30 21:11                           ` Will Crowder
2009-01-30 23:44                   ` Greg KH
2009-01-30  8:34         ` Peter Zijlstra
2009-01-30 16:45           ` Linus Torvalds
2009-01-30 16:49             ` Randy Dunlap

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=1233345190.908.36.camel@lts-notebook \
    --to=lee.schermerhorn@hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@suse.de \
    --cc=hugh@veritas.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maksim.yevmenkin@gmail.com \
    --cc=npiggin@suse.de \
    --cc=riel@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=will@crowder-design.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