From: Christoph Hellwig <hch@infradead.org>
To: Dave Chinner <david@fromorbit.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 4/5] xfs: speed up directory bestfree block scanning
Date: Fri, 26 Oct 2018 03:24:24 -0700 [thread overview]
Message-ID: <20181026102424.GC29302@infradead.org> (raw)
In-Reply-To: <20181024225716.19459-5-david@fromorbit.com>
> @@ -1767,11 +1767,10 @@ xfs_dir2_node_find_freeblk(
> fbp = fblk->bp;
> free = fbp->b_addr;
> findex = fblk->index;
> + bests = dp->d_ops->free_bests_p(free);
> + dp->d_ops->free_hdr_from_disk(&freehdr, free);
> if (findex >= 0) {
> /* caller already found the freespace for us. */
> - bests = dp->d_ops->free_bests_p(free);
> - dp->d_ops->free_hdr_from_disk(&freehdr, free);
> -
This hunk just undoes a move in the previous patch, might be better
idea to just keep it as before there.
> + for ( ; fbno < lastfbno; fbno++) {
> + /* If we don't have a freeblock in hand, get the next one. */
> if (fbp == NULL) {
> + /* If it's ifbno we already looked at it. */
> + if (fbno == ifbno)
> + continue;
> +
The only case where we have a fbp here is if we had a fblk passed in,
but it it did have the index set to -1. But as far as I can tell
searching that again doesn't make any sense at all, so I'd apply
something like this in top of your patch (some of this also seems
to be in your next patch, so independent of the logic change might
be worth moving over here):
diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
index 6a6572c5602e..d1fb0ff38584 100644
--- a/fs/xfs/libxfs/xfs_dir2_node.c
+++ b/fs/xfs/libxfs/xfs_dir2_node.c
@@ -1752,10 +1752,7 @@ xfs_dir2_node_find_freeblk(
struct xfs_buf *fbp = NULL;
int findex;
xfs_dir2_db_t lastfbno;
- xfs_dir2_db_t ifbno = -1;
- xfs_dir2_db_t dbno = -1;
xfs_dir2_db_t fbno = -1;
- xfs_dir2_free_t *free = NULL;
struct xfs_dir3_icfree_hdr freehdr;
__be16 *bests = NULL;
xfs_fileoff_t fo;
@@ -1768,28 +1765,29 @@ xfs_dir2_node_find_freeblk(
*/
if (fblk) {
fbp = fblk->bp;
- free = fbp->b_addr;
findex = fblk->index;
- bests = dp->d_ops->free_bests_p(free);
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
+ bests = dp->d_ops->free_bests_p(fbp->b_addr);
+ dp->d_ops->free_hdr_from_disk(&freehdr, fbp->b_addr);
if (findex >= 0) {
/* caller already found the freespace for us. */
ASSERT(findex < freehdr.nvalid);
ASSERT(be16_to_cpu(bests[findex]) != NULLDATAOFF);
ASSERT(be16_to_cpu(bests[findex]) >= length);
- dbno = freehdr.firstdb + findex;
- goto out;
+ goto found;
}
/*
* The data block looked at didn't have enough room.
- * We'll start at the beginning of the freespace entries.
+ * We'll start searching after this entry.
*/
- ifbno = fblk->blkno;
- fbno = ifbno;
+ fbno = fblk->blkno + 1;
+
+ xfs_trans_brelse(tp, fbp);
+ fblk->bp = NULL;
+ } else {
+ /* If we haven't got a search start block, set it now */
+ fbno = xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET);
}
- ASSERT(dbno == -1);
- findex = 0;
/*
* If we don't have a data block yet, we're going to scan the freespace
@@ -1801,64 +1799,50 @@ xfs_dir2_node_find_freeblk(
return error;
lastfbno = xfs_dir2_da_to_db(args->geo, (xfs_dablk_t)fo);
- /* If we haven't get a search start block, set it now */
- if (fbno == -1)
- fbno = xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET);
-
/*
- * While we haven't identified a data block, search the freeblock
- * data for a data block with enough free space in it.
+ * While we haven't identified a data block, search the freeblock data
+ * for a data block with enough free space in it.
*/
for ( ; fbno < lastfbno; fbno++) {
- /* If we don't have a freeblock in hand, get the next one. */
- if (fbp == NULL) {
- /* If it's ifbno we already looked at it. */
- if (fbno == ifbno)
- continue;
-
- /*
- * Read the block. There can be holes in the freespace
- * blocks, so this might not succeed. This should be
- * really rare, so there's no reason to avoid it.
- */
- error = xfs_dir2_free_try_read(tp, dp,
- xfs_dir2_db_to_da(args->geo, fbno),
- &fbp);
- if (error)
- return error;
- if (!fbp)
- continue;
+ /*
+ * Read the block. There can be holes in the freespace blocks,
+ * so this might not succeed. This should be really rare, so
+ * there's no reason to avoid it.
+ */
+ error = xfs_dir2_free_try_read(tp, dp,
+ xfs_dir2_db_to_da(args->geo, fbno), &fbp);
+ if (error)
+ return error;
+ if (!fbp)
+ continue;
- findex = 0;
- free = fbp->b_addr;
- bests = dp->d_ops->free_bests_p(free);
- dp->d_ops->free_hdr_from_disk(&freehdr, free);
- }
+ bests = dp->d_ops->free_bests_p(fbp->b_addr);
+ dp->d_ops->free_hdr_from_disk(&freehdr, fbp->b_addr);
/* Scan the free entry array for a large enough free space. */
- do {
- if (be16_to_cpu(bests[findex]) != NULLDATAOFF &&
- be16_to_cpu(bests[findex]) >= length) {
- dbno = freehdr.firstdb + findex;
- goto out;
- }
- } while (++findex < freehdr.nvalid);
+ for (findex = 0; findex < freehdr.nvalid; findex++) {
+ u16 best = be16_to_cpu(bests[findex]);
+
+ if (best != NULLDATAOFF && best >= length)
+ goto found;
+ }
/* Didn't find free space, go on to next free block */
xfs_trans_brelse(tp, fbp);
- fbp = NULL;
- if (fblk)
- fblk->bp = NULL;
}
-out:
- *dbnop = dbno;
+ *dbnop = -1;
+ *fbpp = NULL;
+ *findexp = 0;
+ return 0;
+
+found:
+ *dbnop = freehdr.firstdb + findex;
*fbpp = fbp;
*findexp = findex;
return 0;
}
-
/*
* Add the data entry for a node-format directory name addition.
* The leaf entry is added in xfs_dir2_leafn_add.
next prev parent reply other threads:[~2018-10-26 19:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 22:57 [PATCH 0/5] xfs: speed up large directory modifications Dave Chinner
2018-10-24 22:57 ` [PATCH 1/5] xfs: move xfs_dir2_addname() Dave Chinner
2018-10-26 9:24 ` Christoph Hellwig
2018-10-24 22:57 ` [PATCH 2/5] xfs: factor data block addition from xfs_dir2_node_addname_int() Dave Chinner
2018-10-26 9:45 ` Christoph Hellwig
2018-10-26 10:52 ` Dave Chinner
2018-10-26 12:01 ` Christoph Hellwig
2018-10-24 22:57 ` [PATCH 3/5] xfs: factor free block index lookup " Dave Chinner
2018-10-26 9:48 ` Christoph Hellwig
2018-10-26 10:49 ` Dave Chinner
2018-10-24 22:57 ` [PATCH 4/5] xfs: speed up directory bestfree block scanning Dave Chinner
2018-10-26 10:24 ` Christoph Hellwig [this message]
2018-10-26 10:58 ` Dave Chinner
2018-10-26 11:56 ` Christoph Hellwig
2018-10-26 12:12 ` Christoph Hellwig
2018-10-24 22:57 ` [PATCH 5/5] xfs: reverse search directory freespace indexes Dave Chinner
2018-10-26 12:14 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2019-08-29 6:30 [PATCH V2 0/5] xfs: speed up large directory modifications Dave Chinner
2019-08-29 6:30 ` [PATCH 4/5] xfs: speed up directory bestfree block scanning Dave Chinner
2019-08-29 8:18 ` Christoph Hellwig
2019-08-29 8:45 ` Dave Chinner
2019-08-29 8:47 ` Christoph Hellwig
2019-08-29 8:55 ` Dave Chinner
2019-08-29 8:25 ` Christoph Hellwig
2019-08-29 9:31 ` Dave Chinner
2019-08-29 9:33 ` Christoph Hellwig
2019-08-29 10:47 [PATCH v3 0/5] xfs: speed up large directory modifications Dave Chinner
2019-08-29 10:47 ` [PATCH 4/5] xfs: speed up directory bestfree block scanning Dave Chinner
2019-08-29 21:18 ` Darrick J. Wong
2019-08-30 5:24 ` 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=20181026102424.GC29302@infradead.org \
--to=hch@infradead.org \
--cc=david@fromorbit.com \
--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