From: Adam C. Emerson Date: Thu, 15 Sep 2016 15:33:30 +0000 (-0400) Subject: crush: Merge working data and scratch X-Git-Tag: v11.1.0~328^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=95c2df6c7e0b22d2ea9d91db500cf8b9441c73ba;p=ceph.git crush: Merge working data and scratch Much like Arlo Guthrie, I decided that one big pile is better than two little piles. Signed-off-by: Adam C. Emerson --- diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 36013321aa25..059872c6cbb3 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -1090,11 +1090,10 @@ public: const vector<__u32>& weight) const { Mutex::Locker l(mapper_lock); int rawout[maxout]; - int scratch[maxout * 3]; - char work[crush->working_size]; + char work[crush_work_size(crush, maxout)]; crush_init_workspace(crush, work); int numrep = crush_do_rule(crush, rule, x, rawout, maxout, &weight[0], - weight.size(), work, scratch); + weight.size(), work); if (numrep < 0) numrep = 0; out.resize(numrep); diff --git a/src/crush/mapper.c b/src/crush/mapper.c index 4d37e0e9829f..d2417e52a37a 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -23,6 +23,7 @@ # include "hash.h" #endif #include "crush_ln_table.h" +#include "mapper.h" #define dprintk(args...) /* printf(args) */ @@ -851,22 +852,21 @@ void crush_init_workspace(const struct crush_map *m, void *v) { * @weight: weight vector (for map leaves) * @weight_max: size of weight vector * @cwin: Pointer to at least map->working_size bytes of memory or NULL. - * @scratch: scratch vector for private use; must be >= 3 * result_max */ int crush_do_rule(const struct crush_map *map, int ruleno, int x, int *result, int result_max, const __u32 *weight, int weight_max, - void *cwin, int *scratch) + void *cwin) { int result_len; struct crush_work *cw = cwin; - int *a = scratch; - int *b = scratch + result_max; - int *c = scratch + result_max*2; + int *a = (int *)((char *)cw + map->working_size); + int *b = a + result_max; + int *c = b + result_max; + int *w = a; + int *o = b; int recurse_to_leaf; - int *w; int wsize = 0; - int *o; int osize; int *tmp; const struct crush_rule *rule; @@ -897,9 +897,6 @@ int crush_do_rule(const struct crush_map *map, rule = map->rules[ruleno]; result_len = 0; - w = a; - o = b; - for (step = 0; step < rule->len; step++) { int firstn = 0; diff --git a/src/crush/mapper.h b/src/crush/mapper.h index 0b0f05e0cdc6..b9a614d1476d 100644 --- a/src/crush/mapper.h +++ b/src/crush/mapper.h @@ -15,7 +15,17 @@ extern int crush_do_rule(const struct crush_map *map, int ruleno, int x, int *result, int result_max, const __u32 *weights, int weight_max, - void *cwin, int *scratch); + void *cwin); + +/* Returns the exact amount of workspace that will need to be used + for a given combination of crush_map and result_max. The caller can + then allocate this much on its own, either on the stack, in a + per-thread long-lived buffer, or however it likes. */ + +static inline size_t crush_work_size(const struct crush_map *map, + int result_max) { + return map->working_size + result_max * 3 * sizeof(__u32); +} extern void crush_init_workspace(const struct crush_map *m, void *v);