Skip to content

Commit a4e775d

Browse files
committed
Some arc_release() cleanup
- Don't drop L2ARC header if we have more buffers in this header. Since we leave them the header, leave them the L2ARC header also. Honestly we are not required to drop it even if there are no other buffers, but then we'd need to allocate it a separate header, which we might drop soon if the old block is really deleted. Multiple buffers in a header likely mean active snapshots or dedup, so we know that the block in L2ARC will remain valid. It might be rare, but why not? - Remove some impossible assertions and conditions. Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes #17126
1 parent 661310f commit a4e775d

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

module/zfs/arc.c

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6627,27 +6627,11 @@ arc_release(arc_buf_t *buf, const void *tag)
66276627
arc_state_t *state = hdr->b_l1hdr.b_state;
66286628
ASSERT3P(hash_lock, ==, HDR_LOCK(hdr));
66296629
ASSERT3P(state, !=, arc_anon);
6630+
ASSERT3P(state, !=, arc_l2c_only);
66306631

66316632
/* this buffer is not on any list */
66326633
ASSERT3S(zfs_refcount_count(&hdr->b_l1hdr.b_refcnt), >, 0);
66336634

6634-
if (HDR_HAS_L2HDR(hdr)) {
6635-
mutex_enter(&hdr->b_l2hdr.b_dev->l2ad_mtx);
6636-
6637-
/*
6638-
* We have to recheck this conditional again now that
6639-
* we're holding the l2ad_mtx to prevent a race with
6640-
* another thread which might be concurrently calling
6641-
* l2arc_evict(). In that case, l2arc_evict() might have
6642-
* destroyed the header's L2 portion as we were waiting
6643-
* to acquire the l2ad_mtx.
6644-
*/
6645-
if (HDR_HAS_L2HDR(hdr))
6646-
arc_hdr_l2hdr_destroy(hdr);
6647-
6648-
mutex_exit(&hdr->b_l2hdr.b_dev->l2ad_mtx);
6649-
}
6650-
66516635
/*
66526636
* Do we have more than one buf?
66536637
*/
@@ -6659,21 +6643,17 @@ arc_release(arc_buf_t *buf, const void *tag)
66596643
boolean_t protected = HDR_PROTECTED(hdr);
66606644
enum zio_compress compress = arc_hdr_get_compress(hdr);
66616645
arc_buf_contents_t type = arc_buf_type(hdr);
6662-
VERIFY3U(hdr->b_type, ==, type);
6663-
6664-
ASSERT(hdr->b_l1hdr.b_buf != buf || buf->b_next != NULL);
6665-
VERIFY3S(remove_reference(hdr, tag), >, 0);
66666646

66676647
if (ARC_BUF_SHARED(buf) && !ARC_BUF_COMPRESSED(buf)) {
66686648
ASSERT3P(hdr->b_l1hdr.b_buf, !=, buf);
66696649
ASSERT(ARC_BUF_LAST(buf));
66706650
}
66716651

66726652
/*
6673-
* Pull the data off of this hdr and attach it to
6674-
* a new anonymous hdr. Also find the last buffer
6653+
* Pull the buffer off of this hdr and find the last buffer
66756654
* in the hdr's buffer list.
66766655
*/
6656+
VERIFY3S(remove_reference(hdr, tag), >, 0);
66776657
arc_buf_t *lastbuf = arc_buf_remove(hdr, buf);
66786658
ASSERT3P(lastbuf, !=, NULL);
66796659

@@ -6682,7 +6662,6 @@ arc_release(arc_buf_t *buf, const void *tag)
66826662
* buffer, then we must stop sharing that block.
66836663
*/
66846664
if (ARC_BUF_SHARED(buf)) {
6685-
ASSERT3P(hdr->b_l1hdr.b_buf, !=, buf);
66866665
ASSERT(!arc_buf_is_shared(lastbuf));
66876666

66886667
/*
@@ -6704,7 +6683,6 @@ arc_release(arc_buf_t *buf, const void *tag)
67046683
abd_copy_from_buf(hdr->b_l1hdr.b_pabd,
67056684
buf->b_data, psize);
67066685
}
6707-
VERIFY3P(lastbuf->b_data, !=, NULL);
67086686
} else if (HDR_SHARED_DATA(hdr)) {
67096687
/*
67106688
* Uncompressed shared buffers are always at the end
@@ -6720,18 +6698,10 @@ arc_release(arc_buf_t *buf, const void *tag)
67206698
}
67216699

67226700
ASSERT(hdr->b_l1hdr.b_pabd != NULL || HDR_HAS_RABD(hdr));
6723-
ASSERT3P(state, !=, arc_l2c_only);
67246701

67256702
(void) zfs_refcount_remove_many(&state->arcs_size[type],
67266703
arc_buf_size(buf), buf);
67276704

6728-
if (zfs_refcount_is_zero(&hdr->b_l1hdr.b_refcnt)) {
6729-
ASSERT3P(state, !=, arc_l2c_only);
6730-
(void) zfs_refcount_remove_many(
6731-
&state->arcs_esize[type],
6732-
arc_buf_size(buf), buf);
6733-
}
6734-
67356705
arc_cksum_verify(buf);
67366706
arc_buf_unwatch(buf);
67376707

@@ -6759,6 +6729,15 @@ arc_release(arc_buf_t *buf, const void *tag)
67596729
/* protected by hash lock, or hdr is on arc_anon */
67606730
ASSERT(!multilist_link_active(&hdr->b_l1hdr.b_arc_node));
67616731
ASSERT(!HDR_IO_IN_PROGRESS(hdr));
6732+
6733+
if (HDR_HAS_L2HDR(hdr)) {
6734+
mutex_enter(&hdr->b_l2hdr.b_dev->l2ad_mtx);
6735+
/* Recheck to prevent race with l2arc_evict(). */
6736+
if (HDR_HAS_L2HDR(hdr))
6737+
arc_hdr_l2hdr_destroy(hdr);
6738+
mutex_exit(&hdr->b_l2hdr.b_dev->l2ad_mtx);
6739+
}
6740+
67626741
hdr->b_l1hdr.b_mru_hits = 0;
67636742
hdr->b_l1hdr.b_mru_ghost_hits = 0;
67646743
hdr->b_l1hdr.b_mfu_hits = 0;

0 commit comments

Comments
 (0)