Skip to content

Commit e2b149c

Browse files
idryomovSage Weil
authored andcommitted
crush: add chooseleaf_vary_r tunable
The current crush_choose_firstn code will re-use the same 'r' value for the recursive call. That means that if we are hitting a collision or rejection for some reason (say, an OSD that is marked out) and need to retry, we will keep making the same (bad) choice in that recursive selection. Introduce a tunable that fixes that behavior by incorporating the parent 'r' value into the recursive starting point, so that a different path will be taken in subsequent placement attempts. Note that this was done from the get-go for the new crush_choose_indep algorithm. This was exposed by a user who was seeing PGs stuck in active+remapped after reweight-by-utilization because the up set mapped to a single OSD. Reflects ceph.git commit a8e6c9fbf88bad056dd05d3eb790e98a5e43451a. Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent 6ed1002 commit e2b149c

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎include/linux/crush/crush.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ struct crush_map {
173173
* apply to a collision: in that case we will retry as we used
174174
* to. */
175175
__u32 chooseleaf_descend_once;
176+
177+
/* if non-zero, feed r into chooseleaf, bit-shifted right by (r-1)
178+
* bits. a value of 1 is best for new clusters. for legacy clusters
179+
* that want to limit reshuffling, a value of 3 or 4 will make the
180+
* mappings line up a bit better with previous mappings. */
181+
__u8 chooseleaf_vary_r;
176182
};
177183

178184

‎net/ceph/crush/mapper.c‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ static int is_out(const struct crush_map *map,
295295
* @local_retries: localized retries
296296
* @local_fallback_retries: localized fallback retries
297297
* @recurse_to_leaf: true if we want one device under each item of given type (chooseleaf instead of choose)
298+
* @vary_r: pass r to recursive calls
298299
* @out2: second output vector for leaf items (if @recurse_to_leaf)
300+
* @parent_r: r value passed from the parent
299301
*/
300302
static int crush_choose_firstn(const struct crush_map *map,
301303
struct crush_bucket *bucket,
@@ -307,7 +309,9 @@ static int crush_choose_firstn(const struct crush_map *map,
307309
unsigned int local_retries,
308310
unsigned int local_fallback_retries,
309311
int recurse_to_leaf,
310-
int *out2)
312+
unsigned int vary_r,
313+
int *out2,
314+
int parent_r)
311315
{
312316
int rep;
313317
unsigned int ftotal, flocal;
@@ -319,8 +323,11 @@ static int crush_choose_firstn(const struct crush_map *map,
319323
int itemtype;
320324
int collide, reject;
321325

322-
dprintk("CHOOSE%s bucket %d x %d outpos %d numrep %d\n", recurse_to_leaf ? "_LEAF" : "",
323-
bucket->id, x, outpos, numrep);
326+
dprintk("CHOOSE%s bucket %d x %d outpos %d numrep %d tries %d recurse_tries %d local_retries %d local_fallback_retries %d parent_r %d\n",
327+
recurse_to_leaf ? "_LEAF" : "",
328+
bucket->id, x, outpos, numrep,
329+
tries, recurse_tries, local_retries, local_fallback_retries,
330+
parent_r);
324331

325332
for (rep = outpos; rep < numrep; rep++) {
326333
/* keep trying until we get a non-out, non-colliding item */
@@ -335,7 +342,7 @@ static int crush_choose_firstn(const struct crush_map *map,
335342
do {
336343
collide = 0;
337344
retry_bucket = 0;
338-
r = rep;
345+
r = rep + parent_r;
339346
/* r' = r + f_total */
340347
r += ftotal;
341348

@@ -387,6 +394,11 @@ static int crush_choose_firstn(const struct crush_map *map,
387394
reject = 0;
388395
if (!collide && recurse_to_leaf) {
389396
if (item < 0) {
397+
int sub_r;
398+
if (vary_r)
399+
sub_r = r >> (vary_r-1);
400+
else
401+
sub_r = 0;
390402
if (crush_choose_firstn(map,
391403
map->buckets[-1-item],
392404
weight, weight_max,
@@ -396,7 +408,9 @@ static int crush_choose_firstn(const struct crush_map *map,
396408
local_retries,
397409
local_fallback_retries,
398410
0,
399-
NULL) <= outpos)
411+
vary_r,
412+
NULL,
413+
sub_r) <= outpos)
400414
/* didn't get leaf */
401415
reject = 1;
402416
} else {
@@ -653,6 +667,8 @@ int crush_do_rule(const struct crush_map *map,
653667
int choose_local_retries = map->choose_local_tries;
654668
int choose_local_fallback_retries = map->choose_local_fallback_tries;
655669

670+
int vary_r = map->chooseleaf_vary_r;
671+
656672
if ((__u32)ruleno >= map->max_rules) {
657673
dprintk(" bad ruleno %d\n", ruleno);
658674
return 0;
@@ -745,7 +761,9 @@ int crush_do_rule(const struct crush_map *map,
745761
choose_local_retries,
746762
choose_local_fallback_retries,
747763
recurse_to_leaf,
748-
c+osize);
764+
vary_r,
765+
c+osize,
766+
0);
749767
} else {
750768
crush_choose_indep(
751769
map,

0 commit comments

Comments
 (0)