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 2151FC3DA6F for ; Fri, 25 Aug 2023 18:17:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61BE02800BD; Fri, 25 Aug 2023 14:17:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A44E2800BC; Fri, 25 Aug 2023 14:17:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 445D02800BD; Fri, 25 Aug 2023 14:17:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2FDF12800BC for ; Fri, 25 Aug 2023 14:17:32 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C6AE8C076C for ; Fri, 25 Aug 2023 18:17:31 +0000 (UTC) X-FDA: 81163434702.06.5B66AD7 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf21.hostedemail.com (Postfix) with ESMTP id 7AAAD1C0015 for ; Fri, 25 Aug 2023 18:17:29 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=M4FFeikA; spf=pass (imf21.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692987450; 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=ujuMMocBltnOMhznVm766I5QPcNC5qT9zu3nsGMBN7k=; b=fXi1grZLsyp5s0Acjow/rfISBy+WTdNymZxcPDc9cwsHL5+f0Gz6YhYIGB/qFTMNL2Lr1l munfaUhnejmH7iw7TVoraS5GfhJXmJOdthluxU8d2JVPyzHJ3polfefT7D7Jd1TBcQbd1J Gtbh+TH6QJ9XitsVWuEA+LRzsJMiMz4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=M4FFeikA; spf=pass (imf21.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692987450; a=rsa-sha256; cv=none; b=Ayw8Z9OpDvd2hZpuN+IX21EGVU9kvCScy1XzOJCLfauHD5c2ADNDC+Q/aEkMG/X2k21TzI g9GZgFwbnS0j/PmSnSj4mHMikKVBr2OMc34Cj98C3uZiLkXeaKODnxL8/gO//1wvL76xnv xENykbj2CJ0qA7HbafofLR8dFwaQCwg= 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 4B7ED2211E; Fri, 25 Aug 2023 18:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1692987446; 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=ujuMMocBltnOMhznVm766I5QPcNC5qT9zu3nsGMBN7k=; b=M4FFeikAxZfvdQpVl5oyAbEUXrkd22eQQW0u3Q3anuDTciGLnuliGADRpNoIGawDN1ZmMY 6fAymp2LCV4dgFGDtXNjsddXL0o3f+R+xKxtTKxVi40aMLSo8p7XCC5kHcMte/K+8dKowN dLGqToSCjHoMOQ+TElfmbfSRoxpUA+E= 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 27E68138F9; Fri, 25 Aug 2023 18:17:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vPnBBjbw6GRQfAAAMHmgww (envelope-from ); Fri, 25 Aug 2023 18:17:26 +0000 Date: Fri, 25 Aug 2023 20:17:25 +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: <20230821205458.1764662-4-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 7AAAD1C0015 X-Rspam-User: X-Stat-Signature: q8oojmr6uxw3gksmxnxpdsfn5r314zuo X-Rspamd-Server: rspam01 X-HE-Tag: 1692987449-912523 X-HE-Meta: U2FsdGVkX18HbnPfmz+69lHocTGb5xkmuVxHL+vEdwRBkLG6tkz3UGzsIfu1XMvAwphovWuAG9lQqkfWS9cLLv4Ocgccu82z1yEOiv2bljmiczmW6QqZVl6KEVIMSfNrHr8iv+ViLhb1XfonIhJhtx3miw4mHVE2GCCEqlKx6okrcJ9vU6RH6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precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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? -- Michal Hocko SUSE Labs