From: Ezequiel Garcia <elezegarcia@gmail.com>
To: linux-mm@kvack.org
Cc: Ezequiel Garcia <elezegarcia@gmail.com>,
Pekka Enberg <penberg@kernel.org>,
Christoph Lameter <cl@linux.com>
Subject: [PATCH 5/5] mm, slob: Trace allocation failures consistently
Date: Wed, 5 Sep 2012 19:48:43 -0300 [thread overview]
Message-ID: <1346885323-15689-5-git-send-email-elezegarcia@gmail.com> (raw)
In-Reply-To: <1346885323-15689-1-git-send-email-elezegarcia@gmail.com>
This patch cleans how we trace kmalloc and kmem_cache_alloc.
In particular, it fixes out-of-memory tracing: now every failed
allocation will trace reporting non-zero requested bytes, zero obtained bytes.
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
---
mm/slob.c | 30 ++++++++++++++++++------------
1 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/mm/slob.c b/mm/slob.c
index 3f4dc9a..73f16ca 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -428,6 +428,7 @@ static __always_inline void *
__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
{
int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+ size_t alloc_size = 0;
void *ret;
gfp &= gfp_allowed_mask;
@@ -441,24 +442,25 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
ret = slob_alloc(size + align, gfp, align, node);
if (!ret)
- return NULL;
+ goto trace_out;
*(unsigned int *)ret = size;
ret += align;
-
- trace_kmalloc_node(caller, ret,
- size, size + align, gfp, node);
+ alloc_size = size + align;
} else {
unsigned int order = get_order(size);
if (likely(order))
gfp |= __GFP_COMP;
ret = slob_new_pages(gfp, order, node);
+ if (!ret)
+ goto trace_out;
- trace_kmalloc_node(caller, ret,
- size, PAGE_SIZE << order, gfp, node);
+ alloc_size = PAGE_SIZE << order;
}
kmemleak_alloc(ret, size, 1, gfp);
+trace_out:
+ trace_kmalloc_node(caller, ret, size, alloc_size, gfp, node);
return ret;
}
@@ -565,6 +567,7 @@ EXPORT_SYMBOL(kmem_cache_destroy);
void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
{
+ size_t alloc_size = 0;
void *b;
flags &= gfp_allowed_mask;
@@ -573,20 +576,23 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
if (c->size < PAGE_SIZE) {
b = slob_alloc(c->size, flags, c->align, node);
- trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
- SLOB_UNITS(c->size) * SLOB_UNIT,
- flags, node);
+ if (!b)
+ goto trace_out;
+ alloc_size = SLOB_UNITS(c->size) * SLOB_UNIT;
} else {
b = slob_new_pages(flags, get_order(c->size), node);
- trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
- PAGE_SIZE << get_order(c->size),
- flags, node);
+ if (!b)
+ goto trace_out;
+ alloc_size = PAGE_SIZE << get_order(c->size);
}
if (c->ctor)
c->ctor(b);
kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags);
+trace_out:
+ trace_kmem_cache_alloc_node(_RET_IP_, b, c->size, alloc_size,
+ flags, node);
return b;
}
EXPORT_SYMBOL(kmem_cache_alloc_node);
--
1.7.8.6
--
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>
next prev parent reply other threads:[~2012-09-05 22:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-05 22:48 [PATCH 1/5] mm, slab: Remove silly function slab_buffer_size() Ezequiel Garcia
2012-09-05 22:48 ` [PATCH 2/5] mm, slob: Add support for kmalloc_track_caller() Ezequiel Garcia
2012-09-06 0:57 ` David Rientjes
2012-09-06 1:10 ` Ezequiel Garcia
2012-09-06 7:17 ` Pekka Enberg
2012-09-05 22:48 ` [PATCH 3/5] mm, util: Do strndup_user allocation directly, instead of through memdup_user Ezequiel Garcia
2012-09-06 0:59 ` David Rientjes
2012-09-06 1:06 ` Ezequiel Garcia
2012-09-06 19:27 ` JoonSoo Kim
2012-09-07 0:00 ` Ezequiel Garcia
2012-09-07 21:12 ` JoonSoo Kim
2012-09-05 22:48 ` [PATCH 4/5] mm, slob: Use only 'ret' variable for both slob object and returned pointer Ezequiel Garcia
2012-09-06 14:18 ` Christoph Lameter
2012-09-06 15:04 ` Ezequiel Garcia
2012-09-05 22:48 ` Ezequiel Garcia [this message]
2012-09-06 19:09 ` [PATCH 5/5] mm, slob: Trace allocation failures consistently JoonSoo Kim
2012-09-07 0:03 ` Ezequiel Garcia
2012-09-07 21:23 ` JoonSoo Kim
2012-09-08 13:26 ` Ezequiel Garcia
2012-09-07 21:50 ` JoonSoo Kim
2012-09-07 22:00 ` JoonSoo Kim
2012-09-06 0:54 ` [PATCH 1/5] mm, slab: Remove silly function slab_buffer_size() David Rientjes
2012-09-06 1:07 ` Ezequiel Garcia
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=1346885323-15689-5-git-send-email-elezegarcia@gmail.com \
--to=elezegarcia@gmail.com \
--cc=cl@linux.com \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
/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).