[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZCQn86f7sxBt6tyN@dhcp22.suse.cz>
Date: Wed, 29 Mar 2023 13:58:43 +0200
From: Michal Hocko <mhocko@...e.com>
To: Yosry Ahmed <yosryahmed@...gle.com>
Cc: Tejun Heo <tj@...nel.org>, Josef Bacik <josef@...icpanda.com>,
Jens Axboe <axboe@...nel.dk>,
Zefan Li <lizefan.x@...edance.com>,
Johannes Weiner <hannes@...xchg.org>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Shakeel Butt <shakeelb@...gle.com>,
Muchun Song <muchun.song@...ux.dev>,
Andrew Morton <akpm@...ux-foundation.org>,
Michal Koutný <mkoutny@...e.com>,
Vasily Averin <vasily.averin@...ux.dev>,
cgroups@...r.kernel.org, linux-block@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
bpf@...r.kernel.org
Subject: Re: [PATCH v2 3/9] memcg: do not flush stats in irq context
On Tue 28-03-23 22:16:38, Yosry Ahmed wrote:
> Currently, the only context in which we can invoke an rstat flush from
> irq context is through mem_cgroup_usage() on the root memcg when called
> from memcg_check_events(). An rstat flush is an expensive operation that
> should not be done in irq context, so do not flush stats and use the
> stale stats in this case.
>
> Arguably, usage threshold events are not reliable on the root memcg
> anyway since its usage is ill-defined.
>
> Suggested-by: Johannes Weiner <hannes@...xchg.org>
> Suggested-by: Shakeel Butt <shakeelb@...gle.com>
> Signed-off-by: Yosry Ahmed <yosryahmed@...gle.com>
> Acked-by: Shakeel Butt <shakeelb@...gle.com>
> Acked-by: Johannes Weiner <hannes@...xchg.org>
Acked-by: Michal Hocko <mhocko@...e.com>
> ---
> mm/memcontrol.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index c3b6aae78901..ff39f78f962e 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3669,7 +3669,21 @@ static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
> unsigned long val;
>
> if (mem_cgroup_is_root(memcg)) {
> - mem_cgroup_flush_stats();
> + /*
> + * We can reach here from irq context through:
> + * uncharge_batch()
> + * |--memcg_check_events()
> + * |--mem_cgroup_threshold()
> + * |--__mem_cgroup_threshold()
> + * |--mem_cgroup_usage
> + *
> + * rstat flushing is an expensive operation that should not be
> + * done from irq context; use stale stats in this case.
> + * Arguably, usage threshold events are not reliable on the root
> + * memcg anyway since its usage is ill-defined.
> + */
> + if (in_task())
> + mem_cgroup_flush_stats();
> val = memcg_page_state(memcg, NR_FILE_PAGES) +
> memcg_page_state(memcg, NR_ANON_MAPPED);
> if (swap)
> --
> 2.40.0.348.gf938b09366-goog
--
Michal Hocko
SUSE Labs
Powered by blists - more mailing lists