From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Hocko Subject: Re: [PATCH 3/3] mm: memcg: use non-unified stats flushing for userspace reads Date: Fri, 25 Aug 2023 20:43:01 +0200 Message-ID: References: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1692988982; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U4xhHMqMTkHY3UtOF4lG7054Cx/DuOPne55zGTv3p/I=; b=L54UpYfBJd+oU/yBURLk33U3FBt+iizgky8CMUdR7C2OKk/n8sDykjMnqTCNtTIJiCFK8M 2kKb5X2TnjG8wcxLNr5HtfAC+j0rTUawzvwmmnkJYsqWU3mxj/C/yKwTx0H/4FsLZOZqX1 dI0TevFRAy5kjcKvRhVGzzX5S4Yv6kU= Content-Disposition: inline In-Reply-To: List-ID: Content-Type: text/plain; charset="utf-8" To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org On Fri 25-08-23 11:21:16, Yosry Ahmed wrote: > On Fri, Aug 25, 2023 at 11:17 AM Michal Hocko wrote: > > > > On Fri 25-08-23 08:14:54, Yosry Ahmed wrote: > > > On Fri, Aug 25, 2023 at 12:05 AM Michal Hocko wrote: > > [...] > > > > I might be wrong but the whole discussion so far suggests that the > > > > global rstat lock should be reconsidered. From my personal experience > > > > global locks easily triggerable from the userspace are just a receip for > > > > problems. Stats reading shouldn't be interfering with the system runtime > > > > as much as possible and they should be deterministic wrt runtime as > > > > well. > > > > > > The problem is that the global lock also serializes the global > > > counters that we flush to. I will talk from the memcg flushing > > > perspective as that's what I am familiar with. I am not sure how much > > > this is transferable to other flushers. > > > > > > On the memcg side (see mem_cgroup_css_rstat_flush()), the global lock > > > synchronizes access to multiple counters, for this discussion what's > > > most important are: > > > - The global stat counters of the memcg being flushed (e.g. > > > memcg->vmstats->state). > > > - The pending stat counters of the parent being flushed (e.g. > > > parent->vmstats->state_pending). > > > > I haven't digested the rest of the email yet (Friday brain, sorry) but I > > do not think you are adressing this particular part so let me ask before > > I dive more into the following. I really do not follow the serialization > > requirement here because the lock doesn't really serialize the flushing, > > does it? At least not in a sense of a single caller to do the flushing > > atomicaly from other flushers. It is possible that the current flusher > > simply drops the lock midway and another one retakes the lock and > > performs the operation again. So what additional flushing > > synchronization does it provide and why cannot parallel flushers simply > > compete over pcp spinlocks? > > > > So what am I missing? > > Those counters are non-atomic. The lock makes sure we don't have two > concurrent flushers updating the same counter locklessly and > non-atomically, which would be possible if we flush the same cgroup on > two different cpus in parallel. pcp lock (cpu_lock) guarantees the very same, doesn't it? -- Michal Hocko SUSE Labs