Improve code in arc_buf_remove_ref

When we remove references of arc bufs in the arc_anon state we
needn't take its header's hash_lock, so postpone it to where we
really need it to avoid unnecessary invocations of function buf_hash.

Signed-off-by: Ying Zhu <casualfisher@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1557
This commit is contained in:
Ying Zhu 2013-06-29 15:03:49 +08:00 committed by Brian Behlendorf
parent 8e07b99b2f
commit b4f7f10527

View File

@ -1642,7 +1642,7 @@ int
arc_buf_remove_ref(arc_buf_t *buf, void* tag) arc_buf_remove_ref(arc_buf_t *buf, void* tag)
{ {
arc_buf_hdr_t *hdr = buf->b_hdr; arc_buf_hdr_t *hdr = buf->b_hdr;
kmutex_t *hash_lock = HDR_LOCK(hdr); kmutex_t *hash_lock = NULL;
int no_callback = (buf->b_efunc == NULL); int no_callback = (buf->b_efunc == NULL);
if (hdr->b_state == arc_anon) { if (hdr->b_state == arc_anon) {
@ -1651,6 +1651,7 @@ arc_buf_remove_ref(arc_buf_t *buf, void* tag)
return (no_callback); return (no_callback);
} }
hash_lock = HDR_LOCK(hdr);
mutex_enter(hash_lock); mutex_enter(hash_lock);
hdr = buf->b_hdr; hdr = buf->b_hdr;
ASSERT3P(hash_lock, ==, HDR_LOCK(hdr)); ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));