summaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_linux.h
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2023-10-16 09:40:11 -0700
committerDarrick J. Wong <djwong@kernel.org>2023-10-17 16:26:25 -0700
commitef5a83b7e597038d1c734ddb4bc00638082c2bf1 (patch)
tree9b5aa12266f11b3748c81079e004f6d5ecfc4640 /fs/xfs/xfs_linux.h
parent5f57f7309d9ab9d24d50c5707472b1ed8af4eabc (diff)
downloadlinux-stable-ef5a83b7e597038d1c734ddb4bc00638082c2bf1.tar.gz
linux-stable-ef5a83b7e597038d1c734ddb4bc00638082c2bf1.tar.bz2
linux-stable-ef5a83b7e597038d1c734ddb4bc00638082c2bf1.zip
xfs: use shifting and masking when converting rt extents, if possible
Avoid the costs of integer division (32-bit and 64-bit) if the realtime extent size is a power of two. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/xfs_linux.h')
-rw-r--r--fs/xfs/xfs_linux.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index e9d317a3dafe..d7873e0360f0 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -198,6 +198,18 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y)
return x;
}
+/* If @b is a power of 2, return log2(b). Else return -1. */
+static inline int8_t log2_if_power2(unsigned long b)
+{
+ return is_power_of_2(b) ? ilog2(b) : -1;
+}
+
+/* If @b is a power of 2, return a mask of the lower bits, else return zero. */
+static inline unsigned long long mask64_if_power2(unsigned long b)
+{
+ return is_power_of_2(b) ? b - 1 : 0;
+}
+
int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
char *data, enum req_op op);