[PATCH] mm: memcg: remove stats flushing mutex

From: Yosry Ahmed
Date: Mon Dec 04 2023 - 18:43:29 EST


The mutex was intended to make the waiters sleep instead of spin, and
such that we can check the update thresholds again after acquiring the
mutex. However, the mutex has a risk of priority inversion, especially
since the underlying rstat lock can de dropped while the mutex is held.

Synthetic testing with high concurrency of flushers shows no
regressions without the mutex, so remove it.

Suggested-by: Shakeel Butt <shakeelb@xxxxxxxxxx>
Signed-off-by: Yosry Ahmed <yosryahmed@xxxxxxxxxx>
---
mm/memcontrol.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5d300318bf18a..0563625767349 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -749,21 +749,14 @@ static void do_flush_stats(struct mem_cgroup *memcg)
*/
void mem_cgroup_flush_stats(struct mem_cgroup *memcg)
{
- static DEFINE_MUTEX(memcg_stats_flush_mutex);
-
if (mem_cgroup_disabled())
return;

if (!memcg)
memcg =3D root_mem_cgroup;

- if (memcg_should_flush_stats(memcg)) {
- mutex_lock(&memcg_stats_flush_mutex);
- /* Check again after locking, another flush may have occurr=
ed */
- if (memcg_should_flush_stats(memcg))
- do_flush_stats(memcg);
- mutex_unlock(&memcg_stats_flush_mutex);
- }
+ if (memcg_should_flush_stats(memcg))
+ do_flush_stats(memcg);
}

void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg)
--
2.43.0.rc2.451.g8631bc7472-goog