]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: Merge working data and scratch
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 15 Sep 2016 15:33:30 +0000 (11:33 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 9 Nov 2016 18:54:37 +0000 (13:54 -0500)
Much like Arlo Guthrie, I decided that one big pile is better than two
little piles.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/crush/CrushWrapper.h
src/crush/mapper.c
src/crush/mapper.h

index 36013321aa25252a94c6c435daf4705633524c91..059872c6cbb3c196cb7b05344774e4123264eb09 100644 (file)
@@ -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);
index 4d37e0e9829f6528ec4d3296d397a49a867be225..d2417e52a37a871c390774a08e458122baba31b1 100644 (file)
@@ -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;
index 0b0f05e0cdc6ca06482b92d98dc2cadc7978f9c0..b9a614d1476d81fe822aced2cdf9a723bebcf843 100644 (file)
@@ -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);