From patchwork Fri Jul 5 17:02:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725441 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC98216DEC5; Fri, 5 Jul 2024 17:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198980; cv=none; b=SGlUmRuUS1tZ4nT2aT3ByrCYZPsbkY1NPbRRulFnahcmLQE9WYWn1a9RNQbioaGeQvYrXeexNoUFJwONhEXi4IQxXM/sYVCVHxbBmb7yR80D9P1HRhqBLj9OUJMW1yEsSZn6h0CVp9u4HQtc38mip4z4qlB4Q9Df5zY1WtP/OUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198980; c=relaxed/simple; bh=6egteo/GAKvKi/kyQEvLqiRdJFtohhZhx4h73M92r7U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cf4Plr2MqjWhXuBjvXg16tYb533z2xwXwwRa8ri55tk77A/BtKw/RSLp/S3kBx25sP8hoPc+k1np8W3RXMyWIFJdTIDKht7OYWrtMCq1gG73vJr9HKu1SGof6Kv2hRpUu9kPvhfAdjkf3uuIBqrnHrd87oOYOqphdCJBAcRNzAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZCNI8cW6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZCNI8cW6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBD99C4AF0C; Fri, 5 Jul 2024 17:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198979; bh=6egteo/GAKvKi/kyQEvLqiRdJFtohhZhx4h73M92r7U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZCNI8cW6qnvGNabmiHihYQQymy0SzSENToOzOAzQFqrhJWotSRaj1YP8GS4yLkd7x jNzUFMQyRUvWcT99VD9d7vFi0zGEqLU+D2t8Mddbdu4zNS9KopTYXrNBI1u+69LnJG Ayp+Eb4FKw/23wIvVOB6QxudoX5gSvx2FBtAFr09OspIy2Vksl3+75H29GkoIOVn4k jl4L8GFpkOm2eslLk2arVPXSbhuZDlpdwVg09OPDjyr12dmyMeCamFeJ8rvRqBV6Uu m8BznoCWivwW556AL4+hRjtr7QGxpMWfMcNyNa9VMj4l9N6oZJZS829BXasUfTDpPx /xZ7h1SX0WbaA== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:35 -0400 Subject: [PATCH v3 1/9] fs: add infrastructure for multigrain timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-1-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=15182; i=jlayton@kernel.org; h=from:subject:message-id; bh=6egteo/GAKvKi/kyQEvLqiRdJFtohhZhx4h73M92r7U=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc8OGMHDWMfW0xIrqXUl9r0xjyvQao4dg7/t ZkrYHsV/V6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPAAKCRAADmhBGVaC FWq9EACgq287yR+5KLK1BaotXVx1cFJ/bRYSlUTCV5kwiACA9BLQIYILTGlIoBbRV+U0D/TNwwI Pp0IGwAeB02FZU6TY2Rc5bsbQxG4OTGA7L74wjzm8VKHVhRvCiQliaVfi2JhulmwpGKIDCH+L4k ehRCYn0lLCloZaWTQ7mX4RdjdKzzjr6Wq4BTCE6Xc2RDh0vuPwl0BoBJpZzw7BFa1vSXq5gWuS/ jftX4jmVhOwSSFx4Z6lLctxpLPeWDz9uf035TUv+yk8Rwlsue1szTLPgxpODUr3nOGJCyUKuQLW E0qWD+lGe1I3Jyk+kVn6MNGo9q68srIDhOIlgpXpwkfOY3ACK53qVBpamujbTZMdOzpHSSCdTY9 Yrr8ZBC4On/dEPt3NuDzPLOfiMAXeIOjFdxBOg8VrFrU62P5FG7oqXttvGxXQHMpeht2ehruEiV YBbwtrEHqHTn5+btkTXICFAIBUHxMSFtjZSneSvB/zcnultLLfBF/0sjkdwWh0QuekQqPC6ZjAy eZ2KPOpN8rc2mmYRWQZ7VtbKU5mI9y9sySUPvzd+4Q8OEQ8qf9qZwQIwJODgatjMYIaJb4hf5V7 aKp2FjHlXR/1RScSWZS5g2uq6l+yfYmmLBrx/eeGk5vvpBPEqfzuON02IPaRiv7gndwNxOSi+N0 ASb4odbWXjdqmdw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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 we were to always use fine-grained timestamps, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates. What we need 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, we allow the kernel to use a fine-grained timestamp iff it's necessary to make the ctime show a different value. This solves the problem of being able to distinguish the timestamp between updates, but introduces a new problem: it's now possible for a file being changed to get a fine-grained timestamp. A file that is altered just a bit later can then get a coarse-grained one that appears older than the earlier fine-grained time. This violates timestamp ordering guarantees. To remedy this, keep a global monotonic ktime_t value that acts as a timestamp floor. When we go to stamp a file, we first get the latter of the current floor value and the current coarse-grained time. If the inode ctime hasn't been queried then we just attempt to stamp it with that value. If it has been queried, then first see whether the current coarse time is later than the existing ctime. If it is, then we accept that value. If it isn't, then we get a fine-grained time and try to swap that into the global floor. Whether that succeeds or fails, we take the resulting floor time, convert it to realtime and try to swap that into the ctime. We take the result of the ctime swap whether it succeeds or fails, since either is just as valid. 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). Signed-off-by: Jeff Layton --- fs/inode.c | 172 ++++++++++++++++++++++++++++++++++++++++++++--------- fs/stat.c | 36 ++++++++++- include/linux/fs.h | 34 ++++++++--- 3 files changed, 205 insertions(+), 37 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index f356fe2ec2b6..844ff0750959 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -60,6 +60,12 @@ static unsigned int i_hash_shift __ro_after_init; static struct hlist_head *inode_hashtable __ro_after_init; static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); +/* + * This represents the latest time that we have handed out as a + * timestamp on the system. Tracked as a MONOTONIC value, and + * converted to the realtime clock on an as-needed basis. + */ +static __cacheline_aligned_in_smp ktime_t ctime_floor; /* * Empty aops. Can be used for the cases where the user does not * define any of the address_space operations. @@ -2127,19 +2133,72 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/** + * coarse_ctime - return the current coarse-grained time + * @floor: current ctime_floor value + * + * Get the coarse-grained time, and then determine whether to + * return it or the current floor value. Returns the later of the + * floor and coarse grained timestamps, converted to realtime + * clock value. + */ +static ktime_t coarse_ctime(ktime_t floor) +{ + ktime_t coarse = ktime_get_coarse(); + + /* If coarse time is already newer, return that */ + if (!ktime_after(floor, coarse)) + return ktime_mono_to_real(coarse); + return ktime_mono_to_real(floor); +} + +/** + * 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. + */ +struct timespec64 current_time(struct inode *inode) +{ + ktime_t floor = smp_load_acquire(&ctime_floor); + ktime_t now = coarse_ctime(floor); + struct timespec64 now_ts = ktime_to_timespec64(now); + u32 cns; + + 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_ts.tv_nsec == (cns & ~I_CTIME_QUERIED)) + ktime_get_real_ts64(&now_ts); + } +out: + return timestamp_truncate(now_ts, 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)) @@ -2507,6 +2566,14 @@ void inode_nohighmem(struct inode *inode) } EXPORT_SYMBOL(inode_nohighmem); +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 & ~I_CTIME_QUERIED; + return ts; +} +EXPORT_SYMBOL(inode_set_ctime_to_ts); + /** * timestamp_truncate - Truncate timespec to a granularity * @t: Timespec @@ -2538,38 +2605,89 @@ struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode) } EXPORT_SYMBOL(timestamp_truncate); -/** - * current_time - Return FS time - * @inode: inode. - * - * Return the current time truncated to the time granularity supported by - * the fs. - * - * Note that inode and inode->sb cannot be NULL. - * Otherwise, the function warns and returns time without truncation. - */ -struct timespec64 current_time(struct inode *inode) -{ - struct timespec64 now; - - ktime_get_coarse_real_ts64(&now); - return timestamp_truncate(now, inode); -} -EXPORT_SYMBOL(current_time); - /** * 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. + * Set the inode's ctime to the current value for the inode. Returns + * the current value that was assigned. If this is a not multigrain inode, + * then we just set it to whatever the coarse_ctime is. + * + * If it is multigrain, then we first see if the coarse-grained + * timestamp is distinct from what we have. If so, then we'll just use + * that. If we have to get a fine-grained timestamp, then do so, and + * try to swap it into the floor. We accept the new floor value + * regardless of the outcome of the cmpxchg. After that, we try to + * swap the new value into i_ctime_nsec. Again, we take the resulting + * ctime, regardless of the outcome of the swap. */ struct timespec64 inode_set_ctime_current(struct inode *inode) { - struct timespec64 now = current_time(inode); + ktime_t now, floor = smp_load_acquire(&ctime_floor); + struct timespec64 now_ts; + u32 cns, cur; + + now = coarse_ctime(floor); + + /* Just return that if this is not a multigrain fs */ + if (!is_mgtime(inode)) { + now_ts = ktime_to_timespec64(now); + inode_set_ctime_to_ts(inode, now_ts); + goto out; + } - inode_set_ctime_to_ts(inode, now); - return now; + /* + * We only need a fine-grained time if someone has queried it, + * 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) { + ktime_t ctime = ktime_set(inode->i_ctime_sec, cns & ~I_CTIME_QUERIED); + + if (!ktime_after(now, ctime)) { + ktime_t old, fine; + + /* Get a fine-grained time */ + fine = ktime_get(); + + /* + * If the cmpxchg works, we take the new floor value. If + * not, then that means that someone else changed it after we + * fetched it but before we got here. That value is just + * as good, so keep it. + */ + old = cmpxchg(&ctime_floor, floor, fine); + if (old != floor) + fine = old; + now = ktime_mono_to_real(fine); + } + } + now_ts = ktime_to_timespec64(now); +retry: + /* Try to swap the nsec value into place. */ + cur = cmpxchg(&inode->i_ctime_nsec, cns, now_ts.tv_nsec); + + /* If swap occurred, then we're (mostly) done */ + if (cur == cns) { + inode->i_ctime_sec = now_ts.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_ts.tv_sec = inode->i_ctime_sec; + now_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + } +out: + return timestamp_truncate(now_ts, inode); } EXPORT_SYMBOL(inode_set_ctime_current); diff --git a/fs/stat.c b/fs/stat.c index 6f65b3456cad..df7fdd3afed9 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -26,6 +26,32 @@ #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 so the next write + * will ensure a distinct timestamp. + */ +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_fetch_or(I_CTIME_QUERIED, pcn)) & ~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 +84,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 dc9f9c4b2572..f873f6c58669 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1608,6 +1608,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; @@ -1615,7 +1626,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) @@ -1626,13 +1637,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 @@ -2490,6 +2495,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; @@ -2513,6 +2519,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)); @@ -3252,6 +3269,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); extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); From patchwork Fri Jul 5 17:02:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725442 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AAF116F0ED; Fri, 5 Jul 2024 17:03:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198982; cv=none; b=TPjWui6nc+TIXPzyap/uSybxY6dy+ZMK+IUMysV0F4r8fQkgNDS4j6YkCthhDJ3eGW1nJY8xp9PMN+WjitkqIlM0HVRjJBeA71jwhWyHDGr7FhQz36kf/qV9xIjX8kMTP/b70KE7L4LekQ3GTPSJC6YcU3+CVso2EVswkjLiabo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198982; c=relaxed/simple; bh=GhiNb5Rp3y6E5eQ0/354yg7YEonNuQ8RCB0kW9t0l7g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IKLuMx/qdgozZbKQvIOyDveaetV+7cpNPG+rfq1lfFHWtGy1UTGSEAceStPT4mRgYEDNhdHrnnhE1ZySNbqW/umQmtuPgtmaFFDrI6AZ6zSoaBg8GphKfOiDhYu8oj7GurrUDJ1reJ8d5+3eT39rD2xJWmu838LkrlvQoUCWqhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZnLONj/h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZnLONj/h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 911E9C4AF11; Fri, 5 Jul 2024 17:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198982; bh=GhiNb5Rp3y6E5eQ0/354yg7YEonNuQ8RCB0kW9t0l7g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZnLONj/hu2KVW0C2XHKr7k9afRYizo1wBh8VyFbv6ftScL2Ormo4a9UKtrbGiSeSS PoI5PQCaHpTuoSTrDKP5he5ihIvvtoFAc6ilt5eyzV9glRuYhhm9ZktAIBuT0+khtr EFAl1SBZMinhW29ivH/MfynIvKVdLi/yjFVsB7EeMfYad3z6dEySQmSjERoKHJ06mX Im/Nl9fHCmlVprWKnFBsMw8ud2CgBY0PE7GNyApxhcUAq24Z1kjKlZH8g54uA4uTFZ BOzyalGDm7A03saSSO8tfje5/L5r9TNPf6k5dD4Fi1J9p38DofQYMWzckC+XTTT7sx y2VHIeElXje6w== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:36 -0400 Subject: [PATCH v3 2/9] fs: tracepoints around multigrain timestamp events Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-2-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5043; i=jlayton@kernel.org; h=from:subject:message-id; bh=GhiNb5Rp3y6E5eQ0/354yg7YEonNuQ8RCB0kW9t0l7g=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc8sugM77UpnbOVavEn9ip1g17NATieHZMGA YUffdzTePCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPAAKCRAADmhBGVaC FZm9EACreEaIUiF7eQm7h3tdABL+r8H0QLz2l0niCCIEOV82RNNSH1PPunPbnZXlursqjT/Df7h Tj+NsqmueLXMQRE05FUgwYrlAoZbyVa+E/AwsiV/H4KZkYeEZklqMymNm8FJmLWCxbegb+bZC+9 bJxQxz8h+guQsrUKeq314xnP/2y/GvUkKkaG8ZyjK+i3gW3/uz4IqBVANMriISFjd6V4ZF12dcc BpOijtB8arPUZEL7FZCAxNBBTM7s8V00ttTkd/dc/UUQef/NZnDgWmvfJResQwiQ32IsDGcexPv 3Z1gNl7/sCsjz3IeVWJjncScJlTMrCc3yI5v2kNKdcObDBN08TBqA+uUc4/CHwALxAKqgm38z3F tztkbOcqO2RdIwXtqgeoiiQYO9s3IMtjk5uuUzqOQcSAWtg5/iav/BNIx0j1lRCKCz5e1ye+/cV F5iiqULV4t8Zr4KMJPpnw3u9MhwQ6pwyLQX6+L9X6Xkj1wYx7iU01EC60QkYYz7KXAYLanO/zPk UOAwp7NYPm0qGrD9v82FsTZAzE0VdPtHvD71q8yeswu0cOcRIxs6KTFoAetB9Bzbp3mGeB91pqt 3efIx93aokHK1m0vPmwjR/3cOs7smkpBvOatsmQV0C7IGarFno1qtnvTVDpz+PjYAN/84eI8iSq dmikcbxkhLycGBg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add some tracepoints around various multigrain timestamp events. Signed-off-by: Jeff Layton --- fs/inode.c | 5 ++ fs/stat.c | 3 ++ include/trace/events/timestamp.h | 109 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 844ff0750959..4ab7aee3558c 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,9 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" /* @@ -2570,6 +2573,7 @@ struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 t { inode->i_ctime_sec = ts.tv_sec; inode->i_ctime_nsec = ts.tv_nsec & ~I_CTIME_QUERIED; + trace_inode_set_ctime_to_ts(inode, &ts); return ts; } EXPORT_SYMBOL(inode_set_ctime_to_ts); @@ -2667,6 +2671,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) retry: /* Try to swap the nsec value into place. */ cur = cmpxchg(&inode->i_ctime_nsec, cns, now_ts.tv_nsec); + trace_ctime_ns_xchg(inode, cns, now_ts.tv_nsec, cur); /* If swap occurred, then we're (mostly) done */ if (cur == cns) { diff --git a/fs/stat.c b/fs/stat.c index df7fdd3afed9..552dfd67688b 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -23,6 +23,8 @@ #include #include +#include + #include "internal.h" #include "mount.h" @@ -49,6 +51,7 @@ void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) stat->mtime = inode_get_mtime(inode); stat->ctime.tv_sec = inode->i_ctime_sec; stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)) & ~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 000000000000..a004e5572673 --- /dev/null +++ b/include/trace/events/timestamp.h @@ -0,0 +1,109 @@ +/* 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 + +TRACE_EVENT(inode_set_ctime_to_ts, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + + TP_ARGS(inode, ctime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(u32, gen) + __field(time64_t, ctime_s) + __field(u32, ctime_ns) + ), + + 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 + ) +); + +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:%c new=%u cur=%u:%c", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->old & ~I_CTIME_QUERIED, __entry->old & I_CTIME_QUERIED ? 'Q' : '-', + __entry->new, + __entry->cur & ~I_CTIME_QUERIED, __entry->cur & I_CTIME_QUERIED ? 'Q' : '-' + ) +); + +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(u32, gen) + __field(time64_t, ctime_s) + __field(time64_t, mtime_s) + __field(u32, ctime_ns) + __field(u32, mtime_ns) + ), + + 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 Fri Jul 5 17:02:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725443 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E96A16FF31; Fri, 5 Jul 2024 17:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198985; cv=none; b=kzHcr1MzU8l7EbZ9vJ5FBS41AK4HbEhixZJjEU+RnasbVa+e0gYYrw5MERDtd9FaPDeejNxFgS/GAByeMB9WpOsFuYlKdfLjViJlDeOegnYAzZPM70vFfPmZ2yhNYg6j1eZSbjTSXv07kAAIwR1ean5Idr8049vgq9Hq20SE8MU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198985; c=relaxed/simple; bh=+1OK0xDU8G2id45dYRlr32i7detxgV/LcM9BvZ/n97g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ue45s4WcSgc3nKrN15EqM4eTrylh9AJ9ZLyrRJUfFrH/ilmnt1t5m/4LvMBDO0m5iPXvmUW/rKGfm96uinrb056NJuPulJ/5SGR5kB+PDPHnOpbiV8cU9UStq0g53DaO2o/RddD8QjhQE2uigy+tTt2CxWAKjN7UYVlV0mxBEFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DNNqRxxG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DNNqRxxG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48923C4AF50; Fri, 5 Jul 2024 17:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198984; bh=+1OK0xDU8G2id45dYRlr32i7detxgV/LcM9BvZ/n97g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DNNqRxxGHO2l4hhgMZOJMofVeLsl83SaLoA4KkS5nEgKlJ0pS0A8N+2rNxaioxT7+ CiFK+0AmFofAfVZs+rMS9qrqHOgg0cfKitBFhCBCtIn749P6sRp1IHp9ti9A/Hhnf4 vn3ob6MrGjJ/X0lncPcmZyt4UeEwBXTiR06bbxI3+ZDSLvuqJ5aKzBOiAd/DqRcPvd FZJYkk/KuuiLgsRwX+b7/RXis4CLt9jJYZFNODl5tGvZiwKGwmRgoXbbIKOyRV8ZrF /VI6OGDuR+/+HfUPSu+3EIFe372dvyPYeFE/K9TqGAcCA0T/B2GJhWjVdg5EybMTwF buKVApYBc0XUg== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:37 -0400 Subject: [PATCH v3 3/9] fs: add percpu counters to count fine vs. coarse timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-3-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3096; i=jlayton@kernel.org; h=from:subject:message-id; bh=+1OK0xDU8G2id45dYRlr32i7detxgV/LcM9BvZ/n97g=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc9NpIqArIlvQ4m695T/o+BYLlZdPbZsZCBm 5bymx7blxGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FbXsD/0S1Bkq6Yz6RSyvaCXFu41T9zBOdd/yMsk5WBlsV5ppRy2jxalIc7hhIAH2yAxNRTiW6AD Fs6Q6+/UensT2Wt3JluZVcZnHjaR4mL/Xt23H2ZuIYL3owWxb2kQkZG6EfaOi4ASqNpv1fS3V5B /0DQkwBfkoD+9RrlkdTJ/EY4vUOVvHN5sHVA44yTEhF8K/IT9R3HoyBTLWkwNI1qpRuZGUh8UZq Zb5qZxrocLXCzs9Ay7qb+WCTjP51ng3xmTY0KgcH1K81TFGNhvNraGBtwF4FGxaB6AOt6UqWxkI YOeDijkYylcOHaA4l7xnstdm71Ia1CPlNbQEw7hmxhpwD0DKmXUFWBNUP9Uuu4gdY0Ma6JdlIod pi+Vp5JXL2z2rhNNpjATuCqHocDFDEj1RFijUY2vF9cLLwgjvyEbx7DukXeFuC98jL3YaiJE1cS g6zsqYzFfjN/34zAJo2ooq1x5vGIW42JVCJdx9iVK3E7Mi8YhU42jKEmk2+Ci7WXqxdu4/yp0XJ pERG93gcMk25kcaVssOjMAHGeQr9GHwl8TkraT9olc59qhGXmfiycf9MqmfgbVLKSbecBPGNS5u WKpNuOESwnEZO0RKQadcRLJLenjgMmQtpb/DggW2mSevrnANhab5pDD9tB0/C0qlqvmlhfdWpbJ ySj1wc4LTu71FoQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Keep a pair of percpu counters so we can track what proportion of timestamps is fine-grained. Signed-off-by: Jeff Layton --- fs/inode.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 4ab7aee3558c..2e5610ebb205 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -69,6 +71,11 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); * converted to the realtime clock on an as-needed basis. */ static __cacheline_aligned_in_smp ktime_t ctime_floor; + +static struct percpu_counter mg_ctime_updates; +static struct percpu_counter mg_floor_swaps; +static struct percpu_counter mg_ctime_swaps; + /* * Empty aops. Can be used for the cases where the user does not * define any of the address_space operations. @@ -2662,11 +2669,14 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) * as good, so keep it. */ old = cmpxchg(&ctime_floor, floor, fine); - if (old != floor) + if (old == floor) + percpu_counter_inc(&mg_floor_swaps); + else fine = old; now = ktime_mono_to_real(fine); } } + percpu_counter_inc(&mg_ctime_updates); now_ts = ktime_to_timespec64(now); retry: /* Try to swap the nsec value into place. */ @@ -2676,6 +2686,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* If swap occurred, then we're (mostly) done */ if (cur == cns) { inode->i_ctime_sec = now_ts.tv_sec; + percpu_counter_inc(&mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED? @@ -2745,3 +2756,39 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap, return mode & ~S_ISGID; } EXPORT_SYMBOL(mode_strip_sgid); + +static int mgts_show(struct seq_file *s, void *p) +{ + u64 ctime_updates = percpu_counter_sum(&mg_ctime_updates); + u64 floor_swaps = percpu_counter_sum(&mg_floor_swaps); + u64 ctime_swaps = percpu_counter_sum(&mg_ctime_swaps); + + seq_printf(s, "%llu %llu %llu\n", ctime_updates, ctime_swaps, floor_swaps); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + int ret = percpu_counter_init(&mg_ctime_updates, 0, GFP_KERNEL); + + if (ret) + return ret; + + ret = percpu_counter_init(&mg_floor_swaps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_ctime_updates); + return ret; + } + + ret = percpu_counter_init(&mg_ctime_swaps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_floor_swaps); + percpu_counter_destroy(&mg_ctime_updates); + return ret; + } + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init); From patchwork Fri Jul 5 17:02:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725444 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C939171069; Fri, 5 Jul 2024 17:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198987; cv=none; b=ejLGjKQaaHHQQyXwJuiG/TKyuWwJn5PugsxaoeGkcfKZIslycSt1nQfQdlbjvwe3hyn2jCZNE4ZtMpUti9qD6N0nKJGp6/COcPWX33IW6Znzh+MgIa8EigKZeJ7oIVTSGloMeEq5NzNxyTYCecuUV3U7GLHVRT3uVPRQxnYKcTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198987; c=relaxed/simple; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sUYQrwWuFlIcDXxBfbUo54tZIk+R9VouTn41NxIGYEkk0Tdl516bDtFInduCH5+0HhufTDvsGriI4ZoCWU8D4tQCaaWYa+APqpWk1P2aE0UW/dxUcPODCa5jHwNfNKXaBhL4VahR0be1UkxzMjAyUA/eQduDJH3plxsVqfygtM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cyz8CZ2I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cyz8CZ2I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01278C116B1; Fri, 5 Jul 2024 17:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198987; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Cyz8CZ2I8i9mmYGb6ZNUwNOM+PE3vABCpnlA3oN3yzR9v4w0ZVF3UIEsGVMUP98gG jjN1TaIRrsc6xDHJGucWD6Crn+ugFP3rbPn0DWbaSa1EkmfB1wRQkTrVBq6mkyYObE 2jZQgjGSdd0lqGgZ686afBlmBFPI/V8rsl7idRLWf9Gvvm8JpZu+fqkKPj1gBuje4s ZgfyPqvxLkG10WOZPeGGITJ7lOZOKjezg+nKTnFCQV4+ZvcAM7DOD4IsAgB6OcP/pa f5TrQYDghSURE9jMAOc9HS99fKf0NXO6QDQIr6ML5cAUoPdCP3r07ylQmhCo/XJ609 E3zzhwsarXOFw== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:38 -0400 Subject: [PATCH v3 4/9] fs: have setattr_copy handle multigrain timestamps appropriately Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-4-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3403; i=jlayton@kernel.org; h=from:subject:message-id; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc9jHht+laBBOwQf5fabXQzRZYLzNmz+tU17 u0Pkhtrd3CJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FflrD/9UNmmTOjbmFEi/KAzSSVbAVfNgsbqqX+5s63+bZfwuZYllGcNP+F9G4xrOyuE1U5D9qiC xmuwsN2Py5WyoEunyvofUP6i+DH2nWEE3nnXDrW+AZhwWbqSkqh6kq9PAA8pjy/njoAc1qyjJsk p1eoQgk2IKxROPgrfbuNzEDem7vxiqxANMjiC6dz+grRH6m0T8pPELw2oQSWsUliHAMeK/tSRee ff2NVdm+R/v2frifR6dbtweCcIVJii4wCGsg0bWWjpLx96ljg/pVaHxx5t6wWkMyp7zKqCF+39L +iKcZtzGsYbSjN4upIotuFyzeFqZeBbNeF/6vFtMY90KhWzDWG/8wYGr0rXehKglm+P3eI4CuYo zUhsoyoRkcUJKSogV7zqtRRBjS+BKs8I4DivCkUwIY/VwOhOMJoZ+j7E9zgrWsiNrK6muZQjwRR gTUJzzp3rApfGkUNKkxWlneOvRnXdgvR/Gr9EuxTXxnuPoxKr45Wo3x+LV98RTyWs3a9EcVrjtl WIu7NFt95+80lPNtMYBTY5ccCV1Ioi8JHnwpb1OhmiW6rqYVU6xBGbqgy20YQ0vrVkJmxgEMFOE B++cCxOX2PSFLtRn+cuaqfSD91T7uY450SrteDzWd5TUEWXl7JgAnU/vOHfPAmoDqN0XcpOPijS mz7WpBTEbj3VEiA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The setattr codepath is still using coarse-grained timestamps, even on multigrain filesystems. To fix this, we need to 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(). Note that we don't want to do this universally however, as some filesystems (e.g. most networked fs) want to do an explicit update elsewhere before updating the local inode. 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 825007d5cda4..e03ea6951864 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, we need to 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 we're setting those 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 Fri Jul 5 17:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725445 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46A5D1741D6; Fri, 5 Jul 2024 17:03:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198990; cv=none; b=o2X81jqQdqkr7vfazuxKnPoW5aI6SiahNlmWiQTxAFlzaUxTWLYZ5zTaqsz/iK0nRjyKK9bmv9GJwiaZlV0lK29zw0P934NOgpLpee1RNyJFRIqeIT2b7yF2JMJe667KtMEXMlrzFQBjf3OMG1/XKMmNJR8y+2xzgwcScgTb9sQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198990; c=relaxed/simple; bh=Jo9jHESP93Ns2L4cRjs189VoSP34rgHP4WDevXUywUM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WP+bB1m6U/kwU2Ods50Jdl//oj+xdsj+YTD2U35j35ZQ7D+/bMIofpAE1aidXsFx/PfwhKik8OjHw/HqKZTxfqWPnMZWeVpgn/mqeVIozVGFblmHdeLjQSRkF23lRDcU4rPwTHKB8TU8gEygPZuUgV1TGIeOZck5nxNs+uc4jGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E1pYph3G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E1pYph3G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8B28C32786; Fri, 5 Jul 2024 17:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198990; bh=Jo9jHESP93Ns2L4cRjs189VoSP34rgHP4WDevXUywUM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=E1pYph3G5cHM90wnA+rcrhKplEYNOLR7Ksl5KmleFIUQzmfyG7jkLtc0DACl/wVcg cGhyu+/HijeYX2jBXA+OPg6Buw8BLzMzi/liYgQEG8Ydgpe0OHb12W0yeIV7mITqco +R/qbBy2mlJnnCj0cuAD+D+O33qnB4Epuh/xTJp821cniJSk0TqmliyXMup7+24xvQ TsRrYPyX2jvwrZtwkwDduvFwTUorm+NBwFDOaeXDIkK6sppsbl7xxZK3jSfdtlSHu6 vJFo5SRSflfSOrk6/jqD+vV+EKDwoBiBL18eduVlH0mIN234EKXGU36kw+lFn9XC3a ZK9Krotb1HwsA== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:39 -0400 Subject: [PATCH v3 5/9] Documentation: add a new file documenting multigrain timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-5-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6283; i=jlayton@kernel.org; h=from:subject:message-id; bh=Jo9jHESP93Ns2L4cRjs189VoSP34rgHP4WDevXUywUM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc96KXbG+1N5n+hAriiu7soeEHZK7nCeSebK b73rjQpQgWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FeWCD/4xwaw0Zu+wyl2eZJk3bgsgpCQvLN8RxReh2ZqY80Wj6IWqmAOK6HAeWxAEHq0NHWG6ned QgTwfDYznBdehBExWUDppv7UBWlAR8kphFotIhSc8sRonxSs9LyanzukWk/93rWBlOHKQ5V8g09 jXXAJSacWxbI7SDjMjz+mHaJ5r2rj3amOmdzOoDJ6i51t2XEsSWNuP0iw95N9/wJGnId79bFxuL QRgS3IMAY6qvN+ZqoNVeiRgYjR+xlJyOrny4M9nc1jUHF6WXO3yW2SZTD9IRY5h5gvYCh09kwX2 6XOI3z+o+ACdDYGfwMiG7ORo8+4AZby7l43ApWVJiu7vs4tbb8vEgz/iIbGsDXzE9NbZHcZFTfV BNF2mNW5bgBvUtK6JZeYn/Ks3glY99cmhp7Q4pkBfuwvEkt5+2tK/dcsjre29dlA1cERmEplqL8 M9f9/BhpE6+1eh2KLctnyu010c4kEBOCRHBmXgCyKun+wqT3qy1w/ACDMGyoXBgeEN/QjQbN1lT re0AjBQ0eDcHa6wRdjD+2VlXM1997QIimFHl+xoHIP5bYkwL3wM1wIvDRp6RwmKYVYIkFFBtN7Y qPn3gcpSwQt6czdZ6qeY2ntqt++WEgQW2wz6/9s0vMEc7cJuwuWJgFOHtsu03KAYoaZSWEA0gWF VwHbct/dgY/7D3w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add a high-level document that describes how multigrain timestamps work, rationale for them, and some info about implementation and tradeoffs. Signed-off-by: Jeff Layton --- Documentation/filesystems/multigrain-ts.rst | 120 ++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst new file mode 100644 index 000000000000..70d36955bb83 --- /dev/null +++ b/Documentation/filesystems/multigrain-ts.rst @@ -0,0 +1,120 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +Multigrain Timestamps +===================== + +Introduction +============ +Historically, the kernel has always used a coarse time values to stamp +inodes. This value is updated on 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 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. + +Multigrain Timestamps +===================== +Multigrain timestamps are aimed at ensuring that changes to a single file are +always recognizeable, 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, we 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 you should have it call fill_mg_cmtime to +fill those values. From patchwork Fri Jul 5 17:02:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725446 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DCE517623D; Fri, 5 Jul 2024 17:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198993; cv=none; b=J+M6G8BgbBCg04milMJq5m2mIPiX8jwHrfAPGD5679CYXrtlf/EY76FyhIKmzxdcwlRRLydZwe3kd9rPGzUMjNOTPAnMicLlW5aL49jIWjUVb0ZEZJaWhzlaI2UaYGbq4QHUFqa1V/JkrKTGDWiEKU4GS+c3R2p/sgJHAQ+PlAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198993; c=relaxed/simple; bh=fHx/mgJgehSKKeWi0EcYG4swNcOzJbq5fDt162sYPoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ArxE8odlUGiO9HWh36TXuWDPX5K46AtZinYXA3E4dE82x4wq0I6OYZKBK/Zmt5sm2rXBlJItiFiQi9eqDQK+xUvVlqhzrdQWk8Q0F5xAuWeJCKrGFza7VgtpbVs7kmAD8rwFBT4vrh+WRzZ6pYih9z+pFZKPlk3d3axXZ71nNVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pFNMlHRp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pFNMlHRp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AD89C116B1; Fri, 5 Jul 2024 17:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198992; bh=fHx/mgJgehSKKeWi0EcYG4swNcOzJbq5fDt162sYPoU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pFNMlHRptiCPxoVW4EOiR7WO0/zYXa89l/fPMgoNf5AcD1j0QjfFpk7GlhdsvRwIR 5V0uLlGmmChgtw4dhacU78NzZ8i1twVdYClzTvEBMz0xPQNGrpLuMqo3EADhzmgqyM xsvvnJ++uE78MbjIYGF0TWDBmj9VtzLwUhUKIniPBDV/IQQPrbCOkHeRHfyzR4FECJ XyrfqlypAWzBkUXaSIigSGZhQRlBuohxlJH3yYWjHB4/yUqOJ7+IbZ/HABim6RnL8J jqKGc5+xcE7OOh+CBSmCNtZju+LvwHcbs5euvDPZxaOJk5RLEdSiWUv/sqy36PHLJG r4vH5xiDFZnxg== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:40 -0400 Subject: [PATCH v3 6/9] xfs: switch to multigrain timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-6-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2796; i=jlayton@kernel.org; h=from:subject:message-id; bh=fHx/mgJgehSKKeWi0EcYG4swNcOzJbq5fDt162sYPoU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc9e+P556Il0il5vHp8BAdjtXPeX1e8EOhLP jUf6awt9NKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FWn4EACQjm4ox/0vQ42fWfEHqD9prX/Xo8BUzeI6USK/05kred47VvYUJSEcRdTLyFRqI1YZMDu FvBotyrGsb13AYuiDIfYy3zG+irqrknjR/TJVqXQAYLOTUjAy1xuO6q4LA3bk+FVagWda/+mZqm EmcQLal71uzaxW6ngdjZKmhzW+TuxollfsiibuLXPExM8txA8FdcOQPVtm/f9Z/LtcPkvDupdhP FtJauLfBdtkCEXTsM03y71zEGNqTcpKZ2eXs8Pon/FENIvMcs+0+2oWSZdqkDfXBUVCNj0ESYj+ 9b6r/3qoiF49U+hT2eJ8C340v+dsB+FccYmGcuRiOIxdyIIcK4v323FwKe+0uyisHVw3azzx78w WMN/q6SJWSmf2edEhQ13rNyxGQptQLd9ITLvZX5PAIMIURo0/dCYdIe2zW8zxsfJ/1DbzdXUbKz 6N2a4tmjRKf2ohgQ8XMijdpPBfAcuvPluQvYfOQ0USRlErrFMEqH1/p+Og6eL883YkRKPtk18T9 zbrETeNMx68HzXu47YvKDGhJmv0RhYPFw1e3Od4FisiFMrCZjAo/90b98KFG+4/BE+DB5Xf/r5Y Y/76lodMQOMwaJf5jlk5g0l6x7gpzgNg8KoX5mmXq4uPlap+0OvHF/hjQwjsnU6ij7Fy176ax0O TylVmfjyKXvtWUw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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. 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 69fc5b981352..1f3639bbf5f0 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_CREATE) ip->i_crtime = tv; } diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index a00dcbc77e12..d25872f818fa 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -592,8 +592,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)) { @@ -603,11 +604,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 27e9f749c4c7..210481b03fdb 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 Fri Jul 5 17:02:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725447 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7008176ADD; Fri, 5 Jul 2024 17:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198996; cv=none; b=uJjFUmTWZEjuDBUOGjOS4vAoUl5jOO0uHHrV5EfghB0iqajrZE+jwX5hrDnd70DlqbiOI4POChZlYxND9k7S4/C2tOMzY0e45EDwdObhhjSk7rRESLjot8bTHVuz9vXx/ACTH9s9NfClbr9casqAjTqHxUUiUcPk021uEvCPYOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198996; c=relaxed/simple; bh=aIxGR7na/Qdc3ayjXzlWsssXh9j6/eXvzZW4Lz1mI/Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fjefnuT26666vFKgTfVrGavvGsRgcBP7UZ3YVzlcYAZSMtHoG7UuWCsMwgxizdFERGXaex3C+yk+XQaWYLy39BSlQ9T0poCYiBEJg+tWnjkDUluVwNl+oDfnDMzj4CIKCZBKmw2CyLRE0/nbsiKUEzWgNHAxxapVugYl0X4cD54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TReJYSx1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TReJYSx1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C9BFC4AF0B; Fri, 5 Jul 2024 17:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198995; bh=aIxGR7na/Qdc3ayjXzlWsssXh9j6/eXvzZW4Lz1mI/Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TReJYSx1sCjaFckosgokJVYdFRsqdc+BEhrB6aLK/aeu7kaO3qZ0EY14m5FOVfeIV bquuw2wB7AGQAeXWVitRFh1iucPOFXlLIvpMO1xHm+pSXrnj2JfNcK+3uImbVUJqF8 ooVP46QyE9vcHkMC+vCCeyxejoUMK9J7MyO4dDaDlx5SzUZ2CruJdKJrVXtDZoY7OM n9G7T8zBnKQlervr77kDsbh/uWnOKDtqF9wkDmMcrFtbDcaTSw9MEBrBP63aMfsdpq jPjUQE4G1sPS53d+EAtLlH0HeUSTzP0a5rmiq+sxQ5cBkQ0+jqTP6hXvUixI69VNoB 97ddI9/Tc46VQ== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:41 -0400 Subject: [PATCH v3 7/9] ext4: switch to multigrain timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-7-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=839; i=jlayton@kernel.org; h=from:subject:message-id; bh=aIxGR7na/Qdc3ayjXzlWsssXh9j6/eXvzZW4Lz1mI/Q=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc9kz56sgDasuPVWKgUS6NFCixJC5I3irJH/ BJ6/27HOlmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FaabEACeX3QSlJx8oIO3SRGCQ+Om1KIdPCb3C38Fh01RPmQPMKulGZ6MoP+EegyFuxbH8BPk69D P0KfnfHp4PgPo/KVYA1IXdGLZl/ftLMHnSX/TSoHm5zsXYc+eE4VyfBjXrMkxK3uucFCipmehFL OonO5/qF6IhuwmuHA6hqOjKWjFusQBdNiCl/d0WlGJSTK2spR5fz+95PtBAKTaolM1FuRNPU0Np UF+bepYzTVyXvZu2D8RI386JfFI6MhEkOlR+zUbWS2j2eZZT8NUX4Mfu9g31FmS4/mM3/AWRVQy BWu7PXB+AJ2cQpK/KgrgAm/QYhHhjjBXk++FjAraItffpUyBIp0mpj+rODhirB/L4Ql0lDEr9qW G46O6Erz6NmeTBhZ/naS/BbbyX2nONvhsXU+C7E8rlLng+WVZjN5jGfHpm1Ddf0rNkZgIGUZMX1 +sKOcVouQRuTLN9Kwlyb5Ad35NIJwQLqnH1uX+uy9v68qD5eKL/irYtkXUJS4x/6jNu84uX5uor 67SSc5xXA7hQ+YOrHaSl91bPhqrPDmhI3w3chsfl1z/mh0Wt/xWUp3q/HnsoODCEOM2AHJvMisr X1ejiE3Sc9O7jkpCNMxwoA3FdcFBZlSIhPXGpEm9/tyvPIkrQqCAoJTAtVQnnIVzCUpOHoowEdl chcIJfIVrHpmk6g== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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. 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 eb899628e121..95d4d7c0957a 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7294,7 +7294,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 Fri Jul 5 17:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725448 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AC92178382; Fri, 5 Jul 2024 17:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198998; cv=none; b=V50JW4G010SN6lgfr3NJztE6ZDPujNuEMFHXEfIAVN6tLGOYvtkTHcvEpxYsp8Ia0++1L+Z0sgFeYQCHmrVwJbps3SnltTD7NN0ae3CKGiOGAVM0IAwWAfYfxry1PW5PZTMUSQ6Ihp5VN1inoQBl4yUq89CUaNFCTkeTB42iv/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720198998; c=relaxed/simple; bh=xTk9IFiZeoZdqPbR7bcsVc6tPLRLkOIJYDVl81q/MME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rlwya8vXkpU2wPKqcKVNeZMvN5z7AneCrRx/ftZd/jqg3VpRtRG2S8blbfmy7ymALrAh9FBxh4155T+m4seORfnLOyR4IaznPR+vVKe4QsOfIMc1XhRrC7otMmwdhGxYW46SHeUXj9eJZ25Zzc4IWHXTqO+E1n2R9FLqW+dhenc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QIWijJEX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QIWijJEX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4208C4AF0C; Fri, 5 Jul 2024 17:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720198998; bh=xTk9IFiZeoZdqPbR7bcsVc6tPLRLkOIJYDVl81q/MME=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QIWijJEXIlt9Fzjqu0/oHnvwFuJ2XenRfKa2ibEcmz/gfkePuJ28kk0schgfhbNNV bzeyvITyCAeZ4Frg9k7fKKgCKgxo6eyVfVjzqDS21h142buI5F0QAm8aYVNdye4fuD Pld9qED4V6fAh0MLvH50sJ69JOuyzeeQ/zT3YfyxH+eUe/+fNLP/oiK1VMI4+VKNgy Is1DSUdyjI/XKSosEZsvRUs4r06Q1oIYc8WH79i5AodWduOBksgI/GQLD09ksNhgNk 1/emMNC3vRsOxgPhdJyGSRDZVwYWuHNmQX4CqullxwRCJ8t/xeGmTRl1DWB/NdI/ad iFzvu7RHMG0tg== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:42 -0400 Subject: [PATCH v3 8/9] btrfs: convert to multigrain timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-8-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2583; i=jlayton@kernel.org; h=from:subject:message-id; bh=xTk9IFiZeoZdqPbR7bcsVc6tPLRLkOIJYDVl81q/MME=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc9ppo8g7YDcKxR/HjaWHlTOUSO1fFuG2RWe rzanvFK2BiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FXjAD/9SLGHb9It2EGmGcwPeKpz3kwVgydgjCzH9vbqWOlCCrNmmKEuFVdjDeDAteD8frwEH/oF QaCpT6sFLL1YujnB0dXSUN3gadh5CvnJ2UqqkeHfbtRBC3MSiT227r/ouwiQuQ/Wl7CBqDkpYPD 5O3iCg2thusEQzq/SnDL5YJvqEcVT69C1Z6ieDecyWde4cQw/Zknu8IFBH9Wm2UltSah4L2hMFG 75zBSOlzAO/8fg4MetXPWYPXePRSYN3wM+Ml/+fTkEc3eFtWONe8tESuNAX37Ufl40+ogdAY4H5 joJynG2YsCi7wlYtHH+m31T+dauR7iny72PNZQDClsV/t/5GCDDjT6p6y6RZ5kuyXPXxsdG4aaO u6sFQSqKWByK2f1KI8hhx54DxjXKWi74TVtWEc1MHi+cHp/t1PmHBOQJi4erhjaRHN4T8ri8Gy3 VRooo9gMRkLP1Onmbvj7K6aB08Cs2dUkRJBpZTWGB1YFKji2sZeLA7DGEpEUfUyi/fWOHrS1WQ2 4VCA4Hnhgd0pOIsyj88N3dcfPvU9Jg7PieGdT7X4mSEoONnb4l6VfoJYbEQY4NnucRbDvFJKH6V UafPnPFxUCooR4tvZua/vbEvbKr0T80kAFAVgZCKCgJFJS1NR6owJ458/BeoZW41C9mhWfWKP4c PZJJJzXMnFGdWEw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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. 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 d90138683a0a..409628c0c3cc 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); -} - static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count) { @@ -1171,7 +1151,10 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, * 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 f05cce7c8b8d..1cd50293b98d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2173,7 +2173,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 Fri Jul 5 17:02:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13725449 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32B9517A92C; Fri, 5 Jul 2024 17:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720199001; cv=none; b=lWv76TljHy3RpBlaSW5ZvUWgAowxYU/HGyMJ0RAcZIcm0Kjb8KUpWubKcHOMJMc8OQpG3LMhFNI9CmMeoxTwb/qKfYFwf5m+0RQPFoPlOLQNaK0x7jcPqCtAvyEEtS39pyiCf/TnYjZc5LF7AsTXcLQZJoS4sFozWYJlGPIGQwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720199001; c=relaxed/simple; bh=pHEQop1T1fiyamd9jcpDhT/4UZTaEZSdDGTRt6fHlCQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cnlD2QER/kokYC7pIzNkpejgpxHUe6zNEq7J/fS/awVugL6ZuQ7mXoBb5oDthIsc7mFRTv3Ay8VkjXwvIcZT19P8m7G8tqIljtk+k2YFbQj02TLcrd7J9bT3E7I1tH1844w6btyc+fT6pCJJgm+7n6Skvy6mbt/g4INjDAujzhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GIF28tq/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GIF28tq/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69069C4AF07; Fri, 5 Jul 2024 17:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720199000; bh=pHEQop1T1fiyamd9jcpDhT/4UZTaEZSdDGTRt6fHlCQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GIF28tq/EK13s4RMBEeSAadr35rKcDq5IRamnX6pCdUp3F+CPwHJy0EA/gmZalfou 6nDCJ9rdvrdzfiZ9Lqx/ZNlKYu/E2Qa2C4xa96YCY2+X0Y2Iy0/p3taIHbI9vsvitd GCGmLULp8AGxtTjKnaYWN6c004o78XS8dz0M1yPcaUbfmtH3qwUKJ40TLysp68TwTU h7063zJs4fhYdQ2p2VXwE0vJ3vQ4IakiOzZ4jkHjufH/yAUxuYsjmL6D/EEeCLiicE TquJDQsI0jsWjpEV1da96vz8CaJCe2pj/NI/a0Yfm5WdG1CKuViVs5FJoCZ/gjtEGu fp8sXV5JVvSIA== From: Jeff Layton Date: Fri, 05 Jul 2024 13:02:43 -0400 Subject: [PATCH v3 9/9] tmpfs: add support for multigrain timestamps Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-mgtime-v3-9-85b2daa9b335@kernel.org> References: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> In-Reply-To: <20240705-mgtime-v3-0-85b2daa9b335@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-doc@vger.kernel.org, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=775; i=jlayton@kernel.org; h=from:subject:message-id; bh=pHEQop1T1fiyamd9jcpDhT/4UZTaEZSdDGTRt6fHlCQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmiCc9+3lWva5fNpNEWzu+7Rzw+GWxPBkon5ZUU ZWSCd8FdEiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZognPQAKCRAADmhBGVaC FcQ/EACXCMgwagZgAeeTGej6ZdWdoV08xda+ukWEVKdoIUb77+9qfa7Yv3j2f/9/vUmczA20jEa pMsyqiMipIpjHb/h6QXN34WJ12LdxjE1uXpo6tCZsInC6UN2DZS9BhXeYb7ejNH9aGX2uo+Ss9l eQKtsAwT2TQVgdXIggjo30q/WL0UDdlrrNaz8TwUVCsPoC2KeveW+rJYoKLJoVkw+AC6d91L+2O nI4jEVV+3rGAmY3a9UkYPb9aaAAzUpLQaYUYnKHgfn71zVj3thfOkumCfZ69GwVT+tt/3fonV/M EAnDuUuqXuuKMpqD6+6+iJ68pd7sk1HIlFtp2RvvY+8BUdr4pZ0ty/hgbke0sRNIeLSFJxPXTjQ tAQqsdr6u7uujdhIgMen0qCwqfC21yKaJzDa2+ETo+srnwz/Zxz4UwjpYZiU/OBc3C7Cah+WE70 om/sbkLTeER/YssLnFxwJK2dAAc8Ut5jqRaV6+TL6dtDmGDzd/rVbY+9uT7yZMU4xBpCggzk837 /xiNN+jD3DNYksPSR8+nl8+3A0tWZLKIqmqHjthV2ypV8JzeqG/3h6XVp7CS123/twcsw8uF2zH T+mn6oJ7266/eKdofn/eqBog5C5KQrE5oXZvl+0FraKOGR3haAe4gkhgk++OZcAxCEUAZUtV1Jt kQ8/0xbEalSX4mA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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. 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 440e2a9d8726..6dc817064140 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4649,7 +4649,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)