From patchwork Tue Oct 1 10:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817774 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 B24B7CE7D11 for ; Tue, 1 Oct 2024 10:59:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 348F5280071; Tue, 1 Oct 2024 06:59:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1A6280068; Tue, 1 Oct 2024 06:59:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14AF6280071; Tue, 1 Oct 2024 06:59:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EA444280068 for ; Tue, 1 Oct 2024 06:59:16 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9C29F160C8D for ; Tue, 1 Oct 2024 10:59:16 +0000 (UTC) X-FDA: 82624736712.28.9C6406F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id C4CD7C0013 for ; Tue, 1 Oct 2024 10:59:14 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=di+Ntkta; spf=pass (imf10.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780227; 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=q7XdCvNbTwtwXszIgu/p52GnWd98CBWi45ZNHRi5mNs=; b=wT6ltjV2dKR5YHrGKOkhicKkTa0OSS3dpRQt/vZ5gqTLJD8AjQ+t5BMzC7fWeufURxQp51 wbXgcmFdUzZ8aigecqw1t663m6YLvAXszVSLUCINvFKvPrbFwSbmaIqCxlhQlXeI3mS0/b n9qRi4eBiNLEia8cppgo4pPJsQZF/BM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780227; a=rsa-sha256; cv=none; b=WAJOZskjVT8Xv+gjdwGxfkt3SWabe1N3XYsPfD1mHfEPAgV85ZGps7wiiFDDFx2vnodCy8 pgXLsdfL9rTwZjxp5TveM2vHpivvpMyhouwATJuzfW3XkY/SjI28XxD9QalqXKtGaj9LRk kTZCwO2HZ5cCCktCGmPmCba3LZOJisc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=di+Ntkta; spf=pass (imf10.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A8C875C4D4C; Tue, 1 Oct 2024 10:59:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D676DC4CED1; Tue, 1 Oct 2024 10:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780353; bh=Dyhqpi3r2jE4Qp9OIe8aVuLXfVqzINBPByhzwJGovx0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=di+Ntkta84XIbICT1l6uHEZQqcJAWyuEkz56XDUMly44w/9xQ2bM53vsliOMIyNCY WFZn0iYiL+n2Am2GBNpYLLGzJZTei41kMfnCjKXAGL5+0Kjd9b4Lt6CI4iWbhpmG2d VonfbrVQIEV8jsfwNJ5Mj9v/c7o31NnoSV1WAqv/nBIXVbbW8KG16DvSATspUnUieR d2C+aaJF5j9nFIyonHxYD1CChWF6buB3hjeqpFSbgHAPikLudDgCuflPomFx1Sjw1y cNl6EADebtp4b5OqDvoz9O8qUSnTiSWj3lfjrGwBGUyH4qcPsWesmPEVq119GT5KqI SXviJqRrkTDvg== From: Jeff Layton Date: Tue, 01 Oct 2024 06:58:55 -0400 Subject: [PATCH v8 01/12] timekeeping: add interfaces for handling timestamps with a floor value MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-1-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=7181; i=jlayton@kernel.org; h=from:subject:message-id; bh=Dyhqpi3r2jE4Qp9OIe8aVuLXfVqzINBPByhzwJGovx0=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X5JtTXeFjUK9UuoZQvQI8+qcObCx94f/dTY /S/ZWh1uamJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+QAKCRAADmhBGVaC FSXQD/4lCar2TPcWziWfbWJoJLmUiOIURbAaVR6eJgKLBKHOgr9JM3SpvS1z6bDZU5a7tpyQvS7 YEwCjNF/vVWqnVGaNq9gSku9USOKNV4bvpJtatqhqKkYJGW99o6FoD0oP1M/hgJOtgZ4y4Ue0QE +I1FGS3T0QiJLp7T0QRNE548J5KdjyzC8d1vWEKHBoQaYuQNHOANILK2sx+7Ll9GmtR3oFKM6FZ vAb9Uq9cZiMCQH96uRU9SwOI7xRmv+s9wDvcVEmJ/C5sOfatL+SW1C9BH2scMXRXPeOHouFG24e Kssf4xMp6TxLT3pnQERfygw1v3T7JiSand39N+0sLQgE0Udb4XnXtTUQ86OOSeqmfg7lIQlq+fz RYk48ZGEWYokMxJBNf1zyXtAR6GHpECJ4+eWQsgZ3gh/vRjtepMfPyaQggBoAu9bcqZJzUdA7B4 PTKzVJlkCzn8FY/a8Wh/J7xzRBS9xds9fqTlTYLyBrxE7sIvG/7KXXbq/9rBSTJ3nZMrKrv3gzG pNmJlvToQsJSSGSiZJZxdt97nI2B4DD4xAo87YdPd+1rxtE3PzeiF2KGu0Fdg+xA+GivAJc2v3t HamDS6Ofti8G/RFQGXJhwpAPytOmoiBVhg8iETXmCBzB5kFpn66ywgDs1zySURdVisrTq+6Qvxx f5+y8P3aSPKiW+w== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: 1ttt6w4s876mdgspbxdsety5c1hsi4ih X-Rspamd-Queue-Id: C4CD7C0013 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727780354-751441 X-HE-Meta: U2FsdGVkX1/RHAo6d8/sOBCeZSWcLsamLa+bUTSaCfV4BkRpeeNj0H/QlZlu9dSoXG98+tUG2qW2RIf/8HVTmFz4IDoMZuSYkfVwVKs6NNsYmjcOr0jwdszu4AkTxpYOSdGQaUkbo+hu4pqJm1RXgHYwugUM1iOp4d9bFaHL3lSwkenQ4GC3E9XyTtXa2Dgt1QKb/3dV8IEWqJ+iBfll/z2PKwXouMA0khFwYeLol9rzL91X5zyqZWSJ7hlAZO1KMQXtg/3t2UVfohxlPkQWAJ4adPBuBYpnFuZ+0RoQr6eZig46DOqi9DSGw2JwIhPJvVy68oIWyI6u0IpdzYESk0g6xexRyfcf6qLYmhC9LpjUAosnx6viXqfSI0KEd37Ym3tlgDgQB8xQ7Ce6d5C9jzpHhMcrwZXmSfZTwT6mOfgLm2iZOzF56LRgGoM8EvR7aUpo9WsprI4/faBui7dSA72UUzzjiRbbUjq7JI4vLVUSV4iEvUErGrGKJ7USK/FxgiQ095UkIWmMYJAkJFPEfU91Zu4061wzZJgQ+SpUa/FeDc3FHINMGVbFLKKB9ybJL6ObIrTBX4gop0RJQeo2NkQSR/7llXgQOoEvlih8VGjvmmHrag0e4beiI1bcGX3v5KlT7ent2GMyPgHxHgYnKvF5S12yziVPRws6knNzpd3h1F1NM+6u4jLzoBZtTmR7UsA5Vz5zpXhIsUgplFkNKi5cPtIxN4fM8R7QCp3etbIl/E1l7KeNQNXojj00bmGIEV6trehJQn76CYkGelUiNtUpBpzCx8VeFWgKfYRZx6s2X5yW3SYpFGt5tHJG5dAHlB6pZ3sTEZscOHUB8kOscrLpZI5hHNmxcmR+wm+QkdQ9FcoSOFAkCKqNibcKhK48BvktAgyAXulofwwoD7y3yT1YcnZr3xoAMa8Z7hNW8ctQIqbLw2Vr3J8DcBW39YCX7OGLyuEey/S5dlzj29Q DZPMdmYB iIS5ihIxevaZuS9XCOk/x1f5584XYcZ72iGKAtC2/sl9gVwTmcIpy+79wBZl9/veZqvxCp4e+g9H2R0PUskuK5nJnrGp+7hBHsFDIKSyyKahC7q7Qb3ZKn751iR/lktKrp1tfHBOVOg6J3S4Bj6An/6sJ1UdCrLLPrQp5JHm7ASDYIeIYReSixMl4AvyhL9OOod8tvKEl8xxi3VBxE/e67Jj0WrQQFWmLnzcBRoWk13s3ok8Tu/zY5qaVJRSF74WgoyDhjCgda4Rg6gQbWJpjFjcWDg+PX4DUMbL3BmWc1xQvb9Vio76P53SjbA== 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: Multigrain timestamps allow the kernel to use fine-grained timestamps when an inode's attributes is being actively observed via ->getattr(). With this support, it's possible for a file to get a fine-grained timestamp, and another modified after it to get a coarse-grained stamp that is earlier than the fine-grained time. If this happens then the files can appear to have been modified in reverse order, which breaks VFS ordering guarantees. To prevent this, maintain a floor value for multigrain timestamps. Whenever a fine-grained timestamp is handed out, record it, and when coarse-grained stamps are handed out, ensure they are not earlier than that value. If the coarse-grained timestamp is earlier than the fine-grained floor, return the floor value instead. Add a static singleton atomic64_t into timekeeper.c that we can use to keep track of the latest fine-grained time ever handed out. This is tracked as a monotonic ktime_t value to ensure that it isn't affected by clock jumps. Because it is updated at different times than the rest of the timekeeper object, the floor value is managed independently of the timekeeper via a cmpxchg() operation, and sits on its own cacheline. This patch also adds two new public interfaces: - ktime_get_coarse_real_ts64_mg() fills a timespec64 with the later of the coarse-grained clock and the floor time - ktime_get_real_ts64_mg() gets the fine-grained clock value, and tries to swap it into the floor. A timespec64 is filled with the result. Since the floor is global, take care to avoid updating it unless it's absolutely necessary. If we do the cmpxchg and find that the value has been updated since we fetched it, then we discard the fine-grained time that was fetched in favor of the recent update. Note that the VFS ordering guarantees assume that the realtime clock does not experience a backward jump. POSIX requires that we stamp files using realtime clock values, so if a backward clock jump occurs, then files can appear to have been modified in reverse order. Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton Acked-by: John Stultz --- include/linux/timekeeping.h | 4 ++ kernel/time/timekeeping.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index fc12a9ba2c88..7aa85246c183 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -45,6 +45,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 interfaces */ +extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts); +extern void ktime_get_real_ts64_mg(struct timespec64 *ts); + void getboottime64(struct timespec64 *ts); /* diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7e6f409bf311..37004a4758cf 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -114,6 +114,22 @@ static struct tk_fast tk_fast_raw ____cacheline_aligned = { .base[1] = FAST_TK_INIT, }; +/* + * Multigrain timestamps require that we keep track of the latest fine-grained + * timestamp that has been issued, and never return a coarse-grained timestamp + * that is earlier than that value. + * + * mg_floor represents the latest fine-grained time that we have handed out as + * a timestamp on the system. Tracked as a monotonic ktime_t, and converted to + * the realtime clock on an as-needed basis. + * + * This ensures that we never issue a timestamp earlier than one that has + * already been issued, as long as the realtime clock never experiences a + * backward clock jump. If the realtime clock is set to an earlier time, then + * realtime timestamps can appear to go backward. + */ +static __cacheline_aligned_in_smp atomic64_t mg_floor; + static inline void tk_normalize_xtime(struct timekeeper *tk) { while (tk->tkr_mono.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_mono.shift)) { @@ -2394,6 +2410,86 @@ void ktime_get_coarse_real_ts64(struct timespec64 *ts) } EXPORT_SYMBOL(ktime_get_coarse_real_ts64); +/** + * ktime_get_coarse_real_ts64_mg - return latter of coarse grained time or floor + * @ts: timespec64 to be filled + * + * Fetch the global mg_floor value, convert it to realtime and + * compare it to the current coarse-grained time. Fill @ts with + * whichever is latest. Note that this is a filesystem-specific + * interface and should be avoided outside of that context. + */ +void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts) +{ + struct timekeeper *tk = &tk_core.timekeeper; + u64 floor = atomic64_read(&mg_floor); + ktime_t f_real, offset, coarse; + unsigned int seq; + + do { + seq = read_seqcount_begin(&tk_core.seq); + *ts = tk_xtime(tk); + offset = tk_core.timekeeper.offs_real; + } while (read_seqcount_retry(&tk_core.seq, seq)); + + coarse = timespec64_to_ktime(*ts); + f_real = ktime_add(floor, offset); + if (ktime_after(f_real, coarse)) + *ts = ktime_to_timespec64(f_real); +} +EXPORT_SYMBOL_GPL(ktime_get_coarse_real_ts64_mg); + +/** + * ktime_get_real_ts64_mg - attempt to update floor value and return result + * @ts: pointer to the timespec to be set + * + * Get a monotonic fine-grained time value and attempt to swap it into the + * floor. If it succeeds then accept the new floor value. If it fails + * then another task raced in during the interim time and updated the floor. + * That value is just as valid, so accept that value in this case. + * + * @ts will be filled with the resulting floor value, regardless of + * the outcome of the swap. Note that this is a filesystem specific interface + * and should be avoided outside of that context. + */ +void ktime_get_real_ts64_mg(struct timespec64 *ts) +{ + struct timekeeper *tk = &tk_core.timekeeper; + ktime_t old = atomic64_read(&mg_floor); + ktime_t offset, mono; + unsigned int seq; + u64 nsecs; + + do { + seq = read_seqcount_begin(&tk_core.seq); + + ts->tv_sec = tk->xtime_sec; + mono = tk->tkr_mono.base; + nsecs = timekeeping_get_ns(&tk->tkr_mono); + offset = tk_core.timekeeper.offs_real; + } while (read_seqcount_retry(&tk_core.seq, seq)); + + mono = ktime_add_ns(mono, nsecs); + + /* + * Attempt to update the floor with the new time value. Accept the + * resulting floor value regardless of the outcome of the swap. + */ + if (atomic64_try_cmpxchg(&mg_floor, &old, mono)) { + ts->tv_nsec = 0; + timespec64_add_ns(ts, nsecs); + } else { + /* + * Something has changed mg_floor since "old" was + * fetched. "old" has now been updated with the + * current value of mg_floor, so use that to return + * the current coarse floor value. + */ + *ts = ktime_to_timespec64(ktime_add(old, offset)); + } +} +EXPORT_SYMBOL_GPL(ktime_get_real_ts64_mg); + void ktime_get_coarse_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; From patchwork Tue Oct 1 10:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817775 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 008F7CE7D13 for ; Tue, 1 Oct 2024 10:59:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 830C7280072; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78D1A280068; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59238280072; Tue, 1 Oct 2024 06:59:19 -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 1A5D2280068 for ; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D0A7481064 for ; Tue, 1 Oct 2024 10:59:18 +0000 (UTC) X-FDA: 82624736796.04.9030648 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 1BD80180007 for ; Tue, 1 Oct 2024 10:59:16 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RKj3yhF+; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780263; a=rsa-sha256; cv=none; b=wfsUvZ2kr74FRL9MxN3s4gwXbdmDevbVTmoWB1NeToTVdloo4nGGusKU7ggbjsbStnwZnh +ljBWbGA0Ro7UZEzFjWRh06aaKrshbMZ3bIrImQiSEzyfPnDMdXv4fHan58KWB7L4Yzwyw osLM8OSvsx4Yu9AOEduUaZ3XSGs/3a4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RKj3yhF+; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727780263; 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=yiUOK3rTw35TZrDDtW4Dy9XZk4oh8mUxmZIeN6Z2Fj8=; b=KS3Gnf2gJtpuVYvPrcVnaF6tzCcakhq/+bGMgOWukCAQ7nBCBrMVXiiFCjSTU+LC/QbM4B MYxtBeC7qKBQOAbwZ2X+1hKtxSOuAswRHtgKEn0ehGoRetbTKXvzaXZr+v9bt6zPFMJEKp 5Hsat27Ig92obRT7Zvci5Mr4OacZWg0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 198E8A434E3; Tue, 1 Oct 2024 10:59:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DCE5C4CED2; Tue, 1 Oct 2024 10:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780356; bh=aZAy0l7/4k2LGVLomi5Ve4y/LL6QUr6Sx2B+lukvqM0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RKj3yhF+oyStx9Ni6wvM47DBmMhesTGtSCcVZdAfTR4yHvS0WANQ3nvJpFYGtLuhE 8CTbi5m0FG5JDzr6TH+WHBA87ZeoNTTbCpdM276nOUd/nyewrZqFz42lu2WwJU7myQ yocbQsn859y/ddxiV1KGzbca9l+PW9WxNG15zleyD+i2DYRfLODpBXMxVxxWXnEBzO pEPRO9f+Y6NHr2MTh028YXXoS1+bFDYVbocP0/8x5kGDbe55/50Aa2PPptcQmptjno m/1eK26LozQyaAgmrbp4I06xI/IShYV+wcnvmxH5K+Rdr9UIvD26hxRx5n4DoA/jf9 7Khcg74ufAZSg== From: Jeff Layton Date: Tue, 01 Oct 2024 06:58:56 -0400 Subject: [PATCH v8 02/12] fs: add infrastructure for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-2-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=13860; i=jlayton@kernel.org; h=from:subject:message-id; bh=aZAy0l7/4k2LGVLomi5Ve4y/LL6QUr6Sx2B+lukvqM0=; b=kA0DAAgBAA5oQRlWghUByyZiAGb71fmhaxnBnt3uu+eWAn3QZ18UG7uIL1EaKhEmH/OooHjaT okCMwQAAQgAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJm+9X5AAoJEAAOaEEZVoIVSf8QAM+g MP18mwnri8/J0NBz/aWBjcV49FmVxqQWT1SKFUxkr+SiCkdR95yiZrA6HxJKjmG33TwqtYE1xxy jE5MmASJRwNH6eYdcVLzA0HCE+8E8NOQxC7oftNAnRUGVoXbKGK917J3R7CWKt3m9HH2hKMhpvN eW5V0+jP46fcviUwwmn/Hsbqd1ZkfKRsxNXLF8oj9wzYaKQPqLshJOrJXZdnQ8vfsnrj1DCMTtL aDl8K3fIrKV4iuwX87XGp+MuIk30uG7aP/F8n79JcjuW/iHCQXhzKbXGxR0kQGCWKVRerRgry7o RBoX25Sp5bSmIyssXym+CCp3veoq9SNx1l6Pv4EjdpvXr8jwESXNwE7eTrbQxhpPbXJ7P22ZvrF pSY6FpesmwMvkBYuq9SO1ke0GlgGfhtGUYy12PBhsO4wQWGcLHII9K+4EQeuPxDf6BxrgsXsOYj t38h1Ag63T5oSCVrEUCntMTTwCdf2dXv05RKGNyOMAxdsoydC4H8+/YLoBI6zVwvbT1qXUBzg2F nUrepXFfsDgWtVXvjGIAhVvOz4Zhfq9F9Q+taMn7ECNfVAGnFdBF5e74PZVg137ChVusDy4SXfN IdcZiZpHU36/BrIij7yRtN+XpQhbFUhdhPHRC6nz3idRe6Y2lCsqTPVpqyy+tFA9mBlSl/QNjTL pIj6H X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 1BD80180007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: g868dt6eksb9yfr3ebjtpe7hsaac9dgw X-HE-Tag: 1727780356-285665 X-HE-Meta: U2FsdGVkX19Iq9MzHdR7wXBSFbh13mFM3qqR8rRed2kUDsWYzOXqUGk4fH/TiyOKxqEDOMtDeh8bW9G3dJxFf1fNl5WHHzj+k0HPfg9m0LsNPted//e/u6HO48kOr/PszEvXg9VyH0rgRUOfGaOTuzu2Jh4DGZihMt03jLZRFmNwSdB06hs7H//XbxIpxfAbpRVQhHgRGPT6Ap9lPWz763tNDKF7UlYredXLtBl6LJk4hvHW/YzY4Wo7gC8JsuDxeFgZIOj8/6TUXNtXv+xbxU1D50GGyV/tC8FoTMOj+5xKAwgpfvOZFnfwse7aN5egrDUDTDCFeSuiTxv/8vQ1wyOGLsYoxcGWRsdkOapRgLMtZZklklcNdvZPOx7dMMNEmwOeU0FD36sFMZ5j00pJMv62NjDYK1pGvv1bRnM2yyvFJ2zeUodJ4QlrKVTB8CRSsisUtLBtcMEu9ZXRJix6G+PTQ/53KO13K1+6DcKcolRn3b74CwYo677JnBP9E1Kofxf40wRdSCMvIVy9BwAukSK6NJvEK2oOxEas9acGvT9uxbP5O4EQY9k2R2caHi1ZiK3NfaN2wU9ff8xI/HMkQ0RpuMlyFCF5agV9WTWJrL/dF+TjFODd5adNv/fE1JjF878A+l5Cpmb6QrZH2E/xaKGnXIMQc73Jt35KqNOsFVEOZax1or3TNbkLr4wIuR+/LWCYrHvin12iG4PZK5F+MBMG7td1QZSw+Il+AulpWuZDkddonDIOUwsvWfcaaHRuN671hzw7vqfenofFWpGPZJOjbJpaegk3T9RH7za9qGNpzzf7xCDMFfJ6zgsApwQ+Zy8CKT/+c7D4HHK+bjZnQE0nxD5pY/jsHrmjEFkGRu+asGPtZ10koTZ+R6ZpjzLCjEX7pp1GN85FQxLC4273CPFIN42LPKCijdBQCzhbvysphK1vdHefhYX5r6YJSI929dByi6wj9ziBWBhgety E8M2QpSw ZVS9TSlaCLGzTdyqK7pHo20PvJHrX2CZoITjKivWqYvgOfR9FbxAgtgsDZYBgfOa/eRXgLZOiOjfHegB6pQG4mp/32cVUzkxRALgBk89kJQ7j6EW3OaggyLoNnHpkalaSZUnkYLWu3XVdNgEjH7YWY30hVTzoGdJ2xRp513Mn5Mc8uVPSNxIizfakhVNpy6MMQ5WHiGnC9tI2wPtrTPx+3rxF0sMZkYU2r4CudbLTHWcgYM2oqzpAEl69VfoudLB6JEdc9Lbt2XFuwOSDG8JXV29KaZeRGfRZQOjIQoCdOp6aV9wvnoyHuqdqPQ== 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: The VFS has always used 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 when 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. Use the (unused) top bit in inode->i_ctime_nsec as a flag that indicates whether the current timestamps have been queried via stat() or the like. When it's set, we allow the kernel to use a fine-grained timestamp iff it's necessary to make the ctime show a different value. This solves the problem of being able to distinguish the timestamp between updates, but introduces a new problem: it's now possible for a file being changed to get a fine-grained timestamp. A file that is altered just a bit later can then get a coarse-grained one that appears older than the earlier fine-grained time. This violates timestamp ordering guarantees. To remedy this, keep a global monotonic atomic64_t value that acts as a timestamp floor. When we go to stamp a file, we first get the latter of the current floor value and the current coarse-grained time. If the inode ctime hasn't been queried then we just attempt to stamp it with that value. If it has been queried, then first see whether the current coarse time is later than the existing ctime. If it is, then we accept that value. If it isn't, then we get a fine-grained timestamp. Filesystems can opt into this by setting the FS_MGTIME fstype flag. Others should be unaffected (other than being subject to the same floor value as multigrain filesystems). Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/inode.c | 137 +++++++++++++++++++++++++++++++++++++++++++---------- fs/stat.c | 39 ++++++++++++++- include/linux/fs.h | 34 +++++++++---- 3 files changed, 175 insertions(+), 35 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 471ae4a31549..4ec1e71e9a9d 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2209,19 +2209,58 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/** + * current_time - 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 ctime/mtime change. If the ctime is flagged + * as having been QUERIED, get a fine-grained timestamp, but don't update + * the floor. + * + * For a multigrain inode, this is effectively an estimate of the timestamp + * that a file would receive. An actual update must go through + * inode_set_ctime_current(). + */ +struct timespec64 current_time(struct inode *inode) +{ + struct timespec64 now; + u32 cns; + + ktime_get_coarse_real_ts64_mg(&now); + + if (!is_mgtime(inode)) + goto out; + + /* If nothing has queried it, then coarse time is fine */ + cns = smp_load_acquire(&inode->i_ctime_nsec); + if (cns & I_CTIME_QUERIED) { + /* + * If there is no apparent change, then get a fine-grained + * timestamp. + */ + if (now.tv_nsec == (cns & ~I_CTIME_QUERIED)) + ktime_get_real_ts64(&now); + } +out: + return timestamp_truncate(now, inode); +} +EXPORT_SYMBOL(current_time); + static int inode_needs_update_time(struct inode *inode) { + struct timespec64 now, ts; int sync_it = 0; - struct timespec64 now = current_time(inode); - struct timespec64 ts; /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; + now = current_time(inode); + ts = inode_get_mtime(inode); if (!timespec64_equal(&ts, &now)) - sync_it = S_MTIME; + sync_it |= S_MTIME; ts = inode_get_ctime(inode); if (!timespec64_equal(&ts, &now)) @@ -2598,6 +2637,15 @@ void inode_nohighmem(struct inode *inode) } EXPORT_SYMBOL(inode_nohighmem); +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) +{ + set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_nsec; + return ts; +} +EXPORT_SYMBOL(inode_set_ctime_to_ts); + /** * timestamp_truncate - Truncate timespec to a granularity * @t: Timespec @@ -2630,36 +2678,75 @@ struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode) EXPORT_SYMBOL(timestamp_truncate); /** - * current_time - Return FS time - * @inode: inode. + * inode_set_ctime_current - set the ctime to current_time + * @inode: inode * - * Return the current time truncated to the time granularity supported by - * the fs. + * Set the inode's ctime to the current value for the inode. Returns the + * current value that was assigned. If this is not a multigrain inode, then we + * set it to the later of the coarse time and floor value. * - * Note that inode and inode->sb cannot be NULL. - * Otherwise, the function warns and returns time without truncation. + * If it is multigrain, then we first see if the coarse-grained timestamp is + * distinct from what we have. If so, then we'll just use that. If we have to + * get a fine-grained timestamp, then do so, and try to swap it into the floor. + * We accept the new floor value regardless of the outcome of the cmpxchg. + * After that, we try to swap the new value into i_ctime_nsec. Again, we take + * the resulting ctime, regardless of the outcome of the swap. */ -struct timespec64 current_time(struct inode *inode) +struct timespec64 inode_set_ctime_current(struct inode *inode) { struct timespec64 now; + u32 cns, cur; - ktime_get_coarse_real_ts64(&now); - return timestamp_truncate(now, inode); -} -EXPORT_SYMBOL(current_time); + ktime_get_coarse_real_ts64_mg(&now); + now = timestamp_truncate(now, inode); -/** - * inode_set_ctime_current - set the ctime to current_time - * @inode: inode - * - * Set the inode->i_ctime to the current value for the inode. Returns - * the current value that was assigned to i_ctime. - */ -struct timespec64 inode_set_ctime_current(struct inode *inode) -{ - struct timespec64 now = current_time(inode); + /* Just return that if this is not a multigrain fs */ + if (!is_mgtime(inode)) { + inode_set_ctime_to_ts(inode, now); + goto out; + } - inode_set_ctime_to_ts(inode, now); + /* + * We only need a fine-grained time if someone has queried it, + * and the current coarse grained time isn't later than what's + * already there. + */ + cns = smp_load_acquire(&inode->i_ctime_nsec); + if (cns & I_CTIME_QUERIED) { + struct timespec64 ctime = { .tv_sec = inode->i_ctime_sec, + .tv_nsec = cns & ~I_CTIME_QUERIED }; + + if (timespec64_compare(&now, &ctime) <= 0) { + ktime_get_real_ts64_mg(&now); + now = timestamp_truncate(now, inode); + } + } + + /* No need to cmpxchg if it's exactly the same */ + if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) + goto out; + cur = cns; +retry: + /* Try to swap the nsec value into place. */ + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now.tv_nsec)) { + /* If swap occurred, then we're (mostly) done */ + inode->i_ctime_sec = now.tv_sec; + } else { + /* + * Was the change due to someone marking the old ctime QUERIED? + * If so then retry the swap. This can only happen once since + * the only way to clear I_CTIME_QUERIED is to stamp the inode + * with a new ctime. + */ + if (!(cns & I_CTIME_QUERIED) && (cns | I_CTIME_QUERIED) == cur) { + cns = cur; + goto retry; + } + /* Otherwise, keep the existing ctime */ + now.tv_sec = inode->i_ctime_sec; + now.tv_nsec = cur & ~I_CTIME_QUERIED; + } +out: return now; } EXPORT_SYMBOL(inode_set_ctime_current); diff --git a/fs/stat.c b/fs/stat.c index 41e598376d7e..381926fb405f 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -26,6 +26,35 @@ #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 (if not already) + * so the next write will record a distinct timestamp. + */ +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) +{ + atomic_t *pcn = (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->i_ctime_sec; + stat->ctime.tv_nsec = (u32)atomic_read(pcn); + if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED)) + stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)); + stat->ctime.tv_nsec &= ~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 +87,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->ctime = inode_get_ctime(inode); + stat->mtime = inode_get_mtime(inode); + } + stat->blksize = i_blocksize(inode); stat->blocks = inode->i_blocks; diff --git a/include/linux/fs.h b/include/linux/fs.h index e3c603d01337..23908bad166c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1653,6 +1653,17 @@ static inline struct timespec64 inode_set_mtime(struct inode *inode, return inode_set_mtime_to_ts(inode, ts); } +/* + * 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. + */ +#define I_CTIME_QUERIED ((u32)BIT(31)) + static inline time64_t inode_get_ctime_sec(const struct inode *inode) { return inode->i_ctime_sec; @@ -1660,7 +1671,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) @@ -1671,13 +1682,7 @@ static inline struct timespec64 inode_get_ctime(const struct inode *inode) return ts; } -static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, - struct timespec64 ts) -{ - inode->i_ctime_sec = ts.tv_sec; - inode->i_ctime_nsec = ts.tv_nsec; - return ts; -} +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts); /** * inode_set_ctime - set the ctime in the inode @@ -2542,6 +2547,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; @@ -2565,6 +2571,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)); @@ -3321,6 +3338,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); void generic_fill_statx_atomic_writes(struct kstat *stat, From patchwork Tue Oct 1 10:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817776 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 156DCCE7D0D for ; Tue, 1 Oct 2024 10:59:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91778280073; Tue, 1 Oct 2024 06:59:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C7D6280068; Tue, 1 Oct 2024 06:59:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73FCF280073; Tue, 1 Oct 2024 06:59:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 512D8280068 for ; Tue, 1 Oct 2024 06:59:22 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C2E691C6D18 for ; Tue, 1 Oct 2024 10:59:21 +0000 (UTC) X-FDA: 82624736922.27.98500B6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 0C65B40004 for ; Tue, 1 Oct 2024 10:59:19 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jdWGxNnl; spf=pass (imf04.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780233; 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=y4X6MpHEZdpIW7VKtZ7efno5ZAgBe2Y7SL9cgZuuKEQ=; b=TLdpC7YALZP0DmpX0cxZR/+evO5i4+UG4viDScbQm2zzeKz7Zfuz7REvK/ux0pY7AIrj4V /C4q95Y3gc9aiLdS5LTaqtMpshcrk+zYHb9InJhufzxfj4UJZHpW2IVaOVBI/6nlu3Wg50 HjhYWY1obso24qe+OvWd7KUs0bac72A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780233; a=rsa-sha256; cv=none; b=l0iXbx1XZpMj6tldDNKWIXZFXsqfY7Vu45zRQJFY1Nddd4UOJzui5JKW+1cS/edH/hGFvw f3O+5TKCCD7eoysoCRpq65aC0E2AjrvShRnO+UxWTRYxcIwa7LvyHL48kZJpDCsTXSdj+t pkLiuzwXo4/zOpeXACZGFpNyTUo2HX4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jdWGxNnl; spf=pass (imf04.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 362A25C4D08; Tue, 1 Oct 2024 10:59:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64621C4CED4; Tue, 1 Oct 2024 10:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780358; bh=IlK6pMQl1VZaRTQUEj0w67Ch4gWJlIpgXXZruOpOJpc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jdWGxNnlxMwS3+6yjpiIb4x86c6Y3TIErGhniYiNJEOlBFtaxtSGyGJt+YG5JfF5f Co1d4yP95nQF48Y/dcoyaN9DwQBiAFu65Q0MGvTNlhACrPKqHrmzHIAABtrJz47+Fw 3jm3yyjCpgoEKgki1HQlYZFsxXrxk8jaNcgNtoRRRGLXZCym4pKWd8+zTdVtwDO6x6 94owkToMnnnb7OJ5AxGK2IsD08ngJDcukm/REUzkRh1mhDiXycOKyXO67/ReZ60dMa bDAWfvx38Ki4Gisf95iOtoLVvJ5cvcqpxn6qTV2WmySIld5q86F3P4s4KSPwK9/a7C 0phOrYwm4fXmg== From: Jeff Layton Date: Tue, 01 Oct 2024 06:58:57 -0400 Subject: [PATCH v8 03/12] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-3-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3610; i=jlayton@kernel.org; h=from:subject:message-id; bh=IlK6pMQl1VZaRTQUEj0w67Ch4gWJlIpgXXZruOpOJpc=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X5YIAUQIyeGlbkZz0C3Ucs84y+6R8LaUnqt K6DgFg2Ba6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+QAKCRAADmhBGVaC FUcAD/9+TpkoTJObmH1PTrMTi9b6fcDncKerKYhSvomtiUjooe9rP/Z43xb4vfBPHr+mdv9BMDk vMyzIlNK4KZJczt626wn0uV7YrtEHK4SbfNP87PPyZpGztVypqDRAKlx+F5+brwhkYFacDgOiHb WWj6/5oN+zfWHwoMYoa7MuCyf65x1tipBW992ENarxxcFfvFXMeEX2HyJSwu/xlDSQlObSu562a 2GqqvYxaIyJOApO1L4X3rYAoH64xrsCaXWR+4yub4SVu/T3kLXA9K4OxTtJDTnFF1K2Vc+jJEgF 91PqQ61OrRHOuI2CeuSP+K66j/Bo+7/MuDZVhTbRPUTUbaio8MVXLyc0Ak4Q1Nwq1AsPSQPZGba I7htvHUy7c2gRCSoY+tbesZaCesFgqvjRD64fzIy6QNUNb1tfdfEbswaX4cbp2xRZd6mcB52Y0S 4KA63naImLEGCVt+sEGX23x7sv/d1LsFbl/5FlJnIsx/XYNr1Zcb4MwnohlwMTZOFGRge2BXO1Y LxXZ+rUZPw3WDGnO9ONYeKb4juvJy2C1Psgq1Sb5RbG947cVEhpsoVUd6j6EBpXLWIP1RrTcomR a840JJBQ7phKKl3uGoFB/BWexhtYGZCe9RWI79hcjdxdHDq2Kd0JKKT177yuKkshdKXvQpfvVSC kV8NlS8NDSS/E2A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0C65B40004 X-Stat-Signature: q1td9qwukphea3tg9bf56tjtdttfym4m X-HE-Tag: 1727780359-139840 X-HE-Meta: U2FsdGVkX1/wEI/bJgg5QzBvgPDhOzCupib4s2saJ3tDwCJIG2dX37gHI903XxMa/CU5t2tz1b5AdN2NggaZNu+U/o+cVFQesUgegSNssM80uSzKQdtEHuLS7Zo5epwSM3v5rZywjzkZnP40ydwneDvXpXEw92SHAR4y3F0WfvUdZpI2dDD5v5k9p8E19WA3ybjW17mj6WxzbTZERWQTK5uVXvRwIjPr97mb0Smz9CQLiUDln5P9qscYXHxaATCsH0gJa+pCJKHkd75UYMVVX7iwGjq5GiR7hgMwdxYxBPhZdbL48EpzVtA0OTd877meYzVroXXXqtZgBYU7kNViS1rbeIreFTIw4zhwZABUeIRlsT5480g7rkiydukvodQSqpX8ecIXpzjNK40e9PCGfEQ+T2ViXaEjsKPBkuniAtorcGse+onu0ketiPqUZmJhD8tmYo1G9++zyp1c7wxjVqjqbWMhboZ390F0rhn88zqUQty6+1gZbD1XFtraOmlp2pKOF676X/mvMj1z9A0zgD/+sRvLnsrbabXEa7+bgxB7eczKNhd2d4J0Kd9/7+pWV9xrIpks3BmqeD8ggznXnxHfSOFm8wwvK2Mv6kyJHpifnXLdpnhmKsLWTg0zpwogEG1O9VZ4qkzwEecrV3MkmsAnG6ktrbrx+CuqLhRWlTvrJm9+SRAM2O7S9n9ReB9wIiJN82obzYhAYo/MPn9zo1DU5TXhQfo0TixYVf2Ga4LjYdQTUzKP9tKVsYb/u6cZ+QN3Kh6IbBhMHCE2vKEZYg22haedRU/VLcI0l1pqesaxVpy6yojS/IcHlrui5bYAG9q4OEZw91ZlZ/K4P+oi4GFkwFjhXESUakpcYr2v7jg0ygZnY0d1zjMT8nk9dezpV27O7XKNYLn5/UichUksncm/77YX/WeLJ+Oq7Lllr6mwXKMMQ9J1PcqqMy7tWo3Lbh0pbCMtfNeGUOxU8kF S00Fno3K n+N0yANkemBulH3nxOBmmgBX9ZiY3u4eqapOIbhO3uSRfsQ1FzxMYt30/2jdNCw3WImtT2LIdbT65c5DPU5Z00gKqkKUEEZDUOMzHvz/cTLNrWFJ98p9872H8SOVonFVgRaQ4fOX685xNbX7xfJ9IIezilO90WWAtabEjKdJ0zfSuu9rzh/eidXy2QvfDfyjVo8Mk11N1Wnz119uhTjDndfHQKuNyDwjXMoxktgdve6Qj+oQtQZZePw8+OQ3Ep//bczxGsefdVL44xXSMpYJuwdGBlLZvUY4yp5ckCTjdJvzNxsHkJkzE5mOcNxtFHUFCqnBVkHLOwS1S12QWsnbVxOj4Xc+pgIYEYvnBHUUh4jgi4kUKVcqCw0G/kAF8ATsCng2e8nD3UqczYVEsNQuMtl8FiocLo3naKco/ 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: 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. Reviewed-by: Darrick J. Wong Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits 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 c04d19b58f12..3bcbc45708a3 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -271,6 +271,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 @@ -303,12 +339,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, @@ -316,6 +346,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 Tue Oct 1 10:58:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817777 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 4C706CE7D14 for ; Tue, 1 Oct 2024 10:59:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC08A280074; Tue, 1 Oct 2024 06:59:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4847280068; Tue, 1 Oct 2024 06:59:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A26B2280074; Tue, 1 Oct 2024 06:59:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 79C39280068 for ; Tue, 1 Oct 2024 06:59:24 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 364FF120FCD for ; Tue, 1 Oct 2024 10:59:24 +0000 (UTC) X-FDA: 82624737048.22.8E89765 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf08.hostedemail.com (Postfix) with ESMTP id 79745160019 for ; Tue, 1 Oct 2024 10:59:22 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iouMPU0k; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780342; a=rsa-sha256; cv=none; b=EeLuu9gftcYoJ0gXXlJA8GB76Q8zqKqxqZJPO4GX9EP9nAts6iXQdgBTkgleU8+FB84+6b vLOhw0V0BADIiWL/xFmUm8iovmTc5nkg2kAduohmbAsahwK4ONmMNupja07/Ubz5UO2Kr+ 3GY/Wv/n2/sBByBG5LKZHS1UL0rc3GQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iouMPU0k; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf08.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 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=1727780342; 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=M9B4Ipm5j8bxXr4of9Ewzaksl/6V7W9qA18FLGIis8o=; b=qwgwko+WiX41q2lvdNv74cPUIaKfLpHraFtc1oNNQ4GTn8+7sRYRb/WoHnVTBHFm6NkTdW Tha92mgT0vAdA0ku2ikixBCGKGLbJH6hyzG6WA3OWMHV5SsqIyHIlb9LLNxWPp9rPC8yYK GjnUmnTWPpc8A/S94ax+t6cUrMFXOSw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 8E060A434DC; Tue, 1 Oct 2024 10:59:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B8A4C4CED3; Tue, 1 Oct 2024 10:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780361; bh=otxFDOKr6FG8LsCMnriOfpK/JOFC4LtwAGxd1Ko/vgM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iouMPU0kTWC6M8npPfU0q2wFskriO4LNOr8BhfkrxeQrTmfuwtAU2qX8aV59H/EWu yb1y5W49N4SFLIMhwFa+ZA7jQ26HCsz5y1Nc1/f9BCH1gRee7b8ynledplAnFSI57V 263wZ+4IpzwtwIGp8fEeauEOLFnV256F8asITtggzLheTwjSCtfKX1pg8YVm5qukWP lR3lBRAAc91/iOB/suVkMLg2fT2MetTV1GW+6qmAbhHvlpZ3z36l5wb97Wsas8nXyn NGwYXVDOZogH8ePpV0Ue1A/e52jiyh0d2BqZycje35KAPLWN2/Qs/mw30lkiZBn5rF NPJcQXpRtFaMQ== From: Jeff Layton Date: Tue, 01 Oct 2024 06:58:58 -0400 Subject: [PATCH v8 04/12] fs: handle delegated timestamps in setattr_copy_mgtime MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-4-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6276; i=jlayton@kernel.org; h=from:subject:message-id; bh=otxFDOKr6FG8LsCMnriOfpK/JOFC4LtwAGxd1Ko/vgM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X64D3EHKo2ySeez80WVHd3oCsvm+pNbsgmR 0aOttENCLGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+gAKCRAADmhBGVaC FYm7D/4qzJJQm9TmX5xrE7NpsLG94CdIeCac47fLnlVxmf3t3Mjkt5I1L2v0j5u5Af3l2qg3p8i is8M/pFHGfva0Tvm6zCYQyajc1TFOSk1CnHSGbN44zHC3XftW2w+aT7wEleS46FU22+/HmaaQ4d icXVwKy09Hvr8Nmz/pmbP8ADLuWjSnoga/0bhJdOanUvf1WzsV7RgH0lI+I/Mf5r25YH9QmQe18 +ZDRGPs4SBuwzQ6L0CR6pQmSuGHCvo11mEDnulJuEW0MnmkS7L+Q0MJJq8izDNCZAlVF3NqwN0C f3u+OygAKquCyKT8dugS9lqkEOXJBhi5OZhDZdSBGxOkXQiwb0gy5tLMkPhZ8K2g8pLzKeA6KjA AtoR4crhk1WNXcU4nzjhBDgS1wB+idQe8CHHyoTGvy5j97RCr6d+hNVFhEDtAK1HWd7bRJG6dzE b9PhO56VnY1bDWMLHOJCSWf1qgCyVVcHv+Ma+7Z21qnNI/YKo6VVjfj5fuisKZX4QxhHGVgDZv1 pXXPdbO8sttx+ccUD9hwj0etd8WW5IyqRpvbtJFus50FIxV7DVjvMUPPUJ8fjeTSAhnhh8M550A RotKZi9jt8ytEzPXSq/+XyCry209lsk44xqqR5YNZb6WMGC30+UeZrUPJBsNoRdJyuQ1fGjDzl9 CAsXrWV3wpcbqhA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: 5n5s4a4yjr431tqqmd3zq74hax76ka6q X-Rspamd-Queue-Id: 79745160019 X-Rspamd-Server: rspam02 X-HE-Tag: 1727780362-291897 X-HE-Meta: U2FsdGVkX1/0ItLobAj10+/ocWUZ51BL5/R74z0T7e1WTaWu0zOA01urfLTjjVtHeGtOi9Yeuq68nggaXaqd0S6UY0/WHXm/Atd6Bo+kOLVaMtUVBU77muoIkk7iL1r9AULryOuLc2iQvV+Didv48jtMsiBhOJLybbtofsQ0tOjTfN78bzMkzApTEuoEFdplWUCilzqp5VlajlvZLSEvukTbw9fbsqLB0y9GIji9F5l39xjPVL6WiMisuCpP/tqJLAUfi1RMbMGxGmODJLwqHYTzm0J0n/TE5om2fZGv/iGvmwA1AMBp3XQb9JgRhNTUHMotf+R/WMVqNl4seiKeMUig2mho2XVUjrjvF6ONhvESS2R0QI+7V4kj/NAQy1B1O4n0B3GL3hNrZS2xfZS/GbCKgxh+kUtqOEiRc5C5rwjDbC/DanvUQqqL5AmfB5djpyu3KaxeqQrBhkdaEN+J9Ug80xxcKgeWOSxmDDx2qPVR5ykAxjGizA9vw6OQZ6SwStBPkqGlTH5DK5DkqQUJ3bbinHTRQlHUa5jsreCXqwMy+U9ukzIwBIbpo5Bn+OeO0mS/mcxWBdwXeVKTEnkV3Wsr1Cq/USy7qdnHq9QcleA/yWg3Pj6aCLoluhFZlajDGy3Pr2MKfX8rR7jaO9rWYIrrg4qcI+pN/VqFGvy1MNMnf1AD7Y3S8uSGLFg3pEAMJbgIssSe7mjrrr2Bn9TzFf26GN78xJbgV5o9s5GaCpSBg6LxLkXBQ6BOW3ZvjDqiuyWQ3bCG62SczWp9PcXDHZ2GdtTwVTWBL8JDfYnMQU8gY+1tcDo85Ppr8pImrqenf0ZE5ShDKFKbscmOUjX659Vl4GeUVuPOp2WYFUCH/W+mrnCj54QzYFqakYS4JlrlyV/Z25h26oVwNpejXyrw0TJbccVGnAmX7DR16pdqL0pOE229Ap7cMGH+04OPcRye4VdgA/LafRp13+IsJ6q baIEI/jF dfbnRo3mz2j9ErHVzdeCBSI5eyusX8QBjTzccZZkUOTZPvnbuzEDJc7Rg/N2vRcB718kdhkIGUZDDdlS6V/3SlYqEqbtMNP1XNk6D+mjE3/sHpefzcTqDDjEW+ngYJakI109x3stNA0d9ZHiddCYLmnFnaSLyGsskFP5lX25EnbM4zVPUsAzgCwmN1SmrhYUxtQk8cq87kyyRIitEA697W1/H1MFxPRfH9M1ihnEZMtRm+3Y9CJvlYSjIv8aFZmeUvGjDoV6hdM2gTk9rD6lRy71qkVwMzSyglF4fYw8KPv65J9UHkwj33fgtWyllniKBzZ17tqlY09/XDPI8eCc7QI1ofNETCMwRu+vY 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: When updating the ctime on an inode for a SETATTR with a multigrain filesystem, we usually want to take the latest time we can get for the ctime. The exception to this rule is when there is a nfsd write delegation and the server is proxying timestamps from the client. When nfsd gets a CB_GETATTR response, we want to update the timestamp value in the inode to the values that the client is tracking. The client doesn't send a ctime value (since that's always determined by the exported filesystem), but it can send a mtime value. In the case where it does, then we may need to update the ctime to a value commensurate with that instead of the current time. If ATTR_DELEG is set, then use ia_ctime value instead of setting the timestamp to the current time. With the addition of delegated timestamps we can also receive a request to update only the atime, but we may not need to set the ctime. Trust the ATTR_CTIME flag in the update and only update the ctime when it's set. Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/attr.c | 28 +++++++++++++-------- fs/inode.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 3bcbc45708a3..392eb62aa609 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -286,16 +286,20 @@ 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; + if (ia_valid & ATTR_CTIME) { + /* + * In the case of an update for a write delegation, we must respect + * the value in ia_ctime and not use the current time. + */ + if (ia_valid & ATTR_DELEG) + now = inode_set_ctime_deleg(inode, attr->ia_ctime); + else + now = inode_set_ctime_current(inode); + } else { + /* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */ + WARN_ON_ONCE(ia_valid & ATTR_MTIME); } - 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) @@ -354,8 +358,12 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode, 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_CTIME) { + if (ia_valid & ATTR_DELEG) + inode_set_ctime_deleg(inode, attr->ia_ctime); + else + inode_set_ctime_to_ts(inode, attr->ia_ctime); + } } EXPORT_SYMBOL(setattr_copy); diff --git a/fs/inode.c b/fs/inode.c index 4ec1e71e9a9d..7a324d999816 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2751,6 +2751,78 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) } EXPORT_SYMBOL(inode_set_ctime_current); +/** + * inode_set_ctime_deleg - try to update the ctime on a delegated inode + * @inode: inode to update + * @update: timespec64 to set the ctime + * + * Attempt to atomically update the ctime on behalf of a delegation holder. + * + * The nfs server can call back the holder of a delegation to get updated + * inode attributes, including the mtime. When updating the mtime we may + * need to update the ctime to a value at least equal to that. + * + * This can race with concurrent updates to the inode, in which + * case we just don't do the update. + * + * Note that this works even when multigrain timestamps are not enabled, + * so use it in either case. + */ +struct timespec64 inode_set_ctime_deleg(struct inode *inode, struct timespec64 update) +{ + struct timespec64 now, cur_ts; + u32 cur, old; + + /* pairs with try_cmpxchg below */ + cur = smp_load_acquire(&inode->i_ctime_nsec); + cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + cur_ts.tv_sec = inode->i_ctime_sec; + + /* If the update is older than the existing value, skip it. */ + if (timespec64_compare(&update, &cur_ts) <= 0) + return cur_ts; + + ktime_get_coarse_real_ts64_mg(&now); + + /* Clamp the update to "now" if it's in the future */ + if (timespec64_compare(&update, &now) > 0) + update = now; + + update = timestamp_truncate(update, inode); + + /* No need to update if the values are already the same */ + if (timespec64_equal(&update, &cur_ts)) + return cur_ts; + + /* + * Try to swap the nsec value into place. If it fails, that means + * we raced with an update due to a write or similar activity. That + * stamp takes precedence, so just skip the update. + */ +retry: + old = cur; + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, update.tv_nsec)) { + inode->i_ctime_sec = update.tv_sec; + mgtime_counter_inc(mg_ctime_swaps); + return update; + } + + /* + * Was the change due to someone marking the old ctime QUERIED? + * If so then retry the swap. This can only happen once since + * the only way to clear I_CTIME_QUERIED is to stamp the inode + * with a new ctime. + */ + if (!(old & I_CTIME_QUERIED) && (cur == (old | I_CTIME_QUERIED))) + goto retry; + + /* Otherwise, it was a new timestamp. */ + cur_ts.tv_sec = inode->i_ctime_sec; + cur_ts.tv_nsec = cur & ~I_CTIME_QUERIED; + return cur_ts; +} +EXPORT_SYMBOL(inode_set_ctime_deleg); + /** * in_group_or_capable - check whether caller is CAP_FSETID privileged * @idmap: idmap of the mount @inode was found from diff --git a/include/linux/fs.h b/include/linux/fs.h index 23908bad166c..b1a3bd07711b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1584,6 +1584,8 @@ 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); +struct timespec64 inode_set_ctime_deleg(struct inode *inode, + struct timespec64 update); static inline time64_t inode_get_atime_sec(const struct inode *inode) { From patchwork Tue Oct 1 10:58:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817778 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 CC945CE7D10 for ; Tue, 1 Oct 2024 10:59:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D1A9280075; Tue, 1 Oct 2024 06:59:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4593B280068; Tue, 1 Oct 2024 06:59:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AC38280075; Tue, 1 Oct 2024 06:59:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 024A8280068 for ; Tue, 1 Oct 2024 06:59:27 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7E1A5A100E for ; Tue, 1 Oct 2024 10:59:27 +0000 (UTC) X-FDA: 82624737174.25.3DF8D3D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id ABAC2A0004 for ; Tue, 1 Oct 2024 10:59:25 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KJYReTzj; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf15.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=1727780262; a=rsa-sha256; cv=none; b=Rx72fFBlVjH5it5WaWUGxNbTuvPcXOgdwlK+XmtW486HcLmhpROghUeBVZZ1V26YtgetPO fL77KgTWqXFgt0dx0TqAD37oXAoRJIAlnn2bIf/Cn0XKGMCmjkwShmC/ZQ9EJVokVqzws3 j5hmE/W8pOIa59eeIrQaHWuji+2SvWk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KJYReTzj; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf15.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=1727780262; 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=oBR68easM2pMOZbrlTmS+mhWTwICs3oMZV+CLRRQnJ4=; b=GiC+/eAF2vJhkppsRDX/IYoav6TUejjTye2IV/0SokQ+0tsi9CZzrl8IB4g5p0u3xYBHAF cdoBxawa4o6uDwvkL646vTVec+4zKEJwo4hewaFBDWsu02z67hF4TlP6JgLWdI3z5sPDuN H1nl7yiYqd+bJmQmUfDhK8YZ3K8Rr6M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BDFFE5C4C12; Tue, 1 Oct 2024 10:59:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5A3DC4CED5; Tue, 1 Oct 2024 10:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780364; bh=izJl02glxmmNWffqD/IPDGQCuMtAoj3PYaIpg9PyC+M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KJYReTzjCU5juqIQtdAtIbD6Cg8WsgMtVfkxad1wpDaXt0C/azxShGQz0aEdLwS+i NMBJSD5AMwqRC9jAD+agmdvxZbhb1deO6PZ20MXZuTvm5IN2yZOhqr5TYaydIZtyzy xoWFhDolE7EBRb9u82huyjjPzS//NxjCBPgB0yyus0QgUHAP06Y8Wv+UmwMAz13+EK wRZzJDLC3n0/pimokV7Gr3o2unPk5KJgF3sUwNY2CljlHaTslpI+nqcpCkVxr0NBUj 9Tu5xv20Nz3Ux9zeEAaX7IwNb02A5DF0jW/Zxim6vaMiiu8f3Ye7VsX2FYMRggkIvE d7X3TQycX4uFQ== From: Jeff Layton Date: Tue, 01 Oct 2024 06:58:59 -0400 Subject: [PATCH v8 05/12] fs: tracepoints around multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-5-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6077; i=jlayton@kernel.org; h=from:subject:message-id; bh=izJl02glxmmNWffqD/IPDGQCuMtAoj3PYaIpg9PyC+M=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X696gqADrOhEqB6pujGiTNndsyHf/izuC/1 R463+eBHFWJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+gAKCRAADmhBGVaC FbboEACUj+9F3EVD5uJtrX2uK5uY53172VIJT2UCmgEOe9ZlQA7D6if6CWZVPpy84ZAFu0wKvCU nUfGe+A6pYC7FsWSWtboTu4uITOQh80rU3WCcsO2wvzjoi0r+sasAbUqKCSQQ03TKI7P864nU6w s02Q5/aUyzz8G+ClLfJ6+oaoxzxdlqxVt26SF6t/cwBvqv21aB6lPekW0yU+0G9fQzugdYDs9tR 4IaBJVJIPDUGj9CNQLAfmB+R7ZqQCaX0ial0zvkB5j5DThz5OCKhv2BoHsySCKOSxAK5ljs4V29 FSLRdvZe7fmhn+pVlw4zCeGrK90NjBPLY05C1taeQGjXm1KMTYxIRVTYppCGOrbxRlV8HAqCfNA h/f7Kj5Ig3A+TIavynuTUw+cLKXxTS8/KcpbfSa228J9uujdacgBgN5tNHjWJLqbGd1CnxF3EE1 G0/Tc41yTgoQPk1eZbgcEefCxgG1wSzpWVixfbgYFnVHQnxMDxmE6ME/pzql569Onv5uvSoXL7v ii0xb1hqVt3AWZPlFcv2dLDzXp6DCkga+++6O+tiwAR3lOEdBe7ZHyKwGNqa9+ttRmDzG/Y8BPr TJ1hwYpwwsQrPBeldGN5ImNSqSxV05EHm+neGOG5J+7diqsxz74eScJtZxkQ0PkpS6XSSZrquPH CgidwNso0HxHmJA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: ABAC2A0004 X-Stat-Signature: cio9s8hrb36m1n7wesw7drtnreigp3xu X-Rspam-User: X-HE-Tag: 1727780365-403610 X-HE-Meta: U2FsdGVkX1/UBtSR+LT2YdJYnuvHEQ/5Jaht/tdRW3pW0+TsSyc5tsGrmtmudqpOaqe5wWDNCgLSjnkNz91vu502Atsa7/eTX0sM7BamJ9Geo4O/4xuEDen1xpH9tbL9X0GrOjIuC1FR+4gCYe6PSJr0OAru23U9Wvn94ZAgZay2rO1Usx0uABCfInxJtk9VXCStWF/JWMUCB4HdkqLVHBEEaAHmedpySBuLegZ1rVMWQ4Xj14nNBYAlhG3C3G37liRfb4P0aH3NBtMWN/e/jFkFsDuykup8JN25MZxZ/9nVbdaedSNCQELYJARs8x2R6N8lZne/Zio5njWYIelxeMHOeI6T/QxGx1ASV01RJ/WBbyV2A095FNW2EsSHPq6UMdAUReSwKV03XBG6qP8ddxJgndTToi8yno1EJZyYWRIjAcrEQR7cbM5lG0EJE+kST0KjjyVTqv9gdCBGpno24oXaD1yPFbgmaIcPccy1QrQfGwoJ19IxVKDeX37Gu+nllKMLSHprKgADvhArCCC0FoOOY8iutS3gXrMvsMGvC7b0BCdVY8kRcyDIa9lAj8s0JcKlkZpjeEPXvuUx2WyQ1lYpZXLA9NBIt++oEmc0LSjuj6FXctUTEUCddTPoe+j+x9gpwDK/RKRowFyHJMEetNSLzn/U/GYL/aQp/0NDeKy7DXXeIkKP7huyoKjq1PG+jkv/kQ2HgERyszo/avhVqPEPtr4ErvRuRpII73GUUd8W2v4d2nNLq6Xx0c63xjSNeylrf/wDoPkOjPMpAFUqX6wdsJWITJE7YZlQ1eEWhtFGNxFxC0v+QmNIycrOrji8TiEm2HoW6GL5l2DZCKcoVE1wFwdTRE0T53Zo4oUE9Pm5fEC5decY+f91Z5rS9l3mtEmZ7AJ0sdtA6FnCLzUFb+Tick0zMXbQ6s3R5V/upJx5OzmkWbnRoOSu1yrrk6DmAr4Vxu+RdDPH0bR90RV qr53dVT4 TNe8J7R9XfrMQnt4KfZ/uKafNiBi+qmzGYlybPyh8P1EkmA1CE4PMBTfPHmYg5w+rcMLHNaF02y2UX+x2LWgDNUKS6RHh59iVotlhxATavwaHWS9hCY5zVS7qzIbu7eXvyGpuyd64pJ6PbMpLki11mIhqcPsggXcriaPAaGCzmgKUkvAC4BWPihg7DC3sYLeqZCAkQj6KWdPsLknVR6ayccGkp/2/dwl/vpzZUw9gMyClMQtQRsWFJJjFesqAnu7QYYa1PnLSaXih5rf/7waJMU2rXBKGTxkrNpqAmupl8/N3mbHsxMfy/S3Q53Wugd5yHUkMb8bVwoemO4b+W3y3m6YNhIWIQMGSvrYYzzstRmPuAGZWjsx+4slywyrEArhsdWUu6Cl87jDD8eRpemGpd85MHZeEGhz59zt/wLUvobiwYVI= 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: Add some tracepoints around various multigrain timestamp events. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Reviewed-by: Steven Rostedt (Google) Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 9 ++- fs/stat.c | 3 + include/trace/events/timestamp.h | 124 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 7a324d999816..1a7eff2a40e2 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,9 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" /* @@ -2639,6 +2642,7 @@ EXPORT_SYMBOL(inode_nohighmem); struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) { + trace_inode_set_ctime_to_ts(inode, &ts); set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); inode->i_ctime_sec = ts.tv_sec; inode->i_ctime_nsec = ts.tv_nsec; @@ -2723,14 +2727,17 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) } /* No need to cmpxchg if it's exactly the same */ - if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) + if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) { + trace_ctime_xchg_skip(inode, &now); goto out; + } cur = cns; retry: /* Try to swap the nsec value into place. */ if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now.tv_nsec)) { /* If swap occurred, then we're (mostly) done */ inode->i_ctime_sec = now.tv_sec; + trace_ctime_ns_xchg(inode, cns, now.tv_nsec, cur); } else { /* * Was the change due to someone marking the old ctime QUERIED? diff --git a/fs/stat.c b/fs/stat.c index 381926fb405f..72914b6624a5 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -23,6 +23,8 @@ #include #include +#include + #include "internal.h" #include "mount.h" @@ -52,6 +54,7 @@ void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED)) stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)); stat->ctime.tv_nsec &= ~I_CTIME_QUERIED; + trace_fill_mg_cmtime(inode, &stat->ctime, &stat->mtime); } EXPORT_SYMBOL(fill_mg_cmtime); diff --git a/include/trace/events/timestamp.h b/include/trace/events/timestamp.h new file mode 100644 index 000000000000..c9e5ec930054 --- /dev/null +++ b/include/trace/events/timestamp.h @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM timestamp + +#if !defined(_TRACE_TIMESTAMP_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_TIMESTAMP_H + +#include +#include + +#define CTIME_QUERIED_FLAGS \ + { I_CTIME_QUERIED, "Q" } + +DECLARE_EVENT_CLASS(ctime, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + + TP_ARGS(inode, ctime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ctime_s) + __field(u32, ctime_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->ctime_s = ctime->tv_sec; + __entry->ctime_ns = ctime->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld:%u ctime=%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->ctime_s, __entry->ctime_ns + ) +); + +DEFINE_EVENT(ctime, inode_set_ctime_to_ts, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + TP_ARGS(inode, ctime)); + +DEFINE_EVENT(ctime, ctime_xchg_skip, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime), + TP_ARGS(inode, ctime)); + +TRACE_EVENT(ctime_ns_xchg, + TP_PROTO(struct inode *inode, + u32 old, + u32 new, + u32 cur), + + TP_ARGS(inode, old, new, cur), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(u32, gen) + __field(u32, old) + __field(u32, new) + __field(u32, cur) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->old = old; + __entry->new = new; + __entry->cur = cur; + ), + + TP_printk("ino=%d:%d:%ld:%u old=%u:%s new=%u cur=%u:%s", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->old & ~I_CTIME_QUERIED, + __print_flags(__entry->old & I_CTIME_QUERIED, "|", CTIME_QUERIED_FLAGS), + __entry->new, + __entry->cur & ~I_CTIME_QUERIED, + __print_flags(__entry->cur & I_CTIME_QUERIED, "|", CTIME_QUERIED_FLAGS) + ) +); + +TRACE_EVENT(fill_mg_cmtime, + TP_PROTO(struct inode *inode, + struct timespec64 *ctime, + struct timespec64 *mtime), + + TP_ARGS(inode, ctime, mtime), + + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(time64_t, ctime_s) + __field(time64_t, mtime_s) + __field(u32, ctime_ns) + __field(u32, mtime_ns) + __field(u32, gen) + ), + + TP_fast_assign( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->gen = inode->i_generation; + __entry->ctime_s = ctime->tv_sec; + __entry->mtime_s = mtime->tv_sec; + __entry->ctime_ns = ctime->tv_nsec; + __entry->mtime_ns = mtime->tv_nsec; + ), + + TP_printk("ino=%d:%d:%ld:%u ctime=%lld.%u mtime=%lld.%u", + MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->gen, + __entry->ctime_s, __entry->ctime_ns, + __entry->mtime_s, __entry->mtime_ns + ) +); +#endif /* _TRACE_TIMESTAMP_H */ + +/* This part must be outside protection */ +#include From patchwork Tue Oct 1 10:59:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817779 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 70BC8CE7D11 for ; Tue, 1 Oct 2024 10:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEB87280076; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A745A280068; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A2D3280076; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 65654280068 for ; Tue, 1 Oct 2024 06:59:30 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 25BD81C4BD3 for ; Tue, 1 Oct 2024 10:59:30 +0000 (UTC) X-FDA: 82624737300.09.E5DE741 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 5445C14000A for ; Tue, 1 Oct 2024 10:59:28 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GfnDYDpc; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780303; a=rsa-sha256; cv=none; b=wQgoPois+4AWL5JW4WxbYhoBGljiCFpC9m3yu/fCd4hVDRM++lwwG51SWIUZbdoChZidKO sQPA86NASYYPHpjcM9wgVgs0W5I6lvkSWOcSrqBmoWnPG6VnFJ75mBPp+/bGogSHMa0Iwk wqefeBDqkX2JYCx0SHLH844WEL+AJlc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GfnDYDpc; spf=pass (imf26.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780303; 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=M3I0vGBPnlMtvVR07H8Xsh7oUVCPl51S2llG4iNobUA=; b=vOsSmlzPjal51oesE088gwkp9svt+XQcV/lYatsfMt7QaXBNzB+j+L2xHPKWCiJsZ5ktR0 zn+JpfNTMBI0R81hbalQMVXS+eE8WDY2XFXzjNboUonHcsqmtJv4FKYBzoUG7jYr+j3PgP aMY6VXMsaKcLD8lSogg78CZLrJQ3DnQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7CE4B5C4CA5; Tue, 1 Oct 2024 10:59:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB15BC4CECD; Tue, 1 Oct 2024 10:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780367; bh=bnxqTLrbNZyT1g0NvyIT2ylk9FHviHzTCIeX6Q+a9Tw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GfnDYDpcxS3boT3U4rQLJwULi0a8n222Fjnp1VCMDfC20mmbQD0cDIQadBM51cgPJ nV9YRO7/QWGpLPtne8HTI+7ACDNc8Yh6wr2X2n11INCbNF2nFwFWdG88ogoEctFXGK 3eTu3I7U31GhahuJcVqwWBQB62Ha5QtCSqJPyxODA+GxhlZ8/ILXzGt+LHu8ChZiUz PC8M9TXzE6TMHP8suehx38ysXd9H+7CO37Wvfw9VlzkPrWwpi+KMc32f+amoNQvAyW GH/RDL/sP0VJ6V8ofYYdHgnT5D8Q43Va9pxygzXntA2zx8I+RlbyMIblG77RXge9rT J3cX4dtYnSwHg== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:00 -0400 Subject: [PATCH v8 06/12] fs: add percpu counters for significant multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-6-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4249; i=jlayton@kernel.org; h=from:subject:message-id; bh=bnxqTLrbNZyT1g0NvyIT2ylk9FHviHzTCIeX6Q+a9Tw=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X6uFTDpmruN1n3YxfQ4M9GqHLCg78dcLoDF Xy4u5w/fieJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+gAKCRAADmhBGVaC FWKuEACrNZonEdFb91CPslE1FKZ3EnjTmpY62WjtfzkO/dS6Yc+5Vty9sBbTC2Wgj8swV7VQI1E 3n1u4rMgrfPOlKr/QKBU80elsZhvrOmrrheb8ui9AcOo1I+XdXePrsG3aobdnQ/Gv98zQCACcb4 8B3sikCLn0hTps4oScihpn6zZyM8TBMb0TElbFDmt0PEZNuki6joWMvpLwvyNH/nfI03Hw2fpfK oAdmhyFG2rHsyZIGH4wystUL77V2sapnE7zcnoj6JqkAMp8tK3NkVkUcusLKJYJeacY1MAupboZ czHepmwuiXJUE6Cqgy6F3qrOxev1S6jHvRpKb2cKCgvO4rVEIBkIs5mZ5U4Sb1CHU3jf+wLsvbd QRY6NtWBCfTUH5a9hly1Yd3oryA+TCSVmZitD/8XpNEsU+vwLG6WEC2ca+5ElyS1snzgDfhFIBB de7bQwlpZzQi44aNXyKQOwkQNze6xRmXR5rDhdRhFgkmvBu/cOoqP4g5Sr1MSVY4uQ+1qNcBIau Xf1Aq6G1ho60wNVM5P5giwaUn7DeV26EjG2JGKgxypBjstKfHItRHYZFrVfl08OyWr8hK1UplDh bQdjV8UIwzVG91dY0MV35yqrh2hcuKJFCN3kZ6Td8t43eJprgUnh/lnWZtbYu/IU9B5zDnkuF9T 35pY/z3vA4fyIPw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: a75tcyr71srwh7wjc7pwqmmbeuzb8mxh X-Rspamd-Queue-Id: 5445C14000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727780368-956212 X-HE-Meta: U2FsdGVkX18VXIieNNAqmClOAZw2fpKY53nHIedJMGolig2ioCWNDiz1zvDzr1mLJXsK1Ub159nhIR03++v8vzWu+U+iQfLuykvvaUTAYnZQ3YYBBr2QLjTrMLYcum3IkqVlGBnV5RGzd/qAEbJPWCYMXsQXGc5AlbVSR+CrYjSAqoF9u837ExWimGeRYOk2p3TIg07AI6hdhIVKxp5yOFGFbh2BEgYI0rglwj2Btwd+mkb0/LLFL3MQGPDXl96a8Osv3hbVM2DqUeAhFDFJ/PaYrTn8G71Xlftq3jf15GtHhnLv1PmHPPjX50oQ4ETf0VQM1CsLlNqHuD6XXQRRr4qaSDKov+/givk6jCeTGPsdV0tQdJge0sGzXM5ohly0C7qS3kWqdVZK5iztVT6GBZFyIhs87M3EsxCMcbtsvJVcLTj6S5/MUry1teLNAQkRIJj8FFoSP3KTZepAY2FVl10RbYon3CVABHsDEESV+w67oM0npBPAIZeiUYPvVEdsBpu+LkDQcSRThawjpjpUuPWt1qdX+g3e3zu+MATmhNdNkBtVRLM53KSHUmGZOtXTnfd9EVg06MHU4GoXmyozCNz53VFdiQPqLMmj3YrMkxhdN+0TU8V84yHxjhRF/OXy4LncXRVttHvi58Vl+CPfPjEqvPOCNFw8oPpK0CZGcmedRnn85/R3C2zPA/ShGU4X3ksdV6nDIuKtNlR2A15rmNL0LA7ULVaelRA9ZxQZSTmEwdRYgREdrVZiWrBw8fRYWrKT2dvtHKhH2LJXxXK4dClgn+Y7PWomYBLs4uDfyrl4/t0BDCegteaUaH4XP3Z47Lrce9Ew2M31hSVNKdXv3o3rn6boxotyKrWVSlI0FtIiB3ZDxXjSAxBVF4fB13cPUVJotOuHkodYKZmSy3C5Y04StOqkQX0efIqs3tHpQZuk33DhK+ZgFLlvpFXeRcrwV0rLn1AH3M8Wtdd2kZQ e8q/unz3 iOaRDP/90d9ActgL6oJ1ADlBz5SoiKKHkkJRAyqn7YtdOBDgCWfgzftFI0W6iP35LzD+zIYP7/kevsArdSRzyP+VuM/CMAOzLcG5dlTwfC9XHfHJ5ovCi1WpO4IpCSRQhqHdgWlfjwrwjYDrtM/9NonNsY2cs+je3v2a6DibSuq1tbUwQgTVkXRC6zwRLJA9IM5vMUUPqq9W3CiOT3Vw0lUOT2NtLwK7ZWH9LPeasThLLu8uZD4Df8Y1WZ11VTsrTQvdRai4n399SJoAVZiAd+jg+JYJw6XX+HpRVLtqxg5Q8ta1cVo9bLpfPQSBK7Ny7bYbyjShwumVsegT9gPyjkWnrg4KbkYnvLRNirvmSYQVfEvE= 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: New percpu counters for counting various stats around multigrain timestamp events, and a new debugfs file for displaying them when CONFIG_DEBUG_FS is enabled: - number of attempted ctime updates - number of successful i_ctime_nsec swaps - number of fine-grained timestamp fetches Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 1a7eff2a40e2..e46f7170851b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #define CREATE_TRACE_POINTS #include @@ -101,6 +103,69 @@ long get_nr_dirty_inodes(void) return nr_dirty > 0 ? nr_dirty : 0; } +#ifdef CONFIG_DEBUG_FS +static DEFINE_PER_CPU(long, mg_ctime_updates); +static DEFINE_PER_CPU(long, mg_fine_stamps); +static DEFINE_PER_CPU(long, mg_ctime_swaps); + +static unsigned long get_mg_ctime_updates(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_updates, i); + return sum; +} + +static unsigned long get_mg_fine_stamps(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(mg_fine_stamps, i); + return sum; +} + +static unsigned long get_mg_ctime_swaps(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(mg_ctime_swaps, i); + return sum; +} + +#define mgtime_counter_inc(__var) this_cpu_inc(__var) + +static int mgts_show(struct seq_file *s, void *p) +{ + unsigned long ctime_updates = get_mg_ctime_updates(); + unsigned long ctime_swaps = get_mg_ctime_swaps(); + unsigned long fine_stamps = get_mg_fine_stamps(); + + seq_printf(s, "%lu %lu %lu\n", + ctime_updates, ctime_swaps, fine_stamps); + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(mgts); + +static int __init mg_debugfs_init(void) +{ + debugfs_create_file("multigrain_timestamps", S_IFREG | S_IRUGO, NULL, NULL, &mgts_fops); + return 0; +} +late_initcall(mg_debugfs_init); + +#else /* ! CONFIG_DEBUG_FS */ + +#define mgtime_counter_inc(__var) do { } while (0) + +#endif /* CONFIG_DEBUG_FS */ + /* * Handle nr_inode sysctl */ @@ -2691,10 +2756,9 @@ EXPORT_SYMBOL(timestamp_truncate); * * If it is multigrain, then we first see if the coarse-grained timestamp is * distinct from what we have. If so, then we'll just use that. If we have to - * get a fine-grained timestamp, then do so, and try to swap it into the floor. - * We accept the new floor value regardless of the outcome of the cmpxchg. - * After that, we try to swap the new value into i_ctime_nsec. Again, we take - * the resulting ctime, regardless of the outcome of the swap. + * get a fine-grained timestamp, then do so. After that, we try to swap the new + * value into i_ctime_nsec. We take the resulting ctime, regardless of the + * outcome of the swap. */ struct timespec64 inode_set_ctime_current(struct inode *inode) { @@ -2723,8 +2787,10 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) if (timespec64_compare(&now, &ctime) <= 0) { ktime_get_real_ts64_mg(&now); now = timestamp_truncate(now, inode); + mgtime_counter_inc(mg_fine_stamps); } } + mgtime_counter_inc(mg_ctime_updates); /* No need to cmpxchg if it's exactly the same */ if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) { @@ -2738,6 +2804,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) /* If swap occurred, then we're (mostly) done */ inode->i_ctime_sec = now.tv_sec; trace_ctime_ns_xchg(inode, cns, now.tv_nsec, cur); + mgtime_counter_inc(mg_ctime_swaps); } else { /* * Was the change due to someone marking the old ctime QUERIED? From patchwork Tue Oct 1 10:59:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817780 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 0D67CCE7D0D for ; Tue, 1 Oct 2024 10:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EDC2280077; Tue, 1 Oct 2024 06:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 876A5280068; Tue, 1 Oct 2024 06:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A36C280077; Tue, 1 Oct 2024 06:59:33 -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 3BF67280068 for ; Tue, 1 Oct 2024 06:59:33 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E1D7CA103C for ; Tue, 1 Oct 2024 10:59:32 +0000 (UTC) X-FDA: 82624737384.13.26A67A6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 2527080015 for ; Tue, 1 Oct 2024 10:59:30 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=B5NsA4Y3; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780245; 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=j23ea2oSLHwO3VCXd7879q5pR6SW3LD6xwMWmsgaaeA=; b=AXDdvzvXCBjg7d4B4idZ18tjhrS1GIMwRP4OvDSfnKGHyvYtEAvKC8mbrZ6lBwJIkscZa8 +lpCKshwm3QJ56flQKAQTqrS7s+86KCyBETq+nfn0ASVydQyK1xHgb85fZmltxy5cSaqPQ 4I2u6aNSAv2izFjfHQ2bRjnzHME928s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780245; a=rsa-sha256; cv=none; b=EPRX6ogQb6W10M8mkaQcoQiscy6Hxs7nMbBGjYJtC9XqAADbNJ8SylSsqAkK1frTaDxJJh rpXF+yFuGiv3VH12RUrhLpI6YEZZjyEe1cPqBuBClROe/qWVbOhImC+WQ3Z0UR/6cTMk7W 8X0SINvUMbid8z45oPuU+a/zRIzj2XM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=B5NsA4Y3; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3C8C95C488B; Tue, 1 Oct 2024 10:59:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6ECCCC4CECE; Tue, 1 Oct 2024 10:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780370; bh=JL2gW+C3kDxbRAGj0jMp5iB8JHuDuhS4rvTtieX78oY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B5NsA4Y3xe03GSebvPrrYvgPoGZbnw6mZTFF2+mbaE21jaWD0FJgt1XHCPTAvrT79 vPgqIbRwjLzaOimrju2AKsv/b/gSgB/4RSN0bLwKzrtHXHaDqtAnXqCJO2jpq2RqmX X6wO1EBN+PbuMQ86TBeql6QF8WTGyZ5Z00YdTsluw0mp4xGe3a07TAoeUMe6v2oxQv nVlXaK0ssXyss4VOzkZpjy37wUHfRBGsBv4J2GUWKNvzUSzUOk8cj7BRdZFIKFS+aJ vlLE50z3y5Llg/g8PlVvgDXTNVTBWwx4haJ2pHrfwkMGwuWWBl6P4sGfxxbpzF0K6U VFKXOjSzzaz3Q== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:01 -0400 Subject: [PATCH v8 07/12] timekeeping: add percpu counter for tracking floor swap events MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-7-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4015; i=jlayton@kernel.org; h=from:subject:message-id; bh=JL2gW+C3kDxbRAGj0jMp5iB8JHuDuhS4rvTtieX78oY=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X6x1c8e9tak6oUEGlf0VU1qI9Vs0dKdL9Nd tgbNV9wo0aJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+gAKCRAADmhBGVaC Fc1QD/9eMcfRLjkeM4PSq5q9wbdZwKH0ZnxF0our+6FybuPq3dyRBmPN35tLdFGBtPY7yqdWFwS Rs/LS0WNRMUDhr1mdiuuzBDAl87afaQm6m0Ss/fKkpUFhmk/6FI30AQA1Y6CGK6rBPZYvpRMd+t xgQ8SEf51BB4aQuerAYSVbDxfIaQqxooQW4UxsVhihhRpZSz79bvs9BpfTRl7CbRAPptD7zgobF R7mUD1bo7p1UmgGdLuhyprr+Jx7N7pdA9YQpQ08sy/92KZ+vcdGFCcsOkuq10gXYaRdVyf/PRfC rRDl9JHOqi1KNQBD9zb4sWygsFJGWWPQ2CW9bYimEWy0wCKUZoEouWvbzEq4spMhwAoFngdHDsS Bz0hFemqy9Xm0kWfhA2Nfr2napvBTjUBhmHeTbT55Nfpt1HF/UZUInHDF9AdCKxXHuQ+vQSgAhY zjBXOOKmI6/5Qt1tfZh/5yUgcInlYWTFh5JfBEPO8heF5DaWba7euvt0rMdn7cjfKd4yUuyR29s oxz6la25xBwO/N9eJtho78xkfye21spBGiN+rs91RekoH21kMmErBfxm5wrhx2AsEg1f8GUUDnQ DlZ8agBEXLchtmo9h03ROpDuc/ljD3laUG05Nf9rBOcUWDcUaN4Fh4A5/crNSXCfsrkG2Taaleh he48A3qyAV/DzSQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 2527080015 X-Stat-Signature: 5qtowfdm6y3su9bc9jcxhd7txc49xxcf X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727780370-69904 X-HE-Meta: U2FsdGVkX18ci38pi35mqLTaVd8twE399+7/xcmPVN8Hl2jcp2DQvx/SF6M5q6xqHVPil4FWI2nx+fA1W2BheaMi8FxIktVjoyLFbyQFG3bRnnsJqN216GbOGyRZDC4SrQZ1kItECXH27Vq062FVplPE0s5K1/eQGmY1cz55LIDFfonQLc1ycTaMyhCsFS+KsIClpTIF+M7qP3yp5eo1MPQKGRISlq9dHHTnblwhNjXpUi0dt1vyDG/uHdhWanHS7+3zCgGVVEEeQoQ1sKMpJTW9+fkIQ3WLkjXBdLC3Mo2ILQC07T7pcXwsPh8aKi7/HOg54Y0lhxRsk8xeuZmaN6E13ibwgJryxOb8Hojmo1uvltp7zNhj+gRtENVAJCVjbDsWBzugsvx4Ty/RG24cY2O/K3eAZnCsEl1C6IEnQFH4BNDbw7vaq5hA5gA2UBEwIS1IynAiVq37thxzfQ1NJFY4S/Xb1To/s2aTRv6y44hugxhasAUFH0RjE9UKpKIqTg7hCM8Jr2RQRuNSJPQiZCl4ACXLtyE9hnskFTaDcTqbp3Hvl7lWLyHrvJVuN5nOnrmrxWel3EkKn13aJDxlhwC0NUTUOPl9WTmpYEoqRhSD2ZrEMhxGHP8cbMPSM2llqbx1teVpxzptOruGEKF9ZM5SjAfAm6TkTSWY0ENDpm4+dcnlsz1yE+SlShcNDIA3AdMtUVwuGcQDrlSZVnxKp5WrMXAo+xWEpNBl7z1QN04K7vVCL9vChjWWa5Kj3SUlr+4PtemprTxbVPzkUgXqgUDix9VAyx58iDn9nRf36k8tnCD/vSg1HTWVtB+3yL8IkJbzOL/OYghFZAnJVTsnq5EJwnxM7fJjhmWxM4bryAlycBd5/+dYvv24KPIy0DZtc07hb+yDE8SB9f1ZkNUZUdKJWCtqJGzTJMyD6AYTwVTu7ekbjyyPp/r/JDBOlvAh1UrZaYwh9EFnwLiDBHR mLXrkG3W 4TTBdYY7Ia9lvYu/stp9a4/9DWn9xh38VAJee55DXacnQLo9agZLJBIORnnMDow1FRN2pIOuQD+YOsDq+130AHY1Y/A1wMgbmiVxtDDF42uiNM8+gzAo1sHJiiW7wZOjh2hAXcOqy82z88bMt3uVb2IsbnO9/XASM1wj0O/+1OTNwush20swxsoGbSaKmox8q7maBkR0PPpCohUNwdIuT6TbcFBOToM8p+jpcAvtw6V39Lbj0H7itC43kjh8Fc4YCFpkjxfzafQqdlw0GhzOJsoapdVTohCftU3ZThM/ulxgR6gDPp2CetwOzjg== 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: The mgtime_floor value is a global variable for tracking the latest fine-grained timestamp handed out. Because it's a global, track the number of times that a new floor value is assigned. Add a new percpu counter to the timekeeping code to track the number of floor swap events that have occurred. Display that as a fourth integer in /sys/kernel/debug/multigrain_timestamps. Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 5 +++-- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 1 + kernel/time/timekeeping_debug.c | 13 +++++++++++++ kernel/time/timekeeping_internal.h | 9 +++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index e46f7170851b..93a9365cc22d 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -145,9 +145,10 @@ static int mgts_show(struct seq_file *s, void *p) unsigned long ctime_updates = get_mg_ctime_updates(); unsigned long ctime_swaps = get_mg_ctime_swaps(); unsigned long fine_stamps = get_mg_fine_stamps(); + unsigned long floor_swaps = timekeeping_get_mg_floor_swaps(); - seq_printf(s, "%lu %lu %lu\n", - ctime_updates, ctime_swaps, fine_stamps); + seq_printf(s, "%lu %lu %lu %lu\n", + ctime_updates, ctime_swaps, fine_stamps, floor_swaps); return 0; } diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index 7aa85246c183..84a035e86ac8 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -48,6 +48,7 @@ extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); /* Multigrain timestamp interfaces */ extern void ktime_get_coarse_real_ts64_mg(struct timespec64 *ts); extern void ktime_get_real_ts64_mg(struct timespec64 *ts); +extern unsigned long timekeeping_get_mg_floor_swaps(void); void getboottime64(struct timespec64 *ts); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 37004a4758cf..c8a934c1c8aa 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2478,6 +2478,7 @@ void ktime_get_real_ts64_mg(struct timespec64 *ts) if (atomic64_try_cmpxchg(&mg_floor, &old, mono)) { ts->tv_nsec = 0; timespec64_add_ns(ts, nsecs); + timekeeping_inc_mg_floor_swaps(); } else { /* * Something has changed mg_floor since "old" was diff --git a/kernel/time/timekeeping_debug.c b/kernel/time/timekeeping_debug.c index b73e8850e58d..b731621ad811 100644 --- a/kernel/time/timekeeping_debug.c +++ b/kernel/time/timekeeping_debug.c @@ -17,6 +17,9 @@ #define NUM_BINS 32 +/* incremented every time mg_floor is updated */ +DEFINE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps); + static unsigned int sleep_time_bin[NUM_BINS] = {0}; static int tk_debug_sleep_time_show(struct seq_file *s, void *data) @@ -53,3 +56,13 @@ void tk_debug_account_sleep_time(const struct timespec64 *t) (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC); } +unsigned long timekeeping_get_mg_floor_swaps(void) +{ + int i; + unsigned long sum = 0; + + for_each_possible_cpu(i) + sum += per_cpu(timekeeping_mg_floor_swaps, i); + return sum < 0 ? 0 : sum; +} + diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h index 4ca2787d1642..f53e76d5ee7c 100644 --- a/kernel/time/timekeeping_internal.h +++ b/kernel/time/timekeeping_internal.h @@ -10,9 +10,18 @@ * timekeeping debug functions */ #ifdef CONFIG_DEBUG_FS +DECLARE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps); +static inline void timekeeping_inc_mg_floor_swaps(void) +{ + this_cpu_inc(timekeeping_mg_floor_swaps); +} + extern void tk_debug_account_sleep_time(const struct timespec64 *t); #else #define tk_debug_account_sleep_time(x) +static inline void timekeeping_inc_mg_floor_swaps(void) +{ +} #endif #ifdef CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE From patchwork Tue Oct 1 10:59:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817781 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 DB542CE7D12 for ; Tue, 1 Oct 2024 10:59:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A6E8280078; Tue, 1 Oct 2024 06:59:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62EA2280068; Tue, 1 Oct 2024 06:59:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481DF280078; Tue, 1 Oct 2024 06:59:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1A8EB280068 for ; Tue, 1 Oct 2024 06:59:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B40E4405A0 for ; Tue, 1 Oct 2024 10:59:35 +0000 (UTC) X-FDA: 82624737510.01.83A7BED Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id E8F82C000D for ; Tue, 1 Oct 2024 10:59:33 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SqvM7UQu; spf=pass (imf28.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780248; 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=Eywsbia8P2KWlMj0rzkujwaUsbnR4BE6MJvg0/1qMj4=; b=HZ7olYsGIWTpeo2p2HFO9cP/4ZBaBkaEnTktxBA2wqnpWWZ+lyslOGevBPjrmjWnwTUOo5 Lc3nI5XY3G0TdkztzDt4RfyGpb1fHCo3Fp0cKNJArcE6v1k85PiouaoLBPqHw/mfQf2RxR 73Z9DMcSkqW6n9u1yMaWM7YHHRON3gw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780248; a=rsa-sha256; cv=none; b=fNLFGAj0JsTe9InQUxRj+sqM6TLq5zhRlbRSNIj/emmGwTYE2Tvp2pcjyRrByDFVVjBeo2 bx86t1elJqTSOkAPwN9F5Hpq68yvtj1wfoHO1vZ10JD1E5Xpys+6mafbe3cXqpZfNR4QjF Vz59DtUDz+4e4cLJsrx957mjAVaGl5M= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SqvM7UQu; spf=pass (imf28.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0300A5C4D08; Tue, 1 Oct 2024 10:59:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3345EC4CED2; Tue, 1 Oct 2024 10:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780372; bh=oPKJkohv3641xKtdl6Qbhb+FHGtw/eR+Am0SFNCb7W8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SqvM7UQu/XzXqr739ZjUMayt09O7fWxBn1UJtQJ8g351BRbl0wANl4R1Yk6sU400E Yr/UGMe49GdD2ebQnt6DzzvUAxSpIZnscsFIdCwabs0Fa4daX+AenIShCE4RLhI3EV w38XZYULiEitHzBZlVn5jhNigejqimT7ax1kuGb14scgnOiO0aLDBzx8dIalhlVG2R L1t/M4IJFUiw+XbLAZNs9OAcRWh+PTLR644uAXZWnJivFkOSp/nSq5IosNG9Vsgix7 81qKUG8BCST6zgyM9YimVCDPFrhZ39NL7WzZEN9swt6eAyU2mbGtVYPD/SpmZp9HQG 2H+AYtehZPAKQ== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:02 -0400 Subject: [PATCH v8 08/12] Documentation: add a new file documenting multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-8-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=7300; i=jlayton@kernel.org; h=from:subject:message-id; bh=oPKJkohv3641xKtdl6Qbhb+FHGtw/eR+Am0SFNCb7W8=; b=kA0DAAgBAA5oQRlWghUByyZiAGb71frI/VZ8IsS6ruTnBs5BWRyAbQA5bsoqMJG8wDD1XAVxb IkCMwQAAQgAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJm+9X6AAoJEAAOaEEZVoIVsH8P/imV E7s80dTaXxf4ULpYN6X7aZQN/C8GOnFIG+m9PO0VlaOobv+eWULiap2bJb+I/zus8E85zavWgw2 F3cOSJiL0w6d2i/pvNJckkMlroGa9eY9Sn+WDnsyWxDERtp/0VfUgWqmOpWjkKaQprUYXiIKHOT 7892u9SUZxi1sjQXwXRKlBJAsu+2pjJ47/ngqBrAS3XYw6JF6cIfes5YisXQ73TWUDGX33wr1Zv ga4k5NO2Seu+l2F/yOWhgfUgQg9rKh9Vh5fnrmOcVna5fmpk2J3l9sMFO1aLG5VLNvVHKJBdqB5 ky1tvfdWpnMYrpFaQoVtJ96iyMcxAjCk+QIWFjbJGhihWfEQj8OyannWP1hOnXJgQlPiKbdTxtE UUK/KQv1UvZKl6FBtG3jHjRvjkNmqKYc3iOOk9g6RJVTP/tcutVIyMKMR9pP/PxBDmGhbbCCfAM K/xf4E/UXW3Wj6/JWLn6Wie+l7bbJVIcv365ImISGTP2/pUSBSoivUdXMmyEr4Yaw/FbF1aAkto 49mUT8xV/oa8bcnRkEynAZUx5aHQb8VlAsvvQGf2PySLhFQQGOELuVScj4YjskT55adJhrgpSvh n3UCiokQ8gRlaF144PrESWU0berlsMa6+mBSq6fzCT+Y7b9dGyqlRmCG0zV/Qq8vZcpL2iocJhj LcNuR X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: E8F82C000D X-Stat-Signature: xumekcy1dtxwuahaf5pktwc6hrhr14we X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727780373-969507 X-HE-Meta: U2FsdGVkX188FDUHLI3PbTi4mjA3MeTJGIEEQS71MOSDwOz5QIJIad1etXZB5tRnf0C+LEFgrjenvXp4izOmrkrSNljJgd1FazARfWUSfcWSNqQm+vmi9+ld1H+aoVuBhaGokC5yOdXTL326pM6t02SWu7shkba7ozMDQOpRY+00+DZPmFciC7pIjZssBL05rUsSX1RPYyYK5zK8DuF+K8xorESWyJGRo4W0AZPSjg1sgpA3VHG/IQtjGZ5hnY9VWlfWYDPTkXOIBM7ajQ6fhDlr0XX3n3M6P1xElI6wBc+rpi6H2UkXpqKM8TDFy7HU5bPxXEB9T52ns9o6BG9w2RuZRe6j+e+PooUUFfw1QAw8A5m1GnMYmQscxTpW39RnIyrYMde2tZds9Eld959W5vKMf5fOBsryxV+R2srVThzMLPClD+lXPBFNRVfieScCcd7RpWXOcivzwbbLdW/a8kE4UA8ds7PevLreyaIKQW333U7gOPgSaz4QhbEXTviO2++nPYc7pnpWWpIl9i5JGmBbpCUyuh5U7MGR4TtO0vSadBXmS/njwGAjnRBdwLL7ogy4JexjURJViyd4keGvJz1NKpkh5803UZyCICF96E7bSo8LM5akqcZSx0DnCbh0UDWX1qWdC4jN6xABXwMtv1qF6W10aepYqOuv1o9YX0fmQ/LMnUaSIaPWuQqVMW2R19+ulSLpzeHmc8cgBLqLGDfH9KAd0LFey3JUZfkY3g9y/tffvc3X0sNLfchLuwESkprw2zz/99xn5L/7N+CWObJGthVC64OCgCQ6SPhRckvFRClCgWOLLlE0TWu4Iw/ILFzO20OKoozvg3EpAWebqX3EEBh5RxcvWk7btsnE2CZtCv4P5OwMgHR0Cpm2tJwsGOkSXpiaDM2WKfJAvzbsHsF6depzsqQrQO/eYQiwf8cVrZomBxsc1aY4R0jE4Nm0wyXve4c2PlodKEUkM64 YC54D9Ps AxZ7AhXsO/ZAAPL5bySygqB9RI4XPWV9WBu+5s0yJr1OK5RMW3Ogq3GDfiOuSAwPfWxNN+f+apoI7C5NbO/qEeqC4jUvtXHyfhBgzK3jPrInjzLG8HmAmoKvlzuYvm4qfO7ZZSbN+z5OSjIN2hqq7jSYcN18/dc62wykXnvm0iL7ntgAnW89NNZYosmrLdfEOdyvAPN3yo+fOVy8umt6Hgokr0o+Jsqf2fpsCShArw0fyHsMudQM6nyIsbx3gQVyEQtHdZ9OXuuyX4TVoQoOjPBrVocIhwH66MYhBIII0P/bgMWxmlCtiZCpBzCVPgwtez5upNdudgtS2royHARxDag/6/7oYPUqS47oD6UO3ka0GKFg= 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: Add a high-level document that describes how multigrain timestamps work, rationale for them, and some info about implementation and tradeoffs. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Randy Dunlap Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- Documentation/filesystems/index.rst | 1 + Documentation/filesystems/multigrain-ts.rst | 125 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/Documentation/filesystems/index.rst b/Documentation/filesystems/index.rst index e8e496d23e1d..44e9e77ffe0d 100644 --- a/Documentation/filesystems/index.rst +++ b/Documentation/filesystems/index.rst @@ -29,6 +29,7 @@ algorithms work. fiemap files locks + multigrain-ts mount_api quota seq_file diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst new file mode 100644 index 000000000000..a150c93471de --- /dev/null +++ b/Documentation/filesystems/multigrain-ts.rst @@ -0,0 +1,125 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================== +Multigrain Timestamps +===================== + +Introduction +============ +Historically, the kernel has always used coarse time values to stamp inodes. +This value is updated 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, causing the NFS server to substitute +the ctime in many cases. + +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 to 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. + +Note that the above assumes that the system doesn't experience a backward jump +of the realtime clock. If that occurs at an inopportune time, then timestamps +can appear to go backward, even on a properly functioning system. + +Multigrain Timestamp Implementation +=================================== +Multigrain timestamps are aimed at ensuring that changes to a single file are +always recognizable, 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 an unused bit in the i_ctime_nsec field to indicate whether the mtime +or ctime has 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 global floor value that ensures that +this can't happen. The two files in the above example may appear to have been +modified at the same time in such a case, but they will never show the reverse +order. To avoid problems with realtime clock jumps, the floor is managed as a +monotonic ktime_t, and the values are converted to realtime clock values as +needed. + +Implementation Notes +==================== +Multigrain timestamps are intended for use by local filesystems that get +ctime values from the local clock. This is in contrast to network filesystems +and the like that just mirror timestamp values from a server. + +For most filesystems, it's sufficient to just set the FS_MGTIME flag in the +fstype->fs_flags in order to opt-in, providing the ctime is only ever set via +inode_set_ctime_current(). If the filesystem has a ->getattr routine that +doesn't call generic_fillattr, then you should have it call fill_mg_cmtime to +fill those values. For setattr, it should use setattr_copy() to update the +timestamps, or otherwise mimic its behavior. From patchwork Tue Oct 1 10:59:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817782 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 BD1D4CE7D0D for ; Tue, 1 Oct 2024 10:59:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA17A280079; Tue, 1 Oct 2024 06:59:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF58C280068; Tue, 1 Oct 2024 06:59:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2BDB280079; Tue, 1 Oct 2024 06:59:38 -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 98B5B280068 for ; Tue, 1 Oct 2024 06:59:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5AFFC120FD1 for ; Tue, 1 Oct 2024 10:59:38 +0000 (UTC) X-FDA: 82624737636.09.3E9D1BB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 9A55640003 for ; Tue, 1 Oct 2024 10:59:36 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OBF7R15b; spf=pass (imf12.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780337; 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=cckz3p8HeZ7XKfyqcYCtDgyKzu4arTXpHRZYzAXxYAw=; b=cLmawQqT4G8hd45zbXcb1bZuXP7Jd1pEmK6rdwMiHoc9hqLv6MU2LsrHVSuaRhTotLEQmV vEYEiYe1LIjsssuLa6dwDBpgH/DAOdoesUBKPIxEQMiB64/nk24YGYbfmuLucDbU9cpzpi bqMgGv5LZENrYTrugVhlQCHonF2gOnM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OBF7R15b; spf=pass (imf12.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780337; a=rsa-sha256; cv=none; b=j4WIy5OgBQPyZ9Vby7Hl48R0W/KAE7dj2KOW0+cA0MbqG9hw9xHBvIxm2PBfBfGfCEggte LpgvDNJuItY9G24FD8QuRlt2dCCri8PlKH7jA4NfM2PgsQ35GlLEmQ+5wG0kjun5BNI552 yNMWOK/A50Zjn7aIUlpHH9BT4lZHEkw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BCD675C2779; Tue, 1 Oct 2024 10:59:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF78AC4CED1; Tue, 1 Oct 2024 10:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780375; bh=m2lMTjAgLXYxRt3GuKTCEjdRkZam4zPki2ETeaDm/ao=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OBF7R15b9rIqKG+pvtE6rj6OdW0IgTIhklVWXvyfUcsAXEMiM+5A8qs8rYSkp6MC8 WzVD1hANjS7mrm4m9IIzd7x0nU4N+ZQ0oTnkeZzxiWtA7aZ0Q2zGiCcWu7rNV4TDvv vY5EZhnCloVawAC3X0cUHyBeCgMoFAJvdg83/nwaFXGrYvxuDVPp5j/1KFrwxAPUmc nw9YRak3vLrzUcqSw/dL8+Rfg2LfFMeBxk61HLuWD0RUW/74imBhdVzQxLTxVPfZ86 A8ckKa4UPYviPwNPHQ2pP0W7sF7oCdsCZsB4gHDbafgswTs3QldFrlY9qPIW5r5+PD AiNA2CAE8nGow== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:03 -0400 Subject: [PATCH v8 09/12] xfs: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-9-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3012; i=jlayton@kernel.org; h=from:subject:message-id; bh=m2lMTjAgLXYxRt3GuKTCEjdRkZam4zPki2ETeaDm/ao=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X7GLL7kNWVIqPbkvgTfkIdHSTFGll+0bhu5 4aE3jIwHdiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+wAKCRAADmhBGVaC FaInEACrL+q8404CLEi/39DzITks0kx3KFB40IxDLDYM7C53Oow0+1Ouq7o4SsV4HwHWj9/+gUk VPV50u0AiO/cfPNEGjdD94ahfvh7mWZitnVrIoEjaxeRFWMnJdt9boNh7PSwMvSgbsQxKwDitEA xQc6nANNzxjz+taw7eMsTn41hLmZ2CYkEgr66NyNh0H4sRGPh/9SbYeuGshQJ5r9jHcXxEGBoEc j1IuRH4zy++45mvBxNn73FDMnWTFcjdkmmp+RFJsvdDNv/wdPVIDBQ8vQvwHUwSG0M1/y/s3z5j t9hpYhjJ7hVbCWtjI6xliIjp20ftnaNG2gjVzfU1vQZZmjYypYiwSNpuavnnMOmyqumq3Lqk0Lp b/ucLYQc/TjkkS4Rp7RVFxq1FE6nP9df9YQ0+itMOwTRnLnz7U6qGL5jI9uQkb/GeGbURVaH0kX rKd01G645FLE8KuX19ir4hMW8hqMjaNux6D664rxNlVaqH0O5806S8ntjhRcm4K5a5qCtDSHAsz 59gKIxPSNxFFFRxbX/ua1Djl68hWL9viBhwV0HF/k8kwxGKSPeNdYcKfDQi/E/MnjFPPRU6gh0e RU50fMUFq7x5jUN/T4sFPyVEyDtxRONRQCMUIPkD1/6dEiU3Ybt4li3Fb9gN0c255JmbZOohyj1 5L1Zb+qBAeoVzdw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: 55epkzwos7369omgdugwa8oykjoh15pf X-Rspamd-Queue-Id: 9A55640003 X-Rspamd-Server: rspam11 X-HE-Tag: 1727780376-312673 X-HE-Meta: U2FsdGVkX1+6AfC9MPrrlxyaG/k7UE0hUu6FOq6jOSB8c/qhnBzbSJ5L0vLw6y0qF/xmxEl3OKfGFFkNwLKwhadmU0eLsU4XyqRkgSVgcWo9e3+BHnCa3EmSE0raF2d1PjXtLF7e0ZhpgSQsLeDblAGA9/gWl7SltsQDD4hoD15a7mRfMVqh936qYPuoDqP3PH6CJOlBj0NqPGgiUoLqj4LCPBRs2GK2a+R0qcnEA1hp1kQDHcGqwsiGoNJmU6Tq2wUC1OU5yAlC8fDyYs31EKOsuPPgzPe9SP1u23zSqbWofTaeEvponxNINIodjFjazb8f/+6KwTHqkHLvhZVg25/t4TSe4nFo3eCxYdvDQN4mToaj7GsP/8vnihfiVEbTW04wnrP28kktMu7Ywq1pNDjdMwwnbeBhhhRPG7/vO6pD0Wr82R1QU9cwPMc318kvpdpSshPWJd1jG6Ah6DXp9/ywtOy6k5+Z3vXX98eTQ5hfumGYGlYLDBoygzocAwV2/6PtbpveQTDoe2R6c5Eoc6w+yFnAHWIk4KSkRGdckso4Ey7h8eF9+ZGvodAtIjauwTTYL3CLfHSfWJ19B+ne+hWSgxbt0A1bGFngisawCjNWWAG7+XCKc6lnSQN7JjI1L5jiszbD6V0MDiuUgBI8dBSEUfwmRRhKEe1xfQVO8MqZ3ygBtgIlgah0uQ8wMD5Z9N1zfj67MtTfTQYTQe+5ldB4hl6ZDftSZT+op8F0s1IZnpRUQ0wL3ATT2ZDXfGpw5v4vSa6tvT4nWCJjVuHfxllzA1WnjC9bVT4M+V/Qw7WfvuJoYQAe+mKjYaMjiz9rd+HBOsZxpA+eFS9ady/O5Itpuam+guPBG1O/+rVlvzW8d7KuySjHN1S7QEtVrUwgA6EIrl7zTqWBA2oQvFikFtKelTX/zhyOlQOzuCHajxKFCMx4UVWUhDs3+bTrpQA8yfPx6nc4idAeFVed2Ko F0xPtwSH JkMCD+USiDc5lJsqqYPQ0niieJxeSxFD13hPYeULX2WakhqbyuWLMEJK5jPv4VeJ4+Yb07IsgmVsFokcEscSDevRFHVnxwk241VYnCfhxGr4kj9E+WUUNOy9x7oAJB1A78I5jq9w5wePVu5RrU2rntp08yoa0AekxjCZsOTNwbFqkxxMNMV5SxLLNtWWEjcaLgyp6VlJ7Llc36Yve1Cr4zfmLX75ThPZglS9sk2hmmBW+F2Zr/9bH46UEupOwr2fTvCvtAqpme+1MHae9IUzRcHyged21dyiy84BdI9A0QZSPveoxIQrvYzXwk63bsgApGP/32Zdgp8nnEOs84E7LCe77JE9PeYrJw1fOKz2+3hh13mI= 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: 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. Also, anytime the mtime changes, the ctime must also change, and those are now the only two options for xfs_trans_ichgtime. Have that function unconditionally bump the ctime, and ASSERT that XFS_ICHGTIME_CHG is always set. Finally, stop setting STATX_CHANGE_COOKIE in getattr, since the ctime should give us better semantics now. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Tested-by: Randy Dunlap # documentation bits 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 3c40f37e82c7..c962ad64b0c1 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); xfs_assert_ilocked(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_ACCESS) inode_set_atime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_CREATE) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index ee79cf161312..b5d0c5c157e7 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -597,8 +597,9 @@ 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)) { @@ -608,11 +609,6 @@ xfs_vn_getattr( } } - if ((request_mask & STATX_CHANGE_COOKIE) && IS_I_VERSION(inode)) { - stat->change_cookie = inode_query_iversion(inode); - stat->result_mask |= STATX_CHANGE_COOKIE; - } - /* * Note: If you add another clause to set an attribute flag, please * update attributes_mask below. diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index fbb3a1594c0d..fda75db739b1 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -2063,7 +2063,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 Tue Oct 1 10:59:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817799 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 BD0D1CE7D11 for ; Tue, 1 Oct 2024 10:59:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C007628007A; Tue, 1 Oct 2024 06:59:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8960280068; Tue, 1 Oct 2024 06:59:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FEEA28007A; Tue, 1 Oct 2024 06:59:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7E604280068 for ; Tue, 1 Oct 2024 06:59:41 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3DDB41A1019 for ; Tue, 1 Oct 2024 10:59:41 +0000 (UTC) X-FDA: 82624737762.12.635D763 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 7110F40011 for ; Tue, 1 Oct 2024 10:59:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LcPTEgr3; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf27.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=1727780239; 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=N9AzcHyO+ing2lEAJs/wavmYhF3E8INEAc/fntEREVE=; b=4Q9uJ2+xJoZjbcL+tvy+PG4XW5LL5VdCdfTdOqixMHz1zCMSnbDHE9XxDp1V2qzYAYWvrr vUI2Z+L3m2I/CxcmA5hDhFefMSFP7ZaygJwKlfIiOut4QuQs1m6+JKfXHDUoAT3gSMF62s KOJigYbMNADwFpEKiKCKCuTv9PduJ5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780239; a=rsa-sha256; cv=none; b=Uufb8jGsYM5fQn8LTO0jciQJm0juIjtpvBjfnKuk0Pocy7949DskuqWws6f3JbEpPGC4s+ b7X6chvfyxu8tUTTT5/tHt8notWOr3C5nBkJTkr4p7ziiekMoFG5Y2Ej8JcWoTPJxg6/jQ aSgRoYUwdNcNmyDcRuXxdfz+HAIGzFo= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LcPTEgr3; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 82D8E5C4C12; Tue, 1 Oct 2024 10:59:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6341C4CECE; Tue, 1 Oct 2024 10:59:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780378; bh=R1V1oQO/HR6pPYBHRjWPfl1W07s8BDOLPrB79M1Pup0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LcPTEgr3LIGpj4IMEcDLwZimr+7Ka2J8XUVYJXcwKexQKZRNl+B/gz/p1/b1Ylg8+ 5nl9CYhLE3VfTvJdjoQb+w0VjGkr6Q5WjwuZVLIsYjCFnbyFhvrqCrRv69UmT5XrXT 1enVv01CYalZXPqATGBvKz4kxfKoy9Imojb/0cKnCsxxiJclCGg+P2+epw74hC0C2k m0ujunF3zeyo4m+MwsdvxZpNOOXYRmHFmWHzYWity/uxVQsD5uYUaAFVhpb8WOA0c3 pLmLBS9EQuyu02S9dw0f7VlIShj37pTPClFGAtaQqBXbOiCj0GmcModGTyJjik3m73 7GdWlXZfKyRcA== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:04 -0400 Subject: [PATCH v8 10/12] ext4: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-10-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=996; i=jlayton@kernel.org; h=from:subject:message-id; bh=R1V1oQO/HR6pPYBHRjWPfl1W07s8BDOLPrB79M1Pup0=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X7QTZdC+qxCWqwkeb7mXbXTPnc8Dvvtk79L Esr57Aa61CJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+wAKCRAADmhBGVaC FdWkEADGKsoLv/ON86grStfqxYFB5hLkrC5iL1RD8FZTihZ13PjlUIGKzv3+EtpBirfR1HR7mUO ExlJgkZE4GBWdZwAzOu5D+8QI8jad78VVCjiGPvZ/k3bHeXGOomYdKca/IW+bHQIBl3Lota2iGL LSV9Cuc86cEaNFJdUzKhMpPxpxUZkLttJOTH1mr/kBcCOVW/BSqmU8GuRbcBpbvo/09mwD8TVfP XUh0RBYgmfR2hyAZTm+e2ecFXTzgrINqlrdoQSWX0zv8sLQqVPPuSp/JrJu+iP7bCq2we7c0g7k YFte4XhTL9E49zLQOfCw9CyT33b1Yck4rppXMU0afyUv85H+h7TwNJCqRrXbCD0D2pCeueWEtwd OYpViuzKDxY7CNUKoqmKHqk37O1UGvATwb4zBymQvCW/iAjguRQcxVqvtWE6XL8VLAw3sAZzP6a 5QUHD7N98tDqYbP6Nj+efzGD1Ikjcvbi1r1832k6tHWymtTwy0V9+4eEZ0mS+Ci1wjgHBepOB6k GDRlhIMLvA6AdeLGnE+I8adHq+bonD5tCuwBrQzVRihxan4TRqBEjHlEV3uajBoYgYSS6K31Yf6 hjy/of4I7I1g6mQGqIrYJ9v0CQpPHyk7dzDi22K7Cp53vlktS294Q+5TJgQ7bEQo7qa3Z3OWcqr w/9y2eQqRkTcA8Q== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7110F40011 X-Stat-Signature: e3wgatkpausduncbnfpq8p1re8cqsmzx X-Rspam-User: X-HE-Tag: 1727780379-235439 X-HE-Meta: U2FsdGVkX19pGVke56zolXkU9knlZZy1F1TyXG9tYtDsERI8WhRWhNH5sUk7nrFY5GalZZk118n8iJbz2Mfv5xnbwgj6DXvSg+pYZ6RrRmGvSJX2+aKEy57WfIH+caP5VcQ+GyMNAp3kue5Og8zeOh/xhl/hZ9aGIs3gaWJBAwg9mWFdhGNzsDH8GsYKq6fCV07vyJRaMjDykOC9JHAI7LWnrg7WI0UOc6/aU24gpivq7BKTry7FkTjUSHjU5ITP8tCs909s0f9YvbXYigDWNP0l40+ILOqTn8KhjnWKBRij8WGjrCUUDovxntpBP/mL6Fpw+lASjbmXda/gTQ+sLrZWQoQrmvDlGmwemYlLo/xlAPCyt6UpTSZTxFpIXO+EIRqDdWiaYz8Fva5oNYuIZCZ4mmAMaXE92CYtowolDMx6gU/afwRR78vCmHtsIZOQgc7XWsl2/Kjw6OtGBDWYJNRe6WnFnQBVmYvshGcjdC29tYYqCi2sbIny8dlt91XYGVmBsxpbvPsfQJpkGkXZn8XXyxn1ay9bL5thGKCFyfmFQSZs0csCJYgnTE/uyETKBzh1j2x6ZpIWlQ+ZvM9HN82KNdA9GeYCgxRaFXEDtchgfIIHdxwmj5DdG6eJBUu6+1UCBr4ceINwu6+H/F3vl0853HW3DmbYL3F2/Cmn9rzoG0J7KtW7T+mcCBvU8swNsN4jYbxbrgRG6/IyiAxxyPh3DHV+si0m6hb9w35lNSb4ZUc4McfVMbPBpSX8w6OgLf1zmbCR3nkDG1d6EohAMLK+H1TkQbDq/j+9Sx5gqxXpzhLGdT+15xAXYceFzX65KUsIdNpqbyiYG0Cot2icNPkfMU1H/fTAOTr3WZhaX+IPqItijkrfjpTqN5ehxCdOpPB/zPLPknWz7ROavRjYT+NUI8RRTRbsSinwuipnu0piVSFd+u7sr4d/t8P04pmOxOsmt73dWVElKpHPDx6 d/tF2eZO i5RSnsPmJ0Dv0QB6s3rY4ghLJmKF9OER0COMinnSaP6JfoqL8ThxP43QCoFnqKIeRa98lYowhZj1znjQkHi8V7rlJN6lmQLkJLR3AzWO1LaXMuaV3VsXINmCwA9ni4F4DFlyxJOR9ztB2Dh/Y0o4sLcPX4tiuy03JPgdFVTioMTx6ihzBhp4tj3cIkNyLB++c+deTQRZPCEwpt7YmqX4LIpSCyrX0SQhQnHVyVMQAxZ4CA9XNW8gc7yI6JoB9dNPKFHcnbxc69eqv91oJtYAsfb00Lbddp8EShQideK0euCrUp/AKLvFNyh3C5cfU6UT3z5eOZJE3TgAUdVQWDKWtRi78tU62MHO54gzsX48DKjFvvuo= 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: 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. Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits 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 16a4ce704460..b77acba4a719 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7329,7 +7329,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 Tue Oct 1 10:59:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817800 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 89483CE7D10 for ; Tue, 1 Oct 2024 10:59:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82DE528007B; Tue, 1 Oct 2024 06:59:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B6F4280068; Tue, 1 Oct 2024 06:59:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 607F928007B; Tue, 1 Oct 2024 06:59:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 39FAE280068 for ; Tue, 1 Oct 2024 06:59:44 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E9E6C120FCD for ; Tue, 1 Oct 2024 10:59:43 +0000 (UTC) X-FDA: 82624737846.17.B122940 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 264D41A0007 for ; Tue, 1 Oct 2024 10:59:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mgJN2Sog; spf=pass (imf19.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780318; 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=8ZvBNRuRJBDYAMjjty7KQbL3GLtKr+olQlL3N78j8uc=; b=mKCYsRCEj9dFrQXWm5X2It1n72jTxemjk1uc5vuAILLbziXEFvueCqPd1fPV7Km2MXRgsF 915qm5MviPlmvQJtCHJwm4UREF1ik4DD3BZa0apryvZz63dQtHRIne2FsBrE6HlmAByXQP Dzl8fknAnUDquX6tILxbSK6Svs/ECV8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mgJN2Sog; spf=pass (imf19.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780318; a=rsa-sha256; cv=none; b=j1bak0AUl3hlXmiVETv0JFr05avGdg0IaRph6T3EISCx+71fFUFEe3249WYlTbbMfxxNr3 l+vBHnztn0UtI8/HTZ04FoAIcERcKJXih0zqkTL5ozChCIseuE43HL9unRNopUwVHHbxAd BCkG47OBPemB7X2apudeEM67zOkisnU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4A7885C53E7; Tue, 1 Oct 2024 10:59:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BD64C4CED4; Tue, 1 Oct 2024 10:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780381; bh=UttJGln3RsYeF35AMrr2wmS/hNsiLcUiITLEJHfz5Ms=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mgJN2Sog7HIYjLMvgAVx5L/0qUoze9I2mP7px45sIleudkB6K7FWFAeil/EaLhPEH VzjgdMMsdHddmMR+2f/MAtrJt6cNesnog5NsxkUof+2quHpz8CTslLSxToALMQGFM7 wWsQxAB1m4Gt7Pz1CZ5ZMjQY3Tm2l8zwwJdMqJRc62n4R7lgp0KU4B4AeT/10RzU2s Kx6EmB21R4yxJlSlAGDm90IUtao/sJ3amEcEuIwWbcfHidX6A0yqVY1nv30yIhnD9Q xQwjTeAnwm8ExdAUeLxRmp6MTDLeM0ty0u91KcDRi4H0QxGTGEbpMbuem3LnhboaGk wo/PDtzezMb/Q== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:05 -0400 Subject: [PATCH v8 11/12] btrfs: convert to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-11-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2730; i=jlayton@kernel.org; h=from:subject:message-id; bh=UttJGln3RsYeF35AMrr2wmS/hNsiLcUiITLEJHfz5Ms=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X76ziqrcN8sn2M8lQjmFo39dkFvoe6mXrnn gNHXakHKmiJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+wAKCRAADmhBGVaC FYgcD/9eDy7UZeUD34N6bzAuHIz+P17VcBdQftd5Y6GWHvi87dVZ6Mlr61dUDVaOWLuF2WJxMo1 UGWKR828DQiIL2Esoqo/e2ze5VhRIMSTJWrCqQfKPNOmJiPiwt+QNM6sm/xYBBL1Ck5jGZuQFX5 alNr6JqlME4ENtnSzrUKGrXCbq0vqrQqTo0TrtVA25wzuZ9ySJHEyIpIPTooKEqMYXfV+kMH669 orDknC33K1dOmhupXeN6UJtP2MAl5ahASBDGLj0szE2zh0sg7d8axK5usLOT4n/k0sCX7wge2as uXkTL6tGJ1ZoCeHKsEumoCi/bxdiueJmdvjmdJZ2nt1FAPju/LjezACB2mSIstrOCm5zvfM/YXD 6UbrAShHPdMj/E/uMRjsl1v4VpfN452Y3KQkKf24OAArApkzUMwBQQ6MUnbGyXtkus7jTTSr4Ju rpmIEMR3MKC/PfMJP0S/0ryZQMW8PmleNRy/qsDJWlSfNwcoESOQFGfq9dL3v+smtGGFMvqsFef IYyiHLx7Kh1zBZm70fmQq04umgfyGPM7Awpj7QzG5/R/R2qLJCdYHPdAXflFSZhq4Jz7emrGOJ5 Fbc0Nvxk08/GvArfrACwtuv/r5qXk/aMShjA6AC0Mo+bM9nXhFC1MQorOTtBSYsFRQ0O9OvhhQs j0hQSnLz7Aj6sCQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 264D41A0007 X-Stat-Signature: 6q6wgrh9uq4gszbrx1mnxjxcgbkcgozo X-HE-Tag: 1727780381-571647 X-HE-Meta: U2FsdGVkX1+rEIGRk+HsRWhSQuVbSi9ELij3z40q4ETw92AWOq26NIc0wnuBHa/KXk0OFvDhr0xJQTrWNWIP8NbPb5tFN4DMfyB8KBM/z5yxcHPZxL3pFUK5+0MxEI9RzB69195fIW6ArvMKOr7YJnVIv97WQi9fLmP5Y20cklRo4iMgRHhzFNHN/8cl2I7GaenRfK8HaZMBSzVMMRiblym4EsMsD70dMUGdph/swwxTw2gqkXSiF1BzI6OPd8KrF+K7lMaXX6Bn+Ur2QjkgMVDCTVGBlKR0JYP8Pvz7sAlJXuYh0FV8Eb5HSY57AIpGSxq+5WR/fPkMZ7B7dH87NT7TzEQVpbDqUklUSRV3SmXqujbAJae6rAEOzDOiDueJPvymh9K/MzyUruv9NgdLl7H35WFn7pSLFBRFSMzfji9S6p4Am80ccGKCffcJDfwJogpHLW9/amsJsPWOdzLFprYGN6cCJtpO8TNvTos6Z4pmQUPogaZFvtCp6TAHIKva41xK4HMX/Gr6YO3zX2RlmwZUhYEgDVRwg7KMSVJDg99RuBDAXnyQt+/eVrUGQduJ26wGPOzxtE/0ZmpkWucDeW5aGcbfCfbW14EMmvughJwBCjZrw8hwHPvbsqvE3sLwR/mvA83m910uMZtRm4axS+Ns7zredcnCqV1XYR4ZUBLPg7p6QFkHPLPe+PC9UvpoHB4xdPVnYGdsD/GwIWDDTZZIgdwk7O1Xv3KhxekKWFQyEEGRFr3irAs2xnr12oYqB3VL60N53JPy8jMAMJKHH558m3vCUZexe0zdQKVgZ36HsGgdaYJUS7s8paQnpZLYabyEop8uu0U5hJJ8vJMM2aAD/39RuIN0zcGXbhmc7p3qomq1Y7DZRjYSvAf4LKlbxv5E8gK5K936uOtnUGjiKnAo1yPRAsJEjt/LJZBS34PGrwM4/kGO3N5/waIZStoFWMyX5ST/idQ/BJzey3D s47wMPTc JqKZ9f2a92+NWB14ihWpQ7MhZ+qsJ53/AyPdt/X9OayLS4cRk346W3euci7h+z/VzGrZYQHAydh5Zm2gQBpVge3Uqw+TM17p/cdKKQNFH0nifZArKugeKcgEiLnfEzsBkBlfybHyN/TGKyqG7YZkUHa1ZUPE7H9crT9jQ/1AmrFJ3nGjg6AA4KcAFqTAOOcCKVbQ1llHy5cPw5SW+gDuul2THo1FoMCtQ28CiKYETrUfPuubk9ACU592daP2DJhEoHI4uwkrIaf4sNF9YgBUnpkMhE1YsFswcEL6AAHP8vfVyT7QmRT58INF5WAgdKQ2ngY46/sSRsNdWQHCOuYnQga6m9MqTWpCnUTbTr7Nmhrj9tqg= 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: 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. Note that this also drops the IS_I_VERSION check and unconditionally bumps the change attribute, since SB_I_VERSION is always set on btrfs. Reviewed-by: Josef Bacik Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/btrfs/file.c | 25 ++++--------------------- fs/btrfs/super.c | 3 ++- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 4fb521d91b06..e5384ceb8acf 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1120,26 +1120,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); -} - int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count) { struct file *file = iocb->ki_filp; @@ -1170,7 +1150,10 @@ int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, size_t count) * 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 98fa0f382480..d423acfe11d0 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2198,7 +2198,8 @@ static struct file_system_type btrfs_fs_type = { .init_fs_context = btrfs_init_fs_context, .parameters = btrfs_fs_parameters, .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 Tue Oct 1 10:59:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817801 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 857BDCE7D12 for ; Tue, 1 Oct 2024 10:59:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AE0A28007C; Tue, 1 Oct 2024 06:59:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 235A9280068; Tue, 1 Oct 2024 06:59:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0932C28007C; Tue, 1 Oct 2024 06:59:47 -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 D865D280068 for ; Tue, 1 Oct 2024 06:59:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 966E240F71 for ; Tue, 1 Oct 2024 10:59:46 +0000 (UTC) X-FDA: 82624737972.07.0AA6DC8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id D466A40009 for ; Tue, 1 Oct 2024 10:59:44 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NqhWoLr2; spf=pass (imf17.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780320; a=rsa-sha256; cv=none; b=WMnNe7H1y9oRApW0WnycltqxVdaZg8+EdxuU52Kj31pvGlbxOiL1OfXQGKNnGiyp72sEkm tXcP64HZU0LriS4VljiJ3rt9ChoqUTNVVqkE5ZGBEFei2S3iAuAVh4Tux+La38uZGoV+Za A6Iwcyy8oIDdjb3VYqIsoDIke57xc1M= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NqhWoLr2; spf=pass (imf17.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780320; 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=bolnu2yY5sQqpVHirE/5F0yWEoEqV6NQcoUQqtDYtX4=; b=5O/owKcbKzWgGvo6Hhli4V/mEN00BQt1pVTruKouYXYbveou9aBQt4aOvzCB2UyaFUTE3p +a0b8k7vE5zQy/OT8PsjPDkfbatIdhb91f4QrMmFYCyzXnQg194uNnt4y4qnvLmSHQeES8 LNHmIK/F4hBR850xZstWD13AzxoNAIk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0ECC45C4CA5; Tue, 1 Oct 2024 10:59:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 428E1C4CECD; Tue, 1 Oct 2024 10:59:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780383; bh=vfABgeY7uP8db917PbV1dpj3MLFQbmpQZkOBbve6x6s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NqhWoLr2qLRQdOkLcMCIBUNS616yE7Wsn2Do3FYKCPxTNAtUhlMY/8vPDqL9CORJ8 gawIrH/IWI+r3aob9UJ951bTu/BMDqZyz55vv0Dwt75DKG3XVFJh+t15nLMHHgmMbn 96Izn6X94VrbCOjG3imdMEt1RCnZa7cVICavqgsbX/cY5RAUpWFPvAf367i7Z/eUkH fV3g68UZZQ5YPZXcLa396R8kWtFuPbB7nD86sjo58JBtkRSEyAc54RJQT5xRH6ebl3 h/caq+ZGm7/fH6u2XMHwCQ3JTm55c66IdUVEDyJC+VNQhN/gDSUWfHmV3q+IsazEps HUQADV0X3MASA== From: Jeff Layton Date: Tue, 01 Oct 2024 06:59:06 -0400 Subject: [PATCH v8 12/12] tmpfs: add support for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-12-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=932; i=jlayton@kernel.org; h=from:subject:message-id; bh=vfABgeY7uP8db917PbV1dpj3MLFQbmpQZkOBbve6x6s=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm+9X7QDV7gFcbV+IsKkmQpXurd3+vww+OClJdZ SSWm3r5Cg2JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZvvV+wAKCRAADmhBGVaC FV6PEACdz7xhqHbN+F1/z0hQRO4/mNdSl1k7n8dBoxQIuT87EzYxjm+op9ZONXBq7Wi9B7zpVO4 +yg18nLaWlVJ/wyVOFlsN9AyY3M3qJ0E1xVqYGkg+D0siO/CKOYvUIi6DTP6n5rxvjrgB96B6be 3qVtF/YPIEC6ZXkd5pBa1nyA5B8NYkHJNp1mM1DLxDSyui4SfSdOR42NDEYGBB7AYXZHL8I+fGu VN+hVOpC0sW/rp4dEYSNd0rYKNGEc43bN+N6wG8SurCZMFMQYaGXkcTCti3PhldmzKH1WfFX9TG MqF0eshQ5RDGJP7c94SJeYoZrHOoDAV0ad9MDFseXziUXUbJewSI/WdpUbQbcPDdCRw58Qy1gDG VkD2HVjbK9ty8Rpe5GtkhmudPY3sb7BLC9DRg2W++B4uXM5qJO4GPZwHSJ9buzL9grC/6q28BRo lGEJN8oAh0jMElH6cjMSnFA9Kw4waaK2pCj0337UyhmARAFHrE1yXon1oqS6j9XmT68wrXeLw4m bQhXGdsxvFGNn91k35C9P60R3dKONLg5/DcccX8F8HSwGDDH65KbRzt65ICP7217BznAXCP8VQY ywjpwBUVXttEZ9/AGCiJLXq/xZnoaRs6Ss+0JHgEbIbzV4eeXQ5bfTjomIrl9R4boIUCfbf0/k3 JXXFUvScYgNP0ng== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Stat-Signature: 6eskf74n1kubbqrbggtie98ow14pmgdz X-Rspamd-Queue-Id: D466A40009 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727780384-734471 X-HE-Meta: U2FsdGVkX18WzzgGaopTZ2YWBEM2Dy0EUw5ch/XfKOwyCztqBhYEpkbIkGZ25JN3hMc2l/EJfiFccFba6wKXUgO8Ahj3BB9e6lgnIyi68DqGQoSBSycn3gHehUQEnXgG95H6+uuuci7r3dqRhdnizb9znFJyEAZAjTq0ac1jKMS2kcTnOJr18cPmZmGNOkYSisTplL97pXkxoz42fgO/vJyEwTe7k2p7Hec4xJxF44IJnBtBkLDTzWm+CkP4GsYl9H+wYBTQDlpfMFQnbtRX7qsVO/hV5CZn/83LskpivqzVbyFiU9vEQ76wsTWbEUnHa4/9thGixW57b9ppBCE8yzs25jvMbHaEbnLXcyzrn7fTHn1INsnu5ozckBe5Qvi3/+o2COxg7X7d/xPHtqvORaEECnK1nhMhuQSMmAIYAwklHtbcumsSReBQXkErTdUKRtMOjawEFD0DBEkCmRwq2pxm0/d1rpuqFMPx5UUSNxIUyeggLPxOwTTWiTXyb7PFLcIkqtu1qudo+2aC1BVZNM2QuWYWMV4N1kEhjYMJmpSdaiaDgf5PE+X4/FY5BVYvSXDTaV68cHPGmOXTQdnkdqY8inDnY9i5mtjg1PnVWS/LfhZZllDdDYrLkhapIZK17oTuY3O3taPQcKll7O4HcresrjqE24/Vk82tLz54J1etMfNllLOZnrlfUSCAQgtNEgpvQnSQkQh628HrJjsTSD2StQ5rR+UK2FI/j/ADwTByul7Lgl97XHI2fTfxgdfcGhQ8PVAZTsgHV56ABMAtiR4oQcQtCjTy5jBAUlaSf0YGUDraioHkVDvP7I3SuoIH7kUxqb62WgsmkCEVWANkOJgUcgSaGiQ6nJunmpAY0zy8P4BuEhJfgIjPyIWfpQqlOv2Js1+Xo+D9ER+wRkVUR1Yr/FJoHQyrr+Fk37Xeu9hqKUL4UkyU5+PjTb0/W8bG2IZ2ZHYxzMMYkeZqw2t /dYNUrBu fxZWRJgcVg8ksVM4rSMuEelpKTycpaTLJlmjh+3vseN5Vn6phrNjU+Akfu2lbpPQfxe6jxSoHoH2VbolpYbLVbUPZqp+QmO6ofr09gsbN9rafWROWMY71LQBN1IExX7Qe3/r/qjuKU1b/VD7wNVOkcHexXFjmT5xqIMzIbkcSERZTf+ij0c8M59REX0b/ygTUevJftwZcuZmJXglF8j7vwPa90jFohGH/CZTTBWdO66DpqNmauGTRpJmudfZPKFC/tgadDal7Yx+6Wrrjrfqk7UWh3sNcEZ2WFziI8AyF5QfSjfTaq7eNe0tE3R+E+J6MxrmfyWjIDvpXztcSHtxGd+a4AaltDKa/rTGWfpUlxwVLJcY= 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: 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. Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits 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 4f11b5506363..3444efc275b1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4951,7 +4951,7 @@ static struct file_system_type shmem_fs_type = { .parameters = shmem_fs_parameters, #endif .kill_sb = kill_litter_super, - .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP, + .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, }; void __init shmem_init(void)