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: 1991402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=di+Ntkta; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=wiyo=q5=vger.kernel.org=linux-ext4+bounces-4414-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw1p4Qf7z1xsc for ; Tue, 1 Oct 2024 20:59:42 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw1p11F1z4x8D for ; Tue, 1 Oct 2024 20:59:42 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw1p0yNjz4x8T; Tue, 1 Oct 2024 20:59:42 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45e3:2400::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780382; cv=pass; b=xjr0EEwkNtCq+qpZwQfF6wyqSo7eC1qYlTmowfnfGwB45tgUVZTr95ExIjv2vFJSyDRTpKbecnBPdwHp3esMjAiZRlUPesdb3uyeVZcrycMH6/AmjL2HosnzQTPOjrGhjTpjvPKBHxKZrc9AQgULeN6VFgbwcTzmLebb7WBCFaw6l/NMMfBgaFZqnhDl10KdYhW0+nSZgsEV9d8jKn/U4g0H7EXnUksvQVDGAz37JPjIwDBJF2xa+9toGo+7CNJ8GiSNZb9NOTOOCrS2bOIJ8OddvMbWfARhWbcX7QoxzJ+V0y6F54KNQhxPU1hbxkukqqYQrxuRnCbRngLXydmyJA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780382; c=relaxed/relaxed; bh=q7XdCvNbTwtwXszIgu/p52GnWd98CBWi45ZNHRi5mNs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OWO/f31B+fnBIRGbJVcS0wyWsic+7SxjzbTxN/N0+z6MJfb0Qxm7T/Nu4KE7M+megT3XfcKPP7ZUjzAhnRSk/uWAzL3GWZko3CyzisMNh6vonVU9MkEs2XEzuCukkYVNgn2pWX3TnKmFxGGs9JOV6E9wSDaEdAS7XwY79T7oHSV+cKgzEslaFbhgXefdQHdNt8/7G2005KnR/gle6xPNwsntBQYVylfyyeScIo8B5OoRaAeGVwulik6TWIhYmEeTZc7pSqylVp7e/WHJ/ge00bhnNuVwMzoE2DBH3uS4Y5AO/yGYjc85DYsrYhYhK5dlSIH8Tb3NLzwZrDt3G52oTg== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=di+Ntkta; dkim-atps=neutral; spf=pass (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4414-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=di+Ntkta; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4414-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw1n5kT7z4x8D for ; Tue, 1 Oct 2024 20:59:41 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0433628321F for ; Tue, 1 Oct 2024 10:59:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08CFE1BF7FE; Tue, 1 Oct 2024 10:59:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="di+Ntkta" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EB5A1BF7EC; Tue, 1 Oct 2024 10:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780353; cv=none; b=GrHmAtJe2tHYwOJqfs06fhAVvW30uGFTXC4oBUnIlyAmk5xGOC9p6M1Rumsm51rd1i8stn90/HJISrrQNTYuguZD7QzFjKMXFxdTDjeG9RY9hHCgr2S3Oi+TB2w4778J/MiC8KPJg4/UqNjOIHml1JAqpE3pnQjF2DYOuJDNnjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780353; c=relaxed/simple; bh=Dyhqpi3r2jE4Qp9OIe8aVuLXfVqzINBPByhzwJGovx0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=be9E75rV+LWP0OYNvi6w59P+2QZm4Wr+WGFqSOEoj//UFmxjKZGouwqKsMAOYUppIUZlUqv2Rrr5DwsPxJmqlhBWdvWi5RT3YeRZ9nJIDrrZ6ib+W7MLk7pO9CQvDdEGEJMSDai9h9PKeFlV3AI0X3rtBhOMiBNyLl1LtEUumu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=di+Ntkta; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=RKj3yhF+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=gomi=q5=vger.kernel.org=linux-ext4+bounces-4415-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw2F6MMNz1xsc for ; Tue, 1 Oct 2024 21:00:05 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw2F2zPpz4wc4 for ; Tue, 1 Oct 2024 21:00:05 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw2F2vQvz4wyk; Tue, 1 Oct 2024 21:00:05 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.48.161 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780405; cv=pass; b=utWMKyxyv8jn6Ndlg2YC/SfWK1LmG4N89ps4hUREXlQPnraFQKuXjMi7jRa5L87qx3dCSPB5f8rfL/RLwpJq7Bke//pGVFE4nYjBDf8SNfwSRE/b19q73xDyhyRvvXJKC4QCd1ZKq6330o9dPWAhI9bn1HMEdXkljMiTxC6/qaejroWptAKiyjmhX12qj07mLbPaw3Jyuozs+2YjUA3FdHf6O8d5exqM3GwLDZTmndXYov0/pU832U+XeF0o7AHX7Qsv6v6bHHO6KCRV5xdEQpR/5GwUNYeFEkWDzS8McotXxzk4rDLYpY4+WzAyV9d0IlxC3gfkEQeQmW2kP6PGsg== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780405; c=relaxed/relaxed; bh=yiUOK3rTw35TZrDDtW4Dy9XZk4oh8mUxmZIeN6Z2Fj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DNC3lnlMSdFgTtZ7714YarpzsfGkHMbuASkssJP1cXww1diFcor2FJUExxZ9zqwTsSdSjnT8M+rlIzgphHRD3X5pLn093H1vhU5+gOnryblNtBLS/fH3hwHFgvrpt2iODOe5lYMxjl3C+IM/DJmdDV6QkcTNsOs1JsdtL4r7+KPrXiq/WULd4Xc1eKcVKs1y0GynX2fhzlJH+rLlHpNbthoWq5G2MV/zjXfygJokIR3FzJLxSN1O/8w5ae9CT3IqihPTCDEmAdsHbu1UuRvzD0VT/sVVzIiVoSV6mfx9Hjqs+AMe9GqFq26nlRVMYhEJGApcVEL1S8XpqSQyHdnJuQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=RKj3yhF+; dkim-atps=neutral; spf=pass (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4415-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=RKj3yhF+; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4415-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw2F2f8Fz4wc4 for ; Tue, 1 Oct 2024 21:00:05 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 58165B21510 for ; Tue, 1 Oct 2024 11:00:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B852C1BFDF8; Tue, 1 Oct 2024 10:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RKj3yhF+" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DC051BE875; Tue, 1 Oct 2024 10:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780356; cv=none; b=oxps1EuSxZ6Qh8n5cMXO06kGijHmuGvkveFhAvHuDHDvWLkHpQgxXOLckySDnPrb/6u+Szbr/l/1cUKDcO78JnugGCrNqiah73q8GBqyaqqMUjLLzGUt4FX1SUG1wJeZVnYTsjdMzf3MSZIeJlZ6C4HSKkKwWohpxnreZFMinbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780356; c=relaxed/simple; bh=aZAy0l7/4k2LGVLomi5Ve4y/LL6QUr6Sx2B+lukvqM0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jHfZ6aEmW6g5RJcY28KoTUMsSWa/LpRa8qZAMRyVNqaBypX0TLMPN9py62N2+dGiuFV33zLEz4/OcnYoswJ1zANtpVhWQ00xCOq/YsGv6UesS1p0VSFopTprYHZTOPzaqS+jmpUXKljFPw93FzX4E/RwV+hXkJrSHx3ueTJL+TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RKj3yhF+; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jdWGxNnl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=nycr=q5=vger.kernel.org=linux-ext4+bounces-4416-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw2h4QpPz1xsc for ; Tue, 1 Oct 2024 21:00:28 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw2h13smz4wyk for ; Tue, 1 Oct 2024 21:00:28 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw2h11CKz4x04; Tue, 1 Oct 2024 21:00:28 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:4601:e00::3" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780428; cv=pass; b=ifBj3tb0qkoX1XYIz6aQFUjpTeISOlgEfefwa3JpjFW/qzejdpTlpwvhyXtLphih6P9DEFndyA0dkm+pqZHKz1kSp/kejm6EP9KayqMuwqDA3602pwHRPtvHAZwTYUu8zDVQGTXbboD4oTWdvnYjla51zU3CuJBwRp8epOOX6LK9RjOo6wgc+3Yhaiey75bvCMATTYCLsGyRECHudGY4kpAQRZYy2kmntQycv6CuCfDUHJwPbaRjfKp109zHMpc6wMNFdPqaIXhZQtTcVkhHBie/+uU1IXNUF/6A03OKTPFOg6niIc0OJmsvpatqxkb7+nJVEzCNOph6xOflenN7VA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780428; c=relaxed/relaxed; bh=y4X6MpHEZdpIW7VKtZ7efno5ZAgBe2Y7SL9cgZuuKEQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c2cTaVpSgiEDmeeNNhWiIKJA3grFmvVDHHTrpSB4psR9gOYUSEXupC40DyU163+u/+ihEuKLOtVxgm/9tnyljAvFiSzKPBw3xUB4Fc8B63qqO5OXtqUHQTwo/+wcq1WtdkFsV4ZNUPzpXMrYiikkyJ3SeAWXskpjk+NSKtWo4WDkUrEaR98jWjI/iLA3SCQiz9zAQhUyEWYwfnDCVuhTiOcDm8D2nEG90RqYOBtnGn6RFw4MdQe+Yd/dwnRJISWDHTtLRBJHuxRrvto0KbCltkhVr4QuVuG4AnaGyEs7I8VmpgZxdpio/8nK5bx0uT5BKjLEq92mHMAmfAIQ2s05xA== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jdWGxNnl; dkim-atps=neutral; spf=pass (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4416-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jdWGxNnl; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4416-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw2g4PHwz4wyk for ; Tue, 1 Oct 2024 21:00:27 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BC18B1F2179D for ; Tue, 1 Oct 2024 11:00:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F4321C1725; Tue, 1 Oct 2024 10:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jdWGxNnl" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 272E81BF305; Tue, 1 Oct 2024 10:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780359; cv=none; b=hkEPSEt2ipatFsFmEFn2w8bIp4iBvty0AX2BWHQqff0+ba4GC2HygQ6UOoHJ3pLiEFeqwzvZfyOyYppCBKq3MEkUROsa5WT7dCXaa8x+Xpkjsed/H2iwH2ulqr8uDI9jvmXdajQ3qljZXV83AlVwI7+VAJG1TweOWQTl66cUq5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780359; c=relaxed/simple; bh=IlK6pMQl1VZaRTQUEj0w67Ch4gWJlIpgXXZruOpOJpc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nca1RnKD0Y0T+UDtoSp6YyV94i4Ta/RZDGDrLamsHQiSCDTvBaLLmmd5c2gJvNXu/vGhfNg51liLM9SJ397w8kQSSke63uEIdm+ABe9vdmFSYgdbzeJygwZh4sgXO6aBguaPnY/feZzji7xZOfe+LRnjVUtLefQLlEjt6AnzRRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jdWGxNnl; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=iouMPU0k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=yiz1=q5=vger.kernel.org=linux-ext4+bounces-4417-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw3C4NHcz1xsc for ; Tue, 1 Oct 2024 21:00:55 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw3C1F5Lz4wc4 for ; Tue, 1 Oct 2024 21:00:55 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw3C1BJRz4wyk; Tue, 1 Oct 2024 21:00:55 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45e3:2400::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780455; cv=pass; b=fEuY38LbmOpUnOfaijerzLSdeNLfOOJIHzhT4MM0kDS3cGxJddEFc9MZ19q68S7XWYPtbqAwFr1ChhWeqlbXtROzvfgy+W0UfQHw8bkF3TAfdKUutIWBfuRwUr13bTAJTkpmk9hCsI8tWDMNcgReZELhcQ6cKx3eFqp+6QOK4kPiRL0t/IKZDyBE/4dkjbX2vjKKEp+GO5MWs3N9e3qIktcVDCtO4Fiaws5W7kIO0Ml6SQEO0r/BMpL6QmGeR1OK+zLbMutsiAbywadk+ZjZMmV+vCQy/3AutWguh65+JtBuDvXnwoKQdudNBp7lxAojfAcSnn5uMkTREF96iHzJeA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780455; c=relaxed/relaxed; bh=M9B4Ipm5j8bxXr4of9Ewzaksl/6V7W9qA18FLGIis8o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JZ7b+dGr18u3abIq31j1bnZLL5xU+kaWi+/RfOM9kEW+iMnohWO00BNsDbGja+RYrQx0YiUShMpRFFhGx5uKWArcXCKAYf0xSBAnC2X4Gl+ECWcPdoOSCkdxlAXIuu3H8MV709cp41EeAIu7oLb8iKNBQKK/s2qaq7uN7B2BU2aN/hSMo2zVKlt45wIUU3V3022dpZzxjd+/MUJMg4x4mMV7MnylJVQbTvo3NImPpxvG+cIeIlqctmewTxp/OuRt1SVWgIE2MFck+cOEK82OLjQzKmbCwaCMO3/+ZKY9TmWq3e8UAKbbz0mahfJY05O9uZRVesAXqaoBDv1ZISdyug== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=iouMPU0k; dkim-atps=neutral; spf=pass (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4417-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=iouMPU0k; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4417-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw3B62NZz4wc4 for ; Tue, 1 Oct 2024 21:00:54 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 059A528209D for ; Tue, 1 Oct 2024 11:00:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F2B01C232A; Tue, 1 Oct 2024 10:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iouMPU0k" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C84B71C1ADB; Tue, 1 Oct 2024 10:59:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780361; cv=none; b=KSo0m2ZSOw3/SzRHiuBEATEGALrIo9gS/ObuKsvUFKbuPaM/3oUiRAnigWuWUPkj4Gd7NrKJYze7qzuilOvUMwO+O8RUuY1EW++g++e4N7R4v7n8ch6Ff9MT8zBkW67ctolLY7nmRVmuUlqwfJn/yuk4vx5/wMt8iMPNpfmlwwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780361; c=relaxed/simple; bh=otxFDOKr6FG8LsCMnriOfpK/JOFC4LtwAGxd1Ko/vgM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D30kir8W5QFh4tOOBLALM7DSroLN65KvZbyOomxSDxhgQf76QnyzfC8yUjtYmwuJ0VmMvVxSvyCTW7HmmFYsVgKZ0KMmQw28wxNyfbYOA0uGbwvKgqZMq0NyK8YzqzxaLndCemGEUqjjZf5o9JsF+AKtACExg6MvRDXEsKzP6N8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iouMPU0k; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=KJYReTzj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=uqgg=q5=vger.kernel.org=linux-ext4+bounces-4418-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw3g6190z1xsc for ; Tue, 1 Oct 2024 21:01:19 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw3g2b4Gz4wc4 for ; Tue, 1 Oct 2024 21:01:19 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw3g2WWMz4wyk; Tue, 1 Oct 2024 21:01:19 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.199.223 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780479; cv=pass; b=M39PpqWtQzwA+Cq4y+vr20paUt4PCpM9hMUbSVbcTsNnDEQBe+AsKrpTeen7SXDM0nZbNmUKcqmswx5u77xg/JTiipKOSgFXK+Y+h19gAgAUzQvWycinH7DSD0MINnGn98tENFoQ1TA9Ib9iWZbeWmNEiZLDEnWHuJSMS5uIaZVyAeIOU3i5FvUTQWxF2QFRishwoPsG6jYfagZ3k+r5WQaxghdJx5PKxDkwfBiRYAJ5EqzxMeUdG9o8uo+rmLFnZnF/B14Q8fnrtkG7wY2LgyqUz+q+JVYh0jFXRfB+v3H5UAU8P+wkfb7DXDWzIQbCmybhEPk4VheQpgqCZ0M8tQ== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780479; c=relaxed/relaxed; bh=oBR68easM2pMOZbrlTmS+mhWTwICs3oMZV+CLRRQnJ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sVLmJplvzVKulCXViT0CyiBusoFOEHKBve3UswxWvGIT+kXEspWIAnQN0mCrUZ/z8mN+ea9cIWtDWSopdtDlVhW9xW7+4a9AyIAK1zFkapVzhHAH1aUS0f8yKaW+LRAzFJbI9ydXfrdyByYgs55t1m6+7+JpsYGjOw+mPG+qQuvxSjG3s44Zm1V5R8mcyigfxLnW5KbIRI+PSsDKqaYCOrsD8+SMWo+K8CUWCchRTdYyzR7NEZ/VMmsztcjGMW5GHMEaKj4DwSngeS0EaOkwXfEquK9ZWx1WUaJtvTkNaeXMKNTS79b4uFCRKGIMn8wj1ZSA625DljZEscfcc0hQoQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=KJYReTzj; dkim-atps=neutral; spf=pass (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4418-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=KJYReTzj; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4418-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw3f6N5Qz4wc4 for ; Tue, 1 Oct 2024 21:01:18 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 03F311C23609 for ; Tue, 1 Oct 2024 11:01:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 090DF1C2452; Tue, 1 Oct 2024 10:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KJYReTzj" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A69381C2426; Tue, 1 Oct 2024 10:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780364; cv=none; b=LOX1t4BA/ATlax43633cl00uNmXwr+wrRv7qWxFkUWFMMXPrAJACVgsrUbCYN+xIARHXr9xfklI9KsHH9jSl5weQrRLeiIqNKpDfTuqA/5YT6ZaTMshiPZqgtX1ivKwb1nIt4nnrCefwyIjouKyl1fZXoROU/d3FWbrfffyJ7pQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780364; c=relaxed/simple; bh=izJl02glxmmNWffqD/IPDGQCuMtAoj3PYaIpg9PyC+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AwKVmB7hY9Glskw4BV/ymcxpwIOP2PODLD5cdmoi5zISbLHFrsdLd8Wna8GPF3wLzKeFRmE+4fTEHh+ZU1N4KXC608dHooHLtphc5BU0/KIUNPguwXJzytZihtn4R6xGdRQ9utR5WMO1S2csVUF5AEsvDvebydZnvSLl+zWTYTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KJYReTzj; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=GfnDYDpc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=5tdx=q5=vger.kernel.org=linux-ext4+bounces-4419-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw471g0Nz1xsc for ; Tue, 1 Oct 2024 21:01:43 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw465QTsz4wc4 for ; Tue, 1 Oct 2024 21:01:42 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw465N4tz4wyk; Tue, 1 Oct 2024 21:01:42 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.199.223 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780502; cv=pass; b=li1BNdP/V6B6lDqLKw+rzKSEytw5G1hKWIkumhW++6b5bLLmPeZnfaebYwfZUEHoQpCqGHcMxp4Kc4wUiC6GtX86ozbDk9iD6F1VMpubTXKCfagKmYEDT3gK90EXCFVy4jzame9jkURRbG1HffNFVTr0BrVioHKj29qMYKwRBfEgrddGriLOd+dvX6kPri358a9Di5ArVvnYqawtwrbwqOzDkITqhr9/VdFLW3uBHh7LygOAX9a7qmyGfjLblmJVdU+TJQlOEj05ioWd10fvGVNH+ZIclAAMp6Si0flxEItPawYs8juzM6D9nC3aW4Q/CXJckyKjfCB7c27Yp+/Q9g== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780502; c=relaxed/relaxed; bh=M3I0vGBPnlMtvVR07H8Xsh7oUVCPl51S2llG4iNobUA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qAJNGGDWIhxzrFEZvdOPcHkotDZox+CaZA0VhpxNXSJxXI4PN5Yc/qI/hnCizQGIm0l93c9u8E65Z8gOsjcrnv4juVG9MvCJrZwM94auxGm0HmOak9KNeRtNs5ljk3gAKJGeEkBJJHXbRz2oTX6XuoQUnP3zZ8H+HL0rgiUDsCVVxYDXVoCJwD2WAtECm9aHsyAZ1PD227/5XzJnJGUbUbZV+RDg9Y2ge68e7sgV0T/4tft1DvFGO//FFnghaYAtiY/stl6RJsqRUNuipX/ES09NTa9ObJzzxcK1MW1dnqLDnb1hOPHM1YBVx6JoNi3UipiBHTyFNW4+MC9PLWTEQw== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=GfnDYDpc; dkim-atps=neutral; spf=pass (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4419-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=GfnDYDpc; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4419-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw4628Xlz4wc4 for ; Tue, 1 Oct 2024 21:01:42 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C90D91C23667 for ; Tue, 1 Oct 2024 11:01:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3B371C32E5; Tue, 1 Oct 2024 10:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GfnDYDpc" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E3EC1C2DCF; Tue, 1 Oct 2024 10:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780367; cv=none; b=b9sbVAcuV+WMnLmo+F39c3eJHHKkxiIiAex64oSGjcEEwyfOTtaDfwpftg0l9UzlDphx77nrQV56+rnhI3dajHHK2zjoJGeQXSKiQ5ljZSdW3jsGPok0vydpB2314/Ce7QeSRofd8v6elJxHJYRPzvxRs/ZKGlSlp7sS5+khDsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780367; c=relaxed/simple; bh=bnxqTLrbNZyT1g0NvyIT2ylk9FHviHzTCIeX6Q+a9Tw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p/mUf7jyGHlmRrVEIbWD9KIGxqnZ5qLoX0KH9QvkY2VoR2YCfNoGr/RUs9dH0HEwfkPXuhD+ZLbPTbYogFA0Xinfe7s1jJje/320DMx5iPOauTOT5JzzlnpwDyIEj6s/XdfZo9ohC5srn6SZbUx1ffzk1NzMwkEEB6qBIo2pdPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GfnDYDpc; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=B5NsA4Y3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=txgl=q5=vger.kernel.org=linux-ext4+bounces-4420-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw4c6BRFz1xsc for ; Tue, 1 Oct 2024 21:02:08 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw4c2sRmz4wyk for ; Tue, 1 Oct 2024 21:02:08 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw4c2qN4z4x04; Tue, 1 Oct 2024 21:02:08 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:40f1:3f00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780528; cv=pass; b=XESzNj5ua8KlCEIGITnze3r5G+cZv2oUkqS+PskuUEgOKL94oV6OrlyVYVhMzpZpz1mc1GaCizQAAjdsX/dvYyOQorVYP1DkXgWvWNBzjErmPdMhuNSN26MBfBYxR03lpJ+5aBCyd0WSyfb24TkxS2G1bGnRJElrQtsc4WjF7sOA3lcsphalwfx1KBk3lwhc4GI64S9sCwtngVKf1lunhzQvRidfQkE6N2ZK405e48VYO8adABRLoRiB9Q3kjC2n490Vm5efejCfrbPM5g9hZfrre1xb1vC/Bt0NzvnZ32n+6CqdIDPyEaXRLG/JsutJoP8/zUz91d4/tKh2B9AWAA== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780528; c=relaxed/relaxed; bh=j23ea2oSLHwO3VCXd7879q5pR6SW3LD6xwMWmsgaaeA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f6cjH5A/ENjm+huI0Pgx8aIVcAUeMPz0VFmkHV7VEPtAtAUzu5sZy9hY3o/CF7CoDX/XAlLpYXrxDC+jn81rsl4VGhcOvIfnzK6pAC4/3Y37hHFnNP8qFM0aJKws+oSihueYHFeyYKY4bra6LvZmgNj6KmxfF9s2HcpvbsoNwFaxUqwUCCwKZ1i1wzRSAhhuZvL2csuYSy7024JIRp1hN59F7Z5kFD76hrrIT6nd6VPYpZk5ZvSmGuy5oyh0cxW0ss4cbBxeK0p19G91fk+9YhmMa654QXiMFrp09Uk5SLs5cikUyvqN+QPAOKP4Cvl7f7YSnyFMH2HnqGOwPkhP5w== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=B5NsA4Y3; dkim-atps=neutral; spf=pass (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4420-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=B5NsA4Y3; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4420-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw4c2bXDz4wyk for ; Tue, 1 Oct 2024 21:02:08 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C2565B2354E for ; Tue, 1 Oct 2024 11:02:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86EEC1C3F0A; Tue, 1 Oct 2024 10:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B5NsA4Y3" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C11A1C3317; Tue, 1 Oct 2024 10:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780370; cv=none; b=ExMjlUlUxzfG1jPrv6mzfns9I656UsbsSRXSN7PgBFZsyVCV7qmuRLIn4bH7viuie3mV1obJUMrWpgwYTsmTFUiXBYQBnsBKj7k81H+2S8qydBOcekCFUiRfQpgUI1JFvTTYcBxoy9UMfjdGm2pfYHIL/fNGD6fMwevM0uCvris= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780370; c=relaxed/simple; bh=JL2gW+C3kDxbRAGj0jMp5iB8JHuDuhS4rvTtieX78oY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ot923FjRpnISbqovd3kLNtvs99pFAu1P9MkIozcdVJBKleMgI4/yMrsKRAdsY6Kzgo14ZGLryZB0Bz6i1pxMI3w7hvhoCM4iq1twvupIDFUw0vhUsZLyhW2EvKwFaoazEaeTb5iunKR+8rYAB2tvFToQBCwttOL76s9pl1SriWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B5NsA4Y3; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=SqvM7UQu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=jbgb=q5=vger.kernel.org=linux-ext4+bounces-4421-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw5354Sjz1xsc for ; Tue, 1 Oct 2024 21:02:31 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw530KRnz4wc4 for ; Tue, 1 Oct 2024 21:02:31 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw530HPwz4wyk; Tue, 1 Oct 2024 21:02:31 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45d1:ec00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780551; cv=pass; b=bwDBLQQb9dqwbjZJvCQQHG0yzjM/NF79YW8W+2rAN14wTpMvACLCJMpSKq9ns556yZITaGi5upJ5KN7EHR0OOOeurLroFkWTg1GJT+sFuQyKynIRT4HMPZ2BKGxMFb/WZXov4H6ZgXCYvrxsB6KZ47hkW3xQCapcR/3hHP2o/LLLHasjpa3bs6dnouTFAKi+SuodFnw02liqoeHji4El4Muk4sCDYt3IDyAe58mhNmlRrGiZlt5U4iqu9c+PC4M2mcwuiTQX2iEiAU0inpAzdABBr+JGyMnPvEHjgP6xsCjCdegOUzIQsIHTtGTX2CZ8lgDLD1XEu3Qy5yYaO6Ddog== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780551; c=relaxed/relaxed; bh=Eywsbia8P2KWlMj0rzkujwaUsbnR4BE6MJvg0/1qMj4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dwak5uDSdCI9A7BSye4jjx5F5KjjOwCWrZgcDeV0TVhflFX3IYkYeaqwtYulRDonAGjXK+4rDIyTZBiFYWcJgZasNPyD+rzwuSzX1Z2IQTMNUmRB7DQKonjLCi6upm3pOymyCOSxmxcFBqfkDKCQYqsf8kGREhOBWGOL+E6+WjpI3BqhnlhPYvisWIDMGVxXp5kwIWpuD2Za3rxefVldSIzmoDAhEL96g3xHxiU/9fqWQqqquP0eefQP9JfWqD0iNS0EQAMNXj4ERyrYy1ZuhAKg78MUt/kr76Lrpzdy9t9ROn4h2haYEnlysvYN3UuQtJYo+dRo3NxFQLY59lZ0oQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=SqvM7UQu; dkim-atps=neutral; spf=pass (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4421-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=SqvM7UQu; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4421-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw5248pCz4wc4 for ; Tue, 1 Oct 2024 21:02:30 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 19EF31C2208E for ; Tue, 1 Oct 2024 11:02:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 499FB1C4605; Tue, 1 Oct 2024 10:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SqvM7UQu" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5FA71C3F36; Tue, 1 Oct 2024 10:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780373; cv=none; b=lsS+IM5A+UU5YlUxJ7URmdaiKr1mJyuICssVjEn4vKLemVkTdHzN2ItqyKmtPFWiGHICzqQZZcXdUuV0VoZv8At2phcFJDbkJVHiCyd//0D43p4INm8a7ofxQGvD1TgjWA7T4djFr0lob+TyIEH+WEJOrWgMd73s8mvemzL+2CE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780373; c=relaxed/simple; bh=oPKJkohv3641xKtdl6Qbhb+FHGtw/eR+Am0SFNCb7W8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ekbVaxs8EjkDe/AZQO3Xjm1D3rNOuOhXg9HX/nnqzL/cgva0k4+0s98O1ha+6cTfQ68VMuuAdph3/jiRNhaQjuTs8KShkbTbdJLL5Fo/YkVLjvg2sRnn8a7OgC9D11jH1oO1wdkyZVt6J2wbUm1M+Cxwet8hi48Mw295ct0PezY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SqvM7UQu; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=OBF7R15b; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=3iul=q5=vger.kernel.org=linux-ext4+bounces-4422-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw5T0Y7jz1xsc for ; Tue, 1 Oct 2024 21:02:53 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw5S4GwTz4wyk for ; Tue, 1 Oct 2024 21:02:52 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw5S49MVz4x04; Tue, 1 Oct 2024 21:02:52 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=139.178.88.99 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780572; cv=pass; b=G23a8qgBMPNvw8YZPwr91v99CADw+ua2dwkUAqZj68/j4/pkTMvXBJwGmZLjuQ22j5lXdnT3zwRz5G1e8anKW2Xgjly/a5+PY+MluQEr1G8pX3ifrGF93mGBD8RK97h+ZwgjG+mtMsHoVWsugifqmuObCXysDbzVP1BtcyEdqRJn+t2MlmxNwZOJXxuIuDewopUHGHy/xuPqfamXiiI78wCNtRYj3Nm8IL1weNGFMPBJ+PdM9kVRaDUUTsbM12C+n9uaGTxOZhIPoWDj5hw/muhofFrM+0PCFRSLKF/YZRC88Iqfrq8xUwmTJAgAGY8IXEW9VIK6HAWoGK3gos0h2Q== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780572; c=relaxed/relaxed; bh=cckz3p8HeZ7XKfyqcYCtDgyKzu4arTXpHRZYzAXxYAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LGcIUDC30iOBQlQX7ynLXOQOxALK1jERrFv3Abn3AsuRf/Sy0z2a/VbKKlxMjU/wbPt1Wy8TJVGmKo/7lBob/9eUis45f+0GABkFRa0KO4R7KTjKK8PW/0i4UVb4nxxNqiuIBSEs+4nViXqgvwo67sttAY3ml6nnJjPnTzIuaJiPkJeom3o+rsHCM2Cd1J9qhIrY5FMD4XfphJzErXtBx4hrUbUbJXnr6yS7c41sqPcGrJWRO2ObZ4ISSEX5Ui2Lk9YA3ev6Mbbmbr4brtH9JyXraK2i9P9hHx2XLSEJu+yepW9rWWrSt60k1bQceesn2pnDWKoTHz2aKK03tMbcBw== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=OBF7R15b; dkim-atps=neutral; spf=pass (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4422-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=OBF7R15b; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4422-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw5S1wCqz4wyk for ; Tue, 1 Oct 2024 21:02:52 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6F6A1284B4B for ; Tue, 1 Oct 2024 11:02:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1EC51C5784; Tue, 1 Oct 2024 10:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OBF7R15b" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B2CA1BF7E8; Tue, 1 Oct 2024 10:59:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780375; cv=none; b=XIKf+bMKTBh55HTLJtkf4WbW6lg6+yu3JhHKDjby8hXhKztbV0FlWPo7qmu695PyUCmNK+3W0ACzfoBQxlWiIF8z5BJPo+9gohjYfqNwSIWkpoiV6WG/lW8D4UhHyaBz3nwtH2tiV/G2sMAyetwgspYF8EIkyyhJGWT77AWpLEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780375; c=relaxed/simple; bh=m2lMTjAgLXYxRt3GuKTCEjdRkZam4zPki2ETeaDm/ao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DzXwvhop4YW5LCCwwC3OBPjpr0gsH65MLx+V2psYI04mWnYBZDz21QbSRG5OpxM4a9rQmqDXtNMrKnQRKmLt8Bf6V/P1QFE3dHZd1/14kqRURfbldL4pmSGBqDZEQOzV8C8cnX51zR3oEYOcqUh5NwcGN7YWExfIucY1CQlwidM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OBF7R15b; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=LcPTEgr3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=pn2v=q5=vger.kernel.org=linux-ext4+bounces-4423-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw5y0tf8z1xsc for ; Tue, 1 Oct 2024 21:03:18 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw5x4csJz4wc4 for ; Tue, 1 Oct 2024 21:03:17 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw5x4Zjwz4wyk; Tue, 1 Oct 2024 21:03:17 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=139.178.88.99 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780597; cv=pass; b=p0d17Gx+0may25dtDEv+6Ox41F5GTcLeDSD0OU9i8Ljq3oa3TyBUEb3n14UEpRb7Iz6CPUxGATnrAs+KZIriPd6OJ6oGSigM8RTXFKqumZu82sWhUJp8ngeAn+2pQzWHZ5PNULVNeiGkYj1uC+lgl+tecEE0LDafgTHJ08qjdqw8dKl/AaE0tXKEMFm9PWpIs2xWuszage3WgK4VGxhr5FxMDYUHbEYbFY3rwhj9Tx1asJjeIL3k2/6DIUBYDp6fuTgkukAr6isizU9iMCAFDAjhbXVat3lpHgEDeGv60Nvjo6JZoyokr3ayWxDXGz+u4ersTlDfFn4hP5xU5kP4hQ== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780597; c=relaxed/relaxed; bh=N9AzcHyO+ing2lEAJs/wavmYhF3E8INEAc/fntEREVE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UXo5hl3ptKEFVVTPWZ+y9+/5HXZGsFxenvb5HyuuuhSBTV/pYtyvLncOOxOxntGbqbZHfeEZhqaYQpWcbbdbWhSE2K2awUWUy+ucC3ejcz48VSLywsRwZ2mfkHnHxqAg9jskMnjO46QO2NxUdiBO1Hk5VL8TbvTBGo1M5avz4VCank1smG23LP9gPKHeayJgT10jb99oDkOHMDOojlwfKmZjMBPJ30u4kKRmddIIIQ02IsWktXzHV4II7R+9gLYckelFwcxHwWWzE1Xb2wiE+sXDgDCLn94PHPdIg+Ihaew/3QOYbgG5qA7cPCCHsEe+sJRJ2LKthScAEjtZPCns4A== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=LcPTEgr3; dkim-atps=neutral; spf=pass (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4423-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=LcPTEgr3; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4423-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw5x2K32z4wc4 for ; Tue, 1 Oct 2024 21:03:17 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 771C0284368 for ; Tue, 1 Oct 2024 11:03:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAF161C6882; Tue, 1 Oct 2024 10:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LcPTEgr3" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75A761C57B3; Tue, 1 Oct 2024 10:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780378; cv=none; b=T+slMO0OfyeHYTwOrVcNNQYOmbPcXV34xegCMT2hmpZX6DnVM2sIuBniTi5Ovqr/o106yxu42OeUu3litBhi49klEzIrkGDAg8cw3edGW0oXbV/ecCDv9kakH6Ix/Y/dk5DxSqQD132Pw9h3S31lb+PwH3xIj6DTAysNZX5teos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780378; c=relaxed/simple; bh=R1V1oQO/HR6pPYBHRjWPfl1W07s8BDOLPrB79M1Pup0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cR8nmEYPHz7Zg+HhG2OHGYNTjM/NVMkfxfzKCULcBWnUxFB2I0kEoln5NXn6xO8wKGWRMF6w07dYNMLI+Cei1EPFf1PD3wTbN68et4qdwpIyYue9w2Xa3xY3N9At4BeZeL9E5gCoX7e5q1DycHu+L3enF9mnneZ8OofMdV1u3tQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LcPTEgr3; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mgJN2Sog; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=pgbi=q5=vger.kernel.org=linux-ext4+bounces-4424-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw6j21rxz1xsc for ; Tue, 1 Oct 2024 21:03:57 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw6h5k5bz4wyk for ; Tue, 1 Oct 2024 21:03:56 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw6h5fr7z4x04; Tue, 1 Oct 2024 21:03:56 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45e3:2400::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780636; cv=pass; b=n9FOJfklZUM/iO6S01+ZvJIvSapesa5QoxQqYIhOf+WLxzJMD1GpGR+t/WeurMJ9IXDBSayiQiroS2SlIAfMQlUkT7M6N36J8SkiivxZTOqooN7OoTpeuYyk2CbIZDnEbon6WTn/+LbU71z5UR79qhI1nMbeO5n1zrfeDK7tVzkhLHALHJ1LZCi9NwsVLfZB5oq6/KugUTnm2xIk/LPVlnLhIZtdXsNm0GKviTDLLwVjtvwm5i/T7FYr1ORpLyJ4nBxkzH/lpPlgHN4Ia444axaxvCmDEyu7KhhEJgTDX3MvwJiULJFGGHg80r7roQKlKEg3i8aQvR22yIf4dhPVig== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780636; c=relaxed/relaxed; bh=8ZvBNRuRJBDYAMjjty7KQbL3GLtKr+olQlL3N78j8uc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=vYhC1H4ldXwnb9pKr9/uDKzUcqp1jBtjPQERJ1zAzisrTus6fk2hzEB618Jc7EPqfk21b61MRRru9JfHFkZgk+x8aGS25dVDctGrLADuEeACz5AvciDL6g0KBAvb3zzjrzY3cWM7fCDQq17H1t1Yx9GscEHXDb6QO16QlbmmkJ2Rvz6Ya050M5Gu09yNmA30WYRnhSNxwW0HiiOOnOia/LdQW8cY+VIYSMgXXVXn27q4sqi9zng/Iw/CBMvpFoHphLqDjnivzYjPDt3vGMhFEFWZRoV4NVsGNIlXC172AbdeO55aFTknN8M0+8dlFoxpQT5dSccHkEVgYOUfBkE8lw== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mgJN2Sog; dkim-atps=neutral; spf=pass (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4424-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mgJN2Sog; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4424-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw6h3Nscz4wyk for ; Tue, 1 Oct 2024 21:03:56 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C65A0285003 for ; Tue, 1 Oct 2024 11:03:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CF8B1C68BF; Tue, 1 Oct 2024 10:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mgJN2Sog" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 490C11C68AB; Tue, 1 Oct 2024 10:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780381; cv=none; b=BD+VSZHR9w6AWTe8eczeZNizztKmuwskL35W9qRkZSsAC0m61PU/Wed5q/ndkkFe8xW9nLHKmJ00AmIS+DApTcHnbENRWVrCaReZYx1B2Fj8VyFItbkq//Vwa3IVtbkdMHsL9uuC1l3TfdneXwLnj0tg+UdSYXJeo4v/nsybWxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780381; c=relaxed/simple; bh=UttJGln3RsYeF35AMrr2wmS/hNsiLcUiITLEJHfz5Ms=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eLi9io4Z11PmE48Pzx80eSTn1MxDNVBRiwnNmnnembvyBuRzKY7VzfjQ1DOBbmUIl6ljEQXYMZ1SHxvCdcUZavmNNjtqRNTv8yFxBGQn52bOjUtD4++uocHyxxaPDcTguYSmcVg6UGP/FpBo8eREJKRVojCPZ9W6O+oO26C70fg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mgJN2Sog; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 1991413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=NqhWoLr2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=q4vf=q5=vger.kernel.org=linux-ext4+bounces-4425-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHw6v6fhdz1xsc for ; Tue, 1 Oct 2024 21:04:07 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XHw6v3Hv8z4wbx for ; Tue, 1 Oct 2024 21:04:07 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4XHw6v3FjBz4wyk; Tue, 1 Oct 2024 21:04:07 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:4601:e00::3" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780647; cv=pass; b=O0n0hdSMPecrs03YzKtXnvlq8/1N56Tu1woBNkTOk2UiiZ7CfaRvJVjQ1gbmXgljpP6N50EA36uRl23bAFIiRH+9upgMSJeT1ePT5PjMfBy32mArbH8h3rhMmyFsNhPL/WzzjZk8kA0Ou6YcIf8hj079ZP7yk7ei7A3vaTGLjJDJ2vZDobUigMYMSSXPBB2OsmwKGoqH+iFvPQP26z9qNhj+qcVr0iqp9datU1gwLxIazVdyEMibAF/FOxAtP07WgRcJ7bfO57rx0mvtRiDVXdblovlSCRkZrbI218VmJAkfBftAOMS4wqZiOhr6MxdSDgIochr/dmGyIkdVzokTdQ== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1727780647; c=relaxed/relaxed; bh=bolnu2yY5sQqpVHirE/5F0yWEoEqV6NQcoUQqtDYtX4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MaNP/dy5JbRQZIwamcUlQNtkgY4vYkbTWMaZnsMRo6lDRe4wbxntDY8W7OKsPZ67IrFVIWV8UKVdz8Ji2DV3iUsduVQgqIkadQPTG4KEqAn/xHm+vkMJ5PHFnvkbDihSYm3aoGBvYCEYiLvefmh0QmWEgks6lNTsqAF+l1b697cY/CRZ+NT0eIqIQaHBRoRQcjUj2rV0uHMKEQyADUmD+sZkPZL5mD9m19NAoIINhLSexMhMinPlAx0ffg9J49l07bGFZMNUc18fkzKNcN5c+yE3I8LG0rG/feun+p1EVc+RjYbm+UVo6XQwgAJbdYN86DzutyEqeitWe89OGXuy4g== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=NqhWoLr2; dkim-atps=neutral; spf=pass (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4425-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=NqhWoLr2; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4425-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XHw6t6jyNz4wbx for ; Tue, 1 Oct 2024 21:04:06 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 44E241F23911 for ; Tue, 1 Oct 2024 11:04:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 534621C6F75; Tue, 1 Oct 2024 10:59:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NqhWoLr2" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1261C6F67; Tue, 1 Oct 2024 10:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780384; cv=none; b=m+P57GVxJiFloHxOHVYSQ1ZLjE/EM7aJqLSZpSYqztZDoidSCS95Zq002Rq0nEzbMz1Yb5g0wpcTNNV2JFaTS63p6eqqd/zpsMBEWKpcfKXyK65uAiHcU3yIOuYYJo0/3UaDDHQPKruAxrC44j/ydlyZme69201ooG3jqPZoRRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727780384; c=relaxed/simple; bh=vfABgeY7uP8db917PbV1dpj3MLFQbmpQZkOBbve6x6s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DPH6kTSvf8NXNPmlagRC+plNrs0Msnr7RRSPv1ogFMuUDKfIcunSdMeqb+tCx//3J7N0oe4plvBfFnmqqXhWujG2lYTBYz7071JZ96PgOPbUZMK/elm/oxtIgXcifuJYW5BdDvpRYc5NyPmrBbBHIDOvePyMmLp3SGCidwo5e2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NqhWoLr2; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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)