@@ -289,8 +289,8 @@ int zfs_metaslab_mem_limit = 25;
289
289
*/
290
290
unsigned long zfs_metaslab_max_size_cache_sec = 3600 ; /* 1 hour */
291
291
292
- static uint64_t metaslab_weight (metaslab_t * );
293
- static void metaslab_set_fragmentation (metaslab_t * );
292
+ static uint64_t metaslab_weight (metaslab_t * , boolean_t );
293
+ static void metaslab_set_fragmentation (metaslab_t * , boolean_t );
294
294
static void metaslab_free_impl (vdev_t * , uint64_t , uint64_t , boolean_t );
295
295
static void metaslab_check_free_impl (vdev_t * , uint64_t , uint64_t );
296
296
@@ -1845,13 +1845,19 @@ metaslab_verify_weight_and_frag(metaslab_t *msp)
1845
1845
msp -> ms_fragmentation = 0 ;
1846
1846
1847
1847
/*
1848
- * This function is used for verification purposes. Regardless of
1849
- * whether metaslab_weight() thinks this metaslab should be active or
1850
- * not, we want to ensure that the actual weight (and therefore the
1851
- * value of ms_weight) would be the same if it was to be recalculated
1852
- * at this point.
1848
+ * This function is used for verification purposes and thus should
1849
+ * not introduce any side-effects/mutations on the system's state.
1850
+ *
1851
+ * Regardless of whether metaslab_weight() thinks this metaslab
1852
+ * should be active or not, we want to ensure that the actual weight
1853
+ * (and therefore the value of ms_weight) would be the same if it
1854
+ * was to be recalculated at this point.
1855
+ *
1856
+ * In addition we set the nodirty flag so metaslab_weight() does
1857
+ * not dirty the metaslab for future TXGs (e.g. when trying to
1858
+ * force condensing to upgrade the metaslab spacemaps).
1853
1859
*/
1854
- msp -> ms_weight = metaslab_weight (msp ) | was_active ;
1860
+ msp -> ms_weight = metaslab_weight (msp , B_TRUE ) | was_active ;
1855
1861
1856
1862
VERIFY3U (max_segsize , = = , msp -> ms_max_size );
1857
1863
@@ -2335,7 +2341,7 @@ metaslab_init(metaslab_group_t *mg, uint64_t id, uint64_t object,
2335
2341
ms -> ms_trim = range_tree_create (NULL , NULL );
2336
2342
2337
2343
metaslab_group_add (mg , ms );
2338
- metaslab_set_fragmentation (ms );
2344
+ metaslab_set_fragmentation (ms , B_FALSE );
2339
2345
2340
2346
/*
2341
2347
* If we're opening an existing pool (txg == 0) or creating
@@ -2497,7 +2503,7 @@ int zfs_frag_table[FRAGMENTATION_TABLE_SIZE] = {
2497
2503
* value should be in the range [0, 100].
2498
2504
*/
2499
2505
static void
2500
- metaslab_set_fragmentation (metaslab_t * msp )
2506
+ metaslab_set_fragmentation (metaslab_t * msp , boolean_t nodirty )
2501
2507
{
2502
2508
spa_t * spa = msp -> ms_group -> mg_vd -> vdev_spa ;
2503
2509
uint64_t fragmentation = 0 ;
@@ -2532,9 +2538,11 @@ metaslab_set_fragmentation(metaslab_t *msp)
2532
2538
* be shutting down the pool. We don't want to dirty
2533
2539
* any data past this point so skip setting the condense
2534
2540
* flag. We can retry this action the next time the pool
2535
- * is imported.
2541
+ * is imported. We also skip marking this metaslab for
2542
+ * condensing if the caller has explicitly set nodirty.
2536
2543
*/
2537
- if (spa_writeable (spa ) && txg < spa_final_dirty_txg (spa )) {
2544
+ if (!nodirty &&
2545
+ spa_writeable (spa ) && txg < spa_final_dirty_txg (spa )) {
2538
2546
msp -> ms_condense_wanted = B_TRUE ;
2539
2547
vdev_dirty (vd , VDD_METASLAB , msp , txg + 1 );
2540
2548
zfs_dbgmsg ("txg %llu, requesting force condense: "
@@ -2831,16 +2839,17 @@ metaslab_should_allocate(metaslab_t *msp, uint64_t asize, boolean_t try_hard)
2831
2839
2832
2840
return (should_allocate );
2833
2841
}
2842
+
2834
2843
static uint64_t
2835
- metaslab_weight (metaslab_t * msp )
2844
+ metaslab_weight (metaslab_t * msp , boolean_t nodirty )
2836
2845
{
2837
2846
vdev_t * vd = msp -> ms_group -> mg_vd ;
2838
2847
spa_t * spa = vd -> vdev_spa ;
2839
2848
uint64_t weight ;
2840
2849
2841
2850
ASSERT (MUTEX_HELD (& msp -> ms_lock ));
2842
2851
2843
- metaslab_set_fragmentation (msp );
2852
+ metaslab_set_fragmentation (msp , nodirty );
2844
2853
2845
2854
/*
2846
2855
* Update the maximum size. If the metaslab is loaded, this will
@@ -2881,7 +2890,7 @@ metaslab_recalculate_weight_and_sort(metaslab_t *msp)
2881
2890
/* note: we preserve the mask (e.g. indication of primary, etc..) */
2882
2891
uint64_t was_active = msp -> ms_weight & METASLAB_ACTIVE_MASK ;
2883
2892
metaslab_group_sort (msp -> ms_group , msp ,
2884
- metaslab_weight (msp ) | was_active );
2893
+ metaslab_weight (msp , B_FALSE ) | was_active );
2885
2894
}
2886
2895
2887
2896
static int
0 commit comments