* [f2fs-dev] [PATCH] f2fs: annotate lockless last_time[] accesses
@ 2026-05-06 1:07 Cen Zhang
2026-05-09 13:17 ` Chao Yu via Linux-f2fs-devel
2026-05-11 1:41 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
0 siblings, 2 replies; 3+ messages in thread
From: Cen Zhang @ 2026-05-06 1:07 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: baijiaju1990, Cen Zhang, linux-kernel, linux-f2fs-devel
f2fs stores mount-wide activity timestamps in sbi->last_time[] and
samples them from background discard, GC, and balance paths without a
dedicated lock. The timestamps are used as best-effort heuristics to
decide whether background work should run now or sleep a bit longer.
The current helpers use plain loads and stores, so KCSAN can report races
between frequent foreground updates and background readers. Exact
freshness is not required here, but the intentional lockless accesses
should be marked explicitly.
Use WRITE_ONCE() in f2fs_update_time() and READ_ONCE() in
f2fs_time_over() and f2fs_time_to_wait(). This preserves the existing
heuristic behavior and avoids adding locking to hot paths.
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
fs/f2fs/f2fs.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 65c0d20df3a4..f838acc2f7a0 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2121,12 +2121,12 @@ static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
{
unsigned long now = jiffies;
- sbi->last_time[type] = now;
+ WRITE_ONCE(sbi->last_time[type], now);
/* DISCARD_TIME and GC_TIME are based on REQ_TIME */
if (type == REQ_TIME) {
- sbi->last_time[DISCARD_TIME] = now;
- sbi->last_time[GC_TIME] = now;
+ WRITE_ONCE(sbi->last_time[DISCARD_TIME], now);
+ WRITE_ONCE(sbi->last_time[GC_TIME], now);
}
}
@@ -2134,7 +2134,7 @@ static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
{
unsigned long interval = sbi->interval_time[type] * HZ;
- return time_after(jiffies, sbi->last_time[type] + interval);
+ return time_after(jiffies, READ_ONCE(sbi->last_time[type]) + interval);
}
static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi,
@@ -2144,7 +2144,7 @@ static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi,
unsigned int wait_ms = 0;
long delta;
- delta = (sbi->last_time[type] + interval) - jiffies;
+ delta = (READ_ONCE(sbi->last_time[type]) + interval) - jiffies;
if (delta > 0)
wait_ms = jiffies_to_msecs(delta);
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: annotate lockless last_time[] accesses
2026-05-06 1:07 [f2fs-dev] [PATCH] f2fs: annotate lockless last_time[] accesses Cen Zhang
@ 2026-05-09 13:17 ` Chao Yu via Linux-f2fs-devel
2026-05-11 1:41 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-05-09 13:17 UTC (permalink / raw)
To: Cen Zhang, jaegeuk; +Cc: baijiaju1990, linux-kernel, linux-f2fs-devel
On 5/6/26 09:07, Cen Zhang wrote:
> f2fs stores mount-wide activity timestamps in sbi->last_time[] and
> samples them from background discard, GC, and balance paths without a
> dedicated lock. The timestamps are used as best-effort heuristics to
> decide whether background work should run now or sleep a bit longer.
>
> The current helpers use plain loads and stores, so KCSAN can report races
> between frequent foreground updates and background readers. Exact
> freshness is not required here, but the intentional lockless accesses
> should be marked explicitly.
>
> Use WRITE_ONCE() in f2fs_update_time() and READ_ONCE() in
> f2fs_time_over() and f2fs_time_to_wait(). This preserves the existing
> heuristic behavior and avoids adding locking to hot paths.
>
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: annotate lockless last_time[] accesses
2026-05-06 1:07 [f2fs-dev] [PATCH] f2fs: annotate lockless last_time[] accesses Cen Zhang
2026-05-09 13:17 ` Chao Yu via Linux-f2fs-devel
@ 2026-05-11 1:41 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2026-05-11 1:41 UTC (permalink / raw)
To: Cen Zhang; +Cc: baijiaju1990, jaegeuk, linux-kernel, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Wed, 6 May 2026 09:07:09 +0800 you wrote:
> f2fs stores mount-wide activity timestamps in sbi->last_time[] and
> samples them from background discard, GC, and balance paths without a
> dedicated lock. The timestamps are used as best-effort heuristics to
> decide whether background work should run now or sleep a bit longer.
>
> The current helpers use plain loads and stores, so KCSAN can report races
> between frequent foreground updates and background readers. Exact
> freshness is not required here, but the intentional lockless accesses
> should be marked explicitly.
>
> [...]
Here is the summary with links:
- [f2fs-dev] f2fs: annotate lockless last_time[] accesses
https://git.kernel.org/jaegeuk/f2fs/c/c4bbbc96e530
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-11 1:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06 1:07 [f2fs-dev] [PATCH] f2fs: annotate lockless last_time[] accesses Cen Zhang
2026-05-09 13:17 ` Chao Yu via Linux-f2fs-devel
2026-05-11 1:41 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox