Skip to content

Commit 6e53663

Browse files
committed
zio_compress: use min sector size as threshold
Now default compression is lz4, which can stop compression process by itself on incompressible data. If there is additional size checks - we will only make our compressratio worse. So we can check only for common sector size (which can be changed by module parameter). Signed-off-by: George Melikov <[email protected]>
1 parent 94bcf6f commit 6e53663

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

man/man5/zfs-module-parameters.5

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.\" Copyright (c) 2013 by Turbo Fredriksson <[email protected]>. All rights reserved.
33
.\" Copyright (c) 2019 by Delphix. All rights reserved.
44
.\" Copyright (c) 2019 Datto Inc.
5+
.\" Copyright (c) 2019 by George Melikov <[email protected]>. All rights reserved.
56
.\" The contents of this file are subject to the terms of the Common Development
67
.\" and Distribution License (the "License"). You may not use this file except
78
.\" in compliance with the License. You can obtain a copy of the license at
@@ -1097,6 +1098,22 @@ transaction record (itx).
10971098
Default value: \fB5\fR%.
10981099
.RE
10991100

1101+
.sp
1102+
.ne 2
1103+
.na
1104+
\fBzfs_compress_threshold_bytes\fR (int)
1105+
.ad
1106+
.RS 12n
1107+
This controls the threshold of block compressing ratio which must be exceeded to
1108+
write a block on disk compressed, otherwise it will be writted uncompressed
1109+
to save processor time on decompress.
1110+
Because of disk sector size there is a minimal block size, so if we can compress
1111+
data smaller than this size, full sector block will be allocated against
1112+
compression gains.
1113+
.sp
1114+
Default value: \fB512\fR.
1115+
.RE
1116+
11001117
.sp
11011118
.ne 2
11021119
.na

module/zfs/zio_compress.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222
/*
2323
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2424
* Use is subject to license terms.
25-
*/
26-
/*
2725
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
28-
*/
29-
30-
/*
3126
* Copyright (c) 2013, 2018 by Delphix. All rights reserved.
27+
* Copyright (c) 2019 by George Melikov. All rights reserved.
3228
*/
3329

3430
#include <sys/zfs_context.h>
@@ -43,6 +39,9 @@
4339
*/
4440
unsigned long zio_decompress_fail_fraction = 0;
4541

42+
/* Compression threshold, default size is a common disk sector size. */
43+
unsigned long zfs_compress_threshold_bytes = 512;
44+
4645
/*
4746
* Compression vectors.
4847
*/
@@ -120,8 +119,12 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
120119
if (c == ZIO_COMPRESS_EMPTY)
121120
return (s_len);
122121

123-
/* Compress at least 12.5% */
124-
d_len = s_len - (s_len >> 3);
122+
/* Data is already less or equal to compress threshold */
123+
if (s_len <= zfs_compress_threshold_bytes)
124+
return (s_len);
125+
126+
/* Write compressed only if there is at least one sector compressed */
127+
d_len = s_len - MIN(s_len, zfs_compress_threshold_bytes);
125128

126129
/* No compression algorithms can read from ABDs directly */
127130
void *tmp = abd_borrow_buf_copy(src, s_len);
@@ -131,7 +134,6 @@ zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len)
131134
if (c_len > d_len)
132135
return (s_len);
133136

134-
ASSERT3U(c_len, <=, d_len);
135137
return (c_len);
136138
}
137139

@@ -166,3 +168,10 @@ zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
166168

167169
return (ret);
168170
}
171+
172+
#if defined(_KERNEL)
173+
/* BEGIN CSTYLED */
174+
module_param(zfs_compress_threshold_bytes, ulong, 0644);
175+
MODULE_PARM_DESC(zfs_compress_threshold_bytes, "Compression threshold, bytes.");
176+
/* END CSTYLED */
177+
#endif

0 commit comments

Comments
 (0)