aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2016-01-20 18:02:50 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-20 20:09:18 -0500
commit0db1529817b7b16226421f01470c5ba982c5f302 (patch)
tree435a441507f45135160c670af9d24e9681c8425c
parentd886f4e483ce63a3304adc9eda87031b93341c28 (diff)
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 <vdavydov@virtuozzo.com> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Vladimir Davydov <vdavydov@virtuozzo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/memcontrol.h14
-rw-r--r--mm/memcontrol.c33
2 files changed, 21 insertions, 26 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 47995b499429..a3869bf97746 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -85,12 +85,6 @@ enum mem_cgroup_events_target {
85 MEM_CGROUP_NTARGETS, 85 MEM_CGROUP_NTARGETS,
86}; 86};
87 87
88struct cg_proto {
89 struct page_counter memory_allocated; /* Current allocated memory. */
90 int memory_pressure;
91 bool active;
92};
93
94#ifdef CONFIG_MEMCG 88#ifdef CONFIG_MEMCG
95struct mem_cgroup_stat_cpu { 89struct mem_cgroup_stat_cpu {
96 long count[MEM_CGROUP_STAT_NSTATS]; 90 long count[MEM_CGROUP_STAT_NSTATS];
@@ -169,8 +163,11 @@ struct mem_cgroup {
169 163
170 /* Accounted resources */ 164 /* Accounted resources */
171 struct page_counter memory; 165 struct page_counter memory;
166
167 /* Legacy consumer-oriented counters */
172 struct page_counter memsw; 168 struct page_counter memsw;
173 struct page_counter kmem; 169 struct page_counter kmem;
170 struct page_counter tcpmem;
174 171
175 /* Normal memory consumption range */ 172 /* Normal memory consumption range */
176 unsigned long low; 173 unsigned long low;
@@ -236,7 +233,8 @@ struct mem_cgroup {
236 unsigned long socket_pressure; 233 unsigned long socket_pressure;
237 234
238 /* Legacy tcp memory accounting */ 235 /* Legacy tcp memory accounting */
239 struct cg_proto tcp_mem; 236 bool tcpmem_active;
237 int tcpmem_pressure;
240 238
241#ifndef CONFIG_SLOB 239#ifndef CONFIG_SLOB
242 /* Index in the kmem_cache->memcg_params.memcg_caches array */ 240 /* Index in the kmem_cache->memcg_params.memcg_caches array */
@@ -715,7 +713,7 @@ extern struct static_key_false memcg_sockets_enabled_key;
715#define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key) 713#define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key)
716static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) 714static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
717{ 715{
718 if (memcg->tcp_mem.memory_pressure) 716 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure)
719 return true; 717 return true;
720 do { 718 do {
721 if (time_before(jiffies, memcg->socket_pressure)) 719 if (time_before(jiffies, memcg->socket_pressure))
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 379f9911b87b..6937f16f5ecb 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2843,7 +2843,7 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
2843 counter = &memcg->kmem; 2843 counter = &memcg->kmem;
2844 break; 2844 break;
2845 case _TCP: 2845 case _TCP:
2846 counter = &memcg->tcp_mem.memory_allocated; 2846 counter = &memcg->tcpmem;
2847 break; 2847 break;
2848 default: 2848 default:
2849 BUG(); 2849 BUG();
@@ -3028,11 +3028,11 @@ static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
3028 3028
3029 mutex_lock(&memcg_limit_mutex); 3029 mutex_lock(&memcg_limit_mutex);
3030 3030
3031 ret = page_counter_limit(&memcg->tcp_mem.memory_allocated, limit); 3031 ret = page_counter_limit(&memcg->tcpmem, limit);
3032 if (ret) 3032 if (ret)
3033 goto out; 3033 goto out;
3034 3034
3035 if (!memcg->tcp_mem.active) { 3035 if (!memcg->tcpmem_active) {
3036 /* 3036 /*
3037 * The active flag needs to be written after the static_key 3037 * The active flag needs to be written after the static_key
3038 * update. This is what guarantees that the socket activation 3038 * 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)
3050 * patched in yet. 3050 * patched in yet.
3051 */ 3051 */
3052 static_branch_inc(&memcg_sockets_enabled_key); 3052 static_branch_inc(&memcg_sockets_enabled_key);
3053 memcg->tcp_mem.active = true; 3053 memcg->tcpmem_active = true;
3054 } 3054 }
3055out: 3055out:
3056 mutex_unlock(&memcg_limit_mutex); 3056 mutex_unlock(&memcg_limit_mutex);
@@ -3119,7 +3119,7 @@ static ssize_t mem_cgroup_reset(struct kernfs_open_file *of, char *buf,
3119 counter = &memcg->kmem; 3119 counter = &memcg->kmem;
3120 break; 3120 break;
3121 case _TCP: 3121 case _TCP:
3122 counter = &memcg->tcp_mem.memory_allocated; 3122 counter = &memcg->tcpmem;
3123 break; 3123 break;
3124 default: 3124 default:
3125 BUG(); 3125 BUG();
@@ -4295,8 +4295,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
4295 memcg->soft_limit = PAGE_COUNTER_MAX; 4295 memcg->soft_limit = PAGE_COUNTER_MAX;
4296 page_counter_init(&memcg->memsw, &parent->memsw); 4296 page_counter_init(&memcg->memsw, &parent->memsw);
4297 page_counter_init(&memcg->kmem, &parent->kmem); 4297 page_counter_init(&memcg->kmem, &parent->kmem);
4298 page_counter_init(&memcg->tcp_mem.memory_allocated, 4298 page_counter_init(&memcg->tcpmem, &parent->tcpmem);
4299 &parent->tcp_mem.memory_allocated);
4300 4299
4301 /* 4300 /*
4302 * No need to take a reference to the parent because cgroup 4301 * No need to take a reference to the parent because cgroup
@@ -4308,7 +4307,7 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
4308 memcg->soft_limit = PAGE_COUNTER_MAX; 4307 memcg->soft_limit = PAGE_COUNTER_MAX;
4309 page_counter_init(&memcg->memsw, NULL); 4308 page_counter_init(&memcg->memsw, NULL);
4310 page_counter_init(&memcg->kmem, NULL); 4309 page_counter_init(&memcg->kmem, NULL);
4311 page_counter_init(&memcg->tcp_mem.memory_allocated, NULL); 4310 page_counter_init(&memcg->tcpmem, NULL);
4312 /* 4311 /*
4313 * Deeper hierachy with use_hierarchy == false doesn't make 4312 * Deeper hierachy with use_hierarchy == false doesn't make
4314 * much sense so let cgroup subsystem know about this 4313 * much sense so let cgroup subsystem know about this
@@ -4374,7 +4373,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
4374 if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket) 4373 if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
4375 static_branch_dec(&memcg_sockets_enabled_key); 4374 static_branch_dec(&memcg_sockets_enabled_key);
4376 4375
4377 if (memcg->tcp_mem.active) 4376 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_active)
4378 static_branch_dec(&memcg_sockets_enabled_key); 4377 static_branch_dec(&memcg_sockets_enabled_key);
4379 4378
4380 memcg_free_kmem(memcg); 4379 memcg_free_kmem(memcg);
@@ -5601,7 +5600,7 @@ void sock_update_memcg(struct sock *sk)
5601 memcg = mem_cgroup_from_task(current); 5600 memcg = mem_cgroup_from_task(current);
5602 if (memcg == root_mem_cgroup) 5601 if (memcg == root_mem_cgroup)
5603 goto out; 5602 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)
5605 goto out; 5604 goto out;
5606 if (css_tryget_online(&memcg->css)) 5605 if (css_tryget_online(&memcg->css))
5607 sk->sk_memcg = memcg; 5606 sk->sk_memcg = memcg;
@@ -5629,15 +5628,14 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
5629 gfp_t gfp_mask = GFP_KERNEL; 5628 gfp_t gfp_mask = GFP_KERNEL;
5630 5629
5631 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { 5630 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
5632 struct page_counter *counter; 5631 struct page_counter *fail;
5633 5632
5634 if (page_counter_try_charge(&memcg->tcp_mem.memory_allocated, 5633 if (page_counter_try_charge(&memcg->tcpmem, nr_pages, &fail)) {
5635 nr_pages, &counter)) { 5634 memcg->tcpmem_pressure = 0;
5636 memcg->tcp_mem.memory_pressure = 0;
5637 return true; 5635 return true;
5638 } 5636 }
5639 page_counter_charge(&memcg->tcp_mem.memory_allocated, nr_pages); 5637 page_counter_charge(&memcg->tcpmem, nr_pages);
5640 memcg->tcp_mem.memory_pressure = 1; 5638 memcg->tcpmem_pressure = 1;
5641 return false; 5639 return false;
5642 } 5640 }
5643 5641
@@ -5660,8 +5658,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
5660void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) 5658void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
5661{ 5659{
5662 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) { 5660 if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
5663 page_counter_uncharge(&memcg->tcp_mem.memory_allocated, 5661 page_counter_uncharge(&memcg->tcpmem, nr_pages);
5664 nr_pages);
5665 return; 5662 return;
5666 } 5663 }
5667 5664