Skip to content

Commit 66a0e2d

Browse files
committed
crush: remove mutable part of CRUSH map
Then add it to the working state. It would be very nice if we didn't have to take a lock to calculate a crush placement. By moving the permutation array into the working data, we can treat the CRUSH map as immutable. Reflects ceph.git commit cbcd039651c0569551cb90d26ce27e1432671f2a. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 1b6a78b commit 66a0e2d

6 files changed

Lines changed: 218 additions & 86 deletions

File tree

‎include/linux/ceph/osdmap.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ struct ceph_osdmap {
175175

176176
struct mutex crush_scratch_mutex;
177177
int crush_scratch_ary[CEPH_PG_MAX_SIZE * 3];
178+
void *crush_workspace;
178179
};
179180

180181
static inline bool ceph_osd_exists(struct ceph_osdmap *map, int osd)

‎include/linux/crush/crush.h‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ struct crush_bucket {
135135
__u32 size; /* num items */
136136
__s32 *items;
137137

138-
/*
139-
* cached random permutation: used for uniform bucket and for
140-
* the linear search fallback for the other bucket types.
141-
*/
142-
__u32 perm_x; /* @x for which *perm is defined */
143-
__u32 perm_n; /* num elements of *perm that are permuted/defined */
144-
__u32 *perm;
145138
};
146139

147140
struct crush_bucket_uniform {
@@ -211,6 +204,21 @@ struct crush_map {
211204
* device fails. */
212205
__u8 chooseleaf_stable;
213206

207+
/*
208+
* This value is calculated after decode or construction by
209+
* the builder. It is exposed here (rather than having a
210+
* 'build CRUSH working space' function) so that callers can
211+
* reserve a static buffer, allocate space on the stack, or
212+
* otherwise avoid calling into the heap allocator if they
213+
* want to. The size of the working space depends on the map,
214+
* while the size of the scratch vector passed to the mapper
215+
* depends on the size of the desired result set.
216+
*
217+
* Nothing stops the caller from allocating both in one swell
218+
* foop and passing in two points, though.
219+
*/
220+
size_t working_size;
221+
214222
#ifndef __KERNEL__
215223
/*
216224
* version 0 (original) of straw_calc has various flaws. version 1
@@ -248,4 +256,23 @@ static inline int crush_calc_tree_node(int i)
248256
return ((i+1) << 1)-1;
249257
}
250258

259+
/*
260+
* These data structures are private to the CRUSH implementation. They
261+
* are exposed in this header file because builder needs their
262+
* definitions to calculate the total working size.
263+
*
264+
* Moving this out of the crush map allow us to treat the CRUSH map as
265+
* immutable within the mapper and removes the requirement for a CRUSH
266+
* map lock.
267+
*/
268+
struct crush_work_bucket {
269+
__u32 perm_x; /* @x for which *perm is defined */
270+
__u32 perm_n; /* num elements of *perm that are permuted/defined */
271+
__u32 *perm; /* Permutation of the bucket's items */
272+
};
273+
274+
struct crush_work {
275+
struct crush_work_bucket **work; /* Per-bucket working store */
276+
};
277+
251278
#endif

‎include/linux/crush/mapper.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ 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-
int *scratch);
18+
void *cwin, int *scratch);
19+
20+
void crush_init_workspace(const struct crush_map *map, void *v);
1921

2022
#endif

‎net/ceph/crush/crush.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ int crush_get_bucket_item_weight(const struct crush_bucket *b, int p)
4545

4646
void crush_destroy_bucket_uniform(struct crush_bucket_uniform *b)
4747
{
48-
kfree(b->h.perm);
4948
kfree(b->h.items);
5049
kfree(b);
5150
}
@@ -54,14 +53,12 @@ void crush_destroy_bucket_list(struct crush_bucket_list *b)
5453
{
5554
kfree(b->item_weights);
5655
kfree(b->sum_weights);
57-
kfree(b->h.perm);
5856
kfree(b->h.items);
5957
kfree(b);
6058
}
6159

6260
void crush_destroy_bucket_tree(struct crush_bucket_tree *b)
6361
{
64-
kfree(b->h.perm);
6562
kfree(b->h.items);
6663
kfree(b->node_weights);
6764
kfree(b);
@@ -71,15 +68,13 @@ void crush_destroy_bucket_straw(struct crush_bucket_straw *b)
7168
{
7269
kfree(b->straws);
7370
kfree(b->item_weights);
74-
kfree(b->h.perm);
7571
kfree(b->h.items);
7672
kfree(b);
7773
}
7874

7975
void crush_destroy_bucket_straw2(struct crush_bucket_straw2 *b)
8076
{
8177
kfree(b->item_weights);
82-
kfree(b->h.perm);
8378
kfree(b->h.items);
8479
kfree(b);
8580
}

0 commit comments

Comments
 (0)