Skip to content

Commit

Permalink
Fix the L2ARC write size calculating logic
Browse files Browse the repository at this point in the history
l2arc_write_size() should return the write size after adjusting for trim
and overhead of the L2ARC log blocks.

Signed-off-by: George Amanakis <gamanakis@gmail.com>
  • Loading branch information
gamanakis committed Jun 5, 2023
1 parent 6c29422 commit 9b3f0d6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8175,7 +8175,7 @@ l2arc_write_eligible(uint64_t spa_guid, arc_buf_hdr_t *hdr)
static uint64_t
l2arc_write_size(l2arc_dev_t *dev)
{
uint64_t size, dev_size, tsize;
uint64_t size;

/*
* Make sure our globals have meaningful values in case the user
Expand All @@ -8192,35 +8192,40 @@ l2arc_write_size(l2arc_dev_t *dev)
if (arc_warm == B_FALSE)
size += l2arc_write_boost;

/*
* Make sure the write size does not exceed the size of the cache
* device. This is important in l2arc_evict(), otherwise infinite
* iteration can occur.
*/
dev_size = dev->l2ad_end - dev->l2ad_start;

/* We need to add in the worst case scenario of log block overhead. */
tsize = size + l2arc_log_blk_overhead(size, dev);
size += l2arc_log_blk_overhead(size, dev);
if (dev->l2ad_vdev->vdev_has_trim && l2arc_trim_ahead > 0) {
/*
* Trim ahead of the write size 64MB or (l2arc_trim_ahead/100)
* times the writesize, whichever is greater.
*/
tsize += MAX(64 * 1024 * 1024,
(tsize * l2arc_trim_ahead) / 100);
size += MAX(64 * 1024 * 1024,
(size * l2arc_trim_ahead) / 100);
}

if (tsize >= dev_size) {
/*
* Make sure the write size does not exceed the size of the cache
* device. This is important in l2arc_evict(), otherwise infinite
* iteration can occur.
*/
if (size >= dev->l2ad_end - dev->l2ad_start) {
cmn_err(CE_NOTE, "l2arc_write_max or l2arc_write_boost "
"plus the overhead of log blocks (persistent L2ARC, "
"%llu bytes) exceeds the size of the cache device "
"(guid %llu), resetting them to the default (%d)",
(u_longlong_t)l2arc_log_blk_overhead(size, dev),
(u_longlong_t)dev->l2ad_vdev->vdev_guid, L2ARC_WRITE_SIZE);

size = l2arc_write_max = l2arc_write_boost = L2ARC_WRITE_SIZE;

if (arc_warm == B_FALSE)
size += l2arc_write_boost;

size += l2arc_log_blk_overhead(size, dev);
if (dev->l2ad_vdev->vdev_has_trim && l2arc_trim_ahead > 0) {
size += MAX(64 * 1024 * 1024,
(size * l2arc_trim_ahead) / 100);
}
}

return (size);
Expand Down

0 comments on commit 9b3f0d6

Please sign in to comment.