From patchwork Mon Jul 1 10:26:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97A0AC30659 for ; Mon, 1 Jul 2024 10:27:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 062816B0096; Mon, 1 Jul 2024 06:27:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB9426B0098; Mon, 1 Jul 2024 06:27:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6F6D6B0099; Mon, 1 Jul 2024 06:27:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9E44C6B0096 for ; Mon, 1 Jul 2024 06:27:13 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3FE4CC1B34 for ; Mon, 1 Jul 2024 10:27:13 +0000 (UTC) X-FDA: 82290806346.05.619ADE5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 6F11FC0019 for ; Mon, 1 Jul 2024 10:27:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fH62UWFL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829614; a=rsa-sha256; cv=none; b=iBDn0fnOUu6jiN4/L5psFd9Eyu6N4Cr9o2pbhMKDLg5I9xq4oOTPwVDgRqe44yFn7TdJGO Qmd7OyfcAY0B43DpumLTBd3rW+VG5LrDuSeSwD6KxLbEwjqbSKu6elLW7ZQRlatsVs3fny eFU6EyBSv2ISzGjACTqp2mEOKdsVCO0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fH62UWFL; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829614; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=x09LagcIXSQFyjuTYLCcAzu/+JTLEhX/FTgIJyNoLak=; b=AXaHUeF9M3h4NwFA2CIzuHK3ULXFcMNUKl6QQmF0Y7DCr4KILxycdwe09eSfsy9RuWP+gD PGLDd8UkYAEkY/NtP8N7ZDkv9KzrnITXeK/M0Q0nw3w8M76vvfCyaIAgrVnyAqnj7a4YNS sU2FHEuUZNtZ4d9y4QvVqIT7D/sv+jc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A214A6124D; Mon, 1 Jul 2024 10:27:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61429C4AF0F; Mon, 1 Jul 2024 10:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829630; bh=ZBKByquYEdSc8HMPTmMqO17BDUigbAna6N8Jb8o7VIE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fH62UWFLV1muAZCZ9Uqg8bup5NTWlC8DFd1KVhJmlGrmNURVzr8eb8sA0Ls90voPR BbWcdY9SGonGUlyLLohh8+/QHnD9ygByoLBqltTBBsxFJG8QpTGWgi+DTFDv40qK2k FoaAfg3P+swSTgSp56VoeYVv3XfaKaaOmfXxmuqvBBmKFtikx+s7Yd0In339RLRYtH 5DvYLSg6Z+QQFmoaTW5xjJjLvLIoqs0qwKH0u2qrUxflf/dYxqRXZjdcX5xrYSNoD1 6Bu6MS8IxZDMSEHAo90bvmQWpynDEH0t3qJ5M+xLfvP0rnFo0ZTsCBL4UM5tjESSK3 UbDe+sB/rUbqA== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:37 -0400 Subject: [PATCH v2 01/11] fs: turn inode ctime fields into a single ktime_t MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-1-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3344; i=jlayton@kernel.org; h=from:subject:message-id; bh=ZBKByquYEdSc8HMPTmMqO17BDUigbAna6N8Jb8o7VIE=; b=kA0DAAgBAA5oQRlWghUByyZiAGaChHij2CN1I/zkl//fedCXp9VjMU5Dtw3Kbn8GML+q0mPsf 4kCMwQAAQgAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJmgoR4AAoJEAAOaEEZVoIVvDQQAMSY w7rzKxq0PvZZk5HYZj1Fd+MbtYtz2FqcFHuKdCL1wNI9qSIh5roycQHJdjwhp7tcgrSW076CBD8 tEJj4kkd46Nm7jKcMAy2Kv00LGcN29a5c5wnqj9AGRoTXpLf7C5tJBL31pKHj5ignjT4+59wlte o5ZuEo+Gm0ijd/j3es9lK7BIJMyMyFR3BDO5e7dg5rdhPOnt90Y8e9OjTkzc1rCeeVWeBCDDGcb 8LX8+xKrMExJonsClph8lXkxT5LrzJLbSIouBeBicEkm/xh5sbO0sV7fRuNPFZYm7CUyqJNnDJA /Olm4VSauOArxzOmuk+e6jPxboFFxHB7AuIWY1i8KcowJ1FQ4sIsGaqrJOiLnDyhrSeDIJAtOHf j2vthNwFYecOlAWDma4SRUfGpzuwd9Bxb1VZzZWUeL1PqOU+FIA81Wm88el2cdOV8SN4aH6ZcQF E1KZJsOwuDXw/FSgbgFifdijqi3jpaEfiyTiUfOSV/lh4GIYFpHc+1eHkgPOxYO2ty/NxZh35Z6 NJ/e1UPJRnNiFRMKHvPx16kwE4KAsvREDbAd3SRBhXkwBhw/aL1Sx7nYpQv9JENH+6dZeWBgTd9 INL5kJ3hGTS8vYlHAU/WeNNJlO44ASLpvswExclby6lH+tUv/o82oJAcjjfCPr/Y7ri/o+HSzLL 7WR8L X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6F11FC0019 X-Stat-Signature: s4qkzm44t9111iuhzf7j535fbnykda4c X-Rspam-User: X-HE-Tag: 1719829631-666175 X-HE-Meta: U2FsdGVkX196yU5GKdM/kXhnG5vhGjIAl+BlTdHOYCxzZGOc/X7xcI4z+qKhVC8aTYNZaqhZeclUc5RxWpEwDEtGRk/2/OdpXZmp/jMXlvWuV/ch1Hd0z9zGwIjpOncAALSkyMIR6Ds4e+9I+oNZvGU2Q8jI/mMuM423V9lJHqwQkb783IONBggc9f3Tcl658Ep/6Iq/O1C+qRldAEQb7BhgwyqI4l2uvsXmWdfigd8JBNJPDpVE4b6lvw3XYEL+RIr+D2iirbAsFoKVecbenB+4K/rxjPNIJFL+A+LHjjJnXb8wdUD+ajhEt0zlQAta9RwLnr8juuEm9oGi1IKBdAV2wcq5BiMCIVk/wBEwLAL3vmJO8HI6+MAqNloubNCTW12HzV7yb7bwbI/ke4AMbjweeGShGH/TJYROInEIH+ZxoFMiDlon/X6e+2zPwzD1OMPzUnfIXyBFcM7kSQstZjI90pZz6BIYBQ9+AChOcbYJnM5MjSkQKQqAdeYTDxUW+3OtObSWv8TOZqzIjWeCJ/0cemV+Sd76ShOb+NbMGxAmlCaifJzDj7SvE5+0r/LvxzrmcUmskCzqlYPR797sDEqUAKu15ss71/bBkJruBL3oBKEj1xazdXx1s3ch/kGHmUoejeysEttzOZt0q/YCACAR7T6f0FyfTMQtwpMdWcvu3D3lZomcKOTt3JFhKJbb7FRk3VrS1an1eZodgBH19OvvmU0WEVg9faGbZuE2p1PnGjhoMd0wYz+jOcGllJenx1FehjLaTpEXrV0xhyu5SqwpAgFf3Y/6Ym8+Fm1r8uEPGA3+x23v4is4TlzQwmfXmitsnNNf6kThZSKwhbjl2aQY9CMigvP4VGKTwnyjKjCjVVQOwUHb6RdaecMXsZjdIYtsoIGms0xT0QqP59YY6hN9TKLME/OXpr7ROG7UumvxfCZ4p7iUNJ5DHLZRLZerK6aLgcUdLOWmwNUw+SE 5SsV2mMh Da5B7BRuhWzV1EbWCEQWs7iNNT+NXY3nQFX7JDEPFJiZ2g+8KVI0Pk380Q6mB556n6xWMi0q09hn0DDtYBDYOETXE2rhOt4/VxevttCRAtCzBDAb2LMzz3/mJwFCNqcW3aBxI2cgH5/GANL/Y9pVOORjE9BYi3akQEASd2GYxRAwlBIF/fIIQ5GGr93sh8/ggh+rocAUxkYCSyzq8LrKJo3hxMKY8YwR4aMQz3aw8ySREqgZMVBJstNIH59HsqQ2eY3QoumviOFW2VbuEGcaqvO0JDIWtWAIE9NnQB8tWqj0Skhpo3dVmthQQrb4LWfW26FISEl7mH+mOji0wJ7HUcVC5Fxq/19AQ6HSFwVMCTbTTqEjcKH1V0g9PrKtjk3BWGwQs6DMjXyeJK/46G5yGpFNTV1bEEXoKEBZP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The ctime is not settable to arbitrary values. It always comes from the system clock, so we'll never stamp an inode with a value that can't be represented there. If we disregard people setting their system clock past the year 2262, there is no reason we can't replace the ctime fields with a ktime_t. Switch the ctime fields to a single ktime_t. Move the i_generation down above i_fsnotify_mask and then move the i_version into the resulting 8 byte hole. This shrinks struct inode by 8 bytes total, and should improve the cache footprint as the i_version and ctime are usually updated together. The one downside I can see to switching to a ktime_t is that if someone has a filesystem with files on it that has ctimes outside the ktime_t range (before ~1678 AD or after ~2262 AD), we won't be able to display them properly in stat() without some special treatment in the filesystem. The operating assumption here is that that is not a practical problem. Signed-off-by: Jeff Layton --- include/linux/fs.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 2fa06a4d197a..7110d6dc9aab 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -662,11 +662,10 @@ struct inode { loff_t i_size; time64_t i_atime_sec; time64_t i_mtime_sec; - time64_t i_ctime_sec; u32 i_atime_nsec; u32 i_mtime_nsec; - u32 i_ctime_nsec; - u32 i_generation; + ktime_t __i_ctime; + atomic64_t i_version; spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes; u8 i_blkbits; @@ -701,7 +700,6 @@ struct inode { struct hlist_head i_dentry; struct rcu_head i_rcu; }; - atomic64_t i_version; atomic64_t i_sequence; /* see futex */ atomic_t i_count; atomic_t i_dio_count; @@ -724,6 +722,8 @@ struct inode { }; + u32 i_generation; + #ifdef CONFIG_FSNOTIFY __u32 i_fsnotify_mask; /* all events this inode cares about */ /* 32-bit hole reserved for expanding i_fsnotify_mask */ @@ -1608,29 +1608,25 @@ static inline struct timespec64 inode_set_mtime(struct inode *inode, return inode_set_mtime_to_ts(inode, ts); } -static inline time64_t inode_get_ctime_sec(const struct inode *inode) +static inline struct timespec64 inode_get_ctime(const struct inode *inode) { - return inode->i_ctime_sec; + return ktime_to_timespec64(inode->__i_ctime); } -static inline long inode_get_ctime_nsec(const struct inode *inode) +static inline time64_t inode_get_ctime_sec(const struct inode *inode) { - return inode->i_ctime_nsec; + return inode_get_ctime(inode).tv_sec; } -static inline struct timespec64 inode_get_ctime(const struct inode *inode) +static inline long inode_get_ctime_nsec(const struct inode *inode) { - struct timespec64 ts = { .tv_sec = inode_get_ctime_sec(inode), - .tv_nsec = inode_get_ctime_nsec(inode) }; - - return ts; + return inode_get_ctime(inode).tv_nsec; } 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; + inode->__i_ctime = ktime_set(ts.tv_sec, ts.tv_nsec); return ts; } From patchwork Mon Jul 1 10:26:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40ACBC30653 for ; Mon, 1 Jul 2024 10:27:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C220B6B009A; Mon, 1 Jul 2024 06:27:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAAB26B009B; Mon, 1 Jul 2024 06:27:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FD286B009C; Mon, 1 Jul 2024 06:27:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7A74E6B009A for ; Mon, 1 Jul 2024 06:27:19 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 244BF8120E for ; Mon, 1 Jul 2024 10:27:19 +0000 (UTC) X-FDA: 82290806598.08.A4541D4 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf21.hostedemail.com (Postfix) with ESMTP id BD11E1C000C for ; Mon, 1 Jul 2024 10:27:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YLs4U1yk; spf=pass (imf21.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829617; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DL7KnWgv8BjNXe3zLubPpQhmk5E4gZYXOfvsXPMQ0rU=; b=WB+No0yJP0b/efGfB8z6f0OO6jVKKxmQM4dvL+3adqOot0MuiIPOgBSLi+xDV30AYZooQo jOz7E6ABAmPeXGm7A+V3Vat0taKY/RF+OOUUHVye/KQ5iTsGPxi+zuW/x8vj8kcvVbtdni c9gOlv/VfA8lxF8hRr8VkOpUH4YKPY8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829617; a=rsa-sha256; cv=none; b=N4kpVgBalPlZ5koQSZfj6TELBGhEAg4XdsbV+0ioUAS7QiXyE7AdBadRqN4WNNkTavMN8h vvKPeSVlEPH+sIGsMz4gthvcBdM2zvMD7X/uHbseVCUVlbSiQ60WNDzB4t4wddP89wgAaw MosGM3Od60FSbDAXHQzfC+gsYd4NbPw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=YLs4U1yk; spf=pass (imf21.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 7085DCE1173; Mon, 1 Jul 2024 10:27:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFD53C4AF0D; Mon, 1 Jul 2024 10:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829632; bh=+Ll5hg7fP/HJuANKEHFNQPWIdpLiw73n3t3+REkgl74=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YLs4U1yk31/nkByopNeyavqaYbshC2B3idXBrhXHXRo2CcqTf76gc7chybjngqegu 4i8ky0uvI81yiLqr3gc1M2z69PEWNKsksBPjh4PM1UpwzLF15an2pnmGEuGQpvVzpM kNtJxzZW27XgO31tmYxQb+sOB8Q/MVNfNcAhRRjFIDF4PGhPTjkeXTRO/h5YyjyFBZ dpaEMVm8YEW1LEFMvaC3h5qSOFDM3Mq/oiRMq60sfJDzXQks7WTbpzUFXvuk0+40F1 HP/zsQmVq2PxVJP4pG6RP+3c9ireNOi2t0mSMPi85aMTTXdnal2UTVLJbETSHU4bOp laaBRljmQ3/NA== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:38 -0400 Subject: [PATCH v2 02/11] fs: uninline inode_get_ctime and inode_set_ctime_to_ts MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-2-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2576; i=jlayton@kernel.org; h=from:subject:message-id; bh=+Ll5hg7fP/HJuANKEHFNQPWIdpLiw73n3t3+REkgl74=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR4Q8RRSxWkQGur2eUnM/gRhrlIRHemdFcK6 Pl9reaXAbSJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeAAKCRAADmhBGVaC Fb2HEACJ1w7tWJnhLJJHKtIkdTLk/MbD2FV/05Q8JpoUDULrSi2uxwNwsZyUcSTvWlJ7jcH5Th0 dJM6XvoRTYVsd5gyGTJJgTNwCu6GiSbenps/IatnCVH+aGz5ziOxYS4WIYicKw04VP0cxp4oJ34 pdnfOxTgVlSGiSIdeqy1n4Rjbtz3fRosxKP9Et4XlbzVbyRkbUbwjKYuMLcRESjAh507dfENdAi B4fHUsSmf1Sl2IiPZ+kDr/15LDbCqG+nhjQC6ksB+WyYiZE/0VfYXCuJcHJFT9loALbpGS2avhN 9SKYEAF1LMptopK1PAC/qTr9R9sFAmqF6S+s0HHVcI/RNmOLgr664ZHAdGCgxDjZ1kp1VKN27QQ esvHwRRCQaU2cHSGpdg02ajzEQWmtiC3bP4P9XCJJFmsM/pfLRMbQ9WscHTWUUVVThq/56/Lply 5PnVt9ZZbqq1r9kvwbUii4CBn/Z84D/5nYHYWS+i66DNp6/hIm2kCPBJaN8VrVeY6Wodv5JzIt/ KPHC/Lyntosv80bsit416E/riPN6u79SOs4HshmdZbJeW/PLyRasc2YRZehXMqh9ufqdsvUhMs0 Nfc40554ynAy/xY9i1/lZ0v8xjyAgjRsRBl0hxBSKaLqinyOHIsaUoLuwewvhg08NAXaQIGKwuO YG+8TUTESXdJNZA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: BD11E1C000C X-Stat-Signature: pg9wok18sfbhzg6j8fchf96mwqejq48j X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1719829636-388722 X-HE-Meta: U2FsdGVkX19RdXMFbG+zmeHVB6cr+4ZjktPYZ87SdmjqG5+XJOOgGoSNcumndXb7n+RH9j4DqXF5+e0a8zaURsDz5pr7J47LmuuRkBUVqSW2RqUrThYnZZ8OSuqPYgv2igoMXR49si8YoyWxSK7FkfljcBUMhKv4FlUKpRXmcfys6v/2fa2rbuLmsUbcYFrY61oQJGqGqOLpYXpJTouVxa2mplS5LDRPDkl15HjV7iPw1E54/wI1NyrewbuftlGS9e/gmb4h5TCo7Q+xcncyOAXdj4qnrIdHdu6+xB+FLGvglxiTD9bNp1kCGyE2lCxyhEOw2N9NjjjFJH07qtIZ7Gm/CuuKbQXmpRoKlR0Ct8WZNmfimU7yx/k3YCLGdtmZDbLPldDJJV+JEelnea6eNzRfRCKLNrTmqPwZfLya4et/OufAzfchCuW9gH3TJvtHKTAgHct2A2GWC0rtzRh/OWB0u1kGBDZ0MIoK9koWoWK6lktCJdwb2W2/nYBkpRKQoAP2LTaeYdYubYbUltZP1wUG6hS8SjDbgzJ4yOUL14IBs2ALTuKiCbNEfK4daddqWdy3c8XBHZBs7DP7Gz+oqtWdp1OqDXxEFHV/xR888POSmbn1TWq1HWAOPCuBP7RaDzI4nqNidMvM/SRySqYaIp+iuYzUGXc50XU7skkLcqFb0xEfMcSGuBeMAwrSGLmywYigLVANHWNA1zj8sclxexW55ymWDWSpD40kBUoN1yW9zEDHJXaFXKl72VExhgRQ/l4jxnLqupZ0/r5Mnf0XbA/PUAgYsTIqv7CKgh2SfSGbYao9BXBjYSu3mmPBBCz68tGD0OHwgYTz2q29y5gMJSS4S2f1FxpMeEzT5s8FpaTQewn+OreFMt81nw8GCUhsIvkeeK3IK7Ps/US/rAje6ahPNvMmc+wXspybFZlRTLtae+xwiqolWBGVD13KOdmnXaM5Z8S9ijdC+8PHBgR LMLq42j+ ddC1NYyTc+ejwb9ZMVxs9bNSsVvfGvN5coMJLG4vknenckZURx1dtEle5NyuypfPqH7fsN0glIUhjQkZD+kZtl0JFRDWnT63D9pwzk96sxz5MDIiXzsnqxCnUa/qiUljL1cTCQRWF3bUlKg+wfQsHawgF3glruaPH97qpwi+Caf5MsimP7Ette3gAseqUz53xvsF9s2ErST7wfexe9Gk9YTfz5DhMG4y7VmapTmXGDO7PHqboXrKgJKGIcADcxFiltb4g8NCjkCkOVIXdNR+bN58uMJFGiQ+WhzAsYS3eZVRyMSI1tjkE2mloptgDKM1KnUReBcrLrTycmJPjDRY9Kv7Rd0KOcQPzx3gUCDZAnEwZHmzVtJbFXm/7rHUR8cf4+4yyk5+QCFfRrqhdDedXZF38te9DkME1MKzd X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move both functions to fs/inode.c as they have grown a little large for inlining. Signed-off-by: Jeff Layton --- fs/inode.c | 25 +++++++++++++++++++++++++ include/linux/fs.h | 13 ++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index e0815acc5abb..7b0a73ed499d 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2501,6 +2501,31 @@ struct timespec64 current_time(struct inode *inode) } EXPORT_SYMBOL(current_time); +/** + * inode_get_ctime - fetch the current ctime from the inode + * @inode: inode from which to fetch ctime + * + * Grab the current ctime tv_nsec field from the inode, mask off the + * I_CTIME_QUERIED flag and return it. This is mostly intended for use by + * internal consumers of the ctime that aren't concerned with ensuring a + * fine-grained update on the next change (e.g. when preparing to store + * the value in the backing store for later retrieval). + */ +struct timespec64 inode_get_ctime(const struct inode *inode) +{ + ktime_t ctime = inode->__i_ctime; + + return ktime_to_timespec64(ctime); +} +EXPORT_SYMBOL(inode_get_ctime); + +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) +{ + inode->__i_ctime = ktime_set(ts.tv_sec, ts.tv_nsec); + return ts; +} +EXPORT_SYMBOL(inode_set_ctime_to_ts); + /** * inode_set_ctime_current - set the ctime to current_time * @inode: inode diff --git a/include/linux/fs.h b/include/linux/fs.h index 7110d6dc9aab..8e271c9e4a00 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1608,10 +1608,8 @@ static inline struct timespec64 inode_set_mtime(struct inode *inode, return inode_set_mtime_to_ts(inode, ts); } -static inline struct timespec64 inode_get_ctime(const struct inode *inode) -{ - return ktime_to_timespec64(inode->__i_ctime); -} +struct timespec64 inode_get_ctime(const struct inode *inode); +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts); static inline time64_t inode_get_ctime_sec(const struct inode *inode) { @@ -1623,13 +1621,6 @@ static inline long inode_get_ctime_nsec(const struct inode *inode) return inode_get_ctime(inode).tv_nsec; } -static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, - struct timespec64 ts) -{ - inode->__i_ctime = ktime_set(ts.tv_sec, ts.tv_nsec); - return ts; -} - /** * inode_set_ctime - set the ctime in the inode * @inode: inode in which to set the ctime From patchwork Mon Jul 1 10:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D419BC2BD09 for ; Mon, 1 Jul 2024 10:27:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5FD76B009C; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9B9F6B009D; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82BCA6B009E; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4FF466B009D for ; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0EAA4141A96 for ; Mon, 1 Jul 2024 10:27:21 +0000 (UTC) X-FDA: 82290806682.25.549E591 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf20.hostedemail.com (Postfix) with ESMTP id 9C0371C0007 for ; Mon, 1 Jul 2024 10:27:18 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=omKMtLWA; spf=pass (imf20.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829628; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CEbmpuovWZg11HIw93Qn3x7IEhnefIXy04xLDYqx/cw=; b=7ckLvF0CqyFpDiXyVsN3fSL2TMt8z7G5peSrLWajGOcdUcy+CNjo5M3smwBng3Fy9wY9QE KuVUqqXDzUJjyeBbjiyiwjd6Ag8hkcMo9jxrhNhDGEnR4gfZslSAYgp3weTD5CvKg8UHyz 3/AnXLDn5Pf0EHbhE8uDLr8EcOgEGFs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=omKMtLWA; spf=pass (imf20.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829628; a=rsa-sha256; cv=none; b=VWj8UscWE1ta6kgTwv/5AM+SiOIEgPNIm1ixOiZHUhcTFTuP/F8nUNPOT+uuDZqNIk2Ldc 2lvdUErh7ttS8bszeIrumxEN7hejplbS63QdINpTlnTuZOeDHmgqAsHLrgj6WwzR8YjSEz mvhnhQZ7qNdmHA4TfJtpjSs7yVkv5ZU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BD26ECE1174; Mon, 1 Jul 2024 10:27:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 086F0C4AF0A; Mon, 1 Jul 2024 10:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829635; bh=TvAqWM+1osikcEDt9i0N4WD9vik81z9fLBMKtBzROY8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=omKMtLWAsyL0zAsAPOLHmO/PULOiMrdAphGS7XL4KzP6SdkInnFOvrWPg8iNVA8SE O2vLzg+9P8se6O6us7xNZvZOiRvyVe6XH4EsLttxrJ562NbbpORn5fYa5Z9FbZgevX qXDhnyoFG89QoRXmS11fV84bk9fbobyzJUF+UVVU/ysy6MiPwUfK/3YkOXCVEJB8Oa xdVQkFCz2rr2x3UStE4oxMyzA3dYKPEOgg/ltdVkaUwQwIxEKUd4ieRKnYOv7+wR8R uy7OS93B3eNia1jKGcgtDsC5LDu5X5FmWvjRHZhf2FEqX5SgMdVrl6WbKOk1ilNiRs SXGE/9Yod0TbA== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:39 -0400 Subject: [PATCH v2 03/11] fs: tracepoints for inode_needs_update_time and inode_set_ctime_to_ts MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-3-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3425; i=jlayton@kernel.org; h=from:subject:message-id; bh=TvAqWM+1osikcEDt9i0N4WD9vik81z9fLBMKtBzROY8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR4fMvBS8msf2r3qrJVeLrJLPiafhklB5Y2M 2ff/OZrOoWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeAAKCRAADmhBGVaC FewxD/wO4A1OP0QwpPBNzHvQYzQ3QKtbRRz9097tMgFKRzvc9W+rJQXTGyU01Q0frLqh5f3Ju1N +ft2f0BamL4qEFTpRkkkRX61dzmSeFYDJVCau/cNUdcnNYjx+3dm6SlBg6Y3P+mxxf7KkU32/jQ vrmQ/mlWFeK9qxwwHyUOISjol5fs7IXrNbR7PyHfQpj4GfcRd//9tSvfFlB/SecQpUbcUIkZQjW +BSOC9RSuiFVYGiWawlq9Q+O0TchkJwvXS7wj/X5hfI6C+BNnyC5c38G4u0/QIUrdoze6JU20hO UNxwHmOFBHjp+PL73EE3S3GU/+fleMJDlCOTky+50FNHnuOM+lrTZySsYH+DZOc2o7ke9EiFlOf +KL/WVDc3Cia5wKy4lh/xod+mibhHsNcGbIhcv22izrEGGnnOx+4QIFfrI2dnmAyMmHAPSgsZ1d j+0H5m0vv1lcBEIFiSVlGwyytRufnhAQJX4J9RNWkhsHBidzAPogfAZwEY4ef5se6337mLqSF35 pZnYoZV+1blWEStRGHsh383sypvnp67jYhT64JXRqGWZheHFMcyRtK5A7nUzOtAmHAOM/0gBTID K9nklzlgH+VYxyx/euDlDXvIUUbv1bITh/pJ1W7Dg+QlAY78fF/LAEknKlq/ct9/gsNQsdWUhFY xOJIKdmKn59P8HQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 9C0371C0007 X-Stat-Signature: r8n1rjw4ffunyr3cwh318jqt3yzofpoe X-HE-Tag: 1719829638-683303 X-HE-Meta: U2FsdGVkX18Iubu9vmk7hIiU4g1nhv0uhMoFgW9wJ/wnNRZJ5TbR5e97HV3vEAZoa66Eh8DvcQt34mlJNCWlcj5UxTgIeJplRjHfjt11e5Iaj7U8zYDRIKIUsRCrezwDW9gI8bNXjvVVqycb5wXzxKshjNsobZ3esc/Kb+08FMdV8LP2+EOM+9E6+ihgX2AlcbIXadyxTjXcWJ5S7V9X6BkX4LrtC0mchnsketH+hVpTqIzdvC7o0R1mu2tTBZY8gPsmPzwtWwPjeyBJMdIyqpzrORSoVForSEds3ycz41cNl1RFSCxBYgRnkePdCxv9kROAfV3ZFIfwrBO0HuZYAnPeInUlfBsTosrYYbNQszozo9X9z+PuqQljA0VuSq329ZUjxSPdyCqdArodWZJOiStUVKw1qkvqhE3lX6IA+aOwv3BxOr8B+eXkWk30YzPSSsxxmxuM4xc1K9fN2lTUuWUp7WKT5ods70X57FSEDkfxcaXgvf1cSQph2cnwYjzFz/lVZHG/Px/YVBxYHPR9bvaMyivgdoNapusqucsp+kC3vAEotlzDIGNcnkw/2kx08daP32nNHgz4xpLjX7SE2HHAZ8FvW1/Wgvc8I3eOcxoJy4xQuUjMmwiyDV+1VnsJKyEHM1RwtOfUGYyWVuxjlzwwj5fF0fO2SGDFL6+4F8RmWCxBrnoxADn7cWzfDu+r2HZ8FOyN1dYu4LVDM5/YUmyoZ9lnilNolFAU8VMPwJW+w+s0oTxMEa5hWG4hQ2UwwpKq4Sz3P1CElqFPIpVmD5UJNtoeg0RhVUJeXNmwsm02VC0DYkRAPLcGAXiWDMOR1BStj16FicncnnsBbSnwOIl1HFt+IOt2NNp/r9btfAsU1UI2sryUSi4jlqfqsb8HxN8iGhTBbjLky/yqR2Ezr4SqiIQLaJ5cCuQyn6Lv2YavicOmFGRIJIFkImw/QyxE76WGVwRmMa8M6U6Danl xO72SVpF Exd4wdCRlFiPC0NNfyfr8C0uy6ziVUBfI7oQVRQ7HhSIxnNQXN6EKc9AramnwBIwz8QPy6zDdW8jsBq2JwOu1qihUk0/LDuQAoBPAjRqs9Mx9wstwBz+FwLmixSnuBVX7kE76rIaBWoFYUYOVCOOm20/+5ggWDAcMaAHyVxhWPF0I5SUDRfT9ooqzbZcD/NssCuWUAmSnGCg5Cndrp9OqN3SJGNKOB+OVrOJVrD9SX202CQ78wfxL1HzQYrggoYgifqtOj5B9otMdQpFF4Mi3dYfgZecKkTj4Bbob4SAxykwpcLulpSRTB/n2KL6L6zMc/ElU6oDY9XJlvnDj4icv6erwcEUi+pGtNAsg5bgfRPR6iCgDCK6A8PvmcHJpD7ItO4VR6SknxBftWd4DtJDivbhu+23ApW68aGamOPHpJ/lgOWQ1NIoesLvjbA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a new tracepoint for when we're testing whether the timestamps need updating, and around the update itself. Signed-off-by: Jeff Layton --- fs/inode.c | 4 +++ include/trace/events/timestamp.h | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 7b0a73ed499d..5d2b0dfe48c3 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,8 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include #include "internal.h" /* @@ -2096,6 +2098,7 @@ static int inode_needs_update_time(struct inode *inode) if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode)) sync_it |= S_VERSION; + trace_inode_needs_update_time(inode, &now, &ts, sync_it); return sync_it; } @@ -2522,6 +2525,7 @@ EXPORT_SYMBOL(inode_get_ctime); struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) { inode->__i_ctime = ktime_set(ts.tv_sec, ts.tv_nsec); + trace_inode_set_ctime_to_ts(inode, &ts); return ts; } EXPORT_SYMBOL(inode_set_ctime_to_ts); diff --git a/include/trace/events/timestamp.h b/include/trace/events/timestamp.h new file mode 100644 index 000000000000..35ff875d3800 --- /dev/null +++ b/include/trace/events/timestamp.h @@ -0,0 +1,76 @@ +/* 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_needs_update_time, + TP_PROTO(struct inode *inode, + struct timespec64 *now, + struct timespec64 *ctime, + int sync_it), + + TP_ARGS(inode, now, ctime, sync_it), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, now_sec) + __field(time64_t, ctime_sec) + __field(long, now_nsec) + __field(long, ctime_nsec) + __field(int, sync_it) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->sync_it = sync_it; + __entry->now_sec = now->tv_sec; + __entry->ctime_sec = ctime->tv_sec; + __entry->now_nsec = now->tv_nsec; + __entry->ctime_nsec = ctime->tv_nsec; + __entry->sync_it = sync_it; + ), + + TP_printk("ino=%d:%d:%ld sync_it=%d now=%llu.%ld ctime=%llu.%lu", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, + __entry->sync_it, + __entry->now_sec, __entry->now_nsec, + __entry->ctime_sec, __entry->ctime_nsec + ) +); + +TRACE_EVENT(inode_set_ctime_to_ts, + TP_PROTO(struct inode *inode, + struct timespec64 *ts), + + TP_ARGS(inode, ts), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ts_sec) + __field(long, ts_nsec) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->ts_sec = ts->tv_sec; + __entry->ts_nsec = ts->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld ts=%llu.%lu", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, + __entry->ts_sec, __entry->ts_nsec + ) +); +#endif /* _TRACE_TIMESTAMP_H */ + +/* This part must be outside protection */ +#include From patchwork Mon Jul 1 10:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9E95C3065C for ; Mon, 1 Jul 2024 10:27:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 324C06B009B; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B7C46B009C; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B2296B009D; Mon, 1 Jul 2024 06:27:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D12E96B009B for ; Mon, 1 Jul 2024 06:27:20 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 79ECBC1B03 for ; Mon, 1 Jul 2024 10:27:20 +0000 (UTC) X-FDA: 82290806640.12.FC96071 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id A5C701C0008 for ; Mon, 1 Jul 2024 10:27:18 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JUYPxMqz; spf=pass (imf20.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829627; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wYW1NW11whANK0Xzu0A3AvKEfRlv8ps0ecUBldIV8qc=; b=zYiUa+pew6MSwgOuKbuZtT/5MFkF/kPNcr/hzZudxvdIszO/z/dayeQKf8l+3GZuHdsFIF jBtw4/ukHEIMEgEWSmU7Ewfh+e7cjruKq8huwKNpuMj+SClhoE7gJ/+ZYyHXdfdRJmqI0Y PzM8Ur0YGBt4XJvLR+/Nt1BQamDinds= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JUYPxMqz; spf=pass (imf20.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829627; a=rsa-sha256; cv=none; b=J1YFpgfQRIPr4Lre/J43NsGnlzwmtVNXT1z4yx+Og1wUWV5u7V1kvx9HiVmAyI4uuc4WH3 LxbRQSqPPS2TcbzwC/Lv3PpP1bUZW1Ii3BUsoIZbbzPwjFbxKuLDgnWvhLaROKRrtbfNGd LDOPVMuMLQnlQZ/B79Yt29B68zKKX/Y= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C1A946123B; Mon, 1 Jul 2024 10:27:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 546C5C4AF0C; Mon, 1 Jul 2024 10:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829637; bh=k0PASpE836OQmpDiHN4nqw4lE+fzWCGQYeajWGV5+J0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JUYPxMqzEi5EY/MH4MdNa+TAkj71r2+HQEr1KPiTq8PBffx/aggQ04Gd90axJUd7u dqZAB968NjPxqA2PF7lOTOKa2fE2meOiUiRCzECtJ6CRb+0gRfh4IImO3E9UnuCCka LFQJ4s2J1vsf4ItJHE5ivQwVFeEt3ngjdtthZVIg9s867mvrQ5tZRDQHl6MuI5Wxej PbMuI82k2MZgn97pXO4gOL8/3tGRu0+RGsNpygaUYm1NZ5P0alfOSgPw1d8RzhZgc6 KDexkxV3jBGj1byoHPa9bFt2IUo3bwvmo7ehTxtjBbVrut4HGfmyeBINKgfzjJ/3Jk b/dl09l7z3dvA== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:40 -0400 Subject: [PATCH v2 04/11] fs: add infrastructure for multigrain timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-4-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=18627; i=jlayton@kernel.org; h=from:subject:message-id; bh=k0PASpE836OQmpDiHN4nqw4lE+fzWCGQYeajWGV5+J0=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR4d+Qh9dTSmgG2/qAL/8YQ5DnZmVHz5gj5Q 26SkJWRJ/6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeAAKCRAADmhBGVaC FfqDD/99AiugfkF1E1sF92oAzAg2dtjf4IFcm2brKbPuYECLlUFJh3PHAbKzqsq5S2kStxr/lH1 ntVnl/dWHaZAfAJlbaT4W4xBfri0KBHkIBjPpUHh5/AO1OjGAiQ1MNXnc/8uBAuYC9eSjHzcgE2 yAN4yYISP7/IGB6FqPx92XXDdHajRkatWPuJJBcqGxn4MbkyIRuwFtLBIcXnAxcXrrP54aCa50t +hKCBAGhHcKP6cu3r4T1Jd2MFvTmfeo05xSVZdfLZkY8d3fHH3fAvtYjQQ4P0H2fBn8Tth0+VEV NhjwpuLc7UZqJQhXUqZtFxeTfZCokNQUHS8adxg25lwdNcSF8qaOKfvnZ8XFH7tVmnFZNbXEqKL 49VQV3w1HlRDMpRBNLjhzL7Dx7li/RGuBDN2dO6e9fmzCED7DndXH58brEe3DqDQc2djS0DuRvA P+CFUn0S1262ttk8GYySjMYi9NaEFWOwvT1JspqhL5DDxWcuUlea/U6KppjEQL1MjUeEfA5YWzj KWC/tRo/ex2eAoYFHoFwcZjuESQ1A2h5BdFu7OfszomkXNVOACoTwI0uLrP4E/XVEu++q5Y7/ly +8KnWBSWYjorqT6ent3mqij0CFnjVWILpoG3JJgcPjujzShnj9AaN0LJ99x2n9lLUzUysfUCRLX nMv1/GkVEEKYinA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: A5C701C0008 X-Stat-Signature: uoy85sejwf1s6aiysrkgan6wtcztip38 X-Rspam-User: X-HE-Tag: 1719829638-135758 X-HE-Meta: U2FsdGVkX19PHQ07UBZ2IJ9zMQAXnycrmsbqlsXbfOVBiouA2OTWRx0LPg4LCm3PzLySRdjhG8xuEuC/93mITliTkyZpqVmBD0OGIaREcnR5ay4E+MGfBD+NdEJt4qdRhbNZzJTqJIIXgFCW8R/KfK7xHsns2+m4e0EOm8ufERQY8fF1f+SJz0SVjVyy8pLj2DTBLT7AsB9Kl4+pDghywdWzPFsgZOX1IgWgJwS72EI6tbRdP2zxRKxtp8nK4A+5LNW78doGd24gPI6VGEAomPqKUVl90yue99RcBb68aI6JoJqWkVhCxnoHmB2zCbWmHQSusceAPhdGNp57n8S182t02LbL3lxf+KIaFU/QUCSb2ZqKrX10RLgQwCX93gai36z32HEX8EwZj5Y0s6EB5QG5ZbvXEdAKVnaBXFEOPm0SpaqSV6IY0iZ6+dG6+x8PpaUWKYsdB4nLs0gvQiAzGQRrn8Uyzxvy8sgQbone/2ZwyQkbvHKE07iqrZnOSVsXTDqxjPNnL1/UW/UWqW/yN81C7zO472le0nZK9Z6wRK3AOStc2tsZuoDcdMCJ2ZM+187+ytOWYbunDbiWEdFll8SUzWDl5uf/XgcCt5gkeECih9pZTRDAT/L2OEaxXIRB9E2BPE1RrCVFv8yXc3wClzg6jAa9oHiw+RSAQ3G0bEvbczDSBXhxrpp/bl9MvyfDIlqW8jHyxbMO8LlNj5Ce9ia/UQLrAQMY8dEX5Dv7KuGVhNB+w2o+cnvpZZx109CrArrDgk9SrkHbBsm4b63rSTJ0nevKSYJQfbJLvooZ+xVZdieH4+y+xW2fw5VYIQdqmxtSCY6UdhLYsXK/TTp4WiQgXM2v0VitM5NFk5YaCdWYUIlXSgYtDQGasS0wgNSlc8hT1RJ5omPhuo29lTrETkcGpo/apn+wpDNQOT1725XdRsojJS3cL564IVrnIU+l20VK/+tovVhoIJRp5EH koIGNQAR SNNbKfDt7UPhbyaWrK+n1PF4DuvekOEHqXJxP3JXk2FPhx+oc7xmgMblbNVpckUp+rKNQ08f+CLUuQOI9pPnUgoecj/FBJJ/ynraD+jv+FDIpKOwge8wyrxS9slwHkeK4rKqLZJDfqBxTIdvMV/2LE6epsEhRt0EWuasxEALQNf+9y+6bptvrFk/mYnjtD0qk0vjPheh1zECeY+zyx9Yu+EGIdC8o11WsyBtyWA09dybbf54fP43OVayuUOPGWrRs83fownriz37ruTJlJv7CFLDrK+Kbor5aOqki/88/Sk7kaqGPqsoLoUl08/odGBQQnknGLCEJ0uZj9OgEpo8soRqCIi+ahvQaNAY0veXdWQI2eQ41OX83IHX12w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The VFS always uses 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 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. Now that the ctime is stored as a ktime_t, we can sacrifice the lowest bit in the word to act as a flag marking whether the current timestamp has been queried via stat() or the like. 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 and then a file that was altered later to get a coarse-grained one that appears older than the earlier fine-grained time. To remedy this, keep a global 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 (call this "now"). If the current inode ctime hasn't been queried then we just attempt to stamp it with that value using a cmpxchg() operation. If it has been queried, then first see whether the current coarse time appears later than what we have. If it does, then we accept that value. If it doesn'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 and try to swap that into the ctime. There is still one remaining problem: All of this works as long as the realtime clock is monotonically increasing. If the clock ever jumps backwards, then we could end up in a situation where the floor value is "stuck" far in advance of the clock. To remedy this, sanity check the floor value and if it's more than 6ms (~2 jiffies) ahead of the current coarse-grained clock, disregard the floor value, and just accept the current coarse-grained clock. Filesystems opt into this by setting the FS_MGTIME fstype flag. One caveat: those that do will always present ctimes that have the lowest bit unset, even when the on-disk ctime has it set. Signed-off-by: Jeff Layton --- fs/inode.c | 168 +++++++++++++++++++++++++++++++++------ fs/stat.c | 39 ++++++++- include/linux/fs.h | 30 +++++++ include/trace/events/timestamp.h | 97 ++++++++++++++++++++++ 4 files changed, 306 insertions(+), 28 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 5d2b0dfe48c3..12790a26102c 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -62,6 +62,8 @@ 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); +/* Don't send out a ctime lower than this (modulo backward clock jumps). */ +static __cacheline_aligned_in_smp ktime_t ctime_floor; /* * Empty aops. Can be used for the cases where the user does not * define any of the address_space operations. @@ -2077,19 +2079,86 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/* + * The coarse-grained clock ticks once per jiffy (every 2ms or so). If the + * current floor is >6ms in the future, assume that the clock has jumped + * backward. + */ +#define CTIME_FLOOR_MAX_NS 6000000 + +/** + * coarse_ctime - return the current coarse-grained time + * @floor: current ctime_floor value + * + * Get the coarse-grained time, and then determine whether to + * return it or the current floor value. Returns the later of the + * floor and coarse grained time, unless the floor value is too + * far into the future. If that happens, assume the clock has jumped + * backward, and that the floor should be ignored. + */ +static ktime_t coarse_ctime(ktime_t floor) +{ + ktime_t now = ktime_get_coarse_real() & ~I_CTIME_QUERIED; + + /* If coarse time is already newer, return that */ + if (ktime_before(floor, now)) + return now; + + /* Ensure floor is not _too_ far in the future */ + if (ktime_after(floor, now + CTIME_FLOOR_MAX_NS)) + return now; + + return 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 ctime, floor = smp_load_acquire(&ctime_floor); + ktime_t now = coarse_ctime(floor); + struct timespec64 now_ts = ktime_to_timespec64(now); + + if (!is_mgtime(inode)) + goto out; + + /* If nothing has queried it, then coarse time is fine */ + ctime = smp_load_acquire(&inode->__i_ctime); + if (ctime & I_CTIME_QUERIED) { + /* + * If there is no apparent change, then + * get a fine-grained timestamp. + */ + if ((now | I_CTIME_QUERIED) == ctime) { + ktime_get_real_ts64(&now_ts); + now_ts.tv_nsec &= ~I_CTIME_QUERIED; + } + } +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)) @@ -2485,25 +2554,6 @@ 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_get_ctime - fetch the current ctime from the inode * @inode: inode from which to fetch ctime @@ -2518,12 +2568,18 @@ struct timespec64 inode_get_ctime(const struct inode *inode) { ktime_t ctime = inode->__i_ctime; + if (is_mgtime(inode)) + ctime &= ~I_CTIME_QUERIED; return ktime_to_timespec64(ctime); } EXPORT_SYMBOL(inode_get_ctime); struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) { + trace_inode_set_ctime_to_ts(inode, &ts); + + if (is_mgtime(inode)) + ts.tv_nsec &= ~I_CTIME_QUERIED; inode->__i_ctime = ktime_set(ts.tv_sec, ts.tv_nsec); trace_inode_set_ctime_to_ts(inode, &ts); return ts; @@ -2535,14 +2591,74 @@ EXPORT_SYMBOL(inode_set_ctime_to_ts); * @inode: inode * * Set the inode->i_ctime to the current value for the inode. Returns - * the current value that was assigned to i_ctime. + * the current value that was assigned to i_ctime. If this is a not + * multigrain inode, then we just set it to whatever the coarse time 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. 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 ctime, now, cur, floor = smp_load_acquire(&ctime_floor); + + 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)) { + inode->__i_ctime = now; + 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. + */ + ctime = smp_load_acquire(&inode->__i_ctime); + if ((ctime & I_CTIME_QUERIED) && !ktime_after(now, ctime & ~I_CTIME_QUERIED)) { + ktime_t old; + + /* Get a fine-grained time */ + now = ktime_get_real() & ~I_CTIME_QUERIED; + + /* + * If the cmpxchg works, we take the new floor value. If + * not, then that means that someone else changed it after we + * fetched it but before we got here. That value is just + * as good, so keep it. + */ + old = cmpxchg(&ctime_floor, floor, now); + trace_ctime_floor_update(inode, floor, now, old); + if (old != floor) + now = old; + } +retry: + /* Try to swap the ctime into place. */ + cur = cmpxchg(&inode->__i_ctime, ctime, now); + trace_ctime_inode_update(inode, ctime, now, cur); + + /* If swap occurred, then we're done */ + if (cur != ctime) { + /* + * 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 (!(ctime & I_CTIME_QUERIED) && (ctime | I_CTIME_QUERIED) == cur) { + ctime = cur; + goto retry; + } + /* Otherwise, take the new ctime */ + now = cur & ~I_CTIME_QUERIED; + } +out: + return timestamp_truncate(ktime_to_timespec64(now), inode); } EXPORT_SYMBOL(inode_set_ctime_current); diff --git a/fs/stat.c b/fs/stat.c index 6f65b3456cad..7e9bd16b553b 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -22,10 +22,39 @@ #include #include +#include #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_long_t *pc = (atomic_long_t *)&inode->__i_ctime; + + /* 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.tv_sec = inode->i_mtime_sec; + stat->mtime.tv_nsec = inode->i_mtime_nsec; + stat->ctime = ktime_to_timespec64(atomic_long_fetch_or(I_CTIME_QUERIED, pc) & + ~I_CTIME_QUERIED); + trace_fill_mg_cmtime(inode, atomic_long_read(pc)); +} +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 +87,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 8e271c9e4a00..8601425ac249 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1608,6 +1608,23 @@ 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. + * + * We use the least significant bit of the ktime_t to track the QUERIED + * flag. This means that filesystems with multigrain timestamps effectively + * have 2ns resolution for the ctime, even if they advertise 1ns s_time_gran. + */ +#define I_CTIME_QUERIED (1LL) + +static inline bool is_mgtime(const struct inode *inode); + struct timespec64 inode_get_ctime(const struct inode *inode); struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts); @@ -2477,6 +2494,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; @@ -2500,6 +2518,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)); @@ -3234,6 +3263,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); diff --git a/include/trace/events/timestamp.h b/include/trace/events/timestamp.h index 35ff875d3800..1f71738aa38c 100644 --- a/include/trace/events/timestamp.h +++ b/include/trace/events/timestamp.h @@ -8,6 +8,78 @@ #include #include +TRACE_EVENT(ctime_floor_update, + TP_PROTO(struct inode *inode, + ktime_t old, + ktime_t new, + ktime_t cur), + + TP_ARGS(inode, old, new, cur), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(ktime_t, old) + __field(ktime_t, new) + __field(ktime_t, cur) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->old = old; + __entry->new = new; + __entry->cur = cur; + ), + + TP_printk("ino=%d:%d:%lu old=%llu.%lu new=%llu.%lu cur=%llu.%lu swp=%c", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, + ktime_to_timespec64(__entry->old).tv_sec, + ktime_to_timespec64(__entry->old).tv_nsec, + ktime_to_timespec64(__entry->new).tv_sec, + ktime_to_timespec64(__entry->new).tv_nsec, + ktime_to_timespec64(__entry->cur).tv_sec, + ktime_to_timespec64(__entry->cur).tv_nsec, + (__entry->old == __entry->cur) ? 'Y' : 'N' + ) +); + +TRACE_EVENT(ctime_inode_update, + TP_PROTO(struct inode *inode, + ktime_t old, + ktime_t new, + ktime_t cur), + + TP_ARGS(inode, old, new, cur), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(ktime_t, old) + __field(ktime_t, new) + __field(ktime_t, cur) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->old = old; + __entry->new = new; + __entry->cur = cur; + ), + + TP_printk("ino=%d:%d:%ld old=%llu.%ld new=%llu.%ld cur=%llu.%ld swp=%c", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, + ktime_to_timespec64(__entry->old).tv_sec, + ktime_to_timespec64(__entry->old).tv_nsec, + ktime_to_timespec64(__entry->new).tv_sec, + ktime_to_timespec64(__entry->new).tv_nsec, + ktime_to_timespec64(__entry->cur).tv_sec, + ktime_to_timespec64(__entry->cur).tv_nsec, + (__entry->old == __entry->cur ? 'Y' : 'N') + ) +); + TRACE_EVENT(inode_needs_update_time, TP_PROTO(struct inode *inode, struct timespec64 *now, @@ -70,6 +142,31 @@ TRACE_EVENT(inode_set_ctime_to_ts, __entry->ts_sec, __entry->ts_nsec ) ); + +TRACE_EVENT(fill_mg_cmtime, + TP_PROTO(struct inode *inode, + ktime_t ctime), + + TP_ARGS(inode, ctime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(ktime_t, ctime) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->ctime = ctime; + ), + + TP_printk("ino=%d:%d:%ld ctime=%llu.%lu", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, + ktime_to_timespec64(__entry->ctime).tv_sec, + ktime_to_timespec64(__entry->ctime).tv_nsec + ) +); #endif /* _TRACE_TIMESTAMP_H */ /* This part must be outside protection */ From patchwork Mon Jul 1 10:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4440EC2BD09 for ; Mon, 1 Jul 2024 10:27:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 879846B009F; Mon, 1 Jul 2024 06:27:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8029E6B00A1; Mon, 1 Jul 2024 06:27:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E1486B00A2; Mon, 1 Jul 2024 06:27:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 34E236B009F for ; Mon, 1 Jul 2024 06:27:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B1479A1B17 for ; Mon, 1 Jul 2024 10:27:25 +0000 (UTC) X-FDA: 82290806850.29.A160D2A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id 3EAFE180018 for ; Mon, 1 Jul 2024 10:27:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=se0TP++U; spf=pass (imf24.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829633; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v+o9ZKQHoAFrsB1RwNJWn7d7I26VkGC4qWULKLYnDpk=; b=8N9ks8C8ZN9EISh5HitXLm+esPToSBeDi7Ors28ULy3Az7mOQYA76jnYZilOJwLEbp4jxN PxZlED9bSGJzoABKIotyIVL1nRl90s3VPzFxP/faH6JvQcy0OMLPZy+xJdhc3y5IWzlWHN yzKutqgBc+PUABdN91THeKycXewnhys= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=se0TP++U; spf=pass (imf24.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829633; a=rsa-sha256; cv=none; b=qi9Nplc6aa9yUv+ZCoO4/16GfXmCXz3D2HuS3C2lkAwW62Lc/Ghp0zNPZfDEe+/SZEDsTT M6FOT76VBEn6BPQDCIDhMHzztzKMhF//JYwzNKLkk/1cRwiacHaOJ6ZTTB7doHmVGk9U2s ia971/G6LBRLfBNuNyNoBtTwMU598w8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 70636CE1177; Mon, 1 Jul 2024 10:27:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1685C4AF0F; Mon, 1 Jul 2024 10:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829639; bh=JWRcJeXc6fXcX2y9b+IE3C2Bm9hRJGE2VXVsCkiQEEs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=se0TP++UJvdc9tTwQYDWqPXK5SsoCVQEe8u53ed6hPWPwfOgnV88jaGfk7sTo2eXL nRY8Iw2KVokCOgKmtjXDKPs2VPCxAu8K40B7e9mMhjpiFChsUkptNZ24fsETyJsWp7 5D2pKr6uJKJohwPP+TgVb9bw2jPKI/Yo9aiC+RYFhFHGudB/p3G5Ml7axOb0rU+o/w wFDC7qDsqDCY2oZ+aW2yd3pLVq6BOzINc57Ooz542ufQe902LOAsamYyzUvesAO/68 gLkjwevJtszygqTdxvRSNkvVRfseGT4a+O9+IfgapnQnk9HZsFnrF4NiHMXOmaD2Cx ApGhjU0KxyCyA== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:41 -0400 Subject: [PATCH v2 05/11] fs: add percpu counters to count fine vs. coarse timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-5-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2236; i=jlayton@kernel.org; h=from:subject:message-id; bh=JWRcJeXc6fXcX2y9b+IE3C2Bm9hRJGE2VXVsCkiQEEs=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR4nLWjcXTKYRX92RbOTrFgWknM7qS0hOAxr IJZCQkOSZyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeAAKCRAADmhBGVaC FfCmEACKq11QB244lQsJ4wjlEbpNH5+UfFQoAsuVPJp5dxRHy58bwatwzEoStmos+TxpRPReuYO BZjYKqcEMxqby1upgyyi89Q5zEcjY4WURlCYdJljzTmfLmwOxWxQSEPqAnD59ClVzeTCtubwg/9 shcH+Zved1qwW9PV+wgOieb8ctvp5cvV/kLLH4Wf7tHxSELULTrGMj4ZCQnJ/Fwkg78BzW5cSXw MKJM6eQnTkYJ/qtsUFgTTqJVnoAd5GYRkotdtq5qHMu7mpa+kjTA3rRml4h+EprFZ+9KgM7iKn7 BtSyY34jgzUZ7Y7j6mfanIFxe9wKcPN6QJO4xixne5zYaMza+GpFleQdtl5KMqw3qMkR8cJWPVw MUfT4rPv1o6Pwh1fNhqiH1mM2sn3PTbYaYKRzqV1UZg4wdICMImwMvZwQOWS9wtReEdWgUdaFV5 FcbwT2b4VRyf0gmqgjhOH5IcWz5ga4SiIfxyUt6yooXr5maDt+gzF+3d5Iz6FwPZB1opA37HRfO 4lSGU+7r1Mw2ddmhvir8Ou7hyu5rbN3QZtxiqllJUt1EjD74o7zu8+l5kEMUPKh7hyEl0qRrwL2 OtN2Sp+jGr24JxTcjGfdSrCSRgQK8wGLxb91PP9SWu2lTnLgC6ejX/I6eIDgdOwqb8OKfVyiSPW b6R2CXcnj8f+Hfw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3EAFE180018 X-Stat-Signature: qwbdqtnz1oa4ra1w5q9y6jowd53gptuf X-HE-Tag: 1719829642-41372 X-HE-Meta: U2FsdGVkX1+RPvlx7gbBFJvTKmYorSZI73RxedqojypG2QC39pgEj7TuUCKnrexaRZgIJUjOIUmKo64mlZw3WUYcxrrtxlaA1hS1tCmN2LzICvaXprz4xEihkUILnu3AkHHgVP4Xx/IzK/csdf8j3vxPgjVPSXofwWj4uFq0nDDQ9IVIy8BrGbQ7RxH/sOWx+VTuR1clmJcVcrnEhO0X4tDV+Z5v7FdVDBdCcHOx7pnyUPwyJbgvOJKJd46Ne2r4IDNisNkk2i2ArKLAQEVVbp+Eykkf923Ko+ZC5Ha4aOG0KsmqCJ5S6wMam7xXgLV9ZFvRGqKxFjEL8IDjqaHZzP3ofE9eZQShcTs3S9gcT66bobhAy7yCUsRXLPbY7P7akhiCmqPUghrKM8S1cfDP4/VPDASx9Y8ka9uGZfTKNq5TrYq5iKBEGZumUJ73DlsU9JlSeyDVxibTgQqJFNoAxQiF86ZabIy3fyXKZ5MB6FOGgGRFCyhn2JYv0qV863Zz2p3Tu5f5p6spHaibmIaMarIjme+TtQp0O/Eo3qVCsNNBWDP7ZXxL9P3i/tlaP12awtoO1jlybX4ic+EYq6LyjcLoXXXJneEXTI2ko/4Eb+OyLIsgDAwBMF959kMeOc6Qt9yBGKqNjcVzRsaFhGCbUuPFoUQ7oWbERh3EPK/WIVmtrf5LsDSclarA9Mfc+WYBcEPS7OWDuYBZyQzEFzXjeNXxhVBOCRko6mEtH4omsooTZzEwdObVVw5y234hE+hD/YOMf9oz1TehHvQKgOCsde643MJPGKJI46tMdNHMiS6iD02XUOJHTMOm5un8zkp9PcxZQXL33t1jbxXs0EdrO3fFYD1K8oNsKXrlfHZpFsOPwxA51Nj9/aJ62eQPcO1EB+GPKkcjSnVSEmfObpb1AWeFRTaqMjDggYcm+ZEQj3CJDePN/OOudVqYTYDmdH0IYMiNAIMdEe5nFCPdcEI bVxezuZZ zeA7uXufHJlagaN+pnFWaiIQ8PDYuoBuSVlFDlb2Zgf7sK1yae9sqi1ZOXx/1UhVfJjnOH+PbITlsEqHgAh8qlKvJJrQVeqLMov81xJ0676PI8qFpPy2mN4n378z4KRMlosGH1zOWcLep/XO/SSmZakJ+xsJOVlyUKoLWK8mkhH+irQ//0K2wvNGZQsvrxEyExTbSPguWVCu0K8TqF2pjVTRGm7ZEouN3tipOiCyPZE1gZLRQp7Lso8QTSwJognCtJfYxYd8tJHuOd0pVQM/Ikssw9M86Wl6MZjuu X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Keep a pair of percpu counters so we can track what proportion of timestamps is fine-grained. Signed-off-by: Jeff Layton --- fs/inode.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 12790a26102c..5b5a1a8c0bb7 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -64,6 +66,10 @@ static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock); /* Don't send out a ctime lower than this (modulo backward clock jumps). */ static __cacheline_aligned_in_smp ktime_t ctime_floor; + +static struct percpu_counter mg_fine_ts; +static struct percpu_counter mg_coarse_ts; + /* * Empty aops. Can be used for the cases where the user does not * define any of the address_space operations. @@ -2636,6 +2642,9 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) trace_ctime_floor_update(inode, floor, now, old); if (old != floor) now = old; + percpu_counter_inc(&mg_fine_ts); + } else { + percpu_counter_inc(&mg_coarse_ts); } retry: /* Try to swap the ctime into place. */ @@ -2711,3 +2720,32 @@ 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 fine = percpu_counter_sum(&mg_fine_ts); + u64 coarse = percpu_counter_sum(&mg_coarse_ts); + + seq_printf(s, "%llu %llu\n", fine, coarse); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + int ret = percpu_counter_init(&mg_fine_ts, 0, GFP_KERNEL); + + if (ret) + return ret; + + ret = percpu_counter_init(&mg_coarse_ts, 0, GFP_KERNEL); + if (ret) { + percpu_counter_destroy(&mg_fine_ts); + return ret; + } + + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init); From patchwork Mon Jul 1 10:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98A53C30653 for ; Mon, 1 Jul 2024 10:27:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C776B00A0; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 790966B009F; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56D186B00A0; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2A90B6B009E for ; Mon, 1 Jul 2024 06:27:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DB4ABA46F2 for ; Mon, 1 Jul 2024 10:27:24 +0000 (UTC) X-FDA: 82290806808.29.D076AB5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 1524540014 for ; Mon, 1 Jul 2024 10:27:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rAq/h+Og"; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829621; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bJddfqUYKfPkL5IaapNTI+DPloFTuokezQWldk1boEE=; b=Vs0Ekwm25QoGoMOvZzxvz7nLVATokl2Rh9dq5Ge9TnmlXpAThHEXTMIvjfaia8T+2aMmHv uKfOQy48pDP7Jr7RDVoSSXpWfuMJeNOeXHVG3+lWIe9Ppzh1mUtnFbvIiUTrnTYwB5lXi2 YLv3R8+zaWeZNFZq0Dy7degjht8O45U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829621; a=rsa-sha256; cv=none; b=sNMNfCHr7H08hw+o+HqOiQNc/SZLzH1R7O9wdAHV9mc6+X7sAKbkJVVvtgDCGRDJoYHl0J z6iq2s2L17mdj6Cb9CJgoWG3bG6r/GIb2rWLD0XbWc0JQ01uFuNKIT+eDves7H+JKDncOy O62f+vIVa4oUkzgjW1Awz9OQXriM3a4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rAq/h+Og"; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 44A9A6123E; Mon, 1 Jul 2024 10:27:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07FDAC4AF0E; Mon, 1 Jul 2024 10:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829642; bh=/g1ddIto05q7VUdUuGmHZRulUXiGWzaifPHAIEfpWmk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rAq/h+OgmIHQ3zIMfxX5Nuh5uArKUwvnAQ5rWPuLEqT+4ESYLcn2+s1iNn4IGVUPq N7swqaL3CTB0PdUqHWJ9SubqD3nH71n7W/o1mN29bXoOWHACe4NqegsWU8PiQPR8ah oUEzcWEwpwsJJoDzzvpir8kZH4qbg+7bKMjYC0GxxTnplvJUP02GdTCqqHoOIyJS9c jkWX8+1eDjx7q3QpnEZY3Fb090XnzRKi/KlvE06DyPMUynB3PeuNoYLj2yp4bxxeSe 7361qvaMwFlGPQOD813l+53urert7qzRw8sAwh/N6p7+KS++d/BjFguSwdMj5FW5rn 6L/peMMFmlglQ== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:42 -0400 Subject: [PATCH v2 06/11] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-6-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, 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/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR58LRBm5BdNBCR+TQergAamM4jMJnuDIZZS 0IWUHHOHNWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FZfqD/4vNuUYPBi66c7J5PKDuQoOJPTZ2eyZ2nWW1bPmwywtj35VKbgYYgxU4MJDDMRd64oP3NI 24gdEfnDRr62udorC7vft1gdWkaoEHOgTnIowpeTOif6eWWMfHLtvEf4ufB7qWjv6HiiQXt6FWs XUZE/TixP/ajfJvyLsXnJxY2gl26mob5W3HcHZWs2VjJ01bunCKF9z7SlSzWWjfNpRb9IOIBWTq YQG/90bLm7SLCygE64o8fLAjfPV2/v8/G/aeyGKkKtBdu3Uc7x8Vspwrm/aDlqBRJ1XC98bY4HU s5Fkzi7qN/V+eBZ+4mYBNzd93T+Wx17Ecw11QqmT7ifv/108rmjfo+spE3rMBzVBq2Zh9VZGT7N Qf/+TzlzcpRl7L89fCFtJ76kjXWb2phjeMClxn2lvkJwr9oVjeOJyoKcbw9TeE4FQN3LiYghU2m MwiaGUVHC7njwSvbjhFjnImAoEXZGyQs+9yYCyhPxzsFxWyCWxzh2hXqNUUhM7k12s1X3SWZT8o CbHvLMVs0MUFu8ac/a2pNs9d1acf5vTsZw0KmsivcZhL7pAJHfWDUYamlJaQXAIL2q4lDHL4uTk CtMaR4MfeiwBBJ24nwgCpUftL1f/t6d1Z7o72PuSUKGqurGllmzX/bG3Ine+IKa1KwQeqhuiGDk UId2Z/axztB/vFw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: ksx9g398i38ps6b7a4hjg8ucf3o5wz8u X-Rspamd-Queue-Id: 1524540014 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719829642-378419 X-HE-Meta: U2FsdGVkX19WCKOeXUBkLXVgusKcNhi9tVhgJziQgfUxtTDrsxRPw4vw1Qj/7dcD9M2siSleqTHJtoYXNN12SoI0bFPjNJcP+tBgqV0A6W73/IMGIsxydD3kouAQT2kS5wdQENidzUWwgRJ/rKB0unP4uCt3Smi7ruGCfJ8m+qnZOGFqrpZ9tHRCrlYHMIMx5kBEOxiQR1jdYjMIM6wJsOpP5giishDBufCZR/MuB5Q3u2icVqbhzPHXZV3U+dwGpS+r1nSzHiBlei4RWeQEulA2xfIyjKBosLh4vI0Yg57Ixeaz8IKXVjQzWrpG0zcXmw9NBkkRK0Vo8xAVgAhUgFzDJuX5u8BSMOxk8gUksupXHF+wVSWcK4RoayJi112aK9eUdhgI7nwopN8Gt0HFx80dUNq5rnwescM0x5jBmMhdelfIwh7YSi715qVPwHa8qC8MOIFi9b2KNDM/Mrb7URaY9AgdLPky1jEH8/aUPFuNTXbt3NiihkD0E2Rcn8nCZyvVfQVRAfU5djOSHMciaenkmAr4R8kCZ6rczeF4T+XAfXKX83Ye1Pdwh4b19FCFzuz/h9THvHy47Atdb48gwhz5I7610nY90GqG9VNckSLP0BHRz/n1WuollM6fCX2Kan3DpoRfDtwACYrrQdDVFAU7yIvH4iaDR7agjpBt2anyrxECK6hLnyn9g25l7usIbQvaA+3lYxAbnYgO8C2ZzaSGAaVsIaXroQp8X5E8hfXzPiLRSCGFffzSSFDipPPJmdSgH6wNufOry5oMCCwBey67j+rRCaNwCVlwKXy4o/FqYksVAsZnZSyFk22HmJeRg9dv94PujpakKlf43oyRfSiPn3p8wVuwLn5f2VoUCQ7PIMrk2RET+6yPVekia3Uw3UW++cC+efba/zl5jXpP9+BJzGAPdayAeNEi5tDO7LDAcb057M/RJJn2uc+gPAPWMGqdesH5UVJ+ootCOK7 1NdPI55L wJZ5SMA7PVyJOMfJZzWQfNsWfglKvWG/oJt3Koy3yLvwJcRwiDqJx93Y1Jfz3ls6qUfdj0AH6pDIsgeE6Bd2o1UWTQIrJ2CioHjKXq+m8gPjlYf5VfQJ7WNvPJ37P+u+LO7KQ8UPDvc04Q+zUzImDD8IpmLWcTrRE+yWsDt0NPHbdRr+s53CZ1QLIEfKWsc309xWktuoxCBRN8QPvPvYWlvnGI0t3TF39a3OciFHvQN9WWfG9mzOKuYRJwL4+5ELDoV+TLJJV0hugFF08LuByTaIWRkxls0jqiraDXJ0dRLHm5gdx7oLHEXkDFak5RV0Sn9BQfIN4gFDgRmtYAvxbX/fRU5Y+ywrfVp3i0Y/atURuLMSYTj7XJo6bc+1q5rV6MaG389/TuGbaQEQb57uP6f8JPeX07feK5T1z X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The setattr codepath is still using coarse-grained timestamps, even on multigrain filesystems. To fix this, we need to fetch the timestamp for ctime updates later, at the point where the assignment occurs in setattr_copy. On a multigrain inode, ignore the ia_ctime in the attrs, and always update the ctime to the current clock value. Update the atime and mtime with the same value (if needed) unless they are being set to other specific values, a'la utimes(). Note that we don't want to do this universally however, as some filesystems (e.g. most networked fs) want to do an explicit update elsewhere before updating the local inode. Signed-off-by: Jeff Layton --- fs/attr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 825007d5cda4..e03ea6951864 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -271,6 +271,42 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset) } EXPORT_SYMBOL(inode_newsize_ok); +/** + * setattr_copy_mgtime - update timestamps for mgtime inodes + * @inode: inode timestamps to be updated + * @attr: attrs for the update + * + * With multigrain timestamps, we need to take more care to prevent races + * when updating the ctime. Always update the ctime to the very latest + * using the standard mechanism, and use that to populate the atime and + * mtime appropriately (unless we're setting those to specific values). + */ +static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr) +{ + unsigned int ia_valid = attr->ia_valid; + struct timespec64 now; + + /* + * If the ctime isn't being updated then nothing else should be + * either. + */ + if (!(ia_valid & ATTR_CTIME)) { + WARN_ON_ONCE(ia_valid & (ATTR_ATIME|ATTR_MTIME)); + return; + } + + now = inode_set_ctime_current(inode); + if (ia_valid & ATTR_ATIME_SET) + inode_set_atime_to_ts(inode, attr->ia_atime); + else if (ia_valid & ATTR_ATIME) + inode_set_atime_to_ts(inode, now); + + if (ia_valid & ATTR_MTIME_SET) + inode_set_mtime_to_ts(inode, attr->ia_mtime); + else if (ia_valid & ATTR_MTIME) + inode_set_mtime_to_ts(inode, now); +} + /** * setattr_copy - copy simple metadata updates into the generic inode * @idmap: idmap of the mount the inode was found from @@ -303,12 +339,6 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, i_uid_update(idmap, attr, inode); i_gid_update(idmap, attr, inode); - if (ia_valid & ATTR_ATIME) - inode_set_atime_to_ts(inode, attr->ia_atime); - if (ia_valid & ATTR_MTIME) - inode_set_mtime_to_ts(inode, attr->ia_mtime); - if (ia_valid & ATTR_CTIME) - inode_set_ctime_to_ts(inode, attr->ia_ctime); if (ia_valid & ATTR_MODE) { umode_t mode = attr->ia_mode; if (!in_group_or_capable(idmap, inode, @@ -316,6 +346,16 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, mode &= ~S_ISGID; inode->i_mode = mode; } + + if (is_mgtime(inode)) + return setattr_copy_mgtime(inode, attr); + + if (ia_valid & ATTR_ATIME) + inode_set_atime_to_ts(inode, attr->ia_atime); + if (ia_valid & ATTR_MTIME) + inode_set_mtime_to_ts(inode, attr->ia_mtime); + if (ia_valid & ATTR_CTIME) + inode_set_ctime_to_ts(inode, attr->ia_ctime); } EXPORT_SYMBOL(setattr_copy); From patchwork Mon Jul 1 10:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 206F6C2BD09 for ; Mon, 1 Jul 2024 10:27:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0ADC6B00A1; Mon, 1 Jul 2024 06:27:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6B666B00A2; Mon, 1 Jul 2024 06:27:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C21EF6B00A3; Mon, 1 Jul 2024 06:27:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 97A526B00A1 for ; Mon, 1 Jul 2024 06:27:27 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5301840CEA for ; Mon, 1 Jul 2024 10:27:27 +0000 (UTC) X-FDA: 82290806934.01.28D66C3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 8647514000F for ; Mon, 1 Jul 2024 10:27:25 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hoIm8fOx; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829635; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mHBJ8P9xJvRjsbven5uK4O/4I8I92/ECjqgL0Z/oVQk=; b=MlcwUkO6QC/orJIXUk5pKd8DWpEDrg0tcHhTaMhL89oNIaK4GalNlP7PiC+aTOg+N/sctg H+WE020meSc1TveXmZBaIuPcd55uMULsy3sdOTn718aF561IhT3YaVxjXr8MFVBJJ+k2QC POWHlutNOL0Wgs1UKuqmNGVFzG1x2Lg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hoIm8fOx; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829635; a=rsa-sha256; cv=none; b=vAssCGCBeUKW2E0qrg2lTUwxta06xvYWGiOGJZRd/BivEEm8fjFBpo7Ii4ninaqFvtSbfu UkjZHqWvf3yy+8BmaRCY2Kx2/QoRmO5T2Y9gXF8jdiYomWq+XckdcfNkLcnzRTmRL92Fq8 Dm+iFZHROFbMwL3rJc1bOYpAyFflMVY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B1A0E6123B; Mon, 1 Jul 2024 10:27:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52682C4AF0F; Mon, 1 Jul 2024 10:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829644; bh=3rezV2gQwo9fH4xuVx823NKSfsCiMN8Xp4bd4oV0yb0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hoIm8fOxvgPzmo513dFHVds836zgUfxrxsfezK27z2Kntr3Ccg5rPlRJS/pcuTFaQ G7nswzIu1YimZVBpLt7tQ5R6wV/HnPx6uLZf2soZ9CDKUEiM1HbqumyTLOAtAhGSRs dAzFAeU98Qt38QvyoEzTu/NUkjoaSl8SMygT6pZqJFR3L1IXv5HQ2CPufxSzjXBgK4 y+fhw2lAgFR8p1dCadTicB4AiZjS+CB1XRhJmPjezrEVQzpECRnkbNrXvLSLiaWrTA +NkFzxvPw1OLI07XYsbox0HFVMI4AW4yn/F3tEhNy5CEavJdxRJGiMM+3aQGUlhlSp 6PPMnfpqL+M8Q== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:43 -0400 Subject: [PATCH v2 07/11] xfs: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-7-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2415; i=jlayton@kernel.org; h=from:subject:message-id; bh=3rezV2gQwo9fH4xuVx823NKSfsCiMN8Xp4bd4oV0yb0=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR5cLVAd2Hpbh4iHcyU1JIMfk9nPcm3mtCez brvBsNENdSJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FVuvEACzNm2qzQAUpqWzHATLlmoRJtc4IZ3mD7e7Bpup8hkgbhrDAgwtnQCYG0W5P2FN/cXmVsw zLsXXNiPYrqBbATGE2FHsw2iBydcNbvaPxYDojlywTrFteA37WCi+soABdZFVqKaOrVaBOPUnA5 0npisxHrgjo9W63WFyx5QLiSpgFeyM17enz9GcvZneZ/HCWhuMXzSYX3PzHd6/FItgPPkKtNR9F sfVySvNN7gK0odlL+SqL5MZxRTwuj1YttI5LFVFKHuw2ZBiK3bTEJyjMP02m1+5k1+CbyK0zp0r 3RQ23HKGay9iepHvC2vmOw6KQ5RnjOmQbD+GDcMk/MRdqHlaA0alZzkRXWavm3tY9XhiFdYYsHr 4h40PaUS88k65gTxfRuFtWa5Jb6EAbqbc8+9K6QqRQSb+NO0NLYId1Ve9d9bJgX90gIGLPgaA6j 0xo5VWm1MWykp8P3s5K7wpq7N24n1FSfiQRV9UcuxEJnMUSzYXCUVUV5iV6U0IAUk0guo4ZG6R9 Zjt5n2+lNT/NTiPXdBt7ur8Vkv/7xEPcvxYMrFzGIWnytjQymhLP8/CEynyegdHuYsHNPmE1GrQ 0Cg/YRge7xgE1ii5QZT7ZYm/ReayNUa/gZpM2Sk9TAWeLP+hK8GmiNIVrO7vRiEEbwbZW1sCWqs ddQnOafv9nKh8dA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8647514000F X-Stat-Signature: 7gjft4an8a9zyzs6um7h6eme8sw93zkb X-HE-Tag: 1719829645-712264 X-HE-Meta: U2FsdGVkX19pB9jSvFefBUonTqjfJQPRjK8BJCsrl5SIGkWtcXV3S03Q1nO06hJiNQVhwNLtlwK51ObE0ibP7N12QkI0wWgOKCAagFEPCtvpe5K+T9ya3Skvi3vZCnAdBy/CcI1W6BARFFz8DTW56SduZ5iCFda1rKpcVQywcsmljliS2/7GQkA6ourA+/EyUsmZrgTglRmbd6J34zTa+BSXePwNVuQDuJn3Rl+Kxm95vE6CNp6BaVtd+EoYPSmSg79juTqMGYZInPggqbO/KoWkPIeu7FvWJI28qvoh4W25zJ1PwmZ86Kgr6r9QuNpvJAgTxbxumF6MHR3w4tcwZ7Qxrzpusdq1jj7K6sx+AfUbH8n6cKn9tha/bdQ3/+mGqxKJ2JFYhZUu3pBWr4e/EO969NRUTpjyHYyd4/yG6hqGBSqn/PbyA9qoMVZQNltoshKoYRgZDcfpgx45cGJlGC0HWiP4Woj0yNRv1loVn0VK7ZlwMT1xhRP8tmyg+GiirLXESpuy4SkS4jA5wSJ3YF/aOMjPck0OxJbJYNz36DFa7yQ7VOvwYQMjHhc6gyTAWmmw6KwuKUV/enZBCca3H4RNIsRaMjBHVSBn59bEeMKsX9XjhVUg3Ou71QTTe2q70MKTOhRL1TqokX+RT48YwK0whbPJtSV7M1ScuVv2zkApYILfuAfGvr1TssZgidu4jNl3KnDKPmVevw88ybU0XTXRLxlEfEs3W4USM9rdK/P18mSaKN72z7bT0X3WD3TmNI/EqAHL2dfFg6dyw/nKCrA1NHOnLS967ifb9jpf1d7mFfUtWAE3K7/PLoRimNBhSZDVgj8uq/AMW07UNTEkbbTuC6t5XGQNsEsAZ8uM4gGRiqfFyoqOQ3A2ly36De8B46YZfKC9yrImMbAjdsbnLqjHu9YykREsOACkHkfgwR/EoJDREFEsJbGWXkO6BNl0VM4qnHYfhMAy2Y20F/T sRIPpaMy qEACTDv+b/pSmY0MVCs4IND5mdoB958B3ZF/jGroBJHh5T7f5aNuWtRcJJD/jEHSKfLwxUQwFZ+MoyTf1RMx08jPdTYDR+77y2kZM4gOs3Oxp7QXhSNoIRPaaXx2yfVAbQHRC8p3+POTz09N87G5LMuhxuqTG+FXpOeWbrT5WmqO3gh/9aVF91t8cMU262M9bBELv7m990WXcXBOGYalVEkanpyy21V/d/JbMcZ1bWc+kN4AvnPYDuj+Vy1i7W7qAKrBDMt+sytEGEhiYLim8NSb1mofBLp5Quvs7K5fY0pEaMfG8KawBnzXJc9ywEcfB+fj2RQ8GBkyNZVWuw6y3+DU0BFfxdCFf9XehYcO2eZSY/l2VesExtF22JA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Also, anytime the mtime changes, the ctime must also change, and those are now the only two options for xfs_trans_ichgtime. Have that function unconditionally bump the ctime, and ASSERT that XFS_ICHGTIME_CHG is always set. Signed-off-by: Jeff Layton --- fs/xfs/libxfs/xfs_trans_inode.c | 6 +++--- fs/xfs/xfs_iops.c | 6 ++++-- fs/xfs/xfs_super.c | 2 +- 3 files changed, 8 insertions(+), 6 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 ff222827e550..ed6e6d9507df 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -590,10 +590,12 @@ 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)) { if (request_mask & STATX_BTIME) { stat->result_mask |= STATX_BTIME; 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 1 10:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7E6BC2BD09 for ; Mon, 1 Jul 2024 10:27:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 177BA6B00A4; Mon, 1 Jul 2024 06:27:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B49D6B00A5; Mon, 1 Jul 2024 06:27:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA9886B00A7; Mon, 1 Jul 2024 06:27:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AD8546B00A4 for ; Mon, 1 Jul 2024 06:27:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 31AD881A7A for ; Mon, 1 Jul 2024 10:27:33 +0000 (UTC) X-FDA: 82290807186.16.FF96327 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 271D84001C for ; Mon, 1 Jul 2024 10:27:29 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OowJhdWf; spf=pass (imf11.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829640; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wFi9VCa4KervgflwMUv/qihS+sFTtts0CvoK0wS/B+8=; b=Y4oTfzvJ3YfW0fKafUGuhgM2jNWzk+3aDioGAgSKBXOSxnwM/O65GA05GV/2ZaMAi5iWlP 9EzblqZG2YselFOCUde/d+aotAtx41RfUKwV4E4lAo6pie2WohuWQuXUUM6mB3g4uEAfQa wuAKdxkgOzO05KiefERoNPkYscmumGI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OowJhdWf; spf=pass (imf11.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829640; a=rsa-sha256; cv=none; b=jxQUoXloOCfkKYuvItVH8OfFEohly8PZ9fUTMXDriH1wEDHIo4RdJGaHZPBoQo/nPHfpAS b4MTTj5VWzue+CL9pogqzzAJ19wag6jnn7sVsQOw+5q09P/nUK7Wd4n2ff2TkJfAM4sKzm vU0bv/AmxatfJVCnnsItpiS4yf5u/GE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 62278CE1173; Mon, 1 Jul 2024 10:27:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FE45C116B1; Mon, 1 Jul 2024 10:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829646; bh=Rk22CdrDmdQOqV9B263elJ8j6v40sRU7F5SFeqVcw0c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OowJhdWfVqPKKEzYltDwB3xDFDzgsyHuZVnZFzyVf+NMt7lTQ5Xc0tuog3yyfc7ig sTzsTHcSwUnEVnS/lAS8fq3DlhpJXutHyVEQhawSqrWfPNa4nSVTJ4duw3FZDlzJmZ 208icB/wfSVQYNHoz3qgs76HcEVXAx47suT211oSvJKgZkF+DhjT/hwRXWQrOcFMIw /yDzneIZdAfeh+wno6J5k9/ixaEKqGn/02aVR05iSEdWW0ltLmB1hurn9sOluDtEcL 8qMhhXlOYebsXL49jTYC7zgsbjEJj8uiT4Ua+TgTzyOvdBSXN/c5JTqnhMBaP/XZCe kwwaYTUjo9RZg== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:44 -0400 Subject: [PATCH v2 08/11] ext4: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-8-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, 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=Rk22CdrDmdQOqV9B263elJ8j6v40sRU7F5SFeqVcw0c=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR5dUKZAApA/E/nRf8PhsAANcOPXvLXNU/zT iYd1qkDzC+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FSUID/9d0pO7TT9EGNH/i9za9KrWODEB5zSIIaRqI/95Bt/pwLRRr2KYiuSXiRv3RRAWDn1GijG LTSMRD7kVqDNCR6uPWUO5INXMOYvfypXN5mxWWXaPFsp5j6TPDOcsE6Kbf/vCDDGwmIEZZtqAqD CAw8fVNdszgTykJEVngG4sJ7q3c0pIZoDtuiwe8L+krK3SUU4amjj1u8rOGG7z0fDzftIqvknf9 Ke5a1qn+cWa/DgnKPmJVhSGoY2EMvu5fELrasSun90ERTY3dS/87GUcUNY1WryIbebedaVKi6s3 9uVrCQUygyJzW5INth1pNMSMSitS7QN2F3rKFxQaImISFY3Pvi0i5MvXsIbwUuEMDEixB/rmLd/ axKEm6rFltjfvlmWe/VVV/H4fBXv3hhDIT2ZaT/i5rwIdghM8DaGOmiJYjvb4UgHUB3nScbdyWf vloMf0oOIBm1hrE0kSS2xbHYIBZAPyqlq0utguPUKPpyEn8dCBjVsS6lolhydeU+RyeLXYpLV9y rEvrmE5tDwSsi++UlMtX8LxIQgIq6corJIikLnTLC/wOfqqglaQqKYKu9FtUrh8NvTbe4hNgjTG 3mgzSVxouLdteOhi11js/IIAU4lbcillebCeDLZZlqo0+7lXdoK5oYdXeNAygZ0fjpPrLg2R/Vy 8S5NgQBdXHroK6A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 271D84001C X-Stat-Signature: ok7abiu1wtfane7bzxsmh1zfntd9ktbs X-HE-Tag: 1719829649-431580 X-HE-Meta: U2FsdGVkX18P6NQbuTuB4WOcT3HsSN07lZdg7uAQl8G5OespkA3xLSDfiWDYZdhowgf4fzOEUelrs+VsrPm2C2QYyWs8is4S9RjDO5wdDev3ZuOxk6zAwzly5CISpDMQSBp7hgql5WuOJDcpE+zVmrkwG11+jlL0NsyJJXezp/fHdPmsOupkkYD3FYfE+f19YSmghLAJnDRAxYRxtOnYn0Lz9FtUQBzVYr6ndTJtFvG57Q60bJD0blE6o92xiQpZ5U/jm+qAv/MByIxZyuQLfysW+RJ6baw9llPL/Xhb9ozpeJZkSI8jpLFI61DjtNlz298Zr2zga1kICs5BoFhEFELOe6+22c3zAAsLqClbiKABzqk2kvQeCitEmsrTlvZXSTqQR1gn/OcEYMmF/5lPB/xbEAlfBV3RKkVKKotN43x0q9zoMgshnmJ2cGyr2j43cVpOdBc96Ol5ecCwNHRg2Xa/cq9HaOLz+ZWddIspqqp9P+MN0ki/HOpMvjHIwYIJjzOXG4eR2hmZQ2qLBihPFxU++3qWzE6S4hD/43X9ZgYPZb6qhEFi8dU4ogPDru2s//G1BaUdhJsCg97P0bc/OeE230FMZClqHuRPY/75PGnv8t14JHCurQg0sKEREaQwFTDfvGqzf49tmy8zJGxsjBMT7x2un2Fh6oXUNoRod7eeiEUt3AOg5YI7KqwL8ZWpq+dS5NvEHCe9Y1hnW2p7PL08eQ1+0s12P7QBi68y/6zInnVKzRobNh8RojffIxDeOrQHn+nlKJhPNkzPzagO5/fbrU2cW7vy/8KnAn8IQzQc1AI1EHFnaOgTw9YgIQP2peTAR0nmbUPy5Mlde5HvkJxOeDxCaM54KJLenwMzSjj2zKNYfMVjuBq+WaxF85bQHUWj1ZZQ2TetctGLVjHrAb0DIUv3A2WXnxwoxWgK/0yG7jmNxoKkMzWZ1aoumUNw0Dn0UBiCjAKNCZYnowd Do91tKn8 CLIhFwljXGpYIWYW0hFBafUk8NpK8pFfhdjDRqaOaqoOvx5hsYOhjfmbRLgs5YBZt4PL3iYXi8XTcosguyYGFYOnZT/5+t82ljPy+ZcErXffx9hBw48Hj6S2E+NI2xEGgbyVG0pbR5e48NzDuQzwLaGtJwS2CBzCAASpDjkP+bvNz4/KtVMElAZgsKkjrg4pAulj9ITeRofZ2/nkNlDCJmiijVyVG38xc4ple2fzcyc0YYM2ZZ/+suTGhP8aQZ/EKUUDBXpput+1k59wdwYhBgo9CxSZiEHeI6wMW9KdOy2rS1aAEMYkWLxYmZdhlCLBbcWEHYkf22Y/ENqMv3V/JOjnNYxjtw+ge8Ojg2I5zZGiXROE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. For ext4, we only need to enable the FS_MGTIME flag. 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 c682fb927b64..9ae48763f81f 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7310,7 +7310,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 1 10:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6224C2BD09 for ; Mon, 1 Jul 2024 10:27:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C7A26B00A3; Mon, 1 Jul 2024 06:27:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 851EA6B00A4; Mon, 1 Jul 2024 06:27:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A4066B00A5; Mon, 1 Jul 2024 06:27:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3DFC46B00A3 for ; Mon, 1 Jul 2024 06:27:32 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 069DBA1AFE for ; Mon, 1 Jul 2024 10:27:32 +0000 (UTC) X-FDA: 82290807144.28.AB0C2F5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 319F480027 for ; Mon, 1 Jul 2024 10:27:29 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LcqTr9O6; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829639; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vKAahAF2yw27HeBezw4hEaA+QpmJvd8GztLdofMDzIY=; b=s/Nmdr2UnwIgje9W/uQRqKXN7uJ/5AKPhgRsYYFjqF1FoejDo79KysFwIsIC/OD621aGec d6+ZEDwluAhFk8CmPXCLLp+U1Z8HYzuak5oTml/jbkVlEu+QVflnpKN2BV5r+2L0cIa9I9 uGIUdBv/Vn8nkhDfFabLP5P5Hnt0xHA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LcqTr9O6; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829639; a=rsa-sha256; cv=none; b=3vkenSHwPMQVfgsXObXEoPVe5rkpkDuMc3FtglA6OBmx2nNbJePzIK95dX20j8HoBNqE27 oejMZ4Vb/8j2Qh17tfx9ilteAysME1YBbDa1RzyNn02voRGXyeU6VF4zo97ULwu+gtZa1L Smj42lZu0zvYk+cP69ucxa06aSk8/No= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 583CD61221; Mon, 1 Jul 2024 10:27:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE85CC4AF11; Mon, 1 Jul 2024 10:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829649; bh=g6LPjexoZumsLrWQmoQEww6pUVCduYJaKswCWiwjKIg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LcqTr9O6d73yjRPzUOQt3rFcYTBLQZMcbUK8iYcP0QWHG/g9apYIn6p+aPj98OQdG rNXNotsR7h9h6k8c1SI4yOe5w0A0j+DDcUNf2hjfMX0rD6+VnFCDs/XMqHp5IOXSwY MiM+/js9xsFoC9dOVgDc5Y76poHyippIMejuCSnh6YSg00N4x13bd8/Od3DQeIicxR 7F2g+c0OuLfAim7geGIXUUjXgw1MibgvZONgzODpNaUvIefre84JqgqeoPJoZ3Mq1E T6hpFcS96P98iish5/M1eh2SynsIcqr00bNy745ZsMcZyzX57sj2rtNbsM4zP7SGO3 /RjdT8MeQ9q2Q== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:45 -0400 Subject: [PATCH v2 09/11] btrfs: convert to multigrain timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-9-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2439; i=jlayton@kernel.org; h=from:subject:message-id; bh=g6LPjexoZumsLrWQmoQEww6pUVCduYJaKswCWiwjKIg=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR5peVlEh/9fCIgBmWdUayZz1OsZCQEyAymb qH/Z9hlOVmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FZICD/9SQ9g5VLi8qohQ4mJbihBrn0jgzZ/fl6AyCHsI1a+lsfbbpF7BFpvr29WWehMrohSp1dS qEuFGmBwGI/Sm/T+rIO8cqXV9AQlIDd3ePLCO/XWOjPN0CGPLvhGF4ywT1j9MQ+HJn0zUp+kyL0 4GOEv5aXE3X4GZCnxcSG/kDucEjIf5oajhC3l0Kwh+/7QjT783shrSn1OCK57izMhMaqGMrunrV icbjNokBR8s6eM9NlX5IecTBDuPwIG9OBc/15k2tyDsiSj6gISY4GHtI9QL5XQzvEZEe+dejQyR XoV63JJZkCKSJVOKE9+alHFA8EIDroXQt70LTLuWnzB9ROfaOIku11h0/C5Pd6zFVgsEPQS22ay N9NXud7se+TdCm2czPGP+WeSNF4YH0AoDB4ihXIPcob180XPVfNI5s/dOsCBBOel4ym1IvUyEZd 9a2IZOzRMZt29IiEB2VEK8BEVVF2DVBFvS2Ve9EhgrhkHT1LZoHI37sdn2Jt3BPf1TTTFqobHHH EVDpkOTsHyU4PZBc0cBaG7iU7+xU+HPx5xi+mrpJSQtpJNXN84yEVgFP8ctA3tG6XTQHcSJbpLS 2mT2UwJiFyz0LRQkvrrhS6vR/wCODRLMTTFjNIE3zDMrAy1Tn5vWkcaky13cdpTs+uCjtGEnHsm sX/vCHXB2Caf2CQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 319F480027 X-Stat-Signature: wjtdgf3djexyzdhhibprberd857oetqg X-HE-Tag: 1719829649-724300 X-HE-Meta: U2FsdGVkX1+s+fJGjG1JkUTEWMnwomm31pOLraiqFkaLx2ckQCDujgD2JZT1EhGga0e7BwNyNIWqgaQbMl5Kxg/8/eHJtRX4Otv8Yb6DP+gs2MNqwO7O2rEZTSmyF/IoVdKPa9mn5rPhI/DwsEhaZaHEXv9Rn5O8zXuMql8n3+p3J/UYLfAHVXR6DANAwsqHrWqB7imb3H6svLzemIxwABhvSPqO4eDG9CwFhR3R/2Eu7Rb22fZXs0vVuIm8D3pFjeEiPf4DnlBSlB3b09iwE2PWeBPM/JNktwL8HBWUwD6IxyWsIqkJlHKTalWNSHPmsVBzfbFonkr6xK2zjqhqrRASsla/ulsphF/g5PTEDwxIrycxsYtQx4cykMCuBblyfkt5YQh+hX8kB/kI+31AVwvzV7lJRrHMaqScvRuxpZKP2SK0fVgn3ZjaIPxIPWpKocGSVixey9GRKXsb1EwQ3luUr6Ybpd3pSygn044NYQLP3L/KANMo/KE44HNFRtKqVBziwGM4BtnQtKfFP4jX/NsEAS0QDWWeUaOEuRYJKb9mmJXPEB0v/xOmTgeDGe5Zyn5/MaHBQVdxAqvswLDY0HMcdhO9OgLcu/hP9C21x2ymIlzhrFqJ3RNmyiyYvFVVD7vkKYoXgmWDOYPa+lfjnj/5eoYyhxzB3cAGZlqz5/ej92xDXI+2k2fHTgDH/g6CuiEHPD5t6oTVpwwQ979RcYDmjurlyhlefgseauGsHr+Pl5W+GsJpDFG1RToxw8X0+4+zSSMZ5Ckq7KOUstJ97JQUN8ndDscuBi24/9sz5HL5QSRAlXhS4r3rEBHYGnrIuSa8oVTaLgZ7bkk4L9kWZipkHketRfSQiKjpuRLa0TI5vA26jzbkxSIjHQsTnU8iRDSOY+2ARe8WMPEBJM3/1VeJgqFeEPaadYTRAWSyUThvMuLIc1LiuUGGCsJUSi0nBLLOS4cW1/UlS0oqDP1 CCp6L2Eo mPkn2lT2DXVyi3lFn8rm9Av5h3VxMZ5roSj0vCWnH0Iz+xSIBCY2XyoYW+PNSpGxeRMXZp/6NcbS0gaS66SJXJT8b4k+ehIhpeDZk1tD/u3QA8lgA8QwqcOi91ZpfaCYu0qluk/OgMJQw5lC9dnKHaRCRcyE5w6/X21/L5mKoATi/DDItS41zLJbpnbh99JSqzwj29niCUeqBscQAaVy8zF5KP8JKQDzcnb13VxGtE9y5czR5kIZvk+Ps8BRJ7u/nKDGIGHqgf78BXD/V5BpyCONGNcdUR2W9xHtLVjRNQkfmef+5KHOfOHCHQP7gCzh9STyE2s6UNi/EeU5zb4Z0slfIv2A5VWMhC9sgS6KmLzRhN+k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Beyond enabling the FS_MGTIME flag, this patch eliminates update_time_for_write, which goes to great pains to avoid in-memory stores. Just have it overwrite the timestamps unconditionally. 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 1 10:26:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04D58C2BD09 for ; Mon, 1 Jul 2024 10:27:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAAA06B00A9; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0A7E6B00AA; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B36646B00AB; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8772D6B00A9 for ; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 425F9C06D6 for ; Mon, 1 Jul 2024 10:27:37 +0000 (UTC) X-FDA: 82290807354.04.46F72D7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id CE1C914000F for ; Mon, 1 Jul 2024 10:27:34 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CbCgOOtC; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829634; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pR/Gkm0utwNa5sGsytl8cKxQyTuRFBeyECBZJeS4fRY=; b=eWHNdAakxkif8o5oW4yLW94PmesN/gb8rS2yRQNs1Qeu+wIeTVGMgs5zFd1Yymuqay/P3Z BrJ7P72xMPOamts2FNKTq3Q7PzgZv9wyUiBSFErEwI9rrMHru/0UACjoTOJoadzlMDgo6e yZZYF0C3p3X2iy4Wxjb1oxN2QeYzooA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829634; a=rsa-sha256; cv=none; b=nLRIIiAFzVXsZ392Ye/NwvhQQjTqwVZphOdFF2oGMs3+X32T8eC5os3Yyicm2KFcdYo/vi W1CN98wXOnYvKdnVEVCCuBGh0imqawM5NjYvIPxWKeTywq/H0WJFB2kJJjT6KhmwLWl1Kf eV6qXE0fGROTI5fS4qf7xusiDCIwUKA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CbCgOOtC; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 0826ECE0F31; Mon, 1 Jul 2024 10:27:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47338C4AF0C; Mon, 1 Jul 2024 10:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829651; bh=jBp9emvazqFESk9G7QwGGoZvRRiz39syH6qfqPr/6xQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CbCgOOtCgUjRuhHIWfPhLp3fatj5tSfEke2ujk22gomfJxaHjykanHdCLJsVPENww 2aXenQM8IIxPiVGUyt0GORcZ46T9nxZTtaoeuMzgsm0o3GEGcpZjgTtzXmmKT1cm6m paG8e/3l7XyGgoXks1x9hsLuZTQIQ9WQ+d11FHIuP3WkhBypQ+Xs80Y6c+rvklcoyf XB8iYZErJozXyVqVesry5IgFJWyVHnECAiVfCO5V1zTVGWxTQGpfiFfPzBdGxr0/xD NiLrOWZX710iSvmB+1ivdK4CDLwx28tslbEbRW7GPmgFXcwRIU2sWF9bY5cDeu7lSo DWDIWNVIC/gdA== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:46 -0400 Subject: [PATCH v2 10/11] tmpfs: add support for multigrain timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-10-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, 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=jBp9emvazqFESk9G7QwGGoZvRRiz39syH6qfqPr/6xQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR5DeUDlpeVrrOk9nljfFxINKx8vAHQj6+ym pt0XVjbScaJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FQ4KEAC7+XATsQb1o9n+cr8hbr/gERAz5tQsrEdtwYNRSvbbaYxIt5s/AYE4ciw0lt0bl434GRB 9LRV0yRq0wV3vI8lfLFfplAztGqVXE6BMg4WTH6etk66sx8D1Objgt7jyaDYUNAWjRjkwKTh26D /eLu4mVHkMzueOfI0DtfM9U6DhTwTOAhSHj5SKw9BrNiwNEvfOwuMS2rNx5xOAk0bIsCc6zUDsU OofZ/0TrsSd5jEvY+JXK871Q2ZOYcBbki7pVhHbNJcviwvBCa1DlSiqhzp2+syH7dGvjxWyTQ7O UUayRkml6sjLFWnGzUKGDR2WNHTVlJObHQvzuElRDK+m9jJSck/6KA/mVrtF3Vp/5y8Y19uc+gs 1Gcmh3yjdhp0Q6roRW4tl4J5AYxO/xVnUF/Dw73sLkMmZl32xuCIva8Kwg71aqqEfnTd8twX2bp X3W0nsg9fUiQJ5PgB/r/+IebovLu5sn3XaOlGN9//EQFD73PWzCRl1Hm9oppgPWK0DrQI0PwNhQ gQFFa8W8IeZRaUTIRo8vYdBENdYU7UTeW0R+a3aduMYkonp7z3CUtwhKk3/QDFEmFRvl5YaYJdV QFwXrAsHexrEk0N7gn/NqHuh/K4IujwcOfcF6b4xmMmaQqsBReLMbGaNf6c1TFMWP83vRfKduyA wR49eVH/7rg3m+Q== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CE1C914000F X-Stat-Signature: i49sj9mq5tr1i13ia7nt8qhwkk7r87w5 X-HE-Tag: 1719829654-46286 X-HE-Meta: U2FsdGVkX196WBB0IglPV6W2wurMvbOMcAgRXuPg/k/NlBHeKdKdGR30YwdxqcHy9jThg1nzxTXSGfEu1PeqfNUC4gowKuqdKAqwDUiHcf0rwZl3T+TvEDptH4kUoPtUyiIMIbIU/y+7PmwcLZ83xnTx+yixLCVDbRrAl0j7CJHbGRQbiVbiIQlOCYriQSAhnVhCmkcVlqxFJHXfSDkkqprFszx7oxdeM2Bg2sq7DLYWRkqWgXmV2sLr9xp8ONlJ9wEY6f/wXeeyhCeyPhD+fI+aZsjwxSWOV6/YtlHiA61ngpuuHERnHUy7gFISroGf642MZIcWYpLB9aTJT/eHWdZP7uPlhGpYXvFmczPaTnXhcuP69hjgLCtK/bT/9x04upnm0hDLimVFSn1DxWManCW0SZuBDRvrnAplz36hQ0hHkYCIYlIPykn3JIWKnRmtflyB4WC2XznZgUbRJCaxqxB+GYzYm/HgSjZbmsVa0yxsOJhNj4I9u7EG4FyVbFFiyqopJWA3WR1/ak+yPAIKNQyyFuB002FsXi6zlpR4dDaqdvbYRRqTYiaH8/diafIn6ryvu/FLLsHsXLZzu+NOgvkBRXY82mNuMrjU/NAZk+xc5MmRlHdTSG4IFZq+GKaR2uqH9v9Epgmh0weVomDOV7DhuJcg3v5faEVoKRtQuKS5rM/NjnT4+tDrRHTE3PjMhGuv6dPH7ntKqRJRSeTl93WR+avSPtOWWRx0HlpTtKtFg6x5NOWiVV33l3oPfmF2MLrzHqakHyUz8583UHBDmQ/JLOVnSb7Qb1tQqyo1arUgfijGorCWf7GWfh/ymYaU9P0KooBEri2T3MJKWsDqHUwuRR9BdNqiNZ/UWxYC3eLd+YMqpZa9vf8tYWyJQqImUPhsEwRD/Nld5/MBYUxZozcWTmKQ+6UUxsbEAu39B72/zFEhCYofw7zAbOgd80d/r37gBMCrTallsb1LPQf aUuqRafd EB36Ii0O7pK51HH7835Lw2cUBzQ68fkcOvMIbXyd5bMh3Hr/ZJ6wZ38gMnKhil+1AmPRAlIbg4Lt5T22iAj4JK+XT/fESFLt/0bBvu6mcsdmh1Ba7VriMCo2GPTOOh6FTnoSFbWVmHhjoSJBUVORbF+40ZHvtQXlonhUIPMh2wMpfULR0WRuZuA9q506cg+XJrafs1bC9aUjhVJsOlZfPOPHOKQI/oazgz310l2nqDHIlsKLcFMzXyADhrRiI0kSnm625yFENmvj6tr5RwmAbHmc5FU2XHym09+PccZR2TbjnoCZm95tahDmVFNuq0T9sFNt50VvSBxeP430aC5iW/amGkPuSylLmgHNo9kPutXM5U1s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. tmpfs only requires the FS_MGTIME flag. 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 8cdd27db042b..60a8e05eed34 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4653,7 +4653,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) From patchwork Mon Jul 1 10:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13717790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72D5FC2BD09 for ; Mon, 1 Jul 2024 10:27:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BCC46B00A8; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52C996B00A9; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34AEB6B00AA; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0C77A6B00A8 for ; Mon, 1 Jul 2024 06:27:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7933A141A96 for ; Mon, 1 Jul 2024 10:27:36 +0000 (UTC) X-FDA: 82290807312.08.CBF16E4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id 9DC2BC000F for ; Mon, 1 Jul 2024 10:27:34 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Z6GNnASo; spf=pass (imf10.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719829633; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kwSCAOyZ+m+4B8m+nFVNQ68+e+AZDelUT9qN4fhek+E=; b=rlX2gozQH1/te8l/46sdo6Hi/+FTn017DFvAi2U5zfWtZUDCgYXDjnxbwyNRH2iZO7bhN3 Gts6dytXWDZqXFaIHTCCzCJOtyfiM6qlq/PYf1DFJ6RcxT81/NAWXEHZ0CLQkqzbuWugfH 9jGV9XS+Iec+4ejkHanetKqwkWyriNA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719829633; a=rsa-sha256; cv=none; b=3l0eCakSyebyJJvobM4MDW6fw7f+GDfQWtAGEapDy4Qc7y3F12SSS0aOpav8IRR6om8o5e CjQ7JofgNuZb7dHb0mvUIA+GX00Jzc4U1Cvdz3CgqwHDQXpmAOzHImvhfEmOeDpP9nFBA7 xIYvnBYzua4nd5jozdw9hmTS6GtmlCQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Z6GNnASo; spf=pass (imf10.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D15F861221; Mon, 1 Jul 2024 10:27:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 947F5C116B1; Mon, 1 Jul 2024 10:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719829653; bh=yGbFoI0x64Criq5hVXpnf8cTDkEYS+drfXiF9/4UXTc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Z6GNnASo0fot0PtERrcGCWLqCNkhG+ti+9IgcG2z62xbIC1ym5I817maTy4fkKhbY R2soLnBsN9ntBuRXtGUYtbUxBrvdurk/E0KX7EbbDmjOFHzMmSyo90wX0FwClonR8X P4RBkhzh+f0YRGrqIUSoKG7uVfAoeaEL0Ss0NQOw6/1RUJIexOvqBArjV7Pm3HKK+T ELGB782hclQDbjeAOXe38I7SPtwUvE2y977540crj+h57ilap+jopmlWAGnCDy6jcC lu8QPn3FZYpTj4N486u8gYzuOufgDmx/UFNBSoDMzdpGwk8GFl1VmaMqBSCpZXUEsG h//393LSr0nGQ== From: Jeff Layton Date: Mon, 01 Jul 2024 06:26:47 -0400 Subject: [PATCH v2 11/11] Documentation: add a new file documenting multigrain timestamps MIME-Version: 1.0 Message-Id: <20240701-mgtime-v2-11-19d412a940d9@kernel.org> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> In-Reply-To: <20240701-mgtime-v2-0-19d412a940d9@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 Cc: Andi Kleen , 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, Jeff Layton X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6401; i=jlayton@kernel.org; h=from:subject:message-id; bh=yGbFoI0x64Criq5hVXpnf8cTDkEYS+drfXiF9/4UXTc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBmgoR51H+Vt+Exq9KPckzpWSJI72DyZw39g58HZ 6vgl2QTkO+JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZoKEeQAKCRAADmhBGVaC FUgRD/9lsIjZK2rTJJTMM0K7QsIaOP3fGuxn3FJzgS/8fA0BxnWEFHyOjfHbW7G8Pk2e7T3FUtF eRaFdjrKm58/m+Pri5Gimbl9u0L3k8bs3OwWdfEHjjd3vY8dBeCHDYsyOOU96h0C8YAeLXYKW7v awrdt160eBzPfrVCLR+PYf0Nr2R5N1w4tTp8UCEaSy8BhOhiWHE5yEU+0dILaoEVaKub1bwYVjV mPVEWbsALVgC3JDWdkI4JTid9yXq+2fKgyT8ZRN9DuQqtfhetl6akwSxiTy2ZhYjQWXn4MwseN+ Sl42qLYCNzrpb+I3GsuPzd4w3YrijPaS2vDQ82BPfRbQqqj+64kR1zd/yjaqoWMcp0YB5VEUnGO l8uyRah0FF1rQNatV4c+a/SpXu1jdNXXtOG6rlSN+0Vih1+1Q/miYBQH6ApBVf+QJxDKzXW10YR ywIi+5WIwTwVnTTUoJdTzKDyW7vSlMCR/n50SSiuX9vYI7wm5/wi5HL/+KT5Idgv29ro6UPca5C tuQZld6B1HnPwUHD0E34Slj4q9H2YbmDz2UYLavQK9GWVOSWvyVApcHSF74iwlV6XMnozuLwVRs iOP1aC1GI5fBD0AJrcgAxYw/xjmU0slyWE7EPk6otXIYcdc4Qrgc4cWAu3TP2Cu6Kw7o6A269Hq VCQ37btdGTtuEEA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9DC2BC000F X-Stat-Signature: n19hxf5ry6bpfz6e1e1gqqwzy4tf3osd X-HE-Tag: 1719829654-820123 X-HE-Meta: U2FsdGVkX1+pkzGnevoAvDY8aKdRXFuFSE5ZGspjSiIdp1Bhc2r/2bOc81Omoj1gEfuwsvemtBwBYW7WjMCmH3XTfMCr+qdYeBIA/0kjeoyeni8ONHPs0JSN1y3oN7jbElDP1mla/kvf/lp+iq/37BE9blfM+6zBv1SbY/BiO0mfR3x412a/7ldWhzLSvT9rPByt8CVeBh2KEwvaXH7XMyHbQQnKf2SDPnG27ZPSamnrsXTF9wHlYhNOuIdpH1ZDoiI3JpW7Fy77UixdV7pThNhvTiK/MPwPPiBfWALrvRxy/2gT1H5Kjn7jF6suyMK7EgLnKowyXqgSxhpWnnqd1PDxeVmL/OWDrhNnsZO3rRN2HVijrMRR39mlGSDub4c9f0Ih+2YQCvvPnQ29WbgfTBczh8y67HMsPPXKa/ndRDWBAVwUj7OS8VsdCHRyfnLGaJ8dHtTHTIVt7ohC68L1bw4qVyPfbrqfn8MKT6lw9BGEUd6f9q2gFPYKoukOB9EhUQuqGWDDtFLdNcYJQqpeCovlePfG7jofi2V/9BvLnN0NIccUr8zKCNNs45oCc7szxen37nWFm6o8wHYJANOj6h4jZYpT+TiMMArXvz92g2qB72u4d1XsS7aXp7T0kyn8YEkr+DUyPeeoKBdPdUD+B3MLX/5D1MhkURo3u9sl8aV3Fa3C2PhUcRRkbyGVt3mwKMrWN0Jdc/P3zf522YOaG+TAFOKKKptWvsHFpHM3QgLBqeg+dr6OZA0yKvIf+d3Qr9Arh8nxLK2p+H4U9Va9QtdiI5EedO75ByFlNAb6LYwRj3vQiirXpo8w7P+VtNlOwE0L6NzpCf4HZrfh0AfcRHHCEFslR/NOCIMng0dG3/ERgglhm1/CQ4WQfAnVzURbRBMaQy4thoWlQzMK8+8m10lb1h87OSx9VSBRvN/o7h4luos+4aRvWaUIKsOvAdh4RZ/wNcfTTLWKx8X7+x+ ZYeBg1fY 4C8O6IUMXUMG4mSIOrf6JDB9PJi49NHScVN0ME51fxThbsJCWeh1cnKsou+wlMS+g+YUiuYFXE0ump8KY5kPhsEjqzSEV4aMF3a6sJd5mY+eR/VVbKOdDR429rLCHLVs3ClRPkf6beBkZRhgt5mjAPWIK2THIMq2l1PKNhvkV+Vw/JdpN5LnilLAUva2RMyz23FKnzFWxN0Gv9MuN3CQ6rrk3LphoUp5FhjOoWJlvtucSmKWCMgFHOml0LA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a high-level document that describes how multigrain timestamps work, rationale for them, and some info about implementation and tradeoffs. Signed-off-by: Jeff Layton --- Documentation/filesystems/multigrain-ts.rst | 126 ++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst new file mode 100644 index 000000000000..beef7f79108c --- /dev/null +++ b/Documentation/filesystems/multigrain-ts.rst @@ -0,0 +1,126 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +Multigrain Timestamps +===================== + +Introduction +============ +Historically, the kernel has always used a coarse time values to stamp +inodes. This value is updated on every jiffy, so any change that happens +within that jiffy will end up with the same timestamp. + +When the kernel goes to stamp an inode (due to a read or write), it first gets +the current time and then compares it to the existing timestamp(s) to see +whether anything will change. If nothing changed, then it can avoid updating +the inode's metadata. + +Coarse timestamps are therefore good from a performance standpoint, since they +reduce the need for metadata updates, but bad from the standpoint of +determining whether anything has changed, since a lot of things can happen in a +jiffy. + +They are particularly troublesome with NFSv3, where unchanging timestamps can +make it difficult to tell whether to invalidate caches. NFSv4 provides a +dedicated change attribute that should always show a visible change, but not +all filesystems implement this properly, and many just populating this with +the ctime. + +Multigrain timestamps aim to remedy this by selectively using fine-grained +timestamps when a file has had its timestamps queried recently, and the current +coarse-grained time does not cause a change. + +Inode Timestamps +================ +There are currently 3 timestamps in the inode that are updated to the current +wallclock time on different activity: + +ctime: + The inode change time. This is stamped with the current time whenever + the inode's metadata is changed. Note that this value is not settable + from userland. + +mtime: + The inode modification time. This is stamped with the current time + any time a file's contents change. + +atime: + The inode access time. This is stamped whenever an inode's contents are + read. Widely considered to be a terrible mistake. Usually avoided with + options like noatime or relatime. + +Updating the mtime always implies a change to the ctime, but updating the +atime due to a read request does not. + +Multigrain timestamps are only tracked for the ctime and the mtime. atimes are +not affected and always use the coarse-grained value (subject to the floor). + +Inode Timestamp Ordering +======================== + +In addition just providing info about changes to individual files, file +timestamps also serve an important purpose in applications like "make". These +programs measure timestamps in order to determine whether source files might be +newer than cached objects. + +Userland applications like make can only determine ordering based on +operational boundaries. For a syscall those are the syscall entry and exit +points. For io_uring or nfsd operations, that's the request submission and +response. In the case of concurrent operations, userland can make no +determination about the order in which things will occur. + +For instance, if a single thread modifies one file, and then another file in +sequence, the second file must show an equal or later mtime than the first. The +same is true if two threads are issuing similar operations that do not overlap +in time. + +If however, two threads have racing syscalls that overlap in time, then there +is no such guarantee, and the second file may appear to have been modified +before, after or at the same time as the first, regardless of which one was +submitted first. + +Multigrain Timestamps +===================== +Multigrain timestamps are aimed at ensuring that changes to a single file are +always recognizeable, without violating the ordering guarantees when multiple +different files are modified. This affects the mtime and the ctime, but the +atime will always use coarse-grained timestamps. + +It uses the lowest-order bit in the timestamp as a flag that indicates whether +the mtime or ctime have 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 per-time_namespace 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. + +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. + +Caveats +======= +The main sacrifice is the lowest bit in the ctime's field, since that's +where the flag is stored. Thus, timestamps presented by multigrain enabled +filesystems will always have an even tv_nsec value (since the lowest bit +is masked off).