• Jeff Layton's avatar
    fs: add infrastructure for multigrain timestamps · ffb6cf19
    Jeff Layton authored
    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: default avatarJeff Layton <jlayton@kernel.org>
    Reviewed-by: default avatarJan Kara <jack@suse.cz>
    Message-Id: <20230807-mgctime-v7-9-d1dec143a704@kernel.org>
    Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
    ffb6cf19
inode.c 72.5 KB