From patchwork Thu Jun 8 17:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 13272645 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 93133C7EE25 for ; Thu, 8 Jun 2023 17:13:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 125238E0002; Thu, 8 Jun 2023 13:13:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AE9D8E0001; Thu, 8 Jun 2023 13:13:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E90B98E0002; Thu, 8 Jun 2023 13:13:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D52C28E0001 for ; Thu, 8 Jun 2023 13:13:11 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 95668A02E8 for ; Thu, 8 Jun 2023 17:13:11 +0000 (UTC) X-FDA: 80880226182.24.704A361 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf23.hostedemail.com (Postfix) with ESMTP id A4AEA140006 for ; Thu, 8 Jun 2023 17:13:09 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=O8ZJ8Pyi; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf23.hostedemail.com: domain of mkoutny@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mkoutny@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686244390; 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: references:dkim-signature; bh=zcwvri9EO5NgmPKueOn7NC6SyLLY9pSstgNvXylAdIw=; b=KmVG+9ck8ICxAnHdLm92fKSDxLqGj8akK6CqWz2rIcp1gSX0LbeWGCJgsJikSGdfT9DGnN wffZwJ3eBFsiIfH+M0gxt+anKYtmQh0UnZATX3erV9LIyjANRXas2cGha0qMgD//dprDKm 3vRuJHdWrtPCkXOZC8q+T89tkciMi8E= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=O8ZJ8Pyi; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf23.hostedemail.com: domain of mkoutny@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mkoutny@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686244390; a=rsa-sha256; cv=none; b=NFxH43UMFppl5qnfdl3q9nnAUi9RUD/CMfi+BDnWrQSRCahY6fY2bs282YMqhV6Ej+hd3a 4tC8U+KYHpjplVdgzPnMYo0Ll5bo7VlK0J9QgYH6LwwoYtO3vAw+siDLSLDCeDye3GKc0T 8s/P4x/jyNiq7oABEDGZbtYHtqCM7XA= 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 EA395219BC; Thu, 8 Jun 2023 17:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1686244387; 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; bh=zcwvri9EO5NgmPKueOn7NC6SyLLY9pSstgNvXylAdIw=; b=O8ZJ8Pyiu6ad1fjW2LpeHDPLJm7yd9dnHlsYk6/29iqbd/j4jp1uSSzrWqlHs1/Eg2Jorv Dq0BwIHM7DD0/T2Lod56QaRJCVwuDwMeYtE5XAzcfiBFt4c9kRGImzGMGSUYfBbJ2jolAj DJfbtf2g2NizOT63NJ91uTvf3xskc20= 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 A358813480; Thu, 8 Jun 2023 17:13:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Glv/JiMMgmQ5SQAAMHmgww (envelope-from ); Thu, 08 Jun 2023 17:13:07 +0000 From: =?utf-8?q?Michal_Koutn=C3=BD?= To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Christian Brauner , "Liam R . Howlett" , Suren Baghdasaryan , "Michael S . Tsirkin" , Mike Christie , Andrei Vagin , Mathieu Desnoyers , Nicholas Piggin , Peter Zijlstra , Shakeel Butt , Adam Majer , Jan Kara , Michal Hocko Subject: [RFC PATCH] mm: Sync percpu mm RSS counters before querying Date: Thu, 8 Jun 2023 19:12:56 +0200 Message-Id: <20230608171256.17827-1-mkoutny@suse.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A4AEA140006 X-Stat-Signature: 7kfdqdodonnfudy6orad7gyxppy35f3p X-Rspam-User: X-HE-Tag: 1686244389-783802 X-HE-Meta: U2FsdGVkX19eoxUFhwZnrb7jdHyledN+3VSfj+N2saIJ1ACdJ1xo5Yw94yZytIzlLLAZf2pyu9ezL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2KBo3mR+3iayNt9bDSqFY56v/20EmgSPoMAWasLhbi3RY8CeLlMMPylB3GjnVMFlY6OfrIdK7zjuI70d+7CALoByIAA= 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: An issue was observed with stats collected in struct rusage on ppc64le with 64kB pages. The percpu counters use batching with percpu_counter_batch = max(32, nr*2) # in PAGE_SIZE i.e. with larger pages but similar RSS consumption (bytes), there'll be less flushes and error more noticeable. In this given case (getting consumption of exited child), we can request percpu counter's flush without worrying about contention with updaters. Fortunately, the commit f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter") didn't eradicate all traces of SPLIT_RSS_COUNTING and this mechanism already provided some synchronization points before reading stats. Therefore, use sync_mm_rss as carrier for percpu counters refreshes and forget SPLIT_RSS_COUNTING macro for good. Fixes: f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter") Reported-by: Adam Majer Signed-off-by: Michal Koutný --- include/linux/mm.h | 6 ++---- kernel/fork.c | 4 ---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 27ce77080c79..30cfde88d5b2 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2547,13 +2547,11 @@ static inline void setmax_mm_hiwater_rss(unsigned long *maxrss, *maxrss = hiwater_rss; } -#if defined(SPLIT_RSS_COUNTING) -void sync_mm_rss(struct mm_struct *mm); -#else static inline void sync_mm_rss(struct mm_struct *mm) { + for (int i = 0; i < NR_MM_COUNTERS; ++i) + percpu_counter_sum(&mm->rss_stat[i]); } -#endif #ifndef CONFIG_ARCH_HAS_PTE_SPECIAL static inline int pte_special(pte_t pte) diff --git a/kernel/fork.c b/kernel/fork.c index 81cba91f30bb..e030eb902e4b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2412,10 +2412,6 @@ __latent_entropy struct task_struct *copy_process( p->io_uring = NULL; #endif -#if defined(SPLIT_RSS_COUNTING) - memset(&p->rss_stat, 0, sizeof(p->rss_stat)); -#endif - p->default_timer_slack_ns = current->timer_slack_ns; #ifdef CONFIG_PSI