Commit 25485de6 authored by Greg Thelen's avatar Greg Thelen Committed by Linus Torvalds

memcg: refactor mem_control_numa_stat_show()

Refactor mem_control_numa_stat_show() to use a new stats structure for
smaller and simpler code.  This consolidates nearly identical code.

    text      data      bss        dec      hex   filename
  8,137,679 1,703,496 1,896,448 11,737,623 b31a17 vmlinux.before
  8,136,911 1,703,496 1,896,448 11,736,855 b31717 vmlinux.after
Signed-off-by: default avatarGreg Thelen <gthelen@google.com>
Signed-off-by: default avatarYing Han <yinghan@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b76ac7e7
...@@ -5369,45 +5369,33 @@ static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css, ...@@ -5369,45 +5369,33 @@ static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css,
static int memcg_numa_stat_show(struct cgroup_subsys_state *css, static int memcg_numa_stat_show(struct cgroup_subsys_state *css,
struct cftype *cft, struct seq_file *m) struct cftype *cft, struct seq_file *m)
{ {
struct numa_stat {
const char *name;
unsigned int lru_mask;
};
static const struct numa_stat stats[] = {
{ "total", LRU_ALL },
{ "file", LRU_ALL_FILE },
{ "anon", LRU_ALL_ANON },
{ "unevictable", BIT(LRU_UNEVICTABLE) },
};
const struct numa_stat *stat;
int nid; int nid;
unsigned long total_nr, file_nr, anon_nr, unevictable_nr; unsigned long nr;
unsigned long node_nr;
struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *memcg = mem_cgroup_from_css(css);
total_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL); for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) {
seq_printf(m, "total=%lu", total_nr); nr = mem_cgroup_nr_lru_pages(memcg, stat->lru_mask);
for_each_node_state(nid, N_MEMORY) { seq_printf(m, "%s=%lu", stat->name, nr);
node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid, LRU_ALL); for_each_node_state(nid, N_MEMORY) {
seq_printf(m, " N%d=%lu", nid, node_nr); nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
} stat->lru_mask);
seq_putc(m, '\n'); seq_printf(m, " N%d=%lu", nid, nr);
}
file_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL_FILE); seq_putc(m, '\n');
seq_printf(m, "file=%lu", file_nr);
for_each_node_state(nid, N_MEMORY) {
node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
LRU_ALL_FILE);
seq_printf(m, " N%d=%lu", nid, node_nr);
}
seq_putc(m, '\n');
anon_nr = mem_cgroup_nr_lru_pages(memcg, LRU_ALL_ANON);
seq_printf(m, "anon=%lu", anon_nr);
for_each_node_state(nid, N_MEMORY) {
node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
LRU_ALL_ANON);
seq_printf(m, " N%d=%lu", nid, node_nr);
} }
seq_putc(m, '\n');
unevictable_nr = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_UNEVICTABLE));
seq_printf(m, "unevictable=%lu", unevictable_nr);
for_each_node_state(nid, N_MEMORY) {
node_nr = mem_cgroup_node_nr_lru_pages(memcg, nid,
BIT(LRU_UNEVICTABLE));
seq_printf(m, " N%d=%lu", nid, node_nr);
}
seq_putc(m, '\n');
return 0; return 0;
} }
#endif /* CONFIG_NUMA */ #endif /* CONFIG_NUMA */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment