Fix available space accounting for special/dedup (#18222)

Currently, spa_dspace (base to calculate dataset AVAIL) only includes
the normal allocation class capacity, but dd_used_bytes tracks space
allocated across all classes.  Since we don't want to report free
space of other classes as available (we can't promise new allocations
will be able to use it), report only allocated space, similar to how
we report space saved by dedup and block cloning.

Since we need deflated space here, make allocation classes track
deflated allocated space also.  While here, make mc_deferred also
deflated, matching its use contexts.  Also while there, use
atomic_load() to read the allocation class stats.

Reviewed-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <alexander.motin@TrueNAS.com>
Closes #18190
Closes #18222
This commit is contained in:
Alexander Motin
2026-02-19 13:36:35 -05:00
committed by Tony Hutter
parent 46500a0803
commit 3dcd071b51
6 changed files with 60 additions and 36 deletions
+5 -3
View File
@@ -199,10 +199,12 @@ struct metaslab_class {
uint64_t mc_alloc_groups; /* # of allocatable groups */
uint64_t mc_alloc; /* total allocated space */
uint64_t mc_deferred; /* total deferred frees */
uint64_t mc_alloc; /* allocated space */
uint64_t mc_dalloc; /* deflated allocated space */
uint64_t mc_deferred; /* deferred frees */
uint64_t mc_ddeferred; /* deflated deferred frees */
uint64_t mc_space; /* total space (alloc + free) */
uint64_t mc_dspace; /* total deflated space */
uint64_t mc_dspace; /* deflated total space */
uint64_t mc_histogram[ZFS_RANGE_TREE_HISTOGRAM_SIZE];
/*