[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALvZod434VzPru+wcO=PgMDeCs6KPgR06MuGVttaDD64_z3QMw@mail.gmail.com>
Date: Tue, 27 Jul 2021 09:59:57 -0700
From: Shakeel Butt <shakeelb@...gle.com>
To: Johannes Weiner <hannes@...xchg.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Dan Carpenter <dan.carpenter@...cle.com>,
Linux MM <linux-mm@...ck.org>,
Cgroups <cgroups@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH] mm: memcontrol: fix blocking rstat function called from
atomic cgroup1 thresholding code
On Mon, Jul 26, 2021 at 8:01 AM Johannes Weiner <hannes@...xchg.org> wrote:
>
> Dan Carpenter reports:
>
> The patch 2d146aa3aa84: "mm: memcontrol: switch to rstat" from Apr
> 29, 2021, leads to the following static checker warning:
>
> kernel/cgroup/rstat.c:200 cgroup_rstat_flush()
> warn: sleeping in atomic context
>
> mm/memcontrol.c
> 3572 static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
> 3573 {
> 3574 unsigned long val;
> 3575
> 3576 if (mem_cgroup_is_root(memcg)) {
> 3577 cgroup_rstat_flush(memcg->css.cgroup);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> This is from static analysis and potentially a false positive. The
> problem is that mem_cgroup_usage() is called from __mem_cgroup_threshold()
> which holds an rcu_read_lock(). And the cgroup_rstat_flush() function
> can sleep.
>
> 3578 val = memcg_page_state(memcg, NR_FILE_PAGES) +
> 3579 memcg_page_state(memcg, NR_ANON_MAPPED);
> 3580 if (swap)
> 3581 val += memcg_page_state(memcg, MEMCG_SWAP);
> 3582 } else {
> 3583 if (!swap)
> 3584 val = page_counter_read(&memcg->memory);
> 3585 else
> 3586 val = page_counter_read(&memcg->memsw);
> 3587 }
> 3588 return val;
> 3589 }
>
> __mem_cgroup_threshold() indeed holds the rcu lock. In addition, the
> thresholding code is invoked during stat changes, and those contexts
> have irqs disabled as well. If the lock breaking occurs inside the
> flush function, it will result in a sleep from an atomic context.
>
> Use the irsafe flushing variant in mem_cgroup_usage() to fix this.
>
> Fixes: 2d146aa3aa84 ("mm: memcontrol: switch to rstat")
> Cc: <stable@...r.kernel.org>
> Reported-by: Dan Carpenter <dan.carpenter@...cle.com>
> Signed-off-by: Johannes Weiner <hannes@...xchg.org>
Reviewed-by: Shakeel Butt <shakeelb@...gle.com>
BTW what do you think of removing stat flushes from the read side
(kernel and userspace) completely after periodic flushing and async
flushing from update side? Basically with "memcg: infrastructure to
flush memcg stats".
Powered by blists - more mailing lists