4 =======================
6 The *balancer* can optimize the allocation of placement groups (PGs) across
7 OSDs in order to achieve a balanced distribution. The balancer can operate
8 either automatically or in a supervised fashion.
14 To check the current status of the balancer, run the following command:
24 When the balancer is in ``upmap`` mode, the automatic balancing feature is
25 enabled by default. For more details, see :ref:`upmap`. To disable the
26 balancer, run the following command:
32 The balancer mode can be changed from ``upmap`` mode to ``crush-compat`` mode.
33 ``crush-compat`` mode is backward compatible with older clients. In
34 ``crush-compat`` mode, the balancer automatically makes small changes to the
35 data distribution in order to ensure that OSDs are utilized equally.
41 If the cluster is degraded (that is, if an OSD has failed and the system hasn't
42 healed itself yet), then the balancer will not make any adjustments to the PG
45 When the cluster is healthy, the balancer will incrementally move a small
46 fraction of unbalanced PGs in order to improve distribution. This fraction
47 will not exceed a certain threshold that defaults to 5%. To adjust this
48 ``target_max_misplaced_ratio`` threshold setting, run the following command:
52 ceph config set mgr target_max_misplaced_ratio .07 # 7%
54 The balancer sleeps between runs. To set the number of seconds for this
55 interval of sleep, run the following command:
59 ceph config set mgr mgr/balancer/sleep_interval 60
61 To set the time of day (in HHMM format) at which automatic balancing begins,
62 run the following command:
66 ceph config set mgr mgr/balancer/begin_time 0000
68 To set the time of day (in HHMM format) at which automatic balancing ends, run
69 the following command:
73 ceph config set mgr mgr/balancer/end_time 2359
75 Automatic balancing can be restricted to certain days of the week. To restrict
76 it to a specific day of the week or later (as with crontab, ``0`` is Sunday,
77 ``1`` is Monday, and so on), run the following command:
81 ceph config set mgr mgr/balancer/begin_weekday 0
83 To restrict automatic balancing to a specific day of the week or earlier
84 (again, ``0`` is Sunday, ``1`` is Monday, and so on), run the following
89 ceph config set mgr mgr/balancer/end_weekday 6
91 Automatic balancing can be restricted to certain pools. By default, the value
92 of this setting is an empty string, so that all pools are automatically
93 balanced. To restrict automatic balancing to specific pools, retrieve their
94 numeric pool IDs (by running the :command:`ceph osd pool ls detail` command),
95 and then run the following command:
99 ceph config set mgr mgr/balancer/pool_ids 1,2,3
105 There are two supported balancer modes:
107 #. **crush-compat**. This mode uses the compat weight-set feature (introduced
108 in Luminous) to manage an alternative set of weights for devices in the
109 CRUSH hierarchy. When the balancer is operating in this mode, the normal
110 weights should remain set to the size of the device in order to reflect the
111 target amount of data intended to be stored on the device. The balancer will
112 then optimize the weight-set values, adjusting them up or down in small
113 increments, in order to achieve a distribution that matches the target
114 distribution as closely as possible. (Because PG placement is a pseudorandom
115 process, it is subject to a natural amount of variation; optimizing the
116 weights serves to counteract that natural variation.)
118 Note that this mode is *fully backward compatible* with older clients: when
119 an OSD Map and CRUSH map are shared with older clients, Ceph presents the
120 optimized weights as the "real" weights.
122 The primary limitation of this mode is that the balancer cannot handle
123 multiple CRUSH hierarchies with different placement rules if the subtrees of
124 the hierarchy share any OSDs. (Such sharing of OSDs is not typical and,
125 because of the difficulty of managing the space utilization on the shared
126 OSDs, is generally not recommended.)
128 #. **upmap**. In Luminous and later releases, the OSDMap can store explicit
129 mappings for individual OSDs as exceptions to the normal CRUSH placement
130 calculation. These ``upmap`` entries provide fine-grained control over the
131 PG mapping. This balancer mode optimizes the placement of individual PGs in
132 order to achieve a balanced distribution. In most cases, the resulting
133 distribution is nearly perfect: that is, there is an equal number of PGs on
134 each OSD (±1 PG, since the total number might not divide evenly).
136 To use ``upmap``, all clients must be Luminous or newer.
138 The default mode is ``upmap``. The mode can be changed to ``crush-compat`` by
139 running the following command:
143 ceph balancer mode crush-compat
145 Supervised optimization
146 -----------------------
148 Supervised use of the balancer can be understood in terms of three distinct
152 #. evaluating the quality of the data distribution, either for the current PG
153 distribution or for the PG distribution that would result after executing a
155 #. executing the plan
157 To evaluate the current distribution, run the following command:
163 To evaluate the distribution for a single pool, run the following command:
167 ceph balancer eval <pool-name>
169 To see the evaluation in greater detail, run the following command:
173 ceph balancer eval-verbose ...
175 To instruct the balancer to generate a plan (using the currently configured
176 mode), make up a name (any useful identifying string) for the plan, and run the
181 ceph balancer optimize <plan-name>
183 To see the contents of a plan, run the following command:
187 ceph balancer show <plan-name>
189 To display all plans, run the following command:
195 To discard an old plan, run the following command:
199 ceph balancer rm <plan-name>
201 To see currently recorded plans, examine the output of the following status
208 To evaluate the distribution that would result from executing a specific plan,
209 run the following command:
213 ceph balancer eval <plan-name>
215 If a plan is expected to improve the distribution (that is, the plan's score is
216 lower than the current cluster state's score), you can execute that plan by
217 running the following command:
221 ceph balancer execute <plan-name>