From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53FC8C7EE23 for ; Tue, 23 May 2023 10:56:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5782900002; Tue, 23 May 2023 06:56:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B08166B0075; Tue, 23 May 2023 06:56:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F5F0900002; Tue, 23 May 2023 06:56:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8BFA96B0074 for ; Tue, 23 May 2023 06:56:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5A55E406AF for ; Tue, 23 May 2023 10:56:18 +0000 (UTC) X-FDA: 80821215636.06.0D54ABC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 6099080014 for ; Tue, 23 May 2023 10:56:16 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bVruV3sf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684839376; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sBBOEAUMj7xiFFQyHaMbvetqIux9U+XauSBbpQYpkbs=; b=zSkJ4k/qQWjGVJya+Ty+lEMb6XaIf6lz8/M1BMCqytczUxFZAEd7g5lhbKpyaiGoaFKmNw qi8fXTxpti+ZGKVpJJR7sCThrF91YM7pFPQZcdSCgjTB27zRC6WnwzK1958BWXu+gN8JgJ 65ytc2iv7Gl6f+I5fSmZgQkT761fH9A= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bVruV3sf; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684839376; a=rsa-sha256; cv=none; b=gQKS3pyDlK7RlP4XUNW7whh1CYvbe1EjKwRlJS8z+q0CIqN9WhBrFTLZqPi4JeIoNtJlsL YQifpbAHXu+suJeFDv93mQM0Xg/V1GL99jpIYlVymZkeervlxDTaN77lIWPymLZ1x66f9E +bVO1CPVeN0XSECYRwnOBEVqi8UEcDA= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 74DE861093; Tue, 23 May 2023 10:56:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654B3C433EF; Tue, 23 May 2023 10:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684839374; bh=gxdNW1/f/9PAgN6QIwpZFg/Q6GBpd45ovH2YHV9pO24=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bVruV3sfe1VK8SZ8P5llKLoXL2vEi7/YPZpm3eD3FCnwY7TaqZlutR0O5J1XfTFO8 V4FriMdQrV8yIlcYenD73/ZMeKxuvRpTziaPFRSZTlvWV5jHVdurKve62yfwG6Zl+b OBxSQCLK5har0jXlIP5KUo1cr4Ueqf+Ahj2hO9YIC0/3JR7CRwA/vwieKKjvBaPx9U yOlljBAVMuwFvB5OpGcOpKlKmv2bQXmiEJ7DASCKa2t4Q5aB3kwXFyBsINxX2ovN9r TtP3dth+zi3QttpVp2hkLYDXGaW9pIxAj0gJO63C2R56YrNK3EYFmwl/nyP2a4RqKi U3phrhKjQbShQ== Message-ID: Subject: Re: [PATCH v4 2/9] fs: add infrastructure for multigrain inode i_m/ctime From: Jeff Layton To: Jan Kara Cc: Alexander Viro , Christian Brauner , "Darrick J. Wong" , Hugh Dickins , Andrew Morton , Dave Chinner , Chuck Lever , Amir Goldstein , David Howells , Neil Brown , Matthew Wilcox , Andreas Dilger , Theodore T'so , Chris Mason , Josef Bacik , David Sterba , Namjae Jeon , Steve French , Sergey Senozhatsky , Tom Talpey , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Date: Tue, 23 May 2023 06:56:11 -0400 In-Reply-To: <20230523101723.xmy7mylbczhki6aa@quack3> References: <20230518114742.128950-1-jlayton@kernel.org> <20230518114742.128950-3-jlayton@kernel.org> <20230523100240.mgeu4y46friv7hau@quack3> <20230523101723.xmy7mylbczhki6aa@quack3> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.1 (3.48.1-1.fc38) MIME-Version: 1.0 X-Rspamd-Queue-Id: 6099080014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: zf6t89o8my6jktthshd37z1ms6gmsmx6 X-HE-Tag: 1684839376-953186 X-HE-Meta: U2FsdGVkX1+GZlSP/ZZbLvxIp3NXiWQ6b8vgGL09HeKXFMcsK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Ynzl+2PsJkknpQwZ+uLL0ToOJXgrnyK1IaZAUUntllM4IxT67zI74HEXLxTY2G90osA8bBbAaHU6P7G1HeugEYy/V51QUJBk5Ilto8EzEyajygr5ZHj4m/lN92crcA5zEsE6NDArI+uFCbLUNs0fcM5VYLR+5lsk/N/a0MMmJHdobVtzXO1/utqrzi9Xwk5vZQZhfGVphfoaRgmgqo7/bPCqhkTNExiTt7BNNjpmQWEbAskffQ3efL5OoCs3t8pQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 2023-05-23 at 12:17 +0200, Jan Kara wrote: > On Tue 23-05-23 12:02:40, Jan Kara wrote: > > On Thu 18-05-23 07:47:35, Jeff Layton wrote: > > > The VFS always uses coarse-grained timestamp updates for filling out = 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. > > >=20 > > > Unfortunately, this has always been an issue when we're exporting via > > > NFSv3, which relies on timestamps to validate caches. 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. Othe= r > > > applications have similar issues (e.g backup applications). > > >=20 > > > Switching to always using fine-grained timestamps would improve the > > > situation, but that becomes rather expensive, as the underlying > > > filesystem will have to log a lot more metadata updates. > > >=20 > > > What we need is a way to only use fine-grained timestamps when they a= re > > > being actively queried. > > >=20 > > > The kernel always stores normalized ctime values, so only the first 3= 0 > > > bits of the tv_nsec field are ever used. Whenever the mtime changes, = the > > > ctime must also change. > > >=20 > > > Use the 31st bit of the ctime tv_nsec field to indicate that somethin= g > > > has queried the inode for the i_mtime or i_ctime. When this flag is s= et, > > > on the next timestamp update, the kernel can fetch a fine-grained > > > timestamp instead of the usual coarse-grained one. > > >=20 > > > This patch adds the infrastructure this scheme. Filesytems can opt > > > into it by setting the FS_MULTIGRAIN_TS flag in the fstype. > > >=20 > > > Later patches will convert individual filesystems over to use it. > > >=20 > > > Signed-off-by: Jeff Layton > >=20 > > So there are two things I dislike about this series because I think the= y > > are fragile: > >=20 > > 1) If we have a filesystem supporting multigrain ts and someone > > accidentally directly uses the value of inode->i_ctime, he can get bogu= s > > value (with QUERIED flag). This mistake is very easy to do. So I think = we > > should rename i_ctime to something like __i_ctime and always use access= or > > function for it. > >=20 > > 2) As I already commented in a previous version of the series, the sche= me > > with just one flag for both ctime and mtime and flag getting cleared in > > current_time() relies on the fact that filesystems always do an equival= ent > > of: > >=20 > > inode->i_mtime =3D inode->i_ctime =3D current_time(); > >=20 > > Otherwise we can do coarse grained update where we should have done a f= ine > > grained one. Filesystems often update timestamps like this but not > > universally. Grepping shows some instances where only inode->i_mtime is= set > > from current_time() e.g. in autofs or bfs. Again a mistake that is rath= er > > easy to make and results in subtle issues. I think this would be also > > nicely solved by renaming i_ctime to __i_ctime and using a function to = set > > ctime. Mtime could then be updated with inode->i_mtime =3D ctime_peek()= . > >=20 > > I understand this is quite some churn but a very mechanical one that co= uld > > be just done with Coccinelle and a few manual fixups. So IMHO it is wor= th > > the more robust result. >=20 > Also as I'm thinking about it your current scheme is slightly racy. Suppo= se > the filesystem does: >=20 > CPU1 CPU2 >=20 > statx() > inode->i_ctime =3D current_time() > current_mg_time() > nsec =3D atomic_long_fetch_andnot(QUERIED, &inode->i_ctime.tv_nsec) > nsec =3D atomic_long_fetch_or(QUERIED, &inode->i_ctime.tv_nsec) > if (nsec & QUERIED) - not set > ktime_get_coarse_real_ts64(&now) > return timestamp_truncate(now, inode); > - QUERIED flag in the inode->i_ctime gets overwritten by the assignment > =3D> we need not update ctime due to granularity although it was querie= d >=20 > One more reason to use explicit function to update inode->i_ctime ;) When we store the new time in the i_ctime field, the flag gets cleared because at that point we're storing a new (unseen) time. However, you're correct: if the i_ctime in your above example starts at the same value that is currently being returned by ktime_get_coarse_real_ts64, then we'll lose the flag set in statx. I think the right fix there would be to not update the ctime at all if it's a coarse grained time, and the value wouldn't have an apparent change to an observer. That would leave the flag intact. That does mean we'd need to move to a function that does clock fetch and assigns it to i_ctime in one go (like you suggest). Something like: inode_update_ctime(inode); How we do that with atomic operations over two values (the tv_sec and tv_nsec) is a bit tricky. I'll have to think about it. Christian, given Jan's concerns do you want to drop this series for now and let me respin it? Thanks, --=20 Jeff Layton