]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring/wq: avoid indirect do_work/free_work calls
authorCaleb Sander Mateos <csander@purestorage.com>
Sat, 29 Mar 2025 16:15:24 +0000 (10:15 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 21 Apr 2025 11:06:58 +0000 (05:06 -0600)
struct io_wq stores do_work and free_work function pointers which are
called on each work item. But these function pointers are always set to
io_wq_submit_work and io_wq_free_work, respectively. So remove these
function pointers and just call the functions directly.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Link: https://lore.kernel.org/r/20250329161527.3281314-1-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io-wq.c
io_uring/io-wq.h
io_uring/io_uring.c
io_uring/tctx.c

index 04a75d66619510211ed36711327a513835224fd9..d52069b1177b0a6bae86ef9e09befb3fb70154ce 100644 (file)
@@ -114,9 +114,6 @@ enum {
 struct io_wq {
        unsigned long state;
 
-       free_work_fn *free_work;
-       io_wq_work_fn *do_work;
-
        struct io_wq_hash *hash;
 
        atomic_t worker_refs;
@@ -612,10 +609,10 @@ static void io_worker_handle_work(struct io_wq_acct *acct,
                        if (do_kill &&
                            (work_flags & IO_WQ_WORK_UNBOUND))
                                atomic_or(IO_WQ_WORK_CANCEL, &work->flags);
-                       wq->do_work(work);
+                       io_wq_submit_work(work);
                        io_assign_current_work(worker, NULL);
 
-                       linked = wq->free_work(work);
+                       linked = io_wq_free_work(work);
                        work = next_hashed;
                        if (!work && linked && !io_wq_is_hashed(linked)) {
                                work = linked;
@@ -934,8 +931,8 @@ static void io_run_cancel(struct io_wq_work *work, struct io_wq *wq)
 {
        do {
                atomic_or(IO_WQ_WORK_CANCEL, &work->flags);
-               wq->do_work(work);
-               work = wq->free_work(work);
+               io_wq_submit_work(work);
+               work = io_wq_free_work(work);
        } while (work);
 }
 
@@ -1195,8 +1192,6 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
        int ret, i;
        struct io_wq *wq;
 
-       if (WARN_ON_ONCE(!data->free_work || !data->do_work))
-               return ERR_PTR(-EINVAL);
        if (WARN_ON_ONCE(!bounded))
                return ERR_PTR(-EINVAL);
 
@@ -1206,8 +1201,6 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
 
        refcount_inc(&data->hash->refs);
        wq->hash = data->hash;
-       wq->free_work = data->free_work;
-       wq->do_work = data->do_work;
 
        ret = -ENOMEM;
 
index d4fb2940e435f7e5308707f25c8d191360af5b7d..774abab54732efabc1871e7baeed59c04e4dd280 100644 (file)
@@ -21,9 +21,6 @@ enum io_wq_cancel {
        IO_WQ_CANCEL_NOTFOUND,  /* work not found */
 };
 
-typedef struct io_wq_work *(free_work_fn)(struct io_wq_work *);
-typedef void (io_wq_work_fn)(struct io_wq_work *);
-
 struct io_wq_hash {
        refcount_t refs;
        unsigned long map;
@@ -39,8 +36,6 @@ static inline void io_wq_put_hash(struct io_wq_hash *hash)
 struct io_wq_data {
        struct io_wq_hash *hash;
        struct task_struct *task;
-       io_wq_work_fn *do_work;
-       free_work_fn *free_work;
 };
 
 struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
index c6209fe44cb175c02687d6b734542c4aacf74d16..61514b14ee3f4214868d506d02d221a89f856142 100644 (file)
@@ -1812,7 +1812,7 @@ void io_wq_submit_work(struct io_wq_work *work)
        bool needs_poll = false;
        int ret = 0, err = -ECANCELED;
 
-       /* one will be dropped by ->io_wq_free_work() after returning to io-wq */
+       /* one will be dropped by io_wq_free_work() after returning to io-wq */
        if (!(req->flags & REQ_F_REFCOUNT))
                __io_req_set_refcount(req, 2);
        else
index adc6e42c14df6c0152b6f97ee908e7797f489b95..5b66755579c08fac74b77b3f76e51bdd6f5abf35 100644 (file)
@@ -35,8 +35,6 @@ static struct io_wq *io_init_wq_offload(struct io_ring_ctx *ctx,
 
        data.hash = hash;
        data.task = task;
-       data.free_work = io_wq_free_work;
-       data.do_work = io_wq_submit_work;
 
        /* Do QD, or 4 * CPUS, whatever is smallest */
        concurrency = min(ctx->sq_entries, 4 * num_online_cpus());