linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: Rafael Aquini <aquini@redhat.com>
Cc: linux-mm@kvack.org, Randy Dunlap <rdunlap@xenotime.net>,
	Christoph Lameter <cl@linux-foundation.org>,
	Matt Mackall <mpm@selenic.com>, Rik van Riel <riel@redhat.com>,
	Josef Bacik <josef@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] oom: add sysctl to enable slab memory dump
Date: Wed, 22 Feb 2012 15:17:23 +0200	[thread overview]
Message-ID: <CAOJsxLGz4=2tFQdnnFmGLeFVVPq8pX5=0var7V-9+ddi=TPNVA@mail.gmail.com> (raw)
In-Reply-To: <20120222115320.GA3107@x61.redhat.com>

On Wed, Feb 22, 2012 at 1:53 PM, Rafael Aquini <aquini@redhat.com> wrote:
> Adds a new sysctl, 'oom_dump_slabs', that enables the kernel to produce a
> dump of all eligible system slab caches when performing an OOM-killing.
> Information includes per cache active objects, total objects, object size,
> cache name and cache size.
>
> The eligibility for being reported is given by an auxiliary sysctl,
> 'oom_dump_slabs_ratio', which express (in percentage) the memory committed
> ratio between a particular cache size and the total slab size.
>
> This, alongside with all other data dumped in OOM events, is very helpful
> information in diagnosing why there was an OOM condition specially when
> kernel code is under investigation.
>
> Signed-off-by: Rafael Aquini <aquini@redhat.com>

Makes sense. Do you have an example how an out-of-memory slab cache
dump looks like?

> diff --git a/mm/slab.c b/mm/slab.c
> index f0bd785..c2b5d14 100644
> --- a/mm/slab.c
> +++ b/mm/slab.c
> @@ -4629,3 +4629,75 @@ size_t ksize(const void *objp)
>        return obj_size(virt_to_cache(objp));
>  }
>  EXPORT_SYMBOL(ksize);
> +
> +/**
> + * oom_dump_slabs - dump top slab cache users
> + * @ratio: memory committed ratio between a cache size and the total slab size
> + *
> + * Dumps the current memory state of all eligible slab caches.
> + * State information includes cache's active objects, total objects,
> + * object size, cache name, and cache size.
> + */
> +void oom_dump_slabs(int ratio)
> +{
> +       struct kmem_cache *cachep;
> +       struct kmem_list3 *l3;
> +       struct slab *slabp;
> +       unsigned long active_objs, num_objs, free_objects, cache_size;
> +       unsigned long active_slabs, num_slabs, slab_total_mem;
> +       int node;

[snip]

> +       list_for_each_entry(cachep, &cache_chain, next) {
> +               num_objs = 0;
> +               num_slabs = 0;
> +               active_objs = 0;
> +               free_objects = 0;
> +               active_slabs = 0;

Minor style nit: just define the zeroed variables in this block.

> +
> +               for_each_online_node(node) {
> +                       l3 = cachep->nodelists[node];
> +                       if (!l3)
> +                               continue;
> +void oom_dump_slabs(int ratio)
> +{
> +       unsigned long cache_size, slab_total_mem;
> +       unsigned long nr_objs, nr_free, nr_inuse;
> +       struct kmem_cache *cachep;
> +       int node;
> +
> +       slab_total_mem = (global_page_state(NR_SLAB_RECLAIMABLE) +
> +                       global_page_state(NR_SLAB_UNRECLAIMABLE)) << PAGE_SHIFT;
> +
> +       if (ratio < 0)
> +               ratio = 0;
> +
> +       if (ratio > 100)
> +               ratio = 100;
> +
> +       pr_info("--- oom_dump_slabs:\n");
> +       pr_info("<active_objs>    <num_objs>     <objsize>  <cache_name>\n");
> +       down_read(&slub_lock);
> +       list_for_each_entry(cachep, &slab_caches, list) {
> +               nr_objs = 0;
> +               nr_free = 0;

ditto.

> +
> +               for_each_online_node(node) {
> +                       struct kmem_cache_node *n = get_node(cachep, node);
> +                       if (!n)
> +                               continue;
> +

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2012-02-22 13:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22 11:53 Rafael Aquini
2012-02-22 13:17 ` Pekka Enberg [this message]
2012-02-22 16:04   ` Rafael Aquini
2012-02-22 13:55 ` Christoph Lameter
2012-02-22 16:14   ` Rafael Aquini
2012-02-22 16:29     ` Christoph Lameter
2012-02-23  0:44 ` David Rientjes
2012-02-23 15:02   ` Josef Bacik
2012-02-23 23:09     ` David Rientjes
2012-02-24 15:10       ` Josef Bacik
2012-02-24 21:45         ` David Rientjes
2012-02-24 21:52           ` Pekka Enberg
2012-02-24 23:51             ` David Rientjes
2012-02-23 15:22   ` Rafael Aquini
2012-02-23 16:03     ` Pekka Enberg
2012-02-23 23:17     ` David Rientjes
2012-02-24  6:57       ` Pekka Enberg
2012-02-24 10:03         ` David Rientjes
2012-02-24 10:05           ` Pekka Enberg
2012-02-24 10:38             ` Rafael Aquini
2012-02-29  3:39             ` Rafael Aquini

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='CAOJsxLGz4=2tFQdnnFmGLeFVVPq8pX5=0var7V-9+ddi=TPNVA@mail.gmail.com' \
    --to=penberg@kernel.org \
    --cc=aquini@redhat.com \
    --cc=cl@linux-foundation.org \
    --cc=josef@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mpm@selenic.com \
    --cc=rdunlap@xenotime.net \
    --cc=riel@redhat.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