Skip to content

Commit 873f64b

Browse files
jiebinnakpm00
authored andcommitted
mm/memcontrol.c: remove the redundant updating of stats_flush_threshold
Remove the redundant updating of stats_flush_threshold. If the global var stats_flush_threshold has exceeded the trigger value for __mem_cgroup_flush_stats, further increment is unnecessary. Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads). Score gain: 1.95x Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%) CPU: ICX 8380 x 2 sockets Core number: 40 x 2 physical cores Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads) Link: https://lkml.kernel.org/r/20220722164949.47760-1-jiebin.sun@intel.com Signed-off-by: Jiebin Sun <jiebin.sun@intel.com> Acked-by: Shakeel Butt <shakeelb@google.com> Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev> Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com> Acked-by: Muchun Song <songmuchun@bytedance.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: "Huang, Ying" <ying.huang@intel.com> Cc: Amadeusz Sawiski <amadeuszx.slawinski@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 914eedc commit 873f64b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

mm/memcontrol.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,14 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val)
626626

627627
x = __this_cpu_add_return(stats_updates, abs(val));
628628
if (x > MEMCG_CHARGE_BATCH) {
629-
atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold);
629+
/*
630+
* If stats_flush_threshold exceeds the threshold
631+
* (>num_online_cpus()), cgroup stats update will be triggered
632+
* in __mem_cgroup_flush_stats(). Increasing this var further
633+
* is redundant and simply adds overhead in atomic update.
634+
*/
635+
if (atomic_read(&stats_flush_threshold) <= num_online_cpus())
636+
atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold);
630637
__this_cpu_write(stats_updates, 0);
631638
}
632639
}

0 commit comments

Comments
 (0)