* [hch: [PATCH 1/3] slab: clean up leak tracking ifdefs a little bit]
@ 2006-08-04 15:16 Christoph Hellwig
2006-08-04 15:56 ` Pekka Enberg
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2006-08-04 15:16 UTC (permalink / raw)
To: linux-mm
----- Forwarded message from Christoph Hellwig <hch> -----
Date: Fri, 4 Aug 2006 17:15:30 +0200
From: Christoph Hellwig <hch>
Subject: [PATCH 1/3] slab: clean up leak tracking ifdefs a little bit
To: akpm@osdl.org, viro@zeniv.linux.org.uk
Cc: linux-mm@vger.kernel.org
- rename ____kmalloc to kmalloc_track_caller so that people have
a chance to guess what it does just from it's name. Add a comment
describing it for those who don't. Also move it after kmalloc in
slab.h so people get less confused when they are just looking for
kmalloc
- move things around in slab.c a little to reduce the ifdef mess.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: linux-2.6/include/linux/slab.h
===================================================================
--- linux-2.6.orig/include/linux/slab.h 2006-07-26 15:24:10.000000000 +0200
+++ linux-2.6/include/linux/slab.h 2006-07-26 15:30:49.000000000 +0200
@@ -78,13 +78,6 @@
extern struct cache_sizes malloc_sizes[];
extern void *__kmalloc(size_t, gfp_t);
-#ifndef CONFIG_DEBUG_SLAB
-#define ____kmalloc(size, flags) __kmalloc(size, flags)
-#else
-extern void *__kmalloc_track_caller(size_t, gfp_t, void*);
-#define ____kmalloc(size, flags) \
- __kmalloc_track_caller(size, flags, __builtin_return_address(0))
-#endif
/**
* kmalloc - allocate memory
@@ -154,6 +147,23 @@
return __kmalloc(size, flags);
}
+/*
+ * kmalloc_track_caller is a special version of kmalloc that records the
+ * calling function of the routine calling it for slab leak tracking instead
+ * of just the calling function (confusing, eh?).
+ * It's useful when the call to kmalloc comes from a widely-used standard
+ * allocator where we care about the real place the memory allocation
+ * request comes from.
+ */
+#ifndef CONFIG_DEBUG_SLAB
+#define kmalloc_track_caller(size, flags) \
+ __kmalloc(size, flags)
+#else
+extern void *__kmalloc_track_caller(size_t, gfp_t, void*);
+#define kmalloc_track_caller(size, flags) \
+ __kmalloc_track_caller(size, flags, __builtin_return_address(0))
+#endif
+
extern void *__kzalloc(size_t, gfp_t);
/**
@@ -250,7 +260,7 @@
#define kmem_cache_alloc_node(c, f, n) kmem_cache_alloc(c, f)
#define kmalloc_node(s, f, n) kmalloc(s, f)
#define kzalloc(s, f) __kzalloc(s, f)
-#define ____kmalloc kmalloc
+#define kmalloc_track_caller kmalloc
#endif /* CONFIG_SLOB */
Index: linux-2.6/mm/slab.c
===================================================================
--- linux-2.6.orig/mm/slab.c 2006-07-26 15:24:10.000000000 +0200
+++ linux-2.6/mm/slab.c 2006-07-26 15:25:28.000000000 +0200
@@ -3352,22 +3352,25 @@
}
+#ifndef CONFIG_DEBUG_SLAB
void *__kmalloc(size_t size, gfp_t flags)
{
-#ifndef CONFIG_DEBUG_SLAB
- return __do_kmalloc(size, flags, NULL);
-#else
return __do_kmalloc(size, flags, __builtin_return_address(0));
-#endif
}
EXPORT_SYMBOL(__kmalloc);
-#ifdef CONFIG_DEBUG_SLAB
void *__kmalloc_track_caller(size_t size, gfp_t flags, void *caller)
{
return __do_kmalloc(size, flags, caller);
}
EXPORT_SYMBOL(__kmalloc_track_caller);
+
+#else
+void *__kmalloc(size_t size, gfp_t flags)
+{
+ return __do_kmalloc(size, flags, NULL);
+}
+EXPORT_SYMBOL(__kmalloc);
#endif
#ifdef CONFIG_SMP
Index: linux-2.6/mm/util.c
===================================================================
--- linux-2.6.orig/mm/util.c 2006-04-04 16:50:13.000000000 +0200
+++ linux-2.6/mm/util.c 2006-07-26 15:25:55.000000000 +0200
@@ -11,7 +11,7 @@
*/
void *__kzalloc(size_t size, gfp_t flags)
{
- void *ret = ____kmalloc(size, flags);
+ void *ret = kmalloc_track_caller(size, flags);
if (ret)
memset(ret, 0, size);
return ret;
@@ -33,7 +33,7 @@
return NULL;
len = strlen(s) + 1;
- buf = ____kmalloc(len, gfp);
+ buf = kmalloc_track_caller(len, gfp);
if (buf)
memcpy(buf, s, len);
return buf;
Index: linux-2.6/net/core/skbuff.c
===================================================================
--- linux-2.6.orig/net/core/skbuff.c 2006-07-26 13:27:21.000000000 +0200
+++ linux-2.6/net/core/skbuff.c 2006-07-26 15:37:11.000000000 +0200
@@ -163,7 +163,8 @@
/* Get the DATA. Size must match skb_add_mtu(). */
size = SKB_DATA_ALIGN(size);
- data = ____kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
+ data = kmalloc_track_caller(size + sizeof(struct skb_shared_info),
+ gfp_mask);
if (!data)
goto nodata;
----- End forwarded message -----
--
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>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [hch: [PATCH 1/3] slab: clean up leak tracking ifdefs a little bit]
2006-08-04 15:16 [hch: [PATCH 1/3] slab: clean up leak tracking ifdefs a little bit] Christoph Hellwig
@ 2006-08-04 15:56 ` Pekka Enberg
0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2006-08-04 15:56 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-mm
Hi Christoph,
On 8/4/06, Christoph Hellwig <hch@lst.de> wrote:
> +#ifndef CONFIG_DEBUG_SLAB
> void *__kmalloc(size_t size, gfp_t flags)
> {
> -#ifndef CONFIG_DEBUG_SLAB
> - return __do_kmalloc(size, flags, NULL);
> -#else
> return __do_kmalloc(size, flags, __builtin_return_address(0));
Other way around. You want to pass NULL when debugging is disabled.
--
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>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-08-04 15:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-04 15:16 [hch: [PATCH 1/3] slab: clean up leak tracking ifdefs a little bit] Christoph Hellwig
2006-08-04 15:56 ` Pekka Enberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox