stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm, slub: ensure irqs are enabled for kmemcheck
       [not found]     ` <alpine.LFD.2.02.1207091209220.3050@tux.localdomain>
@ 2012-07-09 10:36       ` David Rientjes
  2012-07-09 13:46         ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: David Rientjes @ 2012-07-09 10:36 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: JoonSoo Kim, Fengguang Wu, Vegard Nossum, Christoph Lameter, Rus,
	Ben Hutchings, Steven Rostedt, stable, linux-mm, linux-kernel

kmemcheck_alloc_shadow() requires irqs to be enabled, so wait to disable
them until after its called for __GFP_WAIT allocations.

This fixes a warning for such allocations:

	WARNING: at kernel/lockdep.c:2739 lockdep_trace_alloc+0x14e/0x1c0()

Cc: stable@vger.kernel.org [3.1+]
Acked-by: Fengguang Wu <fengguang.wu@intel.com>
Tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/slub.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1314,13 +1314,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 			stat(s, ORDER_FALLBACK);
 	}
 
-	if (flags & __GFP_WAIT)
-		local_irq_disable();
-
-	if (!page)
-		return NULL;
-
-	if (kmemcheck_enabled
+	if (page && kmemcheck_enabled
 		&& !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
 		int pages = 1 << oo_order(oo);
 
@@ -1336,6 +1330,11 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 			kmemcheck_mark_unallocated_pages(page, pages);
 	}
 
+	if (flags & __GFP_WAIT)
+		local_irq_disable();
+	if (!page)
+		return NULL;
+
 	page->objects = oo_objects(oo);
 	mod_zone_page_state(page_zone(page),
 		(s->flags & SLAB_RECLAIM_ACCOUNT) ?

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

* Re: [patch] mm, slub: ensure irqs are enabled for kmemcheck
  2012-07-09 10:36       ` [patch] mm, slub: ensure irqs are enabled for kmemcheck David Rientjes
@ 2012-07-09 13:46         ` Steven Rostedt
  2012-07-09 14:06           ` Fengguang Wu
  2012-07-09 21:00           ` [patch v2] " David Rientjes
  0 siblings, 2 replies; 5+ messages in thread
From: Steven Rostedt @ 2012-07-09 13:46 UTC (permalink / raw)
  To: David Rientjes
  Cc: Pekka Enberg, JoonSoo Kim, Fengguang Wu, Vegard Nossum,
	Christoph Lameter, Rus, Ben Hutchings, stable, linux-mm,
	linux-kernel

On Mon, 2012-07-09 at 03:36 -0700, David Rientjes wrote:
> kmemcheck_alloc_shadow() requires irqs to be enabled, so wait to disable
> them until after its called for __GFP_WAIT allocations.
> 
> This fixes a warning for such allocations:
> 
> 	WARNING: at kernel/lockdep.c:2739 lockdep_trace_alloc+0x14e/0x1c0()
> 
> Cc: stable@vger.kernel.org [3.1+]
> Acked-by: Fengguang Wu <fengguang.wu@intel.com>
> Tested-by: Fengguang Wu <fengguang.wu@intel.com>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  mm/slub.c |   13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -1314,13 +1314,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
>  			stat(s, ORDER_FALLBACK);
>  	}
>  
> -	if (flags & __GFP_WAIT)
> -		local_irq_disable();
> -
> -	if (!page)
> -		return NULL;
> -
> -	if (kmemcheck_enabled
> +	if (page && kmemcheck_enabled

One micro-optimization nit...

If kmemcheck_enabled is mostly false, and page is mostly true, wouldn't
it be better to swap the two?

	if (kmemcheck_enabled && page

Then the first check would just short-circuit out and we don't do the
double check.

Otherwise it looks good.

Acked-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve

>  		&& !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
>  		int pages = 1 << oo_order(oo);
>  
> @@ -1336,6 +1330,11 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
>  			kmemcheck_mark_unallocated_pages(page, pages);
>  	}
>  
> +	if (flags & __GFP_WAIT)
> +		local_irq_disable();
> +	if (!page)
> +		return NULL;
> +
>  	page->objects = oo_objects(oo);
>  	mod_zone_page_state(page_zone(page),
>  		(s->flags & SLAB_RECLAIM_ACCOUNT) ?



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

* Re: [patch] mm, slub: ensure irqs are enabled for kmemcheck
  2012-07-09 13:46         ` Steven Rostedt
@ 2012-07-09 14:06           ` Fengguang Wu
  2012-07-09 21:00           ` [patch v2] " David Rientjes
  1 sibling, 0 replies; 5+ messages in thread
From: Fengguang Wu @ 2012-07-09 14:06 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: David Rientjes, Pekka Enberg, JoonSoo Kim, Vegard Nossum,
	Christoph Lameter, Rus, Ben Hutchings, stable, linux-mm,
	linux-kernel

On Mon, Jul 09, 2012 at 09:46:33AM -0400, Steven Rostedt wrote:
> On Mon, 2012-07-09 at 03:36 -0700, David Rientjes wrote:
> > kmemcheck_alloc_shadow() requires irqs to be enabled, so wait to disable
> > them until after its called for __GFP_WAIT allocations.
> > 
> > This fixes a warning for such allocations:
> > 
> > 	WARNING: at kernel/lockdep.c:2739 lockdep_trace_alloc+0x14e/0x1c0()
> > 
> > Cc: stable@vger.kernel.org [3.1+]
> > Acked-by: Fengguang Wu <fengguang.wu@intel.com>
> > Tested-by: Fengguang Wu <fengguang.wu@intel.com>
> > Signed-off-by: David Rientjes <rientjes@google.com>
> > ---
> >  mm/slub.c |   13 ++++++-------
> >  1 file changed, 6 insertions(+), 7 deletions(-)
> > 
> > diff --git a/mm/slub.c b/mm/slub.c
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -1314,13 +1314,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
> >  			stat(s, ORDER_FALLBACK);
> >  	}
> >  
> > -	if (flags & __GFP_WAIT)
> > -		local_irq_disable();
> > -
> > -	if (!page)
> > -		return NULL;
> > -
> > -	if (kmemcheck_enabled
> > +	if (page && kmemcheck_enabled
> 
> One micro-optimization nit...
> 
> If kmemcheck_enabled is mostly false, and page is mostly true, wouldn't
> it be better to swap the two?
> 
> 	if (kmemcheck_enabled && page
> 
> Then the first check would just short-circuit out and we don't do the
> double check.

I had the same gut feeling but at the time was not as conscious as you ;)
Now I can dig out a similar optimization by Andrew Morton which also
saves memory bytes:

On Tue, Jun 19, 2012 at 03:00:14PM -0700, Andrew Morton wrote:

: With my gcc and CONFIG_CGROUP_MEM_RES_CTLR=n (for gawd's sake can we
: please rename this to CONFIG_MEMCG?), this:
: 
: --- a/mm/vmscan.c~memcg-prevent-from-oom-with-too-many-dirty-pages-fix
: +++ a/mm/vmscan.c
: @@ -726,8 +726,8 @@ static unsigned long shrink_page_list(st
:                          * writeback from reclaim and there is nothing else to
:                          * reclaim.
:                          */
: -                       if (PageReclaim(page)
: -                                       && may_enter_fs && !global_reclaim(sc))
: +                       if (!global_reclaim(sc) && PageReclaim(page) &&
: +                                       may_enter_fs)
:                                 wait_on_page_writeback(page);
:                         else {
:                                 nr_writeback++;
: 
: 
: reduces vmscan.o's .text by 48 bytes(!).  Because the compiler can
: avoid generating any code for PageReclaim() and perhaps the
: may_enter_fs test.  Because global_reclaim() evaluates to constant
: true.  Do you think that's an improvement?

Thanks,
Fengguang

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

* [patch v2] mm, slub: ensure irqs are enabled for kmemcheck
  2012-07-09 13:46         ` Steven Rostedt
  2012-07-09 14:06           ` Fengguang Wu
@ 2012-07-09 21:00           ` David Rientjes
  2012-07-10 19:44             ` Pekka Enberg
  1 sibling, 1 reply; 5+ messages in thread
From: David Rientjes @ 2012-07-09 21:00 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Steven Rostedt, JoonSoo Kim, Fengguang Wu, Vegard Nossum,
	Christoph Lameter, Rus, Ben Hutchings, stable, linux-mm,
	linux-kernel

kmemcheck_alloc_shadow() requires irqs to be enabled, so wait to disable
them until after its called for __GFP_WAIT allocations.

This fixes a warning for such allocations:

	WARNING: at kernel/lockdep.c:2739 lockdep_trace_alloc+0x14e/0x1c0()

Acked-by: Fengguang Wu <fengguang.wu@intel.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/slub.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1314,13 +1314,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 			stat(s, ORDER_FALLBACK);
 	}
 
-	if (flags & __GFP_WAIT)
-		local_irq_disable();
-
-	if (!page)
-		return NULL;
-
-	if (kmemcheck_enabled
+	if (kmemcheck_enabled && page
 		&& !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
 		int pages = 1 << oo_order(oo);
 
@@ -1336,6 +1330,11 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 			kmemcheck_mark_unallocated_pages(page, pages);
 	}
 
+	if (flags & __GFP_WAIT)
+		local_irq_disable();
+	if (!page)
+		return NULL;
+
 	page->objects = oo_objects(oo);
 	mod_zone_page_state(page_zone(page),
 		(s->flags & SLAB_RECLAIM_ACCOUNT) ?

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

* Re: [patch v2] mm, slub: ensure irqs are enabled for kmemcheck
  2012-07-09 21:00           ` [patch v2] " David Rientjes
@ 2012-07-10 19:44             ` Pekka Enberg
  0 siblings, 0 replies; 5+ messages in thread
From: Pekka Enberg @ 2012-07-10 19:44 UTC (permalink / raw)
  To: David Rientjes
  Cc: Steven Rostedt, JoonSoo Kim, Fengguang Wu, Vegard Nossum,
	Christoph Lameter, Rus, Ben Hutchings, stable, linux-mm,
	linux-kernel

On Mon, 9 Jul 2012, David Rientjes wrote:
> kmemcheck_alloc_shadow() requires irqs to be enabled, so wait to disable
> them until after its called for __GFP_WAIT allocations.
> 
> This fixes a warning for such allocations:
> 
> 	WARNING: at kernel/lockdep.c:2739 lockdep_trace_alloc+0x14e/0x1c0()
> 
> Acked-by: Fengguang Wu <fengguang.wu@intel.com>
> Acked-by: Steven Rostedt <rostedt@goodmis.org>
> Tested-by: Fengguang Wu <fengguang.wu@intel.com>
> Signed-off-by: David Rientjes <rientjes@google.com>

Applied, thanks!

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

end of thread, other threads:[~2012-07-10 19:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20120708040009.GA8363@localhost>
     [not found] ` <CAAmzW4OD2_ODyeY7c1VMPajwzovOms5M8Vnw=XP=uGUyPogiJQ@mail.gmail.com>
     [not found]   ` <alpine.DEB.2.00.1207081558540.18461@chino.kir.corp.google.com>
     [not found]     ` <alpine.LFD.2.02.1207091209220.3050@tux.localdomain>
2012-07-09 10:36       ` [patch] mm, slub: ensure irqs are enabled for kmemcheck David Rientjes
2012-07-09 13:46         ` Steven Rostedt
2012-07-09 14:06           ` Fengguang Wu
2012-07-09 21:00           ` [patch v2] " David Rientjes
2012-07-10 19:44             ` Pekka Enberg

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