aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-08 20:11:24 -0400
committerTejun Heo <tj@kernel.org>2013-08-08 20:11:24 -0400
commit182446d087906de40e514573a92a97b203695f71 (patch)
tree6aee96219c82d0a64b9d389c50666c1ce0ec27ee /mm/memcontrol.c
parent67f4c36f83455b253445b2cb28ac9a2c4f85d99a (diff)
cgroup: pass around cgroup_subsys_state instead of cgroup in file methods
cgroup is currently in the process of transitioning to using struct cgroup_subsys_state * as the primary handle instead of struct cgroup. Please see the previous commit which converts the subsystem methods for rationale. This patch converts all cftype file operations to take @css instead of @cgroup. cftypes for the cgroup core files don't have their subsytem pointer set. These will automatically use the dummy_css added by the previous patch and can be converted the same way. Most subsystem conversions are straight forwards but there are some interesting ones. * freezer: update_if_frozen() is also converted to take @css instead of @cgroup for consistency. This will make the code look simpler too once iterators are converted to use css. * memory/vmpressure: mem_cgroup_from_css() needs to be exported to vmpressure while mem_cgroup_from_cont() can be made static. Updated accordingly. * cpu: cgroup_tg() doesn't have any user left. Removed. * cpuacct: cgroup_ca() doesn't have any user left. Removed. * hugetlb: hugetlb_cgroup_form_cgroup() doesn't have any user left. Removed. * net_cls: cgrp_cls_state() doesn't have any user left. Removed. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Aristeu Rozanski <aris@redhat.com> Acked-by: Daniel Wagner <daniel.wagner@bmw-carit.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r--mm/memcontrol.c88
1 files changed, 45 insertions, 43 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 32cca0f0af0d..ab64dfc84f8c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -483,7 +483,6 @@ enum res_type {
483 */ 483 */
484static DEFINE_MUTEX(memcg_create_mutex); 484static DEFINE_MUTEX(memcg_create_mutex);
485 485
486static inline
487struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s) 486struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
488{ 487{
489 return s ? container_of(s, struct mem_cgroup, css) : NULL; 488 return s ? container_of(s, struct mem_cgroup, css) : NULL;
@@ -1035,7 +1034,7 @@ static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
1035 preempt_enable(); 1034 preempt_enable();
1036} 1035}
1037 1036
1038struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) 1037static inline struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
1039{ 1038{
1040 return mem_cgroup_from_css(cgroup_css(cont, mem_cgroup_subsys_id)); 1039 return mem_cgroup_from_css(cgroup_css(cont, mem_cgroup_subsys_id));
1041} 1040}
@@ -2951,10 +2950,10 @@ static struct kmem_cache *memcg_params_to_cache(struct memcg_cache_params *p)
2951} 2950}
2952 2951
2953#ifdef CONFIG_SLABINFO 2952#ifdef CONFIG_SLABINFO
2954static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, 2953static int mem_cgroup_slabinfo_read(struct cgroup_subsys_state *css,
2955 struct seq_file *m) 2954 struct cftype *cft, struct seq_file *m)
2956{ 2955{
2957 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 2956 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
2958 struct memcg_cache_params *params; 2957 struct memcg_cache_params *params;
2959 2958
2960 if (!memcg_can_account_kmem(memcg)) 2959 if (!memcg_can_account_kmem(memcg))
@@ -4999,9 +4998,10 @@ static int mem_cgroup_force_empty(struct mem_cgroup *memcg)
4999 return 0; 4998 return 0;
5000} 4999}
5001 5000
5002static int mem_cgroup_force_empty_write(struct cgroup *cont, unsigned int event) 5001static int mem_cgroup_force_empty_write(struct cgroup_subsys_state *css,
5002 unsigned int event)
5003{ 5003{
5004 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5004 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5005 int ret; 5005 int ret;
5006 5006
5007 if (mem_cgroup_is_root(memcg)) 5007 if (mem_cgroup_is_root(memcg))
@@ -5014,16 +5014,17 @@ static int mem_cgroup_force_empty_write(struct cgroup *cont, unsigned int event)
5014} 5014}
5015 5015
5016 5016
5017static u64 mem_cgroup_hierarchy_read(struct cgroup *cont, struct cftype *cft) 5017static u64 mem_cgroup_hierarchy_read(struct cgroup_subsys_state *css,
5018 struct cftype *cft)
5018{ 5019{
5019 return mem_cgroup_from_cont(cont)->use_hierarchy; 5020 return mem_cgroup_from_css(css)->use_hierarchy;
5020} 5021}
5021 5022
5022static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, 5023static int mem_cgroup_hierarchy_write(struct cgroup_subsys_state *css,
5023 u64 val) 5024 struct cftype *cft, u64 val)
5024{ 5025{
5025 int retval = 0; 5026 int retval = 0;
5026 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5027 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5027 struct mem_cgroup *parent_memcg = mem_cgroup_from_css(css_parent(&memcg->css)); 5028 struct mem_cgroup *parent_memcg = mem_cgroup_from_css(css_parent(&memcg->css));
5028 5029
5029 mutex_lock(&memcg_create_mutex); 5030 mutex_lock(&memcg_create_mutex);
@@ -5094,11 +5095,11 @@ static inline u64 mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
5094 return val << PAGE_SHIFT; 5095 return val << PAGE_SHIFT;
5095} 5096}
5096 5097
5097static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft, 5098static ssize_t mem_cgroup_read(struct cgroup_subsys_state *css,
5098 struct file *file, char __user *buf, 5099 struct cftype *cft, struct file *file,
5099 size_t nbytes, loff_t *ppos) 5100 char __user *buf, size_t nbytes, loff_t *ppos)
5100{ 5101{
5101 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5102 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5102 char str[64]; 5103 char str[64];
5103 u64 val; 5104 u64 val;
5104 int name, len; 5105 int name, len;
@@ -5131,11 +5132,11 @@ static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft,
5131 return simple_read_from_buffer(buf, nbytes, ppos, str, len); 5132 return simple_read_from_buffer(buf, nbytes, ppos, str, len);
5132} 5133}
5133 5134
5134static int memcg_update_kmem_limit(struct cgroup *cont, u64 val) 5135static int memcg_update_kmem_limit(struct cgroup_subsys_state *css, u64 val)
5135{ 5136{
5136 int ret = -EINVAL; 5137 int ret = -EINVAL;
5137#ifdef CONFIG_MEMCG_KMEM 5138#ifdef CONFIG_MEMCG_KMEM
5138 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5139 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5139 /* 5140 /*
5140 * For simplicity, we won't allow this to be disabled. It also can't 5141 * For simplicity, we won't allow this to be disabled. It also can't
5141 * be changed if the cgroup has children already, or if tasks had 5142 * be changed if the cgroup has children already, or if tasks had
@@ -5151,7 +5152,7 @@ static int memcg_update_kmem_limit(struct cgroup *cont, u64 val)
5151 mutex_lock(&memcg_create_mutex); 5152 mutex_lock(&memcg_create_mutex);
5152 mutex_lock(&set_limit_mutex); 5153 mutex_lock(&set_limit_mutex);
5153 if (!memcg->kmem_account_flags && val != RESOURCE_MAX) { 5154 if (!memcg->kmem_account_flags && val != RESOURCE_MAX) {
5154 if (cgroup_task_count(cont) || memcg_has_children(memcg)) { 5155 if (cgroup_task_count(css->cgroup) || memcg_has_children(memcg)) {
5155 ret = -EBUSY; 5156 ret = -EBUSY;
5156 goto out; 5157 goto out;
5157 } 5158 }
@@ -5221,10 +5222,10 @@ out:
5221 * The user of this function is... 5222 * The user of this function is...
5222 * RES_LIMIT. 5223 * RES_LIMIT.
5223 */ 5224 */
5224static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, 5225static int mem_cgroup_write(struct cgroup_subsys_state *css, struct cftype *cft,
5225 const char *buffer) 5226 const char *buffer)
5226{ 5227{
5227 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5228 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5228 enum res_type type; 5229 enum res_type type;
5229 int name; 5230 int name;
5230 unsigned long long val; 5231 unsigned long long val;
@@ -5248,7 +5249,7 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
5248 else if (type == _MEMSWAP) 5249 else if (type == _MEMSWAP)
5249 ret = mem_cgroup_resize_memsw_limit(memcg, val); 5250 ret = mem_cgroup_resize_memsw_limit(memcg, val);
5250 else if (type == _KMEM) 5251 else if (type == _KMEM)
5251 ret = memcg_update_kmem_limit(cont, val); 5252 ret = memcg_update_kmem_limit(css, val);
5252 else 5253 else
5253 return -EINVAL; 5254 return -EINVAL;
5254 break; 5255 break;
@@ -5297,9 +5298,9 @@ out:
5297 *memsw_limit = min_memsw_limit; 5298 *memsw_limit = min_memsw_limit;
5298} 5299}
5299 5300
5300static int mem_cgroup_reset(struct cgroup *cont, unsigned int event) 5301static int mem_cgroup_reset(struct cgroup_subsys_state *css, unsigned int event)
5301{ 5302{
5302 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5303 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5303 int name; 5304 int name;
5304 enum res_type type; 5305 enum res_type type;
5305 5306
@@ -5332,17 +5333,17 @@ static int mem_cgroup_reset(struct cgroup *cont, unsigned int event)
5332 return 0; 5333 return 0;
5333} 5334}
5334 5335
5335static u64 mem_cgroup_move_charge_read(struct cgroup *cgrp, 5336static u64 mem_cgroup_move_charge_read(struct cgroup_subsys_state *css,
5336 struct cftype *cft) 5337 struct cftype *cft)
5337{ 5338{
5338 return mem_cgroup_from_cont(cgrp)->move_charge_at_immigrate; 5339 return mem_cgroup_from_css(css)->move_charge_at_immigrate;
5339} 5340}
5340 5341
5341#ifdef CONFIG_MMU 5342#ifdef CONFIG_MMU
5342static int mem_cgroup_move_charge_write(struct cgroup *cgrp, 5343static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css,
5343 struct cftype *cft, u64 val) 5344 struct cftype *cft, u64 val)
5344{ 5345{
5345 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5346 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5346 5347
5347 if (val >= (1 << NR_MOVE_TYPE)) 5348 if (val >= (1 << NR_MOVE_TYPE))
5348 return -EINVAL; 5349 return -EINVAL;
@@ -5357,7 +5358,7 @@ static int mem_cgroup_move_charge_write(struct cgroup *cgrp,
5357 return 0; 5358 return 0;
5358} 5359}
5359#else 5360#else
5360static int mem_cgroup_move_charge_write(struct cgroup *cgrp, 5361static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css,
5361 struct cftype *cft, u64 val) 5362 struct cftype *cft, u64 val)
5362{ 5363{
5363 return -ENOSYS; 5364 return -ENOSYS;
@@ -5365,13 +5366,13 @@ static int mem_cgroup_move_charge_write(struct cgroup *cgrp,
5365#endif 5366#endif
5366 5367
5367#ifdef CONFIG_NUMA 5368#ifdef CONFIG_NUMA
5368static int memcg_numa_stat_show(struct cgroup *cont, struct cftype *cft, 5369static int memcg_numa_stat_show(struct cgroup_subsys_state *css,
5369 struct seq_file *m) 5370 struct cftype *cft, struct seq_file *m)
5370{ 5371{
5371 int nid; 5372 int nid;
5372 unsigned long total_nr, file_nr, anon_nr, unevictable_nr; 5373 unsigned long total_nr, file_nr, anon_nr, unevictable_nr;
5373 unsigned long node_nr; 5374 unsigned long node_nr;
5374 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5375 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5375 5376
5376 total_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL); 5377 total_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL);
5377 seq_printf(m, "total=%lu", total_nr); 5378 seq_printf(m, "total=%lu", total_nr);
@@ -5416,10 +5417,10 @@ static inline void mem_cgroup_lru_names_not_uptodate(void)
5416 BUILD_BUG_ON(ARRAY_SIZE(mem_cgroup_lru_names) != NR_LRU_LISTS); 5417 BUILD_BUG_ON(ARRAY_SIZE(mem_cgroup_lru_names) != NR_LRU_LISTS);
5417} 5418}
5418 5419
5419static int memcg_stat_show(struct cgroup *cont, struct cftype *cft, 5420static int memcg_stat_show(struct cgroup_subsys_state *css, struct cftype *cft,
5420 struct seq_file *m) 5421 struct seq_file *m)
5421{ 5422{
5422 struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); 5423 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5423 struct mem_cgroup *mi; 5424 struct mem_cgroup *mi;
5424 unsigned int i; 5425 unsigned int i;
5425 5426
@@ -5503,17 +5504,18 @@ static int memcg_stat_show(struct cgroup *cont, struct cftype *cft,
5503 return 0; 5504 return 0;
5504} 5505}
5505 5506
5506static u64 mem_cgroup_swappiness_read(struct cgroup *cgrp, struct cftype *cft) 5507static u64 mem_cgroup_swappiness_read(struct cgroup_subsys_state *css,
5508 struct cftype *cft)
5507{ 5509{
5508 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5510 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5509 5511
5510 return mem_cgroup_swappiness(memcg); 5512 return mem_cgroup_swappiness(memcg);
5511} 5513}
5512 5514
5513static int mem_cgroup_swappiness_write(struct cgroup *cgrp, struct cftype *cft, 5515static int mem_cgroup_swappiness_write(struct cgroup_subsys_state *css,
5514 u64 val) 5516 struct cftype *cft, u64 val)
5515{ 5517{
5516 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5518 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5517 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css)); 5519 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css));
5518 5520
5519 if (val > 100 || !parent) 5521 if (val > 100 || !parent)
@@ -5829,10 +5831,10 @@ static void mem_cgroup_oom_unregister_event(struct cgroup *cgrp,
5829 spin_unlock(&memcg_oom_lock); 5831 spin_unlock(&memcg_oom_lock);
5830} 5832}
5831 5833
5832static int mem_cgroup_oom_control_read(struct cgroup *cgrp, 5834static int mem_cgroup_oom_control_read(struct cgroup_subsys_state *css,
5833 struct cftype *cft, struct cgroup_map_cb *cb) 5835 struct cftype *cft, struct cgroup_map_cb *cb)
5834{ 5836{
5835 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5837 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5836 5838
5837 cb->fill(cb, "oom_kill_disable", memcg->oom_kill_disable); 5839 cb->fill(cb, "oom_kill_disable", memcg->oom_kill_disable);
5838 5840
@@ -5843,10 +5845,10 @@ static int mem_cgroup_oom_control_read(struct cgroup *cgrp,
5843 return 0; 5845 return 0;
5844} 5846}
5845 5847
5846static int mem_cgroup_oom_control_write(struct cgroup *cgrp, 5848static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css,
5847 struct cftype *cft, u64 val) 5849 struct cftype *cft, u64 val)
5848{ 5850{
5849 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 5851 struct mem_cgroup *memcg = mem_cgroup_from_css(css);
5850 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css)); 5852 struct mem_cgroup *parent = mem_cgroup_from_css(css_parent(&memcg->css));
5851 5853
5852 /* cannot set to root cgroup and only 0 and 1 are allowed */ 5854 /* cannot set to root cgroup and only 0 and 1 are allowed */