Skip to content

Commit 677dc97

Browse files
cdowntorvalds
authored andcommitted
mm, memcg: extract memcg maxable seq_file logic to seq_show_memcg_tunable
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/[email protected] Signed-off-by: Chris Down <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Roman Gushchin <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent aa9694b commit 677dc97

File tree

1 file changed

+19
-45
lines changed

1 file changed

+19
-45
lines changed

mm/memcontrol.c

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5353,6 +5353,16 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)
53535353
root_mem_cgroup->use_hierarchy = false;
53545354
}
53555355

5356+
static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value)
5357+
{
5358+
if (value == PAGE_COUNTER_MAX)
5359+
seq_puts(m, "max\n");
5360+
else
5361+
seq_printf(m, "%llu\n", (u64)value * PAGE_SIZE);
5362+
5363+
return 0;
5364+
}
5365+
53565366
static u64 memory_current_read(struct cgroup_subsys_state *css,
53575367
struct cftype *cft)
53585368
{
@@ -5363,15 +5373,8 @@ static u64 memory_current_read(struct cgroup_subsys_state *css,
53635373

53645374
static int memory_min_show(struct seq_file *m, void *v)
53655375
{
5366-
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
5367-
unsigned long min = READ_ONCE(memcg->memory.min);
5368-
5369-
if (min == PAGE_COUNTER_MAX)
5370-
seq_puts(m, "max\n");
5371-
else
5372-
seq_printf(m, "%llu\n", (u64)min * PAGE_SIZE);
5373-
5374-
return 0;
5376+
return seq_puts_memcg_tunable(m,
5377+
READ_ONCE(mem_cgroup_from_seq(m)->memory.min));
53755378
}
53765379

53775380
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,
53935396

53945397
static int memory_low_show(struct seq_file *m, void *v)
53955398
{
5396-
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
5397-
unsigned long low = READ_ONCE(memcg->memory.low);
5398-
5399-
if (low == PAGE_COUNTER_MAX)
5400-
seq_puts(m, "max\n");
5401-
else
5402-
seq_printf(m, "%llu\n", (u64)low * PAGE_SIZE);
5403-
5404-
return 0;
5399+
return seq_puts_memcg_tunable(m,
5400+
READ_ONCE(mem_cgroup_from_seq(m)->memory.low));
54055401
}
54065402

54075403
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,
54235419

54245420
static int memory_high_show(struct seq_file *m, void *v)
54255421
{
5426-
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
5427-
unsigned long high = READ_ONCE(memcg->high);
5428-
5429-
if (high == PAGE_COUNTER_MAX)
5430-
seq_puts(m, "max\n");
5431-
else
5432-
seq_printf(m, "%llu\n", (u64)high * PAGE_SIZE);
5433-
5434-
return 0;
5422+
return seq_puts_memcg_tunable(m, READ_ONCE(mem_cgroup_from_seq(m)->high));
54355423
}
54365424

54375425
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,
54605448

54615449
static int memory_max_show(struct seq_file *m, void *v)
54625450
{
5463-
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
5464-
unsigned long max = READ_ONCE(memcg->memory.max);
5465-
5466-
if (max == PAGE_COUNTER_MAX)
5467-
seq_puts(m, "max\n");
5468-
else
5469-
seq_printf(m, "%llu\n", (u64)max * PAGE_SIZE);
5470-
5471-
return 0;
5451+
return seq_puts_memcg_tunable(m,
5452+
READ_ONCE(mem_cgroup_from_seq(m)->memory.max));
54725453
}
54735454

54745455
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,
66006581

66016582
static int swap_max_show(struct seq_file *m, void *v)
66026583
{
6603-
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
6604-
unsigned long max = READ_ONCE(memcg->swap.max);
6605-
6606-
if (max == PAGE_COUNTER_MAX)
6607-
seq_puts(m, "max\n");
6608-
else
6609-
seq_printf(m, "%llu\n", (u64)max * PAGE_SIZE);
6610-
6611-
return 0;
6584+
return seq_puts_memcg_tunable(m,
6585+
READ_ONCE(mem_cgroup_from_seq(m)->swap.max));
66126586
}
66136587

66146588
static ssize_t swap_max_write(struct kernfs_open_file *of,

0 commit comments

Comments
 (0)