Print this page
3756 want lz4 support for metadata compression
@@ -19,10 +19,11 @@
* CDDL HEADER END
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013 by Delphix. All rights reserved.
+ * Copyright (c) 2013 Martin Matuska. All rights reserved.
*/
#include <sys/dmu.h>
#include <sys/dmu_impl.h>
#include <sys/dmu_tx.h>
@@ -40,10 +41,11 @@
#include <sys/zfs_ioctl.h>
#include <sys/zap.h>
#include <sys/zio_checksum.h>
#include <sys/zio_compress.h>
#include <sys/sa.h>
+#include <sys/zfeature.h>
#ifdef _KERNEL
#include <sys/vmsystm.h>
#include <sys/zfs_znode.h>
#endif
@@ -1415,11 +1417,11 @@
SET_BOOKMARK(&zb, ds->ds_object,
db->db.db_object, db->db_level, db->db_blkid);
DB_DNODE_ENTER(db);
dn = DB_DNODE(db);
- dmu_write_policy(os, dn, db->db_level, WP_DMU_SYNC, &zp);
+ dmu_write_policy(os, dn, db->db_level, WP_DMU_SYNC, &zp, txg);
DB_DNODE_EXIT(db);
/*
* If we're frozen (running ziltest), we always need to generate a bp.
*/
@@ -1553,13 +1555,15 @@
dnode_setdirty(dn, tx);
dnode_rele(dn, FTAG);
}
int zfs_mdcomp_disable = 0;
+int zfs_mdcomp_lz4 = 0;
void
-dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp)
+dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, zio_prop_t *zp,
+ uint64_t txg)
{
dmu_object_type_t type = dn ? dn->dn_type : DMU_OT_OBJSET;
boolean_t ismd = (level > 0 || DMU_OT_IS_METADATA(type) ||
(wp & WP_SPILL));
enum zio_checksum checksum = os->os_checksum;
@@ -1580,12 +1584,30 @@
if (ismd) {
/*
* XXX -- we should design a compression algorithm
* that specializes in arrays of bps.
*/
- compress = zfs_mdcomp_disable ? ZIO_COMPRESS_EMPTY :
- ZIO_COMPRESS_LZJB;
+ if (zfs_mdcomp_disable)
+ compress = ZIO_COMPRESS_EMPTY;
+ else if (zfs_mdcomp_lz4 && os->os_spa != NULL) {
+ zfeature_info_t *feat = &spa_feature_table
+ [SPA_FEATURE_LZ4_COMPRESS];
+
+ if (spa_feature_is_active(os->os_spa, feat))
+ compress = ZIO_COMPRESS_LZ4;
+ else if (spa_feature_is_enabled(os->os_spa, feat)) {
+ dmu_tx_t *tx;
+
+ tx = dmu_tx_create_assigned(
+ spa_get_dsl(os->os_spa), txg);
+ spa_feature_incr(os->os_spa, feat, tx);
+ dmu_tx_commit(tx);
+ compress = ZIO_COMPRESS_LZ4;
+ } else
+ compress = ZIO_COMPRESS_LZJB;
+ } else
+ compress = ZIO_COMPRESS_LZJB;
/*
* Metadata always gets checksummed. If the data
* checksum is multi-bit correctable, and it's not a
* ZBT-style checksum, then it's suitable for metadata