--- include/linux/slub_def.h | 54 +++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 18 deletions(-) Index: linux-2.6.22-rc4-mm2/include/linux/slub_def.h =================================================================== --- linux-2.6.22-rc4-mm2.orig/include/linux/slub_def.h 2007-06-23 10:09:05.000000000 -0700 +++ linux-2.6.22-rc4-mm2/include/linux/slub_def.h 2007-06-23 10:09:25.000000000 -0700 @@ -178,15 +178,21 @@ static inline struct kmem_cache *kmalloc static inline void *kmalloc(size_t size, gfp_t flags) { - if (__builtin_constant_p(size) && !(flags & SLUB_DMA)) { - struct kmem_cache *s = kmalloc_slab(size); - - if (!s) - return ZERO_SIZE_PTR; - - return kmem_cache_alloc(s, flags); - } else - return __kmalloc(size, flags); + if (__builtin_constant_p(size)) { + if (size > PAGE_SIZE /2) + return (void *)__get_free_pages(flags | __GFP_COMP, + get_order(size)); + + if (!(flags & SLUB_DMA)) { + struct kmem_cache *s = kmalloc_slab(size); + + if (!s) + return ZERO_SIZE_PTR; + + return kmem_cache_alloc(s, flags); + } + } + return __kmalloc(size, flags); } #ifdef CONFIG_NUMA @@ -194,15 +200,27 @@ extern void *__kmalloc_node(size_t size, static inline void *kmalloc_node(size_t size, gfp_t flags, int node) { - if (__builtin_constant_p(size) && !(flags & SLUB_DMA)) { - struct kmem_cache *s = kmalloc_slab(size); - - if (!s) - return ZERO_SIZE_PTR; - - return kmem_cache_alloc_node(s, flags, node); - } else - return __kmalloc_node(size, flags, node); + if (__builtin_constant_p(size)) { + if (size > PAGE_SIZE / 2) { + struct page *page = alloc_pages_node(node, + flags, get_order(size)); + + if (page) + return page_address(page); + else + return NULL; + } + + if (!(flags & SLUB_DMA)) { + struct kmem_cache *s = kmalloc_slab(size); + + if (!s) + return ZERO_SIZE_PTR; + + return kmem_cache_alloc_node(s, flags, node); + } + } + return __kmalloc_node(size, flags, node); } #endif