* [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache
@ 2026-10-20 15:12 Konstantin Khorenko
2026-10-20 15:15 ` no-reply
2026-10-20 15:30 ` Konstantin Khorenko
0 siblings, 2 replies; 3+ messages in thread
From: Konstantin Khorenko @ 2026-10-20 15:12 UTC (permalink / raw)
To: Pavel Tikhomirov, devel, Konstantin Khorenko, Vasileios Almpanis
shrinker_info_unit holds BITS_PER_LONG atomic_long_t of deferred work plus
a one-word bitmap, 520 bytes on 64-bit. kzalloc_node() takes it from
kmalloc-1k, so almost half of every unit is padding.
Allocate the units from a cache of their own, sized to the unit. The
cache is not cache-line aligned: the counters of a unit already share
cache lines between shrinkers, and aligning the unit would only keep
neighbouring units off each other's boundary line, at the cost of part of
the saving.
Link: https://lore.kernel.org/20261019-vstor-144715-shrinker_info_unit-kmem_cache-v3-1-0fb061e09bf4@virtuozzo.com
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
Reviewed-by: Qi Zheng <qi.zheng@linux.dev>
Acked-by: Muchun Song <muchun.song@linux.dev>
Assisted-by: LLM
Cc: Dave Chinner <david@fromorbit.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
(cherry picked from commit b36b71cb22027228fcc0f3a64c0f36900142c637)
Adapted: in 6.12 mem_cgroup_init() is a subsys_initcall and runs after
cgroup_init() has brought the root memcg online, which already needs
the cache. Create it where the root memcg is allocated, in
mem_cgroup_css_alloc(), instead: the function is __ref, and its root
branch runs once, from __init cgroup_init_subsys().
https://virtuozzo.atlassian.net/browse/VSTOR-144714
Feature: mm/shrinker: sparse per-memcg shrinker units
Assisted-by: LLM
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
Port of the mainline patch that moves the per-memcg shrinker_info_unit
from kmalloc-1k, where almost half of every unit is padding, to a cache
sized to the unit. Merged into mm-unstable as b36b71cb22027.
One adaptation: in 6.12 mem_cgroup_init() is a subsys_initcall and runs
after cgroup_init() has brought the root memcg online, so the cache is
created in mem_cgroup_css_alloc() where the root memcg is allocated.
https://virtuozzo.atlassian.net/browse/VSTOR-144714
---
include/linux/memcontrol.h | 1 +
mm/memcontrol.c | 1 +
mm/shrinker.c | 11 +++++++++--
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 2772a7750fa4e..e5b8ac79f6c7c 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1740,6 +1740,7 @@ static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
return false;
}
+void shrinker_unit_cache_init(void);
int alloc_shrinker_info(struct mem_cgroup *memcg);
void free_shrinker_info(struct mem_cgroup *memcg);
void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4e0c0c46689aa..0734c0fa21d05 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4393,6 +4393,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
#endif
page_counter_init(&memcg->cache, NULL, false);
+ shrinker_unit_cache_init();
root_mem_cgroup = memcg;
return &memcg->css;
}
diff --git a/mm/shrinker.c b/mm/shrinker.c
index a70074f7135a9..5e45b230a5ccf 100644
--- a/mm/shrinker.c
+++ b/mm/shrinker.c
@@ -12,6 +12,12 @@ DEFINE_MUTEX(shrinker_mutex);
#ifdef CONFIG_MEMCG
static int shrinker_nr_max;
+static struct kmem_cache *shrinker_unit_cachep;
+
+void __init shrinker_unit_cache_init(void)
+{
+ shrinker_unit_cachep = KMEM_CACHE(shrinker_info_unit, SLAB_PANIC);
+}
static inline int shrinker_unit_size(int nr_items)
{
@@ -33,7 +39,7 @@ static inline void shrinker_unit_free(struct shrinker_info *info, int start)
if (!unit[i])
break;
- kfree(unit[i]);
+ kmem_cache_free(shrinker_unit_cachep, unit[i]);
unit[i] = NULL;
}
}
@@ -47,7 +53,8 @@ static inline int shrinker_unit_alloc(struct shrinker_info *new,
int i;
for (i = start; i < nr; i++) {
- unit = kzalloc_node(sizeof(*unit), GFP_KERNEL, nid);
+ unit = kmem_cache_alloc_node(shrinker_unit_cachep,
+ GFP_KERNEL | __GFP_ZERO, nid);
if (!unit) {
shrinker_unit_free(new, start);
return -ENOMEM;
---
base-commit: ed6900fdc06c26a6b1dd37b4b4420157c9af0c95
change-id: 20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-d968e1813b70
Best regards,
--
Konstantin Khorenko <khorenko@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache
2026-10-20 15:12 [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache Konstantin Khorenko
@ 2026-10-20 15:15 ` no-reply
2026-10-20 15:30 ` Konstantin Khorenko
1 sibling, 0 replies; 3+ messages in thread
From: no-reply @ 2026-10-20 15:15 UTC (permalink / raw)
To: Vasileios Almpanis, Pavel Tikhomirov, Konstantin Khorenko, devel
> shrinker_info_unit holds BITS_PER_LONG atomic_long_t of deferred work plus
> a one-word bitmap, 520 bytes on 64-bit. kzalloc_node() takes it from
> kmalloc-1k, so almost half of every unit is padding.
>
> Allocate the units from a cache of their own, sized to the unit. The
> cache is not cache-line aligned: the counters of a unit already share
> cache lines between shrinkers, and aligning the unit would only keep
> neighbouring units off each other's boundary line, at the cost of part of
> the saving.
>
> Link: https://lore.kernel.org/20261019-vstor-144715-shrinker_info_unit-kmem_cache-v3-1-0fb061e09bf4@virtuozzo.com
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Suggested-by: Andrew Morton <akpm@linux-foundation.org>
> Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
> [ ... ]
> https://virtuozzo.atlassian.net/browse/VSTOR-144714
>
> Feature: mm/shrinker: sparse per-memcg shrinker units
> Assisted-by: LLM
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-v1-1-4bdb03031132@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache
2026-10-20 15:12 [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache Konstantin Khorenko
2026-10-20 15:15 ` no-reply
@ 2026-10-20 15:30 ` Konstantin Khorenko
1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Khorenko @ 2026-10-20 15:30 UTC (permalink / raw)
To: Pavel Tikhomirov, devel, Vasileios Almpanis, Konstantin Khorenko
On Tue, 20 Oct 2026 17:12:07 +0200, Konstantin Khorenko wrote:
> ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.9.vz10, thanks!
[1/1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/8a863d2a0c30
--
Konstantin Khorenko <khorenko@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-20 15:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 15:12 [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache Konstantin Khorenko
2026-10-20 15:15 ` no-reply
2026-10-20 15:30 ` Konstantin Khorenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.