Skip to content

Commit 674f0d0

Browse files
author
Darrick J. Wong
committed
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>
1 parent 6cee51e commit 674f0d0

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

fs/xfs/scrub/attr.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ xchk_xattr_buf_cleanup(
3737
ab->value_sz = 0;
3838
}
3939

40+
/*
41+
* Allocate the free space bitmap if we're trying harder; there are leaf blocks
42+
* in the attr fork; or we can't tell if there are leaf blocks.
43+
*/
44+
static inline bool
45+
xchk_xattr_want_freemap(
46+
struct xfs_scrub *sc)
47+
{
48+
struct xfs_ifork *ifp;
49+
50+
if (sc->flags & XCHK_TRY_HARDER)
51+
return true;
52+
53+
if (!sc->ip)
54+
return true;
55+
56+
ifp = xfs_ifork_ptr(sc->ip, XFS_ATTR_FORK);
57+
if (!ifp)
58+
return false;
59+
60+
return xfs_ifork_has_extents(ifp);
61+
}
62+
4063
/*
4164
* Allocate enough memory to hold an attr value and attr block bitmaps,
4265
* reallocating the buffer if necessary. Buffer contents are not preserved
@@ -66,9 +89,11 @@ xchk_setup_xattr_buf(
6689
if (!ab->usedmap)
6790
return -ENOMEM;
6891

69-
ab->freemap = kvmalloc(bmp_sz, XCHK_GFP_FLAGS);
70-
if (!ab->freemap)
71-
return -ENOMEM;
92+
if (xchk_xattr_want_freemap(sc)) {
93+
ab->freemap = kvmalloc(bmp_sz, XCHK_GFP_FLAGS);
94+
if (!ab->freemap)
95+
return -ENOMEM;
96+
}
7297

7398
resize_value:
7499
if (ab->value_sz >= value_size)

0 commit comments

Comments
 (0)