From patchwork Wed Oct 18 17:41:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4959720vqb; Wed, 18 Oct 2023 10:42:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDCvl+cvf6gzuLEJ8AZVJ4DvtqNsB8lIfpE4cSlSjlg/L+3Zltr89B0vfBzrZ93M3cVTVw X-Received: by 2002:a17:90b:2d8a:b0:27c:ed3f:a73c with SMTP id sj10-20020a17090b2d8a00b0027ced3fa73cmr5203361pjb.42.1697650937444; Wed, 18 Oct 2023 10:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650937; cv=none; d=google.com; s=arc-20160816; b=zyO3qERHFRCc7zri3zfYufV50jJvOJQ6A9o11r/ycVVnlXOkHZ9wljK90xNV/v84em 5PgrC1c0EkFB/QPL+oFAAq8XNyzUoSpodV9/IhxxpenEF7YWSoZSqVAH4Cf1FDs+T1S6 mKJpvTc9RonY3aSPS+fr3E2rUrmBRQTwcGhqMkXDHjAJ3XVY56ab6S9We8t//mRf2RC8 9nELTpDJ7IrseeeTJI2jQF8Xmxw72/nAIoPYN4kEj0bHFqG/HO8GnJqwst3pQrS+SZQc DlyDVWa6hivlUly9KVizHNtmrO+9CbAbaJSNoSabZ2/TR5+OWr8C+prEYerQykfVWxeH uUAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=kTpF+NdChHFSpVpycDabsrC9jci3YAdosloac/EWD5M=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=QY65R4e4yckRqqAfZR8L6xoPSUGLEa/Bpi3EeNvrBSObsZQzaHV/WmcRYgAvN3E/n1 ogWIe9ZHJ3HDbKiolkPSGbq7g/YzCaZ8PYGO359Vgtrg4LtM4Jxlz56hBUtdUvHDU121 b4O5e/JHhu55UTaeZOM9BsyL2JzivywOkM1KXe7+3O/AMa1zD+yX+Aw18LWSf0ehs4hl Zf23iTYRA/esDUeVYKAYrBcEMxoE29GFYXnXEwYK51rHLuJr0zSvwZJKvo5iIDxyT4Sy vS1qlSOP8AaxmAwYPHXgzB14T61m2f/OjWtGJ653znJSIvK3D2vjDX8nDcJggZNFnljY DhcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vHqr3PeT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id nu10-20020a17090b1b0a00b0027dbf69ec11si282479pjb.160.2023.10.18.10.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:42:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vHqr3PeT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7A50982291BC; Wed, 18 Oct 2023 10:42:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231441AbjJRRlq (ORCPT + 24 others); Wed, 18 Oct 2023 13:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbjJRRlh (ORCPT ); Wed, 18 Oct 2023 13:41:37 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EDED11C; Wed, 18 Oct 2023 10:41:34 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0865C433CD; Wed, 18 Oct 2023 17:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650894; bh=jWmZ1Ravl5cu/wOo4Bog6k1d+CwyPST2G6rAUV4ZYAc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vHqr3PeTFpDRNPF3idVxxCdnb1iVi0NE8DkKoUZrVcZEfyflEgmWCoz3c30QBIYgV QHUjC6yzrdbgCryMrV/z8AraieOhCmp5ydSy1Jlqy/frfz3I7YSKlgI5kDCw9W9L0G 6wdcPzpynxo6jrP6c7EPrU4xUvOBBF8acqKT80+bwKIiWoG+0FKGZn2rspmzYEp5Uw yczqNkmwK3PiefZQP5RsLlEHZJRaSQCGu1OYDHgU58+Yl+kixzJq6GJmgUYJk5WB9q jGypQFbK++CbII2WD5VXoDWHRSnbQ9wKs9T6uoUfg0c1QygVUa4DSDyJFGF5QUtR0X akQ1ufOzxnSZQ== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:08 -0400 Subject: [PATCH RFC 1/9] fs: switch timespec64 fields in inode to discrete integers MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-1-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4674; i=jlayton@kernel.org; h=from:subject:message-id; bh=jWmZ1Ravl5cu/wOo4Bog6k1d+CwyPST2G6rAUV4ZYAc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjIMZMk9hA0a0rbXtgzOBS8+JUCWebR2P/8J wgnb+onjoOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyAAKCRAADmhBGVaC FRN4D/4hg/46V/lM9F5UuttDEfFBixG4KR0EymQEurGFApb4lySZ+KxbxVkqAm7IyL+FGAaylWc HWdk3vSQOpB0wg/2wS4ymKQcXH85SVmR/9XEb7cwkGmGji5l1IRuyksbprbUJUoYrd74o3VwZ2J FGfFODjJ1z2g8QOi+FPBhSrHSMPe6a+6t1RhTll6jSfUaLC5mT72UQKVTqezrCk3c7BrDg7wF8W P3sKppsD3IboBFnqLbTs+9FMukgmOdVC5ot278zCccIfSVSTWJov4PuYGZGg2sxnKJHL00sXNzC UpTPwBA06FEZnVVSubHR+v91WVQ9P8C7VgWnpAkNm0CuuoNGtBmtvA7dEM95ePdvysiYdTNgfbL lw9ll9YwoDxfKsgg8rC6dm6qHAEDZ4d2yBpi2ytPeV6cosMnf7ABN6v1L7saN4C9DAj43QdvZ0L NI9Sf0xSeBKtgKlsAkaKw1vFv9SxFWOvRLr06pyTa7aogQymJeKR714W1uy52Hb7lXCTSQGiDqt LBOBs244/a4JkQg0YfaivbgWS4haeHjH/Tc/YCT7wc6YGa+dUSQIviYyiczEXqT1Xvim3WEL+vK QXaNIVewLajwOQrViIMfh0wl3NievUibTIxrqaKsoZH9/zvSBivCwxyjO+SU5bOzzJvjm6OM1Zz MO1qldTLt22SnAw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:42:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116029384005535 X-GMAIL-MSGID: 1780116029384005535 This shaves 8 bytes off struct inode with a garden-variety Fedora Kconfig, but it moves the i_lock into the previous cacheline, away from the fields it protects. To remedy that, move the i_generation just after the nanosecond fields, which moves the 4 byte hole down next to i_fsnotify_mask. Suggested-by: Linus Torvalds Suggested-by: Amir Goldstein Signed-off-by: Jeff Layton --- include/linux/fs.h | 56 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index cc29518517f7..78786c1c32fd 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -671,9 +671,13 @@ struct inode { }; dev_t i_rdev; loff_t i_size; - struct timespec64 __i_atime; - struct timespec64 __i_mtime; - struct timespec64 __i_ctime; /* use inode_*_ctime accessors! */ + 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; spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes; u8 i_blkbits; @@ -730,10 +734,10 @@ struct inode { unsigned i_dir_seq; }; - __u32 i_generation; #ifdef CONFIG_FSNOTIFY __u32 i_fsnotify_mask; /* all events this inode cares about */ + /* 32bit hole reserved for expanding i_fsnotify_mask to 64bit */ struct fsnotify_mark_connector __rcu *i_fsnotify_marks; #endif @@ -1513,23 +1517,27 @@ struct timespec64 inode_set_ctime_current(struct inode *inode); static inline time64_t inode_get_atime_sec(const struct inode *inode) { - return inode->__i_atime.tv_sec; + return inode->i_atime_sec; } static inline long inode_get_atime_nsec(const struct inode *inode) { - return inode->__i_atime.tv_nsec; + return inode->i_atime_nsec; } static inline struct timespec64 inode_get_atime(const struct inode *inode) { - return inode->__i_atime; + struct timespec64 ts = { .tv_sec = inode_get_atime_sec(inode), + .tv_nsec = inode_get_atime_nsec(inode) }; + + return ts; } static inline struct timespec64 inode_set_atime_to_ts(struct inode *inode, struct timespec64 ts) { - inode->__i_atime = ts; + inode->i_atime_sec = ts.tv_sec; + inode->i_atime_nsec = ts.tv_nsec; return ts; } @@ -1538,28 +1546,32 @@ static inline struct timespec64 inode_set_atime(struct inode *inode, { struct timespec64 ts = { .tv_sec = sec, .tv_nsec = nsec }; + return inode_set_atime_to_ts(inode, ts); } static inline time64_t inode_get_mtime_sec(const struct inode *inode) { - return inode->__i_mtime.tv_sec; + return inode->i_mtime_sec; } static inline long inode_get_mtime_nsec(const struct inode *inode) { - return inode->__i_mtime.tv_nsec; + return inode->i_mtime_nsec; } static inline struct timespec64 inode_get_mtime(const struct inode *inode) { - return inode->__i_mtime; + struct timespec64 ts = { .tv_sec = inode_get_mtime_sec(inode), + .tv_nsec = inode_get_mtime_nsec(inode) }; + return ts; } static inline struct timespec64 inode_set_mtime_to_ts(struct inode *inode, struct timespec64 ts) { - inode->__i_mtime = ts; + inode->i_mtime_sec = ts.tv_sec; + inode->i_mtime_nsec = ts.tv_nsec; return ts; } @@ -1573,34 +1585,30 @@ static inline struct timespec64 inode_set_mtime(struct inode *inode, static inline time64_t inode_get_ctime_sec(const struct inode *inode) { - return inode->__i_ctime.tv_sec; + return inode->i_ctime_sec; } static inline long inode_get_ctime_nsec(const struct inode *inode) { - return inode->__i_ctime.tv_nsec; + return inode->i_ctime_nsec; } static inline struct timespec64 inode_get_ctime(const struct inode *inode) { - return inode->__i_ctime; + struct timespec64 ts = { .tv_sec = inode_get_ctime_sec(inode), + .tv_nsec = inode_get_ctime_nsec(inode) }; + + return ts; } static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) { - inode->__i_ctime = ts; + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_nsec; return ts; } -/** - * inode_set_ctime - set the ctime in the inode - * @inode: inode in which to set the ctime - * @sec: tv_sec value to set - * @nsec: tv_nsec value to set - * - * Set the ctime in @inode to { @sec, @nsec } - */ static inline struct timespec64 inode_set_ctime(struct inode *inode, time64_t sec, long nsec) { From patchwork Wed Oct 18 17:41:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4959983vqb; Wed, 18 Oct 2023 10:42:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4t8IxH6nNgdGJ0ChhE/om+UyqKIhsizyk3YzGvQFO/saRzwYrOOUQ1YgQ+o5eLpoMx8v8 X-Received: by 2002:a17:902:c101:b0:1bb:6875:5a73 with SMTP id 1-20020a170902c10100b001bb68755a73mr82345pli.2.1697650966449; Wed, 18 Oct 2023 10:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650966; cv=none; d=google.com; s=arc-20160816; b=nwOKNF84rm3HYZWMaSv++Um0mMxBxdOZFfRDEvAo5Q07LClUliH7JlMyR88oXb5qBQ EuPLezWWPb1g2/y5jCTAzyrxQbv31NspHN26ZD8JsLBfSmRmFm8mYqrGAIZpjuDcnCvF zQPFz0/l62kmoKrNlRrGWRl9hn9HQs1zTmIvHkO9mzzAqiU3z5xgThTqH+lGbGoZEYym aK7GHjkIhU8nu5nN8QHCA/LmKIQ+ZX1EGLC0MNjlueRLmr/KyhhqJGoSv0ISUXE1w0R8 rkpK0u81l/DryYsT06xrUAhG+0WnNR3y7n02jftQ2c5BFM83NuymrYAKTPDxjPdakAjD 3QKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=D+VwaeTo/eajohWlryeUF2HdkxnTLV2ePXnC8ux0Ge4=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=LWZvQCKpYuWN9ArTOixSyL/qfIA/1E2eH9IMV2jKITAdt+7OusGOa1iOhLcuQnqbC0 LqucICrt3AwyUwbSIAGKpD794T6S1mh/Sm9aU3vSGvjWPb2z1cgW3z+YGPMoEMb8vvsX Z3vJfgEQK0keL2EnX9cw8+agpk6PAzk23A+mzxP5NM9/mZD1ECutuiJydUXvMooVqi5N k7PawHJBoZB7h2LRE0RV6j0m7WYNJq0O4KEiloZETXgCE1jB/6EZiYEzjL0sDNbPdymP NtF9ZAvd6/g0tLPAu3GeE/FXcfxFF9HiX2VucsIrLa+ONYz+bfU1pGw6h9654v6JY/JB IKww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LUqQBlq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id f14-20020a170902ab8e00b001bde0b58abesi328063plr.161.2023.10.18.10.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:42:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LUqQBlq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B6F9880A64E2; Wed, 18 Oct 2023 10:42:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231767AbjJRRly (ORCPT + 24 others); Wed, 18 Oct 2023 13:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231266AbjJRRli (ORCPT ); Wed, 18 Oct 2023 13:41:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0512A115; Wed, 18 Oct 2023 10:41:37 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BDD8C433C9; Wed, 18 Oct 2023 17:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650896; bh=l0xHAIUUN2BOMaLZLaXQNle/CdEVUPvjoRJwRfogB3k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LUqQBlq5SbTTxc8Kx4I5i/jnPXcg/nEx9UsQqT9B+eDje7FSiAkGbhYGwQRlQFBq5 qVEbFGoYB6HtCUqP3zUIt+ld6j6Qti0Vb6h7iw3F8f44xPv78xT8mBKrr/YGDlufQ9 tndvU4bWohBgShTn/iB4jplkLEklhbyiqF8FTwc8sM4T1UzsplSeCJur567WQZbXkF F3VaIwe+XEc1jHV5/4BFZD6UVt0Ts9otCsK7RVipp0nXKmd8N0NrfkdWxQulPKu5wY MC9cv5D2gqFsKKlnLdO+j02QzxS5+ftCkhlMxWxW+z9Nwcgi51mkMCUSSoD22g8q1W bjWwbHPGI2/yg== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:09 -0400 Subject: [PATCH RFC 2/9] timekeeping: new interfaces for multigrain timestamp handing MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-2-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6981; i=jlayton@kernel.org; h=from:subject:message-id; bh=l0xHAIUUN2BOMaLZLaXQNle/CdEVUPvjoRJwRfogB3k=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjI+0b0/ffAFY3zqBSBgVUVHdNbNXYnmuLk7 4JnuUitV2OJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyAAKCRAADmhBGVaC FQx3EACBnusFhJaHiDBDntSYskmOtKC9J0xUZA3qU6cq1/bt0CXSpLwV13odEIY6OqqXNUiFOeg zPsedjKHT90OgQ9De85Z2zj3ZP2Ne5Pl1IT58xW7uMWIdkIJpJ0CQAO6Ah2MYsDGPZgWIVN5ehL C2FXIHhVCvw0ZpRu96Vcou1wkA+eZuY1ODNnY1Y2It1eKv8HXIeCa6GKqz1YABH/YWpPrF2K4FD FHvvrN04Me65L/xgLUZWs/c9IuR+IkZrM3vzaUBRr2X+JYyj0EsyCiXnStSs5vSeDaJXWdceykW 9td0tzdxB7Q4yGflpOYRwR+awAiWHytZ0pBmzjS/KO33Z8GCtb4Lmt8sIQDddhjn6sPSiO4+CdT pNxkoE9t1KfhEo9ekAhh4WmOcx4HoES1scAKLKN9boy8Ycb+5zSVRj7kVyO3htCXW+4wKBWtRCW tWuN5BDRlluKCBx+7/SVs7BgZOm2FVaN/8mdYyMr3ysA/3zjaUy3yMdsl0WtJirPH6tiByo5VpS 9/68nBxm1oKiI1czGW4mWPuYXe1KWsPLLPKl/c60N/UK2KykHaxDCJIyLh6VSthY/pULGM4XwXq 2JZAYsJOXw/W6f4tmwd1vQ0f2q4ue8FZJV9TLHDbpUUxncalFo2hfgqU5SCX2MttvcncAi33zDG rifmicacYuiP+yg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:42:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116059599079828 X-GMAIL-MSGID: 1780116059599079828 Multigrain timestamps allow VFS to request fine-grained timestamps when there has been recent interest in the file's attributes. Unfortunately, the coarse-grained timestamps can lag the fine-grained ones. A file stamped with a coarse-grained timestamp after one with a fine-grained one can appear to have been modified in reverse order. This is problematic for programs like "make" or "rsync" which depend on being able to compare timestamps between two different inodes. One way to prevent this is to ensure that when we stamp a file with a fine-grained timestamp, that we use that value to establish a floor for any later timestamp update. Add a new mg_nsec field to the timekeeper structure for tracking the nsec value of the most recent multigrain timestamp, along with two new helper functions for fetching coarse and fine grained timestamps. When getting a fine-grained timestamp update the mg_nsec with the value that was fetched via timekeeping_get_ns. When fetching a coarse-grained timestamp, set the mg_nsec to TK_MG_NSEC_IGNORE. When fetching a coarse-grained time for a multigrain timestamp, apply the mg_nsec value if it's not set to TK_MG_NSEC_IGNORE. Signed-off-by: Jeff Layton --- include/linux/timekeeper_internal.h | 2 + include/linux/timekeeping.h | 4 ++ kernel/time/timekeeping.c | 80 +++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h index 84ff2844df2a..6583b06e7d08 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h @@ -55,6 +55,7 @@ struct tk_read_base { * @tai_offset: The current UTC to TAI offset in seconds * @clock_was_set_seq: The sequence number of clock was set events * @cs_was_changed_seq: The sequence number of clocksource change events + * @mg_nsec: Nanosecond delta for multigrain timestamps * @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second * @raw_sec: CLOCK_MONOTONIC_RAW time in seconds * @monotonic_to_boot: CLOCK_MONOTONIC to CLOCK_BOOTTIME offset @@ -110,6 +111,7 @@ struct timekeeper { u64 xtime_interval; s64 xtime_remainder; u64 raw_interval; + u64 mg_nsec; /* The ntp_tick_length() value currently being used. * This cached copy ensures we consistently apply the tick * length for an entire tick, as ntp_tick_length may change diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index fe1e467ba046..5dc0ad619d42 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -44,6 +44,10 @@ extern void ktime_get_real_ts64(struct timespec64 *tv); extern void ktime_get_coarse_ts64(struct timespec64 *ts); extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); +/* multigrain timestamp support */ +void ktime_get_mg_fine_ts64(struct timespec64 *ts); +void ktime_get_mg_coarse_ts64(struct timespec64 *ts); + void getboottime64(struct timespec64 *ts); /* diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 266d02809dbb..7c20c98b1ea8 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -33,6 +33,9 @@ #define TK_MIRROR (1 << 1) #define TK_CLOCK_WAS_SET (1 << 2) +/* When mg_nsec is set to this, ignore it */ +#define TK_MG_NSEC_IGNORE (~(0ULL)) + enum timekeeping_adv_mode { /* Update timekeeper when a tick has passed */ TK_ADV_TICK, @@ -139,6 +142,7 @@ static void tk_set_xtime(struct timekeeper *tk, const struct timespec64 *ts) { tk->xtime_sec = ts->tv_sec; tk->tkr_mono.xtime_nsec = (u64)ts->tv_nsec << tk->tkr_mono.shift; + tk->mg_nsec = TK_MG_NSEC_IGNORE; } static void tk_xtime_add(struct timekeeper *tk, const struct timespec64 *ts) @@ -146,6 +150,7 @@ static void tk_xtime_add(struct timekeeper *tk, const struct timespec64 *ts) tk->xtime_sec += ts->tv_sec; tk->tkr_mono.xtime_nsec += (u64)ts->tv_nsec << tk->tkr_mono.shift; tk_normalize_xtime(tk); + tk->mg_nsec = TK_MG_NSEC_IGNORE; } static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec64 wtm) @@ -1664,6 +1669,7 @@ void __init timekeeping_init(void) tk_setup_internals(tk, clock); tk_set_xtime(tk, &wall_time); + tk->mg_nsec = TK_MG_NSEC_IGNORE; tk->raw_sec = 0; tk_set_wall_to_mono(tk, wall_to_mono); @@ -2283,6 +2289,80 @@ void ktime_get_coarse_ts64(struct timespec64 *ts) } EXPORT_SYMBOL(ktime_get_coarse_ts64); +/** + * ktime_get_mg_fine_ts64 - Returns a fine-grained time of day in a timespec64 + * @ts: pointer to the timespec64 to be set + * + * Multigrain filesystems use a scheme where they use coarse-grained + * timestamps most of the time, but will use a fine-grained timestamp + * if the previous timestamp was queried and the coarse-grained clock + * hasn't ticked yet. + * + * For this case, the caller is requesting a fine-grained timestamp, + * so we must update the sliding mg_nsec value before returning it. This + * ensures that any coarse-grained timestamp updates that occur after + * this won't appear to have occurred before. + * + * Fills in @ts with the current fine-grained time of day, suitable for + * a file timestamp. + */ +void ktime_get_mg_fine_ts64(struct timespec64 *ts) +{ + struct timekeeper *tk = &tk_core.timekeeper; + unsigned long flags; + u32 nsecs; + + WARN_ON(timekeeping_suspended); + + raw_spin_lock_irqsave(&timekeeper_lock, flags); + write_seqcount_begin(&tk_core.seq); + + ts->tv_sec = tk->xtime_sec; + nsecs = timekeeping_get_ns(&tk->tkr_mono); + tk->mg_nsec = nsecs; + + write_seqcount_end(&tk_core.seq); + raw_spin_unlock_irqrestore(&timekeeper_lock, flags); + + ts->tv_nsec = 0; + timespec64_add_ns(ts, nsecs); +} + +/** + * ktime_get_mg_coarse_ts64 - Returns a coarse-grained time of day in a timespec64 + * @ts: pointer to the timespec64 to be set + * + * Multigrain filesystems use a scheme where they use coarse-grained + * timestamps most of the time, but will use a fine-grained timestamp + * if the previous timestamp was queried and the coarse-grained clock + * hasn't ticked yet. + * + * For this case, the caller is requesting a coarse-grained timestamp, + * which will always be equal to or later than the latest fine-grained + * timestamp that has been handed out. + * + * Fills in @ts with the current coarse-grained time of day, suitable + * for a file timestamp. + */ +void ktime_get_mg_coarse_ts64(struct timespec64 *ts) +{ + struct timekeeper *tk = &tk_core.timekeeper; + unsigned int seq; + u64 nsec; + + do { + seq = read_seqcount_begin(&tk_core.seq); + + *ts = tk_xtime(tk); + nsec = tk->mg_nsec; + } while (read_seqcount_retry(&tk_core.seq, seq)); + + if (nsec != TK_MG_NSEC_IGNORE) { + ts->tv_nsec = 0; + timespec64_add_ns(ts, nsec); + } +} + /* * Must hold jiffies_lock */ From patchwork Wed Oct 18 17:41:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4959562vqb; Wed, 18 Oct 2023 10:41:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYCA7567ynbdDlcon9mMTcFqKnLrLrULKnplsQGYUzpH4dBGTU6fNIwNy63EquqTCl6nNV X-Received: by 2002:a05:6359:100e:b0:143:91a2:8e0a with SMTP id ib14-20020a056359100e00b0014391a28e0amr5733621rwb.4.1697650919539; Wed, 18 Oct 2023 10:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650919; cv=none; d=google.com; s=arc-20160816; b=WaCGTJfBGxylHsbckxDeFF+bCh4uA5bmV2PMZ91krFSkTOVszXUBvQgKogYYhhS2+A Dbh+a6nf5sPTCwm989NFl8vG6rpd+y0rWkR46AhJ0PRUx0PYeCtnYOzbv98Rkd5xnXst Dpo2mESEIwPdRcWHcT+PanemCKmGeBAyGRWQI7WM9jh2+ufCjZ7Z3k3/5jg+V6OHzSZB XPgeZsLvuuWSB6GZkkeySCKubHlZFr9Cy3KmfrJCv8Z7El+dYw//K0D9yYkQ2cu1CE0W 7pplRHsWzJjsO7qqXQDdI0DpccEsdUcJCmBzYNX+afk85SuqbEgg1yiORwZ/zfqMyB/J 5LYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=GwidXsdVI70LROKQV78+/AtnjaNX0OCUTFQHQNNMJNo=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=tKEYCpeRtwS8pGBHIqifVleyOMIk0W6XfOhj1YFN75M0axXgOL2jGAZbeU6gAcmOHD wpETzi9NBCK3NagY7O5ePXBB8zEM5PNnOIstKt+DsUNLFxUTYw+a5FHeorl7x2/R/Azq YJcQBnE6EpdRL2pOcRiAyYDt7J3xfKHcWqzSpgS9BTybQrhy7N5k7piRzziftBhmOe/C KP9518+qiCAJVoYraFZE6iyVCquyjfcD4rhvHf6IEP9uFojbtufO9rEs+ylH4TKKsyKd Srq0PIX8ZtlKAt4xjSnemFCUndvplUJL6ABilpa8+znhatnjK9dmC9PBd5HKCbs5tzxj Db6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GcpsqU3P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r4-20020a632b04000000b005a073e0cca1si2624768pgr.512.2023.10.18.10.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:41:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GcpsqU3P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A84D981B93FE; Wed, 18 Oct 2023 10:41:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231300AbjJRRlt (ORCPT + 24 others); Wed, 18 Oct 2023 13:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbjJRRlo (ORCPT ); Wed, 18 Oct 2023 13:41:44 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75A02120; Wed, 18 Oct 2023 10:41:39 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1BBFC433D9; Wed, 18 Oct 2023 17:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650899; bh=oV0lFdI7Yn7QJ5JE87c+C5HW+Uto4gEIDr/OnGVhofo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GcpsqU3PkpNElzrRNZAh3XTjk9L9FU1ZFKJ0Nuy36O4dTnIGzGvLmzqNHSEPu56yj fwpfkupeILBixno66h7UwaC+ESWCL5Mn9+PHSEDIe/d39R2QJtMWQdIk9dtKO+8mBv fs9yJoR0RLy47E5axLbnbDIwRRY/K92Ahi/zp/JiYqTrHQqZBsRgMsLEMiI58WmFY7 CPOULDJXAtNvZY2Y4tUNSA5fdezHHf+X+L8uPAgCasaFp2dpwPzXlw41p5JMyEMgSF V8IDjIp+cpdNbLf2y+84w2Z35QTu7OAnQl+JskaMxc+mKp7GxaRqPDtAUViX1j0jwi 1qYxkdVgrYioQ== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:10 -0400 Subject: [PATCH RFC 3/9] timekeeping: add new debugfs file to count multigrain timestamps MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-3-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2249; i=jlayton@kernel.org; h=from:subject:message-id; bh=oV0lFdI7Yn7QJ5JE87c+C5HW+Uto4gEIDr/OnGVhofo=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjIZJAEh2EvSWsTRIXNUoSp+/gPrdnrW38DM 8NdE4JkFmWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyAAKCRAADmhBGVaC FYbiD/0ZFfWVcuSGUPgSgemJY2MzGuMffXnd/jkl+/NHQ1nlRsWS01DWyVwdWucUQasEC1H0rdI 5uXOT2GcTX/68+GO+2tqvb1JlhSnujcLZm1Lg456xiDlllxlwIhZ9tZrlYVCOrYuP8jEqXYvjZU V+pX3XjE/kpytbDpv4jBNXvd33alsrO1+bznAl0pM2sOm/dVXZQSQ8NYrpztvxjJk5qNLqUPS7Z U77qUZBIXUm2mQR8NpLwL471ld2/NmDB4pWDRjvCl9+E9LUaKW68g5iDdMrP1FYZEgo5nuBug26 G9gk1+WG8MzsHsYFl6ELLbS2zBVqoMtrdqt568EogG7jT0bV9ZMQdIYySUOXW4QYfw8xmG5gMep x76CG8p1DUeFingRztj1TLljnTJOBjvvu6/y4uHysrrk48R5ZJgW10j9GNfzFxlmWLjzROb5uq1 DrLstWJYcyyzYThiFx6ceWhtadCHD8oOozKVH0QwA2Iz6TUjCXq4wmT/TUthsNQ64iTwZKIscuS i8Te9fkr7v+sjrBd7L3KROqoW+H82LEsMIQaJGP7fXOLTpmGndcbF9RRWYs3TY48ha1YUBvq1tG mr5XAlH/ldtbzv9DCdGsn+zCmXwMuFoPEEiGSzhQzKBi1Xi62s7eCGftf2cmFcAvZBqTr8ByLyl avNZl9vDKp3Z4KQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:41:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116010861377739 X-GMAIL-MSGID: 1780116010861377739 Add two percpu counters for tracking multigrain timestamps -- one for coarse-grained timestamps and one for fine-grained ones. Add a new debugfs file for summing them and outputting the result. Signed-off-by: Jeff Layton --- kernel/time/timekeeping.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7c20c98b1ea8..c843838cb643 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "tick-internal.h" #include "ntp_internal.h" @@ -59,6 +61,9 @@ static struct { static struct timekeeper shadow_timekeeper; +struct percpu_counter mg_fine_ts; +struct percpu_counter mg_coarse_ts; + /* flag for if timekeeping is suspended */ int __read_mostly timekeeping_suspended; @@ -2326,6 +2331,7 @@ void ktime_get_mg_fine_ts64(struct timespec64 *ts) ts->tv_nsec = 0; timespec64_add_ns(ts, nsecs); + percpu_counter_inc(&mg_fine_ts); } /** @@ -2361,6 +2367,7 @@ void ktime_get_mg_coarse_ts64(struct timespec64 *ts) ts->tv_nsec = 0; timespec64_add_ns(ts, nsec); } + percpu_counter_inc(&mg_coarse_ts); } /* @@ -2581,3 +2588,33 @@ void hardpps(const struct timespec64 *phase_ts, const struct timespec64 *raw_ts) } EXPORT_SYMBOL(hardpps); #endif /* CONFIG_NTP_PPS */ + +static int fgts_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(fgts); + +static int __init tk_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, &fgts_fops); + return 0; +} +late_initcall(tk_debugfs_init); From patchwork Wed Oct 18 17:41:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4960094vqb; Wed, 18 Oct 2023 10:42:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFf3YADaUC0uc6KT0pxAMws7vUzUxjxAEnHXViWodq9ynZZfGKCgG664e71wiKF++EJYkgZ X-Received: by 2002:a17:902:e88f:b0:1bc:2abb:4e98 with SMTP id w15-20020a170902e88f00b001bc2abb4e98mr57744plg.21.1697650977865; Wed, 18 Oct 2023 10:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650977; cv=none; d=google.com; s=arc-20160816; b=WRj6vlI+/jX6pW/S+l4SSjRnOVgnpWtddCtOinRlkLlZ8vtbgzA6/3EgNMFJEpuwDW wi9F7nJ5ms7+p/5Mj2s4Bp9wyZWGi5mz4fShQc2qwOQLmHDN0hcnJjF0vLdj9EqEUNtj cT4JsiuA1QLsuYKlf97tBN38PLD4B9zZJ5yzoJd2cI48Xm45INHrva3J0YE5qqOu961R 46+ZmkTEckCSvpqeWmSyzaEvJqE77kIzvdObxKtp6QrnWmTdCmEN3HZTS4jB8XBuuFs+ 2WcudTBrEFzwSd9fdncarM230y2wgMuJiuxDV9lRCzNPNKeAHo0jgPoKLb3ma6nz0ZUV Ffww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=GwQsAbGH3uc7Bl5dCiWKou9GmdhON7t4G4zy/6805M4=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=Hzxv+W1098sLPuybwuZZGrP5maKmTnpUUW6wJrVV+Vl1sFwjvQJq4o6GeUYQJ6Cg94 DzgkW+9DDgA81C8JVelQ1BVeys1eQTM0R9us1+IEOTLd9vWNLx5zQ5N3ADhwMfODbWAr zg89QQ4X9DHTlb9dk6j/RP9XjD7hce0b8ASPwWV5mHTiXVLv6JWQQlvdTnX4EbDT5CMy JOSkvpUtLAn89Gcu7FLbmu/ppSRhtVCvHNqSqpvTfTzWqvYlw9eEmEcnNeW0IDvEbSy2 PjYKoevPubZQC1LiuZkJqDq64B0wVC+T1tdyhTofa/ToBtduooC1cF6qwo2p7ffJD9J1 JRZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d4h0E+xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id t21-20020a1709028c9500b001c9ad8ca211si333671plo.18.2023.10.18.10.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d4h0E+xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 0B6AB8020C1E; Wed, 18 Oct 2023 10:42:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbjJRRl6 (ORCPT + 24 others); Wed, 18 Oct 2023 13:41:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231375AbjJRRlp (ORCPT ); Wed, 18 Oct 2023 13:41:45 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ED47126; Wed, 18 Oct 2023 10:41:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ABF6C43391; Wed, 18 Oct 2023 17:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650901; bh=jEQ7N0OK0MX2jE1ssAAhSIOQltyOCrGAcxWFJvttHxI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=d4h0E+xhad+RgIDC/LYSUsIa5OZJ5j1VZUh8b0oRqYs1DhOGl3OteEmsDq5DE6dvU 4jODdH3GMFjFbOdeqzYGxevfpeSYNelEI/oGfYi8x2K6pLMy8V3EXZ1hB7QP6aJU9S DrxIEYOBoLxt+1DaqjAop+cCWxOYoyu0fZw7zUkI0gEjQocsdNCKrwU1uM3eYnxlDK 641zLCYrSN0dRbHy4sq9Biel5ccarDl1Dc/8YnpT8l0a2/E0OmT+0u2PLNfdDkg2k2 hp4P7RsmukdlDjpa0Jpk+rnM3W5E/PVmgXY4MBR7VJiI584Pt1HOL/R2mdMa8S5GML BUotD8r6fTcRA== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:11 -0400 Subject: [PATCH RFC 4/9] fs: add infrastructure for multigrain timestamps MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-4-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10393; i=jlayton@kernel.org; h=from:subject:message-id; bh=jEQ7N0OK0MX2jE1ssAAhSIOQltyOCrGAcxWFJvttHxI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjIl9JU6MnYsWK33IXzvvdM2nG21olQKhWVr 9guhKbXSFmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyAAKCRAADmhBGVaC Fe00EADW88E+J8cw2JT7UsKSwGT9CpnCWkU+Dzs9iIt4AzRJOr48bdUPGk4Ci+js9zF2WLiSpn8 UkapvZkI2z6IhNHLGQwx8/ZTn7wb1Y0YfjThgUw+zvTuGokLT3+U+ccgN3P4QsXmRGRfr44YvPb rqPyYGUuAAlqPU3m7MHwdsADhTP6QsuYNnNK1ZY0QDXVmeIhRhN+ZfLlsIczGcCbJInULdtNqpk LkgcxIoHrR+KqWHi3rZS3fTfhPkQJB9ATKXVRFpWvNmb8TtL+BNIR3+iMnWAnftkFnTonf/BlUo 72UZBpjrU2Gx0zA01/N8U3pxr906ekp8OVvqk1OOJpBTuFyj4yeeyx85rasqXPJ/4P5oPgASoFO PcKSx5ioMrR+lJso/6OmKXP0NRkNdK7hhoA0yVMGi7ZLCprvATXv5yGbMlg7q+TOWrvT5MWJz6w XvrIsIGKmm5kkG38tmuHL/O5rapUOnU1upDpq5oGEcBiSiSwxq2bAbxzpuIx0sKV5JUTAXREGRO 2ctfeFTOg5uYEDzueAYA0U2Kqk2g2dFHc/DCI9SPZdDu9V8edLa/mgjRRk0OCNU6qxaDMK9G958 KooCxqNGtSsv1+cCNBxLI4zK210ifbeC5pkkqxVAplXfwRKG5DBkQkpWhenyKFfdsLiro1zBt/I oOC2cuZgMmPyzSA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:42:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116072023941406 X-GMAIL-MSGID: 1780116072023941406 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. POSIX generally mandates that when the the mtime changes, the ctime must also change. The kernel always stores normalized ctime values, so only the first 30 bits of the tv_nsec field are ever used. Use the 31st bit of the ctime tv_nsec field to indicate that something has queried the inode for the mtime or ctime. When this flag is set, on the next mtime or ctime update, the kernel will fetch a fine-grained timestamp instead of the usual coarse-grained one. Filesytems can opt into this behavior by setting the FS_MGTIME flag in the fstype. Filesystems that don't set this flag will continue to use coarse-grained timestamps. Later patches will convert individual filesystems to use the new infrastructure. Signed-off-by: Jeff Layton --- fs/inode.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/stat.c | 41 ++++++++++++++++++++++++++++++-- include/linux/fs.h | 31 +++++++++++++++++++++++- 3 files changed, 136 insertions(+), 6 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 0612ad9c0227..83c3378053bc 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2108,10 +2108,40 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/** + * current_mgtime - 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 mtime or ctime update. If the ctime is flagged + * as having been QUERIED, get the most current fine-grained timestamp + * (without advancing the coarse-grained mgtime), otherwise get the + * latest coarse multigrain timestamp. + */ +static struct timespec64 current_mgtime(struct inode *inode) +{ + struct timespec64 now; + atomic_t *pnsec = (atomic_t *)&inode->i_ctime_nsec; + u32 nsec = atomic_read(pnsec); + + if (nsec & I_CTIME_QUERIED) { + ktime_get_real_ts64(&now); + return timestamp_truncate(now, inode); + } + return current_time(inode); +} + +static struct timespec64 current_ctime(struct inode *inode) +{ + if (is_mgtime(inode)) + return current_mgtime(inode); + return current_time(inode); +} + static int inode_needs_update_time(struct inode *inode) { int sync_it = 0; - struct timespec64 now = current_time(inode); + struct timespec64 now = current_ctime(inode); struct timespec64 ts; /* First try to exhaust all avenues to not sync */ @@ -2529,7 +2559,7 @@ struct timespec64 current_time(struct inode *inode) { struct timespec64 now; - ktime_get_coarse_real_ts64(&now); + ktime_get_mg_coarse_ts64(&now); return timestamp_truncate(now, inode); } EXPORT_SYMBOL(current_time); @@ -2544,8 +2574,42 @@ EXPORT_SYMBOL(current_time); struct timespec64 inode_set_ctime_current(struct inode *inode) { struct timespec64 now = current_time(inode); + struct timespec64 ctime; + bool queried; + int tscomp; + + /* Just copy it into place if it's not multigrain */ + if (!is_mgtime(inode)) { + inode_set_ctime_to_ts(inode, now); + return now; + } + + ctime.tv_sec = inode_get_ctime_sec(inode); + ctime.tv_nsec = READ_ONCE(inode->i_ctime_nsec); + queried = ctime.tv_nsec & I_CTIME_QUERIED; + + tscomp = timespec64_compare(&ctime, &now); - inode_set_ctime(inode, now.tv_sec, now.tv_nsec); + /* + * We can use a coarse-grained timestamp if no one has queried for it, + * or coarse time is already later than the existing ctime. + */ + if (!queried || tscomp < 0) { + /* + * Ctime updates are usually protected by the inode_lock, but + * we can still race with someone setting the QUERIED flag. + * Try to swap the new nsec value into place. If it's changed + * in the interim, then just go with a fine-grained timestamp. + */ + if (cmpxchg(&inode->i_ctime_nsec, ctime.tv_nsec, + now.tv_nsec) != ctime.tv_nsec) + goto fine_grained; + inode->i_ctime_sec = now.tv_sec; + return now; + } +fine_grained: + ktime_get_mg_fine_ts64(&now); + inode_set_ctime_to_ts(inode, timestamp_truncate(now, inode)); return now; } EXPORT_SYMBOL(inode_set_ctime_current); diff --git a/fs/stat.c b/fs/stat.c index 24bb0209e459..02d8857bac9f 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -26,6 +26,37 @@ #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 use a fine-grained timestamp. + */ +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) +{ + atomic_t *pnsec = (atomic_t *)&inode->i_ctime_nsec; + + /* If neither time was requested, then don't report them */ + if (!(request_mask & (STATX_CTIME|STATX_MTIME))) { + stat->result_mask &= ~(STATX_CTIME|STATX_MTIME); + return; + } + + stat->mtime = inode_get_mtime(inode); + stat->ctime.tv_sec = inode_get_ctime_sec(inode); + /* + * Atomically set the QUERIED flag and fetch the new value with + * the flag masked off. + */ + stat->ctime.tv_nsec = atomic_fetch_or(I_CTIME_QUERIED, pnsec) & + ~I_CTIME_QUERIED; +} +EXPORT_SYMBOL(fill_mg_cmtime); + /** * generic_fillattr - Fill in the basic attributes from the inode struct * @idmap: idmap of the mount the inode was found from @@ -58,8 +89,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->mtime = inode_get_mtime(inode); + stat->ctime = inode_get_ctime(inode); + } + stat->blksize = i_blocksize(inode); stat->blocks = inode->i_blocks; diff --git a/include/linux/fs.h b/include/linux/fs.h index 78786c1c32fd..c9823ec0da65 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1515,6 +1515,22 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb, struct timespec64 current_time(struct inode *inode); struct timespec64 inode_set_ctime_current(struct inode *inode); +/* + * 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. + * + * The kernel always keeps normalized struct timespec64 values in the ctime, + * which means that only the first 30 bits of the value are used. Use the + * 31st bit of the ctime's tv_nsec field as a flag to indicate that the value + * has been queried since it was last updated. + */ +#define I_CTIME_QUERIED (1L<<30) + static inline time64_t inode_get_atime_sec(const struct inode *inode) { return inode->i_atime_sec; @@ -1590,7 +1606,7 @@ static inline time64_t inode_get_ctime_sec(const struct inode *inode) static inline long inode_get_ctime_nsec(const struct inode *inode) { - return inode->i_ctime_nsec; + return inode->i_ctime_nsec & ~I_CTIME_QUERIED; } static inline struct timespec64 inode_get_ctime(const struct inode *inode) @@ -2372,6 +2388,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; @@ -2395,6 +2412,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)); @@ -3080,6 +3108,7 @@ extern void page_put_link(void *); extern int page_symlink(struct inode *inode, const char *symname, int len); extern const struct inode_operations page_symlink_inode_operations; extern void kfree_link(void *); +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode); void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); From patchwork Wed Oct 18 17:41:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4960097vqb; Wed, 18 Oct 2023 10:42:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbMz+pNC1ot/pcYnzBqR3cEe/7q9su9yEBt8cUu4RcqEBt2GMyc20DO/SlH0dZ8dlP5uNy X-Received: by 2002:a05:6a00:1494:b0:68f:c865:5ba8 with SMTP id v20-20020a056a00149400b0068fc8655ba8mr6880273pfu.18.1697650977992; Wed, 18 Oct 2023 10:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650977; cv=none; d=google.com; s=arc-20160816; b=H6054H3lpt7nX2eYEzdAEaAoD3eSbtBpgfg2ed/tIQ3YnIGcXTdpv3n7VDbb5EifuK I5XmhXkC9n+5Ry/seo6/8kD5nkdvsOT8i6LWlN/6wMIK3HZydm/l18AtybAVUOfPx5dh zwL25HGvYbdDofmjw/KvCm/5UeHz8o+qYU+BpUUpbG4WRSeOjhGoko5bPB73Yg4dRCv/ jAOu2lackLzK/MLd0Gi5Xf3entFnhxT6zVVr4xQWy+zCMUHrJd37ZZENirVmO9QTsnFz xwc9WwN5YuKj5cy93gDtZ90hEOiLfumTMUsw5n855ZKqUnd28bq6VJ/YKZPl07eD4l8U 7WTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=T0BXa4F/iXCKr1XfbujvgPJs4sF4+npdOyaCUKPHksw=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=qwKR5+eACIHJLbvshK4mlKExI8gXZtS2EN2wmYismQwHReP2fdsE/YHb7PK5R4J2Ao 3lOmeAjwZiaMzgp0EqH7E5Suv5YiECxF2mLy/GgQJIKQIX5WLAcCLtioYGS2DvFrE0FW cQlU8JviTGfto/dyaS5Wt6U9RQiCe4xJbyZPp0BDTpqxBphZI1iXSN8JxkQkBzAmfR5f ZT1O0oNiAyIwkCU4M/vIGqPxRDNgva9eiqwQX9O3X7C78KmMM8nOmr4eKL2GwSHrxCZ0 R1q8YORpzKNtZwPehjT4OOW2uqBTO7yxsUpnXCwOrl7z/hk4SMku9LEjJ85iqklwVVOU k68w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ixsIePkg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id x127-20020a626385000000b006b665d40a24si4352409pfb.53.2023.10.18.10.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ixsIePkg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 23F3C80FC090; Wed, 18 Oct 2023 10:42:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjJRRmI (ORCPT + 24 others); Wed, 18 Oct 2023 13:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231418AbjJRRlq (ORCPT ); Wed, 18 Oct 2023 13:41:46 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DFB7B0; Wed, 18 Oct 2023 10:41:44 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D83C6C433C8; Wed, 18 Oct 2023 17:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650904; bh=CebfTX8x0gqnWClXdb2PRiRjob3lBToUpb1yn80x07I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ixsIePkgd6FqsA4/OTA9y+DP1ZywHc7Sr8eHzCsk+2Jo01xrQdac05wRbts2zVrXc C4o0TOGiSxkweFeCUUdfA+iKlqGX4HQZPPZCWCOKfiWi9Uw2kl/nab5pguFYwqx8Ct qqWZcVRN9CSoC9SWY3fnIJGi+/4qH3kV8pkaapRaJ+RFoTnardz2xPns8JG21g8oJN syy5uIQs3ESM7Q0MoYxYJ4hmMSxmOSV0a5aaoB5lriz1+4wr2V1OVE0iP7JaYyQfkA TtsgJXdaS/oQiTQobkbvyPySWa0MnB33bAbS8srOYejBKAHotOjG8J+z20op4bFNXu WudM7ZkhM2p/Q== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:12 -0400 Subject: [PATCH RFC 5/9] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-5-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3403; i=jlayton@kernel.org; h=from:subject:message-id; bh=CebfTX8x0gqnWClXdb2PRiRjob3lBToUpb1yn80x07I=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjIhGAfiHKR2+BMhUvK9Je6zSTAJVNLPujGV e1DN/iJrxSJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyAAKCRAADmhBGVaC FTarEACVylMwhcX6PLK1jzC+Yj+mH5qYypQpchyrOIktUb/AdxXRiWd4sKMRH5DU4sFFxFJHWce 5f8A/LDi2QaJ6fCzZZBK1cfvoc9XAiFCKu3zpxBEmaq++/tX3P2VzqRWTnfE2tgWmG/aUn4Z2tm b2cUog1WhdPXz3ubERRvWNE5WLzgVXFRRtarU/5kEUcrj8ungy2NjdEhUktZQuw8H0+2limB8YS qRrTP47cjY2RtdJA1+X+67DLw+bYymJllU7Db9sEu2CAfCTOMOxO2euB+OHR5wChJas4MjGcc6G WUdoSjOTPlOoiVrGLu9y9zHcC9VUonbBRmRYxTMcIon/aO+1gap4ByfnVvdt0/UhmmD0+lw2wJO G7HUB6PJWXGynG3IpGJorc83Hzi/TSAOc2+zQ/bwZ02IvpHBErXnfh7Nhp7LvyB4nlhJLlvQ43+ TDqOaNj56qR+wFXSFQ83K/wdzpvk1LLbew3buvB1FzEKWdn8RvUU63enQBXlkZ0iUDy3I8dtMUA uWFo0dsHzQMbv6DLYthwF6cJWkmgwEWSCevnwHezl+RA1uT7FSY4RpdjtP99UYzDNh+jqQ6Jbq7 jmJjT0+Lav0EoWH6NwVtw+QqAPT+fxHW3d5Q91P12s38P2PtFjUndb2Rf7IXNKwdcJV9mgtdc+3 9sLsvNrKr7s47Jg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:42:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116072104815313 X-GMAIL-MSGID: 1780116072104815313 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 bdf5deb06ea9..1d3e6f562bec 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -275,6 +275,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 @@ -307,12 +343,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, @@ -320,6 +350,16 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, mode &= ~S_ISGID; inode->i_mode = mode; } + + if (is_mgtime(inode)) + return setattr_copy_mgtime(inode, attr); + + if (ia_valid & ATTR_ATIME) + inode_set_atime_to_ts(inode, attr->ia_atime); + if (ia_valid & ATTR_MTIME) + inode_set_mtime_to_ts(inode, attr->ia_mtime); + if (ia_valid & ATTR_CTIME) + inode_set_ctime_to_ts(inode, attr->ia_ctime); } EXPORT_SYMBOL(setattr_copy); From patchwork Wed Oct 18 17:41:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4960260vqb; Wed, 18 Oct 2023 10:43:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERfxh5pj90wWa2C8nCPt1p4qvLA7a5QUlhWpKcQIOl7ewZ6sL5B4gSDUQxJS5gkyH9OHff X-Received: by 2002:a17:902:e884:b0:1ca:9934:d014 with SMTP id w4-20020a170902e88400b001ca9934d014mr70754plg.10.1697650995791; Wed, 18 Oct 2023 10:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650995; cv=none; d=google.com; s=arc-20160816; b=B8O0vnmfJZPNcJ5f7bHiYJQebY1Z8FR4kQ2urLfUlthZPpDaB6JyFiO2s+cex/PAuF jCRNBMbGtUn955ED0tNJYfVRrTTGHeHlfIrKtGBMN9Du/fhgL1LsuJViSpUW8UhaRU0c vp0vqNPkawqOEo2QUoixSKw8CRwBLtONiDzf+AFpzlKtl6qtvjJtRzkAu/lBbbY0iZan WXLgnZnq1BN56KaGpDyQ72nqRt7CZEZ8DdcwgDxmB4TYzuDw1WXcdVlWpU+Y/f324pRR 3OviVIYq/LgsbE5XeuAkyRfVfzyiHS06WQ8C4DO/cSuTwDxFTWzciRe6vl8cG5E6wsQ7 nUow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=M8sjly69+WZq7uxB3fHk0h1KzutYv+TMgOa3J1WeaSs=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=HdZywkgiGxgQkqtt4aXfRAGm47V6d9jQLRqn9mPQPAiqfbSTTFgbv8CLBiRsS/VbfL +IJ0jfcL5lbSNRczqT2Whucr7jZPQVWZwzNajwOjTE9Zl1wOpvvqVCW5cyGf6lb1W6YG 8/cTkO23ESHz5FTLnn1bBFmfUj4U47+m+VuWl53sje2OdDP0R2EVx77JdTxnCCWXuMdS k2iQERub/u28zggOXSTxQNeTZXLPKwsKOm2zHyXMEHxuKuf4CuCpyyho4Hil9+8v3jGL KKAb0/9hlTSNO/XxbgpSwMyPfYHBhxngcvXtqkII3bzd49d+lCLwDa4AQTg+Imnnj0yN aFfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qSRjlWxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d12-20020a170902c18c00b001ca0cf2582fsi308541pld.410.2023.10.18.10.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:43:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qSRjlWxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C820E8220357; Wed, 18 Oct 2023 10:43:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231822AbjJRRmM (ORCPT + 24 others); Wed, 18 Oct 2023 13:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbjJRRlt (ORCPT ); Wed, 18 Oct 2023 13:41:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32BD11D; Wed, 18 Oct 2023 10:41:46 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53267C433AB; Wed, 18 Oct 2023 17:41:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650906; bh=UwK4Bv3ROcgihmcvu9msHTDCqtlMi8PO5kAJpB/lfoU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qSRjlWxnNTwfGNV0Q8mT7NMDzc+qlSVW/LwsSsZeLwGGA+yuvWHorCuNrchwFb9iF 3oyQEwhmcOSX3YnhNDQKjxLGNdhHfjxGp/RF/UJRiTbFcV6fsdbOFeo7tENOSIPiNQ Zzb7nN41F8bCvJOHamRpFJ+SVAHhSJWzfR+zGMNBY/YBEZZx8poAFbXMjt/EKBoB30 hR60uckQsneqXI7s583v+itxW27moXjS284cFZ7QgCiw1HjSUAQMLgdRJVfLiUpGPu Ds5zGhz8c78Zy02SXFQoFmO8fZClbEDstAq+fFFgUMxs8yH+mp3CZ0GN7EyyMoen9w LoHURLczzAP2Q== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:13 -0400 Subject: [PATCH RFC 6/9] xfs: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-6-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2416; i=jlayton@kernel.org; h=from:subject:message-id; bh=UwK4Bv3ROcgihmcvu9msHTDCqtlMi8PO5kAJpB/lfoU=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjIefuyPVHvdgVpwhPPX60qe6wZ15TLHB4LG U8E6+7devyJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyAAKCRAADmhBGVaC FSDQD/9RrJmco0fSAbgHolmtMmOGKyJDUH+Yax9DZo9G33gFEq3gimnaRJBR7FCRyasd67VQqQT hYeUH8BlluxEFXYZssDkYOl+t7b3HZmPCdyjwhVXzaAg7vbjWghBWGHQbHFFkl9wbhoOWd6gusy zH8QXWGoN5Wz9Sk0Q7QILoMytEya3RHTnmDLbcSEfWg9YAQSNATIZcaNaqWtLSLbEmBGqaksKVY hbbxyKpso/ifX23/Qgb9IMo6ODHPPbV28AbB7kQZV21RqyeEZ+k+Jonlk7aIADMIw9bsFhzOxhO rmyxKZvBUTql2YwcvoFAo3NRjZpQmvfzBRK6Ax6WSMF56OA7XcUqNFaEMaFxhjgAPjZpCxbZfW5 dGjJmnna8XkCv95PUOAtgDLpFAoEJSOS7XOgQ3VSGcSNe3Vvrz0K9jrvkiZf1WyyaHNRPXvijbC DFZX7Pi40JztALqlqNMKTidN68pBd4uvdv5Qk2L8ESP5gf6TaGH16ah5yoj3MAIhT+stlHFT55G Ejzaitu1cicbPvrUTz+i6+YFWFd925Q9EZSLgg3aAka5jtRQ7am7C4ciUbSURjRoVdtQpmrfssX BoFbvPeT0DHZbtZwjdmxDip4mLT5dAVaobppZYIlMhcJlEBN6toFJuE67SPBL4hqePRjDXhm9uC B/Imrrki4dThCiw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:43:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116091001710322 X-GMAIL-MSGID: 1780116091001710322 Signed-off-by: Jeff Layton --- fs/xfs/libxfs/xfs_trans_inode.c | 6 +++--- fs/xfs/xfs_iops.c | 10 +++------- fs/xfs/xfs_super.c | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c index 70e97ea6eee7..42e4e6e964d2 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); ASSERT(xfs_isilocked(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 687eff5d9e16..8fb251cbe061 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -573,8 +573,8 @@ 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)) { @@ -914,12 +914,8 @@ xfs_setattr_size( * these flags set. For all other operations the VFS set these flags * explicitly if it wants a timestamp update. */ - if (newsize != oldsize && - !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) { - iattr->ia_ctime = iattr->ia_mtime = - current_time(inode); + if (newsize != oldsize) iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME; - } /* * The first thing we do is set the size to new_size permanently on diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 819a3568b28f..c8a2dae1dd65 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -2033,7 +2033,7 @@ static struct file_system_type xfs_fs_type = { .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, .kill_sb = xfs_kill_sb, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, }; MODULE_ALIAS_FS("xfs"); From patchwork Wed Oct 18 17:41:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4960382vqb; Wed, 18 Oct 2023 10:43:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+WgO6z4cSQBvQqrEVAndxEQJJvInXafZeedOpFqXQIw3Mw0JVNkLbaGCNgGoqsIwh66q1 X-Received: by 2002:a17:90b:528d:b0:268:1355:b03e with SMTP id si13-20020a17090b528d00b002681355b03emr6305467pjb.38.1697651009785; Wed, 18 Oct 2023 10:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697651009; cv=none; d=google.com; s=arc-20160816; b=AHOfGKamLPhLVY7WUbEpeZGI6os2yrlh/CjphxNscPpEZGF55ni7eZd/rd3WCoS+c4 kAK3J7/3e+Wi7hDY4iXQdaBBP8A+VUs1j0xM5iLACgC31yBcFIQXWUdblS2DZgmDRgku Yv7QzYD9Iqpyz7Rsghi1fVbwGRwvknnffajBBwBgeF9TKLM8OsPkxqtE6zo0UQo3BgiI Bw7vjK7Gxk/AMSCt8x1vt5SbJ5DvUax2PNMwna9m4uxsdHrmgE/WBZKnAkrAaiqyfK8z kvqH9jS7ng1LZYFKT17KZhMNCntUHWoE4xpOJ2nWIoy9iX7gv5IE4Yc2iM+d5OpYHGFP KFGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=5r5+xkT7Cah6bqzzux7AkywwCv2DT8B10T1+CCXYhPY=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=YtdoBSgbrtDl8so1ECCchwVtQkGQTaQo3furfe2ZOkmGg2VzyHGMz+Oi3HlsUQA2Sw v3CKmZVJW31f9CKQ0mHwqp3tt301OsI22wl/awShU4T+nO6jHb8t7X96lxNH3D3HXbLZ AzjcMohKQGcHUPSjJfpqXYymmrnkdY60Y4GAHIjHhaglacV+OX5fWnZ1fFidoB2aGS/k ZUOP/sJOiE2GtgH19MdTA1SWwyiBeyWDblSfA09JUsobP/1AzA63CEVHvknxer7w2amH BoDtVwNxrVRxuJWRNdk5Or0iaJV3OF13Edhilo8sDFhDnMlB3fKk6Gep0s7t4bcR7HzK FO+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YYfoYs3O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id x7-20020a17090a9dc700b0027d0ba6f5ecsi309219pjv.149.2023.10.18.10.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:43:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YYfoYs3O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0AC8280FC08E; Wed, 18 Oct 2023 10:43:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbjJRRmZ (ORCPT + 24 others); Wed, 18 Oct 2023 13:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231851AbjJRRmC (ORCPT ); Wed, 18 Oct 2023 13:42:02 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6298B129; Wed, 18 Oct 2023 10:41:49 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6728C43395; Wed, 18 Oct 2023 17:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650909; bh=4p7KAc4dsK8dQOeLACIwEbavFhpYUlO+UH4AD1OreDY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YYfoYs3OV3OwOoWHJrW77sJgKOC9d7+Xq2vmQwl+Dj5UFhipFADNwQ3Z5KsSsLnjj UVCEUAP+RmDftyHzLhd05wa4Wr9JjLoXLiMNGfHoXxPtQw6AiZe1Lab31EqC9nkk+X SLlEIufv3uKJdxWt2FX2w4ro0YBLs4r3yGGJ2HiiiEmoFU5P7wRsFwR78QI3BZcJKQ JrJadB8JAr5Za++uEa/DHUlvVAmSgMmyDqMs/P/f1w9aWxEst8sifhkZCulFbhCaER HIdZH+kCXuPghYLEvCgDz0lXzMwGopN027mxaYxLLXwTEd1iaD7Uf5TKOI7ecwuiA6 nO8L4XBZg8rPA== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:14 -0400 Subject: [PATCH RFC 7/9] ext4: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-7-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=839; i=jlayton@kernel.org; h=from:subject:message-id; bh=4p7KAc4dsK8dQOeLACIwEbavFhpYUlO+UH4AD1OreDY=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjJsAbzUTfA1QPqzg0MuGg3swqrFXt6uvW1m bGS00EFnDmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyQAKCRAADmhBGVaC FfeYD/98fNSYqHhHFEvbqhES3uKXfBN7CAx91j661F9ZNuvn2CUIquUaA+FfPt5NpL/7OW1KiHo hcxzhv+n0ws5nkme7kVxjI1jfLKkHNNOrue4gPlc1uU8+6SJ/oW//BRSV+nVkhZJtmIBtz7FJh9 yHdA4QbXq2qZwMBMlh3eRQTV913fwSRViLHiYkQYST4FOCORzm2QDfAeQNTscPvOI4ewlnaD/ep 9OIszxsNlLeabXq5eTdHb+tAWYRAcLzGpRDDB+mmxJsTBYPx60lODA9tFAUBrGmwxlDIHNmYx+P TornDYcILN2sWjoW0bqNmlRzp6iY037toqRYrQ7JjWhqpujus+aarDdugYY+r4CECwvRypVhGxK uWz3jjn1nlJmmBZmavbScjo3jReAgwtwxuTgmQQrYqPxwZS0ts3pBhvgk2atABZVejYvtAmZw93 QlP8V1GdxhdElp/hHiUK+LBRy0pKGK0lUt4yzOM5udaB7LCwRCIClVUhQ/IygAEikJXhCqX1de9 ogvCF5Orn0HR0YUZ4mKJ3WD3Oc2V7bfeDJ3zo6hBvWjbiSr6ZXixhXHy03d0TlCIyP+pPfmib9O Hzz0pNgcBzA4WTTYeDb6RhPTqh9IfJli9Ntp5lFmYh+Juwu/yH1cI4E5jnLXa4TO/ziZvclczEQ 7oglGUSvni3TcVQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:43:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116105404497877 X-GMAIL-MSGID: 1780116105404497877 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 c642adf54599..1b111cf4ebe7 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7314,7 +7314,7 @@ static struct file_system_type ext4_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = ext4_kill_sb, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, }; MODULE_ALIAS_FS("ext4"); From patchwork Wed Oct 18 17:41:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4960092vqb; Wed, 18 Oct 2023 10:42:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhKH+9X04CX+w2mC1A4JXnBHUxluiAnK6YP5fGEHUzpzAzlt5wUGW3OKhPxHdtWZGufQ5Y X-Received: by 2002:a17:902:e80b:b0:1c2:193e:1126 with SMTP id u11-20020a170902e80b00b001c2193e1126mr43929plg.28.1697650977840; Wed, 18 Oct 2023 10:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650977; cv=none; d=google.com; s=arc-20160816; b=tq9VGB5PadIgqja3HkuaRoUfTxvffmw1kLTccJzwJMqkbqvkczqISXSWsI2h1CtPwJ thlKDfhANzrWFGNdVJf3EgqVnWszmmFwGtAwcivBnRgeIAHXwfiloO5I+wiYI9/TxLjl hejzb2Nh2r3d5/tDpHupZaLOZEjkazoWSpV9+ySbgak0s7igho7ukKvm3IwThFRBaCf6 hgDGymZEyCJoNibqHjttKvli1sjKU7wHErBQQOGy7rLftoJqeDd/HWdYx9PLJOLl8rLV msTNSjJXUSFxmFg5ni508pJbk9fjuY7LaLvGj8VTYZFLi9FSdqjUw9/D81tvuXmUoqGt BXPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=3I/im1cm3Iyi8zoSuG5Q4U80yeBCLsvqQYdBnHrWXJ4=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=l4ZXF+iItV67tqTwZDhM+AbMeQi8GBBbJBbSYL4FaQRFNv6yC8kERBLtP52X6oohkh wQ9lYa9UzsXo76+hXSimtzaDOJwk9HeTc+GcctayzC8KgpoWfk53aqKo8wOIwKeuTE0m 1b5lI169YIHLikxlvCMeFqnnOZSZLBbBjK2UeT5gjOyvJBd9Nm9rlqIHskjUIunz3sG0 hAlry8kqNMrniOrir5sxlzvU3gXb+dYkCEhPWFm0RGNyLpcWKzy8epfm+ViLjKOSwio8 sCnyA8xihdIhkJ1GqT/ROhfHlTJZfFxYMbtXTS95JJCg0b91btUEGEI92l/Ekm9iRDME XD+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="W/ufbXG6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b15-20020a170902650f00b001b8922e82e3si318054plk.297.2023.10.18.10.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="W/ufbXG6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4312781B93FC; Wed, 18 Oct 2023 10:42:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231928AbjJRRmc (ORCPT + 24 others); Wed, 18 Oct 2023 13:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbjJRRmC (ORCPT ); Wed, 18 Oct 2023 13:42:02 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5378F137; Wed, 18 Oct 2023 10:41:52 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 438D3C433D9; Wed, 18 Oct 2023 17:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650911; bh=08peVOKZI4MR32wuXNO48w8LFAelNL7UOowvOcywmvk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W/ufbXG6bJI9e49CMjNUjxnvN8rpYE07kV1Uv10lbs/C8hNuvNOyNt34VfqYnC9DS I49zl61Mm94s/lF9vju5dzbq67/qC6Ar9L8q60dVvEDaVDtocmAwykqrLymr+qZux/ lVbBynbEAYYfrdp3mlaPnhPGOSlk/bLGkiSCd3V/9bKS5BgA9OPrfvjMa7CO0JzooF M9MdsOlxGkVapwTxlcbX6mNMMUoJtnBk5eL19Gf1y3rjt63K4Q+9v6Pai1IDz/fGIO pb4hveW0yjsp2pnmsVFm6s91KvwIgLFKzm8zK2eCovTbh6AP1vv+TXLbdyc/5r18WG RuObwSWU6PuEA== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:15 -0400 Subject: [PATCH RFC 8/9] btrfs: convert to multigrain timestamps MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-8-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2744; i=jlayton@kernel.org; h=from:subject:message-id; bh=08peVOKZI4MR32wuXNO48w8LFAelNL7UOowvOcywmvk=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjJZH0sHfYjXHZeCrVOFs/hUFjZBM0oBFoPW KoouqyR/TCJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyQAKCRAADmhBGVaC FSbeEACAUjZExA/YblPlgkxwqx2TRI6TFuS5NFnYMhcyki2B2XIkJnpD00JJl8GKM2MskyOvrQ8 Yd7Q8MzEyeQXxkNNt0V+DWuQYMst+8EKu9X5/T7v/1Anjkaz3ZzdirOXSZR6N53cMMLFGgSpJSv mUGs7YUWvT8XrGon0xoQ1CIuie6MmZkT5AQfZEc/0tTcmqk9uNg2/4VypX+oQeNMSyMf+xzO7Ss iQMxMetZB5ZQB1goTm4qxKjeOI3+mzLV977iDUyM96oHtAhYzUukSms5Hw6dNZDMRFkzOweotXZ IXY180/C7BmfVwV7MGwpqfVBRWiVNZEJDRERUQGB3cXYfYlETLz0enJOQvdvw697641AptAD0RD 9sqdT2M5ue6hTbEBj0y/DtlwhFPMeKr2KSDih9MgJZiqUPD89I/hx5RtNbvWcy8QM7ZH/+HVbVq RPl5tV9C0deifptk08XdKAgSnFPEg6Tm5ahINqN5V+lYnhd/b9CjY1kShQfBjex8bwxaUXnXMAq VZamJx2U4u1P3bNGzCpoON3dNyRXvIx3l3Kyc2E4+la0DaCeknTxoXrKWabtu31CEFLEsNN6QGj bC+V3q+EAl3kxNPQV7gpgEJKVOTyWeBu30B76+qZgKOQk4JrNb2ZVmXK2Kj3VHs7OONPBZShAfo fyUe5HZ/2zFbI5A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:42:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116071783831047 X-GMAIL-MSGID: 1780116071783831047 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 | 5 +++-- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 278a4ea651e1..321405bf788c 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1106,26 +1106,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) { @@ -1157,7 +1137,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 f49e597e197f..570613bfd25f 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2154,7 +2154,7 @@ static struct file_system_type btrfs_fs_type = { .name = "btrfs", .mount = btrfs_mount, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_MGTIME, }; static struct file_system_type btrfs_root_fs_type = { @@ -2162,7 +2162,8 @@ static struct file_system_type btrfs_root_fs_type = { .name = "btrfs", .mount = btrfs_mount_root, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | + FS_ALLOW_IDMAP | FS_MGTIME, }; MODULE_ALIAS_FS("btrfs"); From patchwork Wed Oct 18 17:41:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 155053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4960104vqb; Wed, 18 Oct 2023 10:42:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtL7AnVCPqutiIyWpEmM6YG6Ro5bgiZ/MuRM05J58TujzqNICNrROpG/J6VIOtiajLpVAO X-Received: by 2002:a17:902:f0d2:b0:1ca:20a0:7b14 with SMTP id v18-20020a170902f0d200b001ca20a07b14mr25086pla.55.1697650978627; Wed, 18 Oct 2023 10:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697650978; cv=none; d=google.com; s=arc-20160816; b=WD8SdybW5lPCvS0L8N839FmqwQSF3uMifMKETGHCqhuZDuFaa5BlXu68jd59qP6EWP qQiZ0jD2Yo/0G6xOMM68KvBBC6gdrT5MA0ZBENa186IRFtw3Mzk4EKBLeDoErCssjb90 Vw7GJkjl5j09iyohjbHOvAL4To1EETL/zdtRFKpVjWYVGF9UzTcoYk7xP0Bi1gJQy6zd j6LSDgvp2ksYfe6g1aLb8ZXHEoRxGOR5S8cqRlE64MKA6gpHjvud4FfhLmHXAvRMNMca q00C0jrCavkMoI4+mXdf5VLt1GllCJXB1ZpaliBqV2lJrP2p7MvWfI7KuHw5xgzRn5Zy Bbgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ikpCApXB/qWFMOf6x0PCWwyfCqiC7EDQCruKexQ3Fwg=; fh=WA8qFMHWvjTCOJPneOmbWlYMX1uFqoC3pygmELdhK8E=; b=ja5Xe6YRPT6Soz79e5N+0GgwT0x2x/G1AVhC1WA5Dn/WDl+uGGsNQhALn9Lgs7yawJ g33xa8OU+PgQk1uUTVdlsQClL4sJeW2kvMH/WvOxJItyrD3HDEBslcKJ1mCAxvPHlLvg lW/WeBhuVOq56m+iUUwcS0DnCC1KKyxLNmWYWPSnKVq5K6/6sYSPiibvO4j7RlOu1+Yo lO0fyHWxZE7hTHcBc8hdRS45nV/BHsFlapbedctURePUh0TxSi8lnMIT+O6/HSlKFndC BIkOAOFXEKX5qn5ypebOYzpl9T44gTlo7YUEWHKCCLyXlWeXb32LUMzWqcuIRzCeoZ90 Ee+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G9KeDhGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a5-20020a170902ecc500b001c724f99804si370617plh.615.2023.10.18.10.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:42:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G9KeDhGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6575081B94DB; Wed, 18 Oct 2023 10:42:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231419AbjJRRmn (ORCPT + 24 others); Wed, 18 Oct 2023 13:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbjJRRmX (ORCPT ); Wed, 18 Oct 2023 13:42:23 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58085184; Wed, 18 Oct 2023 10:41:54 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1A73C43391; Wed, 18 Oct 2023 17:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697650914; bh=mMRFKHsg6CFW9vRC+qvje6I3FWhEbLE4To87FsaWYy0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G9KeDhGIB9FCmXVvdb8/9fxs0Vl7HqKSxTG2hqRqWmfQABwQW7pdvKOVOXxt1vp/X 7jm9YEVYObd5mwPlrFkNtvsuTXR6xH5Pn13g+WIqWBU+hHOt+fTXPEXY0anLihyfPV N2lpWFc95eFiACPuWlr29oqQ7V4JvOv6Ls07DXNTG3JlEkbj2ZQ7xBoy5SYsS5A2bb DmhFjFozl3Zi+x494NzrmMrPjsGESKGON+RztxqNbwrZ3B7HJddhjWUFBZ8L06ONWC IAqsNdWapv9wZ06yAp7DwcwusRk/S8Fxe9ZUEw3SHPP3VJfZmT69ZHuZptBuaFgOVO uN/SIWObsbWYQ== From: Jeff Layton Date: Wed, 18 Oct 2023 13:41:16 -0400 Subject: [PATCH RFC 9/9] tmpfs: add support for multigrain timestamps MIME-Version: 1.0 Message-Id: <20231018-mgtime-v1-9-4a7a97b1f482@kernel.org> References: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> In-Reply-To: <20231018-mgtime-v1-0-4a7a97b1f482@kernel.org> To: Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Thomas Gleixner , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-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.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=769; i=jlayton@kernel.org; h=from:subject:message-id; bh=mMRFKHsg6CFW9vRC+qvje6I3FWhEbLE4To87FsaWYy0=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlMBjJAuF/mn4fUKEE3uiFdGeHeVKOJDDMsX28Q t9B3mGYu2WJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZTAYyQAKCRAADmhBGVaC FXeLEADGWL+XVQBwiyFQFHvIPzldy2L8awb0YKPCr28SYeSR50oiPbqPzalc6MzF1KFc+NOvzOa 94PHr4jh1Zd5l44XOHvzRAdilY0BBloRQ6qVfnKJd5JmSQGB02a23Qs3Omp8vBldt+xaHk4I3+B PmOCDiBni6Dq8zr1G3M1S/Yu8FVgigl1nkDKRhaEJsogQyoid0JLsND7c43MLWfLm9RL8sEoiFQ 13PHXmfhUTbvhvCwucMjvlifITgBbUzgSxLMSUBINjfVazbERk48Dg/clacnw/Lxm9g0a/H8Dqi gf66uPXr54fnkhwrasliLB1kNNLISNBLVfOfLILNoHn5eDBcWVStIXYRT1dyX9qsbEUbwYpvIog 6k4DE3M+ZiqgvUilXZB1Yd4yiFTjZeMu3E3i3F4XS9ehA2ABL0L5Auyy4/JicO9FStbE5AUqREX u9ySpUplJrMTQ6yGu2XcHasRW703qajO8DORPB8u9DVDkVnoAto6RSwi2W3oGVoMMU7wpt5nhlo rwZLb5irBLYI25FjYy9jsDgdWSE818ID2KYoV9Dt/zjZj0akGxwQBs8aalDIMiw1aD+bQU8e5Qs t8fdVfGjIcSYqpBPVMMkbPB82S9hiajclrg18YKi7sr5wd0+90jWiGZf00jbQvf+BfnSXbG9aE4 IVTP54zf3BOAL2A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 18 Oct 2023 10:42:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780116072753350323 X-GMAIL-MSGID: 1780116072753350323 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 c48239bfa646..6f5941bffa45 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4586,7 +4586,7 @@ static struct file_system_type shmem_fs_type = { #endif .kill_sb = kill_litter_super, #ifdef CONFIG_SHMEM - .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP, + .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, #else .fs_flags = FS_USERNS_MOUNT, #endif