[PATCH] jfs: wrap statistics counters with data_race()

Cen Zhang posted 1 patch 3 weeks ago
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(-)
[PATCH] jfs: wrap statistics counters with data_race()
Posted by Cen Zhang 3 weeks ago
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