Skip to content

Commit d886f4e

Browse files
hnaztorvalds
authored andcommitted
mm: memcontrol: rein in the CONFIG space madness
What CONFIG_INET and CONFIG_LEGACY_KMEM guard inside the memory controller code is insignificant, having these conditionals is not worth the complication and fragility that comes with them. [[email protected]: rework mem_cgroup_css_free() statement ordering] Signed-off-by: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Acked-by: Vladimir Davydov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d55f90b commit d886f4e

File tree

4 files changed

+12
-78
lines changed

4 files changed

+12
-78
lines changed

include/linux/memcontrol.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,11 @@ struct mem_cgroup {
233233
*/
234234
struct mem_cgroup_stat_cpu __percpu *stat;
235235

236-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
236+
unsigned long socket_pressure;
237+
238+
/* Legacy tcp memory accounting */
237239
struct cg_proto tcp_mem;
238-
#endif
240+
239241
#ifndef CONFIG_SLOB
240242
/* Index in the kmem_cache->memcg_params.memcg_caches array */
241243
int kmemcg_id;
@@ -254,10 +256,6 @@ struct mem_cgroup {
254256
struct wb_domain cgwb_domain;
255257
#endif
256258

257-
#ifdef CONFIG_INET
258-
unsigned long socket_pressure;
259-
#endif
260-
261259
/* List of events which userspace want to receive */
262260
struct list_head event_list;
263261
spinlock_t event_list_lock;
@@ -712,15 +710,13 @@ void sock_update_memcg(struct sock *sk);
712710
void sock_release_memcg(struct sock *sk);
713711
bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
714712
void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
715-
#if defined(CONFIG_MEMCG) && defined(CONFIG_INET)
713+
#ifdef CONFIG_MEMCG
716714
extern struct static_key_false memcg_sockets_enabled_key;
717715
#define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key)
718716
static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
719717
{
720-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
721718
if (memcg->tcp_mem.memory_pressure)
722719
return true;
723-
#endif
724720
do {
725721
if (time_before(jiffies, memcg->socket_pressure))
726722
return true;

init/Kconfig

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -964,20 +964,6 @@ config MEMCG_SWAP_ENABLED
964964
For those who want to have the feature enabled by default should
965965
select this option (if, for some reason, they need to disable it
966966
then swapaccount=0 does the trick).
967-
config MEMCG_LEGACY_KMEM
968-
bool
969-
config MEMCG_KMEM
970-
bool "Legacy Memory Resource Controller Kernel Memory accounting"
971-
depends on MEMCG
972-
depends on SLUB || SLAB
973-
select MEMCG_LEGACY_KMEM
974-
help
975-
The Kernel Memory extension for Memory Resource Controller can limit
976-
the amount of memory used by kernel objects in the system. Those are
977-
fundamentally different from the entities handled by the standard
978-
Memory Controller, which are page-based, and can be swapped. Users of
979-
the kmem extension can use it to guarantee that no group of processes
980-
will ever exhaust kernel resources alone.
981967

982968
config BLK_CGROUP
983969
bool "IO controller"
@@ -1190,10 +1176,9 @@ config USER_NS
11901176
to provide different user info for different servers.
11911177

11921178
When user namespaces are enabled in the kernel it is
1193-
recommended that the MEMCG and MEMCG_KMEM options also be
1194-
enabled and that user-space use the memory control groups to
1195-
limit the amount of memory a memory unprivileged users can
1196-
use.
1179+
recommended that the MEMCG option also be enabled and that
1180+
user-space use the memory control groups to limit the amount
1181+
of memory a memory unprivileged users can use.
11971182

11981183
If unsure, say N.
11991184

mm/memcontrol.c

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,11 +2842,9 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
28422842
case _KMEM:
28432843
counter = &memcg->kmem;
28442844
break;
2845-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
28462845
case _TCP:
28472846
counter = &memcg->tcp_mem.memory_allocated;
28482847
break;
2849-
#endif
28502848
default:
28512849
BUG();
28522850
}
@@ -3006,7 +3004,6 @@ static void memcg_free_kmem(struct mem_cgroup *memcg)
30063004
}
30073005
#endif /* !CONFIG_SLOB */
30083006

3009-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
30103007
static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
30113008
unsigned long limit)
30123009
{
@@ -3024,16 +3021,7 @@ static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
30243021
mutex_unlock(&memcg_limit_mutex);
30253022
return ret;
30263023
}
3027-
#else
3028-
static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
3029-
unsigned long limit)
3030-
{
3031-
return -EINVAL;
3032-
}
3033-
#endif /* CONFIG_MEMCG_LEGACY_KMEM */
30343024

3035-
3036-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
30373025
static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
30383026
{
30393027
int ret;
@@ -3068,12 +3056,6 @@ static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
30683056
mutex_unlock(&memcg_limit_mutex);
30693057
return ret;
30703058
}
3071-
#else
3072-
static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
3073-
{
3074-
return -EINVAL;
3075-
}
3076-
#endif /* CONFIG_MEMCG_LEGACY_KMEM && CONFIG_INET */
30773059

30783060
/*
30793061
* The user of this function is...
@@ -3136,11 +3118,9 @@ static ssize_t mem_cgroup_reset(struct kernfs_open_file *of, char *buf,
31363118
case _KMEM:
31373119
counter = &memcg->kmem;
31383120
break;
3139-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
31403121
case _TCP:
31413122
counter = &memcg->tcp_mem.memory_allocated;
31423123
break;
3143-
#endif
31443124
default:
31453125
BUG();
31463126
}
@@ -4094,7 +4074,6 @@ static struct cftype mem_cgroup_legacy_files[] = {
40944074
.seq_show = memcg_numa_stat_show,
40954075
},
40964076
#endif
4097-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
40984077
{
40994078
.name = "kmem.limit_in_bytes",
41004079
.private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT),
@@ -4127,7 +4106,6 @@ static struct cftype mem_cgroup_legacy_files[] = {
41274106
.seq_show = memcg_slab_show,
41284107
},
41294108
#endif
4130-
#ifdef CONFIG_INET
41314109
{
41324110
.name = "kmem.tcp.limit_in_bytes",
41334111
.private = MEMFILE_PRIVATE(_TCP, RES_LIMIT),
@@ -4151,8 +4129,6 @@ static struct cftype mem_cgroup_legacy_files[] = {
41514129
.write = mem_cgroup_reset,
41524130
.read_u64 = mem_cgroup_read_u64,
41534131
},
4154-
#endif
4155-
#endif
41564132
{ }, /* terminate */
41574133
};
41584134

@@ -4280,14 +4256,12 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
42804256
vmpressure_init(&memcg->vmpressure);
42814257
INIT_LIST_HEAD(&memcg->event_list);
42824258
spin_lock_init(&memcg->event_list_lock);
4259+
memcg->socket_pressure = jiffies;
42834260
#ifndef CONFIG_SLOB
42844261
memcg->kmemcg_id = -1;
42854262
#endif
42864263
#ifdef CONFIG_CGROUP_WRITEBACK
42874264
INIT_LIST_HEAD(&memcg->cgwb_list);
4288-
#endif
4289-
#ifdef CONFIG_INET
4290-
memcg->socket_pressure = jiffies;
42914265
#endif
42924266
return &memcg->css;
42934267

@@ -4321,10 +4295,8 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
43214295
memcg->soft_limit = PAGE_COUNTER_MAX;
43224296
page_counter_init(&memcg->memsw, &parent->memsw);
43234297
page_counter_init(&memcg->kmem, &parent->kmem);
4324-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
43254298
page_counter_init(&memcg->tcp_mem.memory_allocated,
43264299
&parent->tcp_mem.memory_allocated);
4327-
#endif
43284300

43294301
/*
43304302
* No need to take a reference to the parent because cgroup
@@ -4336,9 +4308,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
43364308
memcg->soft_limit = PAGE_COUNTER_MAX;
43374309
page_counter_init(&memcg->memsw, NULL);
43384310
page_counter_init(&memcg->kmem, NULL);
4339-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
43404311
page_counter_init(&memcg->tcp_mem.memory_allocated, NULL);
4341-
#endif
43424312
/*
43434313
* Deeper hierachy with use_hierarchy == false doesn't make
43444314
* much sense so let cgroup subsystem know about this
@@ -4353,10 +4323,8 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
43534323
if (ret)
43544324
return ret;
43554325

4356-
#ifdef CONFIG_INET
43574326
if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
43584327
static_branch_inc(&memcg_sockets_enabled_key);
4359-
#endif
43604328

43614329
/*
43624330
* Make sure the memcg is initialized: mem_cgroup_iter()
@@ -4403,18 +4371,13 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
44034371
{
44044372
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
44054373

4406-
#ifdef CONFIG_INET
44074374
if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
44084375
static_branch_dec(&memcg_sockets_enabled_key);
4409-
#endif
4410-
4411-
memcg_free_kmem(memcg);
44124376

4413-
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
44144377
if (memcg->tcp_mem.active)
44154378
static_branch_dec(&memcg_sockets_enabled_key);
4416-
#endif
44174379

4380+
memcg_free_kmem(memcg);
44184381
__mem_cgroup_free(memcg);
44194382
}
44204383

@@ -5613,8 +5576,6 @@ void mem_cgroup_replace_page(struct page *oldpage, struct page *newpage)
56135576
commit_charge(newpage, memcg, true);
56145577
}
56155578

5616-
#ifdef CONFIG_INET
5617-
56185579
DEFINE_STATIC_KEY_FALSE(memcg_sockets_enabled_key);
56195580
EXPORT_SYMBOL(memcg_sockets_enabled_key);
56205581

@@ -5640,10 +5601,8 @@ void sock_update_memcg(struct sock *sk)
56405601
memcg = mem_cgroup_from_task(current);
56415602
if (memcg == root_mem_cgroup)
56425603
goto out;
5643-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
56445604
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcp_mem.active)
56455605
goto out;
5646-
#endif
56475606
if (css_tryget_online(&memcg->css))
56485607
sk->sk_memcg = memcg;
56495608
out:
@@ -5669,7 +5628,6 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56695628
{
56705629
gfp_t gfp_mask = GFP_KERNEL;
56715630

5672-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
56735631
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
56745632
struct page_counter *counter;
56755633

@@ -5682,7 +5640,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56825640
memcg->tcp_mem.memory_pressure = 1;
56835641
return false;
56845642
}
5685-
#endif
5643+
56865644
/* Don't block in the packet receive path */
56875645
if (in_softirq())
56885646
gfp_mask = GFP_NOWAIT;
@@ -5701,19 +5659,16 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
57015659
*/
57025660
void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
57035661
{
5704-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
57055662
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
57065663
page_counter_uncharge(&memcg->tcp_mem.memory_allocated,
57075664
nr_pages);
57085665
return;
57095666
}
5710-
#endif
5667+
57115668
page_counter_uncharge(&memcg->memory, nr_pages);
57125669
css_put_many(&memcg->css, nr_pages);
57135670
}
57145671

5715-
#endif /* CONFIG_INET */
5716-
57175672
static int __init cgroup_memory(char *s)
57185673
{
57195674
char *token;

mm/vmpressure.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
275275

276276
level = vmpressure_calc_level(scanned, reclaimed);
277277

278-
#ifdef CONFIG_INET
279278
if (level > VMPRESSURE_LOW) {
280279
/*
281280
* Let the socket buffer allocator know that
@@ -287,7 +286,6 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
287286
*/
288287
memcg->socket_pressure = jiffies + HZ;
289288
}
290-
#endif
291289
}
292290
}
293291

0 commit comments

Comments
 (0)