Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c =================================================================== --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c (revision 250142) +++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dbuf.c (working copy) @@ -22,6 +22,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2013 by Delphix. All rights reserved. + * Copyright (c) 2013 Martin Matuska. All rights reserved. */ #include @@ -2686,7 +2687,7 @@ wp_flag = WP_SPILL; wp_flag |= (db->db_state == DB_NOFILL) ? WP_NOFILL : 0; - dmu_write_policy(os, dn, db->db_level, wp_flag, &zp); + dmu_write_policy(os, dn, db->db_level, wp_flag, &zp, txg); DB_DNODE_EXIT(db); if (db->db_level == 0 && dr->dt.dl.dr_override_state == DR_OVERRIDDEN) { Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c =================================================================== --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c (revision 250142) +++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu.c (working copy) @@ -21,6 +21,7 @@ /* * 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 @@ -42,6 +43,7 @@ #include #include #include +#include #ifdef _KERNEL #include #endif @@ -1427,7 +1429,7 @@ 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); /* @@ -1569,8 +1571,14 @@ SYSCTL_INT(_vfs_zfs, OID_AUTO, mdcomp_disable, CTLFLAG_RW, &zfs_mdcomp_disable, 0, "Disable metadata compression"); +int zfs_mdcomp_lz4 = 0; +TUNABLE_INT("vfs.zfs.mdcomp_lz4", &zfs_mdcomp_lz4); +SYSCTL_INT(_vfs_zfs, OID_AUTO, mdcomp_lz4, CTLFLAG_RW, + &zfs_mdcomp_lz4, 0, "Compress metadata with lz4"); + 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) || @@ -1595,9 +1603,27 @@ * 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 Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c =================================================================== --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c (revision 250142) +++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_objset.c (working copy) @@ -21,6 +21,7 @@ /* * 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. */ /* Portions Copyright 2010 Robert Milkowski */ @@ -988,7 +989,7 @@ ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID); arc_release(os->os_phys_buf, &os->os_phys_buf); - dmu_write_policy(os, NULL, 0, 0, &zp); + dmu_write_policy(os, NULL, 0, 0, &zp, tx->tx_txg); zio = arc_write(pio, os->os_spa, tx->tx_txg, os->os_rootbp, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os), &zp, Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h =================================================================== --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h (revision 250142) +++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h (working copy) @@ -24,6 +24,7 @@ * Copyright (c) 2012 by Delphix. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2012, Joyent, Inc. All rights reserved. + * Copyright (c) 2013 Martin Matuska. All rights reserved. */ /* Portions Copyright 2010 Robert Milkowski */ @@ -401,7 +402,7 @@ #define WP_SPILL 0x4 void dmu_write_policy(objset_t *os, struct dnode *dn, int level, int wp, - struct zio_prop *zp); + struct zio_prop *zp, uint64_t txg); /* * The bonus data is accessed more or less like a regular buffer. * You must dmu_bonus_hold() to get the buffer, which will give you a