linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan.kim@gmail.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Hiroaki Wakabayashi <primulaelatior@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-mm@kvack.org, Paul Menage <menage@google.com>,
	Ying Han <yinghan@google.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Pekka Enberg <penberg@cs.helsinki.fi>,
	Lee Schermerhorn <lee.schermerhorn@hp.com>
Subject: Re: [PATCH] mm: make munlock fast when mlock is canceled by sigkill
Date: Mon, 24 Aug 2009 11:23:21 +0900	[thread overview]
Message-ID: <28c262360908231923q354281a6yca3b43019af3c40e@mail.gmail.com> (raw)
In-Reply-To: <20090824105139.c2ab8403.kamezawa.hiroyu@jp.fujitsu.com>

On Mon, Aug 24, 2009 at 10:51 AM, KAMEZAWA
Hiroyuki<kamezawa.hiroyu@jp.fujitsu.com> wrote:
> On Mon, 24 Aug 2009 10:44:41 +0900
> Minchan Kim <minchan.kim@gmail.com> wrote:
>
>> On Sun, Aug 23, 2009 at 1:54 AM, Hiroaki
>> Wakabayashi<primulaelatior@gmail.com> wrote:
>> > From 27b2fde0222c59049026e7d0bdc4a2a68d0720f5 Mon Sep 17 00:00:00 2001
>> > From: Hiroaki Wakabayashi <primulaelatior@gmail.com>
>> > Date: Sat, 22 Aug 2009 19:14:53 +0900
>> > Subject: [PATCH] mm: make munlock fast when mlock is canceled by sigkill
>> >
>> > This patch is for making commit 4779280d1e (mm: make get_user_pages()
>> > interruptible) complete.
>> >
>> > At first, munlock() assumes that all pages in vma are pinned,
>> >
>> > Now, by the commit, mlock() can be interrupted by SIGKILL, etc  So, part of
>> > pages are not pinned.
>> > If SIGKILL, In exit() path, munlock is called for unlocking pinned pages
>> > in vma.
>> >
>> > But, there, get_user_pages(write) is used for munlock(). Then, pages are
>> > allocated via page-fault for exsiting process !!! This is problem at canceling
>> > big mlock.
>> > This patch tries to avoid allocating new pages at munlock().
>> >
>> >   mlock( big area )
>> >        <===== sig kill
>> >   do_exit()
>> >    ->mmput()
>> >       -> do_munlock()
>> >         -> get_user_pages()
>> >               <allocate *never used* memory>
>> >       ->.....freeing allocated memory.
>> >
>> > * Test program
>> > % cat run.sh
>> > #!/bin/sh
>> >
>> > ./mlock_test 2000000000 &
>> > sleep 2
>> > kill -9 $!
>> > wait
>> >
>> > % cat mlock_test.c
>> > #include <stdio.h>
>> > #include <stdlib.h>
>> > #include <string.h>
>> > #include <sys/mman.h>
>> > #include <sys/types.h>
>> > #include <sys/stat.h>
>> > #include <fcntl.h>
>> > #include <errno.h>
>> > #include <time.h>
>> > #include <unistd.h>
>> > #include <sys/time.h>
>> >
>> > int main(int argc, char **argv)
>> > {
>> >        size_t length = 50 * 1024 * 1024;
>> >        void *addr;
>> >        time_t timer;
>> >
>> >        if (argc >= 2)
>> >                length = strtoul(argv[1], NULL, 10);
>> >        printf("PID = %d\n", getpid());
>> >        addr = mmap(NULL, length, PROT_READ | PROT_WRITE,
>> >                                MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>> >        if (addr == MAP_FAILED) {
>> >                fprintf(stderr, "mmap failed: %s, length=%lu\n",
>> >                                strerror(errno), length);
>> >                exit(EXIT_FAILURE);
>> >        }
>> >        printf("try mlock length=%lu\n", length);
>> >        timer = time(NULL);
>> >        if (mlock(addr, length) < 0) {
>> >                fprintf(stderr, "mlock failed: %s, time=%lu[sec]\n",
>> >                                strerror(errno), time(NULL) - timer);
>> >                exit(EXIT_FAILURE);
>> >        }
>> >        printf("mlock succeed, time=%lu[sec]\n\n", time(NULL) - timer);
>> >        printf("try munlock length=%lu\n", length);
>> >        timer = time(NULL);
>> >        if (munlock(addr, length) < 0) {
>> >                fprintf(stderr, "munlock failed: %s, time=%lu[sec]\n",
>> >                                strerror(errno), time(NULL)-timer);
>> >                exit(EXIT_FAILURE);
>> >        }
>> >        printf("munlock succeed, time=%lu[sec]\n\n", time(NULL) - timer);
>> >        if (munmap(addr, length) < 0) {
>> >                fprintf(stderr, "munmap failed: %s\n", strerror(errno));
>> >                exit(EXIT_FAILURE);
>> >        }
>> >        return 0;
>> > }
>> >
>> > * Executed Result
>> > -- Original executed result
>> > % time ./run.sh
>> >
>> > PID = 2678
>> > try mlock length=2000000000
>> > ./run.sh: line 6:  2678 Killed                  ./mlock_test 2000000000
>> > ./run.sh  0.00s user 2.59s system 13% cpu 18.781 total
>> > %
>> >
>> > -- After applied this patch
>> > % time ./run.sh
>> >
>> > PID = 2512
>> > try mlock length=2000000000
>> > ./run.sh: line 6:  2512 Killed                  ./mlock_test 2000000000
>> > ./run.sh  0.00s user 1.15s system 45% cpu 2.507 total
>> > %
>> >
>> > Signed-off-by: Hiroaki Wakabayashi <primulaelatior@gmail.com>
>> > ---
>> >  mm/internal.h |    1 +
>> >  mm/memory.c   |    9 +++++++--
>> >  mm/mlock.c    |   35 +++++++++++++++++++----------------
>> >  3 files changed, 27 insertions(+), 18 deletions(-)
>> >
>> > diff --git a/mm/internal.h b/mm/internal.h
>> > index f290c4d..4ab5b24 100644
>> > --- a/mm/internal.h
>> > +++ b/mm/internal.h
>> > @@ -254,6 +254,7 @@ static inline void
>> > mminit_validate_memmodel_limits(unsigned long *start_pfn,
>> >  #define GUP_FLAGS_FORCE                  0x2
>> >  #define GUP_FLAGS_IGNORE_VMA_PERMISSIONS 0x4
>> >  #define GUP_FLAGS_IGNORE_SIGKILL         0x8
>> > +#define GUP_FLAGS_ALLOW_NULL             0x10
>> >
>>
>> I am worried about adding new flag whenever we need it.
>> But I think this case makes sense to me.
>> In addition, I guess ZERO page can also use this flag.
>>
>> Kame. What do you think about it?
>>
> I do welcome this !
> Then, I don't have to take care of mlock/munlock in ZERO_PAGE patch.
>
> And without this patch, munlock() does copy-on-write just for unpinning memory.
> So, this patch shows some right direction, I think.
>
> One concern is flag name, ALLOW_NULL sounds not very good.
>
>  GUP_FLAGS_NOFAULT ?
>
> I wonder we can remove a hack of FOLL_ANON for core-dump by this flag, too.

That's a good point.
It can remove little cache footprint and
unnecessary calls[flush_xxx_page in GUP].

-- 
Kind regards,
Minchan Kim

--
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:[~2009-08-26  1:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-22 16:54 Hiroaki Wakabayashi
2009-08-24  1:44 ` Minchan Kim
2009-08-24  1:51   ` KAMEZAWA Hiroyuki
2009-08-24  2:23     ` Minchan Kim [this message]
2009-08-24  4:13     ` KOSAKI Motohiro
2009-08-25  4:46       ` Hiroaki Wakabayashi
2009-08-25  5:39         ` Minchan Kim
2009-08-25  9:03         ` Hugh Dickins
2009-08-25  9:37           ` KAMEZAWA Hiroyuki
2009-08-25 11:46             ` Minchan Kim
2009-08-26  2:32           ` KOSAKI Motohiro
2009-08-26 11:11           ` Hiroaki Wakabayashi

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=28c262360908231923q354281a6yca3b43019af3c40e@mail.gmail.com \
    --to=minchan.kim@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=lee.schermerhorn@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=menage@google.com \
    --cc=penberg@cs.helsinki.fi \
    --cc=primulaelatior@gmail.com \
    --cc=yinghan@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