summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2023-04-11 19:00:34 -0700
committerDarrick J. Wong <djwong@kernel.org>2023-04-11 19:00:34 -0700
commit674f0d0dc6b5b2228c4e9d597a62d5aa6b54a9c5 (patch)
tree4463a6506b469fc3ec6ed185054d19488247d11e
parent6cee51e6d02bac7ee72969aa23e32c9bdcd7bb6e (diff)
xfs: only allocate free space bitmap for xattr scrub if needed
The free space bitmap is only required if we're going to check the bestfree space at the end of an xattr leaf block. Therefore, we can reduce the memory requirements of this scrubber if we can determine that the xattr is in short format. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
-rw-r--r--fs/xfs/scrub/attr.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c
index d2e1856beeb6..2445fe2860ff 100644
--- a/fs/xfs/scrub/attr.c
+++ b/fs/xfs/scrub/attr.c
@@ -38,6 +38,29 @@ xchk_xattr_buf_cleanup(
}
/*
+ * Allocate the free space bitmap if we're trying harder; there are leaf blocks
+ * in the attr fork; or we can't tell if there are leaf blocks.
+ */
+static inline bool
+xchk_xattr_want_freemap(
+ struct xfs_scrub *sc)
+{
+ struct xfs_ifork *ifp;
+
+ if (sc->flags & XCHK_TRY_HARDER)
+ return true;
+
+ if (!sc->ip)
+ return true;
+
+ ifp = xfs_ifork_ptr(sc->ip, XFS_ATTR_FORK);
+ if (!ifp)
+ return false;
+
+ return xfs_ifork_has_extents(ifp);
+}
+
+/*
* Allocate enough memory to hold an attr value and attr block bitmaps,
* reallocating the buffer if necessary. Buffer contents are not preserved
* across a reallocation.
@@ -66,9 +89,11 @@ xchk_setup_xattr_buf(
if (!ab->usedmap)
return -ENOMEM;
- ab->freemap = kvmalloc(bmp_sz, XCHK_GFP_FLAGS);
- if (!ab->freemap)
- return -ENOMEM;
+ if (xchk_xattr_want_freemap(sc)) {
+ ab->freemap = kvmalloc(bmp_sz, XCHK_GFP_FLAGS);
+ if (!ab->freemap)
+ return -ENOMEM;
+ }
resize_value:
if (ab->value_sz >= value_size)