Print this page
4101 metaslab_debug should allow for fine-grained control
4102 space_maps should store more information about themselves
4103 space map object blocksize should be increased
4104 ::spa_space no longer works
4105 removing a mirrored log device results in a leaked object
4106 asynchronously load metaslab
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Sebastien Roy <seb@delphix.com>


  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2013 by Delphix. All rights reserved.
  28  */
  29 
  30 #ifndef _SYS_METASLAB_IMPL_H
  31 #define _SYS_METASLAB_IMPL_H
  32 
  33 #include <sys/metaslab.h>
  34 #include <sys/space_map.h>

  35 #include <sys/vdev.h>
  36 #include <sys/txg.h>
  37 #include <sys/avl.h>
  38 
  39 #ifdef  __cplusplus
  40 extern "C" {
  41 #endif
  42 
  43 struct metaslab_class {
  44         spa_t                   *mc_spa;
  45         metaslab_group_t        *mc_rotor;
  46         space_map_ops_t         *mc_ops;
  47         uint64_t                mc_aliquot;
  48         uint64_t                mc_alloc_groups; /* # of allocatable groups */
  49         uint64_t                mc_alloc;       /* total allocated space */
  50         uint64_t                mc_deferred;    /* total deferred frees */
  51         uint64_t                mc_space;       /* total space (alloc + free) */
  52         uint64_t                mc_dspace;      /* total deflated space */
  53 };
  54 
  55 struct metaslab_group {
  56         kmutex_t                mg_lock;
  57         avl_tree_t              mg_metaslab_tree;
  58         uint64_t                mg_aliquot;
  59         uint64_t                mg_bonus_area;
  60         uint64_t                mg_alloc_failures;
  61         boolean_t               mg_allocatable;         /* can we allocate? */
  62         uint64_t                mg_free_capacity;       /* percentage free */
  63         int64_t                 mg_bias;
  64         int64_t                 mg_activation_count;
  65         metaslab_class_t        *mg_class;
  66         vdev_t                  *mg_vd;

  67         metaslab_group_t        *mg_prev;
  68         metaslab_group_t        *mg_next;
  69 };
  70 
  71 /*
  72  * Each metaslab maintains an in-core free map (ms_map) that contains the
  73  * current list of free segments. As blocks are allocated, the allocated
  74  * segment is removed from the ms_map and added to a per txg allocation map.
  75  * As blocks are freed, they are added to the per txg free map. These per
  76  * txg maps allow us to process all allocations and frees in syncing context
  77  * where it is safe to update the on-disk space maps.
















  78  *
  79  * Each metaslab's free space is tracked in a space map object in the MOS,
















  80  * which is only updated in syncing context. Each time we sync a txg,
  81  * we append the allocs and frees from that txg to the space map object.
  82  * When the txg is done syncing, metaslab_sync_done() updates ms_smo
  83  * to ms_smo_syncing. Everything in ms_smo is always safe to allocate.
  84  *
  85  * To load the in-core free map we read the space map object from disk.
  86  * This object contains a series of alloc and free records that are
  87  * combined to make up the list of all free segments in this metaslab. These
  88  * segments are represented in-core by the ms_map and are stored in an
  89  * AVL tree.
  90  *
  91  * As the space map objects grows (as a result of the appends) it will
  92  * eventually become space-inefficient. When the space map object is
  93  * zfs_condense_pct/100 times the size of the minimal on-disk representation,
  94  * we rewrite it in its minimized form.


  95  */
  96 struct metaslab {
  97         kmutex_t        ms_lock;        /* metaslab lock                */
  98         space_map_obj_t ms_smo;         /* synced space map object      */
  99         space_map_obj_t ms_smo_syncing; /* syncing space map object     */
 100         space_map_t     *ms_allocmap[TXG_SIZE]; /* allocated this txg   */
 101         space_map_t     *ms_freemap[TXG_SIZE];  /* freed this txg       */
 102         space_map_t     *ms_defermap[TXG_DEFER_SIZE];   /* deferred frees */
 103         space_map_t     *ms_map;        /* in-core free space map       */










 104         int64_t         ms_deferspace;  /* sum of ms_defermap[] space   */
 105         uint64_t        ms_weight;      /* weight vs. others in group   */













 106         metaslab_group_t *ms_group;     /* metaslab group               */
 107         avl_node_t      ms_group_node;  /* node in metaslab group tree  */
 108         txg_node_t      ms_txg_node;    /* per-txg dirty metaslab links */
 109 };
 110 
 111 #ifdef  __cplusplus
 112 }
 113 #endif
 114 
 115 #endif  /* _SYS_METASLAB_IMPL_H */


  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright (c) 2013 by Delphix. All rights reserved.
  28  */
  29 
  30 #ifndef _SYS_METASLAB_IMPL_H
  31 #define _SYS_METASLAB_IMPL_H
  32 
  33 #include <sys/metaslab.h>
  34 #include <sys/space_map.h>
  35 #include <sys/range_tree.h>
  36 #include <sys/vdev.h>
  37 #include <sys/txg.h>
  38 #include <sys/avl.h>
  39 
  40 #ifdef  __cplusplus
  41 extern "C" {
  42 #endif
  43 
  44 struct metaslab_class {
  45         spa_t                   *mc_spa;
  46         metaslab_group_t        *mc_rotor;
  47         metaslab_ops_t          *mc_ops;
  48         uint64_t                mc_aliquot;
  49         uint64_t                mc_alloc_groups; /* # of allocatable groups */
  50         uint64_t                mc_alloc;       /* total allocated space */
  51         uint64_t                mc_deferred;    /* total deferred frees */
  52         uint64_t                mc_space;       /* total space (alloc + free) */
  53         uint64_t                mc_dspace;      /* total deflated space */
  54 };
  55 
  56 struct metaslab_group {
  57         kmutex_t                mg_lock;
  58         avl_tree_t              mg_metaslab_tree;
  59         uint64_t                mg_aliquot;

  60         uint64_t                mg_alloc_failures;
  61         boolean_t               mg_allocatable;         /* can we allocate? */
  62         uint64_t                mg_free_capacity;       /* percentage free */
  63         int64_t                 mg_bias;
  64         int64_t                 mg_activation_count;
  65         metaslab_class_t        *mg_class;
  66         vdev_t                  *mg_vd;
  67         taskq_t                 *mg_taskq;
  68         metaslab_group_t        *mg_prev;
  69         metaslab_group_t        *mg_next;
  70 };
  71 
  72 /*
  73  * This value defines the number of elements in the ms_lbas array. The value
  74  * of 64 was chosen as it covers to cover all power of 2 buckets up to
  75  * UINT64_MAX. This is the equivalent of highbit(UINT64_MAX).
  76  */
  77 #define MAX_LBAS        64
  78 
  79 /*
  80  * Each metaslab maintains a set of in-core trees to track metaslab operations.
  81  * The in-core free tree (ms_tree) contains the current list of free segments.
  82  * As blocks are allocated, the allocated segment are removed from the ms_tree
  83  * and added to a per txg allocation tree (ms_alloctree). As blocks are freed,
  84  * they are added to the per txg free tree (ms_freetree). These per txg
  85  * trees allow us to process all allocations and frees in syncing context
  86  * where it is safe to update the on-disk space maps. One additional in-core
  87  * tree is maintained to track deferred frees (ms_defertree). Once a block
  88  * is freed it will move from the ms_freetree to the ms_defertree. A deferred
  89  * free means that a block has been freed but cannot be used by the pool
  90  * until TXG_DEFER_SIZE transactions groups later. For example, a block
  91  * that is freed in txg 50 will not be available for reallocation until
  92  * txg 52 (50 + TXG_DEFER_SIZE).  This provides a safety net for uberblock
  93  * rollback. A pool could be safely rolled back TXG_DEFERS_SIZE
  94  * transactions groups and ensure that no block has been reallocated.
  95  *
  96  * The simplified transition diagram looks like this:
  97  *
  98  *
  99  *      ALLOCATE
 100  *         |
 101  *         V
 102  *    free segment (ms_tree) --------> ms_alloctree ----> (write to space map)
 103  *         ^
 104  *         |
 105  *         |                           ms_freetree <--- FREE
 106  *         |                                 |
 107  *         |                                 |
 108  *         |                                 |
 109  *         +----------- ms_defertree <-------+---------> (write to space map)
 110  *
 111  *
 112  * Each metaslab's space is tracked in a single space map in the MOS,
 113  * which is only updated in syncing context. Each time we sync a txg,
 114  * we append the allocs and frees from that txg to the space map.
 115  * The pool space is only updated once all metaslabs have finished syncing.

 116  *
 117  * To load the in-core free tree we read the space map from disk.
 118  * This object contains a series of alloc and free records that are
 119  * combined to make up the list of all free segments in this metaslab. These
 120  * segments are represented in-core by the ms_tree and are stored in an
 121  * AVL tree.
 122  *
 123  * As the space map grows (as a result of the appends) it will
 124  * eventually become space-inefficient. When the metaslab's in-core free tree
 125  * is zfs_condense_pct/100 times the size of the minimal on-disk
 126  * representation, we rewrite it in its minimized form. If a metaslab
 127  * needs to condense then we must set the ms_condensing flag to ensure
 128  * that allocations are not performed on the metaslab that is being written.
 129  */
 130 struct metaslab {
 131         kmutex_t        ms_lock;
 132         kcondvar_t      ms_load_cv;
 133         space_map_t     *ms_sm;
 134         metaslab_ops_t  *ms_ops;
 135         uint64_t        ms_id;
 136         uint64_t        ms_start;
 137         uint64_t        ms_size;
 138 
 139         range_tree_t    *ms_alloctree[TXG_SIZE];
 140         range_tree_t    *ms_freetree[TXG_SIZE];
 141         range_tree_t    *ms_defertree[TXG_DEFER_SIZE];
 142         range_tree_t    *ms_tree;
 143 
 144         boolean_t       ms_condensing;  /* condensing? */
 145         boolean_t       ms_loaded;
 146         boolean_t       ms_loading;
 147 
 148         int64_t         ms_deferspace;  /* sum of ms_defermap[] space   */
 149         uint64_t        ms_weight;      /* weight vs. others in group   */
 150         uint64_t        ms_factor;
 151         uint64_t        ms_access_txg;
 152 
 153         /*
 154          * The metaslab block allocators can optionally use a size-ordered
 155          * range tree and/or an array of LBAs. Not all allocators use
 156          * this functionality. The ms_size_tree should always contain the
 157          * same number of segments as the ms_tree. The only difference
 158          * is that the ms_size_tree is ordered by segment sizes.
 159          */
 160         avl_tree_t      ms_size_tree;
 161         uint64_t        ms_lbas[MAX_LBAS];
 162 
 163         metaslab_group_t *ms_group;     /* metaslab group               */
 164         avl_node_t      ms_group_node;  /* node in metaslab group tree  */
 165         txg_node_t      ms_txg_node;    /* per-txg dirty metaslab links */
 166 };
 167 
 168 #ifdef  __cplusplus
 169 }
 170 #endif
 171 
 172 #endif  /* _SYS_METASLAB_IMPL_H */