linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Colin Cross <ccross@android.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Kyungmin Park <kmpark@infradead.org>,
	Christoph Hellwig <hch@infradead.org>,
	John Stultz <john.stultz@linaro.org>,
	Rob Landley <rob@landley.net>, Arnd Bergmann <arnd@arndb.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	David Rientjes <rientjes@google.com>,
	Davidlohr Bueso <dave@gnu.org>, Kees Cook <keescook@chromium.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Hugh Dickins <hughd@google.com>, Mel Gorman <mgorman@suse.de>,
	Michel Lespinasse <walken@google.com>,
	Rik van Riel <riel@redhat.com>,
	Konstantin Khlebnikov <khlebnikov@openvz.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Rusty Russell <rusty@rustcorp.com.au>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Michal Hocko <mhocko@suse.cz>,
	Anton Vorontsov <anton.vorontsov@linaro.org>,
	Pekka Enberg <penberg@kernel.org>, Shaohua Li <shli@fusionio.com>,
	Sasha Levin <sasha.levin@oracle.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Ingo Molnar <mingo@kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
	"open list:GENERIC INCLUDE/A..." <linux-arch@vger.kernel.org>
Subject: Re: [PATCH] mm: add sys_madvise2 and MADV_NAME to name vmas
Date: Fri, 5 Jul 2013 12:40:50 -0700	[thread overview]
Message-ID: <CAMbhsRRjGjo_-zSigmdsDvY-kfBhmP49bDQzsgHfj5N-y+ZAdw@mail.gmail.com> (raw)
In-Reply-To: <20130704202232.GA19287@redhat.com>

On Thu, Jul 4, 2013 at 1:22 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> On 07/03, Colin Cross wrote:
>>
>> The names of named anonymous vmas are shown in /proc/pid/maps
>> as [anon:<name>].  The name of all named vmas are shown in
>> /proc/pid/smaps in a new "Name" field that is only present
>> for named vmas.
>
> And this is the only purpose, yes?

Yes

>>  static long madvise_behavior(struct vm_area_struct * vma,
>>                    struct vm_area_struct **prev,
>> -                  unsigned long start, unsigned long end, int behavior)
>> +                  unsigned long start, unsigned long end, int behavior,
>> +                  void *arg, size_t arg_len)
>>  {
>>       struct mm_struct * mm = vma->vm_mm;
>>       int error = 0;
>>       pgoff_t pgoff;
>>       unsigned long new_flags = vma->vm_flags;
>> +     struct vma_name *new_name = vma->vm_name;
>>
>>       switch (behavior) {
>>       case MADV_NORMAL:
>> @@ -93,16 +97,28 @@ static long madvise_behavior(struct vm_area_struct * vma,
>>               if (error)
>>                       goto out;
>>               break;
>> +     case MADV_NAME:
>> +             if (arg) {
>> +                     new_name = vma_name_get_from_str(arg, arg_len);
>> +                     if (!new_name) {
>> +                             error = -ENOMEM;
>> +                             goto out;
>> +                     }
>> +             } else {
>> +                     new_name = NULL;
>> +             }
>> +             break;
>>       }
>>
>> -     if (new_flags == vma->vm_flags) {
>> +     if (new_flags == vma->vm_flags && new_name == vma->vm_name) {
>>               *prev = vma;
>>               goto out;
>>       }
>>
>>       pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT);
>>       *prev = vma_merge(mm, *prev, start, end, new_flags, vma->anon_vma,
>> -                             vma->vm_file, pgoff, vma_policy(vma));
>> +                             vma->vm_file, pgoff, vma_policy(vma),
>> +                             new_name);
>>       if (*prev) {
>>               vma = *prev;
>>               goto success;
>> @@ -127,8 +143,17 @@ success:
>>        * vm_flags is protected by the mmap_sem held in write mode.
>>        */
>>       vma->vm_flags = new_flags;
>> +     if (vma->vm_name != new_name) {
>> +             if (vma->vm_name)
>> +                     vma_name_put(vma->vm_name);
>> +             if (new_name)
>> +                     vma_name_get(new_name);
>> +             vma->vm_name = new_name;
>> +     }
>
> So we change vma->vm_name after vma_merge(). But given that is_mergeable_vma()
> checks vma->vm_name with this patch, this means that we can have 2 vma's with
> the same ->vm_name which should be merged?
>
> IOW. Suppose that we have vma with vm_start = START, end = START + 2 * PAGE_SIZE.
> Suppose that an application does
>
>         MADV_NAME(START, PAGE_SIZE, "MY_NAME");
>         MADV_NAME(START + PAGE_SIZE, PAGE_SIZE, "MY_NAME");
>
> The 1st MADV_NAME will split this vma, the 2nd won't merge. Not that I think
> this is buggy, just a bit inconsistent imho.

My intention is that any vmas that would be merged without names would
be merged if they have the same name.  I copied the logic used for
vm_flags, but I'll take another look.

> And I guess vma_name_get(new_name) is not needed, you can simply nullify it
> after changing ->vm_name to avoid vma_name_put() below.

Good point, I'll fix it in the next version.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2013-07-05 19:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-04  1:31 Colin Cross
2013-07-04  4:54 ` Eric W. Biederman
2013-07-04  6:32   ` Colin Cross
2013-07-05 16:52     ` Oleg Nesterov
2013-07-06  6:33   ` Pekka Enberg
2013-07-06 11:53     ` Eric W. Biederman
2013-07-07 18:35       ` Colin Cross
2013-07-14  1:38   ` Simon Jeons
2013-07-04  8:56 ` Peter Zijlstra
2013-07-05 20:25   ` Colin Cross
2013-07-10 23:20     ` Dave Hansen
2013-07-04 20:22 ` Oleg Nesterov
2013-07-05 19:40   ` Colin Cross [this message]
2013-07-08 18:04     ` [PATCH 0/1] mm: mempolicy: (Was: add sys_madvise2 and MADV_NAME to name vmas) Oleg Nesterov
2013-07-08 18:05       ` [PATCH 1/1] mm: mempolicy: fix mbind_range() && vma_adjust() interaction Oleg Nesterov
2013-07-08 22:29         ` KOSAKI Motohiro
2013-07-09 15:28           ` Oleg Nesterov
2013-07-09 19:43             ` Oleg Nesterov
2013-07-10  2:49             ` KOSAKI Motohiro
2013-07-09 21:56         ` Andrew Morton
2013-07-10 15:45           ` Oleg Nesterov
2013-07-24  9:40     ` [PATCH] mm: add sys_madvise2 and MADV_NAME to name vmas Jan Glauber
2013-07-24 20:05       ` Colin Cross
2013-07-10 23:08 ` Dave Hansen
     [not found]   ` <CAMbhsRTio2mS=azWTxSdRdaZJRRf5FfMNoQUZmrFjkB7kv9LSQ@mail.gmail.com>
2013-07-10 23:38     ` Dave Hansen
     [not found]       ` <CAMbhsRTs45QE1ze6mvdiL2QYKD0dHjXoRk7o1h2Y_rYP80ckDg@mail.gmail.com>
2013-07-11  0:19         ` Dave Hansen

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=CAMbhsRRjGjo_-zSigmdsDvY-kfBhmP49bDQzsgHfj5N-y+ZAdw@mail.gmail.com \
    --to=ccross@android.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=anton.vorontsov@linaro.org \
    --cc=arnd@arndb.de \
    --cc=dave@gnu.org \
    --cc=ebiederm@xmission.com \
    --cc=gorcunov@openvz.org \
    --cc=hannes@cmpxchg.org \
    --cc=hch@infradead.org \
    --cc=hughd@google.com \
    --cc=john.stultz@linaro.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=keescook@chromium.org \
    --cc=khlebnikov@openvz.org \
    --cc=kmpark@infradead.org \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.cz \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=penberg@kernel.org \
    --cc=riel@redhat.com \
    --cc=rientjes@google.com \
    --cc=rob@landley.net \
    --cc=rusty@rustcorp.com.au \
    --cc=sasha.levin@oracle.com \
    --cc=shli@fusionio.com \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=walken@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