mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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 <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>
This commit is contained in:
parent
bdda2887cb
commit
faaf8b406c
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user