linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan.kim@gmail.com>
To: Wu Fengguang <fengguang.wu@intel.com>,
	Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Rik van Riel <riel@redhat.com>, Jeff Dike <jdike@addtoit.com>,
	Avi Kivity <avi@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	"Yu, Wilfred" <wilfred.yu@intel.com>,
	"Kleen, Andi" <andi.kleen@intel.com>,
	Hugh Dickins <hugh.dickins@tiscali.co.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <cl@linux-foundation.org>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Mel Gorman <mel@csn.ul.ie>, LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>
Subject: Re: [RFC] respect the referenced bit of KVM guest pages?
Date: Tue, 18 Aug 2009 20:00:48 +0900	[thread overview]
Message-ID: <28c262360908180400q361ea322o8959fd5ea5ae3217@mail.gmail.com> (raw)
In-Reply-To: <20090818100031.GC16298@localhost>

On Tue, Aug 18, 2009 at 7:00 PM, Wu Fengguang<fengguang.wu@intel.com> wrote:
> On Tue, Aug 18, 2009 at 05:52:47PM +0800, Minchan Kim wrote:
>> On Tue, 18 Aug 2009 17:31:19 +0800
>> Wu Fengguang <fengguang.wu@intel.com> wrote:
>>
>> > On Tue, Aug 18, 2009 at 12:17:34PM +0800, Minchan Kim wrote:
>> > > On Tue, 18 Aug 2009 10:34:38 +0800
>> > > Wu Fengguang <fengguang.wu@intel.com> wrote:
>> > >
>> > > > Minchan,
>> > > >
>> > > > On Mon, Aug 17, 2009 at 10:33:54PM +0800, Minchan Kim wrote:
>> > > > > On Sun, Aug 16, 2009 at 8:29 PM, Wu Fengguang<fengguang.wu@intel.com> wrote:
>> > > > > > On Sun, Aug 16, 2009 at 01:15:02PM +0800, Wu Fengguang wrote:
>> > > > > >> On Sun, Aug 16, 2009 at 11:53:00AM +0800, Rik van Riel wrote:
>> > > > > >> > Wu Fengguang wrote:
>> > > > > >> > > On Fri, Aug 07, 2009 at 05:09:55AM +0800, Jeff Dike wrote:
>> > > > > >> > >> Side question -
>> > > > > >> > >>  Is there a good reason for this to be in shrink_active_list()
>> > > > > >> > >> as opposed to __isolate_lru_page?
>> > > > > >> > >>
>> > > > > >> > >>          if (unlikely(!page_evictable(page, NULL))) {
>> > > > > >> > >>                  putback_lru_page(page);
>> > > > > >> > >>                  continue;
>> > > > > >> > >>          }
>> > > > > >> > >>
>> > > > > >> > >> Maybe we want to minimize the amount of code under the lru lock or
>> > > > > >> > >> avoid duplicate logic in the isolate_page functions.
>> > > > > >> > >
>> > > > > >> > > I guess the quick test means to avoid the expensive page_referenced()
>> > > > > >> > > call that follows it. But that should be mostly one shot cost - the
>> > > > > >> > > unevictable pages are unlikely to cycle in active/inactive list again
>> > > > > >> > > and again.
>> > > > > >> >
>> > > > > >> > Please read what putback_lru_page does.
>> > > > > >> >
>> > > > > >> > It moves the page onto the unevictable list, so that
>> > > > > >> > it will not end up in this scan again.
>> > > > > >>
>> > > > > >> Yes it does. I said 'mostly' because there is a small hole that an
>> > > > > >> unevictable page may be scanned but still not moved to unevictable
>> > > > > >> list: when a page is mapped in two places, the first pte has the
>> > > > > >> referenced bit set, the _second_ VMA has VM_LOCKED bit set, then
>> > > > > >> page_referenced() will return 1 and shrink_page_list() will move it
>> > > > > >> into active list instead of unevictable list. Shall we fix this rare
>> > > > > >> case?
>> > > > >
>> > > > > I think it's not a big deal.
>> > > >
>> > > > Maybe, otherwise I should bring up this issue long time before :)
>> > > >
>> > > > > As you mentioned, it's rare case so there would be few pages in active
>> > > > > list instead of unevictable list.
>> > > >
>> > > > Yes.
>> > > >
>> > > > > When next time to scan comes, we can try to move the pages into
>> > > > > unevictable list, again.
>> > > >
>> > > > Will PG_mlocked be set by then? Otherwise the situation is not likely
>> > > > to change and the VM_LOCKED pages may circulate in active/inactive
>> > > > list for countless times.
>> > >
>> > > PG_mlocked is not important in that case.
>> > > Important thing is VM_LOCKED vma.
>> > > I think below annotaion can help you to understand my point. :)
>> >
>> > Hmm, it looks like pages under VM_LOCKED vma is guaranteed to have
>> > PG_mlocked set, and so will be caught by page_evictable(). Is it?
>>
>> No. I am sorry for making my point not clear.
>> I meant following as.
>> When the next time to scan,
>>
>> shrink_page_list
>  ->
>                referenced = page_referenced(page, 1,
>                                                sc->mem_cgroup, &vm_flags);
>                /* In active use or really unfreeable?  Activate it. */
>                if (sc->order <= PAGE_ALLOC_COSTLY_ORDER &&
>                                        referenced && page_mapping_inuse(page))
>                        goto activate_locked;
>
>> -> try_to_unmap
>     ~~~~~~~~~~~~ this line won't be reached if page is found to be
>     referenced in the above lines?

Indeed! In fact, I was worry about that.
It looks after live lock problem.
But I think  it's very small race window so  there isn't any report until now.
Let's Cced Lee.

If we have to fix it, how about this ?
This version  has small overhead than yours since
there is less shrink_page_list call than page_referenced.

diff --git a/mm/rmap.c b/mm/rmap.c
index ed63894..283266c 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -358,6 +358,7 @@ static int page_referenced_one(struct page *page,
         */
        if (vma->vm_flags & VM_LOCKED) {
                *mapcount = 1;  /* break early from loop */
+               *vm_flags |= VM_LOCKED;
                goto out_unmap;
        }

diff --git a/mm/vmscan.c b/mm/vmscan.c
index d224b28..d156e1d 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -632,7 +632,8 @@ static unsigned long shrink_page_list(struct
list_head *page_list,
                                                sc->mem_cgroup, &vm_flags);
                /* In active use or really unfreeable?  Activate it. */
                if (sc->order <= PAGE_ALLOC_COSTLY_ORDER &&
-                                       referenced && page_mapping_inuse(page))
+                                       referenced && page_mapping_inuse(page)
+                                       && !(vm_flags & VM_LOCKED))
                        goto activate_locked;




>
> Thanks,
> Fengguang
>
>>       -> try_to_unmap_xxx
>>               -> if (vma->vm_flags & VM_LOCKED)
>>               -> try_to_mlock_page
>>                       -> TestSetPageMlocked
>>                       -> putback_lru_page
>>
>> So at last, the page will be located in unevictable list.
>>
>> > Then I was worrying about a null problem. Sorry for the confusion!
>> >
>> > Thanks,
>> > Fengguang
>> >
>> > > ----
>> > >
>> > > /*
>> > >  * called from munlock()/munmap() path with page supposedly on the LRU.
>> > >  *
>> > >  * Note:  unlike mlock_vma_page(), we can't just clear the PageMlocked
>> > >  * [in try_to_munlock()] and then attempt to isolate the page.  We must
>> > >  * isolate the page to keep others from messing with its unevictable
>> > >  * and mlocked state while trying to munlock.  However, we pre-clear the
>> > >  * mlocked state anyway as we might lose the isolation race and we might
>> > >  * not get another chance to clear PageMlocked.  If we successfully
>> > >  * isolate the page and try_to_munlock() detects other VM_LOCKED vmas
>> > >  * mapping the page, it will restore the PageMlocked state, unless the page
>> > >  * is mapped in a non-linear vma.  So, we go ahead and SetPageMlocked(),
>> > >  * perhaps redundantly.
>> > >  * If we lose the isolation race, and the page is mapped by other VM_LOCKED
>> > >  * vmas, we'll detect this in vmscan--via try_to_munlock() or try_to_unmap()
>> > >  * either of which will restore the PageMlocked state by calling
>> > >  * mlock_vma_page() above, if it can grab the vma's mmap sem.
>> > >  */
>> > > static void munlock_vma_page(struct page *page)
>> > > {
>> > > ...
>> > >
>> > > --
>> > > Kind regards,
>> > > Minchan Kim
>>
>>
>> --
>> Kind regards,
>> Minchan Kim
>



-- 
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-18 11:00 UTC|newest]

Thread overview: 122+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05  2:40 [RFC] respect the referenced bit of KVM guest pages? Wu Fengguang
2009-08-05  4:15 ` KOSAKI Motohiro
2009-08-05  4:41   ` Wu Fengguang
2009-08-05  7:58 ` Avi Kivity
2009-08-05  8:17   ` Avi Kivity
2009-08-05 14:33     ` Rik van Riel
2009-08-05 15:37       ` Avi Kivity
2009-08-05 14:15   ` Rik van Riel
2009-08-05 15:12     ` Avi Kivity
2009-08-05 15:15       ` Rik van Riel
2009-08-05 15:25         ` Avi Kivity
2009-08-05 16:35           ` Andrea Arcangeli
2009-08-05 16:31     ` Andrea Arcangeli
2009-08-05 17:25       ` Rik van Riel
2009-08-05 15:45   ` Dike, Jeffrey G
2009-08-05 16:05   ` Andrea Arcangeli
2009-08-05 16:12     ` Dike, Jeffrey G
2009-08-05 16:19       ` Andrea Arcangeli
2009-08-05 15:58 ` Andrea Arcangeli
2009-08-05 17:20   ` Rik van Riel
2009-08-05 17:42   ` Rik van Riel
2009-08-06 10:15     ` Andrea Arcangeli
2009-08-06 10:08   ` Andrea Arcangeli
2009-08-06 10:18     ` Avi Kivity
2009-08-06 10:20       ` Andrea Arcangeli
2009-08-06 10:59         ` Wu Fengguang
2009-08-06 11:44           ` Avi Kivity
2009-08-06 13:06             ` Wu Fengguang
2009-08-06 13:16               ` Rik van Riel
2009-08-16  3:28                 ` Wu Fengguang
2009-08-16  3:56                   ` Rik van Riel
2009-08-16  4:43                     ` Balbir Singh
2009-08-16  4:55                     ` Wu Fengguang
2009-08-16  5:59                       ` Balbir Singh
2009-08-17 19:47                       ` Dike, Jeffrey G
2009-08-21 18:24                         ` Balbir Singh
2009-08-31 19:43                           ` Dike, Jeffrey G
2009-08-31 19:52                             ` Rik van Riel
2009-08-31 20:06                               ` Dike, Jeffrey G
2009-08-31 20:09                                 ` Rik van Riel
2009-08-31 20:11                                   ` Dike, Jeffrey G
2009-08-31 20:42                                     ` Balbir Singh
2009-08-06 13:46               ` Avi Kivity
2009-08-06 21:09               ` Jeff Dike
2009-08-16  3:18                 ` Wu Fengguang
2009-08-16  3:53                   ` Rik van Riel
2009-08-16  5:15                     ` Wu Fengguang
2009-08-16 11:29                       ` Wu Fengguang
2009-08-17 14:33                         ` Minchan Kim
2009-08-18  2:34                           ` Wu Fengguang
2009-08-18  4:17                             ` Minchan Kim
2009-08-18  9:31                               ` Wu Fengguang
2009-08-18  9:52                                 ` Minchan Kim
2009-08-18 10:00                                   ` Wu Fengguang
2009-08-18 11:00                                     ` Minchan Kim [this message]
2009-08-18 11:11                                       ` Wu Fengguang
2009-08-18 14:03                                         ` Minchan Kim
2009-08-18 16:27                                         ` KOSAKI Motohiro
2009-08-18 15:57                         ` KOSAKI Motohiro
2009-08-19 12:01                           ` Wu Fengguang
2009-08-19 12:05                             ` KOSAKI Motohiro
2009-08-19 12:10                               ` Wu Fengguang
2009-08-19 12:25                                 ` Minchan Kim
2009-08-19 13:19                                   ` KOSAKI Motohiro
2009-08-19 13:28                                     ` Minchan Kim
2009-08-21 11:17                                       ` KOSAKI Motohiro
2009-08-19 13:24                                   ` Wu Fengguang
2009-08-19 13:38                                     ` Minchan Kim
2009-08-19 14:00                                       ` Wu Fengguang
2009-08-06 13:13             ` Rik van Riel
2009-08-06 13:49               ` Avi Kivity
2009-08-07  3:11               ` KOSAKI Motohiro
2009-08-07  7:54                 ` Balbir Singh
2009-08-07  8:24                   ` KAMEZAWA Hiroyuki
2009-08-06 13:11           ` Rik van Riel
2009-08-06 13:08     ` Rik van Riel
2009-08-07  3:17       ` KOSAKI Motohiro
2009-08-12  7:48         ` Wu Fengguang
2009-08-12 14:31           ` Rik van Riel
2009-08-13  1:03             ` Wu Fengguang
2009-08-13 15:46               ` Rik van Riel
2009-08-13 16:12                 ` Avi Kivity
2009-08-13 16:26                   ` Rik van Riel
2009-08-13 19:12                     ` Avi Kivity
2009-08-13 21:16                       ` Johannes Weiner
2009-08-14  7:16                         ` Avi Kivity
2009-08-14  9:10                           ` Johannes Weiner
2009-08-14  9:51                             ` Wu Fengguang
2009-08-14 13:19                               ` Rik van Riel
2009-08-15  5:45                                 ` Wu Fengguang
2009-08-16  5:09                                   ` Balbir Singh
2009-08-16  5:41                                     ` Wu Fengguang
2009-08-16  5:50                                     ` Wu Fengguang
2009-08-18 15:57                                     ` KOSAKI Motohiro
2009-08-17 18:04                                   ` Dike, Jeffrey G
2009-08-18  2:26                                     ` Wu Fengguang
2009-09-02 19:30                                       ` Dike, Jeffrey G
2009-09-03  2:04                                         ` Wu Fengguang
2009-09-04 20:06                                           ` Dike, Jeffrey G
2009-09-04 20:57                                             ` Rik van Riel
2009-08-18 15:57                                   ` KOSAKI Motohiro
2009-08-19 12:08                                     ` Wu Fengguang
2009-08-19 13:40                                     ` [RFC] memcg: move definitions to .h and inline some functions Wu Fengguang
2009-08-19 14:18                                       ` KAMEZAWA Hiroyuki
2009-08-19 14:27                                         ` Balbir Singh
2009-08-20  1:34                                           ` Wu Fengguang
2009-08-14 21:42                               ` [RFC] respect the referenced bit of KVM guest pages? Dike, Jeffrey G
2009-08-14 22:37                                 ` Rik van Riel
2009-08-15  5:32                                   ` Wu Fengguang
2009-09-13 16:23                                 ` KOSAKI Motohiro
2009-08-05 17:53 ` Rik van Riel
2009-08-05 19:00   ` Dike, Jeffrey G
2009-08-05 19:07     ` Rik van Riel
2009-08-05 19:18       ` Dike, Jeffrey G
2009-08-06  9:22         ` Avi Kivity
2009-08-06  9:25           ` Wu Fengguang
2009-08-06  9:35             ` Avi Kivity
2009-08-06  9:35               ` Wu Fengguang
2009-08-06  9:59                 ` Avi Kivity
2009-08-06  9:59                   ` Wu Fengguang
2009-08-06 10:14                     ` Avi Kivity
2009-08-07  1:25                       ` KAMEZAWA Hiroyuki

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=28c262360908180400q361ea322o8959fd5ea5ae3217@mail.gmail.com \
    --to=minchan.kim@gmail.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi.kleen@intel.com \
    --cc=avi@redhat.com \
    --cc=cl@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=jdike@addtoit.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=lee.schermerhorn@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=riel@redhat.com \
    --cc=wilfred.yu@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;
as well as URLs for NNTP newsgroup(s).