@@ -218,6 +218,10 @@ DEFINE_STATIC_KEY_FALSE(slub_debug_enabled);
218218#endif
219219#endif /* CONFIG_SLUB_DEBUG */
220220
221+ #ifdef CONFIG_NUMA
222+ static DEFINE_STATIC_KEY_FALSE (strict_numa );
223+ #endif
224+
221225/* Structure holding parameters for get_partial() call chain */
222226struct partial_context {
223227 gfp_t flags ;
@@ -3949,6 +3953,28 @@ static __always_inline void *__slab_alloc_node(struct kmem_cache *s,
39493953 object = c -> freelist ;
39503954 slab = c -> slab ;
39513955
3956+ #ifdef CONFIG_NUMA
3957+ if (static_branch_unlikely (& strict_numa ) &&
3958+ node == NUMA_NO_NODE ) {
3959+
3960+ struct mempolicy * mpol = current -> mempolicy ;
3961+
3962+ if (mpol ) {
3963+ /*
3964+ * Special BIND rule support. If existing slab
3965+ * is in permitted set then do not redirect
3966+ * to a particular node.
3967+ * Otherwise we apply the memory policy to get
3968+ * the node we need to allocate on.
3969+ */
3970+ if (mpol -> mode != MPOL_BIND || !slab ||
3971+ !node_isset (slab_nid (slab ), mpol -> nodes ))
3972+
3973+ node = mempolicy_slab_node ();
3974+ }
3975+ }
3976+ #endif
3977+
39523978 if (!USE_LOCKLESS_FAST_PATH () ||
39533979 unlikely (!object || !slab || !node_match (slab , node ))) {
39543980 object = __slab_alloc (s , gfpflags , node , addr , c , orig_size );
@@ -5715,6 +5741,23 @@ static int __init setup_slub_min_objects(char *str)
57155741__setup ("slab_min_objects=" , setup_slub_min_objects );
57165742__setup_param ("slub_min_objects=" , slub_min_objects , setup_slub_min_objects , 0 );
57175743
5744+ #ifdef CONFIG_NUMA
5745+ static int __init setup_slab_strict_numa (char * str )
5746+ {
5747+ if (nr_node_ids > 1 ) {
5748+ static_branch_enable (& strict_numa );
5749+ pr_info ("SLUB: Strict NUMA enabled.\n" );
5750+ } else {
5751+ pr_warn ("slab_strict_numa parameter set on non NUMA system.\n" );
5752+ }
5753+
5754+ return 1 ;
5755+ }
5756+
5757+ __setup ("slab_strict_numa" , setup_slab_strict_numa );
5758+ #endif
5759+
5760+
57185761#ifdef CONFIG_HARDENED_USERCOPY
57195762/*
57205763 * Rejects incorrectly sized objects and objects that are to be copied
0 commit comments