mm/memcontrol: make the local VM stats consistent with total stats
Subsystems (2)
PATCH 1/1 mm/memcontrol: make the local VM stats consistent with total stats
After commit 815744d75152 ("mm: memcontrol: don't batch updates of local VM stats and events"), the local VM stats is not consistent with total VM stats.
Bellow is one example on my server (with 8 CPUs),
inactive_file 3567570944 total_inactive_file 3568029696
We can find that the deviation is very great, that is because the 'val' in __mod_memcg_state() is in pages while the effective value
in memcg_stat_show() is in bytes.
So the maximum of this deviation between local VM stats and total VM stats can be (32 * number_of_cpu * PAGE_SIZE), that may be an unacceptable great value.
We should make the local VM stats consistent with the total stats. Although the deviation between local VM events and total events are not great, I think we'd better make them consistent with each other as well.
--- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memcontrol.c +2 -2
@@ -691,12 +691,12 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val)if (mem_cgroup_disabled ())return ; -__this_cpu_add (memcg->vmstats_local->stat[idx], val); x = val +__this_cpu_read (memcg->vmstats_percpu->stat[idx]);if (unlikely (abs (x) >MEMCG_CHARGE_BATCH )) {struct mem_cgroup *mi; +__this_cpu_add (memcg->vmstats_local->stat[idx], x);for (mi = memcg; mi; mi =parent_mem_cgroup (mi))atomic_long_add (x, &mi->vmstats[idx]); x =0 ;
@@ -773,12 +773,12 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx,if (mem_cgroup_disabled ())return ; -__this_cpu_add (memcg->vmstats_local->events[idx], count); x = count +__this_cpu_read (memcg->vmstats_percpu->events[idx]);if (unlikely (x >MEMCG_CHARGE_BATCH )) {struct mem_cgroup *mi; +__this_cpu_add (memcg->vmstats_local->events[idx], x);for (mi = memcg; mi; mi =parent_mem_cgroup (mi))atomic_long_add (x, &mi->vmevents[idx]); x =0 ;
Signature · 1 line
1.8.3.1
Johannes Weiner
maintainerQuoted 14 lines · Yafang Shao
After commit
815744d75152("mm: memcontrol: don't batch updates of local VM stats and events"), the local VM stats is not consistent with total VM stats.Bellow is one example on my server (with 8 CPUs),
inactive_file 3567570944 total_inactive_file 3568029696We can find that the deviation is very great, that is because the 'val' in
__mod_memcg_state()is in pages while the effective value
inmemcg_stat_show()is in bytes.
So the maximum of this deviation between local VM stats and total VM stats can be (32 *number_of_cpu*PAGE_SIZE), that may be an unacceptable great value.
Quoted 3 lines
We should make the local VM stats consistent with the total stats. Although the deviation between local VM events and total events are not great, I think we'd better make them consistent with each other as well.
Ha - the local stats are not percpu-fuzzy enough... But I guess that is a valid complaint.
Quoted 26 lines
--- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/memcontrol.c +1
-1@@ -691,12 +691,12 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val)if (mem_cgroup_disabled ())return ; -__this_cpu_add (memcg->vmstats_local->stat[idx], val); x = val +__this_cpu_read (memcg->vmstats_percpu->stat[idx]);if (unlikely (abs (x) >MEMCG_CHARGE_BATCH )) {struct mem_cgroup *mi; +__this_cpu_add (memcg->vmstats_local->stat[idx], x);for (mi = memcg; mi; mi =parent_mem_cgroup (mi))atomic_long_add (x, &mi->vmstats[idx]); x =0 ;@@ -773,12 +773,12 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx,if (mem_cgroup_disabled ())return ;
mm/memcontrol.c void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, · line 784
Quoted 10 lines
mm/memcontrol.c +1
-1-__this_cpu_add (memcg->vmstats_local->events[idx], count); x = count +__this_cpu_read (memcg->vmstats_percpu->events[idx]);if (unlikely (x >MEMCG_CHARGE_BATCH )) {struct mem_cgroup *mi; +__this_cpu_add (memcg->vmstats_local->events[idx], x);for (mi = memcg; mi; mi =parent_mem_cgroup (mi))atomic_long_add (x, &mi->vmevents[idx]); x =0 ;
Please also update __mod_lruvec_state() to keep this behavior the same across counters, to make sure we won't have any surprises when switching between them.
And please add comments explaining that we batch local counters to keep them in sync with the hierarchical ones. Because it does look a little odd without explanation.
Quoted 64 lines · Johannes Weiner
Quoted 14 lines · Yafang Shao
After commit
815744d75152("mm: memcontrol: don't batch updates of local VM stats and events"), the local VM stats is not consistent with total VM stats.Bellow is one example on my server (with 8 CPUs),
inactive_file 3567570944 total_inactive_file 3568029696We can find that the deviation is very great, that is because the 'val' in
__mod_memcg_state()is in pages while the effective value
inmemcg_stat_show()is in bytes.
So the maximum of this deviation between local VM stats and total VM stats can be (32 *number_of_cpu*PAGE_SIZE), that may be an unacceptable great value.Quoted 3 lines
We should make the local VM stats consistent with the total stats. Although the deviation between local VM events and total events are not great, I think we'd better make them consistent with each other as well.
Ha - the local stats are not percpu-fuzzy enough... But I guess that is a valid complaint.
Quoted 26 lines
--- mm/memcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/memcontrol.c +1
-1@@ -691,12 +691,12 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val)if (mem_cgroup_disabled ())return ; -__this_cpu_add (memcg->vmstats_local->stat[idx], val); x = val +__this_cpu_read (memcg->vmstats_percpu->stat[idx]);if (unlikely (abs (x) >MEMCG_CHARGE_BATCH )) {struct mem_cgroup *mi; +__this_cpu_add (memcg->vmstats_local->stat[idx], x);for (mi = memcg; mi; mi =parent_mem_cgroup (mi))atomic_long_add (x, &mi->vmstats[idx]); x =0 ;@@ -773,12 +773,12 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx,if (mem_cgroup_disabled ())return ;mm/memcontrol.c void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, · line 784
Quoted 10 lines
mm/memcontrol.c +1
-1-__this_cpu_add (memcg->vmstats_local->events[idx], count); x = count +__this_cpu_read (memcg->vmstats_percpu->events[idx]);if (unlikely (x >MEMCG_CHARGE_BATCH )) {struct mem_cgroup *mi; +__this_cpu_add (memcg->vmstats_local->events[idx], x);for (mi = memcg; mi; mi =parent_mem_cgroup (mi))atomic_long_add (x, &mi->vmevents[idx]); x =0 ;Please also update
__mod_lruvec_state()to keep this behavior the same across counters, to make sure we won't have any surprises when switching between them.
Quoted 3 lines
And please add comments explaining that we batch local counters to keep them in sync with the hierarchical ones. Because it does look a little odd without explanation.
Sure, I will do it.
Thanks
Yafang