Skip to content

Commit

Permalink
l2arc-write-target-size.diff
Browse files Browse the repository at this point in the history
adapted to openzfs#3216,

adaption to openzfs#2129 in
@ l2arc_compress_buf(l2arc_buf_hdr_t *l2hdr)

 		/*
 		 * Compression succeeded, we'll keep the cdata around for
 		 * writing and release it afterwards.
 		 */
+		if (rounded > csize) {
+			bzero((char *)cdata + csize, rounded - csize);
+			csize = rounded;
+		}

to

		/*
		 * Compression succeeded, we'll keep the cdata around for
		 * writing and release it afterwards.
		 */
		if (rounded > csize) {
			abd_zero_off(cdata, rounded - csize, csize);
			csize = rounded;
		}

ZFSonLinux:
openzfs#3114
openzfs#3400
openzfs#3433
  • Loading branch information
avg-I authored and kernelOfTruth committed May 21, 2015
1 parent 19b6408 commit 84029b2
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5640,8 +5640,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
boolean_t *headroom_boost)
{
arc_buf_hdr_t *hdr, *hdr_prev, *head;
uint64_t write_asize, write_psize, write_sz, headroom,
buf_compress_minsz;
uint64_t write_asize, write_sz, headroom, buf_compress_minsz;
abd_t *buf_data;
boolean_t full;
l2arc_write_callback_t *cb;
Expand All @@ -5656,7 +5655,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
*headroom_boost = B_FALSE;

pio = NULL;
write_sz = write_asize = write_psize = 0;
write_sz = write_asize = 0;
full = B_FALSE;
head = kmem_cache_alloc(hdr_l2only_cache, KM_PUSHPAGE);
head->b_flags |= ARC_FLAG_L2_WRITE_HEAD;
Expand Down Expand Up @@ -5693,6 +5692,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
for (; hdr; hdr = hdr_prev) {
kmutex_t *hash_lock;
uint64_t buf_sz;
uint64_t buf_a_sz;

if (arc_warm == B_FALSE)
hdr_prev = multilist_sublist_next(mls, hdr);
Expand Down Expand Up @@ -5721,7 +5721,15 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
continue;
}

if ((write_sz + hdr->b_size) > target_sz) {
/*
* Assume that the buffer is not going to be compressed
* and could take more space on disk because of a larger
* disk block size.
*/
buf_sz = hdr->b_size;
buf_a_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);

if ((write_asize + buf_a_sz) > target_sz) {
full = B_TRUE;
mutex_exit(hash_lock);
break;
Expand Down Expand Up @@ -5804,6 +5812,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
mutex_exit(hash_lock);

write_sz += buf_sz;
write_asize += buf_a_sz;
}

multilist_sublist_unlock(mls);
Expand All @@ -5827,6 +5836,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
* and work backwards, retracing the course of the buffer selector
* loop above.
*/
write_asize = 0;
for (hdr = list_prev(&dev->l2ad_buflist, head); hdr;
hdr = list_prev(&dev->l2ad_buflist, hdr)) {
uint64_t buf_sz;
Expand Down Expand Up @@ -5875,7 +5885,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,

/* Compression may have squashed the buffer to zero length. */
if (buf_sz != 0) {
uint64_t buf_p_sz;
uint64_t buf_a_sz;

wzio = zio_write_phys(pio, dev->l2ad_vdev,
dev->l2ad_hand, buf_sz, buf_data, ZIO_CHECKSUM_OFF,
Expand All @@ -5886,14 +5896,12 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz,
zio_t *, wzio);
(void) zio_nowait(wzio);

write_asize += buf_sz;

/*
* Keep the clock hand suitably device-aligned.
*/
buf_p_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);
write_psize += buf_p_sz;
dev->l2ad_hand += buf_p_sz;
buf_a_sz = vdev_psize_to_asize(dev->l2ad_vdev, buf_sz);
write_asize += buf_a_sz;
dev->l2ad_hand += buf_a_sz;
}
}

Expand Down Expand Up @@ -5968,12 +5976,6 @@ l2arc_compress_buf(arc_buf_hdr_t *hdr)

abd_return_buf(hdr->b_l1hdr.b_tmp_cdata, ddata, l2hdr->b_asize);

rounded = P2ROUNDUP(csize, (size_t)SPA_MINBLOCKSIZE);
if (rounded > csize) {
abd_zero_off(cdata, rounded - csize, csize);
csize = rounded;
}

if (csize == 0) {
/* zero block, indicate that there's nothing to write */
abd_free(cdata, len);
Expand All @@ -5982,11 +5984,19 @@ l2arc_compress_buf(arc_buf_hdr_t *hdr)
hdr->b_l1hdr.b_tmp_cdata = NULL;
ARCSTAT_BUMP(arcstat_l2_compress_zeros);
return (B_TRUE);
} else if (csize > 0 && csize < len) {
}

rounded = P2ROUNDUP(csize,
(size_t)1 << l2hdr->b_dev->l2ad_vdev->vdev_ashift);
if (rounded < len) {
/*
* Compression succeeded, we'll keep the cdata around for
* writing and release it afterwards.
*/
if (rounded > csize) {
abd_zero_off(cdata, rounded - csize, csize);
csize = rounded;
}
HDR_SET_COMPRESS(hdr, ZIO_COMPRESS_LZ4);
l2hdr->b_asize = csize;
hdr->b_l1hdr.b_tmp_cdata = cdata;
Expand Down

0 comments on commit 84029b2

Please sign in to comment.