Re: [mm-unstable v4 5/5] mm: memcg: restore subtree stats flushing

From: Shakeel Butt
Date: Sat Dec 02 2023 - 03:31:43 EST


On Wed, Nov 29, 2023 at 03:21:53AM +0000, Yosry Ahmed wrote:
[...]
> +void mem_cgroup_flush_stats(struct mem_cgroup *memcg)
> {
> - if (memcg_should_flush_stats(root_mem_cgroup))
> - do_flush_stats();
> + static DEFINE_MUTEX(memcg_stats_flush_mutex);
> +
> + if (mem_cgroup_disabled())
> + return;
> +
> + if (!memcg)
> + memcg = root_mem_cgroup;
> +
> + if (memcg_should_flush_stats(memcg)) {
> + mutex_lock(&memcg_stats_flush_mutex);

What's the point of this mutex now? What is it providing? I understand
we can not try_lock here due to targeted flushing. Why not just let the
global rstat serialize the flushes? Actually this mutex can cause
latency hiccups as the mutex owner can get resched during flush and then
no one can flush for a potentially long time.

> + /* Check again after locking, another flush may have occurred */
> + if (memcg_should_flush_stats(memcg))
> + do_flush_stats(memcg);
> + mutex_unlock(&memcg_stats_flush_mutex);
> + }
> }