|  | 
| 29 | 29 |  * Copyright (c) 2019, 2023, Klara Inc. | 
| 30 | 30 |  * Copyright (c) 2019, Allan Jude | 
| 31 | 31 |  * Copyright (c) 2020, The FreeBSD Foundation [1] | 
|  | 32 | + * Copyright (c) 2021, 2024 by George Melikov. All rights reserved. | 
| 32 | 33 |  * | 
| 33 | 34 |  * [1] Portions of this software were developed by Allan Jude | 
| 34 | 35 |  *     under sponsorship from the FreeBSD Foundation. | 
| @@ -1786,7 +1787,7 @@ arc_hdr_authenticate(arc_buf_hdr_t *hdr, spa_t *spa, uint64_t dsobj) | 
| 1786 | 1787 | 	    !HDR_COMPRESSION_ENABLED(hdr)) { | 
| 1787 | 1788 | 		abd = NULL; | 
| 1788 | 1789 | 		csize = zio_compress_data(HDR_GET_COMPRESS(hdr), | 
| 1789 |  | -		    hdr->b_l1hdr.b_pabd, &abd, lsize, hdr->b_complevel); | 
|  | 1790 | +		    hdr->b_l1hdr.b_pabd, &abd, lsize, lsize, hdr->b_complevel); | 
| 1790 | 1791 | 		ASSERT3P(abd, !=, NULL); | 
| 1791 | 1792 | 		ASSERT3U(csize, <=, psize); | 
| 1792 | 1793 | 		abd_zero_off(abd, csize, psize - csize); | 
| @@ -9029,8 +9030,8 @@ l2arc_apply_transforms(spa_t *spa, arc_buf_hdr_t *hdr, uint64_t asize, | 
| 9029 | 9030 | 	if (compress != ZIO_COMPRESS_OFF && !HDR_COMPRESSION_ENABLED(hdr)) { | 
| 9030 | 9031 | 		cabd = abd_alloc_for_io(MAX(size, asize), ismd); | 
| 9031 | 9032 | 		uint64_t csize = zio_compress_data(compress, to_write, &cabd, | 
| 9032 |  | -		    size, hdr->b_complevel); | 
| 9033 |  | -		if (csize > psize) { | 
|  | 9033 | +		    size, MIN(size, psize), hdr->b_complevel); | 
|  | 9034 | +		if (csize >= size || csize > psize) { | 
| 9034 | 9035 | 			/* | 
| 9035 | 9036 | 			 * We can't re-compress the block into the original | 
| 9036 | 9037 | 			 * psize.  Even if it fits into asize, it does not | 
| @@ -10521,9 +10522,11 @@ l2arc_log_blk_commit(l2arc_dev_t *dev, zio_t *pio, l2arc_write_callback_t *cb) | 
| 10521 | 10522 | 	 */ | 
| 10522 | 10523 | 	list_insert_tail(&cb->l2wcb_abd_list, abd_buf); | 
| 10523 | 10524 | 
 | 
| 10524 |  | -	/* try to compress the buffer */ | 
|  | 10525 | +	/* try to compress the buffer, at least one sector to save */ | 
| 10525 | 10526 | 	psize = zio_compress_data(ZIO_COMPRESS_LZ4, | 
| 10526 |  | -	    abd_buf->abd, &abd, sizeof (*lb), 0); | 
|  | 10527 | +	    abd_buf->abd, &abd, sizeof (*lb), | 
|  | 10528 | +	    zio_get_compression_max_size(dev->l2ad_vdev->vdev_ashift, | 
|  | 10529 | +	    dev->l2ad_vdev->vdev_ashift, sizeof (*lb)), 0); | 
| 10527 | 10530 | 
 | 
| 10528 | 10531 | 	/* a log block is never entirely zero */ | 
| 10529 | 10532 | 	ASSERT(psize != 0); | 
|  | 
0 commit comments