mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cen Zhang <zzzccc427@gmail.com>
To: shaggy@kernel.org
Cc: jfs-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
	r33s3n6@gmail.com, gality369@gmail.com, zhenghaoran154@gmail.com,
	hanguidong02@gmail.com, ziyuzhang201@gmail.com,
	Cen Zhang <zzzccc427@gmail.com>
Subject: [PATCH] jfs: wrap statistics counters with data_race()
Date: Mon, 16 Mar 2026 15:03:03 +0800	[thread overview]
Message-ID: <20260316070303.2868076-1-zzzccc427@gmail.com> (raw)

JFS uses global statistics counters (lmStat, mpStat, xtStat, TxStat)
that are incremented from multiple contexts (writeback workqueue, IO
kthread, syscall paths) without any lock. The INCREMENT()/DECREMENT()/
HIGHWATERMARK() macros expand to plain C read-modify-write operations:

    #define INCREMENT(x) ((x)++)

These counters are purely informational and only read via /proc for
diagnostic purposes. A concurrent lost increment is acceptable for
approximate statistics. However, the plain C accesses are formally
undefined under LKMM.

Wrap the statistics macro definitions with data_race() to document
that these races are intentional and benign. Also annotate the
proc_show read sides for completeness.

Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
 fs/jfs/jfs_debug.h    |  8 ++++----
 fs/jfs/jfs_logmgr.c   | 10 +++++-----
 fs/jfs/jfs_metapage.c |  6 +++---
 fs/jfs/jfs_txnmgr.c   | 18 +++++++++---------
 fs/jfs/jfs_xtree.c    |  6 +++---
 5 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/fs/jfs/jfs_debug.h b/fs/jfs/jfs_debug.h
index 48e2150c092e..d0441116c5c0 100644
--- a/fs/jfs/jfs_debug.h
+++ b/fs/jfs/jfs_debug.h
@@ -97,13 +97,13 @@ int jfs_txstats_proc_show(struct seq_file *m, void *v);
 int jfs_mpstat_proc_show(struct seq_file *m, void *v);
 int jfs_xtstat_proc_show(struct seq_file *m, void *v);
 
-#define	INCREMENT(x)		((x)++)
-#define	DECREMENT(x)		((x)--)
-#define	HIGHWATERMARK(x,y)	((x) = max((x), (y)))
+#define	INCREMENT(x)		(data_race((x)++))
+#define	DECREMENT(x)		(data_race((x)--))
+#define	HIGHWATERMARK(x, y)	(data_race((x) = max(data_race(x), (y))))
 #else
 #define	INCREMENT(x)
 #define	DECREMENT(x)
-#define	HIGHWATERMARK(x,y)
+#define	HIGHWATERMARK(x, y)
 #endif				/* CONFIG_JFS_STATISTICS */
 
 #endif				/* _H_JFS_DEBUG */
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index ada00d5bc214..c18311805521 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -2481,11 +2481,11 @@ int jfs_lmstats_proc_show(struct seq_file *m, void *v)
 		       "writes completed = %d\n"
 		       "full pages submitted = %d\n"
 		       "partial pages submitted = %d\n",
-		       lmStat.commit,
-		       lmStat.submitted,
-		       lmStat.pagedone,
-		       lmStat.full_page,
-		       lmStat.partial_page);
+		       data_race(lmStat.commit),
+		       data_race(lmStat.submitted),
+		       data_race(lmStat.pagedone),
+		       data_race(lmStat.full_page),
+		       data_race(lmStat.partial_page));
 	return 0;
 }
 #endif /* CONFIG_JFS_STATISTICS */
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 64c6eaa7f3f2..675f664cbe9d 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -944,9 +944,9 @@ int jfs_mpstat_proc_show(struct seq_file *m, void *v)
 		       "page allocations = %d\n"
 		       "page frees = %d\n"
 		       "lock waits = %d\n",
-		       mpStat.pagealloc,
-		       mpStat.pagefree,
-		       mpStat.lockwait);
+		       data_race(mpStat.pagealloc),
+		       data_race(mpStat.pagefree),
+		       data_race(mpStat.lockwait));
 	return 0;
 }
 #endif
diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
index c16578af3a77..51be07337c7a 100644
--- a/fs/jfs/jfs_txnmgr.c
+++ b/fs/jfs/jfs_txnmgr.c
@@ -3006,15 +3006,15 @@ int jfs_txstats_proc_show(struct seq_file *m, void *v)
 		       "txBeginAnon blocked by tlocks low = %d\n"
 		       "calls to txLockAlloc = %d\n"
 		       "tLockAlloc blocked by no free lock = %d\n",
-		       TxStat.txBegin,
-		       TxStat.txBegin_barrier,
-		       TxStat.txBegin_lockslow,
-		       TxStat.txBegin_freetid,
-		       TxStat.txBeginAnon,
-		       TxStat.txBeginAnon_barrier,
-		       TxStat.txBeginAnon_lockslow,
-		       TxStat.txLockAlloc,
-		       TxStat.txLockAlloc_freelock);
+		       data_race(TxStat.txBegin),
+		       data_race(TxStat.txBegin_barrier),
+		       data_race(TxStat.txBegin_lockslow),
+		       data_race(TxStat.txBegin_freetid),
+		       data_race(TxStat.txBeginAnon),
+		       data_race(TxStat.txBeginAnon_barrier),
+		       data_race(TxStat.txBeginAnon_lockslow),
+		       data_race(TxStat.txLockAlloc),
+		       data_race(TxStat.txLockAlloc_freelock));
 	return 0;
 }
 #endif
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index 28c3cf960c6f..d786914d98fe 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -2922,9 +2922,9 @@ int jfs_xtstat_proc_show(struct seq_file *m, void *v)
 		       "searches = %d\n"
 		       "fast searches = %d\n"
 		       "splits = %d\n",
-		       xtStat.search,
-		       xtStat.fastSearch,
-		       xtStat.split);
+		       data_race(xtStat.search),
+		       data_race(xtStat.fastSearch),
+		       data_race(xtStat.split));
 	return 0;
 }
 #endif
-- 
2.34.1


                 reply	other threads:[~2026-03-16  7:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316070303.2868076-1-zzzccc427@gmail.com \
    --to=zzzccc427@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=gality369@gmail.com \
    --cc=hanguidong02@gmail.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=r33s3n6@gmail.com \
    --cc=shaggy@kernel.org \
    --cc=zhenghaoran154@gmail.com \
    --cc=ziyuzhang201@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®