Skip to content

Commit 140378b

Browse files
committed
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 commited 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. Signed-off-by: George Amanakis <[email protected]>
1 parent 6c96269 commit 140378b

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
@@ -8208,7 +8208,7 @@ l2arc_write_size(l2arc_dev_t *dev)
82088208
* device. This is important in l2arc_evict(), otherwise infinite
82098209
* iteration can occur.
82108210
*/
8211-
if (size >= dev->l2ad_end - dev->l2ad_start) {
8211+
if (size > dev->l2ad_end - dev->l2ad_start) {
82128212
cmn_err(CE_NOTE, "l2arc_write_max or l2arc_write_boost "
82138213
"plus the overhead of log blocks (persistent L2ARC, "
82148214
"%llu bytes) exceeds the size of the cache device "
@@ -8218,6 +8218,11 @@ l2arc_write_size(l2arc_dev_t *dev)
82188218

82198219
size = l2arc_write_max = l2arc_write_boost = L2ARC_WRITE_SIZE;
82208220

8221+
if (l2arc_trim_ahead > 1) {
8222+
cmn_err(CE_NOTE, "l2arc_trim_ahead set to 1");
8223+
l2arc_trim_ahead = 1;
8224+
}
8225+
82218226
if (arc_warm == B_FALSE)
82228227
size += l2arc_write_boost;
82238228

@@ -8850,7 +8855,7 @@ l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
88508855

88518856
top:
88528857
rerun = B_FALSE;
8853-
if (dev->l2ad_hand >= (dev->l2ad_end - distance)) {
8858+
if (dev->l2ad_hand + distance > dev->l2ad_end) {
88548859
/*
88558860
* When there is no space to accommodate upcoming writes,
88568861
* evict to the end. Then bump the write and evict hands
@@ -9044,7 +9049,7 @@ l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
90449049
*/
90459050
ASSERT3U(dev->l2ad_hand + distance, <, dev->l2ad_end);
90469051
if (!dev->l2ad_first)
9047-
ASSERT3U(dev->l2ad_hand, <, dev->l2ad_evict);
9052+
ASSERT3U(dev->l2ad_hand, <=, dev->l2ad_evict);
90489053
}
90499054
}
90509055

@@ -9304,7 +9309,13 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
93049309
uint64_t asize = vdev_psize_to_asize(dev->l2ad_vdev,
93059310
psize);
93069311

9307-
if ((write_asize + asize) > target_sz) {
9312+
/*
9313+
* If the allocated size of this buffer plus the max
9314+
* size for the pending log block exceeds the evicted
9315+
* target size, terminate writing buffers for this run.
9316+
*/
9317+
if (write_asize + asize +
9318+
sizeof (l2arc_log_blk_phys_t) > target_sz) {
93089319
full = B_TRUE;
93099320
mutex_exit(hash_lock);
93109321
break;
@@ -9420,7 +9431,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
94209431
*/
94219432
if (l2arc_log_blk_insert(dev, hdr)) {
94229433
/*
9423-
* l2ad_hand has been accounted for in
9434+
* l2ad_hand will be adjusted in
94249435
* l2arc_log_blk_commit().
94259436
*/
94269437
write_asize +=

0 commit comments

Comments
 (0)