mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache

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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Suggested-by: Andrew Morton <[email protected]>
Reviewed-by: Harry Yoo (Meta) <[email protected]>
Reviewed-by: Qi Zheng <[email protected]>
Acked-by: Muchun Song <[email protected]>
Assisted-by: LLM
Cc: Dave Chinner <[email protected]>
Cc: Roman Gushchin <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Shakeel Butt <[email protected]>
This commit is contained in:
Konstantin Khorenko
2026-10-24 01:56:41 -07:00
committed by Andrew Morton
parent bdda2887cb
commit faaf8b406c
3 changed files with 12 additions and 2 deletions
+1
View File
@@ -1717,6 +1717,7 @@ static inline u64 mem_cgroup_get_socket_pressure(const struct mem_cgroup *memcg)
}
#endif
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);
+2
View File
@@ -5984,6 +5984,8 @@ int __init mem_cgroup_init(void)
memcg_pn_cachep = KMEM_CACHE(mem_cgroup_per_node,
SLAB_PANIC | SLAB_HWCACHE_ALIGN);
shrinker_unit_cache_init();
return 0;
}
+9 -2
View File
@@ -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;