Skip to content

Commit 32dd4f9

Browse files
dgchinnerdchinner
authored andcommitted
xfs: remove a superflous hash lookup when inserting new buffers
Currently on the slow path insert we repeat the initial hash table lookup before we attempt the insert, resulting in a two traversals of the hash table to ensure the insert is valid. The rhashtable API provides a method for an atomic lookup and insert operation, so we can avoid one of the hash table traversals by using this method. Adapted from a large patch containing this optimisation by Christoph Hellwig. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
1 parent d8d9bbb commit 32dd4f9

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

fs/xfs/xfs_buf.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,15 @@ xfs_buf_find_insert(
623623
}
624624

625625
spin_lock(&pag->pag_buf_lock);
626-
bp = rhashtable_lookup(&pag->pag_buf_hash, cmap, xfs_buf_hash_params);
626+
bp = rhashtable_lookup_get_insert_fast(&pag->pag_buf_hash,
627+
&new_bp->b_rhash_head, xfs_buf_hash_params);
628+
if (IS_ERR(bp)) {
629+
error = PTR_ERR(bp);
630+
spin_unlock(&pag->pag_buf_lock);
631+
goto out_free_buf;
632+
}
627633
if (bp) {
634+
/* found an existing buffer */
628635
atomic_inc(&bp->b_hold);
629636
spin_unlock(&pag->pag_buf_lock);
630637
error = xfs_buf_find_lock(bp, flags);
@@ -635,10 +642,8 @@ xfs_buf_find_insert(
635642
goto out_free_buf;
636643
}
637644

638-
/* The buffer keeps the perag reference until it is freed. */
645+
/* The new buffer keeps the perag reference until it is freed. */
639646
new_bp->b_pag = pag;
640-
rhashtable_insert_fast(&pag->pag_buf_hash, &new_bp->b_rhash_head,
641-
xfs_buf_hash_params);
642647
spin_unlock(&pag->pag_buf_lock);
643648
*bpp = new_bp;
644649
return 0;

0 commit comments

Comments
 (0)