Skip to content

Commit 991fc56

Browse files
authored
Introduce dedupused/dedupsaved pool properties
Currently there is only a dedup ratio reported via pool properties. If dedup is enabled only for some datasets, it is impossible to say how much space the ratio actually covers. Fix this by introducing dedupused/dedupsaved pool properties, similar to earlier added block cloning ones. Combined with work to expose allocation classes stats, it should give user-space enough visibility to correlate `zpool list` and `zfs list` space numbers. Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Ryan Moeller <ryan.moeller@klarasystems.com> Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com> Closes #18245
1 parent 3408332 commit 991fc56

File tree

10 files changed

+53
-3
lines changed

10 files changed

+53
-3
lines changed

include/sys/ddt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ extern void ddt_get_dedup_histogram(spa_t *spa, ddt_histogram_t *ddh);
396396
extern void ddt_get_dedup_stats(spa_t *spa, ddt_stat_t *dds_total);
397397

398398
extern uint64_t ddt_get_dedup_dspace(spa_t *spa);
399+
extern uint64_t ddt_get_dedup_used(spa_t *spa);
400+
extern uint64_t ddt_get_dedup_saved(spa_t *spa);
399401
extern uint64_t ddt_get_pool_dedup_ratio(spa_t *spa);
400402
extern int ddt_get_pool_dedup_cached(spa_t *spa, uint64_t *psize);
401403

include/sys/fs/zfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ typedef enum {
273273
ZPOOL_PROP_DEDUP_TABLE_QUOTA,
274274
ZPOOL_PROP_DEDUPCACHED,
275275
ZPOOL_PROP_LAST_SCRUBBED_TXG,
276+
ZPOOL_PROP_DEDUPUSED,
277+
ZPOOL_PROP_DEDUPSAVED,
276278
ZPOOL_NUM_PROPS
277279
} zpool_prop_t;
278280

lib/libzfs/libzfs.abi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,9 @@
33703370
<enumerator name='ZPOOL_PROP_DEDUP_TABLE_QUOTA' value='37'/>
33713371
<enumerator name='ZPOOL_PROP_DEDUPCACHED' value='38'/>
33723372
<enumerator name='ZPOOL_PROP_LAST_SCRUBBED_TXG' value='39'/>
3373-
<enumerator name='ZPOOL_NUM_PROPS' value='40'/>
3373+
<enumerator name='ZPOOL_PROP_DEDUPUSED' value='40'/>
3374+
<enumerator name='ZPOOL_PROP_DEDUPSAVED' value='41'/>
3375+
<enumerator name='ZPOOL_NUM_PROPS' value='42'/>
33743376
</enum-decl>
33753377
<typedef-decl name='zpool_prop_t' type-id='af1ba157' id='5d0c23fb'/>
33763378
<typedef-decl name='regoff_t' type-id='95e97e5e' id='54a2a2a8'/>

lib/libzfs/libzfs_pool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf,
380380
case ZPOOL_PROP_BCLONESAVED:
381381
case ZPOOL_PROP_BCLONEUSED:
382382
case ZPOOL_PROP_DEDUP_TABLE_SIZE:
383+
case ZPOOL_PROP_DEDUPUSED:
384+
case ZPOOL_PROP_DEDUPSAVED:
383385
case ZPOOL_PROP_DEDUPCACHED:
384386
if (literal)
385387
(void) snprintf(buf, len, "%llu",

man/man7/zpoolprops.7

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ See
8080
.Xr zpool-prefetch 8 .
8181
.It Sy dedup_table_size
8282
Total on-disk size of the deduplication table.
83+
.It Sy dedupratio
84+
The ratio of the total amount of storage that would be required to store all
85+
the deduplicated blocks without deduplication to the actual storage used.
86+
The
87+
.Sy dedupratio
88+
property is calculated as:
89+
.Pp
90+
.Sy ( ( dedupsaved + dedupused ) * 100 ) / dedupused
91+
.It Sy dedupsaved
92+
The amount of additional storage that would be required if deduplication
93+
was not used.
94+
This represents the space saved by deduplication.
95+
.It Sy dedupused
96+
The amount of storage used by deduplicated blocks.
97+
This is the actual physical space occupied on disk after deduplication.
8398
.It Sy expandsize
8499
Amount of uninitialized space within the pool or device that can be used to
85100
increase the total capacity of the pool.

module/zcommon/zpool_prop.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ zpool_prop_init(void)
117117
zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
118118
PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
119119
"DEDUP", B_FALSE, sfeatures);
120+
zprop_register_number(ZPOOL_PROP_DEDUPUSED, "dedupused", 0,
121+
PROP_READONLY, ZFS_TYPE_POOL, "<size>",
122+
"DEDUP_USED", B_FALSE, sfeatures);
123+
zprop_register_number(ZPOOL_PROP_DEDUPSAVED, "dedupsaved", 0,
124+
PROP_READONLY, ZFS_TYPE_POOL, "<size>",
125+
"DEDUP_SAVED", B_FALSE, sfeatures);
120126
zprop_register_number(ZPOOL_PROP_BCLONEUSED, "bcloneused", 0,
121127
PROP_READONLY, ZFS_TYPE_POOL, "<size>",
122128
"BCLONE_USED", B_FALSE, sfeatures);

module/zfs/ddt_stats.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,21 @@ ddt_get_dedup_dspace(spa_t *spa)
297297
return (spa->spa_dedup_dspace);
298298
}
299299

300+
uint64_t
301+
ddt_get_dedup_used(spa_t *spa)
302+
{
303+
ddt_stat_t dds_total = { 0 };
304+
305+
ddt_get_dedup_stats(spa, &dds_total);
306+
return (dds_total.dds_dsize);
307+
}
308+
309+
uint64_t
310+
ddt_get_dedup_saved(spa_t *spa)
311+
{
312+
return (ddt_get_dedup_dspace(spa));
313+
}
314+
300315
uint64_t
301316
ddt_get_pool_dedup_ratio(spa_t *spa)
302317
{

module/zfs/spa.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ spa_prop_get_config(spa_t *spa, nvlist_t *nv)
483483

484484
spa_prop_add_list(nv, ZPOOL_PROP_DEDUPRATIO, NULL,
485485
ddt_get_pool_dedup_ratio(spa), src);
486+
spa_prop_add_list(nv, ZPOOL_PROP_DEDUPUSED, NULL,
487+
ddt_get_dedup_used(spa), src);
488+
spa_prop_add_list(nv, ZPOOL_PROP_DEDUPSAVED, NULL,
489+
ddt_get_dedup_saved(spa), src);
486490
spa_prop_add_list(nv, ZPOOL_PROP_BCLONEUSED, NULL,
487491
brt_get_used(spa), src);
488492
spa_prop_add_list(nv, ZPOOL_PROP_BCLONESAVED, NULL,

tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typeset -a properties=(
6565
"bclonesaved"
6666
"bcloneratio"
6767
"last_scrubbed_txg"
68+
"dedupused"
69+
"dedupsaved"
6870
"feature@async_destroy"
6971
"feature@empty_bpobj"
7072
"feature@lz4_compress"

tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get_parsable.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
#
3131

3232
# Set the expected properties of zpool
33-
typeset -a properties=("allocated" "capacity" "expandsize" "free" "freeing"
34-
"leaked" "size")
33+
typeset -a properties=("allocated" "bcloneused" "bclonesaved" "capacity"
34+
"dedupused" "dedupsaved" "expandsize" "free" "freeing" "leaked" "size")

0 commit comments

Comments
 (0)