提交 837e53ab 编写于 作者: X Xu Yu

alinux: mm, memcg: rework memory latency histogram interfaces

to #26424368

There are some duplicate codes in the original implementation of memory
latency histogram, such as {x, y, z}_show, and {x, y, z}_write, where x,
y, z represents various types of memory latency.

This reworks common codes of memory latency histogram to make it easier
to add more types of memory latency later.
Signed-off-by: NXu Yu <xuyu@linux.alibaba.com>
Reviewed-by: NYang Shi <yang.shi@linux.alibaba.com>
Reviewed-by: NXunlei Pang <xlpang@linux.alibaba.com>
上级 4bec5cfe
...@@ -89,9 +89,9 @@ struct mem_cgroup_reclaim_cookie { ...@@ -89,9 +89,9 @@ struct mem_cgroup_reclaim_cookie {
struct alloc_context; struct alloc_context;
enum mem_lat_stat_item { enum mem_lat_stat_item {
GLOBAL_DIRECT_RECLAIM, /* global direct reclaim latency */ MEM_LAT_GLOBAL_DIRECT_RECLAIM, /* global direct reclaim latency */
MEMCG_DIRECT_RECLAIM, /* memcg direct reclaim latency */ MEM_LAT_MEMCG_DIRECT_RECLAIM, /* memcg direct reclaim latency */
DIRECT_COMPACT, /* direct compact latency */ MEM_LAT_DIRECT_COMPACT, /* direct compact latency */
MEM_LAT_NR_STAT, MEM_LAT_NR_STAT,
}; };
......
...@@ -4511,80 +4511,40 @@ void memcg_check_wmark_min_adj(struct task_struct *curr, ...@@ -4511,80 +4511,40 @@ void memcg_check_wmark_min_adj(struct task_struct *curr,
} }
} }
static void smp_global_direct_reclaim_write(void *info) #define MEMCG_LAT_STAT_SMP_WRITE(name, sidx) \
{ static void smp_write_##name(void *info) \
struct mem_cgroup *memcg = (struct mem_cgroup *)info; { \
int idx = GLOBAL_DIRECT_RECLAIM; struct mem_cgroup *memcg = (struct mem_cgroup *)info; \
int i; int i; \
\
for (i = MEM_LAT_0_1; i < MEM_LAT_NR_COUNT; i++) for (i = MEM_LAT_0_1; i < MEM_LAT_NR_COUNT; i++) \
this_cpu_write(memcg->lat_stat_cpu->item[idx][i], 0); this_cpu_write(memcg->lat_stat_cpu->item[sidx][i], 0); \
} } \
static void smp_memcg_direct_reclaim_write(void *info) MEMCG_LAT_STAT_SMP_WRITE(global_direct_reclaim, MEM_LAT_GLOBAL_DIRECT_RECLAIM);
{ MEMCG_LAT_STAT_SMP_WRITE(memcg_direct_reclaim, MEM_LAT_MEMCG_DIRECT_RECLAIM);
struct mem_cgroup *memcg = (struct mem_cgroup *)info; MEMCG_LAT_STAT_SMP_WRITE(direct_compact, MEM_LAT_DIRECT_COMPACT);
int idx = MEMCG_DIRECT_RECLAIM;
int i;
for (i = MEM_LAT_0_1; i < MEM_LAT_NR_COUNT; i++)
this_cpu_write(memcg->lat_stat_cpu->item[idx][i], 0);
}
static void smp_direct_compact_write(void *info)
{
struct mem_cgroup *memcg = (struct mem_cgroup *)info;
int idx = DIRECT_COMPACT;
int i;
for (i = MEM_LAT_0_1; i < MEM_LAT_NR_COUNT; i++)
this_cpu_write(memcg->lat_stat_cpu->item[idx][i], 0);
}
smp_call_func_t smp_memcg_lat_write_funcs[] = { smp_call_func_t smp_memcg_lat_write_funcs[] = {
smp_global_direct_reclaim_write, smp_write_global_direct_reclaim,
smp_memcg_direct_reclaim_write, smp_write_memcg_direct_reclaim,
smp_direct_compact_write, smp_write_direct_compact,
}; };
static int memcg_lat_stat_write(struct cgroup_subsys_state *css, static int memcg_lat_stat_write(struct cgroup_subsys_state *css,
enum mem_lat_stat_item idx) struct cftype *cft, u64 val)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(css); struct mem_cgroup *memcg = mem_cgroup_from_css(css);
enum mem_lat_stat_item idx = cft->private;
smp_call_func_t func = smp_memcg_lat_write_funcs[idx]; smp_call_func_t func = smp_memcg_lat_write_funcs[idx];
func((void *)memcg);
smp_call_function(func, (void *)memcg, 1);
return 0;
}
static int global_direct_reclaim_latency_write(struct cgroup_subsys_state *css,
struct cftype *cft, u64 val)
{
if (val != 0) if (val != 0)
return -EINVAL; return -EINVAL;
return memcg_lat_stat_write(css, GLOBAL_DIRECT_RECLAIM); func((void *)memcg);
} smp_call_function(func, (void *)memcg, 1);
static int memcg_direct_reclaim_latency_write(struct cgroup_subsys_state *css,
struct cftype *cft, u64 val)
{
if (val != 0)
return -EINVAL;
return memcg_lat_stat_write(css, MEMCG_DIRECT_RECLAIM);
}
static int memcg_direct_compact_latency_write(
struct cgroup_subsys_state *css,
struct cftype *cft, u64 val)
{
if (val != 0)
return -EINVAL;
return memcg_lat_stat_write(css, DIRECT_COMPACT); return 0;
} }
static u64 memcg_lat_stat_gather(struct mem_cgroup *memcg, static u64 memcg_lat_stat_gather(struct mem_cgroup *memcg,
...@@ -4600,9 +4560,10 @@ static u64 memcg_lat_stat_gather(struct mem_cgroup *memcg, ...@@ -4600,9 +4560,10 @@ static u64 memcg_lat_stat_gather(struct mem_cgroup *memcg,
return sum; return sum;
} }
static void memcg_lat_stat_show(struct seq_file *m, enum mem_lat_stat_item idx) static int memcg_lat_stat_show(struct seq_file *m, void *v)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m)); struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
enum mem_lat_stat_item idx = seq_cft(m)->private;
seq_printf(m, "0-1ms: \t%llu\n", seq_printf(m, "0-1ms: \t%llu\n",
memcg_lat_stat_gather(memcg, idx, MEM_LAT_0_1)); memcg_lat_stat_gather(memcg, idx, MEM_LAT_0_1));
...@@ -4620,25 +4581,6 @@ static void memcg_lat_stat_show(struct seq_file *m, enum mem_lat_stat_item idx) ...@@ -4620,25 +4581,6 @@ static void memcg_lat_stat_show(struct seq_file *m, enum mem_lat_stat_item idx)
memcg_lat_stat_gather(memcg, idx, MEM_LAT_1000_INF)); memcg_lat_stat_gather(memcg, idx, MEM_LAT_1000_INF));
seq_printf(m, "total(ms): \t%llu\n", seq_printf(m, "total(ms): \t%llu\n",
memcg_lat_stat_gather(memcg, idx, MEM_LAT_TOTAL) / 1000000); memcg_lat_stat_gather(memcg, idx, MEM_LAT_TOTAL) / 1000000);
}
static int global_direct_reclaim_latency_show(struct seq_file *m, void *v)
{
memcg_lat_stat_show(m, GLOBAL_DIRECT_RECLAIM);
return 0;
}
static int memcg_direct_reclaim_latency_show(struct seq_file *m, void *v)
{
memcg_lat_stat_show(m, MEMCG_DIRECT_RECLAIM);
return 0;
}
static int memcg_direct_compact_latency_show(struct seq_file *m, void *v)
{
memcg_lat_stat_show(m, DIRECT_COMPACT);
return 0; return 0;
} }
...@@ -5586,18 +5528,21 @@ static struct cftype mem_cgroup_legacy_files[] = { ...@@ -5586,18 +5528,21 @@ static struct cftype mem_cgroup_legacy_files[] = {
}, },
{ {
.name = "direct_reclaim_global_latency", .name = "direct_reclaim_global_latency",
.write_u64 = global_direct_reclaim_latency_write, .private = MEM_LAT_GLOBAL_DIRECT_RECLAIM,
.seq_show = global_direct_reclaim_latency_show, .write_u64 = memcg_lat_stat_write,
.seq_show = memcg_lat_stat_show,
}, },
{ {
.name = "direct_reclaim_memcg_latency", .name = "direct_reclaim_memcg_latency",
.write_u64 = memcg_direct_reclaim_latency_write, .private = MEM_LAT_MEMCG_DIRECT_RECLAIM,
.seq_show = memcg_direct_reclaim_latency_show, .write_u64 = memcg_lat_stat_write,
.seq_show = memcg_lat_stat_show,
}, },
{ {
.name = "direct_compact_latency", .name = "direct_compact_latency",
.write_u64 = memcg_direct_compact_latency_write, .private = MEM_LAT_DIRECT_COMPACT,
.seq_show = memcg_direct_compact_latency_show, .write_u64 = memcg_lat_stat_write,
.seq_show = memcg_lat_stat_show,
}, },
{ {
.name = "force_empty", .name = "force_empty",
......
...@@ -3733,7 +3733,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, ...@@ -3733,7 +3733,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
prio); prio);
memalloc_noreclaim_restore(noreclaim_flag); memalloc_noreclaim_restore(noreclaim_flag);
memcg_lat_stat_update(DIRECT_COMPACT, (ktime_get_ns() - start)); memcg_lat_stat_update(MEM_LAT_DIRECT_COMPACT, (ktime_get_ns() - start));
psi_memstall_leave(&pflags); psi_memstall_leave(&pflags);
if (*compact_result <= COMPACT_INACTIVE) if (*compact_result <= COMPACT_INACTIVE)
...@@ -3953,7 +3953,8 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order, ...@@ -3953,7 +3953,8 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order,
current->reclaim_state = NULL; current->reclaim_state = NULL;
memalloc_noreclaim_restore(noreclaim_flag); memalloc_noreclaim_restore(noreclaim_flag);
fs_reclaim_release(gfp_mask); fs_reclaim_release(gfp_mask);
memcg_lat_stat_update(GLOBAL_DIRECT_RECLAIM, (ktime_get_ns() - start)); memcg_lat_stat_update(MEM_LAT_GLOBAL_DIRECT_RECLAIM,
(ktime_get_ns() - start));
psi_memstall_leave(&pflags); psi_memstall_leave(&pflags);
cond_resched(); cond_resched();
......
...@@ -3488,7 +3488,8 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, ...@@ -3488,7 +3488,8 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
nr_reclaimed = do_try_to_free_pages(zonelist, &sc); nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
memalloc_noreclaim_restore(noreclaim_flag); memalloc_noreclaim_restore(noreclaim_flag);
memcg_lat_stat_update(MEMCG_DIRECT_RECLAIM, (ktime_get_ns() - start)); memcg_lat_stat_update(MEM_LAT_MEMCG_DIRECT_RECLAIM,
(ktime_get_ns() - start));
psi_memstall_leave(&pflags); psi_memstall_leave(&pflags);
trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed); trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册