diff --git a/module/zfs/metaslab.c b/module/zfs/metaslab.c index 35bd968f6..c1424a81b 100644 --- a/module/zfs/metaslab.c +++ b/module/zfs/metaslab.c @@ -3545,6 +3545,15 @@ metaslab_segment_may_passivate(metaslab_t *msp) if (WEIGHT_IS_SPACEBASED(msp->ms_weight) || spa_sync_pass(spa) > 1) return; + /* + * As long as a single largest free segment covers majorioty of free + * space, don't consider the metaslab fragmented. It should allow + * us to fill new unfragmented metaslabs full before switching. + */ + if (metaslab_largest_allocatable(msp) > + zfs_range_tree_space(msp->ms_allocatable) * 15 / 16) + return; + /* * Since we are in the middle of a sync pass, the most accurate * information that is accessible to us is the in-core range tree