From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx194.postini.com [74.125.245.194]) by kanga.kvack.org (Postfix) with SMTP id 6021D6B0044 for ; Fri, 9 Mar 2012 19:23:44 -0500 (EST) Received: by yhr47 with SMTP id 47so1689754yhr.14 for ; Fri, 09 Mar 2012 16:23:43 -0800 (PST) Subject: Re: [PATCH v3] mm: SLAB Out-of-memory diagnostics From: Eric Dumazet In-Reply-To: <20120309202722.GA10323@x61.redhat.com> References: <20120309202722.GA10323@x61.redhat.com> Content-Type: text/plain; charset="UTF-8" Date: Fri, 09 Mar 2012 16:23:39 -0800 Message-ID: <1331339019.4063.365.camel@edumazet-glaptop> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Rafael Aquini Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Randy Dunlap , Christoph Lameter , Pekka Enberg , Matt Mackall , Rik van Riel , Josef Bacik , David Rientjes , Cong Wang On Fri, 2012-03-09 at 17:27 -0300, Rafael Aquini wrote: > Following the example at mm/slub.c, add out-of-memory diagnostics to the > SLAB allocator to help on debugging certain OOM conditions. > > An example print out looks like this: > > > SLAB: Unable to allocate memory on node 0 (gfp=0x11200) > cache: bio-0, object size: 192, order: 0 > node 0: slabs: 3/3, objs: 60/60, free: 0 Should probably be : node: 0 slabs: 3/3, objs: 60/60, free: 0 > > Signed-off-by: Rafael Aquini > Acked-by: Rik van Riel > --- > v2: > * drop the sysctl knob to override __GFP_NOWARN allocation flag (Pekka, David) > > v3: > * adjust the print output to match slub's warning printout (WANG Cong) > > mm/slab.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 50 insertions(+), 1 deletions(-) > > diff --git a/mm/slab.c b/mm/slab.c > index f0bd785..cda1ff6 100644 > --- a/mm/slab.c > +++ b/mm/slab.c > @@ -1731,6 +1731,52 @@ static int __init cpucache_init(void) > } > __initcall(cpucache_init); > > +static noinline void > +slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid) > +{ > + struct kmem_list3 *l3; > + struct slab *slabp; > + unsigned long flags; > + int node; > + > + printk(KERN_WARNING > + "SLAB: Unable to allocate memory on node %d (gfp=0x%x)\n", > + nodeid, gfpflags); > + printk(KERN_WARNING " cache: %s, object size: %d, order: %d\n", > + cachep->name, cachep->buffer_size, cachep->gfporder); > + > + for_each_online_node(node) { > + unsigned long active_objs = 0, num_objs = 0, free_objects = 0; > + unsigned long active_slabs = 0, num_slabs = 0; > + > + l3 = cachep->nodelists[node]; > + if (!l3) > + continue; > + > + spin_lock_irqsave(&l3->list_lock, flags); > + list_for_each_entry(slabp, &l3->slabs_full, list) { > + active_objs += cachep->num; > + active_slabs++; > + } > + list_for_each_entry(slabp, &l3->slabs_partial, list) { > + active_objs += slabp->inuse; > + active_slabs++; > + } > + list_for_each_entry(slabp, &l3->slabs_free, list) > + num_slabs++; > + > + free_objects += l3->free_objects; > + spin_unlock_irqrestore(&l3->list_lock, flags); > + > + num_slabs += active_slabs; > + num_objs = num_slabs * cachep->num; > + printk(KERN_WARNING > + " node %d: slabs: %ld/%ld, objs: %ld/%ld, free: %ld\n", Probably should be : " node: %d slabs: %ld/%ld, objs: %ld/%ld, free: %ld\n", > + node, active_slabs, num_slabs, active_objs, num_objs, > + free_objects); > + } > +} > + > /* > * Interface to system's page allocator. No need to hold the cache-lock. > * > @@ -1757,8 +1803,11 @@ static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid) > flags |= __GFP_RECLAIMABLE; > > page = alloc_pages_exact_node(nodeid, flags | __GFP_NOTRACK, cachep->gfporder); > - if (!page) > + if (!page) { > + if (!(flags & __GFP_NOWARN) && printk_ratelimit()) > + slab_out_of_memory(cachep, flags, nodeid); > return NULL; > + } > > nr_pages = (1 << cachep->gfporder); > if (cachep->flags & SLAB_RECLAIM_ACCOUNT) -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org