From patchwork Wed Oct 2 21:27:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820392 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 B0038CF8542 for ; Wed, 2 Oct 2024 21:27:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EB106B03A4; Wed, 2 Oct 2024 17:27:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 174AB6B03AA; Wed, 2 Oct 2024 17:27:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB8E06B03A1; Wed, 2 Oct 2024 17:27:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BD4896B039C for ; Wed, 2 Oct 2024 17:27:39 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2CDE440FEC for ; Wed, 2 Oct 2024 21:27:39 +0000 (UTC) X-FDA: 82629949038.27.F1AE6B4 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf11.hostedemail.com (Postfix) with ESMTP id 6540B40014 for ; Wed, 2 Oct 2024 21:27:36 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZsBmIDPP; spf=pass (imf11.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904416; 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=OYblGanv/8ITxzmYXUVbxpwgO008+Wz9kmBzucb1nSY=; b=Op3bZcR9b8uSVCYOMsFt0aLg2uCwVjWLXWqjeM7OvzseddMMr/+/4I7Kg8wIh4YVdzfwX9 CfE+QA23UrtotOj+faLm7FjasVGlXXlRpmVDvA9XIwiNch+j4vFI/gkWCWifEvT6ZgD+Eg 6ySQORceWQ8OgrUZj+E8MVp2yJ1e4qY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZsBmIDPP; spf=pass (imf11.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904416; a=rsa-sha256; cv=none; b=CHQ8nJ8zvTsAfiefTo5wCBbmJp8b2vATNadxEus0DGbm3JDPdN/VS4lsCi/Vqy0U/dbv9u Tu6wt29BcgQtQSphF3AvGN+eHuttQO+D4C90G5Q+AQcBTqK8PwEzw21rw+HDW4KuohZqNs MhgpQUQCkLpkSW/YivWO2bkgZ0AIjeQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 438A8A4401B; Wed, 2 Oct 2024 21:27:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93A61C4CECE; Wed, 2 Oct 2024 21:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904454; bh=2+VLMo7X+TKT3T321kqTgs4zMRtNzRRVuC4rj6DW+Cc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZsBmIDPP/TPJIvUs0H0Bq+7XEPNLJ1InQNnB4epFjmVdguwWioPMQS0ex58J6kYmH 76Fs+mTjp0aloR+UbceVmYtsF/mHxicbc7SCRZDtvaZJKzoQby83Om+uyM41nvZm2U nVrZ+05fYngNpI6waazdFuGMsEZt3UJicfAl2I2GxhQTquhWAMA/wnGofhAAU3a5VR 1g4qISpmbhN2ycyH0JhDtn5sH+Ti4dfyVNQe5zHxioJaSlWTFWoFqTKFqhd+njgFgm RZb3hLGlthcy1Pc1qAypf3RxvQisdqLX8i9f050vMPUtK5g1OUzpYfBiDFiACH3HJp oLKTfZgy41pvg== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:16 -0400 Subject: [PATCH v10 01/12] timekeeping: add interfaces for handling timestamps with a floor value MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-1-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7844; i=jlayton@kernel.org; h=from:subject:message-id; bh=2+VLMo7X+TKT3T321kqTgs4zMRtNzRRVuC4rj6DW+Cc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/pOISz++DqIaPinjQXm8r2ux+FEodDWTqw 9MkXKbpGnyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FSNmEAC/ux5B3D/H1d8eVc06UwpsjbzW9qWVQ+EdDb83LSfoT1OyhHOwvJc9orbEruZKyeuVp5F DIwOsP4z9ow//lDNM8u2BapdjY393P5MOpVBh8mYwPPpHGuTvLCcTdWKBciJC85QokG6fiWpGUh CgGtAIuTsvAM2qrN0FeWEslTcTg/XMSEC3FypKoEM2BTa5h2/FhZhsaOk6w/0p5eev9vVvn1uoQ l/YtTg8huFDZeYxEeZp5Yl3nzZGFAbl7m0XHrqGPcnOk1vErmfjY6Nbo+DBNTc+/diAsTwaQNf4 I9IaEwbowLv5z3cEqCsUdxxEtMDvIWyDMSDphlLjhWG07WBhsneSlDyziwWQrZUl6BlewfwbfoV +ZctmC9Xo/48Oah8yVfgW/yhhXvIEBAzg0f++xLKNC6N1ou0jAsN+IWOW9Tuq7/nZKCDDgKSJEU hm4hfXDa9J6EbHhOIURnF3b6jIkhHcHDoB7kSkGoKbMrLWDOa+Cjl4m/eeLALFMnjT4vIaP8XJf x8u/MX+O7HX4faRyBPIU5WUP02BAUGV9gPBpt1XUJaluSUYv7Zh57l6X1a1nijk7nYm2Thwogan 8kG5S56vOv6LQxQEsxRUL5GSFNDQ/glnMJnA2IOXQDXq55O0JYfn/iKCpgCK5WJ+l0bEVSqyCXk amyBDzLFVkZwj3w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: tzictwywc6i8xmzgzfindmzxx7hrm1ij X-Rspamd-Queue-Id: 6540B40014 X-Rspamd-Server: rspam11 X-HE-Tag: 1727904456-781447 X-HE-Meta: U2FsdGVkX18QF7CO/pVRyrES0EOLd9PP7Hs0B3J2HlwJBztKNLSgBb+mhjm7NjKjxqzh753vW/b47COwbv452DvBaNXdpAc1ppONUwJoWqi8KERxR1rW2HCCuBiC9r5alLSEeILv0DTVVa7ds1IXISAbveRbeE8xqU7HECmUzxpDKOVbkDf6LoWNgCOa62JUT4tJouvPrvi/+FjizO9dCAzXwccswk0UVzYQ+YyoTc712AJD1bfTTxBZ6CfZOiZoWap/HUsYA/b9E9BRM6ZmfzdlBcaNmQ9CFQLqtX1RIPeqXBwYBRkSaPMTASn7ZG8DYKQy+WvdWrci5mLpPJZW6xvsssVkd2kaG3SOffPR0gPoD/VxYwjSnEKZW83tSlq1FzrZ6LtuNMzQ0B8rUki+LHFTrr8OnCLwLx23gYvKbeR01dtQardAqwZm6xpE+tWOfUoBkyeTLSrIK2b3Lv+sFJKl9PUeYFpTK+18g7I1pptj6ukACNQlgOQOB5ID/chQRLmiGAjBaFqvP3c006fXaU9TuZhhBvKMgRvfCLbom2Tmexs7NCbYIHZjzAHKpcY1erDhRjoFuuWhSkgDkNThu6YN9dZe5B39IE+EN9xFrA3O9L93J/BK3KsodnQX/Kk3XKQPzdrkU4LxemALlqJmL8jew1Hfe6ki/BbUp75ljHrqKrmbDNg5aNCfWnMMVD/pI3/yJpYoOBcud5nUuvSWKQaH9MPNk50K6O8ioGYXw8ku/TnPxaPHdY3SI70YVKf1rwD7AfGy6lzMSsf6dOATNgAgnOmMhv66NErhuK8h0c8+KgPIuxYG927Pf62lfKu55prZyni+Icn1R207lUS20AeQcofN/QrfbePKCDUPyZkgzgZEkQe3hroTg13MVEK9ORzhDqgcu9ggo6vn1SrBbZPJ/bXQbcQbbuCZQdG6QDB4pWQQF1eOywJOHnTGmKTaM5S+MetOmTitgMaR1Sd 1tWn/kxC Jkxk0oU6NGPh2f5SbROt8+HqqaQWPu2Sf0hJNB1faiswi5FB8iAJbWAZNC9SGIzD7QVfdSzepolOvypRN1ll2Wk/EuLDuc+NaeZSnCTNoZEOTPe9+6RXSIWRLPCih8YsSKgw+aZrzKsFhfNrq2HqpAt/T4yrluzSoQbDEY9T2Gy9jDWjnBW/6zTMmYLPat8oDwroI0TcE0sY08QgqK4Mtp0Fi0ZDHe9FssIXRgTU45PaKPf3MXKPoMI2VSYxgdTXLOf1auZWr6V3kxRCzuo+ig3vrLKScCE2IfQQMngBnwzhPUgxMSG8ji9cH9h+IDCDkryud1ua8aJzggW+IjBVPUJ6RnAMNN0dVRrUYCl88/7uPLTHP7uNG4CdaPj9wdeBn6IxFWWOLXnEI4j/3vTDHVU9/2Xp207BBw/SIX3Ev9IgSasOvCqJCfxnAp2sCxokIF77U 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: Multigrain timestamps allow the kernel to use fine-grained timestamps when an inode's attributes is being actively observed via ->getattr(). With this support, it's possible for a file to get a fine-grained timestamp, and another modified after it to get a coarse-grained stamp that is earlier than the fine-grained time. If this happens then the files can appear to have been modified in reverse order, which breaks VFS ordering guarantees [1]. To prevent this, maintain a floor value for multigrain timestamps. Whenever a fine-grained timestamp is handed out, record it, and when later coarse-grained stamps are handed out, ensure they are not earlier than that value. If the coarse-grained timestamp is earlier than the fine-grained floor, return the floor value instead. Add a static singleton atomic64_t into timekeeper.c that is used to keep track of the latest fine-grained time ever handed out. This is tracked as a monotonic ktime_t value to ensure that it isn't affected by clock jumps. Because it is updated at different times than the rest of the timekeeper object, the floor value is managed independently of the timekeeper via a cmpxchg() operation, and sits on its own cacheline. Add two new public interfaces: - ktime_get_coarse_real_ts64_mg() fills a timespec64 with the later of the coarse-grained clock and the floor time - ktime_get_real_ts64_mg() gets the fine-grained clock value, and tries to swap it into the floor. A timespec64 is filled with the result. The floor value is global and updated via a single try_cmpxchg(). If that fails then the operation raced with a concurrent update. Any concurrent update must be later than the existing floor value, so any racing tasks can accept any resulting floor value without retrying. [1]: POSIX requires that files be stamped with realtime clock values, and makes no provision for dealing with backward clock jumps. If a backward realtime clock jump occurs, then files can appear to have been modified in reverse order. Tested-by: Randy Dunlap # documentation bits Acked-by: John Stultz Signed-off-by: Jeff Layton --- include/linux/timekeeping.h | 4 ++ kernel/time/timekeeping.c | 105 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index fc12a9ba2c884271a75608211a72173b7ebaa24c..7aa85246c183576b039c02af4abba02b4a09ef9d 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -45,6 +45,10 @@ extern void ktime_get_real_ts64(struct timespec64 *tv); extern void ktime_get_coarse_ts64(struct timespec64 *ts); extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); +/* Multigrain timestamp interfaces */ +extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts); +extern void ktime_get_real_ts64_mg(struct timespec64 *ts); + void getboottime64(struct timespec64 *ts); /* diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 5391e4167d60226dfc48c845170e36bcbeb7b292..ebfe846ebde35850c3e4d9c2cc45642c983d137f 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -114,6 +114,24 @@ static struct tk_fast tk_fast_raw ____cacheline_aligned = { .base[1] = FAST_TK_INIT, }; +/* + * Multigrain timestamps require tracking the latest fine-grained timestamp + * that has been issued, and never returning a coarse-grained timestamp that is + * earlier than that value. + * + * mg_floor represents the latest fine-grained time that has been handed out as + * a file timestamp on the system. This is tracked as a monotonic ktime_t, and + * converted to a realtime clock value on an as-needed basis. + * + * Maintaining mg_floor ensures the multigrain interfaces never issue a + * timestamp earlier than one that has been previously issued. + * + * The exception to this rule is when there is a backward realtime clock jump. If + * such an event occurs, a timestamp can appear to be earlier than a previous one. + */ + +static __cacheline_aligned_in_smp atomic64_t mg_floor; + static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->tkr_mono.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_mono.shift)) { @@ -2394,6 +2412,93 @@ void ktime_get_coarse_real_ts64(struct timespec64 *ts) } EXPORT_SYMBOL(ktime_get_coarse_real_ts64); +/** + * ktime_get_coarse_real_ts64_mg - return latter of coarse grained time or floor + * @ts: timespec64 to be filled + * + * Fetch the global mg_floor value, convert it to realtime and + * compare it to the current coarse-grained time. Fill @ts with + * whichever is latest. Note that this is a filesystem-specific + * interface and should be avoided outside of that context. + */ +void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts) +{ + struct timekeeper *tk = &tk_core.timekeeper; + u64 floor = atomic64_read(&mg_floor); + ktime_t f_real, offset, coarse; + unsigned int seq; + + do { + seq = read_seqcount_begin(&tk_core.seq); + *ts = tk_xtime(tk); + offset = tk_core.timekeeper.offs_real; + } while (read_seqcount_retry(&tk_core.seq, seq)); + + coarse = timespec64_to_ktime(*ts); + f_real = ktime_add(floor, offset); + if (ktime_after(f_real, coarse)) + *ts = ktime_to_timespec64(f_real); +} + +/** + * ktime_get_real_ts64_mg - attempt to update floor value and return result + * @ts: pointer to the timespec to be set + * + * Get a monotonic fine-grained time value and attempt to swap it into + * mg_floor. If that succeeds then accept the new floor value. If it fails + * then another task raced in during the interim time and updated the floor. + * Since any update to the floor must be later than the previous floor, + * either outcome is acceptable. + * + * Typically this will be called after calling ktime_get_coarse_real_ts64_mg(), + * and determining that the resulting coarse-grained timestamp did not effect + * a change in the ctime. Any more recent floor value would effect a change to + * the ctime, so there is no need to retry the atomic64_try_cmpxchg() on failure. + * + * @ts will be filled with the latest floor value, regardless of the outcome of + * the cmpxchg. Note that this is a filesystem specific interface and should be + * avoided outside of that context. + */ +void ktime_get_real_ts64_mg(struct timespec64 *ts) +{ + struct timekeeper *tk = &tk_core.timekeeper; + ktime_t old = atomic64_read(&mg_floor); + ktime_t offset, mono; + unsigned int seq; + u64 nsecs; + + do { + seq = read_seqcount_begin(&tk_core.seq); + + ts->tv_sec = tk->xtime_sec; + mono = tk->tkr_mono.base; + nsecs = timekeeping_get_ns(&tk->tkr_mono); + offset = tk_core.timekeeper.offs_real; + } while (read_seqcount_retry(&tk_core.seq, seq)); + + mono = ktime_add_ns(mono, nsecs); + + /* + * Attempt to update the floor with the new time value. As any + * update must be later then the existing floor, and would effect + * a change to the ctime from the perspective of the current task, + * accept the resulting floor value regardless of the outcome of + * the swap. + */ + if (atomic64_try_cmpxchg(&mg_floor, &old, mono)) { + ts->tv_nsec = 0; + timespec64_add_ns(ts, nsecs); + } else { + /* + * Another task changed mg_floor since "old" was fetched. + * "old" has been updated with the latest value of "mg_floor". + * That value is newer than the previous floor value, which + * is enough to effect a change to the ctime. Accept it. + */ + *ts = ktime_to_timespec64(ktime_add(old, offset)); + } +} + void ktime_get_coarse_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; From patchwork Wed Oct 2 21:27:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820393 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 0FF0FCF8540 for ; Wed, 2 Oct 2024 21:27:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4A816B04EE; Wed, 2 Oct 2024 17:27:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BFBC36B04F2; Wed, 2 Oct 2024 17:27:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4E626B04EE; Wed, 2 Oct 2024 17:27:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7B4706B04B3 for ; Wed, 2 Oct 2024 17:27:40 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 13DA5809CC for ; Wed, 2 Oct 2024 21:27:40 +0000 (UTC) X-FDA: 82629949080.22.11FB137 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf05.hostedemail.com (Postfix) with ESMTP id 531F010000E for ; Wed, 2 Oct 2024 21:27:38 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G3mMkbdg; spf=pass (imf05.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904330; 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=ijdS9YNuM/d+8aUO3LLQCja6IxbZMfWf/xrqS8jkEz8=; b=Ax2bGTydiFKPszW2/7WMCqyyiNq5ZqZ+C7AZUE+4BdHU1XobduvZm5YlVj5/ysIFO0pn4q bpO9j0w6Z69y1bNViR8INTrR08oWB4aWicGHh06KSp++49roSGqIXFj38AbF6i2MqFzgn7 RcRn/NMwBwxDIY/ZMYdAa8kvxqfAGQw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904330; a=rsa-sha256; cv=none; b=gAWOoPAhECyFTiHR9HSysS++PyWGJLuNYRfY9kya6fhJBlxq2iPT+7so36633/xqpYtHp/ jOYBrQqdxhnaWbNEFtcU5npKefda1nIGIY1rm5/e8axAS6AC7Cb4W1OjdLMxsoZkwfkfrn PH3ogbdayPDz7X+iZjIwh60qc43uy88= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G3mMkbdg; spf=pass (imf05.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id DCFF9A44023; Wed, 2 Oct 2024 21:27:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55601C4CED1; Wed, 2 Oct 2024 21:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904456; bh=b4XkKth37w2ravUWOahimfnL3UOfVbEBD3lD+3rp+1s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G3mMkbdg0nkDEyn6L/6plWzGy8rzM311X3HHbMz6R3Ai1VYHlupggE7MRYdxecBcW Xvk6ll6KZR/g9zl7uCaka+nNH7x9Tm/RIkT5vO6uSHNqrUjFrtM95g8heH5M+lCE55 F8sgy2iJ9fYi2MZGAAxh7tC2DGiC+V5GkjwU7zP25bmpQ/aYrgzhRDQUPnIsshqeKy O7Jkn3FCOz/3z+OTJtQd0O6UxWljUiDGrmddv3D/etWQiDuDYhcmmN0fD6Ll8pFgyi DBGz2Fo7ZjiuVE0X7WaIHym/aM5Pjo+l4xsKTeBPi+9qboJDAz98MsoDdHe55s5REo dVuTX5zzfKQ1A== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:17 -0400 Subject: [PATCH v10 02/12] timekeeping: add percpu counter for tracking floor swap events MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-2-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3634; i=jlayton@kernel.org; h=from:subject:message-id; bh=b4XkKth37w2ravUWOahimfnL3UOfVbEBD3lD+3rp+1s=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/KG7g3gRmiuGWZ6tpbobqHKVwsPLvCl1+2 PakkzoH/7uJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FZRZD/4yysdw6oqodqdrDqoDwQHs/Q4CF/xQT2tRHqA4QItHNsZTxwidAffBRsnGrGPeTIgeMCM eYGyGB9p4u3XxLEb8dhRFOW1RBgcQ/Cjr8cpZH6SZLYpRAk6GIcclb7JSx0Z+ZsLsb3raxWip/q aQkME57KDFHa5SU4k6wWAI43OaKhloW9psmHOc+VuX08saDovMS29GzzdVVAjB04fD6FVnJ0bOw LhNaYNNOKXmuoYPbwXaeS79CaJBEsoC4hSLmofWpFHtXZSM0eMXenbt01hkg0YPIERLodPld9rp iR7KGQ74j0CMmpjZaG/iu8mh33FVzNhkaSdq0w4OuN8UNcCDibrHS5/mOt4wdm3uhMR74E6vON+ 0hkVua/1WjZWCbWA9MiE7S8g3sORCoVEP2BIlNBS3fMnIDVCW9YjyntS4bsTRJnYK5cVmuROgko 7sLr656frMTXl0fy01yglfhU+MXQcqqrmxOiXyRELla8YEX+AKon8oWhvegEV/KJV2LWq3sc2PJ TaaxJQMW9FMLYqn5/ddC7uMEmiMU4fHMlL7JHWzMIzBCVTUE4F3nzpMWHemwN+a44HbOhkzhyQc 0gsIzOEweoF4Kk/yBwXoIpBJneQyP9cglaRlMWlyaD4SLndBdD4EgyTrBtFMAYZncjdhhZwr8Uz ptEgKiXkkzgo4IQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 531F010000E X-Stat-Signature: 1rotddr8zyjmxdhwz8ijg4wdm9gxuu1k X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727904458-276794 X-HE-Meta: U2FsdGVkX18KVrG2GB6p+MYhzWUamNCIH+DniseclFKRlO1ew6XeR1vkyAuL2GXNU8FV9zNY6snA4eyVImO0ZPnGB0LjL6edn9XbX1nyKqDe/VMxXeZHM2M8uGuPD7L5H1CjeQYy+L/09k3jTkVBMY9vATaddJnnlwsza45MmdGNDFXqgx9UU8NwEgCfHHoWeAQrmqJhNEJ4/jeUxgnPvc+TVkz2gyJgY0BB6DrzYdvhDjUBYnKjIAIFk4b7zHVky1XrNFicVsf215hlbzEVusuUT3C/Y7CyMtZiyUe6JLbsQG9ABzI10TQ9UJZUPOh9NQtytzNezi/Exwe6gD1y5ivKY8VPwITHjAObka2pDpzy30CJiGEqqz+qS7gMWLV6zATkExzIeWg7b9tb50t2cJoBMDAiMvkDq6d+W3WDxSGpCd3OlhmDd7Sv/0LrqpBOA7daSEWkb3AcF7q1kX04wVnhRNKA3jnFXn1KDhqF0tilC9to4P+oLpt/wwPACjl47OmtUmglyhtCDWNqLTR45tFD0xYC8zFpO8NESXvgr/1hcEnkBspR6VhaGfpRimKW1liBkMmHmPPhUmVgO2L9305vyue/j+ulrXqIfXyx8RbcgCWhiFYEkvSA1NPUm94k6mOZ51IMdHla2do4k4XrprbwanuWtk4/XtWQej9M1P2P7doanI/TPqSzeFMD3i12HMPp2nKqM8nrgJwXphF+HJbmQ2V/EhjDtT44xpR2FgL1Us6P81cmc3vIO08yzufXuYq3Fq9PfKgOibGY0vtNO8DjXmy8oQvy1mXbfu36trSE7x1diBS5Zb/XKxYWffg8XSBixySjwnIzNdmiOBlsWkSd7noNudEW02FrhQjGNosqmaYpgOfkjcW5VWcRPpNfrbDbKhngeLuTHQ6CSA1xf4s5zV6cFCpz85wrIs9Wcd/5bdGUN9obNshT/xiJ5aigaI6MOXyTsbV6hm671O2 ZlpaEtbS zdiozDymWgLZ1XMAdL+UFT8L9C/065RfDWchaZ300rtb/tXpeDxVWdvYbFg1+3s+YHjnWTCjhtZ9dj1gr/7/ey7at+WwIPgnGZbzP/6GQV3+zxw0CMbSUzP2a8PhFQxIdRawkGW5FMHIXtDAWWG7U6PfhFqe72L0y5PdJKizlTEZ76itg+XyrOQxj5AU6oDFSVoL+krX65Ge9HGPYBZT6yaS9nMaOu7gamJXXcRvOcsk5JAYopcS+XxUU4xYD1EBXYLEpkVdwwN7kJ1MRi2v+DBHLG9MStBefeaqM1dDBtw5d3jRKAH3KfCu5mA== 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: The mgtime_floor value is a global variable for tracking the latest fine-grained timestamp handed out. Because it's a global, track the number of times that a new floor value is assigned. Add a new percpu counter to the timekeeping code to track the number of floor swap events that have occurred. A later patch will add a debugfs file to display this counter alongside other stats involving multigrain timestamps. Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 1 + kernel/time/timekeeping_debug.c | 14 ++++++++++++++ kernel/time/timekeeping_internal.h | 15 +++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 7aa85246c183576b039c02af4abba02b4a09ef9d..84a035e86ac811f9e7b1649246b71c9296519149 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -48,6 +48,7 @@ extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); /* Multigrain timestamp interfaces */ extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts); extern void ktime_get_real_ts64_mg(struct timespec64 *ts); +extern unsigned long timekeeping_get_mg_floor_swaps(void); void getboottime64(struct timespec64 *ts); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ebfe846ebde35850c3e4d9c2cc45642c983d137f..e8b713e8ce5553f9e7de96c8e7c089714e0aa7a4 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2488,6 +2488,7 @@ void ktime_get_real_ts64_mg(struct timespec64 *ts) if (atomic64_try_cmpxchg(&mg_floor, &old, mono)) { ts->tv_nsec = 0; timespec64_add_ns(ts, nsecs); + timekeeping_inc_mg_floor_swaps(); } else { /* * Another task changed mg_floor since "old" was fetched. diff --git a/kernel/time/timekeeping_debug.c b/kernel/time/timekeeping_debug.c index b73e8850e58d9c5b291559f475e67c7ed47c2db3..36d359cad7ca1d821bf42f59b3e50f89b14afd40 100644 --- a/kernel/time/timekeeping_debug.c +++ b/kernel/time/timekeeping_debug.c @@ -17,6 +17,9 @@ #define NUM_BINS 32 +/* incremented every time mg_floor is updated */ +DEFINE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps); + static unsigned int sleep_time_bin[NUM_BINS] = {0}; static int tk_debug_sleep_time_show(struct seq_file *s, void *data) @@ -53,3 +56,14 @@ void tk_debug_account_sleep_time(const struct timespec64 *t) (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC); } +unsigned long timekeeping_get_mg_floor_swaps(void) +{ + unsigned long sum = 0; + int cpu; + + for_each_possible_cpu(cpu) + sum += data_race(per_cpu(timekeeping_mg_floor_swaps, cpu)); + + return sum; +} + diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h index 4ca2787d1642e2f52bf985607ca3b03785cf9a50..0bbae825bc0226e4eed64e73fe3b454986c7573f 100644 --- a/kernel/time/timekeeping_internal.h +++ b/kernel/time/timekeeping_internal.h @@ -10,9 +10,24 @@ * timekeeping debug functions */ #ifdef CONFIG_DEBUG_FS + +DECLARE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps); + +static inline void timekeeping_inc_mg_floor_swaps(void) +{ + this_cpu_inc(timekeeping_mg_floor_swaps); +} + extern void tk_debug_account_sleep_time(const struct timespec64 *t); + #else + #define tk_debug_account_sleep_time(x) + +static inline void timekeeping_inc_mg_floor_swaps(void) +{ +} + #endif #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE From patchwork Wed Oct 2 21:27:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820394 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 68AC5CF8543 for ; Wed, 2 Oct 2024 21:27:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 967276B0378; Wed, 2 Oct 2024 17:27:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C9816B0380; Wed, 2 Oct 2024 17:27:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A6B96B037D; Wed, 2 Oct 2024 17:27:43 -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 2C5A36B0378 for ; Wed, 2 Oct 2024 17:27:43 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AEB2481074 for ; Wed, 2 Oct 2024 21:27:42 +0000 (UTC) X-FDA: 82629949164.23.7867E7B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf07.hostedemail.com (Postfix) with ESMTP id E10684000D for ; Wed, 2 Oct 2024 21:27:40 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hu21SUfo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904356; a=rsa-sha256; cv=none; b=D98GLs5TPFBvfiWl3qnHVK634S7ae8tndTMJLUHVowLgOnQ7ihUh1arQGreyvGw6AAe6cf O8sKCgL99sdDpnEzJe7x7SkSank9bwgBzzHrIaX42gd2gUayNmcx/hEzv0RWCyA9PhRqD5 h0nMsNUhns5FsOml8CmS1cqootEj5j0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Hu21SUfo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904356; 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=zy/CUzZ1L2VW12wk2ELOCP2Jo/HBcxYzdAtn57BBHrk=; b=XWRelVkMhe/kjmtEUuJZDvwUTjGnrXJSsEQE3eB17i0vfiH8+2Zs2iAVNWx/WkqZKgsjZT GcvMOcZmD50XdCFv60ju1a04FTHJDsnqt+hk8ptK5p89hh3Qrxw2Wuo5KZxlGyC6Mo9CM1 QFKDvPi9uB5MQbSOSQLcUexruYH9Fbo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6AD75A44014; Wed, 2 Oct 2024 21:27:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A4FEC4CECE; Wed, 2 Oct 2024 21:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904459; bh=3KJ68ZBqqX9TlQLj4uVbA/EOzRVQe5kX+liPSYeavbQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Hu21SUfoTS2GaO+kzy1uL8z5jpbOBYPaWlfLvW/XQPfYnzfjz4B7WM+GnZPvdRMqk LvNKxNlUs9Wgog+kgdiEBWH0Rxc5vx9T2O+3/fNWH8y4Xa5wBAdSajN/FE0bBVL0h/ PBd/7wRqEDLz2Td3F3nTXJNU/FJrIuRbZBFW+GDjWDcIyDaBGMseG6XOCu1SNnkRbf xfpoAtT9n8CMnEBEdKZWwIRJ93PY9Os2xo0dIaBjQmKI3t6dGS3MGNzjY8B8wVt0UF NbUq/mUb1qqlD7hLpJa+1MepawXjFF3Rhog5b4oDKIBfns7zypa3opjjocWqgZvUwQ ysyKprM7orOqA== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:18 -0400 Subject: [PATCH v10 03/12] fs: add infrastructure for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-3-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=13738; i=jlayton@kernel.org; h=from:subject:message-id; bh=3KJ68ZBqqX9TlQLj4uVbA/EOzRVQe5kX+liPSYeavbQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/NjtL0rdcXthLZsilQDOdal1o8rmwKEyJn 3seT+Yxz3eJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FeNAD/9gQnAjiTBHt4+Bt/faTCj5awekmmUuH1cUP28lumSOCmznEqw2QkPS0aio4bwe/m+gGOr fcTFvV/qbBBF19RtKklrv75Lo6G/XtIo+j1UzPV5i0cdXds1VPWvRRsKZeFs1A/4EiZfnmEcgzy BrxBh8Ef/0UD+ffLRWbCmXt4/+aQPTZreC8uquY9NuIVSKxVWSpc0aTOquW+V54dCmWZnf25+US 7jXHPqiYkoOxq7Mu4V2iOQCoIB3znzw5V/phPvsaXYfCQ8r4HPYwcXquH9exXLsafE3p+XtsoiD OD4p69FPFcDee9q7xl5vIu+gaTrcOxmc6ztELOx9Pv0fio84vSTuZaWalJG8TXy5zBw9RMhAAZW tqo+r9sdIvVB0wOIGpaHfLxHtKVcfZpxsqRuFl5wcyag4EMhjtLtyFRmkejoIjSXIc9OJoRnsd+ hflte/orHfFVkEDHIBqOSP5M89FQcCazVMopiqstK/Ir3U3403Cb197B2xeeXTppyUu4WL16cZB b3lfGh7ptJ3ncz6OraBFe3Sy4DIBuFShzJ2p7/UUeVf+E9t5JYyW/v12SCtWXMev4pwCu0Rk3rc artghJ6zBnGS6qNHJPX5wgqislqFiebmwNh2Ydgd+R1dRwW/yokekI08Ka4cTBEAMNQFFIgHMxw 9meaE8/e0t0Fl0A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E10684000D X-Stat-Signature: kbopchhpogj4q7jaa8k8bscaihhe4msy X-Rspam-User: X-HE-Tag: 1727904460-734163 X-HE-Meta: U2FsdGVkX18PZYyilaPBP9vJbnIQ4lYDTRKyjp1Uvwyms+53DL7vBExS1MFSJBkmyNYWxX0ZOgqI63ZaQOZz4FUidodYXdqfs9vvnpDwQh/bkHG7kxIukQ18YecBvPwcEuHrWt6rdFHZ13phweRNHr6lS7foLyjOx4CToOTcYsF9I3x10jx/yGtW2UV3zfvapvGCWn92vxxZJTourxQ+45AikPlDJ/Xq9TItgpjHiOAO0mxh3vBZGDVo9jUG39T2HfwYzZuWF7bA3uEn2n++AhbZUHNCNS7qgPIAI5hTlUDcVsVu/qr49Z8+ePR+AIM+zIt5Q4s7d1HmHl99nOTOuVNZpJkd68gfGEo5oDfD9rmC4xVVc18Et1onrZSr4YbBj901kGedhPrqT102WDecQebY/6svOqVMjiDIws6CUVKtEcGk4lJYVh/riCKjEvPQwUHca7ogob2HjK4x1C6C2zLux+9iJSLOE1YS7QZtgVJd/1uN4ffJ8CAU4wO43vR/qwTf4ET0e9f4BszOFB9NKWbaJ+fqAts+3OLssgKfV5WvF+erVGcO+CDokgq1vEI0Xb8aXoG+mPNCCLN6tFY4aujrTTIDKdGL+8HbtBIa8jGCK7HlobaNSqyNs7pNGubKD7CsfSxBcQlijEEwLeeRc/MK8hhGqAsjWmSRPh+PgC9J1JKOqSdz67rrEpMIib2FctWxYVKweau1jbO0nsnJlnzV0KLq6tRszXqmOOOpT4QmqlF96Tzqyk4V7w7pIE+MHnMelZPR3P30NLuumwKe59wQa7urAgfaUq8E56HPC1rJIlLWc70hJzPusxJAOoXUakFfSG0h7K4/Lkjqz8KZpUu6GH7qSq2J3KvhLAhUid36XNz3STjqJ6fc8uZqBJWUJl2K1Feq+n6aR0b5XBdjb0gJtcQj0pAs6VP/5MpYy7VuNfF09h4aYLXVtefUo7CvNDHkT5lXK5ToJvS0aYh hqeQzYy0 7qk4ZrjpnDimglvcI5Ho9ztrtlIWv70xFmeYSBZPi0QgeGuh0BN+/Vl3HwMkQEtvTKsYP7YHMto92TLK/mOVqwI05QL9Z62U+HZOthbbp6fKObNddR8Mpc1l3TtM6n2eXQblC3zPjEz1Ovc4eDDXWniMZfDE+z/gGtI3UAmdfw5axRnvDXeliAv88tD8xQhMmMGqwuL4Zcg+7QUVS3KeC2+zvRu5Zv4Izbpysm13Our+31tANGm/dat5qTQXO6J7oCUHvNPj7hfD+Nib7h0fP7DkLIvFYvbvm63OBc3gD+FCEVUWIKFmyLLBSyMovb+XA7IeKn4tCDBBc9y1MyY8hE5FTdPiFBZZ4pnqwEtsG1UB46+gqFZPhKaQt/xkAvcKEH02k/F3qm2HtG76WY5AohFy48BGnOsjYttBNeL9FT+i2efY= 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: The VFS has always used coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes. Unfortunately, this has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide when to invalidate the cache. Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problems with timestamp granularity. Other applications have similar issues with timestamps (e.g backup applications). If fine-grained timestamps were always used, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates. What is needed is a way to only use fine-grained timestamps when they are being actively queried. Use the (unused) top bit in inode->i_ctime_nsec as a flag that indicates whether the current timestamps have been queried via stat() or the like. When it's set, allow the update to use a fine-grained timestamp iff it's necessary to make the ctime show a different value. If it has been queried, then first see whether the current coarse time is later than the existing ctime. If it is, accept that value. If it isn't, then get a fine-grained timestamp and attempt to stamp the inode ctime with that value. If that races with another concurrent stamp, then abandon the update and take the new value without retrying. Filesystems can opt into this by setting the FS_MGTIME fstype flag. Others should be unaffected (other than being subject to the same floor value as multigrain filesystems). Tested-by: Randy Dunlap # documentation bits Reviewed-by: Jan Kara Signed-off-by: Jeff Layton --- fs/inode.c | 139 +++++++++++++++++++++++++++++++++++++++++++---------- fs/stat.c | 43 ++++++++++++++++- include/linux/fs.h | 34 ++++++++++--- 3 files changed, 181 insertions(+), 35 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 10c4619faeef8cb81d84a91ec2d982d5a1a51a5c..53f56f6e1ff26e718080211880924f37cf0e5b3c 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2172,19 +2172,58 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/** + * current_time - Return FS time (possibly fine-grained) + * @inode: inode. + * + * Return the current time truncated to the time granularity supported by + * the fs, as suitable for a ctime/mtime change. If the ctime is flagged + * as having been QUERIED, get a fine-grained timestamp, but don't update + * the floor. + * + * For a multigrain inode, this is effectively an estimate of the timestamp + * that a file would receive. An actual update must go through + * inode_set_ctime_current(). + */ +struct timespec64 current_time(struct inode *inode) +{ + struct timespec64 now; + u32 cns; + + ktime_get_coarse_real_ts64_mg(&now); + + if (!is_mgtime(inode)) + goto out; + + /* If nothing has queried it, then coarse time is fine */ + cns = smp_load_acquire(&inode->i_ctime_nsec); + if (cns & I_CTIME_QUERIED) { + /* + * If there is no apparent change, then get a fine-grained + * timestamp. + */ + if (now.tv_nsec == (cns & ~I_CTIME_QUERIED)) + ktime_get_real_ts64(&now); + } +out: + return timestamp_truncate(now, inode); +} +EXPORT_SYMBOL(current_time); + static int inode_needs_update_time(struct inode *inode) { + struct timespec64 now, ts; int sync_it = 0; - struct timespec64 now = current_time(inode); - struct timespec64 ts; /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; + now = current_time(inode); + ts = inode_get_mtime(inode); if (!timespec64_equal(&ts, &now)) - sync_it = S_MTIME; + sync_it |= S_MTIME; ts = inode_get_ctime(inode); if (!timespec64_equal(&ts, &now)) @@ -2562,6 +2601,15 @@ void inode_nohighmem(struct inode *inode) } EXPORT_SYMBOL(inode_nohighmem); +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) +{ + set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_nsec; + return ts; +} +EXPORT_SYMBOL(inode_set_ctime_to_ts); + /** * timestamp_truncate - Truncate timespec to a granularity * @t: Timespec @@ -2594,36 +2642,77 @@ struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode) EXPORT_SYMBOL(timestamp_truncate); /** - * current_time - Return FS time - * @inode: inode. + * inode_set_ctime_current - set the ctime to current_time + * @inode: inode * - * Return the current time truncated to the time granularity supported by - * the fs. + * Set the inode's ctime to the current value for the inode. Returns the + * current value that was assigned. If this is not a multigrain inode, then we + * set it to the later of the coarse time and floor value. * - * Note that inode and inode->sb cannot be NULL. - * Otherwise, the function warns and returns time without truncation. + * If it is multigrain, then we first see if the coarse-grained timestamp is + * distinct from what is already there. If so, then use that. Otherwise, get a + * fine-grained timestamp. + * + * After that, try to swap the new value into i_ctime_nsec. Accept the + * resulting ctime, regardless of the outcome of the swap. If it has + * already been replaced, then that timestamp is later than the earlier + * unacceptable one, and is thus acceptable. */ -struct timespec64 current_time(struct inode *inode) +struct timespec64 inode_set_ctime_current(struct inode *inode) { struct timespec64 now; + u32 cns, cur; - ktime_get_coarse_real_ts64(&now); - return timestamp_truncate(now, inode); -} -EXPORT_SYMBOL(current_time); + ktime_get_coarse_real_ts64_mg(&now); + now = timestamp_truncate(now, inode); -/** - * inode_set_ctime_current - set the ctime to current_time - * @inode: inode - * - * Set the inode->i_ctime to the current value for the inode. Returns - * the current value that was assigned to i_ctime. - */ -struct timespec64 inode_set_ctime_current(struct inode *inode) -{ - struct timespec64 now = current_time(inode); + /* Just return that if this is not a multigrain fs */ + if (!is_mgtime(inode)) { + inode_set_ctime_to_ts(inode, now); + goto out; + } - inode_set_ctime_to_ts(inode, now); + /* + * A fine-grained time is only needed if someone has queried + * for timestamps, and the current coarse grained time isn't + * later than what's already there. + */ + cns = smp_load_acquire(&inode->i_ctime_nsec); + if (cns & I_CTIME_QUERIED) { + struct timespec64 ctime = { .tv_sec = inode->i_ctime_sec, + .tv_nsec = cns & ~I_CTIME_QUERIED }; + + if (timespec64_compare(&now, &ctime) <= 0) { + ktime_get_real_ts64_mg(&now); + now = timestamp_truncate(now, inode); + } + } + + /* No need to cmpxchg if it's exactly the same */ + if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) + goto out; + cur = cns; +retry: + /* Try to swap the nsec value into place. */ + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now.tv_nsec)) { + /* If swap occurred, then we're (mostly) done */ + inode->i_ctime_sec = now.tv_sec; + } else { + /* + * Was the change due to someone marking the old ctime QUERIED? + * If so then retry the swap. This can only happen once since + * the only way to clear I_CTIME_QUERIED is to stamp the inode + * with a new ctime. + */ + if (!(cns & I_CTIME_QUERIED) && (cns | I_CTIME_QUERIED) == cur) { + cns = cur; + goto retry; + } + /* Otherwise, keep the existing ctime */ + now.tv_sec = inode->i_ctime_sec; + now.tv_nsec = cur & ~I_CTIME_QUERIED; + } +out: return now; } EXPORT_SYMBOL(inode_set_ctime_current); diff --git a/fs/stat.c b/fs/stat.c index 89ce1be563108c1bc0ecabaff5b277258eb6c398..dd480bf51a2a764e5eb1d0a213c5ec8b640db911 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -26,6 +26,39 @@ #include "internal.h" #include "mount.h" +/** + * fill_mg_cmtime - Fill in the mtime and ctime and flag ctime as QUERIED + * @stat: where to store the resulting values + * @request_mask: STATX_* values requested + * @inode: inode from which to grab the c/mtime + * + * Given @inode, grab the ctime and mtime out if it and store the result + * in @stat. When fetching the value, flag it as QUERIED (if not already) + * so the next write will record a distinct timestamp. + * + * NB: The QUERIED flag is tracked in the ctime, but we set it there even + * if only the mtime was requested, as that ensures that the next mtime + * change will be distinct. + */ +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) +{ + atomic_t *pcn = (atomic_t *)&inode->i_ctime_nsec; + + /* If neither time was requested, then don't report them */ + if (!(request_mask & (STATX_CTIME|STATX_MTIME))) { + stat->result_mask &= ~(STATX_CTIME|STATX_MTIME); + return; + } + + stat->mtime = inode_get_mtime(inode); + stat->ctime.tv_sec = inode->i_ctime_sec; + stat->ctime.tv_nsec = (u32)atomic_read(pcn); + if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED)) + stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)); + stat->ctime.tv_nsec &= ~I_CTIME_QUERIED; +} +EXPORT_SYMBOL(fill_mg_cmtime); + /** * generic_fillattr - Fill in the basic attributes from the inode struct * @idmap: idmap of the mount the inode was found from @@ -58,8 +91,14 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->rdev = inode->i_rdev; stat->size = i_size_read(inode); stat->atime = inode_get_atime(inode); - stat->mtime = inode_get_mtime(inode); - stat->ctime = inode_get_ctime(inode); + + if (is_mgtime(inode)) { + fill_mg_cmtime(stat, request_mask, inode); + } else { + stat->ctime = inode_get_ctime(inode); + stat->mtime = inode_get_mtime(inode); + } + stat->blksize = i_blocksize(inode); stat->blocks = inode->i_blocks; diff --git a/include/linux/fs.h b/include/linux/fs.h index 6ca11e241a24950d4bd44954cb285d51da2751e9..eff688e75f2f29f1c44dca96370ee230f8c21db4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1613,6 +1613,17 @@ static inline struct timespec64 inode_set_mtime(struct inode *inode, return inode_set_mtime_to_ts(inode, ts); } +/* + * Multigrain timestamps + * + * Conditionally use fine-grained ctime and mtime timestamps when there + * are users actively observing them via getattr. The primary use-case + * for this is NFS clients that use the ctime to distinguish between + * different states of the file, and that are often fooled by multiple + * operations that occur in the same coarse-grained timer tick. + */ +#define I_CTIME_QUERIED ((u32)BIT(31)) + static inline time64_t inode_get_ctime_sec(const struct inode *inode) { return inode->i_ctime_sec; @@ -1620,7 +1631,7 @@ static inline time64_t inode_get_ctime_sec(const struct inode *inode) static inline long inode_get_ctime_nsec(const struct inode *inode) { - return inode->i_ctime_nsec; + return inode->i_ctime_nsec & ~I_CTIME_QUERIED; } static inline struct timespec64 inode_get_ctime(const struct inode *inode) @@ -1631,13 +1642,7 @@ static inline struct timespec64 inode_get_ctime(const struct inode *inode) return ts; } -static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, - struct timespec64 ts) -{ - inode->i_ctime_sec = ts.tv_sec; - inode->i_ctime_nsec = ts.tv_nsec; - return ts; -} +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts); /** * inode_set_ctime - set the ctime in the inode @@ -2500,6 +2505,7 @@ struct file_system_type { #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */ #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ +#define FS_MGTIME 64 /* FS uses multigrain timestamps */ #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; @@ -2523,6 +2529,17 @@ struct file_system_type { #define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME) +/** + * is_mgtime: is this inode using multigrain timestamps + * @inode: inode to test for multigrain timestamps + * + * Return true if the inode uses multigrain timestamps, false otherwise. + */ +static inline bool is_mgtime(const struct inode *inode) +{ + return inode->i_sb->s_type->fs_flags & FS_MGTIME; +} + extern struct dentry *mount_bdev(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, int (*fill_super)(struct super_block *, void *, int)); @@ -3262,6 +3279,7 @@ extern void page_put_link(void *); extern int page_symlink(struct inode *inode, const char *symname, int len); extern const struct inode_operations page_symlink_inode_operations; extern void kfree_link(void *); +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode); void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); void generic_fill_statx_atomic_writes(struct kstat *stat, From patchwork Wed Oct 2 21:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820396 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 8C28ACF8543 for ; Wed, 2 Oct 2024 21:27:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B39366B03E1; Wed, 2 Oct 2024 17:27:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE94C6B03E2; Wed, 2 Oct 2024 17:27:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9625F6B03E4; Wed, 2 Oct 2024 17:27:46 -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 6C5076B03E1 for ; Wed, 2 Oct 2024 17:27:46 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1E0FE121063 for ; Wed, 2 Oct 2024 21:27:46 +0000 (UTC) X-FDA: 82629949332.05.9321B28 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 53272180007 for ; Wed, 2 Oct 2024 21:27:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rrg8jFdo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904358; a=rsa-sha256; cv=none; b=bAZTe530yrqIe77zPLGRk9EotG10sbDgRrAzwe329QDyJu3hffjL1343dtzU3MBgtGCrUV z+6g/3ALXUHRyku1mNY5Zlat7z/KzvU+AKly/Z1HD1U3GM3zKuMicBQbwnHcVEUGWQ1/Gz LrotUJwVn5nrQbEjOGwfhqz92+b7rSc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rrg8jFdo; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904358; 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=hRA5VBTxRD83D2Dn/4CC8fdkCWkafHdvui7Kuu5BnTo=; b=OZlnwKAme4VPoe3UY4bsBiWQpk7W64qQIyAta6Z11D9e9vDa0/AnhDJvqBzmbOZNrnRpFp TJHcWl6bSBYjQ7T+/Neo0yksM74TrDE2ooIGmUXw6sBNF2FbuJWLI4c14UMvZybWDMFsPc hgeJMbB6LJ/hCUIxaXrsPU0ytCAwMJE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2DD36A44020; Wed, 2 Oct 2024 21:27:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEAC9C4CED0; Wed, 2 Oct 2024 21:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904462; bh=nWAObiv1pT63De3yrHB7U+GTf1hLNrlZ3AMOKfvjPAI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rrg8jFdosDYWMwAA92V2hbU+Yuic3cTXnqQJL7/CjaS4rr5GNRsDVyFogFc7wde8b 3+ytxmfZcVBW7BHEAGL4MUuw8r8fjtd6551m/mw3PBYEMfUcJX5EVnFh9Dl4h9g9bq E+0f3RyVBQuyVN+jR02fOAGU05QU3hphedY25tfubjbgoT7Ovjfw1tUksa+EGwTKEP cQw9zf61IzShMjY9Nc7Pn7ReERF7yn1KIs8f8bQPZs7a9O4goDuhvZZeDLeqBbBWs0 G1gFKZ/7FA/CHJ+OL4QeRprqQq6UL2esAzsdREnCvyhDIodZoeCmPj/niFarTH0M/n olAqzjyT6/E3Q== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:19 -0400 Subject: [PATCH v10 04/12] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-4-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3623; i=jlayton@kernel.org; h=from:subject:message-id; bh=nWAObiv1pT63De3yrHB7U+GTf1hLNrlZ3AMOKfvjPAI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/ifAGWvuvl6BRwMs4Uby9r2RObyp81rJWQ t0O66nsopCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FUFdEACg0WGt0WZDsR4lYHjv29oOUq3iMhe6DMxJ/AIvWuxlPjl9W5bf1/v4xbhac64hqIi9t75 Ed8baE1O4menek+QPLY2fRZnnBQGeQXQg9S9rBIhp0xF3IDD+27FJYF8TT5BItAgxM+tE08Jj79 TxEMXfS4ytrx3H/6P8gkkrxj/Vq2KgyY+pXxhr6SJL09O3NDWwkl+CmZlhsbJqaDtd0Bu2Nkqoc 7XU2I/HmGc9+oXYAi4FK+WjMwm+NdZxBDxUf+mxJELst25MI6Gn7ZqLMfihTZDlg/lkXmnjoMYc CpIIZoyJ+HTB+U9Kge0Knzi+yySpldS6Jv2RXPCtm4ptKKFDi2JO1mhHQyQ6U0oVux1XaGQMEda hhXz0O+U2tobDuICI10a29pVUBbbzgFMTN60MymsFmu7SunVDjCCb1GVEoIOOfAITwjZdcdxth/ d8tPUuSxoGy4Xm9bPfSc6kUuaWp/GqTpsjbtT22UjDOKz1DJfLRmBLrSNeW2c+1WW6yPWoA5wCX gAjJGRkY+f5UkqUIhYc/guqwfh2fkG5UVSrwX7YjFkNlNJjQxYPkFfaC5YpfqjGNJjS8Mm/XNw8 RuKnlGcHgkVhCZdFDdF9m9DCLNYtwbNGQmPRyak0iaHm3uyL+MOfkADpMxPn3YOLLNHu/1Gw7j9 rHKf7yUI65eskTQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 53272180007 X-Stat-Signature: 861mo56a7xry5aj3nobbf7r4o4tkdij9 X-Rspam-User: X-HE-Tag: 1727904463-866613 X-HE-Meta: U2FsdGVkX19DDk/K4+MS9kvRDljLh1IJNo9Jep6brmCWjqbeznTuiACVQvynnixNn9fFoxAj6HDbT34mSMUN4LGISJAZHAC/BEz7dEcvw70k3kSwTnxD1LD+7I8x5kejyt3twNHrbkdy+tNtNWhYsi00vR21DOixEbTiMpb0tbkGQ/kWnPzWqJtZObHTWN3zAUbqo67BGU+xhyT8KeAQ+nVI5SGtgfgMXJfqBAlgv0UsLI2MsOoQaBFnDRTB61J8Iqxm/M8OU+NouMMi1kQ0OYTUSBDMIe/sQFx4Gx+Yigo39fwocEEQPYEAcuUMscTy9l2cPJhEp3aQJynQzwRkb8mimpVd898P1JwjlvRkcCj/LQPsfIYY6WqFyfeqZWMCr1at7eipqg+En2QLenDAQHRrLklFy89UX70khsA6CTfzmTQ8Z0s5rzyBN0CCOgcX4eaZzWXXGLAaAc8S5gDk0DiV0QNOQuI5PEWfbxc7j5/USusodAuHnTeF6iWCJG6s22xMdtNaZJhleTTq9L1iiMAUZ7QJ44G6Z/6be9DswXx52jmEcDYRvBbPaTIW9Fst9pUBgkYVJjGoT4NysARItjvHlS18mDnB6Nj3VDp16KhY/ubZ3R+7r19LbsU2Q2ANZ9B3b3gOB4n6aM3LxvsxG4+bHs9eSGzAX8xLAKTEhPijS9skawfUlqMGWFOukkcv2cnBPrVVDWGbYClUe/BIjX45ftw5WqnJNgvAsdVqB2bTr9N0ijIrIM1K9hlHq5ZljraWVy/6+ppK4fbrgdpRbl+MbOxiFg9XQn1feeDyY8gQzFdS3k5KBbbf/Al0oE/yg6dMTA+EaFiez1k1hNZ6uhNdFEbSjq+A/fFGYfXspRJh1xi+DJ1VBWetxmTezeobVWDxM33sYJSiY7bRnSiNAGOlo7bhH9x44Cr8phTsrqk0diKdAdEbCO6PrHvq5FtJ8ZpJAn6QqnCseyJNLH8 CrVhwKx8 xoJIn2Nzd8LHwo1PYmbzfYT+7jdH1YU34DvQnQUvm9CpTKkVyd/d9oCYSCglW0drH68Oan6cVp+R2jqEqrEbQcfiHo5QHdTrFJXANbwWh1/Sprrj9FE7ohProoEmszRD7PgZmFhhXd1sQbXELv5AzOt7ajKvrsoSRatB8LpW4T+QG2f13LgK9F99Qtfr4lQTK1wg8xUeGD3bqPJIkF1d/lJTTgAGwLmyWnZSCaSDCh1IAhQp74B5eckNZCm5mdZpb3iEk6rApBVvXE3xSk+fJQc6lzjwkkCr0gPtxCHjdlJJROH5tXIRidhluPGgwJfD8t53sVs0XzDz+8jonHNYaIN2N1vbLowSk2FLfjRDdtqmpoDebW0Wot3lXLc3gY52mqngPcWRvkl3OjkxaAV5qhmRjwCQKtLbuMp41yJmvEdWK3POPfZkuVl3uwID2fUV+ph+mwMj7VuVmEgnZHdwlEyW+rDF6ej72yTGfzwQDXX3oUt8DkJkEekurcppjy65CetMv2O2u2q8ygu1gkK5PdA4Kyg== 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: The setattr codepath is still using coarse-grained timestamps, even on multigrain filesystems. To fix this, fetch the timestamp for ctime updates later, at the point where the assignment occurs in setattr_copy. On a multigrain inode, ignore the ia_ctime in the attrs, and always update the ctime to the current clock value. Update the atime and mtime with the same value (if needed) unless they are being set to other specific values, a'la utimes(). Do not do this universally however, as some filesystems (e.g. most networked fs) want to do an explicit update elsewhere before updating the local inode. Reviewed-by: Darrick J. Wong Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/attr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index c04d19b58f1224c2149da57e3224b7bbbc83561f..0309c2bd8afa04bc43db6ff207f8a58d9f6a617d 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -271,6 +271,42 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset) } EXPORT_SYMBOL(inode_newsize_ok); +/** + * setattr_copy_mgtime - update timestamps for mgtime inodes + * @inode: inode timestamps to be updated + * @attr: attrs for the update + * + * With multigrain timestamps, take more care to prevent races when + * updating the ctime. Always update the ctime to the very latest using + * the standard mechanism, and use that to populate the atime and mtime + * appropriately (unless those are being set to specific values). + */ +static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr) +{ + unsigned int ia_valid = attr->ia_valid; + struct timespec64 now; + + /* + * If the ctime isn't being updated then nothing else should be + * either. + */ + if (!(ia_valid & ATTR_CTIME)) { + WARN_ON_ONCE(ia_valid & (ATTR_ATIME|ATTR_MTIME)); + return; + } + + now = inode_set_ctime_current(inode); + if (ia_valid & ATTR_ATIME_SET) + inode_set_atime_to_ts(inode, attr->ia_atime); + else if (ia_valid & ATTR_ATIME) + inode_set_atime_to_ts(inode, now); + + if (ia_valid & ATTR_MTIME_SET) + inode_set_mtime_to_ts(inode, attr->ia_mtime); + else if (ia_valid & ATTR_MTIME) + inode_set_mtime_to_ts(inode, now); +} + /** * setattr_copy - copy simple metadata updates into the generic inode * @idmap: idmap of the mount the inode was found from @@ -303,12 +339,6 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, i_uid_update(idmap, attr, inode); i_gid_update(idmap, attr, inode); - if (ia_valid & ATTR_ATIME) - inode_set_atime_to_ts(inode, attr->ia_atime); - if (ia_valid & ATTR_MTIME) - inode_set_mtime_to_ts(inode, attr->ia_mtime); - if (ia_valid & ATTR_CTIME) - inode_set_ctime_to_ts(inode, attr->ia_ctime); if (ia_valid & ATTR_MODE) { umode_t mode = attr->ia_mode; if (!in_group_or_capable(idmap, inode, @@ -316,6 +346,16 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, mode &= ~S_ISGID; inode->i_mode = mode; } + + if (is_mgtime(inode)) + return setattr_copy_mgtime(inode, attr); + + if (ia_valid & ATTR_ATIME) + inode_set_atime_to_ts(inode, attr->ia_atime); + if (ia_valid & ATTR_MTIME) + inode_set_mtime_to_ts(inode, attr->ia_mtime); + if (ia_valid & ATTR_CTIME) + inode_set_ctime_to_ts(inode, attr->ia_ctime); } EXPORT_SYMBOL(setattr_copy); From patchwork Wed Oct 2 21:27:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820397 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 A8721CF8542 for ; Wed, 2 Oct 2024 21:27:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C24B36B050A; Wed, 2 Oct 2024 17:27:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD3B36B050C; Wed, 2 Oct 2024 17:27:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4E2A6B050B; Wed, 2 Oct 2024 17:27:48 -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 7A7886B0503 for ; Wed, 2 Oct 2024 17:27:48 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E3B4740FDD for ; Wed, 2 Oct 2024 21:27:47 +0000 (UTC) X-FDA: 82629949374.20.3EC60D0 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf05.hostedemail.com (Postfix) with ESMTP id 28149100003 for ; Wed, 2 Oct 2024 21:27:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pErORCLF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904371; a=rsa-sha256; cv=none; b=MpqTRtdnFm55r8FCGOUdLqx3JIFDcXX4f8ERKw5viR2NDCTXPVmCp7x3uuTVnhszOPI0hM 1MOm9Aj9u+NTfHsq0kgoEm8njbTDH3p47uYx+nzFNWr9AZbMdMAqInnytgj72tytHMLFhB iZDcL0N5cEN6ObtB+wFzWjue2foJGe0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pErORCLF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904371; 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=RthaHd78aIzX6l6fHtlc28hdsCzk1km0BH6z0mUUcWs=; b=mGjfF+fhQkxSVvl8GiU0lfWx39WHvryMi9cF5TW1jsrVD3ZSi9H3MZ6ohZa/kkJ+18DrIF eqIZnAD7E5P64QMUYaJRhTNle2VOa1Z4I+3nXPEEclUId6NVCXJZqaWED72pS3cNUJ/t3L GaA+XrpXjvCmej9jaK8OYWch9aMcZRE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E3A62A4401F; Wed, 2 Oct 2024 21:27:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90C01C4CED8; Wed, 2 Oct 2024 21:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904465; bh=GgXDPuj4VTCO+KYXw1W6wA5jmJ8SPd2bLeg/94OOtzA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pErORCLFbUMtYV6Xg0Q8FSs6oa64pfK8QQ0Y2/53GcZECSBeypOEHAXcefZC1c2Tq nK/M2DGCQG1niK1yXv0WLJLWOr27L/5eLGvZfj6wegF9JGGH3AhxnV5eb9iH3Na9Ep CczJA9ddfxZ72S9kSmFSXcrlzuLes8ZZfp6aov8cqZu1YCkvACsPRLk5LFhVmIPDOa zNbRpMPaHvIm8fNV7gqc0l+mYtzLf4NLo2qaQvjXfMFsIDN4CyZ3MijISmLPCPNomW yrhuvZmXB7WYmqsl/t401/RJz34nyupB8rsbUKUjfJ6QidHDhDlmG0Wh1f1S+Wr0kT wqNcdegxY9Wlw== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:20 -0400 Subject: [PATCH v10 05/12] fs: handle delegated timestamps in setattr_copy_mgtime MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-5-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6385; i=jlayton@kernel.org; h=from:subject:message-id; bh=GgXDPuj4VTCO+KYXw1W6wA5jmJ8SPd2bLeg/94OOtzA=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/8ejyIg0PRylRvcQV6hmgwmnKDZHwiP42g ghVwS8PaLKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FUs6EACFaoAMIiWmAxm2JDOYSGBGqYx7XgULFJuHkZorvtP2QGTa3sFuMu0UtasSpV7DnjmXAp/ 58p6rdY498tiod4Ll7n9AwjwsBnmb2P2aPP3L1wpOZV+tK1hk+BnJ7XfM4/P3Yi4Bbut6GpQl8U x8jnTYyJFrknCniKjxi+mI91aXA67q5KEqqI8W+ZAr4E8C2Ai3/cD+24VbybY41A52VgelzA5EG Ap3liaASdiktai/bt5qbndIJJ2qvjFyn3QcW4Tz0LTSoHZFEY2MRJSO/6Unnl3bsZByuCsgNzCW hgi8TX/79pDgk+WdlH6cN7JN1pNFCNC6u8hyp8H+pbBYmHQ2sgy2vTR+2fKcKKtCls6CuTBkCE8 Lw3Ok0r66ptJdcW4waC3luYXt1KfZc1JpJ/Uw0iMc+jhYjhM8G9GDqFxgudGT60UrBhGkF6juES hrhkkqG/rpPnqv6AmU4Z5DtKHp8wR0nrZeiQUu5H0RqZ/MdrgEH+qhEEM0OKOfkbmNrXYtwuTmo 54WkyE0sLh/y23R41nuZPVgLSJul2Mzx1B3o4zRyc4pX0QiWdPI9CWYp+0ZPwp8fmXkMb+8aVKO qIysDBYjA+SkV0rOsDDA7fXhNsMH40A1UN0npUBje6zvkZFqTM4n/myilmcSEbsnFyU46LlFfRC 8/zxtdFjBqxLvrg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 28149100003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fcc8tnfnknupet81rxmpjqzi6wdx9kxb X-HE-Tag: 1727904465-239255 X-HE-Meta: U2FsdGVkX1+T9jotRoOTm8yYn+tbeAGx17Dh+QNjcCJk0p1isGDY/oqZ8jcmm26t2wqANqunWU24rnG35hG+nK+HSE6s3laWmblMF353YUq+LfJr8QD6uaJtoqHlh8Mz7y6ufAiHa+fzYWonhvABJA35dyPyUJ/MkvX7Rn8H2YEMvLIe6arYZlcA1BHUd02SlLqRByttyFfYPBsi9wLyOoEeK9SlWw2oSSH7N0E6FzqaRoDqKEToeBUXuTT3GkQddevqf+ZGF/nnPjs0FdvtXQpDi25CDVjK/0iXOZYfxmrtx5SAB/2qNaDfLwnark6YUsf0NIIJVapwXAWBLYMVnnjkFCfEBWe9FHWxO966wlLQt2FsDfNLWIiAkf26XfimEIm6KSN25glO9NU0So8OZI7soseYy5AeDdjrN0pv+ElimmkMrnpGyjotSZ5/WfRbnVv843IB466cP3PtIx0GYeLwDD8jKe2S5/TWSdHJmKkDRRANctSzPZ9Nnlx8IzXaOEGSRnoloIzbeZogpOOi5K55hE7z/q+2q9HvUJuiOI7+TCC5rZNsXNYLjZLC91yI3jATsPPVP8oeeRtXB+hfNY3kKPH5iGdFsPsgHgqyfIyUAO72mE9W3H7k2TSlID2MKZk5GOBnnQDm0eHFGvjEvmC50EHkf5lPkH61JdOfAO6BgVUqfLhIAXRrfHjffFwt9CatefyfviwiazBB7jKq0eFjyzX1Gkemi5jWDM9g0xPTjswVT4cgVwPnmBKewO5NQoN0Npo//tQOuWzyTBhN0vM99Mtdn/hKJ3ma9/q11Hw221DhHfcyQOMGdsFVzTI9Na58kexLEjHTsWBmYkcKSaZO7yAGXSV5kYCADwoj6INg+97RT8aEdUsiXuU26owzzLIT0NSuANPC2tosBO6nH43wd1z27z+SrAFODdXRptlUmraDsfXYrwmCneS9u+yNNMUV7H0aYu8MX+KfynM WBwbIJJc gooPx7P8AbE5bWC9jbkKWVNkF+P64D8a3Ttr+6G59kTw5WlrmHlVRasozPLJjGgUB3T6NOu2bpsXW1ushBx+pL8pQ1yXhJOJdC5cgyC2i0gkuo3m9HRGj7ksUqo5sbqm8cC+x4lMIZomXqRec9x+NXEbLH7YBy3YcFeqdv6I38zzZ452mW1IHHCY0+0XUt52d7CPem3u15PKVekroFvtz3/3iuoF9uOoF/AmOtHd8RSGXUb1iW9slGmuJgqKicgwCkYcIe8XsxrDllHeBfcwf/w8DMwTn8emXcUNuSpo2wvwCmLfzsiPNIMrgWbuw+fmAk1s2fPT4zhD0PZMqBi3AtUF9uUvrHstC3OmrCeI/gCUqJZLYP1jz1+JuancKUW2zwv6Qz6FRY77ZfbACB66DuIArgYdKa+CJEYVkdqfSPG/Eb8rpIIdastbTBRLgf7ITgYww/SXNwzi6yp109n+re4K35A== 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: An update to the inode ctime typically requires the latest clock value possible. The exception to this rule is when there is a nfsd write delegation and the server is proxying timestamps from the client. When nfsd gets a CB_GETATTR response, update the timestamp value in the inode to the values that the client is tracking. The client doesn't send a ctime value (since that's always determined by the exported filesystem), but it can send a mtime value. In the case where it does, update the ctime to a value commensurate with that instead of the current time. If ATTR_DELEG is set, then use ia_ctime value instead of setting the timestamp to the current time. With the addition of delegated timestamps, the server may receive a request to update only the atime, which doesn't involve a ctime update. Trust the ATTR_CTIME flag in the update and only update the ctime when it's set. Tested-by: Randy Dunlap # documentation bits Reviewed-by: Jan Kara Signed-off-by: Jeff Layton --- fs/attr.c | 28 +++++++++++++-------- fs/inode.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 0309c2bd8afa04bc43db6ff207f8a58d9f6a617d..c614b954bda5244cc20ee82a98a8e68845f23bd7 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -286,16 +286,20 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr) unsigned int ia_valid = attr->ia_valid; struct timespec64 now; - /* - * If the ctime isn't being updated then nothing else should be - * either. - */ - if (!(ia_valid & ATTR_CTIME)) { - WARN_ON_ONCE(ia_valid & (ATTR_ATIME|ATTR_MTIME)); - return; + if (ia_valid & ATTR_CTIME) { + /* + * In the case of an update for a write delegation, we must respect + * the value in ia_ctime and not use the current time. + */ + if (ia_valid & ATTR_DELEG) + now = inode_set_ctime_deleg(inode, attr->ia_ctime); + else + now = inode_set_ctime_current(inode); + } else { + /* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */ + WARN_ON_ONCE(ia_valid & ATTR_MTIME); } - now = inode_set_ctime_current(inode); if (ia_valid & ATTR_ATIME_SET) inode_set_atime_to_ts(inode, attr->ia_atime); else if (ia_valid & ATTR_ATIME) @@ -354,8 +358,12 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, inode_set_atime_to_ts(inode, attr->ia_atime); if (ia_valid & ATTR_MTIME) inode_set_mtime_to_ts(inode, attr->ia_mtime); - if (ia_valid & ATTR_CTIME) - inode_set_ctime_to_ts(inode, attr->ia_ctime); + if (ia_valid & ATTR_CTIME) { + if (ia_valid & ATTR_DELEG) + inode_set_ctime_deleg(inode, attr->ia_ctime); + else + inode_set_ctime_to_ts(inode, attr->ia_ctime); + } } EXPORT_SYMBOL(setattr_copy); diff --git a/fs/inode.c b/fs/inode.c index 53f56f6e1ff26e718080211880924f37cf0e5b3c..7d1ede60e549683502911f3bb3a3a079768e449b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2717,6 +2717,79 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) } EXPORT_SYMBOL(inode_set_ctime_current); +/** + * inode_set_ctime_deleg - try to update the ctime on a delegated inode + * @inode: inode to update + * @update: timespec64 to set the ctime + * + * Attempt to atomically update the ctime on behalf of a delegation holder. + * + * The nfs server can call back the holder of a delegation to get updated + * inode attributes, including the mtime. When updating the mtime, update + * the ctime to a value at least equal to that. + * + * This can race with concurrent updates to the inode, in which + * case the update is skipped. + * + * Note that this works even when multigrain timestamps are not enabled, + * so it is used in either case. + */ +struct timespec64 inode_set_ctime_deleg(struct inode *inode, struct timespec64 update) +{ + struct timespec64 now, cur_ts; + u32 cur, old; + + /* pairs with try_cmpxchg below */ + cur = smp_load_acquire(&inode->i_ctime_nsec); + cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + cur_ts.tv_sec = inode->i_ctime_sec; + + /* If the update is older than the existing value, skip it. */ + if (timespec64_compare(&update, &cur_ts) <= 0) + return cur_ts; + + ktime_get_coarse_real_ts64_mg(&now); + + /* Clamp the update to "now" if it's in the future */ + if (timespec64_compare(&update, &now) > 0) + update = now; + + update = timestamp_truncate(update, inode); + + /* No need to update if the values are already the same */ + if (timespec64_equal(&update, &cur_ts)) + return cur_ts; + + /* + * Try to swap the nsec value into place. If it fails, that means + * it raced with an update due to a write or similar activity. That + * stamp takes precedence, so just skip the update. + */ +retry: + old = cur; + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, update.tv_nsec)) { + inode->i_ctime_sec = update.tv_sec; + mgtime_counter_inc(mg_ctime_swaps); + return update; + } + + /* + * Was the change due to another task marking the old ctime QUERIED? + * + * If so, then retry the swap. This can only happen once since + * the only way to clear I_CTIME_QUERIED is to stamp the inode + * with a new ctime. + */ + if (!(old & I_CTIME_QUERIED) && (cur == (old | I_CTIME_QUERIED))) + goto retry; + + /* Otherwise, it was a new timestamp. */ + cur_ts.tv_sec = inode->i_ctime_sec; + cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + return cur_ts; +} +EXPORT_SYMBOL(inode_set_ctime_deleg); + /** * in_group_or_capable - check whether caller is CAP_FSETID privileged * @idmap: idmap of the mount @inode was found from diff --git a/include/linux/fs.h b/include/linux/fs.h index eff688e75f2f29f1c44dca96370ee230f8c21db4..ea7ed437d2b165debf680507aa450b2662fd5839 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1544,6 +1544,8 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb, struct timespec64 current_time(struct inode *inode); struct timespec64 inode_set_ctime_current(struct inode *inode); +struct timespec64 inode_set_ctime_deleg(struct inode *inode, + struct timespec64 update); static inline time64_t inode_get_atime_sec(const struct inode *inode) { From patchwork Wed Oct 2 21:27:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820398 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 2C73ACF8542 for ; Wed, 2 Oct 2024 21:27:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6825C6B0431; Wed, 2 Oct 2024 17:27:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6076A6B0439; Wed, 2 Oct 2024 17:27:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 411616B0437; Wed, 2 Oct 2024 17:27:52 -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 122856B042F for ; Wed, 2 Oct 2024 17:27:52 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 701A3AAE20 for ; Wed, 2 Oct 2024 21:27:51 +0000 (UTC) X-FDA: 82629949542.23.72F7E8B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf13.hostedemail.com (Postfix) with ESMTP id 9B0502000D for ; Wed, 2 Oct 2024 21:27:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RiQb+Vas; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904448; a=rsa-sha256; cv=none; b=bOS0UOxd85AHCvUALH38b+PU0G8qBLPi5HvVN1BYMurBAmAIZx4MXPCKo2tGrTtxkpbg5g EwTSOGAwf2D6ZTPSbBQeu2yRkze3hFKYFI2FCNQeXTkLrcClXvDMGFqT9GRuKJeD+I3rcH xhKpVbYoou1MwhBKBdy/zhkLmkfpxgc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RiQb+Vas; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904448; 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=I6ii9aB09e8UKHOBwSaucQlIFVSRtv+jsZSlvHg6Y9I=; b=1+Guxyis6WDjS1izBXikNnX1S1pVxBjNg9E+kutizwiHqHLOnG9FWHiD1fmlo2PEjOJvpq 1wxe97g8HTTgW6mtmbtN18zx5ZG+RLrAkdyQe9+dd3CIOHOZEIFpulE9K/ToCEndy+MDHS vjKOMHAPLJjr1oit8OaMm0SFgLk85Go= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 117C6A4402A; Wed, 2 Oct 2024 21:27:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53227C4CED6; Wed, 2 Oct 2024 21:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904467; bh=MRGGG8rqdJzdD5KgI4WfyNMzLguXPYXob8v5j7W1QaM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RiQb+VasJhrhbm+efzGbpIcwLxszW5XKADxsVvHvZ4PtU9omVM1uKPRYjdDFTLrxU spC6qoc3Jx5R2FiTqiPPDvCGVFpDpJoGjjicm25vd2LLcfcz9jjV/RR/bjlnI1V4EY ad67YYwlvOrSCQNhgnodXxdPfs01FPltkNs3R5FmGOCg4ttPkExz83Q71CZ2EKDmER 3vEcrINS5svEVCEpFlZZQrG/rtN2NbUWpkxh9VaYk5MStmuCmVXUCBhdZXbYBg8jBs 7qYe48hdyaiE4eaWZsSg0Wr6BU5TlKcgxiilkkzod6H78fW5qEKHCFkhLxB0g4czZQ 211YHMvElLRgA== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:21 -0400 Subject: [PATCH v10 06/12] fs: tracepoints around multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-6-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6245; i=jlayton@kernel.org; h=from:subject:message-id; bh=MRGGG8rqdJzdD5KgI4WfyNMzLguXPYXob8v5j7W1QaM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/rrV42gSWRnMywus+4vWn2erTXDHpugNyH p5Jt5mx0kCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FfHLD/0Y+Ozd45QWOEXlGcizIJuYoklt/IclS6YYuOynkLK657rXW0pb+HYJPpKskii5RnL8UEO zVviDGgIKrEHkavVfZbP1PYA1Z+VQJxoYVWmMckxEU4D/ttgg9q8HMGi6CTbx8HZxejV2aRidO5 Q2DxmAfAokB2UKHZIppBcbZszz1P7Kl0yfRlUKeJuklq9GVYBs1Pim1fZgiXRyYL6b+tP/7ps5C ymjA4tKdOekiGiOceknMPhjV8Y9IqU+PmHDLm2KiN5LIetf6bnNXJkL52Q29NJ+eyMJwio0Ff1f Or/F8FVlAfl8FiM6wEM6D4BzMWoUdKQ4jZhMYgFdEkKNPohN1ckS5sGybaKegOQKCmz935a0+QB BPqzCoiaaZpYYAktHl5D4RtVolKmJtLGY2UYlkv0XkOyEjWDXeFzLnjTufDI846IzHPWWVDRGJ8 9EaICfw8ssZEJ1BjJ3qNb5yFKxCidh7aW86QQORcgAC80gN2aI+HZXv9ijN3+4SCsr/suRndazc kUa9Wh92buOEq+U0+WoJQBKJ5dKFUJram9X+6fl//fjCaCVByxDXkahkzeJk+k/CKqLT5eUqaWc XKmwVPbj0nWdMCahwZT6k0Suf4uVnDOSP/+bA9QNEaZGS34TkJrUBsyzRUcRoKoQpfFn6QVLS4H 6h9x5TdrOvNT+vg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: yqdtoddkii5z6y4cti5oc8goy4hbqsxr X-Rspamd-Queue-Id: 9B0502000D X-Rspamd-Server: rspam02 X-HE-Tag: 1727904469-184353 X-HE-Meta: U2FsdGVkX18ZbPmxy5qFCLF0ILYNbJ3JZFac+ordSe6f3EgJweND9EmTRLB1K0JdNDxcYKgYhMR0kUfCrU6gZqOwXO/PNmU4ffG/juq4ARdsypvO1TBchmQHC3CRfYLgrWTGfcm/O9iX3oXT5OoZZTuVMAugJ5AmhLfArNj+kFPbFehXSmAH8oo64+IgCjulXM6UKan9+qORW6jD7iNjQqEq7RxypmF3jPsgBJOiL8wneKqhTF162LHnuv/lvtg4+A46VwpMvBd82KhbI42Oc6tC6cG4mUwdUQL2+qlHgU4Fm/+ffQQLI9ggcylKtO7KsONf58fhOsYSaqyXx9qSbPvgGPi9L9MptOvdNxXfKvsEtJrFZI8WMZJGiBNRggBVlc7h/dHpbwu1oAFyh/tazKfCENwI7z+cDbs1Rq5RS/pPN11VdjS6ft00jmS4nV1ZKf6BRCovv8Wafn7PBlKN9s/fbPLiWutn4h4rOuK4UdKKDFJAKNDGPKWoFvBHViUSu6rfZ9DCacSN22ll0OgiFc0Gfft7eskG//ZUqUEZ+C7YyRIJ3/plEINURalrK7UyUZKM61PNBTACur9N8Bx2jewrvxth/nZORRfeJR52oYDaNK5FG/ZyD/wXoe1TrDcd7GYtyiblOlEMKfUSoof2g6PUqbaHwrLzPFtyGIhxtLNiqfwXHa8qGONYuOuRWaCN8kn9bsW8QwLieLgBMiQ0oAfTCrPzZG4KzaAwxgTJ/oYw1+N0M7DpnaQ9rwK49DoTw/fURjZ3d+54ze+dGUyLzamltFcZzPWS0FiMOSdGFr6zBRxhS7l2iyVa49WPpNbzVle7eRj/N9Jb+PsBizt0AAfCFn5sTiCGcUlyGmx3r2V1QzuXOd+hFusTRzZ4/0Aa42VnenhMOy9NZUiUNMwVg6oJlvpEL5af2EB3Kg8RlYWK6O/Xr3LRkplGIXZqHIa00k9jo2LEaNVTQ+Kagvj +Nv0LSsD 5tnwQsu5RFPjwA4GaGgu5oidMAWJm2ruZB7pjWnHMZGVtWsoJUG2BT60xkPzoCQJq8lPC23UF0MyJqb9+zA3cCVhLk0XNWGK1mEMueALMGAMrLXyzG4wF0u9mSfYxqpWB0FhYaYdnsB7sYeGEIyYXaJ0sDQ5vV1E9jofQ98mSYEBHrv/c68SolvPtuF96c/qpew6OXpkdV7f05GlZfOoUVILGooOc9HlCXeelCh6Jg5b+G+WFQz1qz5IYXTz3vYrI3VSjH7TmD+nFcSBgH4EXoHafZ16VFxIoDfq0rVLG0s5Vk52jiPFArloEgwzsZUMpjrNrfeyr9Oe2OTGAVrAPexV4gdnSwXqMJGJmS/JuMd1Dp4j7myme6j+j09I9US2asNTXAu/hu8VGvS2lTMwY9yPo2LB3l4Pia1nX4igQFPGsxi0= 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: Add some tracepoints around various multigrain timestamp events. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Reviewed-by: Steven Rostedt (Google) Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 9 ++- fs/stat.c | 3 + include/trace/events/timestamp.h | 124 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 7d1ede60e549683502911f3bb3a3a079768e449b..f7a25c511d6b7069fa235135cf3bad0cda32815b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,9 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" /* @@ -2603,6 +2606,7 @@ EXPORT_SYMBOL(inode_nohighmem); struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) { + trace_inode_set_ctime_to_ts(inode, &ts); set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); inode->i_ctime_sec = ts.tv_sec; inode->i_ctime_nsec = ts.tv_nsec; @@ -2689,14 +2693,17 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) } /* No need to cmpxchg if it's exactly the same */ - if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) + if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) { + trace_ctime_xchg_skip(inode, &now); goto out; + } cur = cns; retry: /* Try to swap the nsec value into place. */ if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now.tv_nsec)) { /* 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); } else { /* * Was the change due to someone marking the old ctime QUERIED? diff --git a/fs/stat.c b/fs/stat.c index dd480bf51a2a764e5eb1d0a213c5ec8b640db911..6eb6c39d003755f9e602996ed93dcbd863847820 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -23,6 +23,8 @@ #include #include +#include + #include "internal.h" #include "mount.h" @@ -56,6 +58,7 @@ void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED)) stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)); stat->ctime.tv_nsec &= ~I_CTIME_QUERIED; + trace_fill_mg_cmtime(inode, &stat->ctime, &stat->mtime); } EXPORT_SYMBOL(fill_mg_cmtime); diff --git a/include/trace/events/timestamp.h b/include/trace/events/timestamp.h new file mode 100644 index 0000000000000000000000000000000000000000..c9e5ec930054887a6a7bae8e487611b5ded33d71 --- /dev/null +++ b/include/trace/events/timestamp.h @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM timestamp + +#if !defined(_TRACE_TIMESTAMP_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_TIMESTAMP_H + +#include +#include + +#define CTIME_QUERIED_FLAGS \ + { I_CTIME_QUERIED, "Q" } + +DECLARE_EVENT_CLASS(ctime, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + + TP_ARGS(inode, ctime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ctime_s) + __field(u32, ctime_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->ctime_s = ctime->tv_sec; + __entry->ctime_ns = ctime->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld:%u ctime=%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->ctime_s, __entry->ctime_ns + ) +); + +DEFINE_EVENT(ctime, inode_set_ctime_to_ts, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + TP_ARGS(inode, ctime)); + +DEFINE_EVENT(ctime, ctime_xchg_skip, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + TP_ARGS(inode, ctime)); + +TRACE_EVENT(ctime_ns_xchg, + TP_PROTO(struct inode *inode, + u32 old, + u32 new, + u32 cur), + + TP_ARGS(inode, old, new, cur), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(u32, gen) + __field(u32, old) + __field(u32, new) + __field(u32, cur) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->old = old; + __entry->new = new; + __entry->cur = cur; + ), + + TP_printk("ino=%d:%d:%ld:%u old=%u:%s new=%u cur=%u:%s", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->old & ~I_CTIME_QUERIED, + __print_flags(__entry->old & I_CTIME_QUERIED, "|", CTIME_QUERIED_FLAGS), + __entry->new, + __entry->cur & ~I_CTIME_QUERIED, + __print_flags(__entry->cur & I_CTIME_QUERIED, "|", CTIME_QUERIED_FLAGS) + ) +); + +TRACE_EVENT(fill_mg_cmtime, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime, + struct timespec64 *mtime), + + TP_ARGS(inode, ctime, mtime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ctime_s) + __field(time64_t, mtime_s) + __field(u32, ctime_ns) + __field(u32, mtime_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->ctime_s = ctime->tv_sec; + __entry->mtime_s = mtime->tv_sec; + __entry->ctime_ns = ctime->tv_nsec; + __entry->mtime_ns = mtime->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld:%u ctime=%lld.%u mtime=%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->ctime_s, __entry->ctime_ns, + __entry->mtime_s, __entry->mtime_ns + ) +); +#endif /* _TRACE_TIMESTAMP_H */ + +/* This part must be outside protection */ +#include From patchwork Wed Oct 2 21:27:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820399 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 A28F8CF8540 for ; Wed, 2 Oct 2024 21:28:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBED16B0450; Wed, 2 Oct 2024 17:27:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCFAD6B0452; Wed, 2 Oct 2024 17:27:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5E4C6B0451; Wed, 2 Oct 2024 17:27:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8AFDE6B044C for ; Wed, 2 Oct 2024 17:27:54 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F133F40FCB for ; Wed, 2 Oct 2024 21:27:53 +0000 (UTC) X-FDA: 82629949626.27.E488D61 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf25.hostedemail.com (Postfix) with ESMTP id 2BE95A0015 for ; Wed, 2 Oct 2024 21:27:51 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tzCXJ6wf; spf=pass (imf25.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904344; 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=2niIZp+S6Ffg2N//A/i1ylAEzsQj1OJY1M53VeI4qYQ=; b=IlEGI9rIcRNZ5enXYHZ+FCjUU511pVMkmNkxgJnKsUrfXvmFKgeveL2Bmfgoq+NMUi28hZ yaWxg023IU6IYlwJUcOaZinThBzrj7N4bt3QMFzZP4jzJhBqBBB06ztIHa854RSuJEouW0 3EYXPV7fY3kluN7bafVFbbjZr8kxiwI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904344; a=rsa-sha256; cv=none; b=JK2lZ58fwayNDDCGIzQ/LPFL/VqYHgIIA5nhyHxrA74zV009ets6ITuv6Bm9l7Z5z59Dsq B1Px7qH/rhKgQQcpOGumwOOrMmvgnKn2my9Vc+e5OT+NJxBoBApJoMEoB6rL1npYpNQAx2 LyZ6lwz9z65XGYlb5H3LIOLSRgJ/Fps= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tzCXJ6wf; spf=pass (imf25.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id B83A1A42600; Wed, 2 Oct 2024 21:27:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17306C4CED1; Wed, 2 Oct 2024 21:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904470; bh=Z8ARvNSJ2qaGQw9gXXGsklzintCaz0parTyIMYimjOU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tzCXJ6wfC5VMb2ExRKKrzQ20m0/cMA8alt1mx22BM50xuDhE0GS9gVEFsrjSveh5f HFH5VS9B24S84IqvZUpSgC0C1q24ouXK3xTB7RbQfG8UaeRZcICfAK6HDjmfFkfBV7 3aO9o2M1mNeM3mDVEnXkN4uh72RWd1d3J5IlhvmQyO4+hhMRETQlHKR4X9G6/DFhRe YSYJkbBlozjLOXMmaq1m2Gt9EFtR/FJhOO+7ql9Vva32Q75BFsiORHAqNQJqujNmqW SBn90QVLpNFHTeIS+z4r+VmFCXvrhebJ9B4yq9M8D2P5LJh1lY5wtzoECPs6IH+MI2 QP5O6BUQzp8Rg== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:22 -0400 Subject: [PATCH v10 07/12] fs: add percpu counters for significant multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-7-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3654; i=jlayton@kernel.org; h=from:subject:message-id; bh=Z8ARvNSJ2qaGQw9gXXGsklzintCaz0parTyIMYimjOU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/bq/TMaGYuw/cJFUuusrG5sD9Gz0d9qf6qw5y upmhOuFiF6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26vwAKCRAADmhBGVaC FRvxD/9evDrf3HGvYTuhxkxutkxIEi68sVhkiNZD69Mm7WZA2CzmHFpkbIzJUXlNfytAPvjdSGx Se9Non3XuQRLNglgc0lhxcfcZdu/X+u5yMiBvHkBZEf5lodGBnhBUeXjm4jg9rEign2Xcke0uen zmW17gVIHwMZ3pm48WdgDnI8LGujnHwyRtaKHMgoMO1zgnVvcxwJwwUnejPgDLsmruCTvs+3DcO Y1qi5xwXYC30GgA8xLI3gOheiXnZPH7tbEJ+CH8lRjel+ECcxNYyb4BgLgnjumPTmVu+ctbB3O/ NyFL+R7Pi0fN4SNBqZmhwLTUJrcqb7DCkLXIHsvJwkrbW3Bqnf24X7QYDnJtEJQ9zSf7lLcSU6k V+ew1hvKLd2wb+drV/Ii7HSHdlUZvaWrk8oHWdjSCKLvUAmjwdajzx9wmNWqXhGfXmTr0ecFsKA NXFHfSfVYvzOmgE53f2k3i5mgVRZyIhHJUlyjRFJKFGzUxYaTAIh5NNmXRgDtW4ppFtQH53Hxhu kp4ZqjZv2oO3ibhlxc5JK1fBHr6GVEm5y/b+JdsECtsh3oy/dqkLWdOAHXM5vNLGLzaBO7Qa7Ds CYD7TxCxZPUyWMagc0FhPLEfyvMm79Aw6QZdmp6UVnPQO6c8VRfeyGOyuivKJVQaMeSbXMaQuV2 JHDiBQHJy0omjwA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 2BE95A0015 X-Stat-Signature: bg7eiwefiucguhi9ef7kjg8e3onk8rfz X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727904471-43905 X-HE-Meta: U2FsdGVkX1+zrzriE3AmiGev0E+IzuGnf+IDXahjbXemeR4tdAb/SCp/wrPQElveLfi3eS6u+ag95ZYvl+OOgeIe2fdy/9Dk+AqgFt9ZL2Ku+FCCvsGzeja3u1FgBC+1kRAsMZ2QtYXbsJ6t0SX3hw68DH2OBPrWOaxhMMgxA3p/c2ytf/ToJdG/ifDaa4JQ/NRSkSulU6CH2SEt9ip7yMa9SMcylrXxfNXn2UqFGNiNVwoksU6SAfQvnxhuHXBdj+XDSs+JuwpuDymMS6nWakzD9oEtvUJQogC0te/3Tt4kO+/Gw8Tpayw+7xfLg4SXzLF1vwUByY0zwsmoh2mLgjBfICk14lkeJQyucbFcgrjLwsQx5Ejd4bwk9HE52uzaadI+Zene8nwugIHocvAcgE7taYF2U7opxolMulsl/dOsjJm/Jj8Jv/maH87coFOkKL0tCNdATFm+xE0JPlD8RJ5R9l8Yt4rpOdRawv6v/ioi7uGIN83kL+oLy1qjMRCyuzKgOG30AdXu5PdzO/KgLxqTlGUDpcAFzEacWV/EWJOYrJrw/WL7ZEPtQwD96OsFHY8Qn0BmRUFzW3pnuuTcWeMW+dI5AcePiDMv3AeaI1N71A3lZrjy+dSVk/DvGW/g9ZLZcULJZ94GMDpl6UsxQZXW6Hvwe+PV5WNGMNuy5DtRwLyRRQA1g1F+lpCgMXM5phe81BsBEVz5l30mvtfy+IUmmEprf0h2Kkdw1l9PWgaCAJ5Rf3aiia8mMzWkABg1N7F4UPzM8t2wDTkAdan+PfWw14FT5l2RDn2hpQpl+TCK9pJs2wDP9qF4rxAwCZkMloDtjQnENI8TtsMjd+0Xh5FBIDnevB/ve5QYTeb9/J+K9MgZ7L3gnuX7MgK5wzdnfGnWQ/MKwcvOrWoCVc1eh+AqC/ZJImBTjkPC9fAFqzZ/1K9lE2okxCpaR6v+cAXt3MmewCKZCGgyRIfBGIV IgFbNMDI /fWs58LHAFXlabWIzLWxFnpW9gYPviX6BApithS9fH4k71lfshf96JoXl3kzWIMtPcJ0vlZHjOdbVjB621M2khTN3Bwckg0sICAepL8aY0e53ah0GSftQW0rEudpTLFRyFDo9bWf1900yoBA8K8sIRoc062Di7kYJ//YzkYkKgTPyHE36TeP1yBQA0//84PPJbrPkXS89ud6HRRBXAcafoA/JtJ8/id6rngw1GYwrnRhSRIfscSbHd1YfNZa20AWNmIhM02UAOSbAm3ZqlJC4k75JWtwpuHzGk4A+vO2Vy+4x5ZiV32ut3skmBbrqLvzHM7PlxpVs+9+FTTPE4dvCI8K9LsNijwO0eKndrLLgTb8gvFE= 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 - number of floor value swap events 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 | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index f7a25c511d6b7069fa235135cf3bad0cda32815b..6d501c7308aefcbb8001d64cb46e57f1839b8a3b 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,70 @@ 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) +{ + unsigned long sum = 0; + int i; + + for_each_possible_cpu(i) + sum += data_race(per_cpu(mg_ctime_updates, i)); + return sum; +} + +static unsigned long get_mg_fine_stamps(void) +{ + unsigned long sum = 0; + int i; + + for_each_possible_cpu(i) + sum += data_race(per_cpu(mg_fine_stamps, i)); + return sum; +} + +static unsigned long get_mg_ctime_swaps(void) +{ + unsigned long sum = 0; + int i; + + for_each_possible_cpu(i) + sum += data_race(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(); + unsigned long floor_swaps = timekeeping_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); + +#else /* ! CONFIG_DEBUG_FS */ + +#define mgtime_counter_inc(__var) do { } while (0) + +#endif /* CONFIG_DEBUG_FS */ + /* * Handle nr_inode sysctl */ @@ -2689,8 +2755,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) { @@ -2704,6 +2772,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? From patchwork Wed Oct 2 21:27:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820400 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 047B1CF8543 for ; Wed, 2 Oct 2024 21:28:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDC2B6B040F; Wed, 2 Oct 2024 17:27:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D822B6B0412; Wed, 2 Oct 2024 17:27:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFC7B6B0411; Wed, 2 Oct 2024 17:27:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8EA676B00F2 for ; Wed, 2 Oct 2024 17:27:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 488101C6E70 for ; Wed, 2 Oct 2024 21:27:57 +0000 (UTC) X-FDA: 82629949794.02.E97DDB9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf22.hostedemail.com (Postfix) with ESMTP id 7F1EEC0009 for ; Wed, 2 Oct 2024 21:27:55 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tZdd5t/F"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904435; a=rsa-sha256; cv=none; b=xffmMfoUQq/7s9ySCu+w5YQjVcw0mtNv7+h9v3Bq+4z1Yu5coTFCYQUVaQDyf9oUJi6UhS j+Ab9tsZrdoezinaF76cJ2wRnKjjgFUoIINYV+m1w7h2F095lBFv/nFJi1ehGQhaJycjbg 8WlZlCxoyJWasVhi/6qgaWN7/09mx8U= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tZdd5t/F"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904435; 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=8GThB4sgw8WggfBS/JKrNuZ55/RWPHTqoG1qOHnND80=; b=DXsB8SRvkal17FKQiDtL6/P+2BvP+0RU3feWjGFi2uUx3FyKJogaGSTXKUEd2+TzbUVYRz YIwfv9ZObVjLOjlHCNYhlMLsrcrbySf3CCJOaj/oXVime6oiowLSc0VayuTy0qyyBzlNPg ETVxsnhXvBZnvWufrUTgaiLhg1hJaW0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id DEBD1A40BFE; Wed, 2 Oct 2024 21:27:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDD5AC4CED6; Wed, 2 Oct 2024 21:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904473; bh=qBtzxV6C3gNnpXcNznor+GUfZID0zTF7K3hXwvPKJ3M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tZdd5t/FDA6BUDMKhuyJUMzgrU7Dj+ArevBTpINQ/kUw0bID2yhWKQpKYebxZG9T4 2HlHzHF/uJLRfFA19ndqG3latGrn/u720RlCJbM13CK23otWdgZtsYGMvwyX8ndXZ/ H8igGJd+Yl0+pDHWi/44IMj7dMBiuhLvFzott0kklgeHKAfK+g3pmdflyDlxJOH9sA y36edvjXMAAWajMoebqCmpJp8QVaBZpMdHVODRyfbSppMXtTxwys10nWxxlpiHuZh2 OjTH5zGsziWEHSHh8x/FV255nV5xQkP6RCuEJqa0VcmQfpX79TKxcTXe8XDQZ4pnx0 qZT1ErIW9PRnQ== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:23 -0400 Subject: [PATCH v10 08/12] Documentation: add a new file documenting multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-8-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7402; i=jlayton@kernel.org; h=from:subject:message-id; bh=qBtzxV6C3gNnpXcNznor+GUfZID0zTF7K3hXwvPKJ3M=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/brA6I1dI8EG/U2Sb1UisGHQiXpPg4GwgYbr8 hjnuAbXthWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26wAAKCRAADmhBGVaC FV/tD/9X5pKIVIniCMvGql/J6WLFzqLMJ1KN/xNGXflDxvxSCtFhy3Bk+wgy5xigEQNhlpabOFn LQ6qkRRkug8tMq2+YV3w5KKcCNUzqBJg51UTT2r48f95rUtSl+q3B5N79OsZ1HzK7fkCD99+xaO P5DiED3DEtbfEhbsGCRpRyjrpKWqS5dCYV+3ggmpHv5XXtmAJMicDBzW443AVoks3ua0yvhF7/v dpd86poXepdu9zB2qA1wm17Skp5Paejf+WJXi6ilJOoIjZYVmhmzs9p/u/XmvpWtFuOlnGN4Gou Is4gcsCS1Zbpocaf+FWUf4TZDeQ3tCqb7LlmMFHRcO9MWqKJaKiSeqkdlHcs56K5MPzYnvjq1Gl lXJJjYPdgzD6ZldrFYidpzx3sDvknnjR6lvvo7lbI6dU3QPIMx77R8vd5REqp9nuMZKx4xZXVPg V/vtq7O0C+m6q3YCj+PYh0EYBY4I5Q2YBCG6RlOR2pJUdwPZ731ke2R3gPtm9qp+6WBj4rdEymx oj2xDpllQcSOV4ieVhIL2b7GOsIObiy7LKiLmekwwpazRph8l9tHk0krQvvZw8cK93TUpfYK3VC Ll8T6GXHeXnAko/UaPT9+Xd/1TjOj7hVYYRKN+Id8tDiGX9GQPRy5BPJgcW2zD79/af/mEp1NiZ QYYMHRnTwY+vL7A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Queue-Id: 7F1EEC0009 X-Rspamd-Server: rspam01 X-Stat-Signature: 545yeey4j7ecidjftxfsq5piuwyno144 X-HE-Tag: 1727904475-784037 X-HE-Meta: U2FsdGVkX1/FC3tl+quHSgH+Y161OCS/LlSQpUV5pDIUW5AQCRTq3PLklniVwkf0G81beQnHrdBiDGZExFkpSM3d2nAk4b6E5M2HuDRMUiH/o8F3Z8qYKZ4ZHHpetWn3WhdCIXtwjHCJj80iAD9P30N3WAB8ncBd2qTNXQy6nfVh+k08cs1Ba3FjNYUc80umWdMkfTFtP7ehqkFbuU9BrUb2hzXbFTvwAiF2yoSm4C2jrTj2vR2ZgHdFSxQzLeLtct873TCU9QdpHdesXOPyePkUjRIoYAGXMyAEM/ftcbei24zfitrw1GaH5pprRQLSpDvTNQ73PuGd62JrxrjMGfA9of3BhS7L9Zr5dsxzfm7po6FUUips5F2Ww8leLgEOFZe1aS1Mat8cfZvom661rNvn4FSGX9XJd5WykbH6kG6Ld2/dUsKbC4nHWDbuI5sELp7ON/+/VROCFzt9Za/LBTvX5k4ap/X99GTtSDiPgIYSaF8QgXooOxvLAaiYALwZEFgs/VWzExwERE1YNzmPkbH6JKYe8v2Rom30ehq7hTKwdEjGr+YAnlx7BjRkFPa9w+LogF9ZBnspzkXihaHUef8RmHEa2DwswlYBqhdtxVVoLMgOLdgKh+m1hiekuSo6ZnEoldLHXa9wkj/g1FVBZpfUfMhXDSQJaXQDaPxsVUXalhKE1BZKdVuOlPFRHsyeK9E1DSiPW4hOBuug812VO6Zj50p7BM+yOAGWQ34HKkVzwNq7zAArMDN/ku7M9kleUu0YpFTkfptWJvxztZAtE+p1q8X0KvSXiLkQ0QnLN+R4nhrdz6i5HES+yGGD33S9VCkPiORjRrQRTxvwxVCjMo9jdlN+K+EEIqhz2BqyhIb1VUbh6VnJevGpDmXHEjTGLwkrkW4q/EY3N6oQ9eYO+1PsuK1f0cDMLhcuZKURCHGmsnHani82QTkbVH9qaswKtoGKdSk7QxEjP2o6ZF2 Jt72u3Pv oMae9DehwebysfU7HLjio+s9B2cQoPXIPzPMAxA4WzLn8tTGQBYX4eBFI9VhJ3/Cm5JC+HUq13OcA9e8fZBhAZFg+CW0FNzVDyUSbMXTaifKwOvITiOF7Bu6iCAQqgk2Wltwqcap+xktwuRqSqQau5NbtjInBEIYvZf4jF+mvVcDjuhxyzZzNF//cTczYI7VhiqLk6hNA84G9/ClBHWtCKUJonHHaCN0ETh7TaWGYtOU522DVqP8QTIXafzwfmotv/XjeB5ZCvvLD99WGMOqscyqyiZiQ8xdJrC/5SUmIyC2qjH9IeKHppahTfgo3iFSsjykg1OJ2cpaKbHt0fFvEMlHDav6uHRRLf+TEbofSePAf8755OCfYLl+CnG26gPLBSucNTbsducRs7azM0qD3OPYimH8Hx2YwMgqjkvdC7V6qa//oks6YjI8CHTAiwHo25K02Qt2bDYa12zhcgzaseHh3nHXN8YJsfTfv 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: Add a high-level document that describes how multigrain timestamps work, rationale for them, and some info about implementation and tradeoffs. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Randy Dunlap Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- Documentation/filesystems/index.rst | 1 + Documentation/filesystems/multigrain-ts.rst | 125 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/Documentation/filesystems/index.rst b/Documentation/filesystems/index.rst index e8e496d23e1dd5b523889159b464d7adf5d5c30a..44e9e77ffe0d4b9c85f9921190d33dfd21acff8f 100644 --- a/Documentation/filesystems/index.rst +++ b/Documentation/filesystems/index.rst @@ -29,6 +29,7 @@ algorithms work. fiemap files locks + multigrain-ts mount_api quota seq_file diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst new file mode 100644 index 0000000000000000000000000000000000000000..c779e47284e80f54ad9fc8a6a0b03228dbbf3d59 --- /dev/null +++ b/Documentation/filesystems/multigrain-ts.rst @@ -0,0 +1,125 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +Multigrain Timestamps +===================== + +Introduction +============ +Historically, the kernel has always used coarse time values to stamp inodes. +This value is updated every jiffy, so any change that happens within that jiffy +will end up with the same timestamp. + +When the kernel goes to stamp an inode (due to a read or write), it first gets +the current time and then compares it to the existing timestamp(s) to see +whether anything will change. If nothing changed, then it can avoid updating +the inode's metadata. + +Coarse timestamps are therefore good from a performance standpoint, since they +reduce the need for metadata updates, but bad from the standpoint of +determining whether anything has changed, since a lot of things can happen in a +jiffy. + +They are particularly troublesome with NFSv3, where unchanging timestamps can +make it difficult to tell whether to invalidate caches. NFSv4 provides a +dedicated change attribute that should always show a visible change, but not +all filesystems implement this properly, causing the NFS server to substitute +the ctime in many cases. + +Multigrain timestamps aim to remedy this by selectively using fine-grained +timestamps when a file has had its timestamps queried recently, and the current +coarse-grained time does not cause a change. + +Inode Timestamps +================ +There are currently 3 timestamps in the inode that are updated to the current +wallclock time on different activity: + +ctime: + The inode change time. This is stamped with the current time whenever + the inode's metadata is changed. Note that this value is not settable + from userland. + +mtime: + The inode modification time. This is stamped with the current time + any time a file's contents change. + +atime: + The inode access time. This is stamped whenever an inode's contents are + read. Widely considered to be a terrible mistake. Usually avoided with + options like noatime or relatime. + +Updating the mtime always implies a change to the ctime, but updating the +atime due to a read request does not. + +Multigrain timestamps are only tracked for the ctime and the mtime. atimes are +not affected and always use the coarse-grained value (subject to the floor). + +Inode Timestamp Ordering +======================== + +In addition to just providing info about changes to individual files, file +timestamps also serve an important purpose in applications like "make". These +programs measure timestamps in order to determine whether source files might be +newer than cached objects. + +Userland applications like make can only determine ordering based on +operational boundaries. For a syscall those are the syscall entry and exit +points. For io_uring or nfsd operations, that's the request submission and +response. In the case of concurrent operations, userland can make no +determination about the order in which things will occur. + +For instance, if a single thread modifies one file, and then another file in +sequence, the second file must show an equal or later mtime than the first. The +same is true if two threads are issuing similar operations that do not overlap +in time. + +If however, two threads have racing syscalls that overlap in time, then there +is no such guarantee, and the second file may appear to have been modified +before, after or at the same time as the first, regardless of which one was +submitted first. + +Note that the above assumes that the system doesn't experience a backward jump +of the realtime clock. If that occurs at an inopportune time, then timestamps +can appear to go backward, even on a properly functioning system. + +Multigrain Timestamp Implementation +=================================== +Multigrain timestamps are aimed at ensuring that changes to a single file are +always recognizable, without violating the ordering guarantees when multiple +different files are modified. This affects the mtime and the ctime, but the +atime will always use coarse-grained timestamps. + +It uses an unused bit in the i_ctime_nsec field to indicate whether the mtime +or ctime has been queried. If either or both have, then the kernel takes +special care to ensure the next timestamp update will display a visible change. +This ensures tight cache coherency for use-cases like NFS, without sacrificing +the benefits of reduced metadata updates when files aren't being watched. + +The Ctime Floor Value +===================== +It's not sufficient to simply use fine or coarse-grained timestamps based on +whether the mtime or ctime has been queried. A file could get a fine grained +timestamp, and then a second file modified later could get a coarse-grained one +that appears earlier than the first, which would break the kernel's timestamp +ordering guarantees. + +To mitigate this problem, maintain a global floor value that ensures that +this can't happen. The two files in the above example may appear to have been +modified at the same time in such a case, but they will never show the reverse +order. To avoid problems with realtime clock jumps, the floor is managed as a +monotonic ktime_t, and the values are converted to realtime clock values as +needed. + +Implementation Notes +==================== +Multigrain timestamps are intended for use by local filesystems that get +ctime values from the local clock. This is in contrast to network filesystems +and the like that just mirror timestamp values from a server. + +For most filesystems, it's sufficient to just set the FS_MGTIME flag in the +fstype->fs_flags in order to opt-in, providing the ctime is only ever set via +inode_set_ctime_current(). If the filesystem has a ->getattr routine that +doesn't call generic_fillattr, then it should call fill_mg_cmtime() to +fill those values. For setattr, it should use setattr_copy() to update the +timestamps, or otherwise mimic its behavior. From patchwork Wed Oct 2 21:27:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820401 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 34CB5CF8542 for ; Wed, 2 Oct 2024 21:28:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E71EB6B0474; Wed, 2 Oct 2024 17:27:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCF346B0478; Wed, 2 Oct 2024 17:27:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C26046B0477; Wed, 2 Oct 2024 17:27:59 -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 93C436B0474 for ; Wed, 2 Oct 2024 17:27:59 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3C2E31C6CD9 for ; Wed, 2 Oct 2024 21:27:59 +0000 (UTC) X-FDA: 82629949878.02.864B05A Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf24.hostedemail.com (Postfix) with ESMTP id 729C518000A for ; Wed, 2 Oct 2024 21:27:57 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uXWl4i2t; spf=pass (imf24.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904348; 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=bcSIvLQqq3cBjG0xacxKgM+4NgKUngeWHZItOh0ii1I=; b=FEQhpWr6PxPDyp7IxEG1sBWKaxd4GCFcLME7ahHzoTM/RBG45r0unFsRxcLWdvrC0p3XC/ qP/9K6mTOj7ATUNL9fzM308GM9XWGM1Pl0TfjWnGAct2k/deRLOeXmc/Cil6SsCOuK16/N aYirJIMhFt5pmHiwvRRuoliT9/YNvwc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904348; a=rsa-sha256; cv=none; b=uJ29YFyBkGPK0fyPuhV5Oo2njLKyUfcEHK7Aet6HttCE4Wrd92odzPcYH6M0+JqdjniSFE 2w/Q079X6fX3IlxByJs1jIB8RLrKSR8PeEgEKdm/mypsgZXRH6lyLbf6grqGuvjCQS3zVZ hEOrY36xdHIUbZJp6v90ESCuRBWSsB0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uXWl4i2t; spf=pass (imf24.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 447C9A4401A; Wed, 2 Oct 2024 21:27:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 914A9C4CEE1; Wed, 2 Oct 2024 21:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904476; bh=9HLO3XpJ6HpHWAPYsUm3tCO/nrjDoz9ag2++QNPQia4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uXWl4i2tOgGIMLmuU2mUUroSOWL29/JUAjRh0jzUJWdMog/Qki/kBoa/LFSdc2CUU pbqa6d6QQFcznz/kcCHUnfBl+25eDBB/bQYt/vvfh8OZEglDW3g8h5YdVUtCjUJk7b UfrPAvDtVdFWByOtLKzs+YcAcV75KOpKC8mHwHCuEW4JgLL7C+I/NtrpeJleBPEiz5 tR6gVzMvmjn5B2Iz5vobADmFD3VOCf+5OLU0HnF8a2ppRPEpGzBJqgqgBs1vpr/i/h xH5/4CE0eT8F0g38OYLaDbrwU3mpOZ+7mD6rmrfrTEeZSTGIi2IjWjnuNmmcOsesiL oPkUk4nFRh92A== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:24 -0400 Subject: [PATCH v10 09/12] xfs: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-9-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3180; i=jlayton@kernel.org; h=from:subject:message-id; bh=9HLO3XpJ6HpHWAPYsUm3tCO/nrjDoz9ag2++QNPQia4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/brAZIqVIJKeyaxoHylxGxKgRPgUJZI1VhJRj ZnV5Y921g6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26wAAKCRAADmhBGVaC FUffEACv5L7rnY+EMR497bJG5/8S/s1wJUfmdxaoCDG+LnQbH78d++nzXjCVGoIfX/y7IJQDIfn gM0wlLMYm/efC/7UmR9O/T9jiLQgBrRtaYaPLRcn3puzRSl5C8bOeZ0l3/jOe+501U/1OnL556c FyiMZQsOWor4MSyzHHPbU1rY7gk549eNccvj+67f3WpNM6Zn9CHM7dUv3QxvweREeQo3FRm0+jN CV6uf/GSmzRs8LBhKUpsiqMSBi1unsyQTPnOZBDWdo79OU8tsyUq0vWEOxYGMunxNJNyX/lfjNC hXAZAgp1zWvKl/M1z2GlAIq6y2iez2Vi7H6zrizbo8maTFOf/4wb+de4PNAPQoYK/BjVGiPcSpz uRhGofidblAaoZQ8LjepNkc6jtOKrOMd4qzluTWZ3TFu6JMP2hbkupUV/0i4NiRpOzHFUPxIHcT tM+QAnh8ULcL9xo1NVhsl0FZ/l9s55MnO3A/QoR/FMr3JiT/d6j2t3Adtn4FVTk8VxZjJMldfdw IWbxlJEjfMlYoSmyYGh514J3VI0jNyFV1sAi5fJaZBzZRDVToqGzcd6wQa7KavYEMC2FjZwhfuB TNkWp8Rnabq2rXR4Wq7krJUS3NYKYM1WY6gRph1rGxF1TfhvTaOucrIB1uPPyWY9Y3fdv6EPg0N rjHopf6H5bbG1NQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: jjbpbzq4x6hmse4d1fdyitrbg9h3qasi X-Rspamd-Queue-Id: 729C518000A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727904477-426923 X-HE-Meta: U2FsdGVkX187eclVbMGe2rWEjJgcjaIk+FSyxXLzHjXGcFrb64pq9aBeFXzJgLhCOm4P6UpmOcRETDXEh0x4a4mr9ONykoCLGmgs8DNSvlMTdR7qamNCenUEjB44gFNdC9Y7mfIQ29XLIo0OP2LdomBmXBE5YqIjcNO6FkVa7Us3Dje6OzcvEacxlvzI2RsqJq9zpIf41p2MwtkqMCjJ7F+dQlwKeuaZD28XDg3hT14QG5FZdlNoxcG67reSo+BCu72mO6oDZqC3+Dr3HLRoG074vQkbuBSMc9JcxREZMwQ+eAFUWjFJdHw4JfMN/OuOgoizAQWG21LyJwBSZI8pXCBpbllXEocnrM3xBIYLl6Z1lvL/qObMkrkF6Q5Jh/PE5qnD4S2Kh4URA6i72nzvRxVjXAw7Bch2XzCeK2AK1ZGajeoI+9oh/36PDSCr5wj2EevekC5h//4Nk9Fu/93A0Mbf1cjxlsWCsGALtH/RIlv1nbBeRdVUJblEQJCBmd645giBWL5y3YKuyxkwohPtMruUH1wOSP+6XJlaKt71mNv+RRUhXDFcrf5s1olRiUajhJj4TbOSzVxlCp7DfoWKL8iW2CQqYq7gF8BwLuvp83h2NMTP1QSs4UVuwWc49IZH+o2Oqsw3x0ImX+EAQb+Xn+j6OZPOKoIl0t8Ltrvt2ZbQBKxDnbCse1W3NIP847OmgqcHBJB2BO4jyEQIw58x1W9XaIeG0R5pVnUx1V5mvwkEffKlABLAbPIauReJ5l0QneQItiFfLD5qynACRgQOUcLwmE0sdzrQFUFI/Rg6lr6O7pg4FHrBB4Lu9EzgTLRLW+X6p412y4KzvCoA5NNHzJ7iP/i6BEFsU2XgcT+AqQ36jpxdr1aWxMJD61hx0eRxN44xA6z/82ZxkK9qcjvAEZvaVFcTeGpgyFDzEc9wHYTvPm5mqH9neITaUUMeKCXrvmGrUPXJI2tM3ze7t/c I+zXIFEa eZVRuvEEr6xpKex4dqRIKCpUxQypYEUbFkkkvV0G0CoSHfASX1mrIH0MSSjZ2gzFK82MLacRhcztBjFixnwmd5Ce/dDPfGm2tjJQK1Wu0xLvlYXhzOUkKsw8HRGlmK80IXUcCcX3rlU2x+8nNzhFVkMWRCduUequwo8tGMSiD/7BD0V472agyesgEGNfNSOjr1O7pLV4Oole06WxolU+7MHLwkLJewpuAu7qFI1+z17fQWfbbduSUZjJ0Fk/CuMHRecoJNX0QHML0WF2u2j8tM3slCMUy+KCtnMVOm8aE+nOEHvKrGA1y3ot5g4rHldcKtpJgvtCQLncgFu8MFGwYlGoXLRMXi497AOH3TFrkvTs14njbvLzcKUvxgs1KSXANrOzd8GVAhKHExXMLk6CDavxyw4LdzSI0pwyyGewJcfR/LD+JsZSvoDKX5tMp25iVWNblVt/VJ742VG7YL9XJf/ClcfD6RlOBNMVb 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: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Also, anytime the mtime changes, the ctime must also change, and those are now the only two options for xfs_trans_ichgtime. Have that function unconditionally bump the ctime, and ASSERT that XFS_ICHGTIME_CHG is always set. Finally, stop setting STATX_CHANGE_COOKIE in getattr, since the ctime should give us better semantics now. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/xfs/libxfs/xfs_trans_inode.c | 6 +++--- fs/xfs/xfs_iops.c | 10 +++------- fs/xfs/xfs_super.c | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c index 3c40f37e82c73cf871bb252553331b60c6b1973b..c962ad64b0c10058c1e2eecf664fbc67ec7302f2 100644 --- a/fs/xfs/libxfs/xfs_trans_inode.c +++ b/fs/xfs/libxfs/xfs_trans_inode.c @@ -62,12 +62,12 @@ xfs_trans_ichgtime( ASSERT(tp); xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); - tv = current_time(inode); + /* If the mtime changes, then ctime must also change */ + ASSERT(flags & XFS_ICHGTIME_CHG); + tv = inode_set_ctime_current(inode); if (flags & XFS_ICHGTIME_MOD) inode_set_mtime_to_ts(inode, tv); - if (flags & XFS_ICHGTIME_CHG) - inode_set_ctime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_ACCESS) inode_set_atime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_CREATE) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 1cdc8034f54d93f4a40ab3e3e4f91c6c9dfed7ec..a1c4a350a6dbfd19028ccecdfdb271879f769ccb 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -597,8 +597,9 @@ xfs_vn_getattr( stat->gid = vfsgid_into_kgid(vfsgid); stat->ino = ip->i_ino; stat->atime = inode_get_atime(inode); - stat->mtime = inode_get_mtime(inode); - stat->ctime = inode_get_ctime(inode); + + fill_mg_cmtime(stat, request_mask, inode); + stat->blocks = XFS_FSB_TO_BB(mp, ip->i_nblocks + ip->i_delayed_blks); if (xfs_has_v3inodes(mp)) { @@ -608,11 +609,6 @@ xfs_vn_getattr( } } - if ((request_mask & STATX_CHANGE_COOKIE) && IS_I_VERSION(inode)) { - stat->change_cookie = inode_query_iversion(inode); - stat->result_mask |= STATX_CHANGE_COOKIE; - } - /* * Note: If you add another clause to set an attribute flag, please * update attributes_mask below. diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 27e9f749c4c7fc75c3385aba2e02ac9fc5d1719d..210481b03fdb48fd50e9a7a109d8bcee0e7e3a29 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -2052,7 +2052,7 @@ static struct file_system_type xfs_fs_type = { .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, .kill_sb = xfs_kill_sb, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, }; MODULE_ALIAS_FS("xfs"); From patchwork Wed Oct 2 21:27:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820402 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 4C9B3CF8542 for ; Wed, 2 Oct 2024 21:28:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FD076B04A7; Wed, 2 Oct 2024 17:28:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AB316B04AB; Wed, 2 Oct 2024 17:28:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 100736B04A7; Wed, 2 Oct 2024 17:28:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CDFAF6B049D for ; Wed, 2 Oct 2024 17:28:01 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6EAB012111E for ; Wed, 2 Oct 2024 21:28:01 +0000 (UTC) X-FDA: 82629949962.28.27A2164 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf29.hostedemail.com (Postfix) with ESMTP id B6FE5120013 for ; Wed, 2 Oct 2024 21:27:59 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IRUjz9Pt; spf=pass (imf29.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727904351; 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=jBNvdZZYadLkt1VlVlicSy1e4kmSffesdNke6Y9OBvc=; b=yH0OiwlW/t6lWFTQxsDu//YFybiMgTSOCp4PAq7NcXsgbo9bCD3b/8LwKyaBQG871ao8dC gLfkjowSdVodetS7EjnBbrPBWfPKm5/hhHpDeM7PIEV1FCjvLQgy0bSIDAl5srpPzv8Cf2 sLQ3fcFQawuYjUaqRJBZ8PGZVGo5Axs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904351; a=rsa-sha256; cv=none; b=n7/7b8zs3wI/7tPZ8FXUzXIgUc20wkHaTfH9FsXM09kyFAX2e1Prvl0PIOoeolaaMvqhOA fSkQadDcWPvONuwrVg7Bfxxs/HKfFI8qNERirNnSLp7ueLaG+q7YYMp3jW4sCpET576eOb qwMeaAmITirkZzPSeFuuSm8bMCUz/uo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IRUjz9Pt; spf=pass (imf29.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id A7887A4401F; Wed, 2 Oct 2024 21:27:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53ECAC4CED8; Wed, 2 Oct 2024 21:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904478; bh=L8jPTqE/MEdr2Fk0QAaUZrk7fJPp2DBX4nFI13DAUpM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IRUjz9PtfkWUJi0e9T3IPCCoMESom7iKKJ3CLgq48OxKmXWJ5/EJvSKXnIrqyYPEy cXYB9JoxiwOFWnbShCRYw+L9iXqXp5S4zliQGT+jN/yU8thuWASv7U7Bjhvz9EGmmY HZlWksb1N48laxkgzaACcRF3LuZjruytZTUmrSpfwJaq8yY3L45la4hbhUzL5Ah6uF VaXG+vGAJSrI/YGDgGYKh08C3Vw0bA212OWgDbBCgSBD5cH8kPXgryCalNn7Si1cCg Dnf3IyUzLmz1xed8h41cSfmi79GmS28hKsMSkI0kkEbKETd5KxDP/1sMOPF8c1QCAs uVAvAUbwCSgcA== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:25 -0400 Subject: [PATCH v10 10/12] ext4: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-10-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1052; i=jlayton@kernel.org; h=from:subject:message-id; bh=L8jPTqE/MEdr2Fk0QAaUZrk7fJPp2DBX4nFI13DAUpM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/brAty56j/NgjClfQP+YgB3escq8CktdBFW2L wyBzPE0QpeJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26wAAKCRAADmhBGVaC Fa0aEADUq4geawXWbT0XKiWVNDe5HmCEhbMP2s1/8FXe/A/d6dLhUu7Fit4zb0KvCeOllM/wApx olJNRraOJVZhluYwJX2+A/BfzNrIuGKFiuZKLpkGaKHDg7fimaX1ks2NC8uUO6v/H+MdnvezKx9 gJgvYbPPFJamQt4dC4+RerijvvEQXqyH0HLG49AFR1wty4o8scKEOh9I/tamgS2nUAy46SrtrR6 B+1XmVEtAcemRl3vx8XR2uOGwnGXjQkvw5q2EZryLqOJWHkdmoKckir5tPLfypMc4K8dGev2LcJ gZEhdTe0QOMpFsJ3YrYPySffq9mPRIgNCePbgr4c8Devtb7WMalBfhydHOfRxIzRjC8zz87RNPZ 7bSv0sZtCIwqdawRdMm6GN7iWgCjikImQMy+DBPfaqKkI730o5c+bLd4PZbDWKhm8gDD8hno5Qc WKqliyfZXKshMun31q93qXnviYb3u0Wy6bTHh+yqG/cWD8pi29uSoIx3TJVx0uNeRC+NcgXDse4 z585K1g2IEydh2r+rO5LBZp1Oi4Efe6rOoVVfceCo+FeYE9wY7u3wO/EaORyxVol55Lkxf/Unqr eUknq/qzqTcdoUs+QmZyJeUQIWD/OmqQPzyVVWdMM23OQPgLi9nk1BQB6QzYVf18et5QtWHndAQ LsWTMxYdS9V5lYA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B6FE5120013 X-Stat-Signature: cpk6wp9e5kkqcaz4egxtw1erfqs3umd6 X-HE-Tag: 1727904479-258798 X-HE-Meta: U2FsdGVkX1/W/1QTbMhHflSyg5zhvtznolP0kzNwttkBEuV0MlAkN8gncUodrVmPrXh2wi8EvRFEgL7YBjCdC4unmgTpEBq6BlA6l4ezdtrRi6WpErTPhTcLyGovFGdMSiplS6TU1XHvuXqIlGtpOry3d5WbPG+GtFS+s9zhE9aLzBSC6fA4R7eP8BcAfnfnYGZK53XNkE89pVv+VYXsOA0P9HnHxveN1FUjcKWBkuwPJb16YPSJELB5+Fdu2TzJKrjkAYC/RqomiNK4KeL2wr35/piqtJVfSw+NHrwFBvdcjf3pphSHCwGhfPXcrN8HM6aDd8VzL9ur6wa72uHwyEySYBltiIP4VhpTO0BfjVQDGyJ7uelIJuVOWBivkEoyUdW+Qkm+OQl7MLXQFCbZvu9gwslUzf6KuTSF16FCPoLtYG/liOSptDGEUimb9X714kWmQLu8S8L/t+hZVsJc9qn21sh7S9dwFxo/cuuIdmBaOB8t+5Ekzqq/cEUlKpL6Knqf6X+FvPCkCA80nh2XcOI3yyeEV8FlDLCMQXSkqw/zXcEC+Mvp1yEErF4uI6i/GteKUJHDllFv1Gx0MQSEZqtuSQQ48rdvXM4efoFebOo6Mdw4e3L1GPB2unQiXnZ8ToVp1XsRcY7ihLSp2JzEFHdTrIS2RmP4ZjhesiHIny9kfP3ep2Nyo/c4V9jFaUokHeUEDx32goUB3dtjCZ9gg6ZF/DrcdwE87qNFQQ/CXGEhotpuhbtIs0A/9WiyroNsjv+XpF1xeoVZMtLHqXNpa+OpwWTkiOIo3oGByTvprhcWP95gC/usEvfsYSaUPLb6blFqAyPH+xFkZUJH8v6X+ehXD7274PVsUbGw1DL21f3E3OH9gVbOSIc/YkMYQt7A+siNph7KZWskk9aSqV/8d+bO+gCphKiWeXDIwM1ovP3DFcOU7ybvxA5O1Zwxtx4TOa0UZGzKARYP7nercnA 8EZTL1ab eTsQR6z008p2J5HuP02AHF+FDT/WakYqAwnd9ZOrcVSB/lPLpxxb7dY80pywhaA+6JDyBabVFEcCcdLA5q2IGvWRoPRmdeFMNlWDZlYq7P7Wb61xAy2QjdJXeDOhP/eyJGne2dvOOtBIJsXyxmE/pF53IYkFCH4mn5puGVOsOtEFqiGCSjY/YAmzw1IRxihYWSjNY7Bch3z+7SYpfuh5QN4HnZHiPS/jagFft9+ZyN/kLzT0tOQ5w28mmuRWj1zNMXEZuHpsbWBFMoXGTuMQzXZDyQhkh4G4na/ccvd5EKr7QCcuHH3PM4BIJAlzhK2KSSDBKUOjkkcYjxsn/Wu+5oiy+8rpMh4H06NUJ3UVtjjgrWYRTsaxedQ3C3WSKVRhPSgNCaXjArRvEFAwNdbifoMeYo6Od46qJjQ81kxYGHprge+PWs5p1qD2uDYwA+Dzi+LWS1sbh6oyzBH4N9KZrqMMPWgMm7PtCqcTC 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: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. For ext4, we only need to enable the FS_MGTIME flag. Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index e72145c4ae5a071cf4a809d0519a01a8fb84dc2d..a125d9435b8a1c8f7a96a2a0bdd9ce1b4671f8a2 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7298,7 +7298,7 @@ static struct file_system_type ext4_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = ext4_kill_sb, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, }; MODULE_ALIAS_FS("ext4"); From patchwork Wed Oct 2 21:27:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820403 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 156EBCF8540 for ; Wed, 2 Oct 2024 21:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25EDA4401C7; Wed, 2 Oct 2024 17:28:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 210A44401B5; Wed, 2 Oct 2024 17:28:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08A344401C7; Wed, 2 Oct 2024 17:28:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C76844401B5 for ; Wed, 2 Oct 2024 17:28:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 73752A1006 for ; Wed, 2 Oct 2024 21:28:04 +0000 (UTC) X-FDA: 82629950088.10.54879E0 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf23.hostedemail.com (Postfix) with ESMTP id B47E6140006 for ; Wed, 2 Oct 2024 21:28:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gfzEwwKw; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904388; a=rsa-sha256; cv=none; b=x1lkbmbQapHM9j1A2bvm6U/a2wLtCKbUEiFtz6M5q9YkSFLssNw06b8TSw1E0lZW8Vaizn pGY72H3i3ABxnpl4J5bf1ne/RyIrYwObCjaEHQO3WhFviEo2UuQu1sQhNt/JaAoBvbPq3u Y++HymiriXahKNF8hCLWBMsG7Hrp67A= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gfzEwwKw; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904388; 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=3VdP1jEPz3XQWef88WbMXHkpJ4zyAYNTmJDAVLJRdxk=; b=H0OjdohdnMrUw+LfdjFUsKQ8VVzI76r6DIQO2B8X/TJ7dWu7awNg9c6pDV9iz8jynKe6ix 7M5/RvX3bBqbYyIEkhTH5wDbSl4FL3H5sn8aEiQ+6YE+k7TYOwpRXjYyLOZMlNRrMuCvgB qzpxcBibycZsnJdLksXSHJFG1Bq3RWA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6CCEEA44020; Wed, 2 Oct 2024 21:27:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 166D1C4CEDE; Wed, 2 Oct 2024 21:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904481; bh=zObmtftqo+OaaHLBavfM0NkNtNo0uG0b222Sa7Qmh1I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gfzEwwKwlXuv/icWZdNJWvW+FUy1Vf/0lRfHCezZJdLWd0bObWLG0v+pUO5SPBiLc sdSKXhrmmr7gR7EG/kMlBwBOIXDFpEUY1Q5UnAq0VpOtOMYAK/HuPc2D4OPjxAG28z wX/lhPGtRunaig0jh6Zkqwu0w7i0F86Tdp4KkfnTk2SejE6O+R93qb58TgPsiqWeYO 4cRuZunzYUopQWD7qcAnyzodtqqFqRj3H1Lr00OGp4ASB/P7SjZpWKYcoFHEDC3k+9 DSkuNUfOrYYmTrchTlnoIigRhbdJizzR0WJ2zW6WwSQ7jNNLL1jDQ9z50Wyi2OvURn fBlphFgrhKdLg== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:26 -0400 Subject: [PATCH v10 11/12] btrfs: convert to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-11-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2842; i=jlayton@kernel.org; h=from:subject:message-id; bh=zObmtftqo+OaaHLBavfM0NkNtNo0uG0b222Sa7Qmh1I=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/brAIkH4ZhSMoZFwZdDHij4mmUSui26ZshlEx x57+iG3EBGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26wAAKCRAADmhBGVaC FZD6D/9Sk5MXNcAbxZylsBMFOovUPgZGtFA1V7FLElPi8cEY7bFvXXBEGek1fgh/mw0fw+rRbXb oQFZRU2UfV6ph1kYWVPicQNpEenaSUhXiOXeXIwuelUAe+90WG0JpGTnnTafXP8n+UcVYlkKDiK /mMe1hk0JgbyzqOg5Y9B6BymtY2UqRP9IWF7jCUswdY5ZaiIitOJ/Zj/OTbBECAf7iWWahXA3Fz ruvOwvTybJlrz6JA4fJH1SeI+6rRl/7R/0/SsmczCVpNWOwDJYqckWGX3iI9zjxRoaxctha6TQ+ xAp3b9jijuSBtQ6buORLmDHGJw9REll+c4DNtfZFRHriVBEvcsunWRnHasihG90eKOjU14SL9MC 1ZvySYOHnxGz8tns2wmWZWeRihy1XziiKNCmiRBHl7fyT8EAyQRBuFrLeSMukQtA9aALZqhe1lc zncx27VXeFwy6QXLRi9wyrhs9eKl9nDEw6c4P+31Qh9y6+S9EuVcWcrYTkTeFbkzDAlARXsRyrY PEVG5lg2NNHpKq6HoZ7OStLMuQUkfKvb4MjwAoZXtq+pp6pFT9u8CuPukYWWfM3eYLrp1L5gVLI IZgF/zLShS/XqVzCis+igDAtyWwVPGSgO3wwlQNWQozooZ2dLNaDCj9PeNhDU1CwuRYofGX5t57 qWW84x0PuUmo0Ng== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: B47E6140006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uyqxqodwc6aqcbp6sdag1g6b9engwpgo X-HE-Tag: 1727904482-219060 X-HE-Meta: U2FsdGVkX1+gO6XrVelnIE8o4dVeHv305ImBrXW40fS9ivX04CaLOa4HUGb1JNs28u4pPHIrzcNKvjbFeTMTBRuaTY8KRI3uchwtZFo7yvzMezjbUEAiXvRDhCdF2MwG+714nIH9DTsFNAHZGFM1WABnyJIwg38qY12r75ivDb5BGcgmTuWnBrPeSz1SV9jGuuFTOWsldXtlRvO7Kw6wHOJArtaexRP0s4hB8nZYT505oPf7TVyClrXg6HNNRH6QnngKfsA7Dgd+C5RAeGTwr5jEa6Mdx7Uap/Qu19/OXpKkJgDjFVe9bbsz/Z/U/bNLwI4Tu9C8TTDME8ZOC/5CokFr3k6Hul6zWKmSQyEHN2ER6P8keVJIxAsI9K+vx1kj7pp9Ygy3lQQwVN/1P6m82zEA8JWS1IXlIgaA1JtCnHa0CQXYxwMPFCwHpbfE/9Q2/nMHLkII8rMLVbe/EqOaAZUlfwrBYb4iFrukaialZJk/EeY1qdp4hgT6N1WSablfSN4yiCRugiR898Bs+H3nroUnugIo8yrWQPLiKUTAOoePERyBGOBbDpVVzTSEclkY9D1gwiVDzaNSF82M4veIU4h3v+y/PeYJilT85vCaehDrKeg8Unt7MF0Hsbnhe7bAQ89voJqIXpbn90exfo/bhQZ12GKOzqYuf/irmn+n4PX6McG7q9JR4+zoNtY8qRWLkjT1ce+aDSEHd7RT2sGRUb3vqfjpnVEsfeq4oY2ItPaApqLOvIhLMoKvwz8T9pdg2HGQKQaFkS7RqO1jCSZxFtIdjkgIM5NWqAx6T1VyRjVQosA9kiPHYg6TaZekyj3yhSDvSZr/oZ3l020Y4bMaHeSrIRYc9CdQmaWbEms0zvTUjDgiZVw7MPkbgY3Mfs3E6zxipNgz+MynOP80ZEFgNd6EboGnNUESl1KgrL1zMm/pQyf+RevVArURoKcIkpYFYMPnNNkzPC3hGTKegaU 12tVV0Ow cgDpqqgHlqTo1HpFaGAnFA5ORlIhIsDDP3V2kyi7Zd/XPVqFUrqoEdNit4AIBnf768Z8AsEoO57iULwS7P+meO6EZPsqFq4IoulaucZSonMW4Ycg8D494Npnx6TUH4HYBdv9uaWiPTk/oBrVwbBkGTuHf4hJHXgh15VgFkoPgF5YLhSXZDz/bR5lqNvKrOCOkf46sjAqu3o0WKAX79haBDXZEHBD2kyNwCnQmPdxbpYEuWGp1ktQRqaDVqm3dVcm/1WCyWF2ORoQSaRKNuVcNaHxrFIhYUSPbuhsCoSDFQMGi25RMEG2GLkHnXyh1BPgNMY1fRZXuwjx9inMW1S/cfXDQCOftyJzPiCEpm2/KIImlrrt2rzxSdo+VqHxVyKldUVDGhGsG4nsPackwx3sIulD0+XYVOAfqvi0kMoomqte+QQmRrpnmUi5+yLJxDauC4Z76uFYDyMwNf8E/6ncZkAFfu17iQ8TNSqh3 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: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Beyond enabling the FS_MGTIME flag, this patch eliminates update_time_for_write, which goes to great pains to avoid in-memory stores. Just have it overwrite the timestamps unconditionally. Note that this also drops the IS_I_VERSION check and unconditionally bumps the change attribute, since SB_I_VERSION is always set on btrfs. Reviewed-by: Josef Bacik Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/btrfs/file.c | 25 ++++--------------------- fs/btrfs/super.c | 3 ++- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 2aeb8116549ca970432042a315f29d9e7fa00980..1656ad7498b8161ec94a2752b0ab7cb723fada1c 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1120,26 +1120,6 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode) btrfs_drew_write_unlock(&inode->root->snapshot_lock); } -static void update_time_for_write(struct inode *inode) -{ - struct timespec64 now, ts; - - if (IS_NOCMTIME(inode)) - return; - - now = current_time(inode); - ts = inode_get_mtime(inode); - if (!timespec64_equal(&ts, &now)) - inode_set_mtime_to_ts(inode, now); - - ts = inode_get_ctime(inode); - if (!timespec64_equal(&ts, &now)) - inode_set_ctime_to_ts(inode, now); - - if (IS_I_VERSION(inode)) - inode_inc_iversion(inode); -} - int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count) { struct file *file = iocb->ki_filp; @@ -1170,7 +1150,10 @@ int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count) * need to start yet another transaction to update the inode as we will * update the inode when we finish writing whatever data we write. */ - update_time_for_write(inode); + if (!IS_NOCMTIME(inode)) { + inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); + inode_inc_iversion(inode); + } start_pos = round_down(pos, fs_info->sectorsize); oldsize = i_size_read(inode); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 98fa0f382480a2a51420d586b1e2a2fa6c58d025..d423acfe11d0d1702ff1e17a87d11d65d3ce8cdb 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2198,7 +2198,8 @@ static struct file_system_type btrfs_fs_type = { .init_fs_context = btrfs_init_fs_context, .parameters = btrfs_fs_parameters, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | + FS_ALLOW_IDMAP | FS_MGTIME, }; MODULE_ALIAS_FS("btrfs"); From patchwork Wed Oct 2 21:27:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820404 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 301E2CF8542 for ; Wed, 2 Oct 2024 21:28:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B60774401C8; Wed, 2 Oct 2024 17:28:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B102D4401B5; Wed, 2 Oct 2024 17:28:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 964064401C8; Wed, 2 Oct 2024 17:28:07 -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 6CF3D4401B5 for ; Wed, 2 Oct 2024 17:28:07 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 213FD40FDD for ; Wed, 2 Oct 2024 21:28:07 +0000 (UTC) X-FDA: 82629950214.17.45E7D84 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id 6B88A1C000F for ; Wed, 2 Oct 2024 21:28:05 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pY4qgNaa; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727904343; 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=fu9G5NvuHS3hhZm4MXbt7oUm1nVcACPEV24WzWrbqHY=; b=4a9GtDJy6bVo6Sr0C/agk+b+VHYVFEPk7pGjU6dD52TxaEUP2xkZUcxo9pSZj8TzHAQW8m TgE6OrFIhhKr7RN2xYZ2mT4KSnINg3IqC6SF7lwC+qKj8BQUjpbIkmgxX4UgsEa/vfT/ts UxuOq6TIWXgLp1UlbyRoTcwMJ2kzYMg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727904343; a=rsa-sha256; cv=none; b=48AApWeB+D6hmYCETaxeljlsvENLBiDqyhqIoR+7LpaKG7toDfw5/1Cr6q1Xad0cGeJdBE X2Fxho2UC9U3JD1nZ1rCuD44YlbN9lyDHrI7VlEltJCuYmwmTyhmGT86pmRlJK2PxLuLuD V2mgQ9wSOa2oMXKNklF53ndr1bmj73g= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pY4qgNaa; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 3E5D5A43F8E; Wed, 2 Oct 2024 21:27:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF362C4CEE1; Wed, 2 Oct 2024 21:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727904484; bh=5/dsLO8cNmOaM6p0rv+Qvzx/xMvPBJnx6tvOBbPfMzs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pY4qgNaaCqezS32qjDZEbsRs2uGb8OTkbND/gQNC3DZDk0GQyrjGRmxHYO6BtyTWX EQfJp0qmbpEp8Y4fEBEdJjYyDC1X6D/lcrtX9zhRMFR6vrtcr9gEpaw9lqhsBV4dzt hc/hRRGOV1mrRGkkpHthnO5R0XB4+yg2XN5Y8PwXRYhYvmUUyN5X088MqLAETzHPqn O26reMyyJqwCWRtn9LB+2DwWyURABcR1Pa7VdYMKNk9ArrOhg9DFEh4PfCmVFPe9Be NqUMbmrsKxgNgWyLK1sCeoxlIVRcC4VfPN2PcY5JZrL6kxFEm9kVwZtbsg1V1uskh8 uQiYUVOkUhxhA== From: Jeff Layton Date: Wed, 02 Oct 2024 17:27:27 -0400 Subject: [PATCH v10 12/12] tmpfs: add support for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v10-12-d1c4717f5284@kernel.org> References: <20241002-mgtime-v10-0-d1c4717f5284@kernel.org> In-Reply-To: <20241002-mgtime-v10-0-d1c4717f5284@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.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=988; i=jlayton@kernel.org; h=from:subject:message-id; bh=5/dsLO8cNmOaM6p0rv+Qvzx/xMvPBJnx6tvOBbPfMzs=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/brALjfB22SLtWrZvbq9dOIudVwmi0I1qA+aV n4HN6LIytCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv26wAAKCRAADmhBGVaC FRSFEACPohqXeTh7KgceuIiMgaiZvFEfTN6SD/E380ADOa3A/9s4jdNxUzvvIUF5TGO3RjuqvXp vQ39lbU+sN/EReWdsZdlcuP9wIJTEDPEo0Sd1UVdKEqRfvB7MXkHnFyhigbts8E4EeZm3vtO5Um dEueBuYGU/uHUQ+C6uWNdEqboX38koaVM6De2O+XxmDB25xapHTAlc+OjmcQvs6DpWxF5RNdpJg 84pcISszclA73/fk3T5S6O5wVNqceFy6Rj/wOaY0mSjy0XDKDJKGBWz7VJtKWZKTPmcLIh46ehW D3rEEFjv/THx5b+VU8ecQynhSjyfgPRiRgZ/ZFcxmYMlGzxi639VSAmecRyY4j1lwNLBwcaxP3U qfns+SkW0ZRePXxgunj1ox6ARPkr5OFR5Pa7/h0JkK0hjguHgiSpu5K82GofgSxXHpUFOv0Dkyj Ee32pebJG1fZRa4wWzJRSNqUvn+2uXCZvk35HWRS2uPOeNohiJVtbaJ34ZRn78lHec+pf5Z7ZJ5 GKT64vZ0wq2zEDEprVAk5g9Pid6BM0mn2dixzCz1QwYLKWJdWrcK7YfU6uGpmvh/UiXzYOPesTz zpKM7FScCuy994O5F+7EBot7sYRW87SFI2Nu0MwRE5tPQdBY/CHLfBwZP8GTD2ThHGIm8ZnGudD XIxJwAEylXRaCkQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6B88A1C000F X-Stat-Signature: 33cwh5ewq7p86wqnr8zgbiratkgigqrk X-Rspam-User: X-HE-Tag: 1727904485-555479 X-HE-Meta: U2FsdGVkX18lNvU5hd2NZ/SucN+V5a3IUo3RirquooqOfPSDfqQIn7DOjipNKGBVL9hMMKbmTASdgBYP8eICn86q3WR47iaVaO8XLDkCYA8uTS1aT3IUYKbKB/I0F75XpTyATAGR0wMH/0LTnJv9sNEr5OuCtKoh0g5s1/BnlzsJRtliu0sBAw5ZYXpP8yhiJNvFj+UcZ+N/XyE84zWy6sfdmY/edeVIGVFuEJd4FRBEA497E+Z01RRfOXnx/v7o7h5TfQcsECZDyVvgCNgQRtaR0ivI2BxyIaC8H0Ol5hlHuD6znkiSnQEHU9vZII/iYXytyuZ6bArogsYHdfyc29Pz5Cycu6FZ84uEQORjt7q5/l9TBsaAG6hl6TeSshycVnnaYybNwEl3pYZ6ZShaWmLN5yTp3ukqUvwfyv3fnjKs1vbpy7jHJEb3GIAJIeWgZgA8UC0i0Z8qBrA5gsYV9uZ5nXtycGPwzZWoawvcKUalR/ZGF0TRRG3bAcOLPKGxBGYckWVRUlpvsuLtsbuCFlii7tQR0NXN+us5czpYIf0xsHgxzbLJb4rfiHADYZug+nDu+RGL1iggNZccfXLTtK8K1eUD8/sVBA5uxsphWfYLGYVo20chrk6jctY9lSfwE+WIy5tYF6hddvu+egYDzscF0PibUMjLo8/+GPpin3zImEh2YOiNNMAhIf4xfm4+lA0SRYLCwL/mfGwUW0w+gU5r4l2i9q9GvGE1YLuJUmXDT9V73cQFO2cub1HWEnJPKPsho/cqtl6xTl//XrlUGxmKRRDTs1VNbFNLoJCtc+bK/yRmMxeyShgj11CEHB0TRwwx2IMD0aoriUtsbQB1wIRLE3pP03cDQZE13mIMtALSLHrKimLi/x8k1QW9TX+LRyJodAfBdBVxL9+RTaxlwGWWwdlMucBcxmXiMoBRkWEQ+giJOh0gAG/PNjyCxFQQ50Wvnm4aLfSs3mTNlYP 9cZwB43l rdQdJ/0DaL8rV2D6xsi9jBHYAnqP6wmkxzQRon79sv0uz9Umt3s/08a+X5tP9if/JFdplf6/WJ/MdgxegEB0Cuirn+2A+dIBqMcCZIWsoImJXsc87lormJQXA/niUWTR2JceGeI4TvtIdgeZ6t5e2sHQazIO4R4M8LPhdgYSjpnHkLcqvetHJlilohNJRAQMBCCbAWCGFy7Nx5m8hzcs1BAErknwV5ITQ0gVVG83B+YTwsuW0l7gNn7xKrIi7OpeePqL9Q3IeucgtAJVggGngpMLO9VTdA4kNVggImfRc/iR+cViA9RvCyLSmY6Qsg54GjYScI9343ThoN4yP3KvbfJMr1q1YfChU5EHagroAG0uzNRTm5mWObHDo9ofTFN3dQq2JCHWkXzlk7ZuuFxOGNPprHeLft82tOG/p/ePUFTaNiyzGyPpT87YOf7SvuRLj6i68VlLFVAPJs9NIno4SRUIw6yqzUpwlyAeA 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: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. tmpfs only requires the FS_MGTIME flag. Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5a77acf6ac6a621dc7b5e7b46402b2b714b45bea..5f17eaaa32e2902228be7b245c5b3b11c5fb6a56 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4804,7 +4804,7 @@ static struct file_system_type shmem_fs_type = { .parameters = shmem_fs_parameters, #endif .kill_sb = kill_litter_super, - .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP, + .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, }; void __init shmem_init(void)