Re: [Cluster-devel] [PATCH v7 12/13] ext4: switch to multigrain timestamps

Jeff Layton <[email protected]> Tue, 19 Sep 2023 16:46:25 -0400
Newsgroups com.redhat.cluster-devel,dev.linux.lists.ntfs3,dev.linux.lists.ocfs2-devel,dev.linux.lists.v9fs,net.sourceforge.lists.linux-f2fs-devel,org.infradead.lists.linux-mtd,org.kernel.vger.ceph-devel,org.kernel.vger.ecryptfs,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-cifs,org.kernel.vger.linux-ext4,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs,org.kernel.vger.linux-unionfs,org.kernel.vger.linux-xfs,org.kvack.linux-mm,org.ozlabs.lists.linux-erofs
Message-ID <[email protected]>
On Tue, 2023-09-19 at 13:10 -0700, Paul Eggert wrote:
> On 2023-09-19 09:31, Jeff Layton wrote:
> > The typical case for make
> > timestamp comparisons is comparing source files vs. a build target. If
> > those are being written nearly simultaneously, then that could be an
> > issue, but is that a typical behavior?
>=20
> I vaguely remember running into problems with 'make' a while ago=20
> (perhaps with a BSDish system) when filesystem timestamps were=20
> arbitrarily truncated in some cases but not others. These files would=20
> look older than they really were, so 'make' would think they were=20
> up-to-date when they weren't, and 'make' would omit actions that it=20
> should have done, thus screwing up the build.
>=20
> File timestamps can be close together with 'make -j' on fast hosts.=20
> Sometimes a shell script (or 'make' itself) will run 'make', then modify=
=20
> a file F, then immediately run 'make' again; the latter 'make' won't=20
> work if F's timestamp is mistakenly older than targets that depend on it.
>=20
> Although 'make'-like apps are the biggest canaries in this coal mine,=20
> the issue also affects 'find -newer' (as Bruno mentioned), 'rsync -u',=20
> 'mv -u', 'tar -u', Emacs file-newer-than-file-p, and surely many other=20
> places. For example, any app that creates a timestamp file, then backs=20
> up all files newer than that file, would be at risk.
>=20
>=20
> > I wonder if it would be feasible to just advance the coarse-grained
> > current_time whenever we end up updating a ctime with a fine-grained
> > timestamp?
>=20
> Wouldn't this need to be done globally, that is, not just on a per-file=
=20
> or per-filesystem basis? If so, I don't see how we'd avoid locking=20
> performance issues.
>=20

Maybe. Another idea might be to introduce a new timekeeper for
multigrain filesystems, but all of those would likely have to share the
same coarse-grained clock source.

So yeah, if you stat an inode and then update it, any inode written on a
multigrain filesystem within the same jiffy-sized window would have to
log an extra transaction to write out the inode. That's what I meant
when I was talking about write amplification.

>=20
> PS. Although I'm no expert in the Linux inode code I hope you don't mind=
=20
> my asking a question about this part of inode_set_ctime_current:
>=20
> =09/*
> =09 * If we've recently updated with a fine-grained timestamp,
> =09 * then the coarse-grained one may still be earlier than the
> =09 * existing ctime. Just keep the existing value if so.
> =09 */
> =09ctime.tv_sec =3D inode->__i_ctime.tv_sec;
> =09if (timespec64_compare(&ctime, &now) > 0)
> =09=09return ctime;
>=20
> Suppose root used clock_settime to set the clock backwards. Won't this=20
> code incorrectly refuse to update the file's timestamp afterwards? That=
=20
> is, shouldn't the last line be "goto fine_grained;" rather than "return=
=20
> ctime;", with the comment changed from "keep the existing value" to "use=
=20
> a fine-grained value"?

It is a problem, and Linus pointed that out yesterday, which is why I
sent this earlier today:

https://lore.kernel.org/linux-fsdevel/20230919-ctime-v1-1-97b3da92f504@kern=
el.org/T/#u

Bear in mind that we're not dealing with a situation where the value has
not been queried since its last update, so we don't need to use a fine
grained timestamp there (and really, it's preferable not to do so). A
coarse one should be fine in this case.
--=20
Jeff Layton <[email protected]>