[Devel] [PATCH RHEL7 COMMIT] mm/memcg: get precise stat2 counters for statistics.

Konstantin Khorenko khorenko at virtuozzo.com
Sat Jul 29 14:44:22 MSK 2017


The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.33.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.33.21
------>
commit 6c6eac13167bb1dd99b0f140bd16bd1bb487be08
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Sat Jul 29 15:44:21 2017 +0400

    mm/memcg: get precise stat2 counters for statistics.
    
    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 at virtuozzo.com>
---
 mm/memcontrol.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 19af6a9..5ab5e82 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;


More information about the Devel mailing list