io-wq: remove unused io-wq refcounting
[linux-2.6-microblaze.git] / fs / io-wq.c
index 5361a9b..f058ea0 100644 (file)
@@ -102,7 +102,6 @@ struct io_wqe {
  * Per io_wq state
   */
 struct io_wq {
-       struct io_wqe **wqes;
        unsigned long state;
 
        free_work_fn *free_work;
@@ -110,14 +109,14 @@ struct io_wq {
 
        struct io_wq_hash *hash;
 
-       refcount_t refs;
-
        atomic_t worker_refs;
        struct completion worker_done;
 
        struct hlist_node cpuhp_node;
 
        struct task_struct *task;
+
+       struct io_wqe *wqes[];
 };
 
 static enum cpuhp_state io_wq_online;
@@ -907,17 +906,12 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
        if (WARN_ON_ONCE(!data->free_work || !data->do_work))
                return ERR_PTR(-EINVAL);
 
-       wq = kzalloc(sizeof(*wq), GFP_KERNEL);
+       wq = kzalloc(struct_size(wq, wqes, nr_node_ids), GFP_KERNEL);
        if (!wq)
                return ERR_PTR(-ENOMEM);
-
-       wq->wqes = kcalloc(nr_node_ids, sizeof(struct io_wqe *), GFP_KERNEL);
-       if (!wq->wqes)
-               goto err_wq;
-
        ret = cpuhp_state_add_instance_nocalls(io_wq_online, &wq->cpuhp_node);
        if (ret)
-               goto err_wqes;
+               goto err_wq;
 
        refcount_inc(&data->hash->refs);
        wq->hash = data->hash;
@@ -953,7 +947,6 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
        }
 
        wq->task = get_task_struct(data->task);
-       refcount_set(&wq->refs, 1);
        atomic_set(&wq->worker_refs, 1);
        init_completion(&wq->worker_done);
        return wq;
@@ -962,8 +955,6 @@ err:
        cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
        for_each_node(node)
                kfree(wq->wqes[node]);
-err_wqes:
-       kfree(wq->wqes);
 err_wq:
        kfree(wq);
        return ERR_PTR(ret);
@@ -979,13 +970,16 @@ static bool io_task_work_match(struct callback_head *cb, void *data)
        return cwd->wqe->wq == data;
 }
 
+void io_wq_exit_start(struct io_wq *wq)
+{
+       set_bit(IO_WQ_BIT_EXIT, &wq->state);
+}
+
 static void io_wq_exit_workers(struct io_wq *wq)
 {
        struct callback_head *cb;
        int node;
 
-       set_bit(IO_WQ_BIT_EXIT, &wq->state);
-
        if (!wq->task)
                return;
 
@@ -1003,13 +997,16 @@ static void io_wq_exit_workers(struct io_wq *wq)
                struct io_wqe *wqe = wq->wqes[node];
 
                io_wq_for_each_worker(wqe, io_wq_worker_wake, NULL);
-               spin_lock_irq(&wq->hash->wait.lock);
-               list_del_init(&wq->wqes[node]->wait.entry);
-               spin_unlock_irq(&wq->hash->wait.lock);
        }
        rcu_read_unlock();
        io_worker_ref_put(wq);
        wait_for_completion(&wq->worker_done);
+
+       for_each_node(node) {
+               spin_lock_irq(&wq->hash->wait.lock);
+               list_del_init(&wq->wqes[node]->wait.entry);
+               spin_unlock_irq(&wq->hash->wait.lock);
+       }
        put_task_struct(wq->task);
        wq->task = NULL;
 }
@@ -1020,8 +1017,6 @@ static void io_wq_destroy(struct io_wq *wq)
 
        cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
 
-       io_wq_exit_workers(wq);
-
        for_each_node(node) {
                struct io_wqe *wqe = wq->wqes[node];
                struct io_cb_cancel_data match = {
@@ -1032,20 +1027,15 @@ static void io_wq_destroy(struct io_wq *wq)
                kfree(wqe);
        }
        io_wq_put_hash(wq->hash);
-       kfree(wq->wqes);
        kfree(wq);
 }
 
-void io_wq_put(struct io_wq *wq)
-{
-       if (refcount_dec_and_test(&wq->refs))
-               io_wq_destroy(wq);
-}
-
 void io_wq_put_and_exit(struct io_wq *wq)
 {
+       WARN_ON_ONCE(!test_bit(IO_WQ_BIT_EXIT, &wq->state));
+
        io_wq_exit_workers(wq);
-       io_wq_put(wq);
+       io_wq_destroy(wq);
 }
 
 static bool io_wq_worker_affinity(struct io_worker *worker, void *data)