xfs: reduce the rate of cond_resched calls inside scrub
authorDarrick J. Wong <djwong@kernel.org>
Mon, 22 Apr 2024 16:48:23 +0000 (09:48 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 23 Apr 2024 23:55:17 +0000 (16:55 -0700)
commit271557de7cbfdecb08e89ae1ca74647ceb57224f
tree75935093e4f7e4a38a34523211bda8d95b7555ff
parent3f31406aef493b3f19020909d29974e28253f91c
xfs: reduce the rate of cond_resched calls inside scrub

We really don't want to call cond_resched every single time we go
through a loop in scrub -- there may be billions of records, and probing
into the scheduler itself has overhead.  Reduce this overhead by only
calling cond_resched 10x per second; and add a counter so that we only
check jiffies once every 1000 records or so.

Surprisingly, this reduces scrub-only fstests runtime by about 2%.  I
used the bmapinflate xfs_db command to produce a billion-extent file and
this stupid gadget reduced the scrub runtime by about 4%.

From a stupid microbenchmark of calling these things 1 billion times, I
estimate that cond_resched costs about 5.5ns per call; jiffes costs
about 0.3ns per read; and fatal_signal_pending costs about 0.4ns per
call.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/scrub/common.h
fs/xfs/scrub/scrub.c
fs/xfs/scrub/scrub.h
fs/xfs/scrub/xfarray.c
fs/xfs/scrub/xfarray.h
fs/xfs/scrub/xfile.c