* [PATCH 1/3] mm/slub: remove always-true check in calculate_sizes()
2026-12-01 16:52 [PATCH 0/3] mm/slub: two small cleanups and a small fix Sang-Heon Jeon
@ 2026-12-01 16:52 ` Sang-Heon Jeon
2026-12-01 16:52 ` [PATCH 2/3] mm/slub: use kmem_cache_alloc() in bootstrap() Sang-Heon Jeon
2026-12-01 16:52 ` [PATCH 3/3] mm/slub: copy only the requested size in kvrealloc() Sang-Heon Jeon
2 siblings, 0 replies; 4+ messages in thread
From: Sang-Heon Jeon @ 2026-12-01 16:52 UTC (permalink / raw)
To: Vlastimil Babka, Harry Yoo, Andrew Morton
Cc: Christoph Lameter, David Rientjes, Hao Li, linux-kernel, linux-mm,
Roman Gushchin
When calculate_order() succeeds, a slab of the returned order holds at
least one and at most MAX_OBJS_PER_PAGE objects, so oo_objects(s->oo)
is never zero.
So remove the check and return 1 explicitly.
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/slub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index 47a664427c50..e966a0de1515 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8233,7 +8233,7 @@ static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s)
s->oo = oo_make(order, size);
s->min = oo_make(get_order(size), size);
- return !!oo_objects(s->oo);
+ return 1;
}
static void list_slab_objects(struct kmem_cache *s, struct slab *slab)
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] mm/slub: use kmem_cache_alloc() in bootstrap()
2026-12-01 16:52 [PATCH 0/3] mm/slub: two small cleanups and a small fix Sang-Heon Jeon
2026-12-01 16:52 ` [PATCH 1/3] mm/slub: remove always-true check in calculate_sizes() Sang-Heon Jeon
@ 2026-12-01 16:52 ` Sang-Heon Jeon
2026-12-01 16:52 ` [PATCH 3/3] mm/slub: copy only the requested size in kvrealloc() Sang-Heon Jeon
2 siblings, 0 replies; 4+ messages in thread
From: Sang-Heon Jeon @ 2026-12-01 16:52 UTC (permalink / raw)
To: Vlastimil Babka, Harry Yoo, Andrew Morton
Cc: Christoph Lameter, David Rientjes, Hao Li, linux-kernel, linux-mm,
Roman Gushchin
bootstrap() allocates a kmem_cache with kmem_cache_zalloc(), which
returns zero-initialized memory. memcpy() then overwrites the whole
object, and nothing uses it in between.
So allocate it with kmem_cache_alloc() instead.
No functional change.
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/slub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index e966a0de1515..8e6e900fc39b 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -8671,7 +8671,7 @@ static int slab_memory_callback(struct notifier_block *self,
static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache)
{
int node;
- struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
+ struct kmem_cache *s = kmem_cache_alloc(kmem_cache, GFP_NOWAIT);
struct kmem_cache_node *n;
memcpy(s, static_cache, kmem_cache->object_size);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 3/3] mm/slub: copy only the requested size in kvrealloc()
2026-12-01 16:52 [PATCH 0/3] mm/slub: two small cleanups and a small fix Sang-Heon Jeon
2026-12-01 16:52 ` [PATCH 1/3] mm/slub: remove always-true check in calculate_sizes() Sang-Heon Jeon
2026-12-01 16:52 ` [PATCH 2/3] mm/slub: use kmem_cache_alloc() in bootstrap() Sang-Heon Jeon
@ 2026-12-01 16:52 ` Sang-Heon Jeon
2 siblings, 0 replies; 4+ messages in thread
From: Sang-Heon Jeon @ 2026-12-01 16:52 UTC (permalink / raw)
To: Vlastimil Babka, Harry Yoo, Andrew Morton
Cc: Christoph Lameter, Danilo Krummrich, David Rientjes, Hao Li,
linux-kernel, linux-mm, Michal Hocko, Roman Gushchin
If SLAB_STORE_USER is enabled, the requested size is tracked and
kzalloc() zeroes only the requested size.
But if kvrealloc() falls back to kvmalloc(), it copies the bytes beyond
the requested size up to ksize(p), which might be non-zero even if
__GFP_ZERO is set.
So copy only the requested size instead, like krealloc() already does.
Fixes: 590b9d576cae ("mm: kvmalloc: align kvrealloc() with krealloc()")
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
mm/slub.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 8e6e900fc39b..9742c2825a06 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -7272,10 +7272,18 @@ void *kvrealloc_node_align_noprof(const void *p, DECL_TOKEN_PARAMS(size, token),
if (!n)
return NULL;
- if (p) {
+ if (!ZERO_OR_NULL_PTR(p)) {
+ struct slab *slab = virt_to_slab(p);
+ size_t old_size;
+
+ if (!slab)
+ old_size = ksize(p);
+ else
+ old_size = get_orig_size(slab->slab_cache, (void *)p);
+
/* We already know that `p` is not a vmalloc address. */
kasan_disable_current();
- memcpy(n, kasan_reset_tag(p), min(size, ksize(p)));
+ memcpy(n, kasan_reset_tag(p), min(size, old_size));
kasan_enable_current();
kfree(p);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread