Skip to content

Commit 3a3b7fe

Browse files
hnazakpm00
authored andcommitted
mm: remove CONFIG_MEMCG_KMEM
CONFIG_MEMCG_KMEM used to be a user-visible option for whether slab tracking is enabled. It has been default-enabled and equivalent to CONFIG_MEMCG for almost a decade. We've only grown more kernel memory accounting sites since, and there is no imaginable cgroup usecase going forward that wants to track user pages but not the multitude of user-drivable kernel allocations. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Johannes Weiner <[email protected]> Acked-by: Roman Gushchin <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Shakeel Butt <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6df1323 commit 3a3b7fe

File tree

20 files changed

+59
-131
lines changed

20 files changed

+59
-131
lines changed

include/linux/bpf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ struct bpf_map {
275275
u32 btf_value_type_id;
276276
u32 btf_vmlinux_value_type_id;
277277
struct btf *btf;
278-
#ifdef CONFIG_MEMCG_KMEM
278+
#ifdef CONFIG_MEMCG
279279
struct obj_cgroup *objcg;
280280
#endif
281281
char name[BPF_OBJ_NAME_LEN];
@@ -2252,7 +2252,7 @@ struct bpf_prog *bpf_prog_get_curr_or_next(u32 *id);
22522252

22532253
int bpf_map_alloc_pages(const struct bpf_map *map, gfp_t gfp, int nid,
22542254
unsigned long nr_pages, struct page **page_array);
2255-
#ifdef CONFIG_MEMCG_KMEM
2255+
#ifdef CONFIG_MEMCG
22562256
void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags,
22572257
int node);
22582258
void *bpf_map_kzalloc(const struct bpf_map *map, size_t size, gfp_t flags);

include/linux/list_lru.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct list_lru_node {
5050

5151
struct list_lru {
5252
struct list_lru_node *node;
53-
#ifdef CONFIG_MEMCG_KMEM
53+
#ifdef CONFIG_MEMCG
5454
struct list_head list;
5555
int shrinker_id;
5656
bool memcg_aware;

include/linux/memcontrol.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct mem_cgroup {
195195
/* Range enforcement for interrupt charges */
196196
struct work_struct high_work;
197197

198-
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
198+
#ifdef CONFIG_ZSWAP
199199
unsigned long zswap_max;
200200

201201
/*
@@ -236,7 +236,6 @@ struct mem_cgroup {
236236
*/
237237
unsigned long socket_pressure;
238238

239-
#ifdef CONFIG_MEMCG_KMEM
240239
int kmemcg_id;
241240
/*
242241
* memcg->objcg is wiped out as a part of the objcg repaprenting
@@ -247,7 +246,6 @@ struct mem_cgroup {
247246
struct obj_cgroup *orig_objcg;
248247
/* list of inherited objcgs, protected by objcg_lock */
249248
struct list_head objcg_list;
250-
#endif
251249

252250
struct memcg_vmstats_percpu __percpu *vmstats_percpu;
253251

@@ -532,7 +530,6 @@ static inline struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *ob
532530
return memcg;
533531
}
534532

535-
#ifdef CONFIG_MEMCG_KMEM
536533
/*
537534
* folio_memcg_kmem - Check if the folio has the memcg_kmem flag set.
538535
* @folio: Pointer to the folio.
@@ -548,15 +545,6 @@ static inline bool folio_memcg_kmem(struct folio *folio)
548545
return folio->memcg_data & MEMCG_DATA_KMEM;
549546
}
550547

551-
552-
#else
553-
static inline bool folio_memcg_kmem(struct folio *folio)
554-
{
555-
return false;
556-
}
557-
558-
#endif
559-
560548
static inline bool PageMemcgKmem(struct page *page)
561549
{
562550
return folio_memcg_kmem(page_folio(page));
@@ -1488,7 +1476,7 @@ static inline void split_page_memcg(struct page *head, int old_order, int new_or
14881476
* if MEMCG_DATA_OBJEXTS is set.
14891477
*/
14901478
struct slabobj_ext {
1491-
#ifdef CONFIG_MEMCG_KMEM
1479+
#ifdef CONFIG_MEMCG
14921480
struct obj_cgroup *objcg;
14931481
#endif
14941482
#ifdef CONFIG_MEM_ALLOC_PROFILING
@@ -1663,7 +1651,7 @@ static inline void set_shrinker_bit(struct mem_cgroup *memcg,
16631651
}
16641652
#endif
16651653

1666-
#ifdef CONFIG_MEMCG_KMEM
1654+
#ifdef CONFIG_MEMCG
16671655
bool mem_cgroup_kmem_disabled(void);
16681656
int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order);
16691657
void __memcg_kmem_uncharge_page(struct page *page, int order);
@@ -1806,9 +1794,9 @@ static inline void count_objcg_event(struct obj_cgroup *objcg,
18061794
{
18071795
}
18081796

1809-
#endif /* CONFIG_MEMCG_KMEM */
1797+
#endif /* CONFIG_MEMCG */
18101798

1811-
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP)
1799+
#if defined(CONFIG_MEMCG) && defined(CONFIG_ZSWAP)
18121800
bool obj_cgroup_may_zswap(struct obj_cgroup *objcg);
18131801
void obj_cgroup_charge_zswap(struct obj_cgroup *objcg, size_t size);
18141802
void obj_cgroup_uncharge_zswap(struct obj_cgroup *objcg, size_t size);

include/linux/sched.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,8 @@ struct task_struct {
14571457

14581458
/* Used by memcontrol for targeted memcg charge: */
14591459
struct mem_cgroup *active_memcg;
1460-
#endif
14611460

1462-
#ifdef CONFIG_MEMCG_KMEM
1461+
/* Cache for current->cgroups->memcg->objcg lookups: */
14631462
struct obj_cgroup *objcg;
14641463
#endif
14651464

include/linux/slab.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ enum _slab_flag_bits {
4141
#ifdef CONFIG_FAILSLAB
4242
_SLAB_FAILSLAB,
4343
#endif
44-
#ifdef CONFIG_MEMCG_KMEM
44+
#ifdef CONFIG_MEMCG
4545
_SLAB_ACCOUNT,
4646
#endif
4747
#ifdef CONFIG_KASAN_GENERIC
@@ -171,7 +171,7 @@ enum _slab_flag_bits {
171171
# define SLAB_FAILSLAB __SLAB_FLAG_UNUSED
172172
#endif
173173
/* Account to memcg */
174-
#ifdef CONFIG_MEMCG_KMEM
174+
#ifdef CONFIG_MEMCG
175175
# define SLAB_ACCOUNT __SLAB_FLAG_BIT(_SLAB_ACCOUNT)
176176
#else
177177
# define SLAB_ACCOUNT __SLAB_FLAG_UNUSED
@@ -407,7 +407,7 @@ enum kmalloc_cache_type {
407407
#ifndef CONFIG_ZONE_DMA
408408
KMALLOC_DMA = KMALLOC_NORMAL,
409409
#endif
410-
#ifndef CONFIG_MEMCG_KMEM
410+
#ifndef CONFIG_MEMCG
411411
KMALLOC_CGROUP = KMALLOC_NORMAL,
412412
#endif
413413
KMALLOC_RANDOM_START = KMALLOC_NORMAL,
@@ -420,7 +420,7 @@ enum kmalloc_cache_type {
420420
#ifdef CONFIG_ZONE_DMA
421421
KMALLOC_DMA,
422422
#endif
423-
#ifdef CONFIG_MEMCG_KMEM
423+
#ifdef CONFIG_MEMCG
424424
KMALLOC_CGROUP,
425425
#endif
426426
NR_KMALLOC_TYPES
@@ -435,7 +435,7 @@ kmalloc_caches[NR_KMALLOC_TYPES][KMALLOC_SHIFT_HIGH + 1];
435435
#define KMALLOC_NOT_NORMAL_BITS \
436436
(__GFP_RECLAIMABLE | \
437437
(IS_ENABLED(CONFIG_ZONE_DMA) ? __GFP_DMA : 0) | \
438-
(IS_ENABLED(CONFIG_MEMCG_KMEM) ? __GFP_ACCOUNT : 0))
438+
(IS_ENABLED(CONFIG_MEMCG) ? __GFP_ACCOUNT : 0))
439439

440440
extern unsigned long random_kmalloc_seed;
441441

@@ -463,7 +463,7 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags, unsigne
463463
*/
464464
if (IS_ENABLED(CONFIG_ZONE_DMA) && (flags & __GFP_DMA))
465465
return KMALLOC_DMA;
466-
if (!IS_ENABLED(CONFIG_MEMCG_KMEM) || (flags & __GFP_RECLAIMABLE))
466+
if (!IS_ENABLED(CONFIG_MEMCG) || (flags & __GFP_RECLAIMABLE))
467467
return KMALLOC_RECLAIM;
468468
else
469469
return KMALLOC_CGROUP;

include/trace/events/kmem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TRACE_EVENT(kmem_cache_alloc,
3636
__entry->bytes_alloc = s->size;
3737
__entry->gfp_flags = (__force unsigned long)gfp_flags;
3838
__entry->node = node;
39-
__entry->accounted = IS_ENABLED(CONFIG_MEMCG_KMEM) ?
39+
__entry->accounted = IS_ENABLED(CONFIG_MEMCG) ?
4040
((gfp_flags & __GFP_ACCOUNT) ||
4141
(s->flags & SLAB_ACCOUNT)) : false;
4242
),
@@ -87,7 +87,7 @@ TRACE_EVENT(kmalloc,
8787
__entry->bytes_alloc,
8888
show_gfp_flags(__entry->gfp_flags),
8989
__entry->node,
90-
(IS_ENABLED(CONFIG_MEMCG_KMEM) &&
90+
(IS_ENABLED(CONFIG_MEMCG) &&
9191
(__entry->gfp_flags & (__force unsigned long)__GFP_ACCOUNT)) ? "true" : "false")
9292
);
9393

init/Kconfig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,11 +986,6 @@ config MEMCG_V1
986986

987987
San N is unsure.
988988

989-
config MEMCG_KMEM
990-
bool
991-
depends on MEMCG
992-
default y
993-
994989
config BLK_CGROUP
995990
bool "IO controller"
996991
depends on BLOCK

kernel/bpf/memalloc.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,9 @@ static void *__alloc(struct bpf_mem_cache *c, int node, gfp_t flags)
155155

156156
static struct mem_cgroup *get_memcg(const struct bpf_mem_cache *c)
157157
{
158-
#ifdef CONFIG_MEMCG_KMEM
158+
#ifdef CONFIG_MEMCG
159159
if (c->objcg)
160160
return get_mem_cgroup_from_objcg(c->objcg);
161-
#endif
162-
163-
#ifdef CONFIG_MEMCG
164161
return root_mem_cgroup;
165162
#else
166163
return NULL;
@@ -534,7 +531,7 @@ int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu)
534531
size += LLIST_NODE_SZ; /* room for llist_node */
535532
unit_size = size;
536533

537-
#ifdef CONFIG_MEMCG_KMEM
534+
#ifdef CONFIG_MEMCG
538535
if (memcg_bpf_enabled())
539536
objcg = get_obj_cgroup_from_current();
540537
#endif
@@ -556,7 +553,7 @@ int bpf_mem_alloc_init(struct bpf_mem_alloc *ma, int size, bool percpu)
556553
pcc = __alloc_percpu_gfp(sizeof(*cc), 8, GFP_KERNEL);
557554
if (!pcc)
558555
return -ENOMEM;
559-
#ifdef CONFIG_MEMCG_KMEM
556+
#ifdef CONFIG_MEMCG
560557
objcg = get_obj_cgroup_from_current();
561558
#endif
562559
ma->objcg = objcg;

kernel/bpf/syscall.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void bpf_map_free_id(struct bpf_map *map)
385385
spin_unlock_irqrestore(&map_idr_lock, flags);
386386
}
387387

388-
#ifdef CONFIG_MEMCG_KMEM
388+
#ifdef CONFIG_MEMCG
389389
static void bpf_map_save_memcg(struct bpf_map *map)
390390
{
391391
/* Currently if a map is created by a process belonging to the root
@@ -486,7 +486,7 @@ int bpf_map_alloc_pages(const struct bpf_map *map, gfp_t gfp, int nid,
486486
unsigned long i, j;
487487
struct page *pg;
488488
int ret = 0;
489-
#ifdef CONFIG_MEMCG_KMEM
489+
#ifdef CONFIG_MEMCG
490490
struct mem_cgroup *memcg, *old_memcg;
491491

492492
memcg = bpf_map_get_memcg(map);
@@ -505,7 +505,7 @@ int bpf_map_alloc_pages(const struct bpf_map *map, gfp_t gfp, int nid,
505505
break;
506506
}
507507

508-
#ifdef CONFIG_MEMCG_KMEM
508+
#ifdef CONFIG_MEMCG
509509
set_active_memcg(old_memcg);
510510
mem_cgroup_put(memcg);
511511
#endif

mm/kfence/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static unsigned long kfence_init_pool(void)
602602
continue;
603603

604604
__folio_set_slab(slab_folio(slab));
605-
#ifdef CONFIG_MEMCG_KMEM
605+
#ifdef CONFIG_MEMCG
606606
slab->obj_exts = (unsigned long)&kfence_metadata_init[i / 2 - 1].obj_exts |
607607
MEMCG_DATA_OBJEXTS;
608608
#endif
@@ -652,7 +652,7 @@ static unsigned long kfence_init_pool(void)
652652

653653
if (!i || (i % 2))
654654
continue;
655-
#ifdef CONFIG_MEMCG_KMEM
655+
#ifdef CONFIG_MEMCG
656656
slab->obj_exts = 0;
657657
#endif
658658
__folio_clear_slab(slab_folio(slab));
@@ -1146,7 +1146,7 @@ void __kfence_free(void *addr)
11461146
{
11471147
struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr);
11481148

1149-
#ifdef CONFIG_MEMCG_KMEM
1149+
#ifdef CONFIG_MEMCG
11501150
KFENCE_WARN_ON(meta->obj_exts.objcg);
11511151
#endif
11521152
/*

mm/kfence/kfence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct kfence_metadata {
9797
struct kfence_track free_track;
9898
/* For updating alloc_covered on frees. */
9999
u32 alloc_stack_hash;
100-
#ifdef CONFIG_MEMCG_KMEM
100+
#ifdef CONFIG_MEMCG
101101
struct slabobj_ext obj_exts;
102102
#endif
103103
};

mm/list_lru.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "slab.h"
1616
#include "internal.h"
1717

18-
#ifdef CONFIG_MEMCG_KMEM
18+
#ifdef CONFIG_MEMCG
1919
static LIST_HEAD(memcg_list_lrus);
2020
static DEFINE_MUTEX(list_lrus_mutex);
2121

@@ -83,7 +83,7 @@ list_lru_from_memcg_idx(struct list_lru *lru, int nid, int idx)
8383
{
8484
return &lru->node[nid].lru;
8585
}
86-
#endif /* CONFIG_MEMCG_KMEM */
86+
#endif /* CONFIG_MEMCG */
8787

8888
bool list_lru_add(struct list_lru *lru, struct list_head *item, int nid,
8989
struct mem_cgroup *memcg)
@@ -294,7 +294,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid,
294294
isolated += list_lru_walk_one(lru, nid, NULL, isolate, cb_arg,
295295
nr_to_walk);
296296

297-
#ifdef CONFIG_MEMCG_KMEM
297+
#ifdef CONFIG_MEMCG
298298
if (*nr_to_walk > 0 && list_lru_memcg_aware(lru)) {
299299
struct list_lru_memcg *mlru;
300300
unsigned long index;
@@ -324,7 +324,7 @@ static void init_one_lru(struct list_lru_one *l)
324324
l->nr_items = 0;
325325
}
326326

327-
#ifdef CONFIG_MEMCG_KMEM
327+
#ifdef CONFIG_MEMCG
328328
static struct list_lru_memcg *memcg_init_list_lru_one(gfp_t gfp)
329329
{
330330
int nid;
@@ -544,14 +544,14 @@ static inline void memcg_init_list_lru(struct list_lru *lru, bool memcg_aware)
544544
static void memcg_destroy_list_lru(struct list_lru *lru)
545545
{
546546
}
547-
#endif /* CONFIG_MEMCG_KMEM */
547+
#endif /* CONFIG_MEMCG */
548548

549549
int __list_lru_init(struct list_lru *lru, bool memcg_aware,
550550
struct lock_class_key *key, struct shrinker *shrinker)
551551
{
552552
int i;
553553

554-
#ifdef CONFIG_MEMCG_KMEM
554+
#ifdef CONFIG_MEMCG
555555
if (shrinker)
556556
lru->shrinker_id = shrinker->id;
557557
else
@@ -591,7 +591,7 @@ void list_lru_destroy(struct list_lru *lru)
591591
kfree(lru->node);
592592
lru->node = NULL;
593593

594-
#ifdef CONFIG_MEMCG_KMEM
594+
#ifdef CONFIG_MEMCG
595595
lru->shrinker_id = -1;
596596
#endif
597597
}

mm/memcontrol-v1.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,7 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css,
27562756
return 0;
27572757
}
27582758

2759-
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_SLUB_DEBUG)
2759+
#ifdef CONFIG_SLUB_DEBUG
27602760
static int mem_cgroup_slab_show(struct seq_file *m, void *p)
27612761
{
27622762
/*
@@ -2863,7 +2863,7 @@ struct cftype mem_cgroup_legacy_files[] = {
28632863
.write = mem_cgroup_reset,
28642864
.read_u64 = mem_cgroup_read_u64,
28652865
},
2866-
#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_SLUB_DEBUG)
2866+
#ifdef CONFIG_SLUB_DEBUG
28672867
{
28682868
.name = "kmem.slabinfo",
28692869
.seq_show = mem_cgroup_slab_show,
@@ -2922,7 +2922,6 @@ struct cftype memsw_files[] = {
29222922
{ }, /* terminate */
29232923
};
29242924

2925-
#ifdef CONFIG_MEMCG_KMEM
29262925
void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages)
29272926
{
29282927
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
@@ -2932,7 +2931,6 @@ void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages)
29322931
page_counter_uncharge(&memcg->kmem, -nr_pages);
29332932
}
29342933
}
2935-
#endif /* CONFIG_MEMCG_KMEM */
29362934

29372935
bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
29382936
gfp_t gfp_mask)

0 commit comments

Comments
 (0)