linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
@ 2012-09-19 23:51 Minchan Kim
  2012-09-20 12:36 ` KOSAKI Motohiro
  2012-09-20 15:41 ` Johannes Weiner
  0 siblings, 2 replies; 9+ messages in thread
From: Minchan Kim @ 2012-09-19 23:51 UTC (permalink / raw)
  To: Andrew Morton
  Cc: KOSAKI Motohiro, linux-mm, linux-kernel, Mel Gorman,
	Christoph Lameter, Johannes Weiner, David Rientjes,
	Vasiliy Kulikov

On Wed, Sep 19, 2012 at 02:28:10PM -0400, Johannes Weiner wrote:
> On Wed, Sep 19, 2012 at 01:04:56PM -0400, KOSAKI Motohiro wrote:
> > On Wed, Sep 19, 2012 at 3:45 AM, Minchan Kim <minchan@kernel.org> wrote:
> > > When I looked at zone stat mismatch problem, I found
> > > migrate_to_node doesn't decrease NR_ISOLATED_[ANON|FILE]
> > > if check_range fails.
> 
> This is a bit misleading.  It's not that the stats would be
> inaccurate, it's that the pages would be leaked from the LRU, no?
> 
> > > It can make system hang out.
> 
> Did you spot this by code review only or did you actually run into
> this?  Because...
> 
> > > Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > > Cc: Mel Gorman <mgorman@suse.de>
> > > Cc: Christoph Lameter <cl@linux.com>
> > > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > > ---
> > >  mm/mempolicy.c |   16 ++++++++--------
> > >  1 file changed, 8 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > > index 3d64b36..6bf0860 100644
> > > --- a/mm/mempolicy.c
> > > +++ b/mm/mempolicy.c
> > > @@ -953,16 +953,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
> > >
> > >         vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
> > >                         flags | MPOL_MF_DISCONTIG_OK, &pagelist);
> > > -       if (IS_ERR(vma))
> > > -               return PTR_ERR(vma);
> > > -
> > > -       if (!list_empty(&pagelist)) {
> > > +       if (IS_ERR(vma)) {
> > > +               err = PTR_ERR(vma);
> > > +               goto out;
> > > +       }
> > > +       if (!list_empty(&pagelist))
> > >                 err = migrate_pages(&pagelist, new_node_page, dest,
> > >                                                         false, MIGRATE_SYNC);
> > > -               if (err)
> > > -                       putback_lru_pages(&pagelist);
> > > -       }
> > > -
> > > +out:
> > > +       if (err)
> > > +               putback_lru_pages(&pagelist);
> > 
> > Good catch!
> > This is a regression since following commit. So, I doubt we need
> > all or nothing semantics. Can we revert it instead? (and probably
> > we need more kind comment for preventing an accident)
> 
> I think it makes sense to revert.  Not because of the semantics, but I
> just don't see how check_range() could even fail for this callsite:
> 
> 1. we pass mm->mmap->vm_start in there, so we should not fail due to
>    find_vma()
> 
> 2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
>    and so can not fail
> 
> 3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
>    continue until addr == end, so we never fail with -EIO
> 
> > commit 0def08e3acc2c9c934e4671487029aed52202d42
> > Author: Vasiliy Kulikov <segooon@gmail.com>
> > Date:   Tue Oct 26 14:21:32 2010 -0700
> > 
> >     mm/mempolicy.c: check return code of check_range
> 
> We don't use this code to "check" the range, we use it to collect
> migrate pages.  There is no failure case.
> 

Here it goes.

>From c2c21b551811e034eb0ede6806e0314b201d7e5b Mon Sep 17 00:00:00 2001
From: Minchan Kim <minchan@kernel.org>
Date: Thu, 20 Sep 2012 08:39:52 +0900
Subject: [PATCH] mm: revert 0def08e3, mm/mempolicy.c: check return code of
 check_range

This patch reverts 0def08e3 because check_range can't fail in
migrate_to_node with considering current usecases.

Quote from Johannes
"
I think it makes sense to revert.  Not because of the semantics, but I
just don't see how check_range() could even fail for this callsite:

1. we pass mm->mmap->vm_start in there, so we should not fail due to
   find_vma()

2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
   and so can not fail

3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
   continue until addr == end, so we never fail with -EIO
"

And I add new VM_BUG_ON for checking migrate_to_node's future usecase
which might pass to MPOL_MF_STRICT.

Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Vasiliy Kulikov <segooon@gmail.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 mm/mempolicy.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 3d64b36..9ec87bd 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -946,15 +946,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
 	nodemask_t nmask;
 	LIST_HEAD(pagelist);
 	int err = 0;
-	struct vm_area_struct *vma;
 
 	nodes_clear(nmask);
 	node_set(source, nmask);
 
-	vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
+	/*
+	 * Collect migrate pages and it shoudn't be failed.
+	 */
+	VM_BUG_ON(flags & MPOL_MF_STRICT);
+	check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
 			flags | MPOL_MF_DISCONTIG_OK, &pagelist);
-	if (IS_ERR(vma))
-		return PTR_ERR(vma);
 
 	if (!list_empty(&pagelist)) {
 		err = migrate_pages(&pagelist, new_node_page, dest,
-- 
1.7.9.5

-- 
Kind regards,
Minchan Kim

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
  2012-09-19 23:51 [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch Minchan Kim
@ 2012-09-20 12:36 ` KOSAKI Motohiro
  2012-09-20 15:41 ` Johannes Weiner
  1 sibling, 0 replies; 9+ messages in thread
From: KOSAKI Motohiro @ 2012-09-20 12:36 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Andrew Morton, linux-mm, linux-kernel, Mel Gorman,
	Christoph Lameter, Johannes Weiner, David Rientjes,
	Vasiliy Kulikov

On Wed, Sep 19, 2012 at 7:51 PM, Minchan Kim <minchan@kernel.org> wrote:
> On Wed, Sep 19, 2012 at 02:28:10PM -0400, Johannes Weiner wrote:
>> On Wed, Sep 19, 2012 at 01:04:56PM -0400, KOSAKI Motohiro wrote:
>> > On Wed, Sep 19, 2012 at 3:45 AM, Minchan Kim <minchan@kernel.org> wrote:
>> > > When I looked at zone stat mismatch problem, I found
>> > > migrate_to_node doesn't decrease NR_ISOLATED_[ANON|FILE]
>> > > if check_range fails.
>>
>> This is a bit misleading.  It's not that the stats would be
>> inaccurate, it's that the pages would be leaked from the LRU, no?
>>
>> > > It can make system hang out.
>>
>> Did you spot this by code review only or did you actually run into
>> this?  Because...
>>
>> > > Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
>> > > Cc: Mel Gorman <mgorman@suse.de>
>> > > Cc: Christoph Lameter <cl@linux.com>
>> > > Signed-off-by: Minchan Kim <minchan@kernel.org>
>> > > ---
>> > >  mm/mempolicy.c |   16 ++++++++--------
>> > >  1 file changed, 8 insertions(+), 8 deletions(-)
>> > >
>> > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
>> > > index 3d64b36..6bf0860 100644
>> > > --- a/mm/mempolicy.c
>> > > +++ b/mm/mempolicy.c
>> > > @@ -953,16 +953,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
>> > >
>> > >         vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
>> > >                         flags | MPOL_MF_DISCONTIG_OK, &pagelist);
>> > > -       if (IS_ERR(vma))
>> > > -               return PTR_ERR(vma);
>> > > -
>> > > -       if (!list_empty(&pagelist)) {
>> > > +       if (IS_ERR(vma)) {
>> > > +               err = PTR_ERR(vma);
>> > > +               goto out;
>> > > +       }
>> > > +       if (!list_empty(&pagelist))
>> > >                 err = migrate_pages(&pagelist, new_node_page, dest,
>> > >                                                         false, MIGRATE_SYNC);
>> > > -               if (err)
>> > > -                       putback_lru_pages(&pagelist);
>> > > -       }
>> > > -
>> > > +out:
>> > > +       if (err)
>> > > +               putback_lru_pages(&pagelist);
>> >
>> > Good catch!
>> > This is a regression since following commit. So, I doubt we need
>> > all or nothing semantics. Can we revert it instead? (and probably
>> > we need more kind comment for preventing an accident)
>>
>> I think it makes sense to revert.  Not because of the semantics, but I
>> just don't see how check_range() could even fail for this callsite:
>>
>> 1. we pass mm->mmap->vm_start in there, so we should not fail due to
>>    find_vma()
>>
>> 2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
>>    and so can not fail
>>
>> 3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
>>    continue until addr == end, so we never fail with -EIO
>>
>> > commit 0def08e3acc2c9c934e4671487029aed52202d42
>> > Author: Vasiliy Kulikov <segooon@gmail.com>
>> > Date:   Tue Oct 26 14:21:32 2010 -0700
>> >
>> >     mm/mempolicy.c: check return code of check_range
>>
>> We don't use this code to "check" the range, we use it to collect
>> migrate pages.  There is no failure case.
>>
>
> Here it goes.
>
> From c2c21b551811e034eb0ede6806e0314b201d7e5b Mon Sep 17 00:00:00 2001
> From: Minchan Kim <minchan@kernel.org>
> Date: Thu, 20 Sep 2012 08:39:52 +0900
> Subject: [PATCH] mm: revert 0def08e3, mm/mempolicy.c: check return code of
>  check_range
>
> This patch reverts 0def08e3 because check_range can't fail in
> migrate_to_node with considering current usecases.
>
> Quote from Johannes
> "
> I think it makes sense to revert.  Not because of the semantics, but I
> just don't see how check_range() could even fail for this callsite:
>
> 1. we pass mm->mmap->vm_start in there, so we should not fail due to
>    find_vma()
>
> 2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
>    and so can not fail
>
> 3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
>    continue until addr == end, so we never fail with -EIO
> "
>
> And I add new VM_BUG_ON for checking migrate_to_node's future usecase
> which might pass to MPOL_MF_STRICT.
>
> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Christoph Lameter <cl@linux.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Vasiliy Kulikov <segooon@gmail.com>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>  mm/mempolicy.c |    9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 3d64b36..9ec87bd 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -946,15 +946,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
>         nodemask_t nmask;
>         LIST_HEAD(pagelist);
>         int err = 0;
> -       struct vm_area_struct *vma;
>
>         nodes_clear(nmask);
>         node_set(source, nmask);
>
> -       vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
> +       /*
> +        * Collect migrate pages and it shoudn't be failed.
> +        */
> +       VM_BUG_ON(flags & MPOL_MF_STRICT);
> +       check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
>                         flags | MPOL_MF_DISCONTIG_OK, &pagelist);
> -       if (IS_ERR(vma))
> -               return PTR_ERR(vma);
>
>         if (!list_empty(&pagelist)) {
>                 err = migrate_pages(&pagelist, new_node_page, dest,

Looks good. thank you.

Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
  2012-09-19 23:51 [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch Minchan Kim
  2012-09-20 12:36 ` KOSAKI Motohiro
@ 2012-09-20 15:41 ` Johannes Weiner
  1 sibling, 0 replies; 9+ messages in thread
From: Johannes Weiner @ 2012-09-20 15:41 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Andrew Morton, KOSAKI Motohiro, linux-mm, linux-kernel,
	Mel Gorman, Christoph Lameter, David Rientjes, Vasiliy Kulikov

On Thu, Sep 20, 2012 at 08:51:56AM +0900, Minchan Kim wrote:
> From: Minchan Kim <minchan@kernel.org>
> Date: Thu, 20 Sep 2012 08:39:52 +0900
> Subject: [PATCH] mm: revert 0def08e3, mm/mempolicy.c: check return code of
>  check_range
> 
> This patch reverts 0def08e3 because check_range can't fail in
> migrate_to_node with considering current usecases.
> 
> Quote from Johannes
> "
> I think it makes sense to revert.  Not because of the semantics, but I
> just don't see how check_range() could even fail for this callsite:
> 
> 1. we pass mm->mmap->vm_start in there, so we should not fail due to
>    find_vma()
> 
> 2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
>    and so can not fail
> 
> 3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
>    continue until addr == end, so we never fail with -EIO
> "
> 
> And I add new VM_BUG_ON for checking migrate_to_node's future usecase
> which might pass to MPOL_MF_STRICT.
> 
> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Christoph Lameter <cl@linux.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Vasiliy Kulikov <segooon@gmail.com>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>  mm/mempolicy.c |    9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 3d64b36..9ec87bd 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -946,15 +946,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
>  	nodemask_t nmask;
>  	LIST_HEAD(pagelist);
>  	int err = 0;
> -	struct vm_area_struct *vma;
>  
>  	nodes_clear(nmask);
>  	node_set(source, nmask);
>  
> -	vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
> +	/*
> +	 * Collect migrate pages and it shoudn't be failed.
> +	 */
> +	VM_BUG_ON(flags & MPOL_MF_STRICT);

Adding a check and a comment is a good idea, but I'm not a big fan of
checking for MPOL_MF_STRICT in particular because it's one of the
invalid inputs, and so you need to extend this check when somebody
extends the spectrum of invalid inputs.  I would much prefer checking
directly for !(flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) instead, which
would also make the possible inputs apparent without having to chase
up the call chain to find out what is usually passed in.

And how about

/*
 * This does not "check" the range but isolates all pages that
 * need migration.  Between passing in the full user address
 * space range and MPOL_MF_DISCONTIG_OK, this call can not fail.
 */

?

> +	check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
>  			flags | MPOL_MF_DISCONTIG_OK, &pagelist);
> -	if (IS_ERR(vma))
> -		return PTR_ERR(vma);
>  
>  	if (!list_empty(&pagelist)) {
>  		err = migrate_pages(&pagelist, new_node_page, dest,
> -- 
> 1.7.9.5
> 
> -- 
> Kind regards,
> Minchan Kim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
  2012-09-20 23:24 Minchan Kim
@ 2012-09-21  2:13 ` Johannes Weiner
  0 siblings, 0 replies; 9+ messages in thread
From: Johannes Weiner @ 2012-09-21  2:13 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Andrew Morton, KOSAKI Motohiro, linux-mm, linux-kernel,
	Mel Gorman, Christoph Lameter, David Rientjes, Vasiliy Kulikov

On Fri, Sep 21, 2012 at 08:24:08AM +0900, Minchan Kim wrote:
> On Thu, Sep 20, 2012 at 11:41:11AM -0400, Johannes Weiner wrote:
> > On Thu, Sep 20, 2012 at 08:51:56AM +0900, Minchan Kim wrote:
> > > From: Minchan Kim <minchan@kernel.org>
> > > Date: Thu, 20 Sep 2012 08:39:52 +0900
> > > Subject: [PATCH] mm: revert 0def08e3, mm/mempolicy.c: check return code of
> > >  check_range

[...]

> From: Minchan Kim <minchan@kernel.org>
> Date: Fri, 21 Sep 2012 08:17:37 +0900
> Subject: [PATCH] mm: enhance comment and bug check
> 
> This patch updates comment and bug check.
> It can be fold into [1].
> 
> [1] mm-revert-0def08e3-mm-mempolicyc-check-return-code-of-check_range.patch
> 
> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Minchan Kim <minchan@kernel.org>

Thanks!  To the patch and this update:

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
@ 2012-09-20 23:24 Minchan Kim
  2012-09-21  2:13 ` Johannes Weiner
  0 siblings, 1 reply; 9+ messages in thread
From: Minchan Kim @ 2012-09-20 23:24 UTC (permalink / raw)
  To: Johannes Weiner, Andrew Morton
  Cc: KOSAKI Motohiro, linux-mm, linux-kernel, Mel Gorman,
	Christoph Lameter, David Rientjes, Vasiliy Kulikov

On Thu, Sep 20, 2012 at 11:41:11AM -0400, Johannes Weiner wrote:
> On Thu, Sep 20, 2012 at 08:51:56AM +0900, Minchan Kim wrote:
> > From: Minchan Kim <minchan@kernel.org>
> > Date: Thu, 20 Sep 2012 08:39:52 +0900
> > Subject: [PATCH] mm: revert 0def08e3, mm/mempolicy.c: check return code of
> >  check_range
> > 
> > This patch reverts 0def08e3 because check_range can't fail in
> > migrate_to_node with considering current usecases.
> > 
> > Quote from Johannes
> > "
> > I think it makes sense to revert.  Not because of the semantics, but I
> > just don't see how check_range() could even fail for this callsite:
> > 
> > 1. we pass mm->mmap->vm_start in there, so we should not fail due to
> >    find_vma()
> > 
> > 2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
> >    and so can not fail
> > 
> > 3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
> >    continue until addr == end, so we never fail with -EIO
> > "
> > 
> > And I add new VM_BUG_ON for checking migrate_to_node's future usecase
> > which might pass to MPOL_MF_STRICT.
> > 
> > Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > Cc: Mel Gorman <mgorman@suse.de>
> > Cc: Christoph Lameter <cl@linux.com>
> > Cc: David Rientjes <rientjes@google.com>
> > Cc: Vasiliy Kulikov <segooon@gmail.com>
> > Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > ---
> >  mm/mempolicy.c |    9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > index 3d64b36..9ec87bd 100644
> > --- a/mm/mempolicy.c
> > +++ b/mm/mempolicy.c
> > @@ -946,15 +946,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
> >  	nodemask_t nmask;
> >  	LIST_HEAD(pagelist);
> >  	int err = 0;
> > -	struct vm_area_struct *vma;
> >  
> >  	nodes_clear(nmask);
> >  	node_set(source, nmask);
> >  
> > -	vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
> > +	/*
> > +	 * Collect migrate pages and it shoudn't be failed.
> > +	 */
> > +	VM_BUG_ON(flags & MPOL_MF_STRICT);
> 
> Adding a check and a comment is a good idea, but I'm not a big fan of
> checking for MPOL_MF_STRICT in particular because it's one of the
> invalid inputs, and so you need to extend this check when somebody
> extends the spectrum of invalid inputs.  I would much prefer checking
> directly for !(flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) instead, which
> would also make the possible inputs apparent without having to chase
> up the call chain to find out what is usually passed in.
> 
> And how about
> 
> /*
>  * This does not "check" the range but isolates all pages that
>  * need migration.  Between passing in the full user address
>  * space range and MPOL_MF_DISCONTIG_OK, this call can not fail.
>  */
> 
> ?

Good idea. Thanks Hannes,

>From 13ae84083ac1f057eafbeae49efba862aa7a470e Mon Sep 17 00:00:00 2001
From: Minchan Kim <minchan@kernel.org>
Date: Fri, 21 Sep 2012 08:17:37 +0900
Subject: [PATCH] mm: enhance comment and bug check

This patch updates comment and bug check.
It can be fold into [1].

[1] mm-revert-0def08e3-mm-mempolicyc-check-return-code-of-check_range.patch

Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 mm/mempolicy.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 9ec87bd..0b78fb9 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -951,9 +951,11 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
 	node_set(source, nmask);
 
 	/*
-	 * Collect migrate pages and it shoudn't be failed.
+	 * This does not "check" the range but isolates all pages that
+	 * need migration.  Between passing in the full user address
+	 * space range and MPOL_MF_DISCONTIG_OK, this call can not fail.
 	 */
-	VM_BUG_ON(flags & MPOL_MF_STRICT);
+	VM_BUG_ON(!(flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)));
 	check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
 			flags | MPOL_MF_DISCONTIG_OK, &pagelist);
 
-- 
1.7.9.5

-- 
Kind regards,
Minchan Kim

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
  2012-09-19 18:28   ` Johannes Weiner
@ 2012-09-19 20:38     ` Minchan Kim
  0 siblings, 0 replies; 9+ messages in thread
From: Minchan Kim @ 2012-09-19 20:38 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: KOSAKI Motohiro, Andrew Morton, linux-mm, linux-kernel,
	Mel Gorman, Christoph Lameter

Hi Hannes,

On Wed, Sep 19, 2012 at 02:28:10PM -0400, Johannes Weiner wrote:
> On Wed, Sep 19, 2012 at 01:04:56PM -0400, KOSAKI Motohiro wrote:
> > On Wed, Sep 19, 2012 at 3:45 AM, Minchan Kim <minchan@kernel.org> wrote:
> > > When I looked at zone stat mismatch problem, I found
> > > migrate_to_node doesn't decrease NR_ISOLATED_[ANON|FILE]
> > > if check_range fails.
> 
> This is a bit misleading.  It's not that the stats would be
> inaccurate, it's that the pages would be leaked from the LRU, no?
> 
> > > It can make system hang out.
> 
> Did you spot this by code review only or did you actually run into
> this?  Because...

Just by code review during the bug of memory-hotplug.

> 
> > > Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > > Cc: Mel Gorman <mgorman@suse.de>
> > > Cc: Christoph Lameter <cl@linux.com>
> > > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > > ---
> > >  mm/mempolicy.c |   16 ++++++++--------
> > >  1 file changed, 8 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > > index 3d64b36..6bf0860 100644
> > > --- a/mm/mempolicy.c
> > > +++ b/mm/mempolicy.c
> > > @@ -953,16 +953,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
> > >
> > >         vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
> > >                         flags | MPOL_MF_DISCONTIG_OK, &pagelist);
> > > -       if (IS_ERR(vma))
> > > -               return PTR_ERR(vma);
> > > -
> > > -       if (!list_empty(&pagelist)) {
> > > +       if (IS_ERR(vma)) {
> > > +               err = PTR_ERR(vma);
> > > +               goto out;
> > > +       }
> > > +       if (!list_empty(&pagelist))
> > >                 err = migrate_pages(&pagelist, new_node_page, dest,
> > >                                                         false, MIGRATE_SYNC);
> > > -               if (err)
> > > -                       putback_lru_pages(&pagelist);
> > > -       }
> > > -
> > > +out:
> > > +       if (err)
> > > +               putback_lru_pages(&pagelist);
> > 
> > Good catch!
> > This is a regression since following commit. So, I doubt we need
> > all or nothing semantics. Can we revert it instead? (and probably
> > we need more kind comment for preventing an accident)
> 
> I think it makes sense to revert.  Not because of the semantics, but I
> just don't see how check_range() could even fail for this callsite:
> 
> 1. we pass mm->mmap->vm_start in there, so we should not fail due to
>    find_vma()
> 
> 2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
>    and so can not fail
> 
> 3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
>    continue until addr == end, so we never fail with -EIO
> 
> > commit 0def08e3acc2c9c934e4671487029aed52202d42
> > Author: Vasiliy Kulikov <segooon@gmail.com>
> > Date:   Tue Oct 26 14:21:32 2010 -0700
> > 
> >     mm/mempolicy.c: check return code of check_range
> 
> We don't use this code to "check" the range, we use it to collect
> migrate pages.  There is no failure case.

Right. I will send revert patch when I go to office.
Thanks for the pointing out.

-- 
Kind Regards,
Minchan Kim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
  2012-09-19 17:04 ` KOSAKI Motohiro
@ 2012-09-19 18:28   ` Johannes Weiner
  2012-09-19 20:38     ` Minchan Kim
  0 siblings, 1 reply; 9+ messages in thread
From: Johannes Weiner @ 2012-09-19 18:28 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Minchan Kim, Andrew Morton, linux-mm, linux-kernel, Mel Gorman,
	Christoph Lameter

On Wed, Sep 19, 2012 at 01:04:56PM -0400, KOSAKI Motohiro wrote:
> On Wed, Sep 19, 2012 at 3:45 AM, Minchan Kim <minchan@kernel.org> wrote:
> > When I looked at zone stat mismatch problem, I found
> > migrate_to_node doesn't decrease NR_ISOLATED_[ANON|FILE]
> > if check_range fails.

This is a bit misleading.  It's not that the stats would be
inaccurate, it's that the pages would be leaked from the LRU, no?

> > It can make system hang out.

Did you spot this by code review only or did you actually run into
this?  Because...

> > Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > Cc: Mel Gorman <mgorman@suse.de>
> > Cc: Christoph Lameter <cl@linux.com>
> > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > ---
> >  mm/mempolicy.c |   16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> > index 3d64b36..6bf0860 100644
> > --- a/mm/mempolicy.c
> > +++ b/mm/mempolicy.c
> > @@ -953,16 +953,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
> >
> >         vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
> >                         flags | MPOL_MF_DISCONTIG_OK, &pagelist);
> > -       if (IS_ERR(vma))
> > -               return PTR_ERR(vma);
> > -
> > -       if (!list_empty(&pagelist)) {
> > +       if (IS_ERR(vma)) {
> > +               err = PTR_ERR(vma);
> > +               goto out;
> > +       }
> > +       if (!list_empty(&pagelist))
> >                 err = migrate_pages(&pagelist, new_node_page, dest,
> >                                                         false, MIGRATE_SYNC);
> > -               if (err)
> > -                       putback_lru_pages(&pagelist);
> > -       }
> > -
> > +out:
> > +       if (err)
> > +               putback_lru_pages(&pagelist);
> 
> Good catch!
> This is a regression since following commit. So, I doubt we need
> all or nothing semantics. Can we revert it instead? (and probably
> we need more kind comment for preventing an accident)

I think it makes sense to revert.  Not because of the semantics, but I
just don't see how check_range() could even fail for this callsite:

1. we pass mm->mmap->vm_start in there, so we should not fail due to
   find_vma()

2. we pass MPOL_MF_DISCONTIG_OK, so the discontig checks do not apply
   and so can not fail

3. we pass MPOL_MF_MOVE | MPOL_MF_MOVE_ALL, the page table loops will
   continue until addr == end, so we never fail with -EIO

> commit 0def08e3acc2c9c934e4671487029aed52202d42
> Author: Vasiliy Kulikov <segooon@gmail.com>
> Date:   Tue Oct 26 14:21:32 2010 -0700
> 
>     mm/mempolicy.c: check return code of check_range

We don't use this code to "check" the range, we use it to collect
migrate pages.  There is no failure case.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
  2012-09-19  7:45 Minchan Kim
@ 2012-09-19 17:04 ` KOSAKI Motohiro
  2012-09-19 18:28   ` Johannes Weiner
  0 siblings, 1 reply; 9+ messages in thread
From: KOSAKI Motohiro @ 2012-09-19 17:04 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Andrew Morton, linux-mm, linux-kernel, Mel Gorman, Christoph Lameter

On Wed, Sep 19, 2012 at 3:45 AM, Minchan Kim <minchan@kernel.org> wrote:
> When I looked at zone stat mismatch problem, I found
> migrate_to_node doesn't decrease NR_ISOLATED_[ANON|FILE]
> if check_range fails.
>
> It can make system hang out.
>
> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Christoph Lameter <cl@linux.com>
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>  mm/mempolicy.c |   16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 3d64b36..6bf0860 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -953,16 +953,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
>
>         vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
>                         flags | MPOL_MF_DISCONTIG_OK, &pagelist);
> -       if (IS_ERR(vma))
> -               return PTR_ERR(vma);
> -
> -       if (!list_empty(&pagelist)) {
> +       if (IS_ERR(vma)) {
> +               err = PTR_ERR(vma);
> +               goto out;
> +       }
> +       if (!list_empty(&pagelist))
>                 err = migrate_pages(&pagelist, new_node_page, dest,
>                                                         false, MIGRATE_SYNC);
> -               if (err)
> -                       putback_lru_pages(&pagelist);
> -       }
> -
> +out:
> +       if (err)
> +               putback_lru_pages(&pagelist);

Good catch!
This is a regression since following commit. So, I doubt we need
all or nothing semantics. Can we revert it instead? (and probably
we need more kind comment for preventing an accident)


commit 0def08e3acc2c9c934e4671487029aed52202d42
Author: Vasiliy Kulikov <segooon@gmail.com>
Date:   Tue Oct 26 14:21:32 2010 -0700

    mm/mempolicy.c: check return code of check_range

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch
@ 2012-09-19  7:45 Minchan Kim
  2012-09-19 17:04 ` KOSAKI Motohiro
  0 siblings, 1 reply; 9+ messages in thread
From: Minchan Kim @ 2012-09-19  7:45 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, linux-kernel, Minchan Kim, KOSAKI Motohiro, Mel Gorman,
	Christoph Lameter

When I looked at zone stat mismatch problem, I found
migrate_to_node doesn't decrease NR_ISOLATED_[ANON|FILE]
if check_range fails.

It can make system hang out.

Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Christoph Lameter <cl@linux.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 mm/mempolicy.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 3d64b36..6bf0860 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -953,16 +953,16 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
 
 	vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
 			flags | MPOL_MF_DISCONTIG_OK, &pagelist);
-	if (IS_ERR(vma))
-		return PTR_ERR(vma);
-
-	if (!list_empty(&pagelist)) {
+	if (IS_ERR(vma)) {
+		err = PTR_ERR(vma);
+		goto out;
+	}
+	if (!list_empty(&pagelist))
 		err = migrate_pages(&pagelist, new_node_page, dest,
 							false, MIGRATE_SYNC);
-		if (err)
-			putback_lru_pages(&pagelist);
-	}
-
+out:
+	if (err)
+		putback_lru_pages(&pagelist);
 	return err;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-09-21  2:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-19 23:51 [PATCH] mm: fix NR_ISOLATED_[ANON|FILE] mismatch Minchan Kim
2012-09-20 12:36 ` KOSAKI Motohiro
2012-09-20 15:41 ` Johannes Weiner
  -- strict thread matches above, loose matches on Subject: below --
2012-09-20 23:24 Minchan Kim
2012-09-21  2:13 ` Johannes Weiner
2012-09-19  7:45 Minchan Kim
2012-09-19 17:04 ` KOSAKI Motohiro
2012-09-19 18:28   ` Johannes Weiner
2012-09-19 20:38     ` Minchan Kim

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).