From patchwork Mon Jul 15 12:48:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733440 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 205EFC3DA59 for ; Mon, 15 Jul 2024 12:49:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EF686B0095; Mon, 15 Jul 2024 08:49:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89C8F6B0096; Mon, 15 Jul 2024 08:49:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 714A26B0098; Mon, 15 Jul 2024 08:49:23 -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 4910C6B0095 for ; Mon, 15 Jul 2024 08:49:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 10C771A168D for ; Mon, 15 Jul 2024 12:49:23 +0000 (UTC) X-FDA: 82341967806.03.EA68E7E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 4D5EDC0016 for ; Mon, 15 Jul 2024 12:49:20 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gTkc25ss; spf=pass (imf22.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721047741; a=rsa-sha256; cv=none; b=PrzKQbPyZtqZd9lQXPhDTdrV+w5paHOJw0keNYXhU505R2NUxcHWsJRUmFC8S3w/L6t3Y2 Bl49oKEb6Yp/IAx9UUxI3SfzpX/IADpJS3qxtnM3np+cQ2c3HzyPZDFN+mpkv2vbXgu843 F9vw72r71aQv5RWbnSmj9TI4HAXi390= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gTkc25ss; spf=pass (imf22.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721047741; 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=VTMfzdrp27uG47UaiooorN5rUMq6f5kc/ISsASb0PyQ=; b=eka80/7EpFOl7mO24Q6EVmxWhxumR81wep2sfHEC0vjfL/mKqyLzfcUkHWHsoXK/hqv27N L6DC63Qkjfmj05GAdl6/1Ysyvl9LdJaADCZPjKxy8Ny26r4WmbU/qGob/DWXLjBRSBpaph 7tmLV1LB6Xsy2os9+S+aNSdtz+Y2L8g= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9B3D9610A2; Mon, 15 Jul 2024 12:49:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9369C4AF0F; Mon, 15 Jul 2024 12:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047759; bh=HU6vitpuM/kW1drnmaJbobayjjiX3I313g5+a5XkSf4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gTkc25ssg6JIYDP5yx56GycmMYuUfPA/FzBDPYtSausd5bgyrigtG6xODVb8OFUDc W55GGEX8O4LsV/vWIWiJXaEW57ho7kAdFYc7OntI/7DGEEG+UzzuKwUgoTgXmVHr0D nskM2bOoF9umr01Z2oPfDiJh31unMRdMxVeWkCddFmP5YTNa9cufjicwUcxSdODguS x/ocBfBFbu7LbPcwHdrStZ3DkRPrwj281kjkwLf2LxHJWPf+PfUse8dL0zznuS0lL/ BhOIYPIVsO7NG9BM274kgSdWSBGLKQn3Azf6ARWdsZ/uEBb4sVuN+Qrt/08zmgfGyr Zgy/6fN8dnQHA== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:54 -0400 Subject: [PATCH v6 3/9] fs: add percpu counters for significant multigrain timestamp events MIME-Version: 1.0 Message-Id: <20240715-mgtime-v6-3-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4074; i=jlayton@kernel.org; h=from:subject:message-id; bh=HU6vitpuM/kW1drnmaJbobayjjiX3I313g5+a5XkSf4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrCYPk7Gycow3R8t8u9VHqvaLk0qL2DGj/tC M6baL/u3SKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawgAKCRAADmhBGVaC FfCpD/wO35AVGJ7f4oBU8BPuQpqmK72PLEFjcoUJMSz/9hbuLYnDFxXNGdedZya7sbm3a82unkI OR0VZkAsVmwdUxJJHMEiHejznHsftKsq6O28bDsrH314esp9WXHHaOIbgT9Yv95jifbccGodejm On3SY90Jyi46TF+2jQMGpUlKJXM+FITar4aDAy9UEpPvArFZJRuAkOLijiyecK06u0PvTGzzBEp /0p/+3JwbXJOSNoVNVWXsClCMRKsoxvuc+dT0G22ktyL1aX9linfibZk8ck1bk0PhCVsi/gIm8Y 3P2pe7OkT3F6o9zDCFAr7F3XxetyoRxK7Fu5jPkE5iOR69hCGbmFXEJoya5GVNicwxqRdrRhdVn QjbFyIuJs1lgklHTHQK0qVdTwziVMashfL9yjxes92pMj6QKJGI3GjBsg4v8Q+BmQW6IftmEbOP zu757yUqHCzSRlHe0y1yf1nSY6erGn/S1Rvj41iulKcFd+96hIVbrKjZh5rF/r2wfJczzwAmsRy b8LgQ5p20q0H4h2GElvxGQAxGZqkU8f/uGDY1NwoCqK1dxcftLZUgbJ9HkPZ+AOnkGwGNTZ+viO +CzeoUQIrSpVhPYFFuzrzRvDqU/1xRLqMBMdqEf0c3dUGuE2xoWnhopq8VpLQuMBJX4RgroiKWP P3pBhVgyKiiwuqw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: 5qnoo16jr35itsf38egcprug68yk6ymj X-Rspamd-Queue-Id: 4D5EDC0016 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721047760-277036 X-HE-Meta: U2FsdGVkX1/+qpjeytVkEaKl2gAdNkMhpcrkOix4zuLOKLT8WYt0pijCyQuOramdqBQbo+u5NbyspTZjqrHQsQd2qRtkHXmiqPmSSdVaz5Fr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D9/I5f09wcVPk4EO4NkvQnjFP7F13aHIgWjljbvXHlcWAqyNaOdtX+1sM+UsRs2ydkQ37FGcF/fiSVJwnBvVC8FRVWsDya0weaBcvJg93CRuRh6S2gTJij/wLTGQ== 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: List-Subscribe: List-Unsubscribe: Four percpu counters for counting various stats around mgtimes, and a new debugfs file for displaying them: - number of attempted ctime updates - number of successful i_ctime_nsec swaps - number of fine-grained timestamp fetches - number of floor value swaps Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara --- fs/inode.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 869994285e87..fff844345c35 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -80,6 +82,10 @@ EXPORT_SYMBOL(empty_aops); static DEFINE_PER_CPU(unsigned long, nr_inodes); static DEFINE_PER_CPU(unsigned long, nr_unused); +static DEFINE_PER_CPU(unsigned long, mg_ctime_updates); +static DEFINE_PER_CPU(unsigned long, mg_fine_stamps); +static DEFINE_PER_CPU(unsigned long, mg_floor_swaps); +static DEFINE_PER_CPU(unsigned long, mg_ctime_swaps); static struct kmem_cache *inode_cachep __ro_after_init; @@ -101,6 +107,42 @@ static inline long get_nr_inodes_unused(void) return sum < 0 ? 0 : sum; } +static long get_mg_ctime_updates(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_updates, i); + return sum < 0 ? 0 : sum; +} + +static long get_mg_fine_stamps(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_fine_stamps, i); + return sum < 0 ? 0 : sum; +} + +static long get_mg_floor_swaps(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_floor_swaps, i); + return sum < 0 ? 0 : sum; +} + +static long get_mg_ctime_swaps(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_swaps, i); + return sum < 0 ? 0 : sum; +} + long get_nr_dirty_inodes(void) { /* not actually dirty inodes, but a wild approximation */ @@ -2655,6 +2697,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* Get a fine-grained time */ fine = ktime_get(); + this_cpu_inc(mg_fine_stamps); /* * If the cmpxchg works, we take the new floor value. If @@ -2663,11 +2706,14 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) * as good, so keep it. */ old = floor; - if (!atomic64_try_cmpxchg(&ctime_floor, &old, fine)) + if (atomic64_try_cmpxchg(&ctime_floor, &old, fine)) + this_cpu_inc(mg_floor_swaps); + else fine = old; now = ktime_mono_to_real(fine); } } + this_cpu_inc(mg_ctime_updates); now_ts = timestamp_truncate(ktime_to_timespec64(now), inode); cur = cns; @@ -2682,6 +2728,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* If swap occurred, then we're (mostly) done */ inode->i_ctime_sec = now_ts.tv_sec; trace_ctime_ns_xchg(inode, cns, now_ts.tv_nsec, cur); + this_cpu_inc(mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED? @@ -2751,3 +2798,24 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap, return mode & ~S_ISGID; } EXPORT_SYMBOL(mode_strip_sgid); + +static int mgts_show(struct seq_file *s, void *p) +{ + long ctime_updates = get_mg_ctime_updates(); + long ctime_swaps = get_mg_ctime_swaps(); + long fine_stamps = get_mg_fine_stamps(); + long floor_swaps = get_mg_floor_swaps(); + + seq_printf(s, "%lu %lu %lu %lu\n", + ctime_updates, ctime_swaps, fine_stamps, floor_swaps); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init);