public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Yosry Ahmed <yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org>,
	Shakeel Butt <shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
	Roman Gushchin
	<roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	Muchun Song <muchun.song-fxUVXftIFDnyG1zEObXtfA@public.gmane.org>,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] mm: memcg: provide accurate stats for userspace reads
Date: Mon, 14 Aug 2023 14:35:25 -1000	[thread overview]
Message-ID: <ZNrITZVTf2EILRJq@slm.duckdns.org> (raw)
In-Reply-To: <CAJD7tkYBFz-gZ2QsHxUMT=t0KNXs66S-zzMPebadHx9zaG0Q3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hello,

On Mon, Aug 14, 2023 at 05:28:22PM -0700, Yosry Ahmed wrote:
> > So, the original design used mutex for synchronize flushing with the idea
> > being that updates are high freq but reads are low freq and can be
> > relatively slow. Using rstats for mm internal operations changed this
> > assumption quite a bit and we ended up switching that mutex with a lock.
> 
> Naive question, do mutexes handle thundering herd problems better than
> spinlocks? I would assume so but I am not sure.

I don't know. We can ask Waiman if that becomes a problem.

> > * Flush-side, maybe we can break flushing into per-cpu or whatnot but
> >   there's no avoiding the fact that flushing can take quite a while if there
> >   are a lot to flush whether locks are split or not. I wonder whether it'd
> >   be possible to go back to mutex for flushing and update the users to
> >   either consume the cached values or operate in a sleepable context if
> >   synchronous read is necessary, which is the right thing to do anyway given
> >   how long flushes can take.
> 
> Unfortunately it cannot be broken down into per-cpu as all flushers
> update the same per-cgroup counters, so we need a bigger locking
> scope. Switching to atomics really hurts performance. Breaking down
> the lock to be per-cgroup is doable, but since we need to lock both
> the parent and the cgroup, flushing top-level cgroups (which I assume
> is most common) will lock the root anyway.

Plus, there's not much point in flushing in parallel, so I don't feel too
enthusiastic about splitting flush locking.

> All flushers right now operate in sleepable context, so we can go
> again to the mutex if you think this will make things better. The

Yes, I think that'd be more sane.

> slowness problem reported recently is in a sleepable context, it's
> just too slow for userspace if I understand correctly.

I mean, there's a certain amount of work to do. There's no way around it if
you wanna read the counters synchronously. The only solution there would be
using a cached value or having some sort of auto-flushing mechanism so that
the amount to flush don't build up too much - e.g. keep a count of the
number of entries to flush and trigger flush if it goes over some threshold.

Thanks.

-- 
tejun

  parent reply	other threads:[~2023-08-15  0:35 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09  4:58 [PATCH] mm: memcg: provide accurate stats for userspace reads Yosry Ahmed
     [not found] ` <20230809045810.1659356-1-yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2023-08-09  8:51   ` Michal Hocko
     [not found]     ` <ZNNTgZVPZipTL/UM-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2023-08-09 12:31       ` Yosry Ahmed
     [not found]         ` <CAJD7tkYhxbd2e+4HMZVKUfD4cx6oDauna3vLmttNPLCmFNtpgA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-09 12:58           ` Michal Hocko
2023-08-09 13:13             ` Yosry Ahmed
     [not found]               ` <CAJD7tkb9C77UUxAykw_uMQvkzGyaZOZhM0nwWn_kcPjV0umyuA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-09 13:31                 ` Michal Hocko
     [not found]                   ` <ZNOVS0Smp2PHUIuq-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2023-08-09 18:33                     ` Yosry Ahmed
     [not found]                       ` <CAJD7tkZFxbjas=VfhYSGU84Y5vyjuqHqGsRjiDEOSDWh2BxNAg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-11 12:21                         ` Michal Hocko
     [not found]                           ` <ZNYnx9NqwSsXKhX3-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2023-08-11 19:02                             ` Yosry Ahmed
     [not found]                               ` <CAJD7tkbJ1fnMDudtsS2xubKn0RTWz7t0Hem=PSRQQp3sGf-iOw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-11 19:25                                 ` Michal Hocko
     [not found]                                   ` <ZNaLGVUtPu7Ua/jL-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2023-08-11 20:39                                     ` Yosry Ahmed
     [not found]                                       ` <CAJD7tkbF1tNi8v0W4Mnqs0rzpRBshOFepxFTa1SiSvmBEBUEvw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-12  2:08                                         ` Shakeel Butt
     [not found]                                           ` <CALvZod55S3XeK-MquTq0mDuipq8j0vFymQeX_XnPb_HuPK+oGQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-12  2:11                                             ` Yosry Ahmed
     [not found]                                               ` <CAJD7tkYZxjAHrodVDK=wmz-sULJrq2VhC_5ecRP7T-KiaOcTuw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-12  2:29                                                 ` Shakeel Butt
2023-08-12  2:35                                                   ` Yosry Ahmed
     [not found]                                                     ` <CAJD7tkY-ezyYebvcs=8Z_zrw2UVW8jf2WvP1G8tu2rT=2sMnAA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-12  2:48                                                       ` Shakeel Butt
     [not found]                                                         ` <CALvZod5fH9xu_+6x85K38f63GfKGWD1LqtD2R4d09xmDtLB7ew-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-12  8:35                                                           ` Michal Hocko
     [not found]                                                             ` <ZNdEaw2nktq1NfmH-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2023-08-12 11:04                                                               ` Yosry Ahmed
2023-08-15  0:14                                                                 ` Tejun Heo
     [not found]                                                                   ` <ZNrDWqfjXtAYhnvT-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2023-08-15  0:28                                                                     ` Yosry Ahmed
     [not found]                                                                       ` <CAJD7tkYBFz-gZ2QsHxUMT=t0KNXs66S-zzMPebadHx9zaG0Q3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-15  0:35                                                                         ` Tejun Heo [this message]
     [not found]                                                                           ` <ZNrITZVTf2EILRJq-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2023-08-15  0:39                                                                             ` Yosry Ahmed
     [not found]                                                                               ` <CAJD7tkaXwoF-faApweAmm7Db7jAuS3EO7hVvdyVtqW_rE+T9Vg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-15  0:47                                                                                 ` Tejun Heo
2023-08-15  0:50                                                                                   ` Yosry Ahmed
     [not found]                                                                                     ` <CAJD7tkYgCySTX28zK9GZiWwsabR4nv7M2hQ57y12si-fqtv7zg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-16  0:23                                                                                       ` Shakeel Butt
     [not found]                                                                                         ` <CALvZod6KRxiDzrppCgx+=SHg2+96nFE5crwXCKwe9PZbWM_6cQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-16  0:29                                                                                           ` Yosry Ahmed
     [not found]                                                                                             ` <CAJD7tkaUzhvZPohpo1F8TUKRPuXH7bjDeg9VCzN2CbywQbRutQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-16  1:14                                                                                               ` Shakeel Butt
     [not found]                                                                                                 ` <CALvZod6HUtYhDaXiwXSrcwfxLSrZ37sZhKY1Mg4kmpDFk13aYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-16  2:19                                                                                                   ` Yosry Ahmed
     [not found]                                                                                                     ` <CAJD7tkYzr2cg-aQ899vfqB4jR7iP83t8f-Z4AH8d9iW-yw-nnQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-08-16 17:11                                                                                                       ` Shakeel Butt
2023-08-16 19:08                                                                                                         ` Tejun Heo
     [not found]                                                                                                           ` <ZN0eqq4hLRYQPHCI-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2023-08-16 22:35                                                                                                             ` Yosry Ahmed
2023-08-18 21:40                                                                                                               ` Yosry Ahmed
2023-08-21 20:58                                                                                                                 ` Yosry Ahmed
2023-08-15 15:44                                                                             ` Waiman Long
     [not found]             ` <ZNONgeoytpkchHga-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2023-08-09 13:17               ` 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=ZNrITZVTf2EILRJq@slm.duckdns.org \
    --to=tj-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
    --cc=mhocko-IBi9RG/b67k@public.gmane.org \
    --cc=muchun.song-fxUVXftIFDnyG1zEObXtfA@public.gmane.org \
    --cc=roman.gushchin-fxUVXftIFDnyG1zEObXtfA@public.gmane.org \
    --cc=shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=yosryahmed-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.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