Skip to content

Commit d55f90b

Browse files
Vladimir Davydovtorvalds
authored andcommitted
net: drop tcp_memcontrol.c
tcp_memcontrol.c only contains legacy memory.tcp.kmem.* file definitions and mem_cgroup->tcp_mem init/destroy stuff. This doesn't belong to network subsys. Let's move it to memcontrol.c. This also allows us to reuse generic code for handling legacy memcg files. Signed-off-by: Vladimir Davydov <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: "David S. Miller" <[email protected]> Acked-by: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 489c2a2 commit d55f90b

File tree

7 files changed

+90
-222
lines changed

7 files changed

+90
-222
lines changed

include/net/tcp_memcontrol.h

Lines changed: 0 additions & 10 deletions
This file was deleted.

mm/memcontrol.c

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
#include "internal.h"
6767
#include <net/sock.h>
6868
#include <net/ip.h>
69-
#include <net/tcp_memcontrol.h>
7069
#include "slab.h"
7170

7271
#include <asm/uaccess.h>
@@ -242,6 +241,7 @@ enum res_type {
242241
_MEMSWAP,
243242
_OOM_TYPE,
244243
_KMEM,
244+
_TCP,
245245
};
246246

247247
#define MEMFILE_PRIVATE(x, val) ((x) << 16 | (val))
@@ -2842,6 +2842,11 @@ 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)
2846+
case _TCP:
2847+
counter = &memcg->tcp_mem.memory_allocated;
2848+
break;
2849+
#endif
28452850
default:
28462851
BUG();
28472852
}
@@ -3028,6 +3033,48 @@ static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
30283033
#endif /* CONFIG_MEMCG_LEGACY_KMEM */
30293034

30303035

3036+
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
3037+
static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
3038+
{
3039+
int ret;
3040+
3041+
mutex_lock(&memcg_limit_mutex);
3042+
3043+
ret = page_counter_limit(&memcg->tcp_mem.memory_allocated, limit);
3044+
if (ret)
3045+
goto out;
3046+
3047+
if (!memcg->tcp_mem.active) {
3048+
/*
3049+
* The active flag needs to be written after the static_key
3050+
* update. This is what guarantees that the socket activation
3051+
* function is the last one to run. See sock_update_memcg() for
3052+
* details, and note that we don't mark any socket as belonging
3053+
* to this memcg until that flag is up.
3054+
*
3055+
* We need to do this, because static_keys will span multiple
3056+
* sites, but we can't control their order. If we mark a socket
3057+
* as accounted, but the accounting functions are not patched in
3058+
* yet, we'll lose accounting.
3059+
*
3060+
* We never race with the readers in sock_update_memcg(),
3061+
* because when this value change, the code to process it is not
3062+
* patched in yet.
3063+
*/
3064+
static_branch_inc(&memcg_sockets_enabled_key);
3065+
memcg->tcp_mem.active = true;
3066+
}
3067+
out:
3068+
mutex_unlock(&memcg_limit_mutex);
3069+
return ret;
3070+
}
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 */
3077+
30313078
/*
30323079
* The user of this function is...
30333080
* RES_LIMIT.
@@ -3060,6 +3107,9 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
30603107
case _KMEM:
30613108
ret = memcg_update_kmem_limit(memcg, nr_pages);
30623109
break;
3110+
case _TCP:
3111+
ret = memcg_update_tcp_limit(memcg, nr_pages);
3112+
break;
30633113
}
30643114
break;
30653115
case RES_SOFT_LIMIT:
@@ -3086,6 +3136,11 @@ static ssize_t mem_cgroup_reset(struct kernfs_open_file *of, char *buf,
30863136
case _KMEM:
30873137
counter = &memcg->kmem;
30883138
break;
3139+
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
3140+
case _TCP:
3141+
counter = &memcg->tcp_mem.memory_allocated;
3142+
break;
3143+
#endif
30893144
default:
30903145
BUG();
30913146
}
@@ -4072,6 +4127,31 @@ static struct cftype mem_cgroup_legacy_files[] = {
40724127
.seq_show = memcg_slab_show,
40734128
},
40744129
#endif
4130+
#ifdef CONFIG_INET
4131+
{
4132+
.name = "kmem.tcp.limit_in_bytes",
4133+
.private = MEMFILE_PRIVATE(_TCP, RES_LIMIT),
4134+
.write = mem_cgroup_write,
4135+
.read_u64 = mem_cgroup_read_u64,
4136+
},
4137+
{
4138+
.name = "kmem.tcp.usage_in_bytes",
4139+
.private = MEMFILE_PRIVATE(_TCP, RES_USAGE),
4140+
.read_u64 = mem_cgroup_read_u64,
4141+
},
4142+
{
4143+
.name = "kmem.tcp.failcnt",
4144+
.private = MEMFILE_PRIVATE(_TCP, RES_FAILCNT),
4145+
.write = mem_cgroup_reset,
4146+
.read_u64 = mem_cgroup_read_u64,
4147+
},
4148+
{
4149+
.name = "kmem.tcp.max_usage_in_bytes",
4150+
.private = MEMFILE_PRIVATE(_TCP, RES_MAX_USAGE),
4151+
.write = mem_cgroup_reset,
4152+
.read_u64 = mem_cgroup_read_u64,
4153+
},
4154+
#endif
40754155
#endif
40764156
{ }, /* terminate */
40774157
};
@@ -4241,6 +4321,10 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
42414321
memcg->soft_limit = PAGE_COUNTER_MAX;
42424322
page_counter_init(&memcg->memsw, &parent->memsw);
42434323
page_counter_init(&memcg->kmem, &parent->kmem);
4324+
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
4325+
page_counter_init(&memcg->tcp_mem.memory_allocated,
4326+
&parent->tcp_mem.memory_allocated);
4327+
#endif
42444328

42454329
/*
42464330
* No need to take a reference to the parent because cgroup
@@ -4252,6 +4336,9 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
42524336
memcg->soft_limit = PAGE_COUNTER_MAX;
42534337
page_counter_init(&memcg->memsw, NULL);
42544338
page_counter_init(&memcg->kmem, NULL);
4339+
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
4340+
page_counter_init(&memcg->tcp_mem.memory_allocated, NULL);
4341+
#endif
42554342
/*
42564343
* Deeper hierachy with use_hierarchy == false doesn't make
42574344
* much sense so let cgroup subsystem know about this
@@ -4267,12 +4354,6 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
42674354
return ret;
42684355

42694356
#ifdef CONFIG_INET
4270-
#ifdef CONFIG_MEMCG_LEGACY_KMEM
4271-
ret = tcp_init_cgroup(memcg);
4272-
if (ret)
4273-
return ret;
4274-
#endif
4275-
42764357
if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
42774358
static_branch_inc(&memcg_sockets_enabled_key);
42784359
#endif
@@ -4330,7 +4411,8 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
43304411
memcg_free_kmem(memcg);
43314412

43324413
#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
4333-
tcp_destroy_cgroup(memcg);
4414+
if (memcg->tcp_mem.active)
4415+
static_branch_dec(&memcg_sockets_enabled_key);
43344416
#endif
43354417

43364418
__mem_cgroup_free(memcg);

net/ipv4/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
5656
obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o
5757
obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
5858
obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
59-
obj-$(CONFIG_MEMCG_LEGACY_KMEM) += tcp_memcontrol.o
6059
obj-$(CONFIG_NETLABEL) += cipso_ipv4.o
6160

6261
obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \

net/ipv4/sysctl_net_ipv4.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <net/cipso_ipv4.h>
2525
#include <net/inet_frag.h>
2626
#include <net/ping.h>
27-
#include <net/tcp_memcontrol.h>
2827

2928
static int zero;
3029
static int one = 1;

net/ipv4/tcp_ipv4.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
#include <net/timewait_sock.h>
7474
#include <net/xfrm.h>
7575
#include <net/secure_seq.h>
76-
#include <net/tcp_memcontrol.h>
7776
#include <net/busy_poll.h>
7877

7978
#include <linux/inet.h>

0 commit comments

Comments
 (0)