Skip to content

Commit 546f04e

Browse files
author
Sage Weil
committed
libceph: support crush tunables
The server side recently added support for tuning some magic crush variables. Decode these variables if they are present, or use the default values if they are not present. Corresponds to ceph.git commit 89af369c25f274fe62ef730e5e8aad0c54f1e5a5. Signed-off-by: caleb miles <caleb.miles@inktank.com> Reviewed-by: Sage Weil <sage@inktank.com> Reviewed-by: Alex Elder <elder@inktank.com> Reviewed-by: Yehuda Sadeh <yehuda@inktank.com>
1 parent 1fe60e5 commit 546f04e

4 files changed

Lines changed: 58 additions & 7 deletions

File tree

‎include/linux/ceph/ceph_features.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#define CEPH_FEATURE_MONNAMES (1<<5)
1313
#define CEPH_FEATURE_RECONNECT_SEQ (1<<6)
1414
#define CEPH_FEATURE_DIRLAYOUTHASH (1<<7)
15+
/* bits 8-17 defined by user-space; not supported yet here */
16+
#define CEPH_FEATURE_CRUSH_TUNABLES (1<<18)
1517

1618
/*
1719
* Features supported.
1820
*/
1921
#define CEPH_FEATURES_SUPPORTED_DEFAULT \
20-
(CEPH_FEATURE_NOSRCADDR)
22+
(CEPH_FEATURE_NOSRCADDR | \
23+
CEPH_FEATURE_CRUSH_TUNABLES)
2124

2225
#define CEPH_FEATURES_REQUIRED_DEFAULT \
2326
(CEPH_FEATURE_NOSRCADDR)

‎include/linux/crush/crush.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ struct crush_map {
154154
__s32 max_buckets;
155155
__u32 max_rules;
156156
__s32 max_devices;
157+
158+
/* choose local retries before re-descent */
159+
__u32 choose_local_tries;
160+
/* choose local attempts using a fallback permutation before
161+
* re-descent */
162+
__u32 choose_local_fallback_tries;
163+
/* choose attempts before giving up */
164+
__u32 choose_total_tries;
157165
};
158166

159167

‎net/ceph/crush/mapper.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ static int crush_choose(const struct crush_map *map,
306306
int item = 0;
307307
int itemtype;
308308
int collide, reject;
309-
const unsigned int orig_tries = 5; /* attempts before we fall back to search */
310309

311310
dprintk("CHOOSE%s bucket %d x %d outpos %d numrep %d\n", recurse_to_leaf ? "_LEAF" : "",
312311
bucket->id, x, outpos, numrep);
@@ -351,8 +350,9 @@ static int crush_choose(const struct crush_map *map,
351350
reject = 1;
352351
goto reject;
353352
}
354-
if (flocal >= (in->size>>1) &&
355-
flocal > orig_tries)
353+
if (map->choose_local_fallback_tries > 0 &&
354+
flocal >= (in->size>>1) &&
355+
flocal > map->choose_local_fallback_tries)
356356
item = bucket_perm_choose(in, x, r);
357357
else
358358
item = crush_bucket_choose(in, x, r);
@@ -422,13 +422,14 @@ static int crush_choose(const struct crush_map *map,
422422
ftotal++;
423423
flocal++;
424424

425-
if (collide && flocal < 3)
425+
if (collide && flocal <= map->choose_local_tries)
426426
/* retry locally a few times */
427427
retry_bucket = 1;
428-
else if (flocal <= in->size + orig_tries)
428+
else if (map->choose_local_fallback_tries > 0 &&
429+
flocal <= in->size + map->choose_local_fallback_tries)
429430
/* exhaustive bucket search */
430431
retry_bucket = 1;
431-
else if (ftotal < 20)
432+
else if (ftotal <= map->choose_total_tries)
432433
/* then retry descent */
433434
retry_descent = 1;
434435
else

‎net/ceph/osdmap.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ static int crush_decode_straw_bucket(void **p, void *end,
135135
return -EINVAL;
136136
}
137137

138+
static int skip_name_map(void **p, void *end)
139+
{
140+
int len;
141+
ceph_decode_32_safe(p, end, len ,bad);
142+
while (len--) {
143+
int strlen;
144+
*p += sizeof(u32);
145+
ceph_decode_32_safe(p, end, strlen, bad);
146+
*p += strlen;
147+
}
148+
return 0;
149+
bad:
150+
return -EINVAL;
151+
}
152+
138153
static struct crush_map *crush_decode(void *pbyval, void *end)
139154
{
140155
struct crush_map *c;
@@ -143,13 +158,19 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
143158
void **p = &pbyval;
144159
void *start = pbyval;
145160
u32 magic;
161+
u32 num_name_maps;
146162

147163
dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p));
148164

149165
c = kzalloc(sizeof(*c), GFP_NOFS);
150166
if (c == NULL)
151167
return ERR_PTR(-ENOMEM);
152168

169+
/* set tunables to default values */
170+
c->choose_local_tries = 2;
171+
c->choose_local_fallback_tries = 5;
172+
c->choose_total_tries = 19;
173+
153174
ceph_decode_need(p, end, 4*sizeof(u32), bad);
154175
magic = ceph_decode_32(p);
155176
if (magic != CRUSH_MAGIC) {
@@ -297,7 +318,25 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
297318
}
298319

299320
/* ignore trailing name maps. */
321+
for (num_name_maps = 0; num_name_maps < 3; num_name_maps++) {
322+
err = skip_name_map(p, end);
323+
if (err < 0)
324+
goto done;
325+
}
326+
327+
/* tunables */
328+
ceph_decode_need(p, end, 3*sizeof(u32), done);
329+
c->choose_local_tries = ceph_decode_32(p);
330+
c->choose_local_fallback_tries = ceph_decode_32(p);
331+
c->choose_total_tries = ceph_decode_32(p);
332+
dout("crush decode tunable choose_local_tries = %d",
333+
c->choose_local_tries);
334+
dout("crush decode tunable choose_local_fallback_tries = %d",
335+
c->choose_local_fallback_tries);
336+
dout("crush decode tunable choose_total_tries = %d",
337+
c->choose_total_tries);
300338

339+
done:
301340
dout("crush_decode success\n");
302341
return c;
303342

0 commit comments

Comments
 (0)