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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E10BCEE49A5 for ; Fri, 25 Aug 2023 18:18:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbjHYSRz (ORCPT ); Fri, 25 Aug 2023 14:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233311AbjHYSRq (ORCPT ); Fri, 25 Aug 2023 14:17:46 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C1A2D4C; Fri, 25 Aug 2023 11:17:29 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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