[Devel,rh7] mm/memcg: get precise stat2 counters for statistics.

Submitted by Andrey Ryabinin on July 28, 2017, 4:28 p.m.

Details

Message ID 20170728162856.4505-1-aryabinin@virtuozzo.com
State New
Series "mm/memcg: get precise stat2 counters for statistics."
Headers show

Commit Message

Andrey Ryabinin July 28, 2017, 4:28 p.m.
Currently mem_cgroup_read_stat2() imprecise result for performance
reasons. However, for statistics like 'memory.stat' we'd want the precise
results.

Make mem_cgroup_read_stat2() slower but preciser, and add unprecise but
fast mem_cgroup_read_stat2_fast() for performance-sensitive caller - dcache_is_low().

https://jira.sw.ru/browse/PSBM-69332
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 19af6a9d9fc8..5ab5e82c924e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -973,12 +973,19 @@  mem_cgroup_read_stat(struct mem_cgroup *memcg, enum mem_cgroup_stat_index idx)
 		val = 0;
 	return val;
 }
+
 static inline unsigned long
-mem_cgroup_read_stat2(struct mem_cgroup *memcg, enum mem_cgroup_stat2_index idx)
+mem_cgroup_read_stat2_fast(struct mem_cgroup *memcg, enum mem_cgroup_stat2_index idx)
 {
 	return percpu_counter_read_positive(&memcg->stat2.counters[idx]);
 }
 
+static inline unsigned long
+mem_cgroup_read_stat2(struct mem_cgroup *memcg, enum mem_cgroup_stat2_index idx)
+{
+	return percpu_counter_sum_positive(&memcg->stat2.counters[idx]);
+}
+
 static void mem_cgroup_update_swap_max(struct mem_cgroup *memcg)
 {
 	long long swap;
@@ -1611,9 +1618,9 @@  bool mem_cgroup_dcache_is_low(struct mem_cgroup *memcg, int vfs_cache_min_ratio)
 {
 	unsigned long anon, file, dcache;
 
-	anon = mem_cgroup_read_stat2(memcg, MEM_CGROUP_STAT_RSS);
-	file = mem_cgroup_read_stat2(memcg, MEM_CGROUP_STAT_CACHE);
-	dcache = mem_cgroup_read_stat2(memcg, MEM_CGROUP_STAT_SLAB_RECLAIMABLE);
+	anon = mem_cgroup_read_stat2_fast(memcg, MEM_CGROUP_STAT_RSS);
+	file = mem_cgroup_read_stat2_fast(memcg, MEM_CGROUP_STAT_CACHE);
+	dcache = mem_cgroup_read_stat2_fast(memcg, MEM_CGROUP_STAT_SLAB_RECLAIMABLE);
 
 	return dcache / vfs_cache_min_ratio <
 			(anon + file + dcache) / 100;