summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2017-01-31 09:55:06 -0500
committerIlya Dryomov <idryomov@gmail.com>2017-02-20 06:16:11 -0500
commit743efcffffc6620ab44ea9ec67c7e4e28dfa7742 (patch)
treea087b21bd95308161d8b14269452efd1e798949d
parent66a0e2d579dbec5c676cfe446234ffebb267c564 (diff)
crush: merge working data and scratch
Much like Arlo Guthrie, I decided that one big pile is better than two little piles. Reflects ceph.git commit 95c2df6c7e0b22d2ea9d91db500cf8b9441c73ba. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r--include/linux/ceph/osdmap.h3
-rw-r--r--include/linux/crush/mapper.h14
-rw-r--r--net/ceph/crush/mapper.c17
-rw-r--r--net/ceph/osdmap.c14
4 files changed, 29 insertions, 19 deletions
diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
index cef1cab789b9..8cebdc4158c3 100644
--- a/include/linux/ceph/osdmap.h
+++ b/include/linux/ceph/osdmap.h
@@ -173,8 +173,7 @@ struct ceph_osdmap {
173 * the list of osds that store+replicate them. */ 173 * the list of osds that store+replicate them. */
174 struct crush_map *crush; 174 struct crush_map *crush;
175 175
176 struct mutex crush_scratch_mutex; 176 struct mutex crush_workspace_mutex;
177 int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
178 void *crush_workspace; 177 void *crush_workspace;
179}; 178};
180 179
diff --git a/include/linux/crush/mapper.h b/include/linux/crush/mapper.h
index 3303c7fd8a31..c95e19e1ff11 100644
--- a/include/linux/crush/mapper.h
+++ b/include/linux/crush/mapper.h
@@ -15,7 +15,19 @@ extern int crush_do_rule(const struct crush_map *map,
15 int ruleno, 15 int ruleno,
16 int x, int *result, int result_max, 16 int x, int *result, int result_max,
17 const __u32 *weights, int weight_max, 17 const __u32 *weights, int weight_max,
18 void *cwin, int *scratch); 18 void *cwin);
19
20/*
21 * Returns the exact amount of workspace that will need to be used
22 * for a given combination of crush_map and result_max. The caller can
23 * then allocate this much on its own, either on the stack, in a
24 * per-thread long-lived buffer, or however it likes.
25 */
26static inline size_t crush_work_size(const struct crush_map *map,
27 int result_max)
28{
29 return map->working_size + result_max * 3 * sizeof(__u32);
30}
19 31
20void crush_init_workspace(const struct crush_map *map, void *v); 32void crush_init_workspace(const struct crush_map *map, void *v);
21 33
diff --git a/net/ceph/crush/mapper.c b/net/ceph/crush/mapper.c
index 9e75be5ec716..2e31217ccae3 100644
--- a/net/ceph/crush/mapper.c
+++ b/net/ceph/crush/mapper.c
@@ -855,23 +855,22 @@ void crush_init_workspace(const struct crush_map *map, void *v)
855 * @result_max: maximum result size 855 * @result_max: maximum result size
856 * @weight: weight vector (for map leaves) 856 * @weight: weight vector (for map leaves)
857 * @weight_max: size of weight vector 857 * @weight_max: size of weight vector
858 * @cwin: pointer to at least map->working_size bytes of memory 858 * @cwin: pointer to at least crush_work_size() bytes of memory
859 * @scratch: scratch vector for private use; must be >= 3 * result_max
860 */ 859 */
861int crush_do_rule(const struct crush_map *map, 860int crush_do_rule(const struct crush_map *map,
862 int ruleno, int x, int *result, int result_max, 861 int ruleno, int x, int *result, int result_max,
863 const __u32 *weight, int weight_max, 862 const __u32 *weight, int weight_max,
864 void *cwin, int *scratch) 863 void *cwin)
865{ 864{
866 int result_len; 865 int result_len;
867 struct crush_work *cw = cwin; 866 struct crush_work *cw = cwin;
868 int *a = scratch; 867 int *a = cwin + map->working_size;
869 int *b = scratch + result_max; 868 int *b = a + result_max;
870 int *c = scratch + result_max*2; 869 int *c = b + result_max;
870 int *w = a;
871 int *o = b;
871 int recurse_to_leaf; 872 int recurse_to_leaf;
872 int *w;
873 int wsize = 0; 873 int wsize = 0;
874 int *o;
875 int osize; 874 int osize;
876 int *tmp; 875 int *tmp;
877 const struct crush_rule *rule; 876 const struct crush_rule *rule;
@@ -902,8 +901,6 @@ int crush_do_rule(const struct crush_map *map,
902 901
903 rule = map->rules[ruleno]; 902 rule = map->rules[ruleno];
904 result_len = 0; 903 result_len = 0;
905 w = a;
906 o = b;
907 904
908 for (step = 0; step < rule->len; step++) { 905 for (step = 0; step < rule->len; step++) {
909 int firstn = 0; 906 int firstn = 0;
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 3892e7fa7747..2374956c4d40 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -743,7 +743,7 @@ struct ceph_osdmap *ceph_osdmap_alloc(void)
743 map->pool_max = -1; 743 map->pool_max = -1;
744 map->pg_temp = RB_ROOT; 744 map->pg_temp = RB_ROOT;
745 map->primary_temp = RB_ROOT; 745 map->primary_temp = RB_ROOT;
746 mutex_init(&map->crush_scratch_mutex); 746 mutex_init(&map->crush_workspace_mutex);
747 747
748 return map; 748 return map;
749} 749}
@@ -836,11 +836,14 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
836static int osdmap_set_crush(struct ceph_osdmap *map, struct crush_map *crush) 836static int osdmap_set_crush(struct ceph_osdmap *map, struct crush_map *crush)
837{ 837{
838 void *workspace; 838 void *workspace;
839 size_t work_size;
839 840
840 if (IS_ERR(crush)) 841 if (IS_ERR(crush))
841 return PTR_ERR(crush); 842 return PTR_ERR(crush);
842 843
843 workspace = kmalloc(crush->working_size, GFP_NOIO); 844 work_size = crush_work_size(crush, CEPH_PG_MAX_SIZE);
845 dout("%s work_size %zu bytes\n", __func__, work_size);
846 workspace = kmalloc(work_size, GFP_NOIO);
844 if (!workspace) { 847 if (!workspace) {
845 crush_destroy(crush); 848 crush_destroy(crush);
846 return -ENOMEM; 849 return -ENOMEM;
@@ -1974,11 +1977,10 @@ static int do_crush(struct ceph_osdmap *map, int ruleno, int x,
1974 1977
1975 BUG_ON(result_max > CEPH_PG_MAX_SIZE); 1978 BUG_ON(result_max > CEPH_PG_MAX_SIZE);
1976 1979
1977 mutex_lock(&map->crush_scratch_mutex); 1980 mutex_lock(&map->crush_workspace_mutex);
1978 r = crush_do_rule(map->crush, ruleno, x, result, result_max, 1981 r = crush_do_rule(map->crush, ruleno, x, result, result_max,
1979 weight, weight_max, map->crush_workspace, 1982 weight, weight_max, map->crush_workspace);
1980 map->crush_scratch_ary); 1983 mutex_unlock(&map->crush_workspace_mutex);
1981 mutex_unlock(&map->crush_scratch_mutex);
1982 1984
1983 return r; 1985 return r;
1984} 1986}