From patchwork Mon Jul 8 15:53:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13726773 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 A0A90C3271E for ; Mon, 8 Jul 2024 15:53:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0F2C6B0096; Mon, 8 Jul 2024 11:53:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBDEB6B0098; Mon, 8 Jul 2024 11:53:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B13A06B0099; Mon, 8 Jul 2024 11:53:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 849616B0096 for ; Mon, 8 Jul 2024 11:53:55 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 067621613E3 for ; Mon, 8 Jul 2024 15:53:55 +0000 (UTC) X-FDA: 82317031230.03.545EF0E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 43059C0010 for ; Mon, 8 Jul 2024 15:53:53 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZK+m74Ln; 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=1720453994; 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=0+mTfA4rU1po8svyzP43M8jQDf2DxwWnMP8MnaYJ8h0=; b=NTCoGXRuH54uA3iwUGFEyEhaAUvWkhbAtv8jT7t5nWQFlI4VJVnP4R5RlfgPkYzyOnhKrI BciuiPDIwRZCXYLKJ0vCvettteRj8fNL51FP2XXTFQk30Yf2QCW0HYfNEBHmSJmr3Ihxp3 AjqKCWsMBqviUjRIrZddO1D9naKQ+eg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZK+m74Ln; 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=1720453994; a=rsa-sha256; cv=none; b=6B5pagc/Az22OO/8oYgM6BSjFkB6lUQDRW3f9Wm97BHLm7NeaPeTn5Dkmq+cTzYKEIwzx/ nmiW2bp+BTFhiA1slCiaZm15C0Nx+q5PnbzIMqxsFe0j1qaZF4JdWaXJpYHc42pKWncjc+ zAxSnlDUGaZjf9KzMG1MLEdBCof72Eg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 706AD60E03; Mon, 8 Jul 2024 15:53:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A013CC4AF0D; Mon, 8 Jul 2024 15:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720454032; bh=3Lbwoi1OsUrhgHdGPKIfY5gAyrpedRUJApKASCysnEY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZK+m74LnLYmP4hKfEEcqImJ2WWsRHzZh8aQS2kRZGkex1opFTkUCiiYOFpMJP7NN9 C+xzCJa17mVivTegTyPfkpvrSabc7XuOrKZy8hm5P5CFEniVLhvKlvb45MexFsgWWM fErZ+I3DuJeHvAZdMxnyFH/dGPWM1jgyYweg5qr2jLXuk7+6o0dsJl3tem3MrIxo0q q3SQRCFGMSKU86GPjjS+TE4ZL/Fcg9sn3y8raEHC2szPsIQsSk8jQyW7S037K/3dty cKmeWH6QdtXNzBK++SHOJJtGDBQ1x9qUkwyM4uTQPIYjsf/vKZmU1CQiRNGuK7o+1S FsG+vxtXTW8Lw== From: Jeff Layton Date: Mon, 08 Jul 2024 11:53:36 -0400 Subject: [PATCH v4 3/9] fs: add percpu counters for significant multigrain timestamp events MIME-Version: 1.0 Message-Id: <20240708-mgtime-v4-3-a0f3c6fb57f3@kernel.org> References: <20240708-mgtime-v4-0-a0f3c6fb57f3@kernel.org> In-Reply-To: <20240708-mgtime-v4-0-a0f3c6fb57f3@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 , kernel-team@fb.com, 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=3875; i=jlayton@kernel.org; h=from:subject:message-id; bh=3Lbwoi1OsUrhgHdGPKIfY5gAyrpedRUJApKASCysnEY=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmjAuDCTkX86wQZxt/FexePHG2g2qXIymEXEO5D zP/7w+C29GJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZowLgwAKCRAADmhBGVaC FfVVEACRsXJxxH7+xhMllN37rUAlU4nCqFXZe9HjP1jSGjrbBm11+KznLCamc/MioFvpOSKHatn ux0gbVneJuEOw0SRtqvfdyvpcIeA3tr//bDyUEE6iFIfYQs3Ti/jroUTL0ByKzCv/Gk+VhxNJeA pLwbZgxJmDPjbq3COlkop/rp5Phdfwof3sI/q9IvlJ+NyemoRN2SNmMgSM0nuoYoht2I4n9twAb C8FiR+a7Eumi5eynE8zj4EnvuxZ+Hgo0/wI6ob+vV9720GGQYzNjddDkeb3tq1LHdrE630uxnGT A4wx3CDkxBATrZFdCGwwZP1Hu4PZCAg2H6//4T3VihPP/s9TBa6hIyCyA3QIxP9CYhhrckj6ILr mVOH5ZTbJQCEWThtzT6n2CcjoGnNjYSQwNWrNpw2lLpONd5EKdz7BC89OCEFIsYKjixhce4URO1 nUelqVu6pI8wlUzh972tX+6J6qUJlVzwP9kVDaY93iILZOEZQKjhr3umIqtkZzqNZhLL1w3IvCl FdNKQPT6DUOCpVGSXU7SavEbux6lnmq/f9TdrrmzcHKN/zfys7Fz/GIoQYjVVP87eelAXPPFCc3 /oz5euHbjCPt+3nY8JTmpDCn7sFZTcZNpMd+619k/41SELlbrvgeMU0JeSdNzEiSFtsbCb1JG3h ZAi75SeocmkMcSA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 43059C0010 X-Stat-Signature: smkrjgc99hocc3o498znizgjzko91m1o X-Rspam-User: X-HE-Tag: 1720454033-334237 X-HE-Meta: U2FsdGVkX1+MXS+r63FI3l1nTTxQI0xhQmpV20ekrZ6Q4YuO1+bCY97bNKwANFfy9k9bf+f8foZOgDflVAp+9ETfTqRolZHJwB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gnLhF2If9KP7zG8M2b4rrvpkIX4VhCc2AnxE/ZnEprvii09gosHP7aDQaeZSI/DawCJVOGaex7Q0maQ+we5U3uGF+yZ 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 Signed-off-by: Jeff Layton --- fs/inode.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index b2ff309a400a..9b93d0a47e55 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -70,6 +72,11 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); */ static __cacheline_aligned_in_smp ktime_t ctime_floor; +static struct percpu_counter mg_ctime_updates; +static struct percpu_counter mg_floor_swaps; +static struct percpu_counter mg_ctime_swaps; +static struct percpu_counter mg_fine_stamps; + /* * Empty aops. Can be used for the cases where the user does not * define any of the address_space operations. @@ -2654,6 +2661,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* Get a fine-grained time */ fine = ktime_get(); + percpu_counter_inc(&mg_fine_stamps); /* * If the cmpxchg works, we take the new floor value. If @@ -2662,11 +2670,14 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) * as good, so keep it. */ old = floor; - if (!try_cmpxchg(&ctime_floor, &old, fine)) + if (try_cmpxchg(&ctime_floor, &old, fine)) + percpu_counter_inc(&mg_floor_swaps); + else fine = old; now = ktime_mono_to_real(fine); } } + percpu_counter_inc(&mg_ctime_updates); now_ts = ktime_to_timespec64(now); cur = cns; retry: @@ -2675,6 +2686,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); + percpu_counter_inc(&mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED? @@ -2744,3 +2756,49 @@ 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) +{ + u64 ctime_updates = percpu_counter_sum(&mg_ctime_updates); + u64 ctime_swaps = percpu_counter_sum(&mg_ctime_swaps); + u64 fine_stamps = percpu_counter_sum(&mg_fine_stamps); + u64 floor_swaps = percpu_counter_sum(&mg_floor_swaps); + + seq_printf(s, "%llu %llu %llu %llu\n", + ctime_updates, ctime_swaps, fine_stamps, floor_swaps); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + int ret = percpu_counter_init(&mg_ctime_updates, 0, GFP_KERNEL); + + if (ret) + return ret; + + ret = percpu_counter_init(&mg_floor_swaps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_ctime_updates); + return ret; + } + + ret = percpu_counter_init(&mg_ctime_swaps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_floor_swaps); + percpu_counter_destroy(&mg_ctime_updates); + return ret; + } + + ret = percpu_counter_init(&mg_fine_stamps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_floor_swaps); + percpu_counter_destroy(&mg_ctime_updates); + percpu_counter_destroy(&mg_ctime_swaps); + return ret; + } + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init);