Skip to contentSkip to conversation

slab: optimize kmalloc_node the same way as kmalloc

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

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

PATCH 2/2 slab: optimize kmalloc_node the same way as kmalloc

include/linux/slab.h +24 -1
Index: linux-2.6/include/linux/slab.h
===================================================================
@@ -213,7 +213,30 @@
 
 #ifdef CONFIG_NUMA
 extern void *kmem_cache_alloc_node(kmem_cache_t *, gfp_t flags, int node);
-extern void *kmalloc_node(size_t size, gfp_t flags, int node);
+extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
+
+static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
+{
+	if (__builtin_constant_p(size)) {
+		int i = 0;
+#define CACHE(x) \
+		if (size <= x) \
+			goto found; \
+		else \
+			i++;
+#include "kmalloc_sizes.h"
+#undef CACHE
+		{
+			extern void __you_cannot_kmalloc_that_much(void);
+			__you_cannot_kmalloc_that_much();
+		}
+found:
+		return kmem_cache_alloc_node((flags & GFP_DMA) ?
+			malloc_sizes[i].cs_dmacachep :
+			malloc_sizes[i].cs_cachep, flags, node);
+	}
+	return __kmalloc_node(size, flags, node);
+}
 #else
 static inline void *kmem_cache_alloc_node(kmem_cache_t *cachep, gfp_t flags, int node)
 {
mm/slab.c +1 -1
Index: linux-2.6/mm/slab.c
===================================================================
@@ -3317,7 +3317,7 @@
 }
 EXPORT_SYMBOL(kmem_cache_alloc_node);
 
-void *kmalloc_node(size_t size, gfp_t flags, int node)
+void *__kmalloc_node(size_t size, gfp_t flags, int node)
 {
 	struct kmem_cache *cachep;
 

--
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 1 line · Christoph Hellwig

+static inline void *kmalloc_node(size_t size, gfp_t flags, int node)

[snip]

I think the optimization was left out on purpose as kmalloc_node() is slow anyway. No objections from me though.

--
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>

Acked-by on v1 2/2
#2 lore raw
In reply to Christoph Hellwig
Quoted 1 line · Christoph Hellwig

I actually posted almost the same patch a year ago. But note that kmalloc_node() does not use cpucaches and therefore does not have the speed of kmalloc()

--
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>