From patchwork Wed Oct 2 18:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC85BCEACF3 for ; Wed, 2 Oct 2024 18:49:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34EB36B03F1; Wed, 2 Oct 2024 14:49:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D7DA6B03F4; Wed, 2 Oct 2024 14:49:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 133F46B03F2; Wed, 2 Oct 2024 14:49:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DFDAD6B03EF for ; Wed, 2 Oct 2024 14:49:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 77BBF140E4E for ; Wed, 2 Oct 2024 18:49:58 +0000 (UTC) X-FDA: 82629551676.19.638CE2D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 9555A8000D for ; Wed, 2 Oct 2024 18:49:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uN0sJaVl; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894868; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Upwg8W4cyXxm7qUMOJMyms1ud/EeyzuU503+GvI891Q=; b=my5BDNv3BliYiZKE8uU4c//lBYAqjH/cJzhJXLb7FCX3QNwbcTkC7rSm12o0J5Yznan+qW itx44WvUJJqwxe40ZQ8sUn7skoZy7AB5wYkr/3+egwAH4twJ666HyCRbaxyuYRyYG+HNko NHvukFQJMahqhR22rwAlnys0ItgLKrM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894868; a=rsa-sha256; cv=none; b=xqWh/z5/2eoVNdU+7Owyjb/aXshziXJNNpa/MF+Zzsgahm1WX/94eJnl+nsOdsEUG0WyO4 6NT1bOJguXHUY5j1VBB5pkjTuHZxJA+1WIHk0LhkApFTikSyVjXj4d9yZ6bkJsL4TGpwPy igRc1wiHk6WU9fGo0VzRvLxSZIS/GSc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=uN0sJaVl; spf=pass (imf30.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6E8905C4776; Wed, 2 Oct 2024 18:49:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1446C4CED2; Wed, 2 Oct 2024 18:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727894995; bh=ZOcmZO63qqHuL49Q+t9atBGcog/gC5EgLjrW/PMakhg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uN0sJaVlfkQDIlYofwaD1U0q+EIAc7u2fVKHmnmjEfj92zz2uvvaoKgzFRGtxqvHE ngjX5Q2kMODaiuzV9ya0CP74hoGpOWAkqSHGo8xGiQXtQhA8iMbgNYXC2fSA7+dUCS GjtWEXxhxNI2F9Vp4KPydMSj6jjFlm0VB0Hc6k6pLuyOGL+Jt/b1M6pdTOsd5AfyoB qCVI5M3Y0DRKXeE3VjRv2gfSCvH/OzcyiPAZ9XikVGWE43qvPOnC20u+LpyMcObJ5Y t/osnFhQHp6KanTgj9zQI1sqYs8b9598Q7tvQYGcA3gKc4zwto2NrRXFDcvSDT4gY4 BgjQP0iYSkY1g== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:29 -0400 Subject: [PATCH v9 01/12] timekeeping: add interfaces for handling timestamps with a floor value MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-1-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=7732; i=jlayton@kernel.org; h=from:subject:message-id; bh=ZOcmZO63qqHuL49Q+t9atBGcog/gC5EgLjrW/PMakhg=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXLTPbkQuW/qHxBC62nEmw/Kj2s5ttrIMx/q DY9Rq2hBxOJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VywAKCRAADmhBGVaC FdWkD/4qrF64NTL4UYAUHVTQ8gfFjxTRWZZnZiRwhOCVc0OpZYzPPhPhb+JPdpphxl7KYsx+toY iEhzApUIKOdyxqcAIk3p3lfUvGlVnwkoyqHiyy5mvuoTXCuohIvqbjacF+SkQkfK9ZB/g9L7SzZ BhnZjbgybiu2eEQ+jOhBhrRraZZKZNjxcR7vT/LO+yzI2sbQFXFleaOSN72+TQXxy2ACjFsVKqV 3q7vs3Y8jGEBEP/of8s8oQUlUNTStDC0OY/i4M62Mva3koA3pjaOEdV275dWUJ48T6f17KarVhw XXFxMvPRkRzghabHy07G8tlUKGw77y+eBasurhUE71c9Bt4mN4aI5M9oXoIVEiiRHPP/eXyE9ly hhPiYVlvbYY/FqPo+rWYoB2YMFLtgO0xIfI5ZSGg9HLaOsWfTUgVEWrE7jAFSQhPd7XllhWK2mp wqxo2IcSNQTclQfksz/ieeoA35LzW8TRhv2TlWr0BUS+/P3o99T5KYdB320XBRV4g6OfGnmL4Ue HzMwo+jWZiS3APwRVflnmQdpk/+Xn9OWfrfG9DypzHYNoVf2urjwN0Jtc8qljEFTgRavqCQpS57 zMJBVYphAH9ob0az2H3zEHEOwKhwu3Rxa31hvz41pFnDdyyvB8pJzB8/qTLVO8AP6v3eNZESL6B shjOHWhNJIp/QSw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9555A8000D X-Stat-Signature: 6ca3gheu6wrtrscs4xoomeu9yopdcwmz X-HE-Tag: 1727894996-720986 X-HE-Meta: U2FsdGVkX1+bYqLP8hQObuzyOXEttQUvK6XSsVinzRKQPLzP+HtLlNzC3TGgF6N6fB2Enk73Ek9ie462PXNA2Ve3AQmEiY9/wyDkH5A5upicE1cjbJ+i36n0UXLTUniwcoymXJIu8A2rXyOSIIzo83Gfric1g1d7uGgdu99yDZ7ObJfi57xTUEZbuX8Ug5BWfaxxhVDje99d3OEVhEZK2uUrwmnq12avBb4htSqwzabFc+N2J1KcutaUsMaT7nQ4oxXbjH+8XoSP+i3fG0V17MLWL9zYP0Cv+zkGrLfckq69vq590xn8lKocYeOLEP6J0wMbsIv11wLF1iuwcTVv9s5tuoGQl+t9hsHd6riYrIQeExftQa1bhkD+BuIfDtHtLJMDauHqmqt6+3pDBKEAt3dvarM0L15pCQ+jQfJsF3k9TSKoyQRy/wCMHvPzEBRaQrDSplK41/NlvjBwJ62NaN47Y2dA/SQwwUaS4PIu86zF/RekfM5VLXBhNYo5HNAIlUarJ6iOk6UcCnxcQHiemTB6NEa4V6I61Z0Z/do+u/haHreBaSXQkfg2947ezMsMO9Bp89EEzVy+OaMG0C//qFhV/Njug3uTA/bxankY7Aq3uNenq/MXOUkOxI5G1h8kGI/EpTnrwwSzXOaM4yJMGwNIj/HbqDPqS/dA0n1PyYNv45iG8erM/DeOrdqwbvF8zUJIfIz09zk3bjvuXMiHeWYYnQ8Juy3AWCs9Jube1t4xAvLdolk3A+2ubNkHbUAzWMUe3tmOIS+O3mUEXUCXsfnd7w5y+Vj1fY1aj4uSjErr6I2Mv9NOcDaIrjlVEtVEe/0bgwS/Z/uIOSSyDTA5zhhryNCZKNfrz2mikESc83NkXYOXaYbG3dXhuGvTbPmDeGed+tgWjn3EMRzysMndw3OCXRQ2akMpfPsSMve/Ls0joRk6yzjlAsdT9RNTcnTvcjo1VU4B54hw2YryvlH LdGgXIZZ RWp9nL2D44KpJSwGx0AM4MIeknbj03MyWgkwFxjLcdBtNew+8XpjK6ogVA1csDxN7Vi/0jwIMI0zkvd2nGX6x1REDdkMZ9YaDbbOsVeHvbGXX1eo0EgObwFtgrcqTNs4ebarnEKxFjSGIFUVKiqVSd9Pj/jDPxU2ae4zYcXU0GAOfUPMs7F10xJqMyhVZbHRMKbsqfR97eEBm4NgwJEDWjBe5R1S9P5OLi0sIi1Bd52GOX7TrCgTkizA+28odn5p89lHIrr+PYN5SIyVHj3hK+UR0x6KnYTjJkQ2B6JKNQR6k+bfs9t3iJt/NcakFdng64cGpalhYRaVg6jg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Multigrain timestamps allow the kernel to use fine-grained timestamps when an inode's attributes is being actively observed via ->getattr(). With this support, it's possible for a file to get a fine-grained timestamp, and another modified after it to get a coarse-grained stamp that is earlier than the fine-grained time. If this happens then the files can appear to have been modified in reverse order, which breaks VFS ordering guarantees [1]. To prevent this, maintain a floor value for multigrain timestamps. Whenever a fine-grained timestamp is handed out, record it, and when later 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 is used 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. Add 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. The floor value is global and updated via a single try_cmpxchg(). If that fails then the operation raced with a concurrent update. Any concurrent update must be later than the existing floor value, so any racing tasks can accept any resulting floor value without retrying. [1]: POSIX requires that files be stamped with realtime clock values, and makes no provision for dealing with backward clock jumps. If a backward realtime clock jump occurs, then files can appear to have been modified in reverse order. Tested-by: Randy Dunlap # documentation bits Acked-by: John Stultz Signed-off-by: Jeff Layton --- include/linux/timekeeping.h | 4 ++ kernel/time/timekeeping.c | 105 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 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 5391e4167d60..ebfe846ebde3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -114,6 +114,24 @@ static struct tk_fast tk_fast_raw ____cacheline_aligned = { .base[1] = FAST_TK_INIT, }; +/* + * Multigrain timestamps require tracking the latest fine-grained timestamp + * that has been issued, and never returning a coarse-grained timestamp that is + * earlier than that value. + * + * mg_floor represents the latest fine-grained time that has been handed out as + * a file timestamp on the system. This is tracked as a monotonic ktime_t, and + * converted to a realtime clock value on an as-needed basis. + * + * Maintaining mg_floor ensures the multigrain interfaces never issue a + * timestamp earlier than one that has been previously issued. + * + * The exception to this rule is when there is a backward realtime clock jump. If + * such an event occurs, a timestamp can appear to be earlier than a previous one. + */ + +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 +2412,93 @@ 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); +} + +/** + * 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 + * mg_floor. If that succeeds then accept the new floor value. If it fails + * then another task raced in during the interim time and updated the floor. + * Since any update to the floor must be later than the previous floor, + * either outcome is acceptable. + * + * Typically this will be called after calling ktime_get_coarse_real_ts64_mg(), + * and determining that the resulting coarse-grained timestamp did not effect + * a change in the ctime. Any more recent floor value would effect a change to + * the ctime, so there is no need to retry the atomic64_try_cmpxchg() on failure. + * + * @ts will be filled with the latest floor value, regardless of the outcome of + * the cmpxchg. 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. As any + * update must be later then the existing floor, and would effect + * a change to the ctime from the perspective of the current task, + * 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 { + /* + * Another task changed mg_floor since "old" was fetched. + * "old" has been updated with the latest value of "mg_floor". + * That value is newer than the previous floor value, which + * is enough to effect a change to the ctime. Accept it. + */ + *ts = ktime_to_timespec64(ktime_add(old, offset)); + } +} + void ktime_get_coarse_ts64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; From patchwork Wed Oct 2 18:49:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CB98CEACF3 for ; Wed, 2 Oct 2024 18:50:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFE424401C8; Wed, 2 Oct 2024 14:50:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAF354401B5; Wed, 2 Oct 2024 14:50:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A02EA4401C8; Wed, 2 Oct 2024 14:50:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6D9CC4401B5 for ; Wed, 2 Oct 2024 14:50:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B443DC0E7A for ; Wed, 2 Oct 2024 18:50:02 +0000 (UTC) X-FDA: 82629551844.05.67B23B7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf04.hostedemail.com (Postfix) with ESMTP id ECDEE40012 for ; Wed, 2 Oct 2024 18:49:59 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iELSDJpT; spf=pass (imf04.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894829; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EAwD0uRlnn0xgT0nc2go2NDFad9ZqMytYxmnawQNvW4=; b=PcJijLNHP49+q+ZCohjM3pIDmNWLSipA+KcXP5SQt/ReLBQQ5ZKplTTJG+y7yVlhHfGe1/ ktiWgVtY3dQ/j6HLOFVaCsaiI/dP0Y94FHrlkd3DFL1MY0Jc7ZcoCTyNv9ebsmLxojcqdJ b9hetYbBaeb6mJgKyel+tb3vQbKU6A4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iELSDJpT; spf=pass (imf04.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894829; a=rsa-sha256; cv=none; b=xiqM4NVtOkL8kSDJEPLE/P5RKTPzFwGKXPxLhhV1XgHkuz8uY45USIFYZlYK+apT/1n6lR klJ2ol5B8yRc24CF41yzVv8LA1xkYJJjEn77pePK32Bkd5EaXB06KeV7wrWkRXjGMXwOIT R01kf/Lsc5UrpqFW910MRhZ6TlS0b78= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 140E8A427CA; Wed, 2 Oct 2024 18:49:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85498C4CED3; Wed, 2 Oct 2024 18:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727894998; bh=lWIeTtPiI+ai6qKZudnjNZrxKOAsE771WcfrcaA6eA8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iELSDJpTc38MeEvbtdl0OEwL5LvjWHdrYtI745f7k+JXAdmWTmsxrHr5hKXyok1RF wga5wjJHQI32nCM/7NZ2ispr34lXDRw1sUix05NzEahfxdKxQPUGT0z1p23swc0tEQ olLV9uBSYc1x1qA1kB2Pys5a2icT4FVmZXY8IIZVdbmcRQq5UYHNk1lbubMxStHc6y qMAt+5njhyLEDY6iONNK7Sif2lZAQILkPAlcHwbDlRNzHj3ZMx87TdfYbzGuwjkjQ6 o+GhIcCf8eZrv+NYVTQVwG60vX1cCiahkA2+GpRTirkguohjDff91V31QGhyzm1HZP b0qRmI34RcXHw== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:30 -0400 Subject: [PATCH v9 02/12] fs: add infrastructure for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-2-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=13570; i=jlayton@kernel.org; h=from:subject:message-id; bh=lWIeTtPiI+ai6qKZudnjNZrxKOAsE771WcfrcaA6eA8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXL/47kzw0EDS05DGJsTs28j/X5WO+L1olmN G6MLBUypBmJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VywAKCRAADmhBGVaC FY8sEADAyOjzBxqMnCAy2kT/rpD8kGgBDEcNMxvkbaIDu7fqC95/2KJPMkV1cDVIuBVIPrOjUtA VDbJLgGkLMO466oEkCLtFdCNrY9fpL1RpOQOAk2Cg2+HQgPEVNqisV65UMz6CZD3OIOKd3qoUQy 4vqisKxk7Z9oxi4wW6mrV4lsUJBskJgzNjaA8yHWTjsQTxLlG+UkfcY7dhvQf/o9EvTzPpBu107 pf6F7SGEAOQHBp0IBWnJQ6MZ84PLfTxaNzR8Gne8kQgDcTs/kBtaiv9C2zuMIGsDdtqiJVeYG2n 2fuSVtaSCjclrfjGVAQbkwNyPYgL2j4CYhrqCo8y29WXniF/j8MWRUxMfIZSw+VlkvGv3/Gxux0 pSiFMaARqdjpOBRUTEeDHtoC1stA7Dt6X7n2yHeBiy/GCF5bXk5FIcQ57Ai+d9z66FtXCauGK51 BMFEO/41B5L3Y4+nKhpE6rQ9MlRhwGew5Hed2C4zeDpFU06Od7yaSCsAFYszkTAwxa8ELPn5osx iHMIrlfs79Scv1OI7GA+bX3kg+EFFAX7UTODmG364vjLvTN6tEXJDGZJfnaCojs7Xrw69oJe+PZ FMqcq7AAFgY0Bfvx4OXsO37lbKUHz1WQ+0WHLlUUBYxIjay8FCHokK7i01zTXoDfOOWX/49JaKu 43nXChnM6wpquaw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: ECDEE40012 X-Stat-Signature: xwb6gtszh5q3yqw9x95dmd4oueh18mbx X-Rspam-User: X-HE-Tag: 1727894999-541122 X-HE-Meta: U2FsdGVkX19PiHuXVvDVaLTPERqb6PkIAzu9nc803DHB8gK1nL63YJlkEWNn6v4irRSpUjbVRtkGrU1QPWCk43s+ppq2zX9mr+/7vmWP6Cc2tPAKcSpXWH6pRWyv3prvPmHabi4jOzMYccWCgV/Pui0KlUskdi+4sD+d8rR02H4SW1UiMnaLnWg3+eFBEdUMPhunsCn63N5lrNAJNUaXOJVutu7yxpx8lLyE23m0DII2BVfwrH8jTKP3lgv0bTKUhi6b8Jzfh0i6qMZFE+uVqI1q6qWtscDXQtm4iJETXBVvxPFZPCB4TCuS1rz+bZFKf3nVzOYFw3DZS+36HiZHQ3oJPSwf3QBsSoYEmsUuKATrLOoKYlrtDWrn919Rq2YA/A5omi89k8pWVHhh6ODCmOkTyas69VMIzQmx9oWl3GT0+YYr/boeBTDp4cUm0cHlYty0L1ai0RCrabJQB0Uu0pLh89ejzZ4YLOXiATA/6B1sRnXQLkahx7agAlo0InMviTY/B/ouIT1XndP8MdgG81kuw72yAA5YXHApscuaMviE+QrSae+Vc1o1BEKjvM19yfCnJc54681iNy9U/tcG6+s1yxoRyfwDMT/RyUec8Wa86ffudCpiOa+valFXrjPim+ytdjrvGxg9w5nlWT7pcmSYelVHRBpNWU5mgWHCAl99cgDKbtpSLSa+iUpbwmGt2LRuZLiQMnPWckwVqnPtdYih6oB5yZbIGYxQKEADp3uLyj505LuartahZD//7/kW9lcB1OeSLgeO+yE1dM4BMua5kEXhlFUlE6TbaF98CliBvHmwRZ4GOo9ZGfy+pwvUXYixF95I8uW6zi88yOhD+a7XwxG2+s5jczCEdFH8eVCzwNQl4yStYGJ4V1Tz0G2IWkZf+grm/4jREfQY6HEiApRBFvYrdelHOb/pf5vaQhu7PGMzcsKUPjDIdGKhVex8obBlNXnLjbCf07pHEdd rO5h7Jdm 0lRcGOTvm8de+xnSq+9f8/9kA2zUjWbvE9CLDPizug0z+ff0yaEC5/Km/1yirEBx6OvNoCmeI5ZdUrTnoEJuOMBJHyfk7/qSu83uDHHESwaJ5yh6il08Eupxkj5iVC4Px8PwuRTbInX7CJNZ17qF9T1jaX/CRfQthliACBPPYhWWEPxCf7GaG76WSPGl1F1PPhAWMikrekVxm0zluLiEBrL4QElTs+P062aU/cSjqh9jCLZGKkCAC/6xgBfNyKAtKk9vfW4N6a1R71e27W5UQKfSJwZAsMhKpEdXgoUPUOaUoSJu6thyTMuwJDw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The VFS has always used coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes. Unfortunately, this has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide when to invalidate the cache. Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problems with timestamp granularity. Other applications have similar issues with timestamps (e.g backup applications). If fine-grained timestamps were always used, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates. What is needed 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, allow the update to use a fine-grained timestamp iff it's necessary to make the ctime show a different value. If it has been queried, then first see whether the current coarse time is later than the existing ctime. If it is, accept that value. If it isn't, then get a fine-grained timestamp and attempt to stamp the inode ctime with that value. If that races with another concurrent stamp, then abandon the update and take the new value without retrying. 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 Reviewed-by: Jan Kara Signed-off-by: Jeff Layton --- fs/inode.c | 139 +++++++++++++++++++++++++++++++++++++++++++---------- fs/stat.c | 43 ++++++++++++++++- include/linux/fs.h | 34 ++++++++++--- 3 files changed, 181 insertions(+), 35 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 10c4619faeef..53f56f6e1ff2 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2172,19 +2172,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)) @@ -2562,6 +2601,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 @@ -2594,36 +2642,77 @@ 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 is already there. If so, then use that. Otherwise, get a + * fine-grained timestamp. + * + * After that, try to swap the new value into i_ctime_nsec. Accept the + * resulting ctime, regardless of the outcome of the swap. If it has + * already been replaced, then that timestamp is later than the earlier + * unacceptable one, and is thus acceptable. */ -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); + /* + * A fine-grained time is only needed if someone has queried + * for timestamps, 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 89ce1be56310..dd480bf51a2a 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -26,6 +26,39 @@ #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. + * + * NB: The QUERIED flag is tracked in the ctime, but we set it there even + * if only the mtime was requested, as that ensures that the next mtime + * change will be distinct. + */ +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 +91,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 6ca11e241a24..eff688e75f2f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1613,6 +1613,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; @@ -1620,7 +1631,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) @@ -1631,13 +1642,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 @@ -2500,6 +2505,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; @@ -2523,6 +2529,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)); @@ -3262,6 +3279,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 Wed Oct 2 18:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A195CF3189 for ; Wed, 2 Oct 2024 18:50:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BC476B01A6; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CE026B01FA; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54B236B01F2; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 146AF6B0167 for ; Wed, 2 Oct 2024 14:50:05 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B50F3120ED7 for ; Wed, 2 Oct 2024 18:50:04 +0000 (UTC) X-FDA: 82629551928.22.0B2FDE0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id DC58F1C0003 for ; Wed, 2 Oct 2024 18:50:01 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="b/usSVuS"; spf=pass (imf18.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894873; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cetM6DcUpL/i5MVkjPYtC/6TXnwcPmwMNQbZo+1PDmA=; b=zZJyi8EgJGa/9GegG7w5h87oIhwaJmERfFQ/AYItRIjbNTpvxVH2xHx7ASCzia5D/7wf58 nHPVSMXinIY7Amb5LNcR3nzgWeP2auEB3JlyQGaovNifaJX4C8GNG8d77rpIa1VV7kQvIQ nlBjGQ+spHl0delf6M8/gs2EzceLvqA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894873; a=rsa-sha256; cv=none; b=beK6I6J8cdbpeW2vrH5c9yl6wOh8W29g+mlC/nhdCHg96e9O1QQOPwHHleEQ3oWA9UmRB0 OHoe23pxET/v6Ff7wB2dXauLacDKy9FOX5ODLuTQhP8HdLKym4dBZZPWSeah2FJFwvDATw Q7V677XHKxHFFrxP2hVgO+MkLbHli+U= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="b/usSVuS"; spf=pass (imf18.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DB7045C3F98; Wed, 2 Oct 2024 18:49:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 493A0C4CED5; Wed, 2 Oct 2024 18:49:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895000; bh=lFYSNqHeRNdwWK/XmB3fXwkWmQ/Yur1I7QduAGtTJ+o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=b/usSVuScvrhwtxn3KQ3g8X7gxx+GLcKCda37HDaKPKadL7yvk4Qxq6H7ckAaZwnZ ybxJcUQK6FOY+03t4AL49mpKmpcBoZpKGCMNKYC+DAFlO0/9Co2eSvxg77BVwhF4F7 RqGep6DbLs92sxXLQgsQGQCheuqGJwPkgrMZZuHwGNm5HoaLqXomIdAm62ThqgDsWF litXVEKjtv1iuby+l0bSGF5LglapLW+nGjAkxKlGfHV3MV0RQ3JE2xopJQqnnzjF3Z hhtx3uNEUPqlJNsoitanLbQVTESccX/tuKGHFmiQzJGS3sNQbaWB2ZUcnlUiXXj5N6 pkkReY8oZEE+w== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:31 -0400 Subject: [PATCH v9 03/12] fs: have setattr_copy handle multigrain timestamps appropriately MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-3-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=3567; i=jlayton@kernel.org; h=from:subject:message-id; bh=lFYSNqHeRNdwWK/XmB3fXwkWmQ/Yur1I7QduAGtTJ+o=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXLyz50rdlWAisS9Rf+dtjs/DFcV4kQkosAS gsaH3DiB1eJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VywAKCRAADmhBGVaC FdnyD/0T67VbA87szAGb/s1YdZ5BTkf8gOF2Numd/G9SJyW8QcFJ6/yvfLD4bdsK4CpgmSinn/M krQHTiP3fLpmQLCFa41sT/mzaXSvPE9nTGuhJcM0UDjUJ1U5Tho484hKLCp+80b1o6WaSytN9DA LeLu3X35R/BoMq58P3wpvEqZC7nMtUH4WdC0uD6wjBxZG4VjTqIBh3+ur5DefXYKFYvRFpLIRmN FjVHQ/1vkuteTVAiEFNVAaz3wRu51qO++aatDnPpEujYwdW4R52GpCZasPXNLAlovjocwJF7vTr AlEV7hs1LvxxsCptjClbAltWbbrZdQi04CBS+88BhDb524XUpqJjsYc8KvNXs+IVy0qYBJZZn8b IGWgT+mvBgUfqTb2CR/KocbLTHQlNSIKFakoIiike8KdNFl0pky+9ZpZT+pLYe9M5f1pzgzeWWk c7lTuQKw5CPpDrlQSBs8egJZx1F33lrdtTuGJngk2rJpxpkd/8BF+3FTlFPfUkNoNLMNRj72FWx y2ssowrBJF8YWClqMU7xkMwq/uJBL7xkCQJPv/o24YQ8ruFoYC76JwYwD5kcQA58wg+radHxDei kVBt9tfuyNeKuDFuY1rdUimnUXnnJjPEto+PvVjgvvVVgbH2y4Qr4t4+qMI01h7Uva5k1X6+i7Z brYV4SA9Mhi5igA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DC58F1C0003 X-Stat-Signature: omffhrtct4c5mjgt9j3uuq6xhxbkdde7 X-HE-Tag: 1727895001-954228 X-HE-Meta: U2FsdGVkX1/tS4uqGow5AQbpk0Cu9Q38sXNbQaOEyXO+mQqorESyYN1Uf988PjN3uoyET9WAF3ALv4zixm1SNisxanpINDSQzrHqomDcCSTI/Iq6q8O6WFOOKy9n1DNs987V+g3Q6J4Nt1KAfat5x/RnPASzmEcLq7MgCD3461RYn78HQKnxe6qFLDCUoxCDjxOz+ofCKEtJIwy/k3BHSeZNmw4jLFe794sEWgZH9hqgRt62XLifTPBLVxSE9URTysuHkOs9SWEZpnZNrXGigSbfzC/H/LvwZHPAGPs/NxnNSbtx8DdEDNlxGvKwW5uuqxQR37TtYkAYw3ePPpzh4H7ejCetbGyqM+VaCsxOsyIIyw8Wux1TFssgAfNx10T39Ubem5GPaZguKt1TBszsHKk6JvbDGNchxF+T7XeJPHN9VsUYanO7gd8yaK0KophdpXeM42hdPYUj/sNjQ846Z9ZZcIfuykKNBulcsWKJbsRcrJVUGs3SD/4vegoY2Yhf2v8NzNNVIIvXXLYrn2JB/zkXXzROcxGPpJHsGZZ4HTajKGPP1ov89sjhfwqylYEa/H3PVfxtrSNUTaFfN/CyxWzSlqpbPftPqqu5H6f9sckU3fNL4GX5FCGulnZMjz6QehTAzaFJAcjXqGZVBiiv98yrZaCq+5p7xfj0lnBDapjIKcT33wNObK9IYRMgD9ykTHPka0lmJzyHSvTPJoZBixVOnZTwffZeKqkUczqXr1AyG3h23BFiCOeAboRoxPlDiOR8B3BW4kglmEXpZgqaRQvKBpN+GuWSIJLl217CfF06Mdl7f7vX6O/mxxANZcZ127VJm0++ELdkAFe5r/Vi+bhqpUL+d4GByNKP4dm1o5ttpHD8vrEj0w8qdJvZ5w1UM1+LEovr3/QYh4knJw/fo8ChJ2DUVFHbGGOc5ECo1IrPyYc0MTgQdD3+B+qFafofnfKnKJSvpYDgE9PhaAA RPLWhfOp l6WrA3pR3FWYoH9lS4jlfW2PUah8xyvTWp7uotGjE1fGboiOEB1R+YhGfusYNJPjx71tXZ3vGgcfzLs8JUBwuE+tR4yx3WymvKcLj5OJrIoAyUjgB4RO0Qmn60QenKmM1x+IsSWAQOh16MDbdJcfzk6lzicSrz65+xuChsEfrBGNDObK41mZp8JDWvNmFO/3BUm/eKKIKTF53HKuQklJcRlRLVRYOMjCY+dxGX/AiDnwsZPpdpOdCo0Q6wySLQrlJhJTtokrqj5/eO7/EPXJZ0zVMmyzAsPLd+HsXK9FQ0RT8uNuPsM3cp7jnTOc+U8nXnxKB6CVZRB7YgOrDvVpu1FubXDhv305yZm9caj3CDHYc1bcESI86Xp1RO3AP663oTCkb75p0/HNUSCWLTpIRLf705UUKJq8kfAla X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The setattr codepath is still using coarse-grained timestamps, even on multigrain filesystems. To fix this, 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(). Do not 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..0309c2bd8afa 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, 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 those are being set 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 Wed Oct 2 18:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1A8CCEB2E2 for ; Wed, 2 Oct 2024 18:50:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 460246B024F; Wed, 2 Oct 2024 14:50:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E7736B0251; Wed, 2 Oct 2024 14:50:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23ABF6B0253; Wed, 2 Oct 2024 14:50:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ED07B6B024F for ; Wed, 2 Oct 2024 14:50:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F7AE120E8E for ; Wed, 2 Oct 2024 18:50:06 +0000 (UTC) X-FDA: 82629552012.02.8D2CF13 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id C3FFB40011 for ; Wed, 2 Oct 2024 18:50:04 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=m29kn21o; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894965; a=rsa-sha256; cv=none; b=XUaHQ7v23YV3sQzf36NqnXUWgBkX/tsFQ2ft3VVFWg/sYTc7B1PtvNoelMsmcc+NK3npbQ Gk78VP6fLJHq0PBexnLoCix+i4+CCbKXcNM3uCQhhIvTqiv8QnuxMwx53St2pEKZx7/X1e 5EiHuJ/Bq/Il7wZd1mfq5YsjPilpoqw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=m29kn21o; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894965; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BnSrOm+SlXumXk6c+y3kNd25OzfMZK4zTK03/InT6p8=; b=CwkYoZX3XfJTO9mce7FXc4xp9SHdWKBR9+mFQu5oxkDs0jZdCymyGus++xFT376tJzRbf1 mG1T8Q2EtfI1ue5rfq44IEyPvxtCCVkA3amrEpDBRm4t/djeTrXbMZCoudRgBbWtx0HbY1 8spvaXBUV9j2b/dyhHUBXKhN1cGmp6A= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B28735C4003; Wed, 2 Oct 2024 18:49:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F247C4CED6; Wed, 2 Oct 2024 18:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895003; bh=607LRAQ5lYI/rYHwJWudAw3VqFTtnPId8/VXkMTcyVI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=m29kn21oThOWn8FA3lIOxu891/RPN4jgBUyw5AcmTnYQW3nxAervpGlIeLy3HbIcv JFgHvNsfXUryLA6XYI9KgtNURXTbcYLjIxf6QiqValFyd36gG4pXxJJon+0/ZWLhDb cB+au0L/oDT2l10Nf0T1LV2RX5mCJhaLiBbZGNcrKOlXfLRTz53NBq2CIwq8BCh/zF AG3ySqlcVwUCQcyqUivBA/Zm1gLSLGw5RfwpH1doHBf6Nk2MWEhb0PcrV5MwKD7f1F XWF1vbWNym0+i8+ZAinFzZlOpVmLnpoxkSDBFp7IS3ykdXbn1De9CGkb/0DONHW4w9 IZaD+B9dT2LYQ== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:32 -0400 Subject: [PATCH v9 04/12] fs: handle delegated timestamps in setattr_copy_mgtime MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-4-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=6217; i=jlayton@kernel.org; h=from:subject:message-id; bh=607LRAQ5lYI/rYHwJWudAw3VqFTtnPId8/VXkMTcyVI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXM5rS0bxHUPi1uZgMZGm2lnd37dfflL6NJB yztoxeouX6JAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzAAKCRAADmhBGVaC FYkzD/9PTpFx52ZO8A+U0V3o8KkeLeBWD+hZ1Sx6vNZvIFxjnqkOsTXC4Y4vSpq75YZLAUcZfmj z6YQNmZaJWgVPZnO8Md9u62OezZuDjmnZZ7+9Xqwyc8+/fMpu7AiLwv9F3LW8qZ0QuEwFZmpdLG l9wo9XpuoLGcAOunDit8Pi7nS45zJ3yeEwLtdUGwTGY8ue3SnNVNDKsMyAjKkCiLXUgaL6qDE9A FMGf3pyRHNhYbkOJQK9Gi41M+47BttNnuYCVLA5ZbPibqbFovLKbvfbP7EQZjRfELrIDhVU8B2B ycIFDvYCfjUmaBNl0BOv21FeHfWOApYJWntTioRONDy3Yh5/oaJqYdpeSXxIZFoNtG1G1mWNjk7 mBETrDuITMf9g3Yr6+Xf3KKdb19q6Uw/SVcFK/Fqm2FrvVZSpjxaGc8UJ4TGEufO/1It62fQPu2 YFyelm7XMplEeuGXEuDcOxDXFMr/TgjmEpiOxNblirKPjxV8soK4A9gx6bR4MgBA+33CWaqeo2/ J6WnYTgFCLgL14H8wKWzVmOcYJl6tXCD07d4GRYA+cijQTkL5VPVlPTPjgQucVnzVxRsRYfXquL xP6iHiQWaJzD1OhEXOLzVrnoh1cr/p5xu2HPKSw5GCLdQqUTnH5603gpWXAPXtFAWkYyOSTb1NJ Mb24SKJzynhFlhA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Queue-Id: C3FFB40011 X-Rspamd-Server: rspam01 X-Stat-Signature: g4rxurq7bxi41pkohxjg3e9dqzfj4cz5 X-HE-Tag: 1727895004-937840 X-HE-Meta: U2FsdGVkX19bQXlu520GzqzkRGAfqZ6r854GxEKY3au+9cDY20X/hEDL3H+KFbFxl2amjjiiB2ZwI1T+F0ms2CXzRa+6NlFfv0S1j52N0Kz5fZAIqhVRVEed9mfs5kj5a7j4YzPF+BxWJ1DBTdhxjbmNeA3k2ymAQH8ucMMvYoKupm99/Qv0vDPjCSJzSLyurIIckbOfP3yVt+6C7wsXsA2YMX0buvX3G1uNQOxzHtEPKiGfZoFsbMthyHja6BQHsnvqW19NLqF8xEeN6n7vnir4CjpYIixXp2DQKRXlO8RBXFakeyKBFDCSv1mYqeflQpEocRWGDA3NM4fYPO2cC7uW7V0C2Py+Zi5LWUV3WvLpVPvxtMSO9atgl/PNLC1x5p7VYcmsl8cuMIqJfbxAJvvDWVIra71kgn9iVXsX167+PDxKzba5I5VFJWRDaIwre8F5ZWFS5Sa8NgW30rVJ3WuDjcLYfGeUk7xu5c/w4YIsXgFXLp3+qtbKchcUSt7AjWT0CmwooXWF6E1fQmkPh/SdHF7JP8/32WCUTvOjObkxicjTWr/m1PfNT2oOf6+Hiki0bekL8fNgAp/FzO0sK9l4ENcE6FF97Mb6RMlyRk32nMR7XybonuwYkUsK42WEVNd4Cw67YEpgY8fTSql1+hKksXodkNJVmYuFuDjaqI0E0knBcKrV98ZmiLfnIcZBjEhrps/OkNzE9rWNMkv+R6TqW0q8eJ7ikgUC6pyfgOF9gJffLdAJ8q+1VrqQYtpCBzSaZ2k+CQW7VI23ETHzGTc2sCewdNf2e97Lmk5uJw/yB6m7n5iNvDojkbBWMZ7bidyf9cuZR77oBljgKyZ/P25iJg2JBYmXHPLSBtYNxC1ppGn0FjXwrNadG0Ze5uhIXnivT3+mL1hQb34dET/cUPSlgpBt1ftvfYa80Kmcja+j7iGbi0JbZOPaC3Od3v17mLlv7sPLHkeBFU1C5kv Rmp0QUO7 TfjMLDqDHkFe7yxxIaRrbL1quB/hjr7syNa6x3nUz7WL7AfT3KS4KNLv0Wwe8K8Nu2kgVy318lJbE/KOHYa78zgu/UthGne86DYjjD3tOcpseqTf+vwSgXNtYo5wV2HEHJj80aDpEEWplW8RZkpj2qfpKOsRq0+ITjy2nkccmLHitWsg1ZcpDe5xLoGN9LMUqvN6B2un2nAg2AUyLIGpFlX8425/qngEA4QKDRVyzCsDgOzKCJ/RljLxClzfnxVydXlHAbJ7C6TsYF/x54O/HRJMThQf2/Hdek20SYevNZuv+lMR74EUROSqNjcm7zH00oXDKC/2ExolUR290Kbri4OckScrSO1yL3uxM X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: An update to the inode ctime typically requires the latest clock value possible. 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, 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, 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, the server may receive a request to update only the atime, which doesn't involve a ctime update. Trust the ATTR_CTIME flag in the update and only update the ctime when it's set. Tested-by: Randy Dunlap # documentation bits Reviewed-by: Jan Kara Signed-off-by: Jeff Layton --- fs/attr.c | 28 +++++++++++++-------- fs/inode.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index 0309c2bd8afa..c614b954bda5 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 53f56f6e1ff2..7d1ede60e549 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2717,6 +2717,79 @@ 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, update + * the ctime to a value at least equal to that. + * + * This can race with concurrent updates to the inode, in which + * case the update is skipped. + * + * Note that this works even when multigrain timestamps are not enabled, + * so it is used 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 + * it 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 another task 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 eff688e75f2f..ea7ed437d2b1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1544,6 +1544,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 Wed Oct 2 18:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E74BCEACF3 for ; Wed, 2 Oct 2024 18:50:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10D474401C9; Wed, 2 Oct 2024 14:50:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0671E4401B5; Wed, 2 Oct 2024 14:50:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD6CC4401C9; Wed, 2 Oct 2024 14:50:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B32A04401B5 for ; Wed, 2 Oct 2024 14:50:09 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 610C1140E79 for ; Wed, 2 Oct 2024 18:50:09 +0000 (UTC) X-FDA: 82629552138.09.6272120 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 80B79A0012 for ; Wed, 2 Oct 2024 18:50:07 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V4OObcVn; spf=pass (imf25.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894967; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=40tC2epBZPnTYtQvn8eLplJ1T1ytGo2EU4yzWThOwyk=; b=zTU2z9uWN0grqOuuqExupQiCL8D4oV97hWTTXbcEBklW8j4iHALhrXbFI9CGAVwCcLR7U1 IxSYJskESESB49Q8KA0UgwhfGIhYLGoOiUQROWdphNXUR948mR0jS3yjvQM9R2I8RzfVuA 6IiigAyJ4bxBRwUd9cQaYa32e4w0iaI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=V4OObcVn; spf=pass (imf25.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894967; a=rsa-sha256; cv=none; b=kHXVnCMogU9utwSFd3aZ0tClbTzlLU/nw0P3zEWQjAZdrDH0Logqailn7QE0LxHyymUzYA TnFIe3fKcZe2NuQxrifeldNrCP+PZ4OpXAPcvpzmxk+CCLR+XdZRVvCPlsWZQ4MPJbP9+n n8nGkaAqD43iyknWcooPYz0OwdqU7nA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 824AF5C3ED2; Wed, 2 Oct 2024 18:50:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C88DBC4CEC2; Wed, 2 Oct 2024 18:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895006; bh=4t2FhPU1ioCf1EafHL72wvSNrYptyiNtdL+ORaEoEmg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=V4OObcVnB2u4+GoipJoXrQ2p1ZeNEneChyK4w9m3o/Me4PaL1gRSEkUaYQwoClmBB 8vjqALRU8/RkodIS4HT8hP69AznS9H8Q3xK749hHviPbHo7X2Wz0eLV3mQ/XF2Xkf+ RDK/dm9uaGykveRB9TSc1OV4eS4EbZTUd65QO9SMwYF/zu7xGoGCrA2WsRQunqvv/6 6/0cPzY3xoVzL/SVOMjZlqJfwWfD0ElqQz8J1ibtqpBqZSNg9U5A0FJgINkgicbPI7 ThgF1gqcsOifzM8v/chn0v0rJ2ZFIuLcnlc84JhRBKuejq3n7bUTFQ6wimznvVlq10 /cxW3tE81aodA== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:33 -0400 Subject: [PATCH v9 05/12] fs: tracepoints around multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-5-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=4t2FhPU1ioCf1EafHL72wvSNrYptyiNtdL+ORaEoEmg=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXMOz1RaltWVjfd1YGG3CyRGDkmvjFrNgyX2 acg/8g3uPqJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzAAKCRAADmhBGVaC FdGsD/9hhin5H+43N15Xq+nWKGrjdKX4oiSyK0hU4y9aA3MnXMxN7JC3vsG8ftV5CFA4BG+a2fB L+xf5SOgkom1v2cr+olmxrOZbCoffl6/Uws0ITKzhdC6jpge/oPWdZodaEINZH8zWEqi/sT69q9 bwn+YwmnLwTBWcgHh2obcUTXZrVetfV6Py67U9Ty1yAbYEr2WoNS+WSGvx2FA3SrMel3gdNPwDo dBhyxFNPDMaxPznCSL3OP3ed2ZdrS0ya09LyzS/rDs2zwdSlhQpUIeGlLw6KrvF73TJEl4gYdHI a5/SPBsK81jIYPHrp5DrbKdYYEQkcaiwv3dCiw+WUehaftXj77+jqCo75xxNNV/1OYvcjhrkAJt yapJyWhlZPTQ7jnX0+fl9FQ8TBbvE1KX/y6fcGzUhTAVad2getD292ucx3KA8OY2EoGJxkuY8bJ xoIH/0XVUEeAq4IJyChrNlVkSCDqbsJluKkQNKjuUt/DWGf6NEGDAS51GDOMHDq31H3xLnn/+Vi LirGIVYgA31zDTQHT4eFFwJ6/lN1OWZ5N89LKocHcYBFGx0oZ81dEFSwn+9f6AXzZRFmp+DT7t8 BptgyqUZ2+yXUXywYul7/qVQr6SoUsIwCgNzfkepNSPWm8mg40QWVTIfI7iHwhLIqV3wZmqHflb IllTaKUWYPTcS5A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: k8epxafo4wa3bxca6pw713x4so7x8u9a X-Rspamd-Queue-Id: 80B79A0012 X-Rspamd-Server: rspam11 X-HE-Tag: 1727895007-366829 X-HE-Meta: U2FsdGVkX19jjPG8nalaNcBpJn9bvma9tUG1E0CdKQSq/L8CLUUmRcrqCu5TZ0tgl1wc1PG/EFUS3UCPBq0QHqMaJacTEliZEyF0WEDJOpsZ5YBYm3ELIsBUg/bmEVHAiLXPeBchupwvD0A6f2FtlSDVl9C0ZqLNf8fo8iOnSv8WWJxGIAZpJRhnCj4L2Vkm4+KYTCJncjjp+P3fuxgfuxd3/CmaFaEbgS7jwWi/6IKXPIQS3yyMPUUw/lWMIgo01NDjPHNViZKD87DAll7ui21qbfoKL0kLb3H59hrHsy7BaFxxH/H5QyTF7s3fs9SZZSi8VFNpPeG8riumBRRxbsd47bR5ypJHEEdNX6hD2ox/s1Tfi5RPkPq72eRzcNQpDCZugnrRyBzB0dC55l4JHMOKWCRQElOt2LmR9H0n3xjm0Foih4eBnvy9IYbm/vD1J6/xCPbtf4GxIlRvYeti9GxmERsPkyS6lkc/PHHiTL44kvYvHgmDnHBu+H6Wx5VEoLknP/30WU7FKiL+CER+6rb7uFIgdtyRMkqyJ7zHmTbqJUo9I9fcvZA4P3ZeE6SXvUW4FsvHvf3EEEIkFHgiquvlKCsab9K3AaaSZ8y46YXM1lUeavsavs7HrSFGnbmzHBa0F+tUoqUK+uT6QJPqlpr49LBIRZf9cfCWgXDH2DDvX6Wx7ModKIyTlvwEegKaggy0pGoxMs8y8rO4Erz0jesSo+nyVwAAaUPj1D6daV07XQZTuHEPJ3yaKw3CbLmW71Dz9rEt17ZdytUpjh8EnOcuv3orLy6GoZj3lDEmcjxfE0VGMOa26qqGs89PUANJx4/y+TAuAibbn4nMS1H59XuygVrvZbzSrhNKMK1P+QmzgCtaz4OtXTtnzoq/lByFzHZQC/vN+qhv9BGqsGEoDmZiRm3eiKOBOuisEseRWKDZgeUzFcMby3D1Gau8SxF4wpqqg5sIfAZTfsR2GJi Tc9VcH5G 5KmEFI6rVApam9sBC4R/L59c2+pccqBl6KzASJhAPEJYd+yfj1X5TVYB7UZBECOIjs6aYCKu4K4iCoJWC+GdSAp5jw5UhuHz9N65RsC/sGBpVr2Ww4rFLSj15gzwHdgUChdUTyvVd2QmyxwOQemJTS9TH5lUcQ0JndO8AoD0GkCsXLXB5rygDljLb8vfPnTLzdtzciZzMF9Wa9qzmjzPNCWXnCYxvXro2Dq1SL6YxI32E+V6+jms6K9p75JA+Dcq1UIQEM/whRzbZpZFizb+7WTpIVG2EtCgPr45Qlo3rPH+xja2ShMXvZpH0ApHWcxqntXH2/AcWkbrLtS93mtBRIVB5pSEytcNQRB1B4cKmk8NZkK6F1xkhds1FrqLYZqexnZ4tXrxOsdKFcJUSePy455G5Zh5WEHf9UXdTxuAP3VzdtPs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add some tracepoints around various multigrain timestamp events. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Reviewed-by: Steven Rostedt (Google) Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 9 ++- fs/stat.c | 3 + include/trace/events/timestamp.h | 124 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 7d1ede60e549..f7a25c511d6b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -22,6 +22,9 @@ #include #include #include +#define CREATE_TRACE_POINTS +#include + #include "internal.h" /* @@ -2603,6 +2606,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; @@ -2689,14 +2693,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 dd480bf51a2a..6eb6c39d0037 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -23,6 +23,8 @@ #include #include +#include + #include "internal.h" #include "mount.h" @@ -56,6 +58,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 Wed Oct 2 18:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85D8ACEACF3 for ; Wed, 2 Oct 2024 18:50:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0DF06B03FD; Wed, 2 Oct 2024 14:50:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBC4D6B0400; Wed, 2 Oct 2024 14:50:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D10906B03FF; Wed, 2 Oct 2024 14:50:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A78FB6B03FB for ; Wed, 2 Oct 2024 14:50:12 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4445D1A0E8F for ; Wed, 2 Oct 2024 18:50:12 +0000 (UTC) X-FDA: 82629552264.18.F1ED6F1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf27.hostedemail.com (Postfix) with ESMTP id 6FC6E4001D for ; Wed, 2 Oct 2024 18:50:10 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jakiBEt2; spf=pass (imf27.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894970; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3gU3nyrraY8CubZ8FodkvGoDohKy/j1zXwdzD5kWX0M=; b=t1bLJ+bebspB/QNiJID/OfySxD9B5ApXMv7XA/E3ar+yFeg2VQXzphzk3CKZqeo0shcoFA msntQiIKSasns9XckfUXzALODvRestakOQgz6BaeBTnajLPgFjxfJBAeQRkd1XzOki0TCW g3HGgrYVX44ZX/5IaZFXfRr3nVOKuwM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jakiBEt2; spf=pass (imf27.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894970; a=rsa-sha256; cv=none; b=L+tUAeKtC4s3kz6uRYkgJfyMssEppYus1yBFAstyn1Oc3R7ClSpuj26gC5LQ0xQMF3kwFm Cb6TT5IAlRdrhHX4hMbcrEiIIkMWVRyU3kDneVIUPyHHlC/VfOijwv8Je7jtyKwMFEr84O q5FyZvJq/Sg3EilCMIIR0M20V25pe7s= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1BBBAA427CA; Wed, 2 Oct 2024 18:50:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E6EDC4CECD; Wed, 2 Oct 2024 18:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895009; bh=ybB7Jq6PT/ZNMBeOogL4z2UfVWt3aicdUam5Wxv2K1c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jakiBEt2k3OKyDhgEkn9ZhNmc3gm+CSxovyXO4T9s0vMM3vnbfRaX33hpGWtWeGod 0w+jC14ldR+52dDugSmbDba+UaPQ2TlIytUZuco35MeImO8FZ43+OVtnIVSb3oYyr0 qRnTOc+mZADskjg9Nos7u59aZ8n5g8X+hT7Vto9njcHshvaHZ2j5BZH0Dsy0nNXdsK InQ3dJWOAg6ld7Kt2+gtL/D9Fw2TS9P5hgwyOBBpnJ97kuXvKMykbohVnxbW3kQ6zn Chul7ZArrdzfjCAqzCvN1gBoMyY9O2Q4T9cfNc1AOuhh85Ic4xkI6zbzuQ2BJxSaLx e75dB3iQvoWyA== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:34 -0400 Subject: [PATCH v9 06/12] fs: add percpu counters for significant multigrain timestamp events MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-6-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=3446; i=jlayton@kernel.org; h=from:subject:message-id; bh=ybB7Jq6PT/ZNMBeOogL4z2UfVWt3aicdUam5Wxv2K1c=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXMCff1Bu3nV1C9p/EgImanbwC6KH7xo9Z8L WHrsJ1mIgKJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzAAKCRAADmhBGVaC Fb4LD/9wspekghH2RFnMuwf1MnF4LUapWBw5tZWsQIODmI+2sIhcxzp5USg264EHIX6q5+yoJ/z 8ud9S98Wj3j1G/x5W/4FeqscjDBuelE3urjjbdcNyU4FC6+EENRbn22SvQ1DIxSOy+luToAtjgA 4mbu+gHEBNweGUkg4H6VD3M7PNrqEU8TNotbwvMMtpdHLdcsaG6YdHBgYt6WwSiwJPwlYZv6g// OUPNGen7nqk1dMUyrWVUmpnvaM3ALEJe+3ywkwfu6i1mCIc9JC0EfLoPoAn5+q/z+ydn4FtZj7Z qWp6JQSb9H3SsUyn/KUB2vRVD5yzcG/++qxzeZM7C3umzt5bkC9N69H7Yc7Vc7n8t+uHIZwt863 kai0nolffijAAxKGY6mM8phzDIoqKyAXPoPe2pFaa6Ouf2GFMzdLy/BVb1QDf0gHPs1vlKZI/rZ SlLk+m/pPRYiHQNo0t5RKMv42xtaDSL6dGSePgtDc3oF3E5/jNyRzQQ/w2pZjtKkAkMHef3YP2w c7Qc+U9OJGF1M3aTlL2cOyRSY3m/9pkNMFuioHQ02Hy59Nxo5eZe4gC2PsapgJWjxEIsWLFZEUu 9aDCY97TV11I8B8BJsw/sEHcwFqADXX+vRzYODKX1fqWJAQhmeWUYVWQUAxM4X8ssPWO5mzK9ij Mmdk4UMLqKk2slQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: t1stbcopj7m1ersh9ez7rm4b5katzx7m X-Rspamd-Queue-Id: 6FC6E4001D X-Rspamd-Server: rspam11 X-HE-Tag: 1727895010-108592 X-HE-Meta: U2FsdGVkX1+6jII2Sw3euPMWUq5z4nTOXnVbnTImMRXRGUHpYHm9eO50hBSdh3bwHO298AynlQka76QWS9FVsI3NLNs+OQmdSis7Npv3q6BUqnYun2YylSWsWZwZtO83R4D8hCIeRwpQGayl4mbnLb60PVV/qKXNIfouiB9JxwiJgcsdnTHQBDcgLh/9vXxaA7j4LU3T57jeA6IHWrSlZbObiP/K0tlKlIILeXwi5NcWVm6lkX4pJiIHmCosLQFG82+vjSUvitN/HmHElAte6lajtxgvXwnNJxmdAVq8qFY52OdG8bEcX5WAuGKSm7GkKnuu6SDhclINlurgtA8cdZ3vaXjkrBCb8Qsfa7LQCz9iWIN0jSMD91yOiYW47wAo4Zc43rwWqtrFgQ+bWwTUVEsFPMQUKYpeLz00IVXmyq4RRkzyc+BhhAZGOnaBzp1Ak0XflEB/ezSmiGZons9jLjpH7FSS5JrIBpKQjjKYJGmDT8Hg/cv3znDc0oNduWLUte3i0tsAhjWbGZBiByFNNpJxKF/qg/eqyAQmk4C8QVJrvpRonCon3TW9SfRX2Rl/vMc9HwHVAYGHLf/GxzJW6rUcYLjbArj+l6VP/Zg3n39UNwje+V2KiUFKKI08TguLJ+FaTPHLzvqAqbjbWgsPqQqRIqEbPml01eaO9SNeNm+k0PmfV0OvKbPZdBeX6AS/VTI5JwJVd1WaHNGBzjPsbFBaSZ6ufDv0f0yCXPjM2ICTXCxC8BCWTxFrv8wssQhDzErA6Sd0sqxdcbYOu+GATz/aXpj1Y5XjYDXBuyHVaL4YTZixOW9V0Y1lfsF0prn7j8rHO0HYbihHchhbqtXCS1E6xL2+NZ/rG6BkuXkK/oSLkM2JfoCmNRTqRH+ww0ylwC97mkPp1wk+GB0H8WlI8xeja6HeDDYwyHUOE6z6wl7wEKpOBsDL/s5fxGB5Mz7I9XwI5Akd3JclssaiG0P QWEKM00D iDaMFjHhMAt0oQAlqSyRXusTbWW2sxLXwzsX4JhMYD4oy56mIcdX1Aidbie20lMOgqSS/Bwh55j4XYHE22+0J/LPtLK4otIxpVe4JVEwfLRdoEsqOxdb1MdQcPIhXai2dg780M5jBoRb5n+BXsabdXRfsOcJVs+NhEruxnajPGl9mfeGG4nOJFsI5Kr60r5focy4ZzZrwGmzNA11SinxCKyDOId6PWf/ToNWuoerDQ5f0JggmfW65S73RopYpN+lM9bbqsuZSoVOWNGGTf+mPy+2N5vr1W+mvPuT7NJeyaf7V+KAHj960nC+cYApvk7GN21X69gmuWdMwnsJ/HBqXTXmX2u/3qV/RkGGRCisPmG/jd2g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: New percpu counters for counting various stats around multigrain timestamp events, and a new debugfs file for displaying them when CONFIG_DEBUG_FS is enabled: - number of attempted ctime updates - number of successful i_ctime_nsec swaps - number of fine-grained timestamp fetches Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index f7a25c511d6b..0223f8ec3cfb 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 */ @@ -2689,8 +2754,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) { @@ -2704,6 +2771,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 Wed Oct 2 18:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5412CEACF3 for ; Wed, 2 Oct 2024 18:50:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39C806B0403; Wed, 2 Oct 2024 14:50:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 34DE16B0404; Wed, 2 Oct 2024 14:50:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 129C36B0405; Wed, 2 Oct 2024 14:50:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D86716B0403 for ; Wed, 2 Oct 2024 14:50:15 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 410C1C0E67 for ; Wed, 2 Oct 2024 18:50:15 +0000 (UTC) X-FDA: 82629552390.06.2A4827E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 0D30D1A001B for ; Wed, 2 Oct 2024 18:50:12 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fpAwcvtX; spf=pass (imf19.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894884; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NWHXEakX0NYRflUYHZvCjby4t/YakqhmOgYli6I+wPI=; b=IPZATWJdf5VO4j/wZGgqijUfTSCv780aRxlcpmd4F+zMskxAaQYvx68vmIvHrblkCvg7kV LZfZyABUabj34nsfcClERbozS8iwNtAL0GoIDcDkcXdtsDQQAwJ9CAkMckng0oLbYq+LOq 8YySLoywVaeqbdLMw2UI5SICVripV/w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894884; a=rsa-sha256; cv=none; b=oVQpkGL9zaPjbPUZ793wuf9hWtISsVnKZmhrf1d496mYcl+E34JY0R+kJX76fQ6J5Q7ajS dnN4CmePlKfu86CCccEoFlkAfHmwhEgEZX/qDZ/RBH9Yua4dlEYYWxuGWqIJq6MQwXiOnv rb0HYZzmN9Uw2wa7C9vZ701bkTq/NAg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fpAwcvtX; spf=pass (imf19.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E0D015C4590; Wed, 2 Oct 2024 18:50:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5535EC4CECE; Wed, 2 Oct 2024 18:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895011; bh=FAEtrer/wxauwCEIrxfqdGNO00oW6MLUKCATzsbfXLI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fpAwcvtXD8gfXd+PRfOJ+eqsAUC72UscmwOYTBkuWJzbNNB4lEzo1BS9ykVMuQnzL I1anPto2AGBaLRz0Q+v3kDGQ8gWnGoPQTXUPSI9cfLGMpD3YnDpElJIrvmztyv6fMA QkHfGNeYclB/Qh3WRx1AfgQR0AKMYASoueR/HIBIZI1s2l9Xk2eqtyQkwL7IEI9Ego z8V83SwLi6tetczfYZ8miK3HwZNhMdeRP5cZe9WWmUP8dRbxXA09wyqwaNZdzCUj54 bJ/UxGRxJ085xIavpXrM3j0Z8mU/0QaSxe60rs/RYwR4Ab5Gul1xTwAFM43qml1b0d ry3eRS2sLlcWQ== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:35 -0400 Subject: [PATCH v9 07/12] timekeeping: add percpu counter for tracking floor swap events MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-7-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=4023; i=jlayton@kernel.org; h=from:subject:message-id; bh=FAEtrer/wxauwCEIrxfqdGNO00oW6MLUKCATzsbfXLI=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXMjLTfOiELFgyyDhd7gxbf4QE/JplmWCrQl HH5l56MD7SJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzAAKCRAADmhBGVaC FTH4D/kBv/Pckw5cqhCOB6dqYpa9qps2pXUNeKu2ETbMkfkS9X4q8TDcK80iM/edS2D9zjeuEAx dlLzn6rHLiWHxyauX5kFVWDTjMISqrraFxbEX9RA1FI8Kr1OIJoYof20HadOT2uApXtnswJL680 NjBU3qCtIic1QfxkOs3kfme3JJ7lS917DSFkrEuwGKGCMfV2ug44Ka+EmlyRaTHgaMMT/yjqTKT Z3ECTJCfmKPRbpbrjvphcx5vMRKpngzgPq6tlDx8qvm0hGao4wNR+cl2g4sqGFvATw4x7C/BT6v mSAESlBpjD7XWrhL2IvmIP6NjtPjknSe84QJjoJTDWpAeo6YZ1DzWja546B7NfCfS63N7KJ4l2+ SRs9p4DneuGAgiH9xMkjR6Z7CpghFFebG2X7XeOOL7Qp9GR7VMiOvH859wZlSSMT/VHQStfhySU xgzaRuUDYuuFeDmShYt4BQ4n3eprchbdIWH9FlQ6LcH16YHY2jhkCHS8EkdEIfFk/idMVsGaIuw OhTptpcKtQ7BUB7DwnZ8OTq3UykDihR1UKba07UMvN3l5JRyO883UWIqauXfGygHnzK0ZBENuFO DkEoXCUxw3nxHTNqxHzaRdKWd4xbqcNWWrf/YtQj+A1TP7lia9MoZdQJwqzhmLEUnCClCNEoQTy 57Aq63B6eJV6wUQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0D30D1A001B X-Stat-Signature: rxr6cme57335cq7bik4f8qmtmppdogh8 X-HE-Tag: 1727895012-470163 X-HE-Meta: U2FsdGVkX1/ZHlEM0cR2+LD5d4bABti7LJHuxYqQjdY3oB1Agzf3mINEqSJ4oRviDcoEWxD8mlGkqkqSp6SX1g7STHou+Y0978V05ckf7G0I3020m66DVOgdkaluRSjV+Opp4nvmfagEnB+Jtnf5MYx2n+cn5DunVb2X6SS23jKf4AsQVRHOICQrUc/f8KBIi7CFh/2mDWDbzmIAnaYFxGH5Y9vCvSnqjsLil7oyWCzsO2BHvEh1FxrpS6NdO8TJoHb0ZskQl6rf+ub6fqgMazRyM1bKnEnETtR9ejSpm9Jl8u2FjqOpy8Yb/0GQMN6724Be5+kQfEOQrWv1P4xb7wnSXMYsu74H/AsPD56rdJV4rZY/wQ0cPlloLSq/ATnOsYDpZb10EjITOQvr6dJozp7R9ZqeiNbNnUdjMVhyx0DsK8P2fvOMp3RNI/lyrR5TU69+J2ZS8neeikOybS9d/x/+B4SKRRg9Yrcnu7J7ANurxado7nOt2RaluThkHeTMcJDAdAnkrhrLMldrkd5Jk8tp263iP7Emkxz/SDorWQ3TGjlNR38c/ln2gmmLYQJ2GFmESskQ8hnofoVD+2tgi1oO+gg68j++0zbB7zFUYFAW4IJ/YK6ItKx9ShKhD7R6ud7dhaYvjDvw3kY6gBn+s4+xNdB61erwFyzf/q9Ga2CiOBW19a/n0AUv810Cf7styQaLUJtkbxZd1b53LLTHbaWhaQGSpLaDm4wy3u6nkuRzH0wINP3DWk9WC2yXndgI6uLZB8P0BeEinV1PiTgU0BCu7nJgfGKXCVx+hgaorm/+oVGvtZMakHWJ/TRNC0k/YGW24vukDfDKGPs8eNdVzb7v0eu7oyfEChuvv+HHgoNQv801yN7UVo/FzauutM4aPrIAlRPrBro4mBGyYYniJxJCmekm/OVqqfcB9Blz59NarLDT7gZsOtd5t6XHzqbhVJ01FDlAB8muJuwC42o q8O5+eJC 9eeMg2Cgch+UxKSM0zXx9lw9DcpMgio6DAAwhtORcSSNDrQZXl0uMtMuZVkeUEB9NzofkN1kI++liMoGeNfcdwSay4HHz8FGHKBt/Q446DXcRhOTQL1xkWZMdefSU4KdfMEoJslf20kasd0mt8ntyHFNOusUfsZERFn2eqCJCgUPMzMC+y1GoJxZddoPMWY7oXAsPmp921HlymTEJitAo9Rkwlp+IY1hpI7bBM4A1N0YEF7I7rqwysVNms8U9JY/YI+PkO4B9p49LZ/JF4IOUn9G9aV07s2ojq836ELqsqSAr204RmHrtRcm8Zg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The mgtime_floor value is a global variable for tracking the latest fine-grained timestamp handed out. Because it's a global, track the number of times that a new floor value is assigned. Add a new percpu counter to the timekeeping code to track the number of floor swap events that have occurred. Display that as a fourth integer in /sys/kernel/debug/multigrain_timestamps. Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/inode.c | 5 +++-- include/linux/timekeeping.h | 1 + kernel/time/timekeeping.c | 1 + kernel/time/timekeeping_debug.c | 13 +++++++++++++ kernel/time/timekeeping_internal.h | 9 +++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 0223f8ec3cfb..1edac9ab1ecc 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 ebfe846ebde3..e8b713e8ce55 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2488,6 +2488,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 { /* * Another task changed mg_floor since "old" was fetched. 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 Wed Oct 2 18:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA842CEB2E2 for ; Wed, 2 Oct 2024 18:50:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE04A6B027F; Wed, 2 Oct 2024 14:50:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B14006B0405; Wed, 2 Oct 2024 14:50:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9694D6B0404; Wed, 2 Oct 2024 14:50:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6601B6B00D0 for ; Wed, 2 Oct 2024 14:50:18 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 19FCCC0E86 for ; Wed, 2 Oct 2024 18:50:18 +0000 (UTC) X-FDA: 82629552516.05.C26789B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf07.hostedemail.com (Postfix) with ESMTP id 455A54000E for ; Wed, 2 Oct 2024 18:50:16 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XvBH9LB2; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894846; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1qeWHE5mHrGFsc1b44PsJIUS6Zyt5VkttsRW7fHuGGk=; b=qgAlOdCurDG1JdxhV2fhB+eFQPbYZgA5AZlY/LLEBKdpq5piMdOsOi5ovM9hNhAFBM2LmS qBJMAHKzBUQTdi0l2levGWhr7agDn8yMPbsjMYkdhNqKz2zWK5YmI0aFVu7E4GIP8gzwYj N0ZTiemOq6d5BeGco9fP821KjC7ISdk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XvBH9LB2; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894846; a=rsa-sha256; cv=none; b=sUI68qNT8BUR/ySX4kyKYtrF9gfiMZbQt1WLMQn1iFlJBzELUC+AMwABS+vWkz88R46+vk leTDo4H2BhMfiGUuVk5W4BOZFARj6krKHB+JqnezlAyguIoCPJr8sId8n7in1dtWvowAox DU0IbMU4GYgyYDpLDL0cmp6XffTs7iQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id A1BF8A427CA; Wed, 2 Oct 2024 18:50:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18FC3C4CED5; Wed, 2 Oct 2024 18:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895014; bh=yU3ux0/2Dtj33S4oJe5U/3bWMbsd90MTGAANY4A51kE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XvBH9LB2fmEjgRxUykO9Mmm5sj8iqfay0+A30RJBERXYirFJUXgSdeB259F90X6PF oXNBts/3rpgqFkpclUGpTpAV7HpwOsfjyE06TclQoeCCL2rIRwAoCQwFxD0Pat0QTG tr12tHICR1C2F2Axhdui82G5Xqa4gCQQEgPbuzemgii7wf302vlF36BY9MEszwBis0 mQR84ZKkMne3WdaUMa+1deCr3t5xJ9Fw/zBxfefkH46o4bzgfEDzLNfl/5fKdogt3F VilUn4NJ1u2+At3B7NV8Xgu8M1/+rmJNBMmaGMIFd2TM6Vekj2whJLFXpYjBHN5qNb 36eQC74yhzrlQ== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:36 -0400 Subject: [PATCH v9 08/12] Documentation: add a new file documenting multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-8-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=7290; i=jlayton@kernel.org; h=from:subject:message-id; bh=yU3ux0/2Dtj33S4oJe5U/3bWMbsd90MTGAANY4A51kE=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXMHmQlIM1XltglOKZZMLpcT3TrGf3O4cPbk 2Y7Zl/tM/GJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzAAKCRAADmhBGVaC FWtmD/4ljmJ5SjJ0YYZIgYOuuC1tG2m9LzbX5IH1G9yVu5KijxWOZWa6jl/6djpXxBIR/hXE+8J oQ15OQ5qJ19h9q7ixp9LTwzbhs0CRzMDQflyXtW2Pbl0fCd5/pKb3uXbwrEN8Bqc7Yz9EQB1sMo wSPhHCdR/h1Dl9W9yytIAlPr1mg6WqV9iynvU80v9VYF3vd/lM5BPd96ddlnnNDRBXvb+7xlOkA mtmzAxtOhcdSDKch71FVHYmJ3PR+uZGG8E5XfIRH3j1MfPW3YZgOelTOZ6DoiV6e83XYAUuMQm1 wuna4OKC0zXlyFUUYiwyet/jt67VRc2ht8Q3QK+68wkQgROjSPTjoSr1iU/ypxH0RnPNBrMQdXJ Nqv99kKd9TmJPfVWt4MYxx0fes4+i/iWTsV9LEKbpU3EXU0KF/HyJnecw64V0rHLLDY+v2RP8HZ jQ5mBuKpRNtezbXYOzCBFri6HwyEUsmBl/6EG/r0n7M8neuxorWx8bkIdIvMWSLTJk8wqmWOyV8 d6KZdZ9NDYkfOatQMbQfkiwIXsZTd9jnp1MUh+hYXcEyU0dtf8TJtTxInzPS1ZwuF83XFstwvCr vJs5e1foaiQdx7tMBIhFWmhzuZPmbqd/EW1C6sWjQg/r0qRDBvZx4Jk7oyesdhUotKyhorBc9pj ttfdObbsH8mEtVQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 455A54000E X-Stat-Signature: i5iksn77jt5sc8fae81npmiftaxbfeno X-Rspam-User: X-HE-Tag: 1727895016-177998 X-HE-Meta: U2FsdGVkX1+cn0JI2uEX/D0hgp3+AUtaxst92BQPpOwQBecsEz88OesoSUWxF6htK5zJLGL2yK1SPXjBtqDJO9Ep1weHnyDXoQlExKH2vkEGQ6HNEep30uMuBweBL1YFgWGFE6DqjMHQgdjNCxPhvMWbg6eUsVT7FHVjxudAdOHO3RglPOx/+k/EgXisnVhw4BHvLKE1iobLVHlahSetznYnTgU2gkEPy0PGhPeSwwPAfurOLGUFWcbR7vJkrjuJeamh4i+diRMVYWqbPFBS1fSm4Ct/I3QXe/GSV8yF72qIW5Nb9rjDOOF4u237bx5NqsKflavainBdDRbh3cz9pfOknygtPgTzIUK84kjEtrOOvczw8l341QdDYwQP9r/dQKPptgZq0ypTgdHB/F8jzHDc+vmGm792MUDXJ9F44TOrOKNzDKWrYNjPAJ+LktNRSZqN6Fapc7b7sqtjVgL0ub07SL9AwrIzL/t5BP5g/ZVLwWFHEFCrBS0dACfIBKcoHUXWAJovOij6Ib967slHGqx2YDrDjaX6OJHuIOIpAHmOkuLYjzeGfJQFB4Dm93kbDSFvb7av6eB5fhFkig1HPi33O1iFqFPAVu15axzLN0UxOgxIKweaGZ2DMSXslQvrQEYdMlCRHlbtgc1Kh3ZZFzYgml9FhUFO9usTt9Txu9A8FG0RzPVMgQAHJeyODy37GL3iNN6/Yk5fr+WSKrKhXgbh9qdHguv6aFDXE/gi+0MtJ9qhsnVF2DhfHAeB7dhCGZsJftep+yKZxUj61iHgXK439bLPVBgYwz4pxOW0P55abFXF/olWOMPyqnic793ns+necnGTuGZI8+3GiqLz1Zg7Tag8N6qJf5ryEboz7AweXArpgmAHC23m8MC8noxGYcuVKxi/T+NINL15xgOCMLUjt4XujX7HK9mNpQONqcD5Pcq1I7GNCSamOFzc8gy2fTIr/+nHFXvXQcbD3bA 0nSZHzrX YEN4bbGNRW5YdAViOhbFWbbJ2N+srfvtmF7hz8M1F07aqFd+0qkZlLyW1SQdq5FpK0UKhTFGIy6mxKs2v2lFb8xr7qx1MzpOwnYI80F6R1UlP2FiiG8rsc/bNEAUe1PXgkJ0BSHEPEg75eGQM2gZVjgbV6Jgy44vUOviXW9Tk9Ne97hUor1LzUo94buia5v8JEqvrg8HOYerYKQqCnT4GnVgLQDIVrugmthxMImK8sXKIt3vk4eiYmutvvg7Sh23gm3NCMAyuyoGEUgAwMeFhlUyC+p6eiwX+xHD4RvbRuQ3Qak9+LTq2P1YLk80h8p8rz8WzdETrXoJAXsdtAiPSOw8JFbVVG4VPy2QfJklAiNwb5W8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a high-level document that describes how multigrain timestamps work, rationale for them, and some info about implementation and tradeoffs. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Reviewed-by: Randy Dunlap Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton Reviewed-by: Bagas Sanjaya --- 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..c779e47284e8 --- /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, 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 it should 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 Wed Oct 2 18:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 599AECF319F for ; Wed, 2 Oct 2024 18:50:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7204B4401CA; Wed, 2 Oct 2024 14:50:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CEF34401B5; Wed, 2 Oct 2024 14:50:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F8B04401CA; Wed, 2 Oct 2024 14:50:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 24A084401B5 for ; Wed, 2 Oct 2024 14:50:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CCC95AC5DC for ; Wed, 2 Oct 2024 18:50:20 +0000 (UTC) X-FDA: 82629552600.22.E0CDACD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id ECF8A20002 for ; Wed, 2 Oct 2024 18:50:18 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Jm6HRedi; spf=pass (imf03.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894891; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=u6S2Fv2aERaJvv72TmoiJHl2rfCDCXnKds3UfJ3phqs=; b=1QiIvMExPkkQb/PLJZEi40NUOrCKCAmbDxVO67RyAZI4CeWNt7iZHzjJgqIaLfmQn14olF FDwoGGd0W7S148ia0M9wyVVqwSpXxzRCOKERzRlDwgva9I5zcPUT7oVc/kSrYJGxQ77qr8 0SAd25wmk1+o7geNO86ESl0KTDjwI0g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894891; a=rsa-sha256; cv=none; b=2rocgTVGjwHRMuRu8Sfq5RLQDuvY+9PHaR7aNfRMhcqHTzQJ6R8qVfeemjd1nPaRt/lp9d pIEMqwhAR0kPwIrWBd3ldRLp76GimniPM+SC+e6wrthTeH7+Cl92X+hLwmXZ6l5kt5B/Nt Dn2jnAJT2XVSNDDrtsKFjMNXRWjoUMc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Jm6HRedi; spf=pass (imf03.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EBA115C431C; Wed, 2 Oct 2024 18:50:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D106FC4CEC2; Wed, 2 Oct 2024 18:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895017; bh=5lfqUj45QnwrVOVDCUQ2LnUQUpaLf2LkOjJrAuHMoZ8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jm6HRedi2Q60O4WQojXVg3EB5FKC6fOcQmmc4GVn15b3YoEq4PV32Ke+gosH12scW ZA/OJDgT+bGZqSFB8tYv1Nu95tP9tX/WsSDsJbQHCL3AyogLZEh0zLrma9PWJ1nIrT NSY2QlJUNRav/+H+Yw7d2rFEPSugIhsR45BUNMWKpWHyPNq27+y59g4q9yAdjOmXqV nbJgviE1+jI7KcfVv5Cycj/JmtM2r9ahjOMRT2Bywld/m59TqSyX83HiadtrvAjTqk 3/uhTK/fqS0vs2ic3LAtWV7Ko7NgqqmzTB1TLgaSqJZQtVYXMpj89vOBkPP9SAAv9B c8MpznLyLLWdw== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:37 -0400 Subject: [PATCH v9 09/12] xfs: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-9-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=5lfqUj45QnwrVOVDCUQ2LnUQUpaLf2LkOjJrAuHMoZ8=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXNFfizrIh/qPxAkXi3xFswOUBA7q6HVl//Z Nf0eicKVQaJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzQAKCRAADmhBGVaC FcWND/97d+O8sPWKiT3s4JXUlD36zTj4bC7iSHTr7j5GsNtEzs9iTbJWkglnCEmxZn0WgdU2etT qLFxnGJKGOYK0BrOmozKkvSjXv13cifuCouB7vaZLA5/A74OODCGwYqYmz8YYs5OtKPdYs23wqA dZkGEObXPWuK+drG8PgNLQa13hlXjJ1oBZAzRTv6bmU6PcC9cBEYJoVyCBaopcQPJw2pJAg73kL LuVLq/U14v14gWmxW6+NSwCpOVlGr15nQnGhqaAC3SkFTL5z/+Fh7N4VJeVD0IBRoQyyEwJJwe4 edg7P0IoKfQJyaqUugCZ9u2f8YDAa/MZJKhjzoWGyv+QF/iyQtrn8ZHPnY5UyZ8ujoHZlFt40d0 2VhpIHgeNYS4QKAqTHP254a4VeWnI1n6xzQi5pozOsPZEo0b20E6vpjsngvI5K/p6rgwcF3ZkAc W5JUGqSt/j2RHkECa6m69Imp2VoCJ4xR30/iFPJbo0gPaR7gG7PERkBYsgUJfws1QbPqf2aK91a l+NTBUglrCXw3hanZ70+Z2xPr6xn2djNAsDy7UG5/LnzOr7QOJEL/Zd8NUKLJuDOV4tZGw/fOPX O2ogtnjx7MlR0WP3SAUn8Dhr1qLqO7nLO6zypRI/QJra+c7f4hB9XH9j1JTHVkMTxb4KQYkTvL2 eb4Hq1xvi9JVh6A== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: ECF8A20002 X-Stat-Signature: 8guxzju4pwf4zny16rhqxytfxrjo17n3 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727895018-458139 X-HE-Meta: U2FsdGVkX1+Pz7Z4G75sinCgzfyESpjd89n+p9uv/rxkx8zyU3rd9rmx9N7SzM5A76zyRvQs+zqbD4XAl+xN3Yuq1eR1hGdFWp+W6NqUdJfJRoA5ERhtNnudUY9Xedd56GFoTNq3zcZRwvZ2kiQRv/ByNkLLtU6rgxpRdB7clnR4M6Yqhev517Onb/ErGjk24maHOV2mxfudH22+F0lzOshTPnPqlU1sSvq8MFw9xzj8WeR+R+JTCyqv6LEeZAXhpd1Y/BM3bsZcQRsxQfiCViOzfFffZaW4n7ZoY6ZESFNvnleeQiK7EltJLUMDxecBcn7A/KzneylDZeXmPb+klZLkVxWPEnjd4A92egV4ejig5T9/0zf7qrYnI+fiU2n+U4wmKCXFk+tmujnAp6/bFWy9I+OzR9I0EQJH6to5Z/hRKG4hhN3UvLXlHqrQgYM5KY2OEJVmG/t1bcU5iwh44vyp5j3SYME1A6zJ8cVsntriRocR9sDUlRGJ2NF3NF7NHzQZqQdVDIU8CgObGdD3DSZ9O+BO8FLn7vfZBgzLVV1JTdPylLuLnCOHPWZVYbcm7it+ViI/cJQ9gdf3e/OV/kR0rhBAcOCPww/h95s3YODeZE2MYmd6+Bp+ayNIrXKRKZjH//Zae6YevjeuqnTXwuCqWdgPAdkOibscj0cWGuqQrrsfAF2jlf9t6+GJ5+kZjEXVlC1WcOupvILoo52ITVsgIbaRVX5D0vFSuAOaQO3tgrbzfWVpK9xzCWgVThMdvwHzP7Iyv1iI4xwCIo48hkS4wRB4xd2X9Sw9piYhlM2YJaxtLWfISGDircNZoUF2sKIQ7oxMvjBcTaTCinK593+pWwlTvzMfKpjm5gTyOjQPXiozHLb5/BWqFAkLZeF/OyOvluQXHmVNdUaIrDCOKMTiCaolTJts+ewJ+EYTso1c4vuGYcM72G/1wsVDzSGCJp/doKZCnrdVjKR2j5M hCjteovp k7xqwzu48FM+htyNv50kuxLu/UKVPMnSj3t3l6iyvLTenropmMTwmd2fM4UsOQ1f+KAaWt/fiWT6AzAxJzSigs/quAfjJIgy3naiuGQ+HyyZHb+pXetkU7MqE3DzeYlHx77EhIHgKNglt0f8wkMbxcalVSFv0DgewN+7NcEIYpSK/cAzGNbC7j/k7+60ciK7650vXOtZEnDHPbK9Oh5AgDWfSSGp5fed3+O5rLepCS5p//NByWiIg4RM6swZUbmv1FytOvIF/AQSQtXM48l2w+KRgZwtLEhqEHOqT8fKzxS35M16gH9VX/HGm59fVLXpFTxYQzLDp+cuMMn9jKmUqu3dFYtdI94hLWnknGSVHcq9y58CV2ATMKsCNeGhrajYOx/tSqilBQuFCOAfSjEdpi9ONRIC5PZn4ksAwtHeCwz09PbIl7JgZbKjHyBnFQhFyjuEvIOyHAyc/MtxwyNpwJiQQprM3q1wes/2/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Also, anytime the mtime changes, the ctime must also change, and those are now the only two options for xfs_trans_ichgtime. Have that function unconditionally bump the ctime, and ASSERT that XFS_ICHGTIME_CHG is always set. Finally, stop setting STATX_CHANGE_COOKIE in getattr, since the ctime should give us better semantics now. Reviewed-by: Josef Bacik Reviewed-by: Darrick J. Wong Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/xfs/libxfs/xfs_trans_inode.c | 6 +++--- fs/xfs/xfs_iops.c | 10 +++------- fs/xfs/xfs_super.c | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c index 3c40f37e82c7..c962ad64b0c1 100644 --- a/fs/xfs/libxfs/xfs_trans_inode.c +++ b/fs/xfs/libxfs/xfs_trans_inode.c @@ -62,12 +62,12 @@ xfs_trans_ichgtime( ASSERT(tp); xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); - tv = current_time(inode); + /* If the mtime changes, then ctime must also change */ + ASSERT(flags & XFS_ICHGTIME_CHG); + tv = inode_set_ctime_current(inode); if (flags & XFS_ICHGTIME_MOD) inode_set_mtime_to_ts(inode, tv); - if (flags & XFS_ICHGTIME_CHG) - inode_set_ctime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_ACCESS) inode_set_atime_to_ts(inode, tv); if (flags & XFS_ICHGTIME_CREATE) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 1cdc8034f54d..a1c4a350a6db 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 27e9f749c4c7..210481b03fdb 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -2052,7 +2052,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 Wed Oct 2 18:49:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06F5FCEB2E2 for ; Wed, 2 Oct 2024 18:50:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39D054401CB; Wed, 2 Oct 2024 14:50:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 324C54401B5; Wed, 2 Oct 2024 14:50:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 178AF4401CB; Wed, 2 Oct 2024 14:50:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E15AC4401B5 for ; Wed, 2 Oct 2024 14:50:23 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8830880EF3 for ; Wed, 2 Oct 2024 18:50:23 +0000 (UTC) X-FDA: 82629552726.29.F9431D3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf02.hostedemail.com (Postfix) with ESMTP id 957A580013 for ; Wed, 2 Oct 2024 18:50:21 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Akemb1Uy; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727895000; a=rsa-sha256; cv=none; b=2pWRO6/pxDPT58wMPVEPYdOctiN4UwdtF8L/g1Q5dhT/Vgrvrxii9QPeYcuHV5R2NJhmvX +dKvOyoPJDDt5jIVlKNSpqQ+elJydAe10Ungb/Wc3hs6WU+Rplp7HpNIC50FQeGVkMqgoU E5OYQ9KV+GEPfxuFzZpZWlfMy15iu0A= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Akemb1Uy; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727895000; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EZAwKTiKQCtMiItDr7km/0EnprZestW0PNPeXfq1Yyg=; b=pJdCPhh5TOhNmILAfuoFuyHCLZHWS9MnNNV/Y5/sFlReXKb1I7xLn8nSZMmOvdObYOC/oJ JIUnpsSOviZsWduh3DQNW2Tot2GUYc95zu+9uHuZ6h7+yI9BzKMqHECQrSlQFWkLdSgjbC THowi1y9ZORPaUjtgxPAmuzusOscVBo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 90B6A5C4003; Wed, 2 Oct 2024 18:50:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9498DC4CED9; Wed, 2 Oct 2024 18:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895020; bh=17YM0jGTS4LAz/A8JflBVmBC2Z9foP+AR8Y8ijPQ/zQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Akemb1UyyNFZQmH2LT47raszKyXtRV8Opv79lAGvBUy5veSNjonNQxiw+IVzN9nCY Y+RVnuYvs8780OesSMunIUbvJkmLs38rBbM+VEUm6zd8XhOloDQGdvcDyTHJJi/V3P EgGDqjlwwWb7+G3F/ScifYFaSByiLxVRf7oD1Iqk16bnUSLTR3qZwzZkTcJhELv7Kj lrGYtzXbw+gMDzQuv0vhqauJzLndBthDbMZ11gK8h+vEx43ENsZRCo3xIpSR7Z+iLO abtnm7yB9DB1hoQnVtuPawl1gySiCzBzje93lgycsuXwwQaGDfIIYp2FhBbq5RHVnb IUgKkPV3AGzLg== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:38 -0400 Subject: [PATCH v9 10/12] ext4: switch to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-10-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=17YM0jGTS4LAz/A8JflBVmBC2Z9foP+AR8Y8ijPQ/zQ=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXNl90Ovh4yBGNYYNUjOfRa+vhMULk3F2EVv mLp/Zow2SGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzQAKCRAADmhBGVaC FcTYD/490T6GELPrEWHfHOVJ36jwwRdjutmRKiVEDi7ln7D6Vl8DndDba/fXaNQjlM2UwupkkIf nk6kqStlbV+8W9ZXduwJISOCi6IQCekXvU30NzAhKUXmwzh3gbLygwxCgWpuc5lcYpRihX3ymHj u4qIjO7elCUBpr2L06qvIFSvLUOvTUy3fXXplCywwsqhXtX0lwOM5Evq2hB24ZCC86vdX3mWAHb rlFHyQl3x5nwhmymQGFXW1RZEj4wJppf2lxHppsNw2cwP3wUrApo8vwYvK0QJyKfT3HeVPtIOTG L3FrqMXZ+0xYdJPp4akSdrhjhNpG7lYgbQojjd53suHonfTHvRf3QU2cfXw/nZZ0qcR8WoclGxF sthItaTwpvidMz47RbYM/yboSWLf+uvl7IJn+sAtUKnAd/mXKMP1M2Gvq8SpHUjlwh06qpyHZmm /wqsZByc3ICGZNsbZSdO9g9Y3pZmfv6KmVQeAXasPsDGBKOEcYL5q5z5D4+YDH8f5KOVy3eXr5i D+whU5wyxnGqIao7BD6OC2sXqDhGJ27JgwqZemBcL1eDTyz5fJkj0ZuJ6Db9p4W5c86OwbkMCB4 IPGG98gvWdzJghGcUd0Dozfd/TSPCeeDqtv4TQFIBH15fojwSDo1+J1/Io7/F/Y6kzpc9QTOuEg Kikb9wfEApjZaOw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Stat-Signature: dn54b1gxdn3p78girf1wz9dfjwpgxm4a X-Rspamd-Queue-Id: 957A580013 X-Rspamd-Server: rspam02 X-HE-Tag: 1727895021-951504 X-HE-Meta: U2FsdGVkX1+Ry9j4j/yx/Xf5qkMDqTrajg0lCIjVmAdqNgylWBqYMi0e0uJarnRbI/QNwMaQBiCgfUr1UZO5iJ3N+npZcTZ2gOpuwEdDoJkeXgcQuHiZHguOCJ9me9ln2aETdQcWHirGTULV7h+EgN46M1VVxMXhFyVoYMEwQxrxevBi9WAwmJmAy/brtOc0oUxbsoT56FwTXmi3Lpb4NK3UrhLMEihjMHcNAl9h9KYukSpXMNb9iGmhbFOf/VYqknWF7TNbGRh/Sn2ZEb4tT0uRQW/lLOAa7EqgKpqvCMhX2Zyva/IuA8PSHlv85i4GL+R8Bdq/1d3LmcSYTPia9qMv8TNY5XzNPOnxK+MmasIhcYD9rpRqzj6iX71sLBAh8TmABU1N2sx99ny4odkQvqr3zOFc68dlfZYynNX49ZMy+wwMgVHveZuiUBaWaayPmqHEu1eHIrPgLtH2s+B5FRo2OMxYhqTojiNCjcQ4yTZ4XZt/fnplyxBUKOQ+B29tTh9vX3L1+kSBkTHCROqwGHqJOp2Uc3yZGvJvBtOXoJIqLo8P4PP1VTGzBxEQhnlizhZJ/isd3I7yRwQAmRamn8BNTWvB+e8guCKMKpQ0QbbTsSGJfm7NA6yA4eNCbCt7eiyLjFm4OVbP/8NGND7qIyqGEAPG33ZZAdqDMScNJzY39MPlHS1OmeC7bi79GVQMQVzvE1uaxbG3EQO0PCDD5EpT8DISo53ZQAy+XWxi6a85pe7E0+UYyHuExtxZnt8Fo6n2ytMH9HjjO4leUX+Y/8FhqKDRlFYYkX8BhKYjBeuloLp6nd/64PSs347FFf3JNgxpvfIIHqvtQUy2Ef3LTVjKXGUFGWdVH8tgwwe96yu9iuSjhgCo7jZ46qbbodwHhILjrJbjJ6QiqjdonjmK/IEwhNqU9/u3ATsKXD7PPsDy5X+q1WzQeGtSvL3XMV9MZdWKZJXpp9V3xOOAlk9 Uekr7wvX b0sYSgeqB38FlwwNcBY/gGD70fFq3PuRzLX6JWvpP6IFsSO9jTupJ6Bq03bXZ4i1tp0ozu64nZEVWBuXnLtL1lPuoOowHC2pOo8FWcNQezo3TwnC52KL1eoQOXi03nyEJ7Mrn4bRuQbKfs6pURImyC8kO3+XjxZNe8lwWBHOF+fofhCAhgCfWtKq0g3i8U7MjHG2BsWSgzAO0EIuLvgDItFndb6Ovwy/IlbSuWnavPCXuqvHSqPOX7xCrcj0wKV9nDWMgVArW59sNq7n6OldBeHayMSc/jhr8DJYYYQ8LJ5pbfqP/F2OpfB8XJS358VCKzEftZNUETNL1O22PA5AgalIymOWYzT+AuTbzp13t/qfU0p/koIP1fE88/U1ldC4n9/s4sBn663lDQFgYakqEvDgN1vOJWqSYPE1evi/r2zZ3bhdI0IACiNmqoHzkCWruRroB77F9q3Y7i/VUe3j6LC4rZWTDqKcUkuq3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. For ext4, we only need to enable the FS_MGTIME flag. Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index e72145c4ae5a..a125d9435b8a 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7298,7 +7298,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 Wed Oct 2 18:49:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B57C6CF3189 for ; Wed, 2 Oct 2024 18:50:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC1316B028D; Wed, 2 Oct 2024 14:50:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E22DE4401B5; Wed, 2 Oct 2024 14:50:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C72AF6B028F; Wed, 2 Oct 2024 14:50:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9A0376B028A for ; Wed, 2 Oct 2024 14:50:26 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 36E4780EE4 for ; Wed, 2 Oct 2024 18:50:26 +0000 (UTC) X-FDA: 82629552852.26.A049D82 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf07.hostedemail.com (Postfix) with ESMTP id 7746F4000B for ; Wed, 2 Oct 2024 18:50:24 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=btST0E3i; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894984; a=rsa-sha256; cv=none; b=ZURt8dLfT2RkddlwI+z0TL+FOxMHNNmhdS7PqYyXUu/qk7M0jxuzZHAMEf6fvMvoc+xC/e kJnIRRsG5CUhH2Y3Yvojv5hVFxZ4S/2qfu0tgEbSPowe2GnDnvNdg3LQvhlOw5Ths+NHcN A9skIooQlznqYJ+OZxKwQug4BFG6tL0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=btST0E3i; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894984; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xijyGSIC8tg/9mUjJT0YCP6eSmyLiThSFhxgUHS3XuE=; b=iiG9tTBY3N7B4OhS4GfOOZKTUTbyOEaQWuqDGE9VSY8Df4ouo1xxyAeTU1u9f+WoPev8qj z88FZhwwiBpLph00nFYcOU9t282CROwtc23Bg4MEIW9Wpw+QUV47ucDaEuIc7fYJLBfCWk 2+xwNq452jSTa5sCLchkiQ3IDOyZyWc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id F2023A4320A; Wed, 2 Oct 2024 18:50:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB47C4CED3; Wed, 2 Oct 2024 18:50:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895022; bh=eXOv2g+6erFOUU/IZaJxbO9vQa8NYTuiShGXQ/xSzWM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=btST0E3iIz3iPli6d0XpPAZAlh8/lnqSl4ah3WBtM4T3MH8ErVcaBvT2ZWfwETiNb YUSY2+5n9NSMhGVEcYZp+qG5kWLAxDb1EAixKCNENdjIyrDNtWcYV4m2AOi8SMFl8K ZnuQFDpARMh3w3B3slkPCa5+dx0fqm3kiyQ/9McJskBSZEbVrZ64APa0EcDhymjEvO KsMDUPNCuaWpMfYPD29GYkVgR4QskGiLsO82bSgPMYXyKXU0zGiV9ozsdsXhilO4nM TVzjzTDFTCoJwDHZ4V4wRF/HPZqliH4EfLd/oQbMzYM+munWopfG4iQIN3HMAwqBLb JqT5spsL0ogRQ== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:39 -0400 Subject: [PATCH v9 11/12] btrfs: convert to multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-11-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=eXOv2g+6erFOUU/IZaJxbO9vQa8NYTuiShGXQ/xSzWM=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXNnKUmRwB5iP9mmNcvN/pr53xiTfFvvcjUC +QnCEKMk1mJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzQAKCRAADmhBGVaC FQQgEACkRH4Qq0FubBmBQFsHTewXtBTlXLGNYfrlI+kSx3fb/dOij2i7ycA8d1/UZPwNpkHi++k XUIS6mXDj/NQ0PlVoOy2k8ybTh0UDwVYHkBDXrFpsxRMc5ZiQp1C4c02RKiET8x76r5KMQJxAJF M0gS+kQEdP64e6qvSZAXIb60uNyfpQb0RV/vgoe8ZTyMC083FnyndAx4JK20ks0nKJVVFf1q5Ag GjJsW/qRwBI0K0/2BcdPNw/pDrjK+1cxRO6jvCa3FhieuIPtCo4HdZJrz0qaIhPocmvVG7UB9EL GVNc7mPk0Yml9ghjsQAFf83e9CoavPbF4to4DT7C8lS1OpwR9nAOW9g0CevmFrUPr8gs8DFmA9I NApVjZlKEnzB0/BbktFG0a1YHet7mfjLdc8oYAiVGj7ycClsAA6dJq4iAvCmh0ozZTgmm5z3RPn EVGKKh8uY++mprUufcphF/TFPLZ6GIefT9oyPyB9CuzwA2AHIMrgbHCo7SKBLv+skxmUVWWGOuc uV03HX6PSiTSaGPvSTDszi7aYP/T0HoMNdGQ+Pv9H02o/RT/W0NoWemRDo5TzttOUiaTVosx7/7 AT9c434zhUstN3P4O7zU98K/VnOls+ZOd3sSblMmPfcBpMx0vgLQYDx33M8XWHDwgVP8ZulNMtI 2nSsA/v1yvbCVfw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspam-User: X-Rspamd-Queue-Id: 7746F4000B X-Rspamd-Server: rspam01 X-Stat-Signature: 3jh9hjadrd6hi6qjgtgp7j4umerdm5fa X-HE-Tag: 1727895024-882396 X-HE-Meta: U2FsdGVkX19eeWSNnVLRrqnuFKZCdZGfCbfJTmfdw17TaUGjgCVl2uvXW/NYGiv91jfDD4sBBC+zAWjnAD124BAapyvK4aPdi0KdAGhJpOtuvR0upv5J5LzBGr4ZLoBVfKPpZpxqzgWpCYZ5rP9kW6PUfbXDn0i0aQLVipUPMZ7Vc9hHzc7mMeR4QJEwABoS4QT7GkAqZt/Oyt3iiTFtta92wRAfHTbcCmFOUWlBVdGkmWS/a8iAIGd8FhPV/35AX3olzVgeo3a4Cw0yJ67ZunyPfK5oAfsTM9qGaqN58jb0aFBEocmb7ACB+k7m63+8xzUIhO4ZFvF9wMb/amqyqdfyHff5xpeKVkcDnlARcLf+C+LG0HS675pust0Lk8BX0LADE113fT2dcH+0Tjr1EAfwtqj7amXyeQLYp75p2we81LXBjoQCCO7RmAB0vxmjGPOB9dqJARzZx1GHo3xUSgq+rCvn2/ujH4arieXH5ua4LuWCf6cagTrCM/o1nqdZ6PjR2zHEzj+5LJQJCYFDZufRBeMRu5bdy9jG1N3B1c8eKnBE6eTOoXXUZzQ0dCoiD1hVxYfsp2c5fSCs9YdI6LYXP0N66Dy83b5aJ4A7xU37ok4S3qyUqSINKDatS+nFH8A+wVmXRlKAPGeJl6ebqQuqKuC0pOVW30GBmKzuqOhtZ7YGbH98c5Z+lnpBofcJSx327NV0bUMIl7TVPqBi9HT6J6cotXzARCm5pfjUFVBLw5OGz6YKKXh2cw/fYUHzzvcnqEMNokKAYEogJwT+kKatP69oF2CjyNKNkptrXFbCEbdAUtawZ5snNWo7FsT0XlWoZx0mUa5DW6h2AWE1/fZOZG+Ss5XLFJxzxvN5iSOyscEi0C1begtonHT9AZWqJxrGW+pCZCMQ45qcE8Nhoouz1qnDWS1D9SslQShksfjm4aaSSNggN3TUqqr4s54yfEpob9HTnGeH8rLfSPl dq8UjyZD J24Et59c65apPEWcO0BkQkb0ROkQ5f4OCMpoB1fPMFR14yJq+78zNJwAng2Os0j10tGYhiequr0yNVhI7WF5Atr03348kLSwYAWTDHoW8GUm0sZE2GphGoPNnadJcfEVPr3irZFZZnKb5Zp5Xnj74lSNFxNV2wrE1QjOrdU3hj52cUPWg5uolzE2LIU6BKr0sQTlf+4KlVlIYtWXc65GAUhly7vE7lnN83J7d/2EvKiZiT7F8jdos/4shUG51lKsFa26wdR8q6iBDYPdcW+WG9H+coKZKf5S/uaLDgVfVsv0n+Jy4A11SkDISgcwI8sp5OvSpZntCV5kCbcPMB1Cyq53SgORvAh3L+uNubf/RsiC+J5Iuu2wbdwuFzv4gFwRRi5hH5/NQuOIoeXYa0LadGI/cRuY6GbiJSeSTTTe+1SkkXU6zlakh3oGz1G7HuMvxW9hXFAF+GIAOG/PD0xa3JjN0Wg74zniWFJaA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. Beyond enabling the FS_MGTIME flag, this patch eliminates update_time_for_write, which goes to great pains to avoid in-memory stores. Just have it overwrite the timestamps unconditionally. Note that this also drops the IS_I_VERSION check and unconditionally bumps the change attribute, since SB_I_VERSION is always set on btrfs. Reviewed-by: Josef Bacik Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- fs/btrfs/file.c | 25 ++++--------------------- fs/btrfs/super.c | 3 ++- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 2aeb8116549c..1656ad7498b8 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 Wed Oct 2 18:49:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13820263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49BCBCEB2E2 for ; Wed, 2 Oct 2024 18:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A5B74401CC; Wed, 2 Oct 2024 14:50:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 855724401B5; Wed, 2 Oct 2024 14:50:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D2AE4401CC; Wed, 2 Oct 2024 14:50:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3F9C24401B5 for ; Wed, 2 Oct 2024 14:50:29 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D5D6F40E2D for ; Wed, 2 Oct 2024 18:50:28 +0000 (UTC) X-FDA: 82629552936.29.1BAC40C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 1083BA0006 for ; Wed, 2 Oct 2024 18:50:26 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O6KA5467; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727894932; a=rsa-sha256; cv=none; b=t8uutLRRNVevP/Ns4vFi+PbndVMbPrqveceJNG/UfIACBNd5rpBPAsZE90gcU4iFgm8s9I rdcQTQ8i1xdd8J81oeYSs2W9CKtIY6B+gls6bMVQy0JrCVFz9CL7fGq/I2e+DLtzIrTHRV JE0gXeYPGZmjVBYDvI2evhL584t3yFI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O6KA5467; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of jlayton@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727894932; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tWU7JuiIG/52a9xPGSB/o0KYOU8XDZUsmY4PohQfE28=; b=pvTkN5kUoKfh9B0/pfgvRgDo+hUvi3l810YqvSzwH8KyRADxnPXLuRE/jaeEJEHKO61E9k DbqworTsfHf/VUqHkVu0HURP59q49cDliBQUt10fHpXCIoVf80HK4prEWUzRdQF25rg+cY 7Dn51H8SBrZA9jFv13IDYT2/iZ/qc1w= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 063D85C4248; Wed, 2 Oct 2024 18:50:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DCDFC4CED6; Wed, 2 Oct 2024 18:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727895025; bh=XlC7YeycewlZi2a3r3W7IO7Qd7YSP47/MVJ/d8lrj20=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=O6KA5467Sbp5TN0nr9okSkPDnFzH6zjeE7j6psU2LHS76B0vrpzt9XXInhnHpKxj6 IJs1st80UCkJwLsitlK7096E6X9jQZ7DAweZwN5sVJy+FC2ISbg1SbXK3VGPenYxEk U1IAgYoMVkepjPYtM/hR3yd7lJxl9NKfOImCUoaQR4qRm/5o/Tv+wRjtMzSXJXvoRk icvbBr7WDPMt13T6kpBcJ1IQsUsshFCn4l47xcRCfIkm/Pt+BUR0EEtuogKsRctilw Z7ryrSB373dkJA5xHGzMG+5E8MF7Q282D9nx7DfVsDLyUd396fvwKC8xgFkLfmt5Pi CNEBkjUV9IVeQ== From: Jeff Layton Date: Wed, 02 Oct 2024 14:49:40 -0400 Subject: [PATCH v9 12/12] tmpfs: add support for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241002-mgtime-v9-12-77e2baad57ac@kernel.org> References: <20241002-mgtime-v9-0-77e2baad57ac@kernel.org> In-Reply-To: <20241002-mgtime-v9-0-77e2baad57ac@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=XlC7YeycewlZi2a3r3W7IO7Qd7YSP47/MVJ/d8lrj20=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBm/ZXN6h1nh3Jd6jDRqtordF48NCXbHTMIIvKYt k0JvUmUUnGJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZv2VzQAKCRAADmhBGVaC Feo8D/41p25TrFB0UfY7raME3RSw3V2+1l+VzsBd4T4VUALomAlvpx4rASZanyQ4quJ03pKkB6s rQ9nT3rVtZ+El2EmDy69MXcp8S4KT6MYsiE3NYuVD68oO/NzqNxYUJqM+iSlB7dOB9VONqcos/D uuLiZrD4b/K1jV8heLBwjcXK5mn0koIux75p1x/JCycT5gLRXS2ADRz0cntSbdRPheNG+QcWJtP kt1yBPc6JbSDnXd7F7W+ouC3SylDJfAntabc8Xi0Wns5/8XFWcLjMw0xCsW3dGwbIl8o0O8GEd1 eSpRT0khfdmm2ovPwC9gPXrrQPRdD+ZeEB1o8iUUhQ4LZmc8DWRL5sQ8gDH30E0P748Z/x/QvL1 dTNj80QaMOjeDyzEczN/3basPLVSn6FmAJMSHy04/Q48JvoMbBlLDfaNqlMSg8BT5WneKtii63O VYAAGC+sHZBu/sCKkSE49A4yZZ11DWlK5lD8zYO6BxmQMkhQ/X8weMwUFlZz5jwnFO6dZOtoFg1 RwtHKlDJSUn37SiERYT+bS9JfPGzMDXPW4grx9yYoHTgw9K3MvbsLBlXqCNU5SkAH+HY8mkKr40 MQom1aU4ONpgq+6oOFh1kuv+sb4AUhpUCpPaSDInyl1cNw2X4crJh9AJQR6ujOvMOCbLK9NjmRi F8V1mxt8ohQeGyw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 1083BA0006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6m358eckr63oy6oj3m94zaqmoeih96ui X-HE-Tag: 1727895026-166911 X-HE-Meta: U2FsdGVkX19+wZ4Kj39EDvm2YdWHF/dlF45mxhLomywYtfWIbLrqcKpWmlZGVZTdUCcLzmNFeai/lped42KxYHzMxrf2vCPzsuq6FPADt2/DRTM+mVRAuDvb7lUcQBMydDpiSnW/DLs38NvYUOgHlypJQP6vm0rXHcJoi3I9qeDFHtUYKC5lHhcGVqXJfRZKNyCtHJD9pVI/s6Un6Lg9IH0uJToHdHVhG0NRQKDo2waX/uDwfB5csMfnvA35+immaInTgV3x+r5EqftcCzLPypl4fnGkVnEsEwTRgSdoRR2jt14rv4vFBGraoNWJ5LNoHnFW+tWGqyGwsImKcR0RUZ0edAJfF4emE//+DjSY3kf4arqScVTWlfz6j6gQOULu6jJbVWU7JxfOGP1S3c+v/CFvrrGwXYir37aUrPfNimEEBXo6yT3iM9SAJlMLxQ37XZHAkmq5DdtDGsP+uLEzzjwnSRgbH0LoZv3uTluvnxOxODjqKSVhDc/pLjen/l2NgLYIp55ad++dPDaSJIx+7+0PaBTCJlwLzi3xLbREFjzm/ronvvIpPcjeQTaSfHGt9DG1lu20u3eKjSJDc7vbF1C3F5t6uU4izvrLG/Gu5mmPYa3EBuqT/Gfn2oyxJGbY1PG4gGucv4N0ogaMtxGoM2COxK63jHgwFQyXZUtkPArn/fDs6Xv9+3IJSVdPVPLIfYg/hchtyb0KxZDxK/6p2/MiyQWc4/qDI+JA69laYcs3721TF4Htlv0g5yvGgKLHLlP5KweK+c1YbmoiIMBW4NLmNbfC0CT3mHHxVQqCiAjMnmPIDv2EiQGFOOq6DN1kyW+0x3vfo8Um+tyRNqfmMtpfbiJfaYCJBeo58KAjtGwapR8eHLVBLGouMZS6su8g0Hl4c8E++lA0zvx0i2K/hGUCa0OtY362Nbqt9SsfHnv0AaT5hB5PX6pOTYIUyC3Cmf0OzeVduMJwZNNlXDe CjzS4Dg4 A8tkCpW8dYzLCNiZByRzx9HWRG+HUPuDo2t6rqFNswTwqe4nanPA7Eg3oe9l7LNsGrzcLP6k1PYmyTtzfp56OI4YwMtKmfAm7K5U8/sXi+5u7LZ+aY8PvlsXDF7zdRjGqnItLKp21o+cGoYcPZd/y7Dfm+5+PZT8NEZhDCIGAFuiHpCqhvE4sAPYX4i4vgCU2ihjEHrnAI6spQC9R2KMdiXuSP40kE93VaEqb3oqsQqmDBaEeRZebI3amYnfnCiqKi+TnNMVRaaD89V5DlZVfQHZRQXh+mtzrdNzmXcWJ85xPd9YVCW8iTjksTjuFAZrSp7j1Bkc3mLfwrAiAbH2CBwsK0hjQ9XH8yyjUfkPca+bWvsTYUvZCmMlhNdXggXqcti7AThSGVINQ9Nu3iBbBt+W0/6iMzMB9NgyrwvPWXw/2MirxI31ORTLA1Ba4v57nuZVC9a9B6T4g9lFZ5l86qen6hlwcBONtfmgj X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr. tmpfs only requires the FS_MGTIME flag. Reviewed-by: Josef Bacik Reviewed-by: Jan Kara Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton --- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5a77acf6ac6a..5f17eaaa32e2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4804,7 +4804,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)