Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the L2ARC write size calculating logic (2) #14954

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8208,7 +8208,7 @@ l2arc_write_size(l2arc_dev_t *dev)
* device. This is important in l2arc_evict(), otherwise infinite
* iteration can occur.
*/
if (size >= dev->l2ad_end - dev->l2ad_start) {
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 "
Expand All @@ -8218,6 +8218,11 @@ l2arc_write_size(l2arc_dev_t *dev)

size = l2arc_write_max = l2arc_write_boost = L2ARC_WRITE_SIZE;

if (l2arc_trim_ahead > 1) {
cmn_err(CE_NOTE, "l2arc_trim_ahead set to 1");
l2arc_trim_ahead = 1;
}
behlendorf marked this conversation as resolved.
Show resolved Hide resolved

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

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

top:
rerun = B_FALSE;
if (dev->l2ad_hand >= (dev->l2ad_end - distance)) {
if (dev->l2ad_hand + distance > dev->l2ad_end) {
/*
* When there is no space to accommodate upcoming writes,
* evict to the end. Then bump the write and evict hands
Expand Down Expand Up @@ -9044,7 +9049,7 @@ l2arc_evict(l2arc_dev_t *dev, uint64_t distance, boolean_t all)
*/
ASSERT3U(dev->l2ad_hand + distance, <, dev->l2ad_end);
if (!dev->l2ad_first)
ASSERT3U(dev->l2ad_hand, <, dev->l2ad_evict);
ASSERT3U(dev->l2ad_hand, <=, dev->l2ad_evict);
}
}

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

if ((write_asize + asize) > target_sz) {
/*
* If the allocated size of this buffer plus the max
* size for the pending log block exceeds the evicted
* target size, terminate writing buffers for this run.
*/
if (write_asize + asize +
sizeof (l2arc_log_blk_phys_t) > target_sz) {
full = B_TRUE;
mutex_exit(hash_lock);
break;
Expand Down Expand Up @@ -9420,7 +9431,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
*/
if (l2arc_log_blk_insert(dev, hdr)) {
/*
* l2ad_hand has been accounted for in
* l2ad_hand will be adjusted in
* l2arc_log_blk_commit().
*/
write_asize +=
Expand Down