From patchwork Thu Jul 11 11:08:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730376 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 6D1B515B995; Thu, 11 Jul 2024 11:08:28 +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=1720696108; cv=none; b=hrFp3BhUZ7diDY0QRl1MlFz76EgPxCKuAPBSgz0bJwGdmQAFjRLqUtqGYP2DXbdEfxpU4u25PV9Z9hRu+Oy168uGQ2hB4+vwVjDKWgFyty86NDeBpXHFclD+srelRUT8DxIXU/majyP55YOJmvGU2OIltP4Vr/g+CDt4EO5TCb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696108; c=relaxed/simple; bh=IxBI5x78cxV+TlUA9TXEi+rPKuXyv5wGl1bxdbx3V9Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HpEmwYWTn0p/lVKyas3V+S9lxSHiMG0InthbgIbQ08P/7SyPQMb5NAM7guUhaOQ7xKahF0Nji+aIT0bZ09sy7QY2r6EBltSJy2a5l+1XBTPecj0u8ZNlcW5ATn3LT/0vBmd3A95cB2Sd0BiGpGYPh6BrpeJzQBEHrMfUVNpi/+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VUBwPH/V; 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="VUBwPH/V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08DAFC4AF0D; Thu, 11 Jul 2024 11:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696107; bh=IxBI5x78cxV+TlUA9TXEi+rPKuXyv5wGl1bxdbx3V9Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VUBwPH/VC+0W+NWeJnYLSaqtZm3MOeNdGRJClNTEfpflrKoiGVMEY4sxW5ZtJ4T6Q ZP+n1zDk7wlSdhlgKHZReJGnlZhHelPoB9wf1tfb8Qh7SAbQ21tpD2lxjjaF5DxIma n6EqI75EoSQgKfBtTLXuGaWtaRFWdshpjskE5TXmw2s6OQ6zN0wZCuO5FaBdiuFg/5 pSd4Hw/1/MRzVPHYLCQ4J15YkxFS3jMLcqNQsrcoOSl6bzpCYyJoqdiVhxLTiqjA9E wIWLs1BW/jS8va5aMBOrTPzIV5XoVFTF1xuh9JJAbb8GeuyHorVJd+OB2BUhlSXJww oeBIGxI2rCldQ== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:05 -0400 Subject: [PATCH v5 1/9] fs: add infrastructure for multigrain timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-1-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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=15228; i=jlayton@kernel.org; h=from:subject:message-id; bh=IxBI5x78cxV+TlUA9TXEi+rPKuXyv5wGl1bxdbx3V9Q=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70kb6ejazT61So4QBLkPJwXd+zBh5L6+1bhV F6m1VqHiX6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JAAKCRAADmhBGVaC FY9YEACNQeF2qsweCizgVPk1zHMSP3qpEz+Ctu2PfuTZWlae42CfJIpJXteIFmB/V2GT6bK3KDT lf3h46fLEaLOmVAtLNOjJq8vgFOTYkjlq2G9wQoAgWzsKv94PLSGOct+UTK0sydH5O8aMq+cLy3 ZY7oEaeAw+iYAxN7A29s3MlV5iNhonXg7TeixvIyeWfW1gBODBrZYb7IszpHDB1uC3gJUJvG53i TxEa1sSxavCw7wiU9wY3771gaaigWThV/bLcCycOObU80/IUw5uCJlKp2FOcaxOnQkhi0Pg/CXe brY9Q2rC/Q6XJGeG/6yR7qpzIUrjhaT6UXTveTXUsSxUZfDyl0vy6J9kq/x7lq3we2tc4xn3iaw DNjIbB7/s671fuP4LAmD5arKIQ7ISo9WogViLnGi+IA8P1Nm1T5Mj7BXkJy/D3OUI5Xe6XVEquJ TsUIBMwVnCdvzUJj1/5MfxYOEUPpzlPuK8JIVBY5yXKbhA8sRvEdoe/GOcTlLYPkiUWuccIQw09 m3pEZcCa36FzNL90zyFOGwCyAWM79xk8RngeWIJktbXjMOanN+n9sZlTJbh98rykHHWgnMQcSQ4 9jyu6fcS24Lk3XSyi+qX92afuQ80r3MA6rkPEG66gkuZvEdlfNp3G6Jrh6bNGzqUTSP2QsIRnW7 b0Iv+QdDzBmmoOw== 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 Reviewed-by: Darrick J. Wong --- fs/inode.c | 171 ++++++++++++++++++++++++++++++++++++++++++++--------- fs/stat.c | 36 ++++++++++- include/linux/fs.h | 34 ++++++++--- 3 files changed, 204 insertions(+), 37 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index f356fe2ec2b6..2b5889ff7b36 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -60,6 +60,13 @@ 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 fine-grained 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 atomic64_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 +2134,72 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/** + * coarse_ctime - return the current coarse-grained time + * @floor: current (monotonic) 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_get_coarse_real(); + 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 = atomic64_read(&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 +2567,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 +2606,87 @@ 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 not a 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 = atomic64_read(&ctime_floor); + struct timespec64 now_ts; + u32 cns, cur; + + now = coarse_ctime(floor); - inode_set_ctime_to_ts(inode, now); - return now; + /* Just return that if this is not a multigrain fs */ + if (!is_mgtime(inode)) { + now_ts = timestamp_truncate(ktime_to_timespec64(now), inode); + inode_set_ctime_to_ts(inode, now_ts); + goto out; + } + + /* + * 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 = floor; + if (!atomic64_try_cmpxchg(&ctime_floor, &old, fine)) + fine = old; + now = ktime_mono_to_real(fine); + } + } + now_ts = timestamp_truncate(ktime_to_timespec64(now), inode); + cur = cns; +retry: + /* Try to swap the nsec value into place. */ + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now_ts.tv_nsec)) { + /* If swap occurred, then we're (mostly) done */ + 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 now_ts; } 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 Thu Jul 11 11:08:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730377 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 6C50F16C844; Thu, 11 Jul 2024 11:08:31 +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=1720696111; cv=none; b=AUwD7wHGz/Dlu+HpRnrf8smLuytUWban6zlHYIhF82WMhyJLoYj9VeVZpNI/ZmX2GGlD9yEzaWPCGzXpuV1V6CozPq1vZNd7gJnye8DywQuHiiCaRGGP+Qfhb1jCpL2YbBlBKjpprFZajkl10Uvcf2UIh3lWfwV+YVE336yd0oY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696111; c=relaxed/simple; bh=rFzpgz1HqOKOCLh7b0SiDnaZS+NN3RBwFhHtuP1qUx4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AxGOC2mJHGkStA/01bvAuXZyx97tsPJTlM+ZB+M4NuN0Dd1FKsrygM2Ly1cUVRpaN0PBIKZiW+WW/tLgjoRmd2wckT2wbFgU3/1oPP4fC2+JrbzX9pFCjYuWUHHLrvbRTgIjT1thnLbtpMYgEIbJjSRDiy8AtgC1SI73j7VPuCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CLLmbufx; 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="CLLmbufx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28D80C4AF07; Thu, 11 Jul 2024 11:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696111; bh=rFzpgz1HqOKOCLh7b0SiDnaZS+NN3RBwFhHtuP1qUx4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CLLmbufxrMwqRIxsj3EShlbrXkeTe6QolAUV6OjeFmXNDxMrS8FgaZD5fet1zUGYK EuTAGivoIefR/QittNO1F0NVIxe/dS51KBHibbHueFnUadb5ve6vJiRuNL2BMH5unO bLpDY+VzZFC8jCXRma6W6JQ8FpSb3gi5uf6XgsV7RdM829lo6SghJDd4296X49b5Gp LRQ2TDjlvJBkDsNpa9lfKHTLunLNPiPQi9eaelK17ZwAOtk9XL3AgFLnOraT72P6Z8 eL1ItkUDt2fNUTMY8+d2jrdYOaOqk9huYtOczCijmsagZL4hsS518H2PdT4GMoXDYL GB+1wxSKonsRA== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:06 -0400 Subject: [PATCH v5 2/9] fs: tracepoints around multigrain timestamp events Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-2-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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=5096; i=jlayton@kernel.org; h=from:subject:message-id; bh=rFzpgz1HqOKOCLh7b0SiDnaZS+NN3RBwFhHtuP1qUx4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70kIZqRBAr9twF69KZlGMkMn1TAN28mNNhTf ngIzrb7jvWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JAAKCRAADmhBGVaC FX5SD/9yMgo83hVnTouqwh7Wudzs0Jud5XixMFsw35LiO08WfJQztDhsi7MJ6lxuIejoTHfuqus zAkkVjU1NHU1aPGZM1LaW8NY+PM5Vm0rg1H3Tp8LWaxM4u/kapfjM0f6xep+yI75SHRBm2T00Yu I0nrE8Ymxm8IwMju/5dPeqZG4gWibKcorgyLgv4TAmwfmidRhjYRIALqhKMAN+Zc2OCBLG48VMS foedmx1f1jk/Kv5n9NDlIFT6BNGhZrGahDsqXM5UaTVTksmsnXUL/o/neOWINHggU6rvsjS72SL ygap7ep9ZUCBW7Lh8t3Zm/htJpqnwBw6c7NvDCjFa4JBYo4v+6Jqbxkgy1qO/A7rCLhmnfQE2sv /SnXaHKUznyFIl0sOa4xvOln1B14jAlfpxmcUE/e3NWkb6Bzb+TxMujcTXnuVFUrepr/WsCnsU7 gzVw9Q/HcugitbGMkQgmeWtGtGfYHKUmf+LPetEcK8lPO95Gq5Bk5KRgVfoPTN5hX9vX8vVq36J TFbun/sDhI9A7eWtnr7ZkYbo9D71S6Iq+FQGQf3WeWlWqx77ThDn/39obkMI2vV/2/95kFnM+hw G1nCZSOkBoc/K5bQqsbxktIJueJou5XmijV4ZvXD0O4dC9kciGPM5YYI3NrMs3YdqjZwhI9KyRG 9mD08b4tXRCD0fg== 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 2b5889ff7b36..81b45e0a95a6 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,9 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" /* @@ -2571,6 +2574,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); @@ -2670,6 +2674,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now_ts.tv_nsec)) { /* If swap occurred, then we're (mostly) done */ inode->i_ctime_sec = now_ts.tv_sec; + trace_ctime_ns_xchg(inode, cns, now_ts.tv_nsec, cur); } else { /* * Was the change due to someone marking the old ctime QUERIED? 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..3a603190b46c --- /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(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 + ) +); + +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(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 Thu Jul 11 11:08:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730378 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 75EA516CD0E; Thu, 11 Jul 2024 11:08:34 +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=1720696114; cv=none; b=PQv+wtgOwMiT4n9elUjTBWtbAI+Hp81ii2jCzwFDOdGukAyVnmSFOo0wvkzGSU8xRj9NneATtJIy02ju5DvpzERuVSi0mwhzZq2EEUVam5vDHwIgLg0icni4nJv4m2Mhc3iq+JGBSpCxAdGJwcET8mpLbvelDjRxK2wV0O0cyds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696114; c=relaxed/simple; bh=V0Y36Pam00rCiMQb26squSrDlnu7zkSekBYQGaNEp4g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r65QmJrhGLyPKXgnh0gKeimcqEYjc7tCuPtjbOc+NUsSPzwnMPVIxJnxOsN+6IGi7qimy1eDbXjjaWshx39pOD3E7wUYPU2GGVh93PDKcmb07qQpdKjC5ISa1O9/Xcmo8YuW33YMbKMUvgaIuyTHZrxXkMb8FPv+1oXjR9p8xeM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JNqlpCJQ; 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="JNqlpCJQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34BA0C32786; Thu, 11 Jul 2024 11:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696114; bh=V0Y36Pam00rCiMQb26squSrDlnu7zkSekBYQGaNEp4g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JNqlpCJQnzaR4gPRF+/O7iGm2A36GRWO+KYPfgCzi+SSbIJ978sLXFTiY7DHW2bE+ eGFmiXzdEx7tdFvxZrS8DXqAwndXrA2C1o5/vvB9K8i68QH2Ewh29kC00nDEodVbE4 FGz+TV/F2NmCZueArvI+bsTRWDzQUzQvURwbYUXojZlDeJ4qb/uL2WLucfVPg8olqf 7s78U0dC7qDEidr4Hr1Xv4cO3CpxgpquMVzYVT1tTg9xPdewRFVqA7SLvfGnntJe5P rJDK7r5NSwVCzs4BrJ/5g8Wujp/7ggImfhB9jhhSY2N+Gxs07I1C/bCj5G5MBtTdAC 4mFINDf7SE5/w== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:07 -0400 Subject: [PATCH v5 3/9] fs: add percpu counters for significant multigrain timestamp events Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-3-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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=3923; i=jlayton@kernel.org; h=from:subject:message-id; bh=V0Y36Pam00rCiMQb26squSrDlnu7zkSekBYQGaNEp4g=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70krkIlkGBeCvXUTXPhRsNRgPGJ/7YIxm4VL oKt1D2isCCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JAAKCRAADmhBGVaC FW9aEACXcSFuqDDqkal+wDTNWITDuTTUB2w8mpenTaC/RQ3UZtBsS3UcX1Cx8QGaA/9P1j70Kpc b24dZI2nx8fs3w6Tdw+tosbB/bBOkwvgj6FdMTijoam8dSosicCguBmMSx5afItFNUeokv4BpZq fYTF7BCzFykIsuYa8XzhyDtFt5TpzJtbHjrFMhpCioS62H8q+jReo87cZThXZkAagQYFnFb7G2X yNacNVvoBPllyhx9PA0PdCv3+A5HDmtWKzFH/w+doHLJb3Umabh9NkkQNvf93F5jKFrpMD9jNxa odgFtZ7FVa08ZF5AoVNUUa7/TwwAYlsvMJt7eZsthrL2N5/zth9xDVzCJd1qVvgwrAjfKUzo2Co yKM5XS+ZmsTnpi1u6TesAh1lvQk+L3uX01nCXJEtyovW1FvVRTPBgFNvviObAKTj/cyd2ZHJno0 iaC79matLqywBRRBk7lkHD48raPWyTxIniS3Oo8dAzxF+sRZeMZFkMwgnuLXyJk/oghLI0NqlUf dXAA5OHTlY0zGAZWoVLrcnPu2NXMDt9074Qvn7BcbYsOs8KVGY9Wm3XyT+IX0c9FQX1O6bWT/J3 oTWjUmrPm+su1GqxnnelBFzr1W79r+m/y4xgRiiD9eJLqFBEx4O5EoSFC+o6wdeplizkl0ovYh/ /RbyRLwcUU9VYrw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Four percpu counters for counting various stats around mgtimes, and a new debugfs file for displaying them: - number of attempted ctime updates - number of successful i_ctime_nsec swaps - number of fine-grained timestamp fetches - number of floor value swaps Signed-off-by: Jeff Layton --- fs/inode.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 81b45e0a95a6..011148c82901 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -70,6 +72,11 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); */ static __cacheline_aligned_in_smp atomic64_t ctime_floor; +static struct percpu_counter mg_ctime_updates; +static struct percpu_counter mg_floor_swaps; +static struct percpu_counter mg_ctime_swaps; +static struct percpu_counter mg_fine_stamps; + /* * Empty aops. Can be used for the cases where the user does not * define any of the address_space operations. @@ -2654,6 +2661,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* Get a fine-grained time */ fine = ktime_get(); + percpu_counter_inc(&mg_fine_stamps); /* * If the cmpxchg works, we take the new floor value. If @@ -2662,11 +2670,14 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) * as good, so keep it. */ old = floor; - if (!atomic64_try_cmpxchg(&ctime_floor, &old, fine)) + if (atomic64_try_cmpxchg(&ctime_floor, &old, fine)) + percpu_counter_inc(&mg_floor_swaps); + else fine = old; now = ktime_mono_to_real(fine); } } + percpu_counter_inc(&mg_ctime_updates); now_ts = timestamp_truncate(ktime_to_timespec64(now), inode); cur = cns; retry: @@ -2675,6 +2686,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* If swap occurred, then we're (mostly) done */ inode->i_ctime_sec = now_ts.tv_sec; trace_ctime_ns_xchg(inode, cns, now_ts.tv_nsec, cur); + percpu_counter_inc(&mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED? @@ -2744,3 +2756,49 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap, return mode & ~S_ISGID; } EXPORT_SYMBOL(mode_strip_sgid); + +static int mgts_show(struct seq_file *s, void *p) +{ + u64 ctime_updates = percpu_counter_sum(&mg_ctime_updates); + u64 ctime_swaps = percpu_counter_sum(&mg_ctime_swaps); + u64 fine_stamps = percpu_counter_sum(&mg_fine_stamps); + u64 floor_swaps = percpu_counter_sum(&mg_floor_swaps); + + seq_printf(s, "%llu %llu %llu %llu\n", + ctime_updates, ctime_swaps, fine_stamps, floor_swaps); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + int ret = percpu_counter_init(&mg_ctime_updates, 0, GFP_KERNEL); + + if (ret) + return ret; + + ret = percpu_counter_init(&mg_floor_swaps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_ctime_updates); + return ret; + } + + ret = percpu_counter_init(&mg_ctime_swaps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_floor_swaps); + percpu_counter_destroy(&mg_ctime_updates); + return ret; + } + + ret = percpu_counter_init(&mg_fine_stamps, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_floor_swaps); + percpu_counter_destroy(&mg_ctime_updates); + percpu_counter_destroy(&mg_ctime_swaps); + return ret; + } + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init); From patchwork Thu Jul 11 11:08:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730379 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 7017815E5CA; Thu, 11 Jul 2024 11:08:37 +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=1720696117; cv=none; b=jkgKt+jWCEYkoPKzikvN/j2rprYjR/FkC7sH411hdjrfteeTsHckJzCDr4v1LVi19s6FlcnAgHqkMcMX6WBk8zX3OhXJS7cGMy8gtzp9T3iqlCbyLcTj6C4Nu0spWTDXLNT5eDiF2KSOcpIaOpZjjb191B+/m6zFl2wxPEqxFgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696117; c=relaxed/simple; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HeBmJFXiiBnUnyuinXhPNwFX7jtp4Wyw1lQOO5dCBo0sllRBDNSd3DjvJn0wXbwu8pYjvEKsgS58jTg32Dmweyni0uTFrbr93CZfx67PzhDVmQaPBldf/uJolg9sEnIBEAJZKFgNh8ZAPA8MwSNsUxtGdBtNh69Y+B2xL8OxoQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aM6rnkQn; 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="aM6rnkQn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ED33C4AF0F; Thu, 11 Jul 2024 11:08:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696117; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aM6rnkQnft67EwdDPveBEC+aLnbaz9Iw/J9cEyYCG3WskFlIH9k0egFU0+Qi2Q05c PGTgq5xVMimnrOH/NEwwdPJJxHGQC59lahoqxdR1589/Od69pfsq/S4P9rCm6EDfnE CCbH8QPfqjRO2bzt1m/KEINTRYYAeM41mPxo/nmz0cf7H3iakPlLS6s8HITwbeYPU+ i2/lDosNupJCDwHLlMu9LzEE4CucQJZFqhDTVII8U+QLk+uhFR97875JWbKdeb8kEY m6RUPbotcrmnFL7PG2S+dR12jKaQ79i/hUeM6l9cFRvMyW7Ub2xHxlN/HxyaaoQOIU tNrQX0xPxYWJw== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:08 -0400 Subject: [PATCH v5 4/9] fs: have setattr_copy handle multigrain timestamps appropriately Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-4-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70l0tB8wkk1mE/fQzmfxmASsaLYnQ6xULsvM medg6N9UiyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JQAKCRAADmhBGVaC FRj/D/9/qFMGv96YIkAUDVx329NA3lwGZlqp79bN1JG78zGjqY7RX8Uv8c805I25dhpqy2+jfBk VnWd2HCtg1ShenHgPEfnBAsQNjiSUqeF1uIuEVVrTwFaq8AsGY8LTu0QVyeuGImLKtdQomtuVwt FSmNefB0eXDRt6rmOFfnflJoXglp10hyeikatMaHGEr4ASXHDObg50snibOl81qye5cNJh6LbWT UZSgieB+TtqZzZfxAqwNVBRXLrT8QjDcSyfNuJoiB16Jnejn5qaFVEiGGqomR3//RmFSBozZ16y 1HwtgYp+Wn/io/r+6kKUrUeYHURFsR2sVu7s/XBzTb6gJ3yMjd8YTaCSg8Oy+yKNh32pf39Lhmh arf0zK8/W8lt2iOWSuLYJ2//NzoH8u/p12GqCm2dhWvmIWg1CD7YqW3cDGiWc8bltkudb+doVt7 JnP52FRHLAy8v3Sbp5QD9WLr/4lBVDEaE+ulNhzfxNjI6XIaMRQLWY83t1qsaNRRd9+l/QdIh4D w8GSkDpmq9M+iIPOmGLF2GndPggmO3X5p84sFpQHkNa9P8Nc+DBt0RnoIS+1FTm4LfAs3VrB9Se XHTcE4rfgHM0uGMDzvP3iybkgvcTipYHi9n9zPYC1UflB4CkmguObxvjJKWVAOuSCGxvMhtPjBt g4r/yhDL2VECz9A== 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 Reviewed-by: Darrick J. Wong --- 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 Thu Jul 11 11:08:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730380 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 8DBF416D4E9; Thu, 11 Jul 2024 11:08:40 +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=1720696120; cv=none; b=pxEk/S08OmaDlDX7YEAgoJdkJFa1adJj7uDc52DTgz4lUQJVDVwbZj6IZwnMZ5rCf8gDY0FPcn/qGjuF8/KRURCc3s4AyoTdtecrNJBrg2VDP7heEotSAT3hPdl6IDUXk12WVuuP9sPvaJlZ5agqvZPL9cB4fWphpWsDdy48W3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696120; c=relaxed/simple; bh=pW/jFkAPiF/HbV8e5Z5baq9Y5PvUD3bzN6ubPEHLIXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mB7MLcd3/ZH0H9wbZPajIOPkwg7KMGu/YgOo58w320/QmDCFCOGYHrGV+O02X7vP3YZWC4YufYlGtZ9QiExgCRKD79kjTzOreKM1BsARKGh/SNCG/SNVWjqmYpGiuuqgdmSR1uyo/3BwoKVcAeSwho+/fMYiHD0LMT8B42SVHBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WCzTZU0J; 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="WCzTZU0J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49D2CC4AF19; Thu, 11 Jul 2024 11:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696120; bh=pW/jFkAPiF/HbV8e5Z5baq9Y5PvUD3bzN6ubPEHLIXQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WCzTZU0Jr3v43eG8Kx5I8d4s5hM4Nl+4vwkWWwhE05eXLo7V1b4+GWNCE/DgQpjrC I4wY2fE1b8a9AzJf6PqRGaVfDxSQpO6S3ESRLeYAxDf4sN3ZcBDuErjicZUkW1FKoY M4c//kk3Wv8DChNgGR1TK/cPTm4pLi0RY/GC28H1rN03MPSHbtbTWmshnlF/2ojlLH rYQX9W079Lr36VIK9vZSc31GuUnOLeQo/eC1jCmnLGOSp5kNr1x7yNIFj1fOPSkcq6 Z4fG0FH8w9I2wetEiPhdXL5lmwxvUNZCS8wfBrR8OE4yw4GerUFNinTLpSfH65X8Oa 1EeUzRbEQKY8w== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:09 -0400 Subject: [PATCH v5 5/9] Documentation: add a new file documenting multigrain timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-5-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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=pW/jFkAPiF/HbV8e5Z5baq9Y5PvUD3bzN6ubPEHLIXQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70lBBUxl022ofr76yZVy6+CpmCaiGsVxhD3/ T3eOiMHVuuJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JQAKCRAADmhBGVaC FWpmD/9kRQrNGkdVPNBW8W7BmKOZt1X+58Y3KY4xzbfBqyo3Eg/XG6dQT717nBirvgi8SfDwtIO JW1PZ6ynlRUujLXq/frAtLhMkEZfbgiyqHQnwRnpwL7utKuPHgze9QZBYbEfp9T9AzxH0qOpcEN J8Suy3DPo+btdubYZPs5rkpxRXyI0SnmsTDoYU/JmIFvUeRguPCDNMGNHRDx9uOt/z0wcOUti1p e8g+jaKiQYw+NnOx24ynuurPOmfg97ad6Z1w7YkiVWSuvnSoLhssKAGQcdKzllDCDpJjwCHWvjQ voU3krCPd+4HXIxC+/pUvFcYTDRYODr1DY96YL4P0whozRIxX4OsSmWKYofSbPVyZww1jYja+Wj HgRGVktAXTXmlXCSb34KeQ7gpBiOTl+ggwqidK86S5ubl8bm3bQwqC/rYjxxRU5OpzjBtQphNeJ Rvqb+vtV9V94Fu1fEaMD5HgGvywWWhN3+VmQqRMsExvrwAlfZc+/AHeNvP1gQJf3JpFR5KirITv NMkZR/IhO1xaXfNoD3JyqkoT0+VE+PrnNsdNI5O7o6ahm2BozM9GBqQTlCA4NR6laYYmy9teQT7 hWgSpi5wdzG60pn4z5+cqXs3cEZu34bW3K/UDzxjHeqeHe04KHdAbmZ2Ykz1oJPd91MfaB3E9WD E+Lb3+lWAbLCPsg== 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..5cefc204ecec --- /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 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 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. + +Multigrain Timestamps +===================== +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, 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 Thu Jul 11 11:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730381 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 45A4816DC30; Thu, 11 Jul 2024 11:08:43 +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=1720696123; cv=none; b=YjCOr/jvGFE+iGHtOPRDLf2ZCTncLgOgLCT2A6tEb5Z5benuOCTrIM0wyPaL4uneJYIbrMZfnyvT03hJlCH3W3ROItyRy7Uc0lYPydtQs5sY1GKzS/g3yQudv1KeJeBLSj13qe9C5XMUUJE8dnZE8XoPUuN6lNPSvr8IcZTr4Q0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696123; c=relaxed/simple; bh=fHx/mgJgehSKKeWi0EcYG4swNcOzJbq5fDt162sYPoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NI7a+L+PANBfeGHfE30Sh/bfjDL901v51kjyJGad3z6/yXLs5jOR9AebhrxAsJSjUXjd6o34ONZq3x3yP84vxFtDOtXtcrcLCYnY3wIrarsKr2TvkmDzdrOOU5W/8t6YQmem0rPz6g1qxnXjPfEGYXASpCPnW7wcqtxalg3VNgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OfcZxRI1; 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="OfcZxRI1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57940C4AF0A; Thu, 11 Jul 2024 11:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696123; bh=fHx/mgJgehSKKeWi0EcYG4swNcOzJbq5fDt162sYPoU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OfcZxRI1S61fYHl8qHzhI3AAeoHxhQ+TZqus8p3/jlXgd23s/5AvLeA/iHAMNu9dX 2Afrdk77c8F5kg5T9PUJKYDVh1AC8OyNV7YXK7vTTl447pU3OZ+thjT7wqgaoeLjAw xpoVoTBTgLt1nS8wwbbLjV4oNQY/TD3/gbbsmy21zkRUx8bSsOtRM/5LZiUaNlUMG6 3vHwisH4gHRWKGKfnSQa0bdXp8/EqBarQqYs0ZJTZQNsaUS40mn//uGzDipM8xMY/l Bbt4qp9y8ZRuuOPEZh4mPeb5azSLL0xI5JxQyZH5FMsxhe/cQd4MvO/WnvCVj0YeeW pleRtchZqlusA== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:10 -0400 Subject: [PATCH v5 6/9] xfs: switch to multigrain timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-6-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70lX4OEuE/qxmSz5H5yszC0h3kRUmqoeXVzO 9+ohuiXnomJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JQAKCRAADmhBGVaC FVKwD/4nUE2xnHwjBoFzgjJ5fD/kv/mS9yEN5YGF/355Lk7Ayx+lsUACghZYoPm2AU13LRQAg9Y axQhahdEmYPMVxmId6ETZe/uGV5uA55R1M5A8rVpkkElbzAXnB87ASBKfjkuIFNANnv4ZJcGklC 9QUuH02p7d7rBLpfUBLMG3H0ikQu5DgnEqba0KSBKJ8RvQrY7PSz4GRexOb6pwC7tEA3uSl6HPA bCa0E7/lcuiduqPeM89Q3fnU0cD39CzvaX9DbfD0Bz9JLc07PV6MR1g+9f4Gz/q0XaRj59OuCtv iS8Uu4MFDT4p/B6FP2I6As1Jr2SOBIf9RUqsl0fc3Fow45eZ346ALIuwXjmy2YAZbsdTy5g/kvn Kgz1YkcOU6ZTaN8edZD6GrgFT9+h9L7ewVPlFGCnMMVC4TKZBvvAh2g/d9Dw8ZBs0UiDxtU4OmO uAEzSy9lf3IRN2K+MgipP0l89f6yft5sdpnCHAimcdGuZN/AF7vRmEoW2+rCNgN5hZZ0KLJbtWq dsBKD7sbQKF7fMWaFdVgLTC8JtNAg+IIWXutwkOM1w92c69GW5nXNpbmZWa1wSr9u7fG8bu9ULp hI2I2Iz+KyK20ocK4rZgnBgII4Xa/hM/6tDuJrv/wohXYkTwD/uySqf+M8sepMhqgIhyFoczp4W X6W7CoD4lWXPXlw== 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 Thu Jul 11 11:08:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730382 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 9296316E869; Thu, 11 Jul 2024 11:08:46 +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=1720696126; cv=none; b=WCOOoWLkBPgKiRl0LG4ZhB1UNr99fBQu5zMd7FZUVlT1e4413RItn14xMgMyjIDTWwUa5lyLeUy93tT2GsAbQtPDlfRMYVR2uCZWCuz2PxozaMZWFVwgIwh5TB1T/r0fjI2KOW1FxCxF3LArQ2pIqXH7xTr2t5PKRU7lFlVWdTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696126; 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=Af2b2teXqvSrDMnWtB/EXDzF553F8ippFSG8YgRBmq2fC7DeHfC2Yp48v5nO6mIBGvoG6I+GmsEgmtARZsEe7DEMft3ScnlXW3KIFee3dXUtNLG66wVz17KwnySOHW+JcHO8jwEi4n7HoiVbONmUw2uPsSZU76PKUGBz/ucnm0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p3RoEDci; 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="p3RoEDci" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61540C4AF19; Thu, 11 Jul 2024 11:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696126; bh=aIxGR7na/Qdc3ayjXzlWsssXh9j6/eXvzZW4Lz1mI/Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=p3RoEDciD+DzxXOQ4bkKEi/2XUp+heLaAS7X8Rk2SnsiE8e8X+bNY6DnQrWWaPCg8 vDT2+s2Xj2d05hRPt9U1h20xOMTqaC4iyDa9XL3ktuDcG4PfpGXLsckn6gM9Pz76vr 7tmNuLiIYwtH2KSw5EBteQInK93cspWsfKPf2CsBJWRSYtQGXc17pRkEFbbJ4XVyEj g0gBE7VDIKgTumvWLyAQHqK21u+zMeksCE0+4ZxsZF/zS0xNny2zd5DELfTBxS0IE0 3qJKTSkKQD3mdSNnbQxQ856Qipa1ntOZjZuwZcThGvzVEeTFW+SsAfTzXBGS0Nhn/R q+UiX+o4cfhtg== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:11 -0400 Subject: [PATCH v5 7/9] ext4: switch to multigrain timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-7-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70lLGwtVIH3fc84IqxhCflp0IWdNwkGUMG2A KdkQdY1RniJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JQAKCRAADmhBGVaC FS6uD/4iWWotu9rZZKKFv50AvekdwtGDtGPWRiHDnyK+Z4WsUIEm7Je//sOMkTYveYEOhKTwiw2 JKNOdXyMaZppvgpDkeNa4cv9LhdxnQCV1yGdeh/RorjGmeNAekQF6FEuvXnYZDjU/b6P07Jhbsf BD3rSONfp1FDpMNZryrsO40nWnTF3Jk4xpZ23j/5uVlj6otGJOQJTHR233i+gb7LSlKmYffo2kQ ynpKKfUFhGoIIYspBFefTrK3pEVBGuwY+mlpteZbQofFI5+pYXqiLj2PAgZMnRAja5y9Xww1E52 0gx8Cysjr06dcF1/CMrXF3hVDB+/NQzXV4a6EJDcmWL2ap13OLgV5LYfhpiSM0dLZDmSNK6+Vxo I1MJVA9Rnk3W49gq/rZD48IRm2M6ctw+raFZic5nKFC/qKSrNKp6znW9JPsQLbclpwn5s3BS0CU kTBWse7xWx83BQ4pbJl2np9CXPeprNQqup22HN/p5+jTqcaos8t9mN4bXfdA4xhnTMGcOfCY8QZ iGnLSJ7FaKQex+xK/q2E/1K2rvzPtmDJKFiVvSRgIUmpQ3b2/4v23Z671/UGCpCgT1MtYzzCYvU FbsAT67Wp8UNzXVatlzSKXwQvEDyRbXasYy1gEniN6W7uExCqQf/k0sA0ToW/ptxlQfb/z/EFd0 /NYocsP6uJA2FgQ== 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 Thu Jul 11 11:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730383 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 AAE0F16EB55; Thu, 11 Jul 2024 11:08:49 +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=1720696129; cv=none; b=ALV7g7f6j8XqQXUKW7ocdZ8A0MkBpLEVKALxwWbsz6hwebYaKj+DyHMtMB+QViwfZMe5NU1DR7KzPclxkrh9ODlMlLycj4U0tdntc3KIoDgRT8X8lHlSsVqIF2evKbLdJ5gs0UmeXynFTsoiGVGK48gBwH2j4Nm7dReZ+qaQQWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696129; c=relaxed/simple; bh=xTk9IFiZeoZdqPbR7bcsVc6tPLRLkOIJYDVl81q/MME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FxRFtMk8ed1/0xAXL/clLth7/xwQ7ONgzvLeOK/5Uv+ehpLJSyI/F+vD9f/h0BGLOYC2idNXlQnYvmHAoYL1vu2fvHiz72xWbAVJr5pbAInDNCMydfQl0cUKfA7R1OgbddwOaOhXJY6rZRUY8hl/BQvlRdjhdBmIaZ1LnDZ3vmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PIYSBlDz; 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="PIYSBlDz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 690D2C4AF0A; Thu, 11 Jul 2024 11:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696129; bh=xTk9IFiZeoZdqPbR7bcsVc6tPLRLkOIJYDVl81q/MME=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PIYSBlDzi3izlhhsIih/pyOcBS1LMKHlSVybt8iwDKMCT/KuB+uwW5ZH/4UDnvHt2 iQmqRu9FPZfscB4x1O8ANDwsFpStacAQn1MZcv3WRPTRtaX73PHMYQyQFGyYQGHiSD uVU0KS+6pKts00oAL3Oad3Sdrxu58b4u/W8mOZNypM4ig/boWOPsrXhK79SRxP+ror Vi0p96D0J6Xep6j+EXS9SFWrtblFyvbZV6WHVx8Rvyoiqw9M0WX/4w55T4qbJ/Ghkc ufKRaU4Ci/y52xxGlR2i1JJsMXG0lQDkq+SsEElni0wujfCUS4LA2B8yXhSG4Ifr2+ 70sfbdd2Cqs1Q== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:12 -0400 Subject: [PATCH v5 8/9] btrfs: convert to multigrain timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-8-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70lhNewWHh61CO1bt11704SMJNMRrO6Etw2W 30QskLPOVmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JQAKCRAADmhBGVaC FWr4D/9/BKDDLNpeTxoxJKR9NnOB0Mj4UHHvSvM5FydPU9wm1TtZNljZG5FdmhRnlVA/EU3EXzh jf/KKNDLSi/SkxpUOyQcE/LCWROpGNQa8YBQVBIrykpJkAuUaTSB/x3HeDxG1iNhLnyZOP6wmv7 CKV77Ru+Ii2wwDEoVcJ5lK/s9p0eidSnOxpZhJLK+yjjY5n64i+NVh/Is5z0+bCWVJC/Wkm1RH+ tNa1TaLjw+meKTwcACY4E5sbvvFtJJAboc11Ga/shYG8MEikSL+PEnLXpy5qovDMn0a+o2f0Ym7 k64mPNcEDEbQA+pq0VFMER0k2zzjogtxHfVDP8CPHs44giEoqX+5QRMSB4qlvElDZJeYfOfNkCL h6CgItnEYUOg7obynfz1AKOmd5WeuEpHoH32KDvJGcr8u+wNqFW2bjON7JpfxXdiNQg67aOX3i7 cqM2H4I2b+Owt1/0khoFpTec36REaIYLbwYzuJl9I7knlouHgymKaeJNYKdKPQUrPgBa6h9PzRd r8gQtiz/H1OwqeSyKf7WhIqGVAa/TI7+AkAH4tyAEzG3AUdzNctz4o5MbhhGkRzOGJSTa3wkQiH iZ1RyliJcivTulNvI+EYYJoflW+3qIliMy3wtk5seaDzPMrlZJO7+uQTJBw7YAlp1Y8S9F7YbXU acGupOaNKLqwSnw== 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 Thu Jul 11 11:08:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13730384 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 AC51116EC13; Thu, 11 Jul 2024 11:08:52 +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=1720696132; cv=none; b=WiDNZQPMKCPB4neqpz6fWrlCsjNS2aqsmREd5Wy8GSiiEU6j+9sXOdfCgdDSzl75LL5BOfoGpTAjrSyGQVBHrlN33RTGWMpdcHpUBjM02s9U4FDzLcmlYeRdwyKOdzdKm0J2jUtiusnRXPZkgsfkvElq0J+5MH8umi85UMHiY+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720696132; c=relaxed/simple; bh=OTapqLUtOhOklsMt0JtGipDN7/MAEwqOBUQ+KnQBUIw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rGTIkZbdQXaTOpzkA+/lkrP89EoQlmxGB4SgocJhEIrIaFf9Rn2N3I1mDxyneWnS5zsofDjMwkXCEnXgEIDexDeI0SfpLnhsRV2wkKax73b7owcBbM4S9Ego08pcTpELRo9t3bvz8ahFBBaaZJbnzs+PNCFMoHfdvupxxXDJEdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kZWlnKSt; 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="kZWlnKSt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72C94C4AF0D; Thu, 11 Jul 2024 11:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720696132; bh=OTapqLUtOhOklsMt0JtGipDN7/MAEwqOBUQ+KnQBUIw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kZWlnKStTWj/I08Tl3NCNpksnVXMXWM9yXlhktX3p2YwFtK1kZcembFkaADm1ByML 2hqUuLfknzwwRWW8jz0tWvJZnTLio+NcpivJ7DKtiZzjradOKuHmkN/rEMucFiJoVD qrqSIY5CLhJuV+gEMUuHR4ZYrg39tcU+yG36QOb53fR2jfy+FtZv4VnGEX/i9um87T Hct1UhKTZePkdLV9+ldCeBWNs80da+df5Om6mWiOakKtFDt83ux9e+hcKRLH/jc+dO wb08v3rnt5ZOUgzIkWiy7lcUXUxtmHZ5Xyy9dCUoLkfwj8sgDCq5Us7mAzhTwXAyWR bhpic4mjWPRMQ== From: Jeff Layton Date: Thu, 11 Jul 2024 07:08:13 -0400 Subject: [PATCH v5 9/9] tmpfs: add support for multigrain timestamps Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-mgtime-v5-9-37bb5b465feb@kernel.org> References: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> In-Reply-To: <20240711-mgtime-v5-0-37bb5b465feb@kernel.org> To: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Jonathan Corbet Cc: Dave Chinner , Andi Kleen , Christoph Hellwig , Uros Bizjak , Kent Overstreet , Arnd Bergmann , Randy Dunlap , 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=OTapqLUtOhOklsMt0JtGipDN7/MAEwqOBUQ+KnQBUIw=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmj70l7ZnQeMlGHhjvFghMhoPkLSm0RtSQvRi/6 iYpytjkGrGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZo+9JQAKCRAADmhBGVaC FZNfEADRHxrrM5sremg5UaJseVwuJj4hBX4wOg9PWhSGsvDhBSLnesYgeOMU7tABwVt/Z/8KcII E7FyeB7UeKZrk8KHbfDLrkFr4s2S/TsKPL0w538UEz8RtlzRM4BSv05QfJBJoRKpw3uBgJQA2St owelXYZBb5lXQeYVY3Xjg6yE03rw7iXm7Wu6v+u5+KVwkX9L5Cybg1j5UmqyA7WAs0lIqln/R+p wRjdQjL+3DK8MeqWiReYlmE9bBRLXa6DAseu3M4zC6xlaNGriEHoTWjFGbtyVwrPBailuJjRHrY wlIbkJBkkU72wY8rV4URo52g0iKX5b26BzHIzseEAqFJP6QHZGBVS6xFGsT/V4kw6EtPicdbsYN 7FlnO1dz1NWgv+TY02YEv5Gwd1Qxi3FeOHpJxt9o+5H5ASHjBGqlsdfjbp/hykirLGwFeBwQjAr vrz+47ffKte5ROyhV/V2djA/crlVqZq8xMxybO3ewVl5FymC+c4VbtWkTS60XsbXyFieFVR6Akb lnJcrsgvNEjeJoI01ocrq89wTYm9uYLYl6Z4W/Ffcp9WVS+BDgNe2Qk0r7JXbZ/aKZ8Jjm96txk +IdIydQLrUXuYBlPjpWI3oZp1xjrFddm/vOkQfR9dOD4JKH/hotMg3sRlNQzAo7lHreH0cGxP+Y TpESK6T5rsq7iwQ== 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 7f2b609945a5..75a9a73a769f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4660,7 +4660,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)