Skip to content

Commit 0db1529

Browse files
hnaztorvalds
authored andcommitted
mm: memcontrol: flatten struct cg_proto
There are no more external users of struct cg_proto, flatten the structure into struct mem_cgroup. Since using those struct members doesn't stand out as much anymore, add cgroup2 static branches to make it clearer which code is legacy. Suggested-by: Vladimir Davydov <[email protected]> Signed-off-by: Johannes Weiner <[email protected]> Acked-by: Vladimir Davydov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d886f4e commit 0db1529

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

include/linux/memcontrol.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ enum mem_cgroup_events_target {
8585
MEM_CGROUP_NTARGETS,
8686
};
8787

88-
struct cg_proto {
89-
struct page_counter memory_allocated; /* Current allocated memory. */
90-
int memory_pressure;
91-
bool active;
92-
};
93-
9488
#ifdef CONFIG_MEMCG
9589
struct mem_cgroup_stat_cpu {
9690
long count[MEM_CGROUP_STAT_NSTATS];
@@ -169,8 +163,11 @@ struct mem_cgroup {
169163

170164
/* Accounted resources */
171165
struct page_counter memory;
166+
167+
/* Legacy consumer-oriented counters */
172168
struct page_counter memsw;
173169
struct page_counter kmem;
170+
struct page_counter tcpmem;
174171

175172
/* Normal memory consumption range */
176173
unsigned long low;
@@ -236,7 +233,8 @@ struct mem_cgroup {
236233
unsigned long socket_pressure;
237234

238235
/* Legacy tcp memory accounting */
239-
struct cg_proto tcp_mem;
236+
bool tcpmem_active;
237+
int tcpmem_pressure;
240238

241239
#ifndef CONFIG_SLOB
242240
/* Index in the kmem_cache->memcg_params.memcg_caches array */
@@ -715,7 +713,7 @@ extern struct static_key_false memcg_sockets_enabled_key;
715713
#define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key)
716714
static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
717715
{
718-
if (memcg->tcp_mem.memory_pressure)
716+
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure)
719717
return true;
720718
do {
721719
if (time_before(jiffies, memcg->socket_pressure))

mm/memcontrol.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
28432843
counter = &memcg->kmem;
28442844
break;
28452845
case _TCP:
2846-
counter = &memcg->tcp_mem.memory_allocated;
2846+
counter = &memcg->tcpmem;
28472847
break;
28482848
default:
28492849
BUG();
@@ -3028,11 +3028,11 @@ static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
30283028

30293029
mutex_lock(&memcg_limit_mutex);
30303030

3031-
ret = page_counter_limit(&memcg->tcp_mem.memory_allocated, limit);
3031+
ret = page_counter_limit(&memcg->tcpmem, limit);
30323032
if (ret)
30333033
goto out;
30343034

3035-
if (!memcg->tcp_mem.active) {
3035+
if (!memcg->tcpmem_active) {
30363036
/*
30373037
* The active flag needs to be written after the static_key
30383038
* update. This is what guarantees that the socket activation
@@ -3050,7 +3050,7 @@ static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
30503050
* patched in yet.
30513051
*/
30523052
static_branch_inc(&memcg_sockets_enabled_key);
3053-
memcg->tcp_mem.active = true;
3053+
memcg->tcpmem_active = true;
30543054
}
30553055
out:
30563056
mutex_unlock(&memcg_limit_mutex);
@@ -3119,7 +3119,7 @@ static ssize_t mem_cgroup_reset(struct kernfs_open_file *of, char *buf,
31193119
counter = &memcg->kmem;
31203120
break;
31213121
case _TCP:
3122-
counter = &memcg->tcp_mem.memory_allocated;
3122+
counter = &memcg->tcpmem;
31233123
break;
31243124
default:
31253125
BUG();
@@ -4295,8 +4295,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
42954295
memcg->soft_limit = PAGE_COUNTER_MAX;
42964296
page_counter_init(&memcg->memsw, &parent->memsw);
42974297
page_counter_init(&memcg->kmem, &parent->kmem);
4298-
page_counter_init(&memcg->tcp_mem.memory_allocated,
4299-
&parent->tcp_mem.memory_allocated);
4298+
page_counter_init(&memcg->tcpmem, &parent->tcpmem);
43004299

43014300
/*
43024301
* No need to take a reference to the parent because cgroup
@@ -4308,7 +4307,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
43084307
memcg->soft_limit = PAGE_COUNTER_MAX;
43094308
page_counter_init(&memcg->memsw, NULL);
43104309
page_counter_init(&memcg->kmem, NULL);
4311-
page_counter_init(&memcg->tcp_mem.memory_allocated, NULL);
4310+
page_counter_init(&memcg->tcpmem, NULL);
43124311
/*
43134312
* Deeper hierachy with use_hierarchy == false doesn't make
43144313
* much sense so let cgroup subsystem know about this
@@ -4374,7 +4373,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
43744373
if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
43754374
static_branch_dec(&memcg_sockets_enabled_key);
43764375

4377-
if (memcg->tcp_mem.active)
4376+
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_active)
43784377
static_branch_dec(&memcg_sockets_enabled_key);
43794378

43804379
memcg_free_kmem(memcg);
@@ -5601,7 +5600,7 @@ void sock_update_memcg(struct sock *sk)
56015600
memcg = mem_cgroup_from_task(current);
56025601
if (memcg == root_mem_cgroup)
56035602
goto out;
5604-
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcp_mem.active)
5603+
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcpmem_active)
56055604
goto out;
56065605
if (css_tryget_online(&memcg->css))
56075606
sk->sk_memcg = memcg;
@@ -5629,15 +5628,14 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56295628
gfp_t gfp_mask = GFP_KERNEL;
56305629

56315630
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
5632-
struct page_counter *counter;
5631+
struct page_counter *fail;
56335632

5634-
if (page_counter_try_charge(&memcg->tcp_mem.memory_allocated,
5635-
nr_pages, &counter)) {
5636-
memcg->tcp_mem.memory_pressure = 0;
5633+
if (page_counter_try_charge(&memcg->tcpmem, nr_pages, &fail)) {
5634+
memcg->tcpmem_pressure = 0;
56375635
return true;
56385636
}
5639-
page_counter_charge(&memcg->tcp_mem.memory_allocated, nr_pages);
5640-
memcg->tcp_mem.memory_pressure = 1;
5637+
page_counter_charge(&memcg->tcpmem, nr_pages);
5638+
memcg->tcpmem_pressure = 1;
56415639
return false;
56425640
}
56435641

@@ -5660,8 +5658,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56605658
void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56615659
{
56625660
if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
5663-
page_counter_uncharge(&memcg->tcp_mem.memory_allocated,
5664-
nr_pages);
5661+
page_counter_uncharge(&memcg->tcpmem, nr_pages);
56655662
return;
56665663
}
56675664

0 commit comments

Comments
 (0)