From: Yulei Zhang <yuleixzhang@xxxxxxxxxxx> Record the number of times we trigger the memory allocation throttle. Signed-off-by: Jiang Biao <benbjiang@xxxxxxxxx> Signed-off-by: Yulei Zhang <yuleixzhang@xxxxxxxxxxx> --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index b20820f7fdbf..59e6cb78a07a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -239,6 +239,7 @@ struct mem_spd_ctl { unsigned long prev_chg; int has_lmt; atomic_t updating; + atomic_long_t nr_throttled; }; #endif diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a1e33a9e6594..ca39974403a3 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1401,11 +1401,19 @@ static void mem_cgroup_mst_msc_reset(struct mem_cgroup *memcg) return; msc = &memcg->msc; - msc->has_lmt = 0; - msc->mem_spd_lmt = 0; - msc->slice_lmt = 0; - msc->prev_chg = 0; - msc->prev_thl_jifs = 0; + while (msc->prev_thl_jifs || + msc->prev_chg || + msc->slice_lmt || + msc->mem_spd_lmt || + msc->has_lmt || + atomic_long_read(&msc->nr_throttled)) { + atomic_long_set(&msc->nr_throttled, 0); + msc->has_lmt = 0; + msc->mem_spd_lmt = 0; + msc->slice_lmt = 0; + msc->prev_chg = 0; + msc->prev_thl_jifs = 0; + } } static void mem_cgroup_mst_has_lmt_init(struct mem_cgroup *memcg) @@ -1552,6 +1560,8 @@ static void mem_cgroup_mst_spd_throttle(struct mem_cgroup *memcg) if (!ret) return; + atomic_long_inc(&msc->nr_throttled); + /* * Throttle the allocation for amount of jiffies according to * the fraction between the actual memory usage and allowed @@ -1586,11 +1596,22 @@ static void mem_cgroup_mst_show_mem_spd_max(struct mem_cgroup *memcg, seq_printf(m, "mst_mem_spd_max %lu\n", mem_cgroup_mst_get_mem_spd_max(memcg)); } + +static void mem_cgroup_mst_show_nr_throttled(struct mem_cgroup *memcg, + struct seq_file *m) +{ + seq_printf(m, "mst_nr_throttled %lu\n", + atomic_long_read(&memcg->msc.nr_throttled)); +} #else /* CONFIG_MEM_SPEED_THROTTLE */ static void mem_cgroup_mst_spd_throttle(struct mem_cgroup *memcg) { } +static void mem_cgroup_mst_spd_throttle(struct mem_cgroup *memcg) +{ +} + static void mem_cgroup_mst_has_lmt_init(struct mem_cgroup *memcg) { } @@ -1678,6 +1699,8 @@ static char *memory_stat_format(struct mem_cgroup *memcg) #ifdef CONFIG_MEM_SPEED_THROTTLE seq_buf_printf(&s, "mst_mem_spd_max %lu\n", mem_cgroup_mst_get_mem_spd_max(memcg)); + seq_buf_printf(&s, "mst_nr_throttled %lu\n", + atomic_long_read(&memcg->msc.nr_throttled)); #endif /* The above should easily fit into one page */ @@ -4131,6 +4154,7 @@ static int memcg_stat_show(struct seq_file *m, void *v) #endif mem_cgroup_mst_show_mem_spd_max(memcg, m); + mem_cgroup_mst_show_nr_throttled(memcg, m); return 0; } -- 2.28.0