Skip to content

Commit 743efcf

Browse files
committed
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>
1 parent 66a0e2d commit 743efcf

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

‎include/linux/ceph/osdmap.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ struct ceph_osdmap {
173173
* the list of osds that store+replicate them. */
174174
struct crush_map *crush;
175175

176-
struct mutex crush_scratch_mutex;
177-
int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
176+
struct mutex crush_workspace_mutex;
178177
void *crush_workspace;
179178
};
180179

‎include/linux/crush/mapper.h‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ extern int crush_do_rule(const struct crush_map *map,
1515
int ruleno,
1616
int x, int *result, int result_max,
1717
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+
*/
26+
static 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+
}
1931

2032
void crush_init_workspace(const struct crush_map *map, void *v);
2133

‎net/ceph/crush/mapper.c‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -855,23 +855,22 @@ void crush_init_workspace(const struct crush_map *map, void *v)
855855
* @result_max: maximum result size
856856
* @weight: weight vector (for map leaves)
857857
* @weight_max: size of weight vector
858-
* @cwin: pointer to at least map->working_size bytes of memory
859-
* @scratch: scratch vector for private use; must be >= 3 * result_max
858+
* @cwin: pointer to at least crush_work_size() bytes of memory
860859
*/
861860
int crush_do_rule(const struct crush_map *map,
862861
int ruleno, int x, int *result, int result_max,
863862
const __u32 *weight, int weight_max,
864-
void *cwin, int *scratch)
863+
void *cwin)
865864
{
866865
int result_len;
867866
struct crush_work *cw = cwin;
868-
int *a = scratch;
869-
int *b = scratch + result_max;
870-
int *c = scratch + result_max*2;
867+
int *a = cwin + map->working_size;
868+
int *b = a + result_max;
869+
int *c = b + result_max;
870+
int *w = a;
871+
int *o = b;
871872
int recurse_to_leaf;
872-
int *w;
873873
int wsize = 0;
874-
int *o;
875874
int osize;
876875
int *tmp;
877876
const struct crush_rule *rule;
@@ -902,8 +901,6 @@ int crush_do_rule(const struct crush_map *map,
902901

903902
rule = map->rules[ruleno];
904903
result_len = 0;
905-
w = a;
906-
o = b;
907904

908905
for (step = 0; step < rule->len; step++) {
909906
int firstn = 0;

‎net/ceph/osdmap.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ struct ceph_osdmap *ceph_osdmap_alloc(void)
743743
map->pool_max = -1;
744744
map->pg_temp = RB_ROOT;
745745
map->primary_temp = RB_ROOT;
746-
mutex_init(&map->crush_scratch_mutex);
746+
mutex_init(&map->crush_workspace_mutex);
747747

748748
return map;
749749
}
@@ -836,11 +836,14 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
836836
static int osdmap_set_crush(struct ceph_osdmap *map, struct crush_map *crush)
837837
{
838838
void *workspace;
839+
size_t work_size;
839840

840841
if (IS_ERR(crush))
841842
return PTR_ERR(crush);
842843

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);
844847
if (!workspace) {
845848
crush_destroy(crush);
846849
return -ENOMEM;
@@ -1974,11 +1977,10 @@ static int do_crush(struct ceph_osdmap *map, int ruleno, int x,
19741977

19751978
BUG_ON(result_max > CEPH_PG_MAX_SIZE);
19761979

1977-
mutex_lock(&map->crush_scratch_mutex);
1980+
mutex_lock(&map->crush_workspace_mutex);
19781981
r = crush_do_rule(map->crush, ruleno, x, result, result_max,
1979-
weight, weight_max, map->crush_workspace,
1980-
map->crush_scratch_ary);
1981-
mutex_unlock(&map->crush_scratch_mutex);
1982+
weight, weight_max, map->crush_workspace);
1983+
mutex_unlock(&map->crush_workspace_mutex);
19821984

19831985
return r;
19841986
}

0 commit comments

Comments
 (0)