From: Yosry Ahmed <yosryahmed@google.com>
To: Tejun Heo <tj@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeelb@google.com>,
Muchun Song <muchun.song@linux.dev>,
Ivan Babrou <ivan@cloudflare.com>,
linux-mm@kvack.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] mm: memcg: use non-unified stats flushing for userspace reads
Date: Tue, 29 Aug 2023 13:20:34 -0700 [thread overview]
Message-ID: <CAJD7tkZn_7ppFB1B1V8tBEw12LXCnEOue2Beq6e19PkUAVHUSQ@mail.gmail.com> (raw)
In-Reply-To: <ZO5RROsZ1VESCsMG@slm.duckdns.org>
On Tue, Aug 29, 2023 at 1:12 PM Tejun Heo <tj@kernel.org> wrote:
>
> Hello,
>
> On Tue, Aug 29, 2023 at 12:54:06PM -0700, Yosry Ahmed wrote:
> ...
> > > Maybe leave the global lock as-is and gate the userland flushers with a
> > > mutex so that there's only ever one contenting on the rstat lock from
> > > userland side?
> >
> > Waiman suggested this as well. We can do that for sure, although I
> > think we should wait until we are sure it's needed.
> >
> > One question. If whoever is holding that mutex is either flushing with
> > the spinlock held or spinning (i.e not sleepable or preemptable),
> > wouldn't this be equivalent to just changing the spinlock with a mutex
> > and disable preemption while holding it?
>
> Well, it creates layering so that userspace can't flood the inner lock which
> can cause contention issues for kernel side users. Not sleeping while
> actively flushing is an side-effect too but the code at least doesn't look
> as anti-patterny as disabling preemption right after grabbing a mutex.
I see. At most one kernel side flusher will be spinning for the lock
at any given point anyway, but I guess having that one kernel side
flusher competing against one user side flusher is better competing
with N flushers.
I will add a mutex on the userspace read side then and spin a v3.
Hopefully this addresses Michal's concern as well. The lock dropping
logic will still exist for the inner lock, but when one userspace
reader drops the inner lock other readers won't be able to pick it up.
>
> I don't have a strong preference. As long as we stay away from introducing a
> new user interface construct and can address the noticed scalability issues,
> it should be fine. Note that there are other ways to address priority
> inversions and contentions too - e.g. we can always bounce flushing to a
> [kthread_]kworker and rate limit (or rather latency limit) how often
> different classes of users can trigger flushing. I don't think we have to go
> there yet but if the simpler meaures don't work out, there are still many
> ways to solve the problem within the kernel.
I whole-heartedly agree with the preference to fix the problem within
the kernel with minimal/none user space involvement.
Thanks!
next prev parent reply other threads:[~2023-08-29 20:21 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-21 20:54 [PATCH 0/3] memcg: non-unified flushing for userspace stats Yosry Ahmed
2023-08-21 20:54 ` [PATCH 1/3] mm: memcg: properly name and document unified stats flushing Yosry Ahmed
2023-08-21 20:54 ` [PATCH 2/3] mm: memcg: add a helper for non-unified " Yosry Ahmed
2023-08-22 13:01 ` Michal Koutný
2023-08-22 16:00 ` Yosry Ahmed
2023-08-22 16:35 ` Michal Koutný
2023-08-22 16:48 ` Yosry Ahmed
2023-08-21 20:54 ` [PATCH 3/3] mm: memcg: use non-unified stats flushing for userspace reads Yosry Ahmed
2023-08-22 9:06 ` Michal Hocko
2023-08-22 15:30 ` Yosry Ahmed
2023-08-23 7:33 ` Michal Hocko
2023-08-23 14:55 ` Yosry Ahmed
2023-08-24 7:13 ` Michal Hocko
2023-08-24 18:15 ` Yosry Ahmed
2023-08-24 18:50 ` Yosry Ahmed
2023-08-25 7:05 ` Michal Hocko
2023-08-25 15:14 ` Yosry Ahmed
2023-08-25 18:17 ` Michal Hocko
2023-08-25 18:21 ` Yosry Ahmed
2023-08-25 18:43 ` Michal Hocko
2023-08-25 18:44 ` Michal Hocko
2023-08-28 15:47 ` Michal Hocko
2023-08-28 16:15 ` Yosry Ahmed
2023-08-28 17:00 ` Shakeel Butt
2023-08-28 17:07 ` Yosry Ahmed
2023-08-28 17:27 ` Waiman Long
2023-08-28 17:28 ` Yosry Ahmed
2023-08-28 17:35 ` Waiman Long
2023-08-28 17:43 ` Waiman Long
2023-08-28 18:35 ` Yosry Ahmed
2023-08-29 7:27 ` Michal Hocko
2023-08-29 15:05 ` Waiman Long
2023-08-29 15:17 ` Michal Hocko
2023-08-29 16:04 ` Yosry Ahmed
2023-08-29 18:44 ` Tejun Heo
2023-08-29 19:13 ` Yosry Ahmed
2023-08-29 19:36 ` Tejun Heo
2023-08-29 19:54 ` Yosry Ahmed
2023-08-29 20:12 ` Tejun Heo
2023-08-29 20:20 ` Yosry Ahmed [this message]
2023-08-31 9:05 ` Michal Hocko
2023-08-22 13:00 ` [PATCH 0/3] memcg: non-unified flushing for userspace stats Michal Koutný
2023-08-22 15:43 ` Yosry Ahmed
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=CAJD7tkZn_7ppFB1B1V8tBEw12LXCnEOue2Beq6e19PkUAVHUSQ@mail.gmail.com \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=ivan@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
--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