From: cem@kernel.org
To: linux-xfs@vger.kernel.org
Subject: [PATCH 16/35] xfs: use shifting and masking when converting rt extents, if possible
Date: Thu, 15 Feb 2024 13:08:28 +0100 [thread overview]
Message-ID: <20240215120907.1542854-17-cem@kernel.org> (raw)
In-Reply-To: <20240215120907.1542854-1-cem@kernel.org>
From: "Darrick J. Wong" <djwong@kernel.org>
Source kernel commit: ef5a83b7e597038d1c734ddb4bc00638082c2bf1
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>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
include/xfs_mount.h | 2 ++
libxfs/libxfs_priv.h | 24 ++++++++++++++++++++++++
libxfs/xfs_rtbitmap.h | 29 +++++++++++++++++++++++++++++
libxfs/xfs_sb.c | 2 ++
4 files changed, 57 insertions(+)
diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index 9adc1f898..98d5b199d 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -71,6 +71,7 @@ typedef struct xfs_mount {
uint8_t m_blkbb_log; /* blocklog - BBSHIFT */
uint8_t m_sectbb_log; /* sectorlog - BBSHIFT */
uint8_t m_agno_log; /* log #ag's */
+ int8_t m_rtxblklog; /* log2 of rextsize, if possible */
uint m_blockmask; /* sb_blocksize-1 */
uint m_blockwsize; /* sb_blocksize in words */
uint m_blockwmask; /* blockwsize-1 */
@@ -93,6 +94,7 @@ typedef struct xfs_mount {
struct radix_tree_root m_perag_tree;
uint64_t m_features; /* active filesystem features */
uint64_t m_low_space[XFS_LOWSP_MAX];
+ uint64_t m_rtxblkmask; /* rt extent block mask */
unsigned long m_opstate; /* dynamic state flags */
bool m_finobt_nores; /* no per-AG finobt resv. */
uint m_qflags; /* quota status flags */
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index ed437e38e..30ff8dba9 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -323,6 +323,30 @@ roundup_pow_of_two(uint v)
return 0;
}
+/* If @b is a power of 2, return log2(b). Else return -1. */
+static inline int8_t log2_if_power2(unsigned long b)
+{
+ unsigned long mask = 1;
+ unsigned int i;
+ unsigned int ret = 1;
+
+ if (!is_power_of_2(b))
+ return -1;
+
+ for (i = 0; i < NBBY * sizeof(unsigned long); i++, mask <<= 1) {
+ if (b & mask)
+ ret = i;
+ }
+
+ return ret;
+}
+
+/* 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;
+}
+
/* buffer management */
#define XBF_TRYLOCK 0
#define XBF_UNMAPPED 0
diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h
index ecf5645dd..3686a53e0 100644
--- a/libxfs/xfs_rtbitmap.h
+++ b/libxfs/xfs_rtbitmap.h
@@ -11,6 +11,9 @@ xfs_rtx_to_rtb(
struct xfs_mount *mp,
xfs_rtxnum_t rtx)
{
+ if (mp->m_rtxblklog >= 0)
+ return rtx << mp->m_rtxblklog;
+
return rtx * mp->m_sb.sb_rextsize;
}
@@ -19,6 +22,9 @@ xfs_rtxlen_to_extlen(
struct xfs_mount *mp,
xfs_rtxlen_t rtxlen)
{
+ if (mp->m_rtxblklog >= 0)
+ return rtxlen << mp->m_rtxblklog;
+
return rtxlen * mp->m_sb.sb_rextsize;
}
@@ -28,6 +34,9 @@ xfs_extlen_to_rtxmod(
struct xfs_mount *mp,
xfs_extlen_t len)
{
+ if (mp->m_rtxblklog >= 0)
+ return len & mp->m_rtxblkmask;
+
return len % mp->m_sb.sb_rextsize;
}
@@ -36,6 +45,9 @@ xfs_extlen_to_rtxlen(
struct xfs_mount *mp,
xfs_extlen_t len)
{
+ if (mp->m_rtxblklog >= 0)
+ return len >> mp->m_rtxblklog;
+
return len / mp->m_sb.sb_rextsize;
}
@@ -45,6 +57,9 @@ xfs_rtb_to_rtx(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
+ if (likely(mp->m_rtxblklog >= 0))
+ return rtbno >> mp->m_rtxblklog;
+
return div_u64(rtbno, mp->m_sb.sb_rextsize);
}
@@ -54,6 +69,9 @@ xfs_rtb_to_rtxoff(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
+ if (likely(mp->m_rtxblklog >= 0))
+ return rtbno & mp->m_rtxblkmask;
+
return do_div(rtbno, mp->m_sb.sb_rextsize);
}
@@ -67,6 +85,11 @@ xfs_rtb_to_rtxrem(
xfs_rtblock_t rtbno,
xfs_extlen_t *off)
{
+ if (likely(mp->m_rtxblklog >= 0)) {
+ *off = rtbno & mp->m_rtxblkmask;
+ return rtbno >> mp->m_rtxblklog;
+ }
+
return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
}
@@ -79,6 +102,12 @@ xfs_rtb_to_rtxup(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
+ if (likely(mp->m_rtxblklog >= 0)) {
+ if (rtbno & mp->m_rtxblkmask)
+ return (rtbno >> mp->m_rtxblklog) + 1;
+ return rtbno >> mp->m_rtxblklog;
+ }
+
if (do_div(rtbno, mp->m_sb.sb_rextsize))
rtbno++;
return rtbno;
diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
index 01935017c..1ebdb7ec4 100644
--- a/libxfs/xfs_sb.c
+++ b/libxfs/xfs_sb.c
@@ -973,6 +973,8 @@ xfs_sb_mount_common(
mp->m_blockmask = sbp->sb_blocksize - 1;
mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
mp->m_blockwmask = mp->m_blockwsize - 1;
+ mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize);
+ mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize);
mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
--
2.43.0
next prev parent reply other threads:[~2024-02-15 12:09 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 12:08 [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 cem
2024-02-15 12:08 ` [PATCH 01/35] xfs: bump max fsgeom struct version cem
2024-02-15 12:08 ` [PATCH 02/35] xfs: hoist freeing of rt data fork extent mappings cem
2024-02-15 12:08 ` [PATCH 03/35] xfs: fix units conversion error in xfs_bmap_del_extent_delay cem
2024-02-15 12:08 ` [PATCH 04/35] xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h cem
2024-02-15 12:08 ` [PATCH 05/35] xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator cem
2024-02-15 12:08 ` [PATCH 06/35] xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t cem
2024-02-15 12:08 ` [PATCH 07/35] xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t cem
2024-02-15 12:08 ` [PATCH 08/35] xfs: rename xfs_verify_rtext to xfs_verify_rtbext cem
2024-02-15 12:08 ` [PATCH 09/35] xfs: convert rt extent numbers to xfs_rtxnum_t cem
2024-02-15 12:08 ` [PATCH 10/35] xfs: create a helper to convert rtextents to rtblocks cem
2024-02-15 12:08 ` [PATCH 11/35] xfs: create a helper to compute leftovers of realtime extents cem
2024-02-15 12:08 ` [PATCH 12/35] xfs: create a helper to convert extlen to rtextlen cem
2024-02-15 12:08 ` [PATCH 13/35] xfs: create helpers to convert rt block numbers to rt extent numbers cem
2024-02-15 12:08 ` [PATCH 14/35] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls cem
2024-02-15 12:08 ` [PATCH 15/35] xfs: create rt extent rounding helpers for realtime extent blocks cem
2024-02-15 12:08 ` cem [this message]
2024-02-15 12:08 ` [PATCH 17/35] xfs: convert the rtbitmap block and bit macros to static inline functions cem
2024-02-15 12:08 ` [PATCH 18/35] xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros cem
2024-02-15 12:08 ` [PATCH 19/35] xfs: convert open-coded xfs_rtword_t pointer accesses to helper cem
2024-02-15 12:08 ` [PATCH 20/35] xfs: convert rt summary macros to helpers cem
2024-02-15 12:08 ` [PATCH 21/35] xfs: convert to new timestamp accessors cem
2024-02-15 12:08 ` [PATCH 22/35] xfs: create helpers for rtbitmap block/wordcount computations cem
2024-02-15 12:08 ` [PATCH 23/35] xfs: create a helper to handle logging parts of rt bitmap/summary blocks cem
2024-02-15 12:08 ` [PATCH 24/35] xfs: use accessor functions for bitmap words cem
2024-02-15 12:08 ` [PATCH 25/35] xfs: create helpers for rtsummary block/wordcount computations cem
2024-02-15 12:08 ` [PATCH 26/35] xfs: use accessor functions for summary info words cem
2024-02-15 12:08 ` [PATCH 27/35] xfs: consolidate realtime allocation arguments cem
2024-02-15 12:08 ` [PATCH 28/35] xfs: cache last bitmap block in realtime allocator cem
2024-02-15 12:08 ` [PATCH 29/35] xfs: simplify xfs_rtbuf_get calling conventions cem
2024-02-15 12:08 ` [PATCH 30/35] xfs: simplify rt bitmap/summary block accessor functions cem
2024-02-15 12:08 ` [PATCH 31/35] xfs: invert the realtime summary cache cem
2024-02-15 12:08 ` [PATCH 32/35] xfs: factor out xfs_defer_pending_abort cem
2024-02-15 12:08 ` [PATCH 33/35] xfs: abort intent items when recovery intents fail cem
2024-02-15 12:08 ` [PATCH 34/35] xfs: fix internal error from AGFL exhaustion cem
2024-02-15 12:08 ` [PATCH 35/35] xfs: inode recovery does not validate the recovered inode cem
2024-02-16 7:11 ` [PATCH 00/35] xfsprogs: libxfs-sync for 6.7 Christoph Hellwig
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=20240215120907.1542854-17-cem@kernel.org \
--to=cem@kernel.org \
--cc=linux-xfs@vger.kernel.org \
/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