From patchwork Mon Jul 15 12:48:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733478 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 272CB18D4B7; Mon, 15 Jul 2024 12:49:13 +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=1721047754; cv=none; b=kISDUAHMRpArYMawgIshZ11XhlEf49/TtMARQTttE8VLU8baHWRr2XmvZYW1qcKXc75y5jGQ4GFuDndgOevPTkCD0LT2QdHj0nXNbV1hx+QjLZgwURM/2WfMpmL/OW8z2hMk8JKfF7fIHPljvuPxKj6HuAReeSbP0TB7hHrrvWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047754; c=relaxed/simple; bh=6RYo72I5y5RcRdxKYi2v4wCnQYvk9YGbpl/t75l2w/8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dwCBX2KjueD4bJ5oMTqW2OPNVRjUm41XnvqR3uiXUx5EBvv4NoCpOpiKZG0mFnT5PbqqUqHi3Muo3bMO8HettNUUHttKnmWwKpv4FvokPy09v7dqZuyGRAilD6bbw2skV74KIH0Wf3hMcVgApV7E04NmhxYsQngrML6kuuUAfPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qYCKKiNb; 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="qYCKKiNb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D091CC4AF0C; Mon, 15 Jul 2024 12:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047753; bh=6RYo72I5y5RcRdxKYi2v4wCnQYvk9YGbpl/t75l2w/8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qYCKKiNbmw8qJxTSl91sH55UoflXy7kmg5C3rmJRKKoK6l0iZn6igiowuHxR6GStS vmzK8X3wu7OhtJO8bJS+o6lJGgHolq5NCiwLJasqqD1zV5nR0+Lzu7OF9G89sOtFap gWF3+zBh54bx47eAhtS4G57pLiS61YeHt/PIva3iyL1xVbrCx7MbOT3bEH0AYgBBKl MwYWoBccADAdyQdIVUqsbzXx21EQJvXLysKApGOE51SQmDqGECESGlo0SIYY/GNnHa 9ggtthQPNEQB00R9H+ItDVqQmY+j1ZCPxfxFvC6B+/75+bpzQqfi2a/nyxVdRVL9Sm 8sIqTMf2Btyww== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:52 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-1-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=15508; i=jlayton@kernel.org; h=from:subject:message-id; bh=6RYo72I5y5RcRdxKYi2v4wCnQYvk9YGbpl/t75l2w/8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrCsEsrn1gBjZlojfc55qZiw5ENu0CWwKCap gZvNtjpeKaJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawgAKCRAADmhBGVaC Fc0KD/9e7+cdNJn5WFxvtHizKo7QQt2+iq4QAJKr2bekcs14nlvK0IWVZ2siySQ89SUoGFSBhYg IHQVqFG+nE/yzXGsAdlNJf+/3sdsoaVrIZ1kx48WLZJTfrDdNQFNuzNXCOqvrriJo01TQyjzeuI RRUzr2TBiDhxUvqkr6ufdq+jV/KSBgBtjNOPCI9u+Y6gD5GnqJjb/XOfmN6uORidN6v5nXh8W8G 3j40oqYfZ8ZSdy9aYDWO21IgGuUW3P3XeO+ZaVjpYft1bxzAlX0j8G3W8AmE30guyFNM6Uknjzk WWvoc8EEGR2FiP7x6Al2CWA9yONOD67nVEBUxRjF+x4rnw2JKzJpYDMrFVUqToxpkn8ofLtVB16 Qb/UhvZcr4L86cQvXrWCuUCZo+fjEcS46gZmLG1KG60H6U9c6xymvCTP9a9ADffnCZEoNyhE3d7 KBsFoA/aqsjOQtXSXvCwPylKRZGzsxNaHng5cHvCt19y65OKAkb02jDuD9vlflpZ9Bs3FJCRc9h Ga8hH2z+rmj4nJIlc6CRB2NO4fGVeVuZjFTMq7Q61GOVCGE0Zyog6IGPWLkMLaSwjheNbm1TD01 5AbycQVeYPqR41uV7Yz70qlvOgDCuhPi194oyOtlMsBRUKv3AxUMe5sUoppi6eVS1nX2NXKhVvo 3FH6iYl14AX9umg== 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 atomic64_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). Reviewed-by: Darrick J. Wong Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/inode.c | 176 +++++++++++++++++++++++++++++++++++++++++++++-------- fs/stat.c | 36 ++++++++++- include/linux/fs.h | 34 ++++++++--- 3 files changed, 209 insertions(+), 37 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index f356fe2ec2b6..417acbeabef3 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,15 @@ void inode_nohighmem(struct inode *inode) } EXPORT_SYMBOL(inode_nohighmem); +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) +{ + set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_nsec; + return ts; +} +EXPORT_SYMBOL(inode_set_ctime_to_ts); + /** * timestamp_truncate - Truncate timespec to a granularity * @t: Timespec @@ -2538,38 +2607,91 @@ 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); + + /* 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(); - inode_set_ctime_to_ts(inode, now); - return now; + /* + * 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; + + /* No need to cmpxchg if it's exactly the same */ + if (cns == now_ts.tv_nsec && inode->i_ctime_sec == now_ts.tv_sec) + goto out; +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 Mon Jul 15 12:48:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733479 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 DC72318C330; Mon, 15 Jul 2024 12:49:16 +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=1721047757; cv=none; b=INEQ0im4puKQPGAJBJOnxsvlpuhvKEMMncx+wBnRkOp35HFfCZCWGP+HOzYMxOqdsSNl7Q/cj4oEkqxK7hBVhH996gA+tLo5aEdKOcR6FEDp8C/XErUJT0wjXRUWraWFqlf9lt41ctiZPJDS90IpCu+29CN1Eej8qGRTCcX15hU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047757; c=relaxed/simple; bh=JF/UPK3ugqCOBOaDB3oltr4AnbnZLO/O9/Xo7V+dF+g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uf81bVkaY97kJ+bCbqG2pdFvmT2T0m2Y6bN+scQK8CFYeO12zFifPXzPluofCJBpUfQeq/X3ttyHO9+0r3Vtn5C5RwsEcMPY0bQHQm2HIRZnTeGL1WnBvOywIuez3EyjSq3er7FZDQEJD2/+1H0koyumRrnXEIQhJetPJqlPyYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ur9LdRyA; 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="Ur9LdRyA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA9A6C4AF12; Mon, 15 Jul 2024 12:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047756; bh=JF/UPK3ugqCOBOaDB3oltr4AnbnZLO/O9/Xo7V+dF+g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ur9LdRyAvrQagDyjIWlEueNxPt9nz4/83/B6DD+X9AKi2i4/a5sMfqUVlz8RbBvcE Px7Gaj/Lm7MtFRRybgKxCT/6t6an+0CinXqzM5r/4Ddt/uWMtaXBjx19DXKcLlBPLZ Y2y1mYNlM6rQHHBhxXvFe527889tYnjdqlLtjyr1yUOS2DxQyXXi2+uD6DHbXOhX2b E1Ga4zCQj4fJNeyw/q+Zos3j3cyle2JETp8CEVD39WIJUhBxNHi+wy4R9D5GQyQC+O O4jzYdl07IPgm0A0EyuPEG2KANH9JzsGAuoOq9gQukqfxLMRVWW4uUrIcAHL1bjAlY KQC636ATizJXg== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:53 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-2-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=5888; i=jlayton@kernel.org; h=from:subject:message-id; bh=JF/UPK3ugqCOBOaDB3oltr4AnbnZLO/O9/Xo7V+dF+g=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrCSgUIIsCgXmn1E3IInVm5DrnlaLkzFW1Jw Q+FZkqs1YuJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawgAKCRAADmhBGVaC FeayD/4qqJuWDW34Qj9rLUQz1zDsDJLwxRBQatCJZuZzyADr4yvwLceGX6w1+FUvXEa67majQhJ e7oBwc+4hdgMiY3uolxhzopsEolZMhJ0iQqVJknfBn9+457EHEsVYbUv3lbZt2FUI0+z3F1CjZe tlBSFJ5YtE6qYdGbVLfp7t+6h9WeNhRCndTXKSM+Rhq62e+ECQyEVvkFCGD7Z2yWnn7X0TFZIFo F6t/iZwxyG4d7FNQFSXRBnHBX94VW4L5SdosG9r4N4o8OCTKSH0cEwAv/RRj6Bl6AsRTAoC486f 5JooGyoWoUxLj4BTmVYknjinuTvdD8CNaua5BvXftYb6NZfx8wM4vjlxsosIH2ag4AvP4B+loSY fBhiNsjn6oFZ9R/y3yiLqXD4hKHs0B6TSYjPZUKOnF+IOIdt7wnaJJPoUpJ5XcR7cvAsvg35Q5G q4YzxTeFXs4B37EfoEHKXJNRP53TC7Exzv1Gkg3z9dV5iqep1Yr6tCCcXYz4qRmYPCQegvTkSDe rrQB5mVJ/qWQ/uhYcF+1tDw6JhZcVIDgS9Ux4kYW2sYVA0znjt4RwDhTvZB7HOhaDDU/+u232Sy 5UDpuVg1mOk5Sp9DpgFxvvqL+Ft0vVIgua2aXNn8v5w7PfPa476R4sLaUcfUXlMt0QCw/jFVIOV D1//ICt1f739Nfg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add some tracepoints around various multigrain timestamp events. Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara --- fs/inode.c | 9 ++- fs/stat.c | 3 + include/trace/events/timestamp.h | 124 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 417acbeabef3..869994285e87 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,9 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" /* @@ -2569,6 +2572,7 @@ EXPORT_SYMBOL(inode_nohighmem); struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) { + trace_inode_set_ctime_to_ts(inode, &ts); set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); inode->i_ctime_sec = ts.tv_sec; inode->i_ctime_nsec = ts.tv_nsec; @@ -2668,13 +2672,16 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) cur = cns; /* No need to cmpxchg if it's exactly the same */ - if (cns == now_ts.tv_nsec && inode->i_ctime_sec == now_ts.tv_sec) + if (cns == now_ts.tv_nsec && inode->i_ctime_sec == now_ts.tv_sec) { + trace_ctime_xchg_skip(inode, &now_ts); goto out; + } 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; + 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..c9e5ec930054 --- /dev/null +++ b/include/trace/events/timestamp.h @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM timestamp + +#if !defined(_TRACE_TIMESTAMP_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_TIMESTAMP_H + +#include +#include + +#define CTIME_QUERIED_FLAGS \ + { I_CTIME_QUERIED, "Q" } + +DECLARE_EVENT_CLASS(ctime, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + + TP_ARGS(inode, ctime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ctime_s) + __field(u32, ctime_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->ctime_s = ctime->tv_sec; + __entry->ctime_ns = ctime->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld:%u ctime=%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->ctime_s, __entry->ctime_ns + ) +); + +DEFINE_EVENT(ctime, inode_set_ctime_to_ts, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + TP_ARGS(inode, ctime)); + +DEFINE_EVENT(ctime, ctime_xchg_skip, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + TP_ARGS(inode, ctime)); + +TRACE_EVENT(ctime_ns_xchg, + TP_PROTO(struct inode *inode, + u32 old, + u32 new, + u32 cur), + + TP_ARGS(inode, old, new, cur), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(u32, gen) + __field(u32, old) + __field(u32, new) + __field(u32, cur) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->old = old; + __entry->new = new; + __entry->cur = cur; + ), + + TP_printk("ino=%d:%d:%ld:%u old=%u:%s new=%u cur=%u:%s", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->old & ~I_CTIME_QUERIED, + __print_flags(__entry->old & I_CTIME_QUERIED, "|", CTIME_QUERIED_FLAGS), + __entry->new, + __entry->cur & ~I_CTIME_QUERIED, + __print_flags(__entry->cur & I_CTIME_QUERIED, "|", CTIME_QUERIED_FLAGS) + ) +); + +TRACE_EVENT(fill_mg_cmtime, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime, + struct timespec64 *mtime), + + TP_ARGS(inode, ctime, mtime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ctime_s) + __field(time64_t, mtime_s) + __field(u32, ctime_ns) + __field(u32, mtime_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->ctime_s = ctime->tv_sec; + __entry->mtime_s = mtime->tv_sec; + __entry->ctime_ns = ctime->tv_nsec; + __entry->mtime_ns = mtime->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld:%u ctime=%lld.%u mtime=%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->ctime_s, __entry->ctime_ns, + __entry->mtime_s, __entry->mtime_ns + ) +); +#endif /* _TRACE_TIMESTAMP_H */ + +/* This part must be outside protection */ +#include From patchwork Mon Jul 15 12:48:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733480 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 DB44318EA72; Mon, 15 Jul 2024 12:49:19 +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=1721047760; cv=none; b=HaacfFSxRJK+JduoXTv4KcULgzdazvb7Rw0w8qLVwPkayEBffzYib8eWjeGuKKFrJUYr6xmq0bDaYUaH1H7CUr+5ZVaqZ4Fgg3cDiOdljtL/Wa3mLOrdJSm7V+ibb+JzdxW2DQYkS/xMtikIBJ0TWjhG7jp3ZS8BQniAEXuGczU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047760; c=relaxed/simple; bh=HU6vitpuM/kW1drnmaJbobayjjiX3I313g5+a5XkSf4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kDdQBUePusgrAyBTwKtzxfxW4/5YTbC+ggQagAMSD9nIhJwuzNP18eb0Ja9D13tp2k27qfW9pMMsMYoSJcVfPITk1VN/LU7NEa7Up9NLiSdSXhodS8Ds5qx3Wx8uKtQPttPFNIKA7WQII3i+6TbnN85rfGdOx++wAltq3oQ7PEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gTkc25ss; 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="gTkc25ss" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9369C4AF0F; Mon, 15 Jul 2024 12:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047759; bh=HU6vitpuM/kW1drnmaJbobayjjiX3I313g5+a5XkSf4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gTkc25ssg6JIYDP5yx56GycmMYuUfPA/FzBDPYtSausd5bgyrigtG6xODVb8OFUDc W55GGEX8O4LsV/vWIWiJXaEW57ho7kAdFYc7OntI/7DGEEG+UzzuKwUgoTgXmVHr0D nskM2bOoF9umr01Z2oPfDiJh31unMRdMxVeWkCddFmP5YTNa9cufjicwUcxSdODguS x/ocBfBFbu7LbPcwHdrStZ3DkRPrwj281kjkwLf2LxHJWPf+PfUse8dL0zznuS0lL/ BhOIYPIVsO7NG9BM274kgSdWSBGLKQn3Azf6ARWdsZ/uEBb4sVuN+Qrt/08zmgfGyr Zgy/6fN8dnQHA== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:54 -0400 Subject: [PATCH v6 3/9] fs: add percpu counters for significant 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: <20240715-mgtime-v6-3-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=4074; i=jlayton@kernel.org; h=from:subject:message-id; bh=HU6vitpuM/kW1drnmaJbobayjjiX3I313g5+a5XkSf4=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrCYPk7Gycow3R8t8u9VHqvaLk0qL2DGj/tC M6baL/u3SKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawgAKCRAADmhBGVaC FfCpD/wO35AVGJ7f4oBU8BPuQpqmK72PLEFjcoUJMSz/9hbuLYnDFxXNGdedZya7sbm3a82unkI OR0VZkAsVmwdUxJJHMEiHejznHsftKsq6O28bDsrH314esp9WXHHaOIbgT9Yv95jifbccGodejm On3SY90Jyi46TF+2jQMGpUlKJXM+FITar4aDAy9UEpPvArFZJRuAkOLijiyecK06u0PvTGzzBEp /0p/+3JwbXJOSNoVNVWXsClCMRKsoxvuc+dT0G22ktyL1aX9linfibZk8ck1bk0PhCVsi/gIm8Y 3P2pe7OkT3F6o9zDCFAr7F3XxetyoRxK7Fu5jPkE5iOR69hCGbmFXEJoya5GVNicwxqRdrRhdVn QjbFyIuJs1lgklHTHQK0qVdTwziVMashfL9yjxes92pMj6QKJGI3GjBsg4v8Q+BmQW6IftmEbOP zu757yUqHCzSRlHe0y1yf1nSY6erGn/S1Rvj41iulKcFd+96hIVbrKjZh5rF/r2wfJczzwAmsRy b8LgQ5p20q0H4h2GElvxGQAxGZqkU8f/uGDY1NwoCqK1dxcftLZUgbJ9HkPZ+AOnkGwGNTZ+viO +CzeoUQIrSpVhPYFFuzrzRvDqU/1xRLqMBMdqEf0c3dUGuE2xoWnhopq8VpLQuMBJX4RgroiKWP P3pBhVgyKiiwuqw== 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 Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara --- fs/inode.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 869994285e87..fff844345c35 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -80,6 +82,10 @@ EXPORT_SYMBOL(empty_aops); static DEFINE_PER_CPU(unsigned long, nr_inodes); static DEFINE_PER_CPU(unsigned long, nr_unused); +static DEFINE_PER_CPU(unsigned long, mg_ctime_updates); +static DEFINE_PER_CPU(unsigned long, mg_fine_stamps); +static DEFINE_PER_CPU(unsigned long, mg_floor_swaps); +static DEFINE_PER_CPU(unsigned long, mg_ctime_swaps); static struct kmem_cache *inode_cachep __ro_after_init; @@ -101,6 +107,42 @@ static inline long get_nr_inodes_unused(void) return sum < 0 ? 0 : sum; } +static long get_mg_ctime_updates(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_updates, i); + return sum < 0 ? 0 : sum; +} + +static long get_mg_fine_stamps(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_fine_stamps, i); + return sum < 0 ? 0 : sum; +} + +static long get_mg_floor_swaps(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_floor_swaps, i); + return sum < 0 ? 0 : sum; +} + +static long get_mg_ctime_swaps(void) +{ + int i; + long sum = 0; + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_swaps, i); + return sum < 0 ? 0 : sum; +} + long get_nr_dirty_inodes(void) { /* not actually dirty inodes, but a wild approximation */ @@ -2655,6 +2697,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* Get a fine-grained time */ fine = ktime_get(); + this_cpu_inc(mg_fine_stamps); /* * If the cmpxchg works, we take the new floor value. If @@ -2663,11 +2706,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)) + this_cpu_inc(mg_floor_swaps); + else fine = old; now = ktime_mono_to_real(fine); } } + this_cpu_inc(mg_ctime_updates); now_ts = timestamp_truncate(ktime_to_timespec64(now), inode); cur = cns; @@ -2682,6 +2728,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); + this_cpu_inc(mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED? @@ -2751,3 +2798,24 @@ 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) +{ + long ctime_updates = get_mg_ctime_updates(); + long ctime_swaps = get_mg_ctime_swaps(); + long fine_stamps = get_mg_fine_stamps(); + long floor_swaps = get_mg_floor_swaps(); + + seq_printf(s, "%lu %lu %lu %lu\n", + ctime_updates, ctime_swaps, fine_stamps, floor_swaps); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init); From patchwork Mon Jul 15 12:48:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733481 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 CC41518EFDD; Mon, 15 Jul 2024 12:49:22 +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=1721047763; cv=none; b=UHXhb5n4aWw/zvzAWW05MjpQsvbmol901n4ZYO6LFKAihoUuen+vk91nmmBkbI1Z7VtfkLeMTwSbDOxFNX8uzuyRU7YiuavyeDqrdIzFg387EA3E8z5If4kI4Pa68o6mSOqR8k/BRZEOJU1I9jPX3bIYVOyAS2Mc42LZv4sSqpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047763; c=relaxed/simple; bh=QeVccJxIIqw839FMAslwYN0cCtumM5RGorsmI4f3Ba8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ri3tzD4Rl1J4vss6U3Xf/w6X/Pr60GpvRYTa6Ko940NRgY39ZGg1WKCMRP/sJmkBYVR6dIadVjcEvLrttFWyhy4bpycwZtjsa3+hNv8gx98M58ZflOMZ2g0MVbGOIFJpk92tQ+YzctQbgpssvYg94jzEkAf4lFHTbZ3537Kh+ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GiWQXcYj; 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="GiWQXcYj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB26DC4AF0E; Mon, 15 Jul 2024 12:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047762; bh=QeVccJxIIqw839FMAslwYN0cCtumM5RGorsmI4f3Ba8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GiWQXcYj1to6dm4zqB3WZcP047jHZ6ztSMtTi+WxEaaMYw+niVkY9vKzScQredr+L OvHfw134L8C7mHiOMPXDdO0VZiYVW34o6XUZAONLlvhtC4N5fPTgckq8KgS2iO6BmQ zkfHj7wkaflVGgU4Jgpu3lhmTzfasIAtVteUGf9cgKR/Cc05mBM9z5kzj9GCiLb71/ C4bUPXIS6p1E/ZaQx7MUg0mdkuHVcCPzEAFMCE7HxyzaHJK7vKlYy3HmERyREnj/sB egfTLiRvHuyGjPIGvm2Qpzy8c7O4wLLogMgKEJvzvlpBC9CwslWSvDuhzRRJQn/nVG 9/Kipe3dKWfAA== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:55 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-4-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=3502; i=jlayton@kernel.org; h=from:subject:message-id; bh=QeVccJxIIqw839FMAslwYN0cCtumM5RGorsmI4f3Ba8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrCv6y9K94MS/Va6IMTGYStbxE7qbrcFZ0Ck ktMIQhcUj+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawgAKCRAADmhBGVaC FXaTD/4+907j6epNme39/Jvo42T2sVT8Gr4WtDO44maokkPWgfEq/tA5OdSZsLRKdQnyuOtxDZa KCzRZScbuIWev9UWubIT11gAkcf2at6Wu20ez7swsPIwbw8+BHd8+2cjjN1XFbuTEaQ2QMW1Ruo 6MQEsCv+EgExV27/ORkA6sizkDMDb2m8dtxZ5YXpZnp9WOiF1QKDAJBU5JtgYklvKnxacG13xgd Wws5jbg+9FxOokzjJ5G2DHUGC5/JxmiJAx5Zf1OIqOhIEUrYzaQv/3Yo36AeskCYUqbA2q2MqH9 j5of3fjIixxU7GHEkmq3+CdclNooG7OAIpnb7lGEHj56qewVRnxrbZBRK1z159RcXYicVi6qF65 i1mTSjcgcz4fJ/BG1oNHRxR1S3ivBPlycHN3Y5AHr6WApq6eK9wU1sQ6X+pGdi8TttQg1K9AHOE Zq2mBVjy3m/YcpxJgUiYnrwiVwgq3/MQ1yOLfrczrXzkGon/hUelkp8pB96JI6yE/UsNc0eYlXM OA69o9g7LUH+JN5sfl0/r5jwABDL3lm5ZJXtIZXjaDklDWQUT1r2RNcjcwS4pdgRXKyhT4HZ+Hs Z1h74eWkZ/uHYdiWIEwtzOBFNHRHIn1eNloZ2T05WWNowSmDtEJAerXDjpCNdDrLdHvZMo7zxVC 0Vy0lk5VKnmahgA== 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. Reviewed-by: Darrick J. Wong Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- 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 Mon Jul 15 12:48:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733482 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 A4BF218F2E3; Mon, 15 Jul 2024 12:49:25 +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=1721047765; cv=none; b=fjIDFbxFg0TUsWWLn7vHNQQ3oYLqm9goDUAFd1Trttkf1rEwXsK8xR/4OwebcbLa0A5VRTmvReMt4+hSYgi3Ehcgi7JiJy9UzVi1sARkdiiJpKrJLdFees9nBSzeqsBYoseYeGN3lKuLRffOyW5vYJcZuW7qgOm7lZBx/QRNivw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047765; c=relaxed/simple; bh=iWqOXrOqIjnZmnolg+NEkEq3Yoj/1L10uHjOuc/xylw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l4FdqaYe2OZEmInT8h3WQhzbxQZNPV6wrMabRIzljd2z11bEpuxEdf66qd3vIDPjuyRhYrgmOzMr/tdqeGZWhkw9Z82hy43JwF8yml5oldXWYp+t/z8xUJdGBGtvpTkOqaVRwanK5l9V72G6rM6i5vDLL1Ck+TiCeijIqvCwVR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z5Orqeh8; 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="Z5Orqeh8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 964E4C4AF0A; Mon, 15 Jul 2024 12:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047765; bh=iWqOXrOqIjnZmnolg+NEkEq3Yoj/1L10uHjOuc/xylw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Z5Orqeh8dgUc1gNrWO3awvIvearNO9jL/GLYnPiI9DfmGf76A0FSclTsiydvsVdLX P9z9VAeoZuqzFgOvQPhpA2BmMpvnmyZsI9Kd2ynTkH+ZcZtfjNVVAEzpA6RgAWof3c o/N6/gadf6s382d4wQ4m1FNp7Xh/uQuQUuzrqwZukVlT8q9iTq+jarW+dGVMu8szFE bisYIjh7qxk/bJfUKxkw3afk+G7/sb/xtgcW3wCgyi8K7lvffpoyAt35E8jC1SxieU 1MsnZzgZhKv9hABIDSRl7acGfYIcVREvZ9L0J3uu5d5S59ku7A7lpsvDWx/2JWOQo/ EEodhM1YL0B6A== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:56 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-5-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=6332; i=jlayton@kernel.org; h=from:subject:message-id; bh=iWqOXrOqIjnZmnolg+NEkEq3Yoj/1L10uHjOuc/xylw=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrD1XVGZ1c8cCIJmwfS2YZ77i/n0JY0rvv7g EETniwfzleJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawwAKCRAADmhBGVaC FQDbEACwh6VmE4qLcnqitmCqk2O7mVTzebx37UKl9uS8FvZaSKi7BdWNZFzrWhFsOOo9nzQ2J7P EqhJd5AIWZUsRNsgRnWS+LPusCZkJ9r6EpGPCg8hCzqMJH3YFaOJyt7s2qn3/UxF4zUQ+G2T1r/ VdlV60RJVEb6Qs7Nr/5oxiN0TSy92wa+Ghd3Fj0BNLCrY3LvOft1bl7wd7wRAnTcBT5hhdhkaLo j30lZHe8lEr4UkWtY9pEx/v17SxSJjfm0CB1fxn08pvNYczGPGRgsEQj5jyZZqMOTb50zZINVIw UOt6gLE6BvayN94BfnnRzzCs+EErUWMY/3g8ef1Axz71mdyfAs+xebNeTulyC6ZRqPbJRjBMhgc J7iGxT9m95TeJEmmvX+9/IL21XPs37yDNx35L9jPy2xZy/0TuROcmu+ev5JqSD4NnXJ/Crkp3JL fGi5gHVxrzVS6gCxkWaVYkybLQMz9KL9ni/aVdPdlWVdCps+lNuhIHtwcyQi/5rh1Vzwn8XR7ru 0aOuBIuitYqxg5TMVk4IGrT1gYV11D06hQSs90iPER8bf2rT9bbuahH4SjgL4d8yGNJf3ZyBvh4 cR9+fivitdTWSR5mpTSQ6bSqDDpt+zzYtLglpl+Gg2gHblc26C72aVc6yXyHbfHYomie/n2H+9q a2O0O4lkIL9NCJQ== 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. Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Darrick J. Wong Reviewed-by: Randy Dunlap Reviewed-by: Jan Kara --- 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 Mon Jul 15 12:48:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733483 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 45E3E18FC9E; Mon, 15 Jul 2024 12:49: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=1721047768; cv=none; b=FHI4XRxNMcN9xAslfsgs3GpNDytVCX1P7q85Im5fRbalB0PczFmsN5U/WTeVZkJ/rEy9IsILX6xQflo+b7SRaZ+n0J+BOzOjtMOVv03rxigtHS1pn168TO8prwJG+fgxk3unYD40/kk5rHRn6Hm7Aqmt3hUfXKsZKTVrG24xR24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047768; c=relaxed/simple; bh=Za4x1Iy/d7H0eflkTicTt1UaefhIWQ90YwrfG99Zd/s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i6f77OuX5ffSm9LNBYuiz9MfySgHOOy4OxJWITiiSZm/1F/d2tJ2yMGufgPWzn4TdJhU+WyJc2xWUswdIKvuiDTFu90wsCcow+ArX7+UgwVHkxEy/xxhSwWhmWH2C2k0Ho5IlPnjkVA3CDYkyC7FUTX0s7e8EgVuFjmGbIEcguY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MsgBtdWJ; 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="MsgBtdWJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D220C4AF0C; Mon, 15 Jul 2024 12:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047768; bh=Za4x1Iy/d7H0eflkTicTt1UaefhIWQ90YwrfG99Zd/s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MsgBtdWJCSqIckHd8N/sLkK2H3UIksWen4AFqt0e1Vqov1QXoqSeqhnEyiEBfk0KI zj0dYtnefpLl+FmWTb6ufRTO1eLgUOQTtZsF3BZ2+dtqqeUn0cEVv3TvDGMR7c6Sem ZNRa6hMxaIqS/T0hzOUpgdNgTHHbIWxGSrfEgbTQOFeTgCDhc9xcUkD0aYgu1yu8e8 Qy2ZLRQn9sHe2ibmplFUdcKXFpNVMxxBTark2MPod1F/4YMoyURrYbO3xf/7YBGTRZ lZBi7Hg2xzw2XFivw95Cxm3vfGotZmDsB291SEKV/5Plyr5C8JMBdUihn6s8uWXqEi SNVMxc/c4ocbQ== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:57 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-6-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=2845; i=jlayton@kernel.org; h=from:subject:message-id; bh=Za4x1Iy/d7H0eflkTicTt1UaefhIWQ90YwrfG99Zd/s=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrDU4nWQP3Re9QBLBdg/iDcdaRe20/HAbh5B Sh/ulM1S0yJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawwAKCRAADmhBGVaC FZu2EAC2wyQqv9ZanaKX0NuqQvQl2qcPF6diqtykkUObkhXK0jRkoEC+iEJPmSWECO54qgYrEMf aVXeh4ZR7BDbS3icu8iCATQzL7ICRAOfLPkM3ZFag4JsScuSM4JKijVGPIGAfR7zG6913stH+Pk aFE1lCE+eOyTUpo6XxYvMk2Oer15sWj8b5ZL2HO3Pwg3uofMhramJ9jxwAElIkoHuVA9JKxrLam Bp6j3uDOGbdZxecYvRzCD0Iprz9ZCVQblK4MEyISVe5XzHyNlWlmkKoRODyhnfV3pz5j6bvW/61 96K62l0sABrGRf+4lw4K2xekAP+pB9jgeup/7knviQJye8w68hj1kcwKSX6ckZkxS4CzZwTROQm 1VOBCYWGI4cbJ+V/ILEQTzNqkS67R5BCc9XRXgElutxcMXOMBtU8yQoQUs6z9HC5SQldvs/Bcgs IwvYbzhFvmyynv3B0vX1Q9mV9OkAdYHbfH27HtzXCqfPxfCpFwrWiTZTy9wKbYC36tgVy9nGH6S PNInEiAel+lNAF5n697sbRIQfTDDMbTjkB6sAjUQQTNzVPCPr/OL6Fnhzl50Ju8H+Ihzs9u8Ehf lTfaqd9QL5Z2kzDmkUkCXLkf1P+oDoD99tlMutYBCdj3NC7p8r6eZUrtoUa3pwVj+YyDWbe5R8y 0wRft36HqyrPZyA== 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. Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Darrick J. Wong --- 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 Mon Jul 15 12:48:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733484 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 2CB50190696; Mon, 15 Jul 2024 12:49: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=1721047771; cv=none; b=PIzSsQraK9tbVW0up8rYuMypXfJKEFcSyOsED+SxoUVJlQmLK810MFS6qvVqM9hF7pZWZ2WnDLHIAb3/p2NMGvuW+la3j7F1ktlf+qyHNH82npdUQObtW44mckRxXf6ao10HjtKZfq9mUF+TgxAnqljW/0/BIbLmgQAEqWB9foY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047771; c=relaxed/simple; bh=o+gyYbKvXkNExYjsuAJ8m7WMS8PZUinH23WSH2Xu+Mk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EwGO1TUgQLfFaqbWucN2yn7cV9ER5P6qSWGKzXbY5Ex/fLy0SZ9FX33x4H1ChMLFdhmrPL8mif1AlKca7+K/g7q4HwxaMiusHKnBBnjXNulGhtxrmmfqI3u6ZZLq3DaE35Gq2m9ihnF0vC/5wNLYADJLIsy3LW4jAsIKYYAKsmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dRAlerJu; 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="dRAlerJu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63B49C4AF13; Mon, 15 Jul 2024 12:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047771; bh=o+gyYbKvXkNExYjsuAJ8m7WMS8PZUinH23WSH2Xu+Mk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dRAlerJuBd8JkM9VU84MlAHiMeZsxsf5H+2iDx8okusCUrns1bfvO0zdGul5dcknF sUqrcyt5LPwrDZLTCazlsNLaZIGKgXgxUvZeTbQFYc18YKukJQpwMJjvbDCMc9VHW4 mYhgD/hePs6YdNdqNN8is+NjLcevZBaupiE8wiqAPjyMH1t9ae8WG23eKmp7YhcJJn olDHXS8PqdS0eMKgH+2OqBfejhVSOdvmCX8lPd08AzjITxV+1375oAgz3ZJ/bXNq2f HU/m9MgJ7kEvT0Q6SH1MHYwtIlWi32QJxYF9Z0AzefTrXou3tHk4wznS1XrSHc4Zua 6xUwhfdAHh1Pg== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:58 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-7-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=888; i=jlayton@kernel.org; h=from:subject:message-id; bh=o+gyYbKvXkNExYjsuAJ8m7WMS8PZUinH23WSH2Xu+Mk=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrDVHNMl9hO9HTihB98s1BA9SAsORNuI5QNF B0qYkAQuMGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawwAKCRAADmhBGVaC FQo8EACcB1c4yRYITKFx6X7py1QtR4U1d1NUafTeKADoWBjerJPN9fsm6ZpaaCtQbtKA4W1iXUv kpcrsxM8gVi+PTn7Xx8/2ehSVovURyGJnPiHesoWN1DMF3wklKzBb+p+NAJH+ur+LxQjSc8zvdG MObZZHN91O7WhIcM/FOXYHusZ/q5rmKog9G83gjv1kosz19oxzdVTU38iC1pgRoMpmrlNIWV2+q J8bQZDAm1Kf1h/+ZN5TtfknFpBDJW+XyLUWL4wwGCTMQMKSM4aJ1dVnvDF3Mf6M9FwcoMUEssCN +lDwW0hFcHrX5QBhbU3dzC/4M6Czi3YMz/cWz92a/mGv1+Odh1rV5lUmtZEY9MafBvN8Z79H/BI p00YDvjO81Mr14q+LSG4V2rT91AJlEoFYDWw+lbJb6UnTHRCzX2gP4N+HlDcdHz0q67r/pBEiFY URwwNnnSmogqs1l1onFf3Ea2HRACisOBllB/MQf+OorxBz/tisk9LkGBMeFJJCUH5lND2wE8jBQ Imzp4daiSeYfk4qX/8JN2iV3tvEBiEqQ/Ucr+AKZkm9/QYLXI2zufG9ZCwHgw69vQN5BTdQsR9B YjJl9/SQQz/+pqO6h3/oEvnZvO1XYn46KHM8rb754N/szjYamIA30H3k/BQHQGuK4y04RrI38N4 PGkLTg+1A4pF3lQ== 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. Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- 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 Mon Jul 15 12:48:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733485 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 62AAC191F93; Mon, 15 Jul 2024 12:49: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=1721047774; cv=none; b=GBW4JkL1t4xCQuwGW1f6r5X2FS769J3BAHTuj0aTJMUtouN9JHy195eer0yIqdg3Rku6kM9LGqKapV/Nn8a6A6y29sA2/ui1/Uin3kTS7px22JcJiIPVv6HlRm3DZPg9qZYqaVwvV15Gs6SyL7B88TMkPDUUeSNFWW53+E+3bJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047774; c=relaxed/simple; bh=n/GBFDubJ9Ek68qv1catP2lBxJ/9I9EY6EzBmvQbZCE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aS7uqzR/0NGr4/+yC6AmallkOlwN8I55vUE7AVtFJjitol0EP4INOc2Hqd6V9PnZLEchbSNDj/831cXrOZq+0spUPgfgVGz6/s2m+nivHdIY1eGbCNYOjjF6uEyxJvyGqtuDuEqY7SstjVvf7jWUWlOpfR7ThJEdVet3hM2mPBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZtyYbWAd; 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="ZtyYbWAd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AA12C4AF0C; Mon, 15 Jul 2024 12:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047773; bh=n/GBFDubJ9Ek68qv1catP2lBxJ/9I9EY6EzBmvQbZCE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZtyYbWAdVGt+M9geIi9nq1XjNNQKoMnt4VvhJB4ByJb93S22H8PaeX8D+elBcZmA8 impfQEW14muDzQ8mqnKoESrz8Gr10uGPLm63I+ch9I+zWCDY92DOYLcnHznRSfIEz5 x/nUQ7EWPdrA/coYjsXKG0S6bIk4DgwnzLIkDZiZlfyt+lexFtIlTZE+/erPHt6QaK 0eM3Pnc3hhcq91YNFO/cFAiRBaYJpg5tpZc+04sECOGNuL3RAY9OYACGN8vPxWKGbZ poCwkG8HsUOnrBLgRdLZtcnNdU667lJj9uPt/n3SS3h0OKujpuh9GXE/MRP4ajdBjV sXgXQH2/rqp0g== From: Jeff Layton Date: Mon, 15 Jul 2024 08:48:59 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-8-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=2632; i=jlayton@kernel.org; h=from:subject:message-id; bh=n/GBFDubJ9Ek68qv1catP2lBxJ/9I9EY6EzBmvQbZCE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrD197rYggBbmtQ+Pjfq0t5urOGWrOjhcCqL H+PDb1PlFKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawwAKCRAADmhBGVaC FWPPD/98OrTQhimjzIjdpNE2OeuExL1hLuo1FcAxjnPSODQMEGaEHQrTD1UnX5t+mb6vf7Fkhu5 4/Z4EkWwtnFXTrw7dWpDzmqHAMT7jYXa89Ga0TYbI2wx1q8tAuYvBzEQQ6z1E/pcmNQ1dJqOh/l ZDznTDp1mPTy9iE2jum19TBePEDngLxLqGiyqRE95/lJOwuaddhd4MvHdFWjSVPpdjYKE9KYope zyr90O9njRTaqFQlbSPHrd5XdE0NrF35opH85Yocwm/eGFHcN+SrKAMsbApMomPEaKSiFbC1RlN kLd4iYUx7PNDV+XvVGdTGXYbqSgsV7CL2bOxpOK+CYqU6RSKX15uZSqAnMv4Owpee3gZgAllHYU OHiyNZllPfZEOo72mqw3OgahIaEUKKrcWAFzvoyKbCazaMaqFP3d9XUFqOdYWn/iALgO3ZdUq8o VO3MyzVxCOZDjdISoPM5/cgfWc7wBJNLnudOnaQp2X6gH7vIuy3V78Q6SF7P2rezMSTgMepE/8s 7GkW31uEiZYJcpiE+aF0V33DllQqUoca2q+Eg9he4tHp4Nm05N/SXsadR2wgzOZ63OB15CgDJBn ip0syOwO653BxgR8VkjvdOHXxF+Zra0Ky9CCbWqDZWf49I1BJeeYTWCNNOyFrxFjKrVYOBlYtq3 Eh1fhvKxogJPFdw== 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. Reviewed-by: Josef Bacik 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 Mon Jul 15 12:49:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13733486 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 3AEE9192B87; Mon, 15 Jul 2024 12:49:36 +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=1721047777; cv=none; b=uwpygMcF2vmKoIlHhwHwUCQU50tCA/3zigK+GT8slZfDFidEYhdMaK6ZcOeItGiCGjUbKmLdq+Itrsn/IS+3+o4Qcv1GY1PKmpH7exxNxS/uM+S+NZgneFDA9aM+ZYKx5xCgwUgyp6fvwKpXsn3Nkx4aXkaEUXByoPhW40m2nC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721047777; c=relaxed/simple; bh=EGo15KA9RzWejobFOdJXVIKVsZGyPzCyG1uwa3tZn1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s9B6lq+lVLKPmuKibwIjee5i3KhVAieXkmRkfe+vx8SY/1p/cGZvEeeWRiH8QKdSeqWoS+5YckKgYFhLPiVvhg+jnUgcFJ5Q4Pj6PzjH74e/sHZy8ouz5pKhhhsesRBKi3O+P+Df0xbuvmPjsADFW9GcoiFoNgejhsONpPILqpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Op5sWagJ; 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="Op5sWagJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 312FFC4AF0A; Mon, 15 Jul 2024 12:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721047776; bh=EGo15KA9RzWejobFOdJXVIKVsZGyPzCyG1uwa3tZn1I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Op5sWagJjl+DaoEpT6U6Roz5G+OZlHnYlPX1GVRhRCs1ph5A4POU7AelkpSydaFE1 0S/6XZ5jrsy1l+pU8jT0i8xNz7C46rPcqZFpDt+RZwciCR30kKbKz24evOTitf1+Vr FzJPtBPOU5iclZk+mYyMWcBFe2aGVnk/Rn4MMAL/btOLEN7TC8VvQMsoRlssdnUhcZ RS8B6yYf90rMB3TbhzRrgFQYyqfAqu/Tv/l74Z/8C5XrCGsIXk7l2nSGlPXuk9Pf3/ YnBJu+MnFdqez9L3jJ10joq8GI/5b45+aubtvZlH8RUDpFYLgxThEgXVu7Ys1oCnQc YomcYnBGoWouQ== From: Jeff Layton Date: Mon, 15 Jul 2024 08:49:00 -0400 Subject: [PATCH v6 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: <20240715-mgtime-v6-9-48e5d34bd2ba@kernel.org> References: <20240715-mgtime-v6-0-48e5d34bd2ba@kernel.org> In-Reply-To: <20240715-mgtime-v6-0-48e5d34bd2ba@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 , 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=824; i=jlayton@kernel.org; h=from:subject:message-id; bh=EGo15KA9RzWejobFOdJXVIKVsZGyPzCyG1uwa3tZn1I=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmlRrD4m6AcCbQEbB3V0ipLp+HPBka/5rUVsmDG +UI6LP4LSyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZpUawwAKCRAADmhBGVaC FehwEACB/2bL0lHsL7x+6a2mF1cA08ExumwGUUpjqhfW/iUJDZW8NksCANkEjZy3jkVO2UFom9k MsZ5dg106pC96JwTEgOw+Wz+KchU1EDu+k20LB4uv5tnPDvb/ET5ncKyvxJ5+wX90wtxidCfK4h TWJwKVyQsBqdLsZ9w4OXei8HGv99hsDxrY/rhQ1KaOY6CEdzPcQOpCJbSKZ0n3rRR4X3KCEm0A4 vJv7X1XCzEgq0XUFHxamtkbmLAiGeaDng0kVnJQntBpaoFWUvbE8nUnCKwO42rKF9RgKHFMFhr9 Hr5D7G1iySVSJQ2BR5sJDVgMk5HGd1iyI2pVyeFVC6McOAbLpkl2Q5lHCE8kJkxFjd8KLcIwiVW o50Xzk8xJyxBuopmF8fzBrgaXB7Vsova2nDppB4/gexJo9H/PagYElk6p9zsOndkBubvDxLfP3h EJ+mL8K/MHCwpTOt1Ef72Y4QbrbvjsKee5N/8O7YTpBbai8Df1rRFhQrunoWqFh94wkmlSaFm7q bvYRMax6wvvOUL4sKAulaMdnh/m92gAeta1TxcYbI7XC5LI0f/7NQjMaSTQW+lXe6+Um8SHiZvY H5DVd1+vLNraR6/Ry+rSfK0uCHPXRyQadKt9ly2ZbezoPAN3Fslo6ewd+azr8Y3pyp9SvkpysRm d24+EIjmNvSAjGw== 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. Reviewed-by: Josef Bacik Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- 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)