* [PATCH slab] slab: Clarify comments regarding pfmemalloc and NUMA preferences
@ 2025-09-16 1:46 Alexei Starovoitov
2025-09-16 10:21 ` Vlastimil Babka
0 siblings, 1 reply; 2+ messages in thread
From: Alexei Starovoitov @ 2025-09-16 1:46 UTC (permalink / raw)
To: bpf, linux-mm
Cc: vbabka, harry.yoo, shakeel.butt, mhocko, bigeasy, andrii, memxor,
akpm, peterz, rostedt, hannes
From: Alexei Starovoitov <ast@kernel.org>
Clarify comments regarding pfmemalloc and NUMA preferences
when ___slab_alloc() operating in !allow_spin mode.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
mm/slub.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 83983de948f3..c995f3bec69d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4456,9 +4456,17 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
/*
* same as above but node_match() being false already
* implies node != NUMA_NO_NODE.
- * Reentrant slub cannot take locks necessary to
- * deactivate_slab, hence ignore node preference.
- * kmalloc_nolock() doesn't allow __GFP_THISNODE.
+ *
+ * We don't strictly honor pfmemalloc and NUMA preferences
+ * when !allow_spin because:
+ *
+ * 1. Most kmalloc() users allocate objects on the local node,
+ * so kmalloc_nolock() tries not to interfere with them by
+ * deactivating the cpu slab.
+ *
+ * 2. Deactivating due to NUMA or pfmemalloc mismatch may cause
+ * unnecessary slab allocations even when n->partial list
+ * is not empty.
*/
if (!node_isset(node, slab_nodes) ||
!allow_spin) {
@@ -4547,11 +4555,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
slab = slub_percpu_partial(c);
slub_set_percpu_partial(c, slab);
- /*
- * Reentrant slub cannot take locks necessary for
- * __put_partials(), hence ignore node preference.
- * kmalloc_nolock() doesn't allow __GFP_THISNODE.
- */
if (likely(node_match(slab, node) &&
pfmemalloc_match(slab, gfpflags)) ||
!allow_spin) {
--
2.47.3
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH slab] slab: Clarify comments regarding pfmemalloc and NUMA preferences
2025-09-16 1:46 [PATCH slab] slab: Clarify comments regarding pfmemalloc and NUMA preferences Alexei Starovoitov
@ 2025-09-16 10:21 ` Vlastimil Babka
0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2025-09-16 10:21 UTC (permalink / raw)
To: Alexei Starovoitov, bpf, linux-mm
Cc: harry.yoo, shakeel.butt, mhocko, bigeasy, andrii, memxor, akpm,
peterz, rostedt, hannes
On 9/16/25 03:46, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> Clarify comments regarding pfmemalloc and NUMA preferences
> when ___slab_alloc() operating in !allow_spin mode.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Folding that into "slab: Introduce kmalloc_nolock() and kfree_nolock()." in
slab/for-next, thanks.
> ---
> mm/slub.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 83983de948f3..c995f3bec69d 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4456,9 +4456,17 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
> /*
> * same as above but node_match() being false already
> * implies node != NUMA_NO_NODE.
> - * Reentrant slub cannot take locks necessary to
> - * deactivate_slab, hence ignore node preference.
> - * kmalloc_nolock() doesn't allow __GFP_THISNODE.
> + *
> + * We don't strictly honor pfmemalloc and NUMA preferences
> + * when !allow_spin because:
> + *
> + * 1. Most kmalloc() users allocate objects on the local node,
> + * so kmalloc_nolock() tries not to interfere with them by
> + * deactivating the cpu slab.
> + *
> + * 2. Deactivating due to NUMA or pfmemalloc mismatch may cause
> + * unnecessary slab allocations even when n->partial list
> + * is not empty.
> */
> if (!node_isset(node, slab_nodes) ||
> !allow_spin) {
> @@ -4547,11 +4555,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
> slab = slub_percpu_partial(c);
> slub_set_percpu_partial(c, slab);
>
> - /*
> - * Reentrant slub cannot take locks necessary for
> - * __put_partials(), hence ignore node preference.
> - * kmalloc_nolock() doesn't allow __GFP_THISNODE.
> - */
> if (likely(node_match(slab, node) &&
> pfmemalloc_match(slab, gfpflags)) ||
> !allow_spin) {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-16 10:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-16 1:46 [PATCH slab] slab: Clarify comments regarding pfmemalloc and NUMA preferences Alexei Starovoitov
2025-09-16 10:21 ` Vlastimil Babka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox