From c0672efab56c21d0e7da334b27cd4ed18b16c1a4 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Tue, 1 Jul 2014 21:19:10 +0000 Subject: [PATCH] 4924 LZ4 Compression for metadata Reviewed by Matthew Ahrens Reviewed by Saso Kiselkov Approved by: Christopher Siden illumos/illumos-gate@b8289d24d866c1af02d7007348f7f057693c15d3 --- common/zfs/zfeature_common.c | 3 ++- man/man5/zpool-features.5 | 15 ++++++++------- uts/common/fs/zfs/dmu.c | 14 ++++++++++++-- uts/common/fs/zfs/spa.c | 18 +++++++++++++++++- uts/common/fs/zfs/zfs_ioctl.c | 32 +------------------------------- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/common/zfs/zfeature_common.c b/common/zfs/zfeature_common.c index 447c64cc2007..9b046ab07db1 100644 --- a/common/zfs/zfeature_common.c +++ b/common/zfs/zfeature_common.c @@ -23,6 +23,7 @@ * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved. */ #ifdef _KERNEL @@ -169,7 +170,7 @@ zpool_feature_init(void) zfeature_register(SPA_FEATURE_LZ4_COMPRESS, "org.illumos:lz4_compress", "lz4_compress", "LZ4 compression algorithm support.", B_FALSE, B_FALSE, - B_FALSE, NULL); + B_TRUE, NULL); zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP, "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump", diff --git a/man/man5/zpool-features.5 b/man/man5/zpool-features.5 index d21ffc9f5e33..24398124f0f7 100644 --- a/man/man5/zpool-features.5 +++ b/man/man5/zpool-features.5 @@ -243,13 +243,14 @@ giving approximately 10% better compression ratio. When the \fBlz4_compress\fR feature is set to \fBenabled\fR, the administrator can turn on \fBlz4\fR compression on any dataset on the -pool using the \fBzfs\fR(1M) command. Please note that doing so will -immediately activate the \fBlz4_compress\fR feature on the underlying -pool (even before any data is written), and the feature will not be -deactivated. Since this feature is not read-only compatible, this -operation will render the pool unimportable on systems without support -for the \fBlz4_compress\fR feature. Booting off of \fBlz4\fR-compressed -root pools is supported. +pool using the \fBzfs\fR(1M) command. Also, all newly written metadata +will be compressed with \fBlz4\fR algorithm. Since this feature is not +read-only compatible, this operation will render the pool unimportable +on systems without support for the \fBlz4_compress\fR feature. Booting +off of \fBlz4\fR-compressed root pools is supported. + +This feature becomes \fBactive\fR as soon as it is enabled and will +never return to being \fBenabled\fB. .RE .sp diff --git a/uts/common/fs/zfs/dmu.c b/uts/common/fs/zfs/dmu.c index 1a62ddb48b15..a1bd0d810301 100644 --- a/uts/common/fs/zfs/dmu.c +++ b/uts/common/fs/zfs/dmu.c @@ -24,6 +24,7 @@ */ /* Copyright (c) 2013 by Saso Kiselkov. All rights reserved. */ /* Copyright (c) 2013, Joyent, Inc. All rights reserved. */ +/* Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved. */ #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #ifdef _KERNEL #include #include @@ -1635,8 +1637,16 @@ dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp) * XXX -- we should design a compression algorithm * that specializes in arrays of bps. */ - compress = zfs_mdcomp_disable ? ZIO_COMPRESS_EMPTY : - ZIO_COMPRESS_LZJB; + boolean_t lz4_ac = spa_feature_is_active(os->os_spa, + SPA_FEATURE_LZ4_COMPRESS); + + if (zfs_mdcomp_disable) { + compress = ZIO_COMPRESS_EMPTY; + } else if (lz4_ac) { + compress = ZIO_COMPRESS_LZ4; + } else { + compress = ZIO_COMPRESS_LZJB; + } /* * Metadata always gets checksummed. If the data diff --git a/uts/common/fs/zfs/spa.c b/uts/common/fs/zfs/spa.c index 2aedc4279dba..c8cabb2c32e3 100644 --- a/uts/common/fs/zfs/spa.c +++ b/uts/common/fs/zfs/spa.c @@ -22,7 +22,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2014 by Delphix. All rights reserved. - * Copyright 2013 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2013, 2014, Nexenta Systems, Inc. All rights reserved. */ /* @@ -6106,6 +6106,22 @@ spa_sync_upgrades(spa_t *spa, dmu_tx_t *tx) spa->spa_uberblock.ub_version >= SPA_VERSION_FEATURES) { spa_feature_create_zap_objects(spa, tx); } + + /* + * LZ4_COMPRESS feature's behaviour was changed to activate_on_enable + * when possibility to use lz4 compression for metadata was added + * Old pools that have this feature enabled must be upgraded to have + * this feature active + */ + if (spa->spa_uberblock.ub_version >= SPA_VERSION_FEATURES) { + boolean_t lz4_en = spa_feature_is_enabled(spa, + SPA_FEATURE_LZ4_COMPRESS); + boolean_t lz4_ac = spa_feature_is_active(spa, + SPA_FEATURE_LZ4_COMPRESS); + + if (lz4_en && !lz4_ac) + spa_feature_incr(spa, SPA_FEATURE_LZ4_COMPRESS, tx); + } rrw_exit(&dp->dp_config_rwlock, FTAG); } diff --git a/uts/common/fs/zfs/zfs_ioctl.c b/uts/common/fs/zfs/zfs_ioctl.c index 01105be5c51c..83ec68854ed2 100644 --- a/uts/common/fs/zfs/zfs_ioctl.c +++ b/uts/common/fs/zfs/zfs_ioctl.c @@ -27,6 +27,7 @@ * Copyright (c) 2013 by Delphix. All rights reserved. * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. * Copyright (c) 2013 Steven Hartland. All rights reserved. + * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved. */ /* @@ -2453,37 +2454,6 @@ zfs_prop_set_special(const char *dsname, zprop_source_t source, } break; } - case ZFS_PROP_COMPRESSION: - { - if (intval == ZIO_COMPRESS_LZ4) { - spa_t *spa; - - if ((err = spa_open(dsname, &spa, FTAG)) != 0) - return (err); - - /* - * Setting the LZ4 compression algorithm activates - * the feature. - */ - if (!spa_feature_is_active(spa, - SPA_FEATURE_LZ4_COMPRESS)) { - if ((err = zfs_prop_activate_feature(spa, - SPA_FEATURE_LZ4_COMPRESS)) != 0) { - spa_close(spa, FTAG); - return (err); - } - } - - spa_close(spa, FTAG); - } - /* - * We still want the default set action to be performed in the - * caller, we only performed zfeature settings here. - */ - err = -1; - break; - } - default: err = -1; }