Skip to contentSkip to conversation

kfence: skip __GFP_THISNODE allocations on NUMA systems

PATCH Applied Marco Elver 2 participants 2 messages Jan 24, 2025

Subsystems (2)
lore
Share & tools
lore

Marco Elver

author maintainer
#0 lore raw

PATCH 1/1 kfence: skip __GFP_THISNODE allocations on NUMA systems

On NUMA systems, __GFP_THISNODE indicates that an allocation _must_ be on a particular node, and failure to allocate on the desired node will result in a failed allocation.

Skip __GFP_THISNODE allocations if we are running on a NUMA system, since KFENCE can't guarantee which node its pool pages are allocated on.

Cc Christoph Lameter <[email protected]>
Fixes 236e9f153852 ("kfence: skip all GFP_ZONEMASK allocations")
---
 mm/kfence/core.c | 2 ++
 1 file changed, 2 insertions(+)
mm/kfence/core.c +2 -0
index 67fc321db79b..102048821c22 100644
@@ -21,6 +21,7 @@
 #include <linux/log2.h>
 #include <linux/memblock.h>
 #include <linux/moduleparam.h>
+#include <linux/nodemask.h>
 #include <linux/notifier.h>
 #include <linux/panic_notifier.h>
 #include <linux/random.h>
@@ -1084,6 +1085,7 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags)
 	 * properties (e.g. reside in DMAable memory).
 	 */
 	if ((flags & GFP_ZONEMASK) ||
+	    ((flags & __GFP_THISNODE) && num_online_nodes() > 1) ||
 	    (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) {
 		atomic_long_inc(&counters[KFENCE_COUNTER_SKIP_INCOMPAT]);
 		return NULL;
Signature · 1 line
2.48.1.262.g85cc9f2d1e-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Marco Elver

On NUMA systems, __GFP_THISNODE indicates that an allocation _must_ be on a particular node, and failure to allocate on the desired node will result in a failed allocation.

Skip __GFP_THISNODE allocations if we are running on a NUMA system, since KFENCE can't guarantee which node its pool pages are allocated on.

Cc Christoph Lameter <[email protected]>
Fixes 236e9f153852 ("kfence: skip all GFP_ZONEMASK allocations")

Thanks.

Quoted 24 lines
---
 mm/kfence/core.c | 2 ++
 1 file changed, 2 insertions(+)
mm/kfence/core.c +2 -0
index 67fc321db79b..102048821c22 100644
@@ -21,6 +21,7 @@
 #include <linux/log2.h>
 #include <linux/memblock.h>
 #include <linux/moduleparam.h>
+#include <linux/nodemask.h>
 #include <linux/notifier.h>
 #include <linux/panic_notifier.h>
 #include <linux/random.h>
@@ -1084,6 +1085,7 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags)
 	 * properties (e.g. reside in DMAable memory).
 	 */
 	if ((flags & GFP_ZONEMASK) ||
+	    ((flags & __GFP_THISNODE) && num_online_nodes() > 1) ||
 	    (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) {
 		atomic_long_inc(&counters[KFENCE_COUNTER_SKIP_INCOMPAT]);
 		return NULL;