From 21578d0bf770ea30307b8140f0c6303c8e559f5e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 13 Dec 2012 13:31:53 -0800 Subject: [PATCH] PR14957: Don't force __GFP_ZERO into kmalloc_node It turns out that rhel5-era kernels have a BUG check in slab cache_grow that doesn't permit __GFP_ZERO from this path. Later kernels corrected this, as the implementation of kzalloc_node is just kmalloc_node with __GFP_ZERO added, but for compatibility we can't rely on that. * runtime/linux/alloc.c (_stp_kzalloc_node_gfp): Use a plain _stp_kmalloc_node_gfp, then memset-0 manually. --- runtime/linux/alloc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/runtime/linux/alloc.c b/runtime/linux/alloc.c index 0a5b3f9f1..2737a0caa 100644 --- a/runtime/linux/alloc.c +++ b/runtime/linux/alloc.c @@ -407,7 +407,21 @@ static void *_stp_kmalloc_node_gfp(size_t size, int node, gfp_t gfp_mask) } static void *_stp_kzalloc_node_gfp(size_t size, int node, gfp_t gfp_mask) { - return _stp_kmalloc_node_gfp(size, node, gfp_mask | __GFP_ZERO); + /* This used to be simply: + * return _stp_kmalloc_node_gfp(size, node, gfp_mask | __GFP_ZERO); + * but rhel5-era kernels BUG out on that flag. (PR14957) + * + * We could make a big #if-alternation for kernels which have support + * for kzalloc_node (kernel commit 979b0fea), as in _stp_kzalloc_gfp, + * but IMO that's needlessly complex. + * + * So for now, just malloc and zero it manually. + */ + void *ret = _stp_kmalloc_node_gfp(size, node, gfp_mask); + if (likely(ret)) { + memset (ret, 0, size); + } + return ret; } static void *_stp_kmalloc_node(size_t size, int node) { -- 2.43.5