Illumos #1092: zfs refratio property
authorMatt Ahrens <Matt.Ahrens@delphix.com>
Tue, 26 Jul 2011 19:23:00 +0000 (12:23 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 1 Aug 2011 19:09:11 +0000 (12:09 -0700)
Add a "REFRATIO" property, which is the compression ratio based on
data referenced. For snapshots, this is the same as COMPRESSRATIO,
but for filesystems/volumes, the COMPRESSRATIO is based on the
data "USED" (ie, includes blocks in children, but not blocks
shared with the origin).

This is needed to figure out how much space a filesystem would
use if it were not compressed (ignoring snapshots).

Reviewed by: George Wilson <George.Wilson@delphix.com>
Reviewed by: Adam Leventhal <Adam.Leventhal@delphix.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Reviewed by: Richard Elling <richard.elling@richardelling.com>
Reviewed by: Mark Musante <Mark.Musante@oracle.com>
Reviewed by: Garrett D'Amore <garrett@nexenta.com>
Approved by: Garrett D'Amore <garrett@nexenta.com>

References to Illumos issue and patch:
- https://www.illumos.org/issues/1092
- https://github.com/illumos/illumos-gate/commit/187d6ac08a

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #340

include/sys/fs/zfs.h
lib/libzfs/libzfs_dataset.c
man/man8/zfs.8
module/zcommon/zfs_prop.c
module/zfs/dsl_dataset.c

index a2b68ed..2ac84f6 100644 (file)
@@ -21,6 +21,7 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 by Delphix. All rights reserved.
  */
 
 /* Portions Copyright 2010 Robert Milkowski */
@@ -122,6 +123,7 @@ typedef enum {
        ZFS_PROP_DEDUP,
        ZFS_PROP_MLSLABEL,
        ZFS_PROP_SYNC,
+       ZFS_PROP_REFRATIO,
        ZFS_NUM_PROPS
 } zfs_prop_t;
 
index 5f8847a..996bae2 100644 (file)
@@ -21,6 +21,7 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 by Delphix. All rights reserved.
  */
 
 #include <ctype.h>
@@ -2025,6 +2026,7 @@ zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
                }
                break;
 
+       case ZFS_PROP_REFRATIO:
        case ZFS_PROP_COMPRESSRATIO:
                if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
                        return (-1);
index 3da2e44..26dc6ca 100644 (file)
@@ -360,7 +360,7 @@ This property can also be referred to by its shortened column name, \fBavail\fR.
 .ad
 .sp .6
 .RS 4n
-The compression ratio achieved for this dataset, expressed as a multiplier. Compression can be turned on by running: \fBzfs set compression=on \fIdataset\fR\fR. The default value is \fBoff\fR.
+For non-snapshots, the compression ratio achieved for the \fBused\fR space of this dataset, expressed as a multiplier.  The \fBused\fR property includes descendant datasets, and, for clones, does not include the space shared with the origin snapshot.  For snapshots, the \fBcompressratio\fR is the same as the \fBrefcompressratio\fR property.  Compression can be turned on by running: \fBzfs set compression=on \fIdataset\fR\fR. The default value is \fBoff\fR.
 .RE
 
 .sp
@@ -424,6 +424,19 @@ This property can also be referred to by its shortened column name, \fBrefer\fR.
 .ne 2
 .mk
 .na
+\fB\fBrefcompressratio\fR\fR
+.ad
+.sp .6
+.RS 4n
+The compression ratio achieved for the \fBreferenced\fR space of this
+dataset, expressed as a multiplier.  See also the \fBcompressratio\fR
+property.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
 \fB\fBtype\fR\fR
 .ad
 .sp .6
@@ -1235,7 +1248,7 @@ Recursively destroy all dependents, including cloned file systems outside the ta
 Force an unmount of any file systems using the \fBunmount -f\fR command. This option has no effect on non-file systems or unmounted file systems.
 .RE
 
-Extreme care should be taken when applying either the \fB-r\fR or the \fB-f\fR options, as they can destroy large portions of a pool and cause unexpected behavior for mounted file systems in use. 
+Extreme care should be taken when applying either the \fB-r\fR or the \fB-R\fR options, as they can destroy large portions of a pool and cause unexpected behavior for mounted file systems in use.
 .RE
 
 .sp
index ce03a49..9d65e35 100644 (file)
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 by Delphix. All rights reserved.
  */
 
 /* Portions Copyright 2010 Robert Milkowski */
@@ -311,6 +312,9 @@ zfs_prop_init(void)
        zprop_register_number(ZFS_PROP_COMPRESSRATIO, "compressratio", 0,
            PROP_READONLY, ZFS_TYPE_DATASET,
            "<1.00x or higher if compressed>", "RATIO");
+       zprop_register_number(ZFS_PROP_REFRATIO, "refcompressratio", 0,
+           PROP_READONLY, ZFS_TYPE_DATASET,
+           "<1.00x or higher if compressed>", "REFRATIO");
        zprop_register_number(ZFS_PROP_VOLBLOCKSIZE, "volblocksize",
            ZVOL_DEFAULT_BLOCKSIZE, PROP_ONETIME,
            ZFS_TYPE_VOLUME, "512 to 128k, power of 2", "VOLBLOCK");
index c34ac2a..26362c9 100644 (file)
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 by Delphix. All rights reserved.
  */
 
 #include <sys/dmu_objset.h>
@@ -2153,7 +2154,7 @@ dsl_dataset_sync(dsl_dataset_t *ds, zio_t *zio, dmu_tx_t *tx)
 void
 dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv)
 {
-       uint64_t refd, avail, uobjs, aobjs;
+       uint64_t refd, avail, uobjs, aobjs, ratio;
 
        dsl_dir_stats(ds->ds_dir, nv);
 
@@ -2180,6 +2181,11 @@ dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv)
        dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_DEFER_DESTROY,
            DS_IS_DEFER_DESTROY(ds) ? 1 : 0);
 
+       ratio = ds->ds_phys->ds_compressed_bytes == 0 ? 100 :
+           (ds->ds_phys->ds_uncompressed_bytes * 100 /
+           ds->ds_phys->ds_compressed_bytes);
+       dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRATIO, ratio);
+
        if (ds->ds_phys->ds_next_snap_obj) {
                /*
                 * This is a snapshot; override the dd's space used with
@@ -2187,10 +2193,7 @@ dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv)
                 */
                dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED,
                    ds->ds_phys->ds_unique_bytes);
-               dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO,
-                   ds->ds_phys->ds_compressed_bytes == 0 ? 100 :
-                   (ds->ds_phys->ds_uncompressed_bytes * 100 /
-                   ds->ds_phys->ds_compressed_bytes));
+               dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO, ratio);
        }
 }