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 6C351C2BD09 for ; Mon, 1 Jul 2024 13:53:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D11BA6B0099; Mon, 1 Jul 2024 09:52:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC12F6B009A; Mon, 1 Jul 2024 09:52:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B614A6B009B; Mon, 1 Jul 2024 09:52:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 99AAD6B0099 for ; Mon, 1 Jul 2024 09:52:59 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 367781A1C1C for ; Mon, 1 Jul 2024 13:52:59 +0000 (UTC) X-FDA: 82291324878.21.2C89BC7 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 50C9220013 for ; Mon, 1 Jul 2024 13:52:57 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=MAapyADw; spf=none (imf03.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719841966; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jKuw/nIkwEFc0H9vWonO0UW2rpxls958cLbHkMvMg2w=; b=oxctIHoUHpjSw2NUYpfT3I6cKooGFfsGMM0Wb4zt1ZUzje3l46iHhPi/Ju1QjIXyFA8rHa YtlsPmZAxHlTcbPJvVpafZD0UYax6G0Mg2q4xWFmX/Bk6G2QN5HsVPQI1vLq/QqlednMmc T+Mx+pBrY/F2tRh+J7iaWjsWht7n6KY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=MAapyADw; spf=none (imf03.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719841966; a=rsa-sha256; cv=none; b=dGtE2yBHUDEclMKbi6wU7VPhvVCpYBKDC0sn+Gbo+lnV6eCY9a7pxO3M6DCOp1zPJ+f2c0 dAmfV3BMYdJwq6LGWlJDbZYX+XAJ3FGvJU1es84XrdX6G3cwfAs7oyTMCN1BrGotM5Escx 35g5tYpJesTdleIs/Trm7lwGhnFUbAw= Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-44642df9af1so16355741cf.2 for ; Mon, 01 Jul 2024 06:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1719841976; x=1720446776; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jKuw/nIkwEFc0H9vWonO0UW2rpxls958cLbHkMvMg2w=; b=MAapyADwAyO315s98N5RDVl1LYCYqiV4HbhPYYigz6Bdk0r5kuwSt9PXaS+yQDagoo sO2K1m6sRe2tgtdRG7GUgKWTXn42wZi9SfjC7oi8uXLjOyRNvsKEP9H2ykjwpaVKeUPJ /EE9xpRxg1hz59n4k53fSiBCFA0XDx+r9av9VvylbIZW3OT0XJdkukDCgzC34yiBC7Ia U1BYXkGUsDVvdUxeA7rMRXdLan+3JQKC0VFn/CSzVBnAkdrI/vhqf5DAobYkzDqCe5TL eH3IiUTqQJWgf3frXIjsy8KxhhUVmT2M7KRbL0n5YwILFfDYbl6nuadOLG5MMWpH6M3/ 5VSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719841976; x=1720446776; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jKuw/nIkwEFc0H9vWonO0UW2rpxls958cLbHkMvMg2w=; b=R8EYgmpdfURetwL3xzdW2UioSdORhWgRM2uw5lURh8VsBw16snNfFrtQVkuzOpkan8 pj2aVmtRx3tP5gDNbJMlEYjYbM7SLXk2+7XZV5CP6ZRFmhYwoJBQkpF/e8CtGmLouMon Sfe7fnzz3Ku+X0fFCH+1exK99rusmL+6Ov7l5itQA11mDEshlkIOzpNvNPAgQ5PCLIm1 SoWCQj1kKw/rHbMTBpp9KveqME1cj99GMkcuN91mYZl6BtJ6jSIQj3oSbEcwV/G/AlX1 nJ5+5bAGlT7tcElGpBjl3wrf5Yt033/eSZP03ppD5xNYN5cMUWIh5PpshAhfbYL39ZEw TmGw== X-Forwarded-Encrypted: i=1; AJvYcCViuodChbB2M7tqr3HASelRtp2sopBz3O5KJCO51Vtyps1oAC32OOOUdauqTL1CtV2Gakh7HTm2qOnCaoMIfeGH7II= X-Gm-Message-State: AOJu0Yzp5tfL2vpKoIEldPTgStgn8l5YWYJztsYPpIe+cnGSl42EtulR v9VyY2GSgfsSK44Z8xJMAEFrFj3KpT8zCWWxtbQWsYGr80SWVKKr/mdhNRSAac0= X-Google-Smtp-Source: AGHT+IG0odLHf0JhbhZb8Muk3vgjQvMvDZGGoTkntSJ6AQwPL3He86crHRASswudCYGbceV8muYfdQ== X-Received: by 2002:ac8:7f12:0:b0:441:55dd:b4f3 with SMTP id d75a77b69052e-44662eb927emr81392241cf.63.1719841976260; Mon, 01 Jul 2024 06:52:56 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-446513dbccfsm31269871cf.19.2024.07.01.06.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 06:52:55 -0700 (PDT) Date: Mon, 1 Jul 2024 09:52:55 -0400 From: Josef Bacik To: Jeff Layton Cc: Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , David Sterba , Hugh Dickins , Andrew Morton , Andi Kleen , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org Subject: Re: [PATCH v2 11/11] Documentation: add a new file documenting multigrain timestamps Message-ID: <20240701135255.GC504479@perftesting> References: <20240701-mgtime-v2-0-19d412a940d9@kernel.org> <20240701-mgtime-v2-11-19d412a940d9@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240701-mgtime-v2-11-19d412a940d9@kernel.org> X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 50C9220013 X-Stat-Signature: asfufm1hnmwreqehbbu7jqqyhknswebi X-HE-Tag: 1719841977-973826 X-HE-Meta: U2FsdGVkX19RhitkJE1tnFAWVvHuBgnwxIzvPuA7iWYsOiZwpE1UgUIdDUj2MvR54UztI+0rTN6CByhPa18lOcH8EdlG/VCOCc2r+3VLxCI2MXqbJ/MdIAMD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b8HtqyjnGPzbIHS8ENSgxv2gODueD3eKowO4uHfag5ejHWJ+CEnbC7aTFYscpGKde5WzmDIuWussPM2MvlLnF8sNeEHU8NWwrGiQnpSwYHlRJG02Rl+dW59WawMuRK+PAQ37NDOTWFSfDEABFPF4PXF9ARJzZLg9XiUacek7gyoK8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jul 01, 2024 at 06:26:47AM -0400, Jeff Layton wrote: > Add a high-level document that describes how multigrain timestamps work, > rationale for them, and some info about implementation and tradeoffs. > > Signed-off-by: Jeff Layton > --- > Documentation/filesystems/multigrain-ts.rst | 126 ++++++++++++++++++++++++++++ > 1 file changed, 126 insertions(+) > > diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst > new file mode 100644 > index 000000000000..beef7f79108c > --- /dev/null > +++ b/Documentation/filesystems/multigrain-ts.rst > @@ -0,0 +1,126 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +===================== > +Multigrain Timestamps > +===================== > + > +Introduction > +============ > +Historically, the kernel has always used a coarse time values to stamp > +inodes. This value is updated on every jiffy, so any change that happens > +within that jiffy will end up with the same timestamp. > + > +When the kernel goes to stamp an inode (due to a read or write), it first gets > +the current time and then compares it to the existing timestamp(s) to see > +whether anything will change. If nothing changed, then it can avoid updating > +the inode's metadata. > + > +Coarse timestamps are therefore good from a performance standpoint, since they > +reduce the need for metadata updates, but bad from the standpoint of > +determining whether anything has changed, since a lot of things can happen in a > +jiffy. > + > +They are particularly troublesome with NFSv3, where unchanging timestamps can > +make it difficult to tell whether to invalidate caches. NFSv4 provides a > +dedicated change attribute that should always show a visible change, but not > +all filesystems implement this properly, and many just populating this with > +the ctime. > + > +Multigrain timestamps aim to remedy this by selectively using fine-grained > +timestamps when a file has had its timestamps queried recently, and the current > +coarse-grained time does not cause a change. > + > +Inode Timestamps > +================ > +There are currently 3 timestamps in the inode that are updated to the current > +wallclock time on different activity: > + > +ctime: > + The inode change time. This is stamped with the current time whenever > + the inode's metadata is changed. Note that this value is not settable > + from userland. > + > +mtime: > + The inode modification time. This is stamped with the current time > + any time a file's contents change. > + > +atime: > + The inode access time. This is stamped whenever an inode's contents are > + read. Widely considered to be a terrible mistake. Usually avoided with > + options like noatime or relatime. > + > +Updating the mtime always implies a change to the ctime, but updating the > +atime due to a read request does not. > + > +Multigrain timestamps are only tracked for the ctime and the mtime. atimes are > +not affected and always use the coarse-grained value (subject to the floor). > + > +Inode Timestamp Ordering > +======================== > + > +In addition just providing info about changes to individual files, file > +timestamps also serve an important purpose in applications like "make". These > +programs measure timestamps in order to determine whether source files might be > +newer than cached objects. > + > +Userland applications like make can only determine ordering based on > +operational boundaries. For a syscall those are the syscall entry and exit > +points. For io_uring or nfsd operations, that's the request submission and > +response. In the case of concurrent operations, userland can make no > +determination about the order in which things will occur. > + > +For instance, if a single thread modifies one file, and then another file in > +sequence, the second file must show an equal or later mtime than the first. The > +same is true if two threads are issuing similar operations that do not overlap > +in time. > + > +If however, two threads have racing syscalls that overlap in time, then there > +is no such guarantee, and the second file may appear to have been modified > +before, after or at the same time as the first, regardless of which one was > +submitted first. > + > +Multigrain Timestamps > +===================== > +Multigrain timestamps are aimed at ensuring that changes to a single file are > +always recognizeable, without violating the ordering guarantees when multiple > +different files are modified. This affects the mtime and the ctime, but the > +atime will always use coarse-grained timestamps. > + > +It uses the lowest-order bit in the timestamp as a flag that indicates whether > +the mtime or ctime have been queried. If either or both have, then the kernel > +takes special care to ensure the next timestamp update will display a visible > +change. This ensures tight cache coherency for use-cases like NFS, without > +sacrificing the benefits of reduced metadata updates when files aren't being > +watched. > + > +The ctime Floor Value > +===================== > +It's not sufficient to simply use fine or coarse-grained timestamps based on > +whether the mtime or ctime has been queried. A file could get a fine grained > +timestamp, and then a second file modified later could get a coarse-grained one > +that appears earlier than the first, which would break the kernel's timestamp > +ordering guarantees. > + > +To mitigate this problem, we maintain a per-time_namespace floor value that You dropped this bit in the series, so this isn't correct, should just be "we maintain a floor value" Thanks, Josef