From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A658C3DA66 for ; Fri, 25 Aug 2023 18:43:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D2672800C1; Fri, 25 Aug 2023 14:43:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 259B82800C0; Fri, 25 Aug 2023 14:43:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D4FF2800C1; Fri, 25 Aug 2023 14:43:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EE6812800C0 for ; Fri, 25 Aug 2023 14:43:06 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C32731A0711 for ; Fri, 25 Aug 2023 18:43:06 +0000 (UTC) X-FDA: 81163499172.09.97DD04F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf19.hostedemail.com (Postfix) with ESMTP id C2CA71A0014 for ; Fri, 25 Aug 2023 18:43:03 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=L54UpYfB; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf19.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692988985; a=rsa-sha256; cv=none; b=vCCZ0AIk+iQgWH0QADI69W5kZU0iH7iq52MZOj+bNC9Sxs6fGrzGLPrsvbd5Qeu+jGPPLT WuC2IEhYdpUhnJZXnRyuQWqz9B8Xb/x77uxPXbpwJvWKeclf7n6yaR2fh7QVI86269mAnl LCev0GoQhHmRSnzF8uv5EL7YXDJ/u5Y= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=L54UpYfB; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf19.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692988985; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=U4xhHMqMTkHY3UtOF4lG7054Cx/DuOPne55zGTv3p/I=; b=LtXHwugVAp94mw01vLvG98dB6tT/eipVtWYdyEDx9u/p707zO4v1/LgjcbhUzA3aTtEtaM 8UwynmmxQ5TjcLYlriQRZH9LCs9mR69CwCu9D7NTN0g6m3u++kyxLd/7vqGe9ZlAWjRkts ZmgjDb4UWag+zWsZGL15A4TdjgkK6MA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9D26321869; Fri, 25 Aug 2023 18:43:02 +0000 (UTC) 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= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 73801138F9; Fri, 25 Aug 2023 18:43:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bzmsGDb26GQUBwAAMHmgww (envelope-from ); Fri, 25 Aug 2023 18:43:02 +0000 Date: Fri, 25 Aug 2023 20:43:01 +0200 From: Michal Hocko To: Yosry Ahmed Cc: Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , 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 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C2CA71A0014 X-Stat-Signature: 5o4s66ei39hrmuxfssatxigigzr9ea3o X-HE-Tag: 1692988983-164382 X-HE-Meta: U2FsdGVkX18O6DOKIdN5MdcXx/gbA9zsugcCrpNMoexLB7T0Ed2ax75J5+ivj1cxmew3lPy5pgwrNxFxt7W73tl9h+W9u55nRZOxQDu6GIcrvsPF7oVzGaJZAykwaOCw3fYCcMMhMCxwdrXLhY8Fqe38cjIZ+7huEVdLUNKTLGpv3Bup2QuK3CxNqhGSkYSgEF9QmpNvtkNCbwNci7gRr+TcXsYPOd6rHOT6T8XAF3fBIKvMmpsASUHQJDubvogp2K1GVVlxEZKesvafBLNE6jx8xlfMwlpC8hDCel6c2FMohhUEQ4EzPPaQ3uf71VXjbOYxnrrJMgJgvLHD9vxi2YXLNHjWetH7gFARjXzTfyZuTWwEQ1sicAQ5/PIqLI/6iICJ0a1ig2pCsT/ZOAtsazp7s/C8/DaDt+5xR0oycQHLaYnesf/CA8V6sYXwLslLeGJGjYVlfenE8Ba8TkweHxk2EGxNzXmA7yaVWwznFVkoKDfzGEmvLCqfxlS9FpKit+N9E3Yg4teFGTw+hWZBJeldj7MJqFWdggh6cysdvikWFUAnTLAznNPomGsOtMqlsEuhXDejrk84W2hZnhCcwghYMKh5GIK0DMBwTFmLREE+IaAoPatkhfY9fSFespTO8joG1sHgTsmOFhEirzT6KDOKXG+uN5g2OPcJo7XFYggZW4k5YPMpWcSrlivE/e3bZBzoyw2doH6G4y2SSgCURtbGmHFQXhZyn8fbmKAbr/dgvh3WKwFjbDTJYNqPWypqwlfxmJKtcBRaGaC17VHBone5j+SkPgiSXEqzWLbWg2iPoNBumUzSS5IhRTRRRs7HKgGRquuFDFWiaeqt5M7mmtPg034RfKUTCxyGHjZC48vvy2Ti5RVP15wh5Kn0bStqynSWSz16qVvZozU8ugSZZjl+Xduv51cG+TrMXYXvJV66TcfhJIuCq2pZEt8R+AuAbnyEsF2BZL/5fwH1ro7 A4xrTyAq EDePsSW9Kxwga37wHS5kGcdcRXStw0oQ7AhsXDq7XJYzVhNhHmZXwmMJAVkBDrZe79FhVLro7MZvI1XtiVsgBwWOGDDxI93HSrbvhFCyp6yDzxFG4PWBJ6rhSy191fcWhiHYDEMZD83lau/J3vN9L/tA9opiYsOHpp099BbkMm6VE1aOXrLTJ1mjqyFZQ64kia/LWTZtlvXapAFs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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