From: Yosry Ahmed <yosryahmed@google.com>
To: Jesper Dangaard Brouer <hawk@kernel.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
tj@kernel.org, cgroups@vger.kernel.org, hannes@cmpxchg.org,
lizefan.x@bytedance.com, longman@redhat.com,
kernel-team@cloudflare.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH V4 2/2] cgroup/rstat: Avoid thundering herd problem by kswapd across NUMA nodes
Date: Tue, 16 Jul 2024 14:54:12 -0700 [thread overview]
Message-ID: <CAJD7tkYX9OaAyWg=L_5v7GaKtKmptPpMGJh7Org5tcY4D-YnCw@mail.gmail.com> (raw)
In-Reply-To: <9a7930b9-dec0-418c-8475-5a7e18b3ec68@kernel.org>
On Mon, Jul 8, 2024 at 8:26 AM Jesper Dangaard Brouer <hawk@kernel.org> wrote:
>
>
> On 28/06/2024 11.39, Jesper Dangaard Brouer wrote:
> >
> >
> > On 28/06/2024 01.34, Shakeel Butt wrote:
> >> On Thu, Jun 27, 2024 at 11:18:56PM GMT, Jesper Dangaard Brouer wrote:
> >>> Avoid lock contention on the global cgroup rstat lock caused by kswapd
> >>> starting on all NUMA nodes simultaneously. At Cloudflare, we observed
> >>> massive issues due to kswapd and the specific mem_cgroup_flush_stats()
> >>> call inlined in shrink_node, which takes the rstat lock.
> >>>
> [...]
> >>> static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu);
> >>> @@ -312,6 +315,45 @@ static inline void __cgroup_rstat_unlock(struct
> >>> cgroup *cgrp, int cpu_in_loop)
> >>> spin_unlock_irq(&cgroup_rstat_lock);
> >>> }
> >>> +#define MAX_WAIT msecs_to_jiffies(100)
> >>> +/* Trylock helper that also checks for on ongoing flusher */
> >>> +static bool cgroup_rstat_trylock_flusher(struct cgroup *cgrp)
> >>> +{
> >>> + bool locked = __cgroup_rstat_trylock(cgrp, -1);
> >>> + if (!locked) {
> >>> + struct cgroup *cgrp_ongoing;
> >>> +
> >>> + /* Lock is contended, lets check if ongoing flusher is already
> >>> + * taking care of this, if we are a descendant.
> >>> + */
> >>> + cgrp_ongoing = READ_ONCE(cgrp_rstat_ongoing_flusher);
> >>> + if (cgrp_ongoing && cgroup_is_descendant(cgrp, cgrp_ongoing)) {
> >>
> >> I wonder if READ_ONCE() and cgroup_is_descendant() needs to happen
> >> within in rcu section. On a preemptable kernel, let's say we got
> >> preempted in between them, the flusher was unrelated and got freed
> >> before we get the CPU. In that case we are accessing freed memory.
> >>
> >
> > I have to think about this some more.
> >
>
> I don't think this is necessary. We are now waiting (for completion) and
> not skipping flush, because as part of take down function
> cgroup_rstat_exit() is called, which will call cgroup_rstat_flush().
>
>
> void cgroup_rstat_exit(struct cgroup *cgrp)
> {
> int cpu;
> cgroup_rstat_flush(cgrp);
>
>
Sorry for the late response, I was traveling for a bit. I will take a
look at your most recent version shortly. But I do have a comment
here.
I don't see how this addresses Shakeel's concern. IIUC, if the cgroup
was freed after READ_ONCE() (and cgroup_rstat_flush() was called),
then cgroup_is_descendant() will access freed memory. We are not
holding the lock here so we are not preventing cgroup_rstat_flush()
from being called for the freed cgroup, right?
next prev parent reply other threads:[~2024-07-16 21:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-27 21:18 [PATCH V4 1/2] cgroup/rstat: Helper functions for locking expose trylock Jesper Dangaard Brouer
2024-06-27 21:18 ` [PATCH V4 2/2] cgroup/rstat: Avoid thundering herd problem by kswapd across NUMA nodes Jesper Dangaard Brouer
2024-06-27 23:34 ` Shakeel Butt
2024-06-28 9:39 ` Jesper Dangaard Brouer
2024-06-28 22:15 ` Yosry Ahmed
2024-07-02 10:35 ` Jesper Dangaard Brouer
2024-07-02 12:00 ` Yosry Ahmed
2024-07-08 15:26 ` Jesper Dangaard Brouer
2024-07-16 21:54 ` Yosry Ahmed [this message]
2024-07-17 7:46 ` Jesper Dangaard Brouer
2024-07-17 16:04 ` Yosry Ahmed
2024-06-27 22:22 ` [PATCH V4 1/2] cgroup/rstat: Helper functions for locking expose trylock Waiman Long
2024-06-28 1:06 ` Waiman Long
2024-06-28 12:13 ` Jesper Dangaard Brouer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJD7tkYX9OaAyWg=L_5v7GaKtKmptPpMGJh7Org5tcY4D-YnCw@mail.gmail.com' \
--to=yosryahmed@google.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hawk@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox