# The balancer: upmap and crush-compat

*HTML: https://book.ceph-s3.ir/en/lab-balancer.html*
*Licence: CC BY-NC-SA 4.0. Author: Ramin Najarbashi.*

[Interactive lab](lab.html)The balancer: upmap and crush-compat
In the book: [Chapter 19](19-operations-maintenance.html#sec-19-6-2), [Chapter 28](28-low-crush-bits.html#sec-28-9)
LabThe balancer: upmap and crush-compatCRUSH places the PGs, and some OSDs always end up with more than their share. Run a balancer round and see how upmap, with a few pg-upmap-items, or crush-compat, by changing the weight-set, reduces the deviation.**20.2 → 13.2**max deviation (PGs), start → now**26–48**fewest to most PGs on one OSD**20**pg_upmap_items entries**10 / 20**PGs moved: this round / allEach bar is one OSD and the dashed line its target. Red: overfull, yellow: underfull (relative to upmap_max_deviation).Commands of round 2`ceph osd pg-upmap-items 1.20 6 11
ceph osd pg-upmap-items 1.2f 0 1
ceph osd pg-upmap-items 1.37 4 11
ceph osd pg-upmap-items 1.40 4 11
ceph osd pg-upmap-items 1.4b 4 11
ceph osd pg-upmap-items 1.4d 7 11
ceph osd pg-upmap-items 1.69 0 2
ceph osd pg-upmap-items 1.6d 0 2
ceph osd pg-upmap-items 1.74 7 9
ceph osd pg-upmap-items 1.7d 7 9`Turning the balancer on`ceph osd set-require-min-compat-client luminous
ceph balancer mode upmap
ceph config set mgr mgr/balancer/upmap_max_deviation 5
ceph balancer on
ceph balancer eval`targeti = wi × size × pg_num / Σw · deviationi = PGsi − targeti · overfull: deviation > max_deviation · underfull: deviation < −max_deviationupmap does not change CRUSH; it adds exceptions for single PGs, so it is precise and moves little data, but clients must be at least luminous. With a low pg_num even a perfect balance leaves a large relative deviation; fix pg_num first (chapter 7).Follows:`src/osd/OSDMap.cc :: OSDMap::calc_pg_upmaps, calc_deviations, fill_overfull_underfull, try_drop_remap_overfull, try_drop_remap_underfull, try_pg_upmap, find_best_remap, _apply_upmap` The upmap calculation: overfull and underfull, dropping earlier upmaps, one pair per step`src/crush/CrushWrapper.cc :: try_remap_rule, _choose_type_stack, get_rule_weight_osd_map` Finding a replacement OSD in the same failure domain`src/pybind/mgr/balancer/module.py :: do_upmap, do_crush_compat, calc_eval, calc_stats; upmap_max_deviation (5), upmap_max_optimizations (10)` The mgr balancer module and its defaults`src/common/options/global.yaml.in :: osd_calc_pg_upmaps_aggressively (true), osd_calc_pg_upmaps_local_fallback_retries (100), target_max_misplaced_ratio (0.05)` The calc_pg_upmaps options and the misplaced limitA fixed snapshot of the simulator; the interactive version is in the web edition's lab. [Interactive lab: The balancer: upmap and crush-compat](lab-balancer.html)The interactive version needs JavaScript; this is a fixed snapshot.
