mm, memcg: extract memcg maxable seq_file logic to seq_show_memcg_tunable
authorChris Down <chris@chrisdown.name>
Tue, 5 Mar 2019 23:45:55 +0000 (15:45 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 6 Mar 2019 05:07:17 +0000 (21:07 -0800)
memcg has a significant number of files exposed to kernfs where their
value is either exposed directly or is "max" in the case of
PAGE_COUNTER_MAX.

This patch makes this generic by providing a single function to do this
work.  In combination with the previous patch adding
mem_cgroup_from_seq, this makes all of the seq_show feeder functions
significantly more simple.

Link: http://lkml.kernel.org/r/20190124194100.GA31425@chrisdown.name
Signed-off-by: Chris Down <chris@chrisdown.name>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/memcontrol.c

index 027abf9935d0c6ef0d92ba5bdae732d47b310ba5..59425a35763c1a683b626a658bb0cb3d6c40876a 100644 (file)
@@ -5353,6 +5353,16 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)
                root_mem_cgroup->use_hierarchy = false;
 }
 
+static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value)
+{
+       if (value == PAGE_COUNTER_MAX)
+               seq_puts(m, "max\n");
+       else
+               seq_printf(m, "%llu\n", (u64)value * PAGE_SIZE);
+
+       return 0;
+}
+
 static u64 memory_current_read(struct cgroup_subsys_state *css,
                               struct cftype *cft)
 {
@@ -5363,15 +5373,8 @@ static u64 memory_current_read(struct cgroup_subsys_state *css,
 
 static int memory_min_show(struct seq_file *m, void *v)
 {
-       struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
-       unsigned long min = READ_ONCE(memcg->memory.min);
-
-       if (min == PAGE_COUNTER_MAX)
-               seq_puts(m, "max\n");
-       else
-               seq_printf(m, "%llu\n", (u64)min * PAGE_SIZE);
-
-       return 0;
+       return seq_puts_memcg_tunable(m,
+               READ_ONCE(mem_cgroup_from_seq(m)->memory.min));
 }
 
 static ssize_t memory_min_write(struct kernfs_open_file *of,
@@ -5393,15 +5396,8 @@ static ssize_t memory_min_write(struct kernfs_open_file *of,
 
 static int memory_low_show(struct seq_file *m, void *v)
 {
-       struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
-       unsigned long low = READ_ONCE(memcg->memory.low);
-
-       if (low == PAGE_COUNTER_MAX)
-               seq_puts(m, "max\n");
-       else
-               seq_printf(m, "%llu\n", (u64)low * PAGE_SIZE);
-
-       return 0;
+       return seq_puts_memcg_tunable(m,
+               READ_ONCE(mem_cgroup_from_seq(m)->memory.low));
 }
 
 static ssize_t memory_low_write(struct kernfs_open_file *of,
@@ -5423,15 +5419,7 @@ static ssize_t memory_low_write(struct kernfs_open_file *of,
 
 static int memory_high_show(struct seq_file *m, void *v)
 {
-       struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
-       unsigned long high = READ_ONCE(memcg->high);
-
-       if (high == PAGE_COUNTER_MAX)
-               seq_puts(m, "max\n");
-       else
-               seq_printf(m, "%llu\n", (u64)high * PAGE_SIZE);
-
-       return 0;
+       return seq_puts_memcg_tunable(m, READ_ONCE(mem_cgroup_from_seq(m)->high));
 }
 
 static ssize_t memory_high_write(struct kernfs_open_file *of,
@@ -5460,15 +5448,8 @@ static ssize_t memory_high_write(struct kernfs_open_file *of,
 
 static int memory_max_show(struct seq_file *m, void *v)
 {
-       struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
-       unsigned long max = READ_ONCE(memcg->memory.max);
-
-       if (max == PAGE_COUNTER_MAX)
-               seq_puts(m, "max\n");
-       else
-               seq_printf(m, "%llu\n", (u64)max * PAGE_SIZE);
-
-       return 0;
+       return seq_puts_memcg_tunable(m,
+               READ_ONCE(mem_cgroup_from_seq(m)->memory.max));
 }
 
 static ssize_t memory_max_write(struct kernfs_open_file *of,
@@ -6600,15 +6581,8 @@ static u64 swap_current_read(struct cgroup_subsys_state *css,
 
 static int swap_max_show(struct seq_file *m, void *v)
 {
-       struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
-       unsigned long max = READ_ONCE(memcg->swap.max);
-
-       if (max == PAGE_COUNTER_MAX)
-               seq_puts(m, "max\n");
-       else
-               seq_printf(m, "%llu\n", (u64)max * PAGE_SIZE);
-
-       return 0;
+       return seq_puts_memcg_tunable(m,
+               READ_ONCE(mem_cgroup_from_seq(m)->swap.max));
 }
 
 static ssize_t swap_max_write(struct kernfs_open_file *of,