Commit 6bc103498f5fe512928496fc7802d639cc2d1d20
1 parent
af36f906c0
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
cgroup: convert memcg controller to the new cftype interface
Convert memcg to use the new cftype based interface. kmem support abuses ->populate() for mem_cgroup_sockets_init() so it can't be removed at the moment. tcp_memcontrol is updated so that tcp_files[] is registered via a __initcall. This change also allows removing the forward declaration of tcp_files[]. Removed. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Li Zefan <lizf@cn.fujitsu.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Glauber Costa <glommer@parallels.com> Cc: Hugh Dickins <hughd@google.com> Cc: Greg Thelen <gthelen@google.com>
Showing 2 changed files with 13 additions and 15 deletions Side-by-side Diff
mm/memcontrol.c
... | ... | @@ -4764,6 +4764,7 @@ |
4764 | 4764 | .read = mem_cgroup_read, |
4765 | 4765 | }, |
4766 | 4766 | #endif |
4767 | + { }, /* terminate */ | |
4767 | 4768 | }; |
4768 | 4769 | |
4769 | 4770 | static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *memcg, int node) |
... | ... | @@ -5041,15 +5042,7 @@ |
5041 | 5042 | static int mem_cgroup_populate(struct cgroup_subsys *ss, |
5042 | 5043 | struct cgroup *cont) |
5043 | 5044 | { |
5044 | - int ret; | |
5045 | - | |
5046 | - ret = cgroup_add_files(cont, ss, mem_cgroup_files, | |
5047 | - ARRAY_SIZE(mem_cgroup_files)); | |
5048 | - | |
5049 | - if (!ret) | |
5050 | - ret = register_kmem_files(cont, ss); | |
5051 | - | |
5052 | - return ret; | |
5045 | + return register_kmem_files(cont, ss); | |
5053 | 5046 | } |
5054 | 5047 | |
5055 | 5048 | #ifdef CONFIG_MMU |
... | ... | @@ -5639,6 +5632,7 @@ |
5639 | 5632 | .can_attach = mem_cgroup_can_attach, |
5640 | 5633 | .cancel_attach = mem_cgroup_cancel_attach, |
5641 | 5634 | .attach = mem_cgroup_move_task, |
5635 | + .base_cftypes = mem_cgroup_files, | |
5642 | 5636 | .early_init = 0, |
5643 | 5637 | .use_id = 1, |
5644 | 5638 | }; |
net/ipv4/tcp_memcontrol.c
... | ... | @@ -6,8 +6,6 @@ |
6 | 6 | #include <linux/memcontrol.h> |
7 | 7 | #include <linux/module.h> |
8 | 8 | |
9 | -static struct cftype tcp_files[4]; /* XXX: will be removed soon */ | |
10 | - | |
11 | 9 | static inline struct tcp_memcontrol *tcp_from_cgproto(struct cg_proto *cg_proto) |
12 | 10 | { |
13 | 11 | return container_of(cg_proto, struct tcp_memcontrol, cg_proto); |
... | ... | @@ -36,7 +34,7 @@ |
36 | 34 | |
37 | 35 | cg_proto = tcp_prot.proto_cgroup(memcg); |
38 | 36 | if (!cg_proto) |
39 | - goto create_files; | |
37 | + return 0; | |
40 | 38 | |
41 | 39 | tcp = tcp_from_cgproto(cg_proto); |
42 | 40 | |
... | ... | @@ -59,9 +57,7 @@ |
59 | 57 | cg_proto->sockets_allocated = &tcp->tcp_sockets_allocated; |
60 | 58 | cg_proto->memcg = memcg; |
61 | 59 | |
62 | -create_files: | |
63 | - return cgroup_add_files(cgrp, ss, tcp_files, | |
64 | - ARRAY_SIZE(tcp_files)); | |
60 | + return 0; | |
65 | 61 | } |
66 | 62 | EXPORT_SYMBOL(tcp_init_cgroup); |
67 | 63 | |
68 | 64 | |
... | ... | @@ -266,5 +262,13 @@ |
266 | 262 | .trigger = tcp_cgroup_reset, |
267 | 263 | .read_u64 = tcp_cgroup_read, |
268 | 264 | }, |
265 | + { } /* terminate */ | |
269 | 266 | }; |
267 | + | |
268 | +static int __init tcp_memcontrol_init(void) | |
269 | +{ | |
270 | + WARN_ON(cgroup_add_cftypes(&mem_cgroup_subsys, tcp_files)); | |
271 | + return 0; | |
272 | +} | |
273 | +__initcall(tcp_memcontrol_init); |