Skip to content

Commit c7f405d

Browse files
isilenceaxboe
authored andcommitted
io-wq: embed wqe ptr array into struct io_wq
io-wq keeps an array of pointers to struct io_wqe, allocate this array as a part of struct io-wq, it's easier to code and saves an extra indirection for nearly each io-wq call. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/1482c6a001923bbed662dc38a8a580fb08b1ed8c.1623634181.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 976517f commit c7f405d

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

fs/io-wq.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ struct io_wqe {
102102
* Per io_wq state
103103
*/
104104
struct io_wq {
105-
struct io_wqe **wqes;
106105
unsigned long state;
107106

108107
free_work_fn *free_work;
@@ -118,6 +117,8 @@ struct io_wq {
118117
struct hlist_node cpuhp_node;
119118

120119
struct task_struct *task;
120+
121+
struct io_wqe *wqes[];
121122
};
122123

123124
static enum cpuhp_state io_wq_online;
@@ -907,17 +908,12 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
907908
if (WARN_ON_ONCE(!data->free_work || !data->do_work))
908909
return ERR_PTR(-EINVAL);
909910

910-
wq = kzalloc(sizeof(*wq), GFP_KERNEL);
911+
wq = kzalloc(struct_size(wq, wqes, nr_node_ids), GFP_KERNEL);
911912
if (!wq)
912913
return ERR_PTR(-ENOMEM);
913-
914-
wq->wqes = kcalloc(nr_node_ids, sizeof(struct io_wqe *), GFP_KERNEL);
915-
if (!wq->wqes)
916-
goto err_wq;
917-
918914
ret = cpuhp_state_add_instance_nocalls(io_wq_online, &wq->cpuhp_node);
919915
if (ret)
920-
goto err_wqes;
916+
goto err_wq;
921917

922918
refcount_inc(&data->hash->refs);
923919
wq->hash = data->hash;
@@ -962,8 +958,6 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
962958
cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
963959
for_each_node(node)
964960
kfree(wq->wqes[node]);
965-
err_wqes:
966-
kfree(wq->wqes);
967961
err_wq:
968962
kfree(wq);
969963
return ERR_PTR(ret);
@@ -1036,7 +1030,6 @@ static void io_wq_destroy(struct io_wq *wq)
10361030
kfree(wqe);
10371031
}
10381032
io_wq_put_hash(wq->hash);
1039-
kfree(wq->wqes);
10401033
kfree(wq);
10411034
}
10421035

0 commit comments

Comments
 (0)