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

[WIP] Adaptive Compression Refresh #9689

Closed
Closed
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions cmd/dbufstat/dbufstat
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ def get_typestring(t):


def get_compstring(c):
comp_strings = ["ZIO_COMPRESS_INHERIT", "ZIO_COMPRESS_ON",
"ZIO_COMPRESS_OFF", "ZIO_COMPRESS_LZJB",
"ZIO_COMPRESS_EMPTY", "ZIO_COMPRESS_GZIP_1",
"ZIO_COMPRESS_GZIP_2", "ZIO_COMPRESS_GZIP_3",
"ZIO_COMPRESS_GZIP_4", "ZIO_COMPRESS_GZIP_5",
"ZIO_COMPRESS_GZIP_6", "ZIO_COMPRESS_GZIP_7",
"ZIO_COMPRESS_GZIP_8", "ZIO_COMPRESS_GZIP_9",
"ZIO_COMPRESS_ZLE", "ZIO_COMPRESS_LZ4",
"ZIO_COMPRESS_FUNCTION"]
comp_strings = ["ZIO_COMPRESS_INHERIT", "ZIO_COMPRESS_ON",
"ZIO_COMPRESS_OFF", "ZIO_COMPRESS_LZJB",
"ZIO_COMPRESS_EMPTY", "ZIO_COMPRESS_GZIP_1",
"ZIO_COMPRESS_GZIP_2", "ZIO_COMPRESS_GZIP_3",
"ZIO_COMPRESS_GZIP_4", "ZIO_COMPRESS_GZIP_5",
"ZIO_COMPRESS_GZIP_6", "ZIO_COMPRESS_GZIP_7",
"ZIO_COMPRESS_GZIP_8", "ZIO_COMPRESS_GZIP_9",
"ZIO_COMPRESS_ZLE", "ZIO_COMPRESS_LZ4",
"ZIO_COMPRESS_ADAPTIVE", "ZIO_COMPRESS_FUNCTION"]

# If "-rr" option is used, don't convert to string representation
if raw > 1:
Expand Down
1 change: 1 addition & 0 deletions include/sys/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COMMON_H = \
$(top_srcdir)/include/sys/bqueue.h \
$(top_srcdir)/include/sys/cityhash.h \
$(top_srcdir)/include/sys/dataset_kstats.h \
$(top_srcdir)/include/sys/compress_adaptive.h \
$(top_srcdir)/include/sys/dbuf.h \
$(top_srcdir)/include/sys/ddt.h \
$(top_srcdir)/include/sys/dmu.h \
Expand Down
38 changes: 38 additions & 0 deletions include/sys/compress_adaptive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

#ifndef _SYS_ADAPTIVE_COMPRESS_H
#define _SYS_ADAPTIVE_COMPRESS_H

#define COMPRESS_ADAPTIVE_LEVELS 10

#include <sys/spa.h>
#include <sys/zio.h>

size_t compress_adaptive(zio_t *zio, abd_t *src, void *dst,
size_t s_len, enum zio_compress *c);

void compress_calc_avg_without_zero(uint64_t act, uint64_t *res, int n);

uint64_t compress_calc_Bps(uint64_t byte, hrtime_t delay);


#endif /* _SYS_ADAPTIVE_COMPRESS_H */
13 changes: 13 additions & 0 deletions include/sys/dsl_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ boolean_t dsl_dataset_get_uint64_array_feature(dsl_dataset_t *ds,
void dsl_dataset_activate_redaction(dsl_dataset_t *ds, uint64_t *redact_snaps,
uint64_t num_redact_snaps, dmu_tx_t *tx);


int dsl_dataset_activate_compress_adaptive(const char *ddname);

void dsl_dataset_activate_feature(uint64_t dsobj, spa_feature_t f, void *arg,
dmu_tx_t *tx);
void dsl_dataset_deactivate_feature(dsl_dataset_t *ds, spa_feature_t f,
dmu_tx_t *tx);
boolean_t dsl_dataset_feature_is_active(dsl_dataset_t *ds, spa_feature_t f);
boolean_t dsl_dataset_get_uint64_array_feature(dsl_dataset_t *ds,
spa_feature_t f, uint64_t *outlength, uint64_t **outp);



#ifdef ZFS_DEBUG
#define dprintf_ds(ds, fmt, ...) do { \
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
Expand Down
3 changes: 3 additions & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,9 @@ typedef struct vdev_stat_ex {
uint64_t vsx_agg_histo[ZIO_PRIORITY_NUM_QUEUEABLE]
[VDEV_RQ_HISTO_BUCKETS];


uint64_t vsx_diskBps[ZIO_TYPES];

} vdev_stat_ex_t;

/*
Expand Down
1 change: 1 addition & 0 deletions include/sys/vdev_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct vdev_cache {

typedef struct vdev_queue_class {
uint32_t vqc_active;
uint64_t vqc_queued_size;

/*
* Sorted by offset or timestamp, depending on if the queue is
Expand Down
7 changes: 7 additions & 0 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <sys/avl.h>
#include <sys/fs/zfs.h>
#include <sys/zio_impl.h>
#include <sys/compress_adaptive.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -513,6 +514,12 @@ struct zio {

/* Taskq dispatching state */
taskq_ent_t io_tqent;

/* stored in pio */
uint8_t io_compress_level;
boolean_t io_compress_adaptive_exploring;

uint64_t io_compress_adaptive_Bps[COMPRESS_ADAPTIVE_LEVELS];
};

extern int zio_bookmark_compare(const void *, const void *);
Expand Down
1 change: 1 addition & 0 deletions include/sys/zio_compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum zio_compress {
ZIO_COMPRESS_GZIP_9,
ZIO_COMPRESS_ZLE,
ZIO_COMPRESS_LZ4,
ZIO_COMPRESS_ADAPTIVE,
ZIO_COMPRESS_FUNCTIONS
};

Expand Down
1 change: 1 addition & 0 deletions include/zfeature_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef enum spa_feature {
SPA_FEATURE_BOOKMARK_WRITTEN,
SPA_FEATURE_LOG_SPACEMAP,
SPA_FEATURE_LIVELIST,
SPA_FEATURE_COMPRESS_ADAPTIVE,
SPA_FEATURES
} spa_feature_t;

Expand Down
1 change: 1 addition & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ KERNEL_C = \
btree.c \
bqueue.c \
cityhash.c \
compress_adaptive.c \
dbuf.c \
dbuf_stats.c \
ddt.c \
Expand Down
27 changes: 27 additions & 0 deletions man/man5/zpool-features.5
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,33 @@ This feature becomes \fBactive\fR when a bookmark is created and will be
returned to the \fBenabled\fR state when all bookmarks with these fields are destroyed.
.RE

.sp
.ne 2
.na
\fB\fBcompress_adaptive\fR\fR
.ad
.RS 4n
.TS
l l .
GUID org.zfsonlinux:compress_adaptive
READ\-ONLY COMPATIBLE yes
DEPENDENCIES lz4_compress,extensible_dataset
.TE

\fBcompress_adaptive\fR chooses the compression algorithm out of lz4 and gzip[1-9]
to perform with optimal write throughput.

When the \fBcompress_adaptive\fR feature is set to \fBenabled\fR, the
administrator can turn on \fBcompress_adaptive\fR on any dataset on the
pool using the \fBzfs\fR(8) command. Please note that doing so will
immediately activate the \fBcompress_adaptive\fR feature on the underlying
pool.

This feature becomes \fBactive\fR as soon as it is used on one dataset and will
return to being \fBenabled\fR once all filesystems that have ever had their compression set to
+\fBcompress_adaptive\fR are destroyed.
.RE

.sp
.ne 2
.na
Expand Down
13 changes: 12 additions & 1 deletion man/man8/zfsprops.8
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ for more information on these algorithms.
.Pp
Changing this property affects only newly-written data.
.It Xo
.Sy compression Ns = Ns Sy on Ns | Ns Sy off Ns | Ns Sy gzip Ns | Ns
.Sy compression Ns = Ns Sy on Ns | Ns Sy off Ns | Ns Sy adaptive Ns | Ns Sy gzip Ns | Ns
.Sy gzip- Ns Em N Ns | Ns Sy lz4 Ns | Ns Sy lzjb Ns | Ns Sy zle
.Xc
Controls the compression algorithm used for this dataset.
Expand All @@ -731,6 +731,17 @@ does not select a fixed compression type.
As new compression algorithms are added to ZFS and enabled on a pool, the
default compression algorithm may change.
The current default compression algorithm is either
.Pp
If compression is set to
.Sy adaptive
the optimal compression algorithm out of lz4 and gzip-[1-9] will be choosen based on system load and write performance of the pool's devices, to maintain optimal write speed. To use this compression mode, the
.Sy compress_adaptive
feature flag needs to be enabled. See
.Xr zpool-features 5
for details on ZFS feature flags and the
.Sy compress_adaptive
feature.
.Pp
.Sy lzjb
or, if the
.Sy lz4_compress
Expand Down
13 changes: 13 additions & 0 deletions module/zcommon/zfeature_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ zpool_feature_init(void)
"LZ4 compression algorithm support.",
ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, ZFEATURE_TYPE_BOOLEAN, NULL);

{
static const spa_feature_t compress_adaptive_deps[] = {
SPA_FEATURE_LZ4_COMPRESS,
SPA_FEATURE_EXTENSIBLE_DATASET,
SPA_FEATURE_NONE
};
zfeature_register(SPA_FEATURE_COMPRESS_ADAPTIVE,
"org.zfsonlinux:compress_adaptive", "compress_adaptive",
"adaptive compression algorithm selection support.",
ZFEATURE_FLAG_PER_DATASET | ZFEATURE_FLAG_READONLY_COMPAT,
ZFEATURE_TYPE_BOOLEAN, compress_adaptive_deps);
}

zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
"com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
"Crash dumps to multiple vdev pools.",
Expand Down
5 changes: 3 additions & 2 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ zfs_prop_init(void)
{ "gzip-9", ZIO_COMPRESS_GZIP_9 },
{ "zle", ZIO_COMPRESS_ZLE },
{ "lz4", ZIO_COMPRESS_LZ4 },
{ "adaptive", ZIO_COMPRESS_ADAPTIVE },
{ NULL }
};

Expand Down Expand Up @@ -322,8 +323,8 @@ zfs_prop_init(void)
zprop_register_index(ZFS_PROP_COMPRESSION, "compression",
ZIO_COMPRESS_DEFAULT, PROP_INHERIT,
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
"on | off | lzjb | gzip | gzip-[1-9] | zle | lz4", "COMPRESS",
compress_table);
"on | off | adaptive | lzjb | gzip | gzip-[1-9] | zle | lz4",
"COMPRESS", compress_table);
zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
"hidden | visible", "SNAPDIR", snapdir_table);
Expand Down
1 change: 1 addition & 0 deletions module/zfs/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $(MODULE)-objs += arc.o
$(MODULE)-objs += blkptr.o
$(MODULE)-objs += bplist.o
$(MODULE)-objs += bpobj.o
$(MODULE)-objs += compress_adaptive.o
$(MODULE)-objs += bptree.o
$(MODULE)-objs += btree.o
$(MODULE)-objs += bqueue.o
Expand Down
Loading