Skip to contentSkip to conversation

slab: account leaks to caller version of kmalloc_node

PATCH In review Christoph Hellwig 2 participants 2 messages Aug 4, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 slab: account leaks to caller version of kmalloc_node

Implement a kmalloc_track_caller equivalent for kmalloc_node. It's needed for the the slab-aware alloc_skb patch that I posted to linux-netdev to not break slab leak tracking. The code is ugly but that's because it's a cut & paste of the already ugly kmalloc version.

And no, that one can't be made much cleaner either without slowing kmalloc down.

include/linux/slab.h +22 -1
Index: linux-2.6/include/linux/slab.h
===================================================================
@@ -237,6 +237,25 @@
 	}
 	return __kmalloc_node(size, flags, node);
 }
+
+/*
+ * kmalloc_node_track_caller is a special version of kmalloc_node 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_node 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_node_track_caller(size, flags, node) \
+	__kmalloc_node(size, flags, node)
+#else
+extern void *__kmalloc_track_caller(size_t, gfp_t, void*);
+#define kmalloc_node_track_caller(size, flags, node) \
+	__kmalloc_node_track_caller(size, flags, node, \
+			__builtin_return_address(0))
+#endif
+
 #else
 static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int node)
 {
@@ -246,7 +265,9 @@
 {
 	return kmalloc(size, flags);
 }
-#endif
+#define kmalloc_node_track_caller(size, flags, node) \
+	kmalloc_track_caller(size, flags)
+#endif /* CONFIG_NUMA */
 
 extern int FASTCALL(kmem_cache_reap(int));
 extern int FASTCALL(kmem_ptr_validate(kmem_cache_t *cachep, void *ptr));
mm/slab.c +38 -9

91 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 11 lines · Christoph Hellwig
mm/slab.c +11 -0
+#ifndef CONFIG_DEBUG_SLAB
+void *__kmalloc_node(size_t size, gfp_t flags, int node)
+{
+       return __do_kmalloc_node(size, flags, node,
+                       __builtin_return_address(0));
+}
+EXPORT_SYMBOL(__kmalloc_node);
+
+void *__kmalloc_node_track_caller(size_t size, gfp_t flags,
+               int node, void *caller)
+{

mm/slab.c line 3358

Quoted 10 lines
mm/slab.c +9 -0
+       return __do_kmalloc_node(size, flags, node, caller);
+}
+EXPORT_SYMBOL(__kmalloc_node_track_caller);
+#else
+void *__kmalloc_node(size_t size, gfp_t flags, int node)
+{
+       return __do_kmalloc_node(size, flags, node, NULL);
+}
+EXPORT_SYMBOL(__kmalloc_node);
 #endif

You are passing NULL when CONFIG_DEBUG_SLAB is enabled but you want it the other way around.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>