From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
devel@openvz.org, Konstantin Khorenko <khorenko@virtuozzo.com>,
Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
Subject: [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache
Date: Tue, 20 Oct 2026 17:12:07 +0200 [thread overview]
Message-ID: <20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-v1-1-4bdb03031132@virtuozzo.com> (raw)
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
next reply other threads:[~2026-10-20 15:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 15:12 Konstantin Khorenko [this message]
2026-10-20 15:15 ` no-reply
2026-10-20 15:30 ` Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-v1-1-4bdb03031132@virtuozzo.com \
--to=khorenko@virtuozzo.com \
--cc=devel@openvz.org \
--cc=ptikhomirov@virtuozzo.com \
--cc=vasileios.almpanis@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.