Skip to content

Commit adaa3e6

Browse files
gamanakisandrewc12
authored andcommitted
Fix the L2ARC write size calculating logic (2)
While commit bcd5321 adjusts the write size based on the size of the log block, this happens after comparing the unadjusted write size to the evicted (target) size. In this case l2ad_hand will exceed l2ad_evict and violate an assertion at the end of l2arc_write_buffers(). Fix this by adding the max log block size to the allocated size of the buffer to be committed before comparing the result to the target size. Also reset the l2arc_trim_ahead ZFS module variable when the adjusted write size exceeds the size of the L2ARC device. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: George Amanakis <[email protected]> Closes openzfs#14936 Closes openzfs#14954
1 parent 67118a7 commit adaa3e6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

module/zfs/arc.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8206,7 +8206,7 @@ l2arc_write_size(l2arc_dev_t *dev)
82068206
* device. This is important in l2arc_evict(), otherwise infinite
82078207
* iteration can occur.
82088208
*/
8209-
if (size >= dev->l2ad_end - dev->l2ad_start) {
8209+
if (size > dev->l2ad_end - dev->l2ad_start) {
82108210
cmn_err(CE_NOTE, "l2arc_write_max or l2arc_write_boost "
82118211
"plus the overhead of log blocks (persistent L2ARC, "
82128212
"%llu bytes) exceeds the size of the cache device "
@@ -8216,6 +8216,11 @@ l2arc_write_size(l2arc_dev_t *dev)
82168216

82178217
size = l2arc_write_max = l2arc_write_boost = L2ARC_WRITE_SIZE;
82188218

8219+
if (l2arc_trim_ahead > 1) {
8220+
cmn_err(CE_NOTE, "l2arc_trim_ahead set to 1");
8221+
l2arc_trim_ahead = 1;
8222+
}
8223+
82198224
if (arc_warm == B_FALSE)
82208225
size += l2arc_write_boost;
82218226

@@ -8842,7 +8847,7 @@ l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
88428847

88438848
top:
88448849
rerun = B_FALSE;
8845-
if (dev->l2ad_hand >= (dev->l2ad_end - distance)) {
8850+
if (dev->l2ad_hand + distance > dev->l2ad_end) {
88468851
/*
88478852
* When there is no space to accommodate upcoming writes,
88488853
* evict to the end. Then bump the write and evict hands
@@ -9036,7 +9041,7 @@ l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
90369041
*/
90379042
ASSERT3U(dev->l2ad_hand + distance, <, dev->l2ad_end);
90389043
if (!dev->l2ad_first)
9039-
ASSERT3U(dev->l2ad_hand, <, dev->l2ad_evict);
9044+
ASSERT3U(dev->l2ad_hand, <=, dev->l2ad_evict);
90409045
}
90419046
}
90429047

@@ -9296,7 +9301,13 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
92969301
uint64_t asize = vdev_psize_to_asize(dev->l2ad_vdev,
92979302
psize);
92989303

9299-
if ((write_asize + asize) > target_sz) {
9304+
/*
9305+
* If the allocated size of this buffer plus the max
9306+
* size for the pending log block exceeds the evicted
9307+
* target size, terminate writing buffers for this run.
9308+
*/
9309+
if (write_asize + asize +
9310+
sizeof (l2arc_log_blk_phys_t) > target_sz) {
93009311
full = B_TRUE;
93019312
mutex_exit(hash_lock);
93029313
break;
@@ -9412,7 +9423,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
94129423
*/
94139424
if (l2arc_log_blk_insert(dev, hdr)) {
94149425
/*
9415-
* l2ad_hand has been accounted for in
9426+
* l2ad_hand will be adjusted in
94169427
* l2arc_log_blk_commit().
94179428
*/
94189429
write_asize +=

0 commit comments

Comments
 (0)