All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 9/9] xfs: only allocate free space bitmap for xattr scrub if needed
Date: Sun, 02 Oct 2022 11:20:41 -0700	[thread overview]
Message-ID: <166473484120.1085108.12625299349355602768.stgit@magnolia> (raw)
In-Reply-To: <166473483982.1085108.101544412199880535.stgit@magnolia>

From: Darrick J. Wong <djwong@kernel.org>

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>
---
 fs/xfs/scrub/attr.c |   31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)


diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c
index f6eb6070488b..b315a499ba32 100644
--- a/fs/xfs/scrub/attr.c
+++ b/fs/xfs/scrub/attr.c
@@ -37,6 +37,29 @@ xchk_xattr_buf_cleanup(
 	ab->value_sz = 0;
 }
 
+/*
+ * 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
@@ -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)


  parent reply	other threads:[~2022-10-02 18:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-02 18:20 [PATCHSET v23.1 0/9] xfs: clean up memory management in xattr scrub Darrick J. Wong
2022-10-02 18:20 ` [PATCH 2/9] xfs: split freemap from xchk_xattr_buf.buf Darrick J. Wong
2022-10-02 18:20 ` [PATCH 4/9] xfs: split valuebuf " Darrick J. Wong
2022-10-02 18:20 ` [PATCH 5/9] xfs: remove flags argument from xchk_setup_xattr_buf Darrick J. Wong
2022-10-02 18:20 ` [PATCH 1/9] xfs: remove unnecessary dstmap in xattr scrubber Darrick J. Wong
2022-10-02 18:20 ` [PATCH 7/9] xfs: check used space of shortform xattr structures Darrick J. Wong
2022-10-02 18:20 ` [PATCH 3/9] xfs: split usedmap from xchk_xattr_buf.buf Darrick J. Wong
2022-10-02 18:20 ` [PATCH 6/9] xfs: move xattr scrub buffer allocation to top level function Darrick J. Wong
2022-10-02 18:20 ` Darrick J. Wong [this message]
2022-10-02 18:20 ` [PATCH 8/9] xfs: clean up xattr scrub initialization Darrick J. Wong

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=166473484120.1085108.12625299349355602768.stgit@magnolia \
    --to=djwong@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.