From patchwork Tue Oct 1 10:59:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817779 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 70BC8CE7D11 for ; Tue, 1 Oct 2024 10:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEB87280076; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A745A280068; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A2D3280076; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 65654280068 for ; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 25BD81C4BD3 for ; Tue, 1 Oct 2024 10:59:30 +0000 (UTC) X-FDA: 82624737300.09.E5DE741 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 5445C14000A for ; Tue, 1 Oct 2024 10:59:28 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GfnDYDpc; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780303; a=rsa-sha256; cv=none; b=wQgoPois+4AWL5JW4WxbYhoBGljiCFpC9m3yu/fCd4hVDRM++lwwG51SWIUZbdoChZidKO sQPA86NASYYPHpjcM9wgVgs0W5I6lvkSWOcSrqBmoWnPG6VnFJ75mBPp+/bGogSHMa0Iwk wqefeBDqkX2JYCx0SHLH844WEL+AJlc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GfnDYDpc; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780303; 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=M3I0vGBPnlMtvVR07H8Xsh7oUVCPl51S2llG4iNobUA=; b=vOsSmlzPjal51oesE088gwkp9svt+XQcV/lYatsfMt7QaXBNzB+j+L2xHPKWCiJsZ5ktR0 zn+JpfNTMBI0R81hbalQMVXS+eE8WDY2XFXzjNboUonHcsqmtJv4FKYBzoUG7jYr+j3PgP aMY6VXMsaKcLD8lSogg78CZLrJQ3DnQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7CE4B5C4CA5; Tue, 1 Oct 2024 10:59:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB15BC4CECD; Tue, 1 Oct 2024 10:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780367; bh=bnxqTLrbNZyT1g0NvyIT2ylk9FHviHzTCIeX6Q+a9Tw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GfnDYDpcxS3boT3U4rQLJwULi0a8n222Fjnp1VCMDfC20mmbQD0cDIQadBM51cgPJ nV9YRO7/QWGpLPtne8HTI+7ACDNc8Yh6wr2X2n11INCbNF2nFwFWdG88ogoEctFXGK 3eTu3I7U31GhahuJcVqwWBQB62Ha5QtCSqJPyxODA+GxhlZ8/ILXzGt+LHu8ChZiUz PC8M9TXzE6TMHP8suehx38ysXd9H+7CO37Wvfw9VlzkPrWwpi+KMc32f+amoNQvAyW GH/RDL/sP0VJ6V8ofYYdHgnT5D8Q43Va9pxygzXntA2zx8I+RlbyMIblG77RXge9rT J3cX4dtYnSwHg== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:00 -0400 Subject: [PATCH v8 06/12] fs: add percpu counters for significant multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-6-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4249; i=jlayton@kernel.org; h=from:subject:message-id; bh=bnxqTLrbNZyT1g0NvyIT2ylk9FHviHzTCIeX6Q+a9Tw=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X6uFTDpmruN1n3YxfQ4M9GqHLCg78dcLoDF Xy4u5w/fieJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+gAKCRAADmhBGVaC FWKuEACrNZonEdFb91CPslE1FKZ3EnjTmpY62WjtfzkO/dS6Yc+5Vty9sBbTC2Wgj8swV7VQI1E 3n1u4rMgrfPOlKr/QKBU80elsZhvrOmrrheb8ui9AcOo1I+XdXePrsG3aobdnQ/Gv98zQCACcb4 8B3sikCLn0hTps4oScihpn6zZyM8TBMb0TElbFDmt0PEZNuki6joWMvpLwvyNH/nfI03Hw2fpfK oAdmhyFG2rHsyZIGH4wystUL77V2sapnE7zcnoj6JqkAMp8tK3NkVkUcusLKJYJeacY1MAupboZ czHepmwuiXJUE6Cqgy6F3qrOxev1S6jHvRpKb2cKCgvO4rVEIBkIs5mZ5U4Sb1CHU3jf+wLsvbd QRY6NtWBCfTUH5a9hly1Yd3oryA+TCSVmZitD/8XpNEsU+vwLG6WEC2ca+5ElyS1snzgDfhFIBB de7bQwlpZzQi44aNXyKQOwkQNze6xRmXR5rDhdRhFgkmvBu/cOoqP4g5Sr1MSVY4uQ+1qNcBIau Xf1Aq6G1ho60wNVM5P5giwaUn7DeV26EjG2JGKgxypBjstKfHItRHYZFrVfl08OyWr8hK1UplDh bQdjV8UIwzVG91dY0MV35yqrh2hcuKJFCN3kZ6Td8t43eJprgUnh/lnWZtbYu/IU9B5zDnkuF9T 35pY/z3vA4fyIPw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: a75tcyr71srwh7wjc7pwqmmbeuzb8mxh X-Rspamd-Queue-Id: 5445C14000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727780368-956212 X-HE-Meta: U2FsdGVkX18VXIieNNAqmClOAZw2fpKY53nHIedJMGolig2ioCWNDiz1zvDzr1mLJXsK1Ub159nhIR03++v8vzWu+U+iQfLuykvvaUT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9IM5vMUUPqq9W3CiOT3Vw0lUOT2NtLwK7ZWH9LPeasThLLu8uZD4Df8Y1WZ11VTsrTQvdRai4n399SJoAVZiAd+jg+JYJw6XX+HpRVLtqxg5Q8ta1cVo9bLpfPQSBK7Ny7bYbyjShwumVsegT9gPyjkWnrg4KbkYnvLRNirvmSYQVfEvE= 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: New percpu counters for counting various stats around multigrain timestamp events, and a new debugfs file for displaying them when CONFIG_DEBUG_FS is enabled: - number of attempted ctime updates - number of successful i_ctime_nsec swaps - number of fine-grained timestamp fetches Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 1a7eff2a40e2..e46f7170851b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -101,6 +103,69 @@ long get_nr_dirty_inodes(void) return nr_dirty > 0 ? nr_dirty : 0; } +#ifdef CONFIG_DEBUG_FS +static DEFINE_PER_CPU(long, mg_ctime_updates); +static DEFINE_PER_CPU(long, mg_fine_stamps); +static DEFINE_PER_CPU(long, mg_ctime_swaps); + +static unsigned long get_mg_ctime_updates(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_updates, i); + return sum; +} + +static unsigned long get_mg_fine_stamps(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(mg_fine_stamps, i); + return sum; +} + +static unsigned long get_mg_ctime_swaps(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_swaps, i); + return sum; +} + +#define mgtime_counter_inc(__var) this_cpu_inc(__var) + +static int mgts_show(struct seq_file *s, void *p) +{ + unsigned long ctime_updates = get_mg_ctime_updates(); + unsigned long ctime_swaps = get_mg_ctime_swaps(); + unsigned long fine_stamps = get_mg_fine_stamps(); + + seq_printf(s, "%lu %lu %lu\n", + ctime_updates, ctime_swaps, fine_stamps); + 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); + +#else /* ! CONFIG_DEBUG_FS */ + +#define mgtime_counter_inc(__var) do { } while (0) + +#endif /* CONFIG_DEBUG_FS */ + /* * Handle nr_inode sysctl */ @@ -2691,10 +2756,9 @@ EXPORT_SYMBOL(timestamp_truncate); * * If it is multigrain, then we first see if the coarse-grained timestamp is * distinct from what we have. If so, then we'll just use that. If we have to - * get a fine-grained timestamp, then do so, and try to swap it into the floor. - * We accept the new floor value regardless of the outcome of the cmpxchg. - * After that, we try to swap the new value into i_ctime_nsec. Again, we take - * the resulting ctime, regardless of the outcome of the swap. + * get a fine-grained timestamp, then do so. After that, we try to swap the new + * value into i_ctime_nsec. We take the resulting ctime, regardless of the + * outcome of the swap. */ struct timespec64 inode_set_ctime_current(struct inode *inode) { @@ -2723,8 +2787,10 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) if (timespec64_compare(&now, &ctime) <= 0) { ktime_get_real_ts64_mg(&now); now = timestamp_truncate(now, inode); + mgtime_counter_inc(mg_fine_stamps); } } + mgtime_counter_inc(mg_ctime_updates); /* No need to cmpxchg if it's exactly the same */ if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) { @@ -2738,6 +2804,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* If swap occurred, then we're (mostly) done */ inode->i_ctime_sec = now.tv_sec; trace_ctime_ns_xchg(inode, cns, now.tv_nsec, cur); + mgtime_counter_inc(mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED?