From: Christoph Lameter kmalloc_node() falls back to ___cache_alloc() under certain conditions and at that point memory policies may be applied redirecting the allocation away from the current node. Therefore kmalloc_node(...,numa_node_id()) or kmalloc_node(...,-1) may not return memory from the local node. Fix this by doing the policy check in __cache_alloc() instead of ____cache_alloc(). This version here is a cleanup of Kiran's patch. - Tested on ia64. - Extra material removed. - Consolidate the exit path if alternate_node_alloc() returned an object. Signed-off-by: Alok N Kataria Signed-off-by: Ravikiran Thirumalai Signed-off-by: Shai Fultheim Signed-off-by: Christoph Lameter Signed-off-by: Andrew Morton --- mm/slab.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff -puN mm/slab.c~slab-fix-kmalloc_node-applying-memory-policies-if-nodeid-==-numa_node_id mm/slab.c --- a/mm/slab.c~slab-fix-kmalloc_node-applying-memory-policies-if-nodeid-==-numa_node_id +++ a/mm/slab.c @@ -3030,14 +3030,6 @@ static inline void *____cache_alloc(stru void *objp; struct array_cache *ac; -#ifdef CONFIG_NUMA - if (unlikely(current->flags & (PF_SPREAD_SLAB | PF_MEMPOLICY))) { - objp = alternate_node_alloc(cachep, flags); - if (objp != NULL) - return objp; - } -#endif - check_irq_off(); ac = cpu_cache_get(cachep); if (likely(ac->avail)) { @@ -3060,7 +3052,17 @@ static __always_inline void *__cache_all cache_alloc_debugcheck_before(cachep, flags); local_irq_save(save_flags); + +#ifdef CONFIG_NUMA + if (unlikely(current->flags & (PF_SPREAD_SLAB | PF_MEMPOLICY))) { + objp = alternate_node_alloc(cachep, flags); + if (objp != NULL) + goto out; + } +#endif + objp = ____cache_alloc(cachep, flags); +out: local_irq_restore(save_flags); objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); _