Skip to content

Commit 24f755e

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: split xfs_buf_rele for cached vs uncached buffers
xfs_buf_rele is a bit confusing because it mixes up handling of normal cached and the special uncached buffers without much explanation. Split the handling into two different helpers, and use a clearly named helper that checks the hash key to distinguish the two cases instead of checking the pag pointer. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent 6a701eb commit 24f755e

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

fs/xfs/xfs_buf.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ xfs_buf_submit(
6060
return __xfs_buf_submit(bp, !(bp->b_flags & XBF_ASYNC));
6161
}
6262

63+
static inline bool xfs_buf_is_uncached(struct xfs_buf *bp)
64+
{
65+
return bp->b_rhash_key == XFS_BUF_DADDR_NULL;
66+
}
67+
6368
static inline int
6469
xfs_buf_is_vmapped(
6570
struct xfs_buf *bp)
@@ -996,12 +1001,19 @@ xfs_buf_hold(
9961001
atomic_inc(&bp->b_hold);
9971002
}
9981003

999-
/*
1000-
* Release a hold on the specified buffer. If the hold count is 1, the buffer is
1001-
* placed on LRU or freed (depending on b_lru_ref).
1002-
*/
1003-
void
1004-
xfs_buf_rele(
1004+
static void
1005+
xfs_buf_rele_uncached(
1006+
struct xfs_buf *bp)
1007+
{
1008+
ASSERT(list_empty(&bp->b_lru));
1009+
if (atomic_dec_and_test(&bp->b_hold)) {
1010+
xfs_buf_ioacct_dec(bp);
1011+
xfs_buf_free(bp);
1012+
}
1013+
}
1014+
1015+
static void
1016+
xfs_buf_rele_cached(
10051017
struct xfs_buf *bp)
10061018
{
10071019
struct xfs_perag *pag = bp->b_pag;
@@ -1010,15 +1022,6 @@ xfs_buf_rele(
10101022

10111023
trace_xfs_buf_rele(bp, _RET_IP_);
10121024

1013-
if (!pag) {
1014-
ASSERT(list_empty(&bp->b_lru));
1015-
if (atomic_dec_and_test(&bp->b_hold)) {
1016-
xfs_buf_ioacct_dec(bp);
1017-
xfs_buf_free(bp);
1018-
}
1019-
return;
1020-
}
1021-
10221025
ASSERT(atomic_read(&bp->b_hold) > 0);
10231026

10241027
/*
@@ -1086,6 +1089,19 @@ xfs_buf_rele(
10861089
xfs_buf_free(bp);
10871090
}
10881091

1092+
/*
1093+
* Release a hold on the specified buffer.
1094+
*/
1095+
void
1096+
xfs_buf_rele(
1097+
struct xfs_buf *bp)
1098+
{
1099+
trace_xfs_buf_rele(bp, _RET_IP_);
1100+
if (xfs_buf_is_uncached(bp))
1101+
xfs_buf_rele_uncached(bp);
1102+
else
1103+
xfs_buf_rele_cached(bp);
1104+
}
10891105

10901106
/*
10911107
* Lock a buffer object, if it is not already locked.

0 commit comments

Comments
 (0)