Skip to content

Commit 5a0ec4a

Browse files
amotinixhamza
authored andcommitted
L2ARC: Move different stats updates earlier
..., before we make the header or the log block visible to others. It should fix assertion on allocated space going negative if the header is freed once the lock is dropped, while the write is still going. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Rob Norris <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes openzfs#16040 Closes openzfs#16743
1 parent 092cb94 commit 5a0ec4a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

module/zfs/arc.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9287,6 +9287,14 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
92879287
hdr->b_l2hdr.b_hits = 0;
92889288
hdr->b_l2hdr.b_arcs_state =
92899289
hdr->b_l1hdr.b_state->arcs_state;
9290+
arc_hdr_set_flags(hdr, ARC_FLAG_HAS_L2HDR |
9291+
ARC_FLAG_L2_WRITING);
9292+
9293+
(void) zfs_refcount_add_many(&dev->l2ad_alloc,
9294+
arc_hdr_size(hdr), hdr);
9295+
l2arc_hdr_arcstats_increment(hdr);
9296+
vdev_space_update(dev->l2ad_vdev, asize, 0, 0);
9297+
92909298
mutex_enter(&dev->l2ad_mtx);
92919299
if (pio == NULL) {
92929300
/*
@@ -9298,12 +9306,6 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
92989306
}
92999307
list_insert_head(&dev->l2ad_buflist, hdr);
93009308
mutex_exit(&dev->l2ad_mtx);
9301-
arc_hdr_set_flags(hdr, ARC_FLAG_HAS_L2HDR |
9302-
ARC_FLAG_L2_WRITING);
9303-
9304-
(void) zfs_refcount_add_many(&dev->l2ad_alloc,
9305-
arc_hdr_size(hdr), hdr);
9306-
l2arc_hdr_arcstats_increment(hdr);
93079309

93089310
boolean_t commit = l2arc_log_blk_insert(dev, hdr);
93099311
mutex_exit(hash_lock);
@@ -9333,7 +9335,6 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
93339335
write_psize += psize;
93349336
write_asize += asize;
93359337
dev->l2ad_hand += asize;
9336-
vdev_space_update(dev->l2ad_vdev, asize, 0, 0);
93379338

93389339
if (commit) {
93399340
/* l2ad_hand will be adjusted inside. */
@@ -10585,6 +10586,8 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb)
1058510586
(void) zio_nowait(wzio);
1058610587

1058710588
dev->l2ad_hand += asize;
10589+
vdev_space_update(dev->l2ad_vdev, asize, 0, 0);
10590+
1058810591
/*
1058910592
* Include the committed log block's pointer in the list of pointers
1059010593
* to log blocks present in the L2ARC device.
@@ -10598,7 +10601,6 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb)
1059810601
zfs_refcount_add_many(&dev->l2ad_lb_asize, asize, lb_ptr_buf);
1059910602
zfs_refcount_add(&dev->l2ad_lb_count, lb_ptr_buf);
1060010603
mutex_exit(&dev->l2ad_mtx);
10601-
vdev_space_update(dev->l2ad_vdev, asize, 0, 0);
1060210604

1060310605
/* bump the kstats */
1060410606
ARCSTAT_INCR(arcstat_l2_write_bytes, asize);

0 commit comments

Comments
 (0)