Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/io-wq: add io_worker.acct pointer

This replaces the `IO_WORKER_F_BOUND` flag. All code that checks this
flag is not interested in knowing whether this is a "bound" worker;
all it does with this flag is determine the `io_wq_acct` pointer. At
the cost of an extra pointer field, we can eliminate some fragile
pointer arithmetic. In turn, the `create_index` and `index` fields
are not needed anymore.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Link: https://lore.kernel.org/r/20250128133927.3989681-3-max.kellermann@ionos.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Max Kellermann and committed by
Jens Axboe
3d3bafd3 3c75635f

+8 -15
+8 -15
io_uring/io-wq.c
··· 30 30 IO_WORKER_F_UP = 0, /* up and active */ 31 31 IO_WORKER_F_RUNNING = 1, /* account as running */ 32 32 IO_WORKER_F_FREE = 2, /* worker on free list */ 33 - IO_WORKER_F_BOUND = 3, /* is doing bounded work */ 34 33 }; 35 34 36 35 enum { ··· 45 46 */ 46 47 struct io_worker { 47 48 refcount_t ref; 48 - int create_index; 49 49 unsigned long flags; 50 50 struct hlist_nulls_node nulls_node; 51 51 struct list_head all_list; 52 52 struct task_struct *task; 53 53 struct io_wq *wq; 54 + struct io_wq_acct *acct; 54 55 55 56 struct io_wq_work *cur_work; 56 57 raw_spinlock_t lock; ··· 78 79 struct io_wq_acct { 79 80 unsigned nr_workers; 80 81 unsigned max_workers; 81 - int index; 82 82 atomic_t nr_running; 83 83 raw_spinlock_t lock; 84 84 struct io_wq_work_list work_list; ··· 133 135 bool cancel_all; 134 136 }; 135 137 136 - static bool create_io_worker(struct io_wq *wq, int index); 138 + static bool create_io_worker(struct io_wq *wq, struct io_wq_acct *acct); 137 139 static void io_wq_dec_running(struct io_worker *worker); 138 140 static bool io_acct_cancel_pending_work(struct io_wq *wq, 139 141 struct io_wq_acct *acct, ··· 165 167 166 168 static inline struct io_wq_acct *io_wq_get_acct(struct io_worker *worker) 167 169 { 168 - return io_get_acct(worker->wq, test_bit(IO_WORKER_F_BOUND, &worker->flags)); 170 + return worker->acct; 169 171 } 170 172 171 173 static void io_worker_ref_put(struct io_wq *wq) ··· 321 323 raw_spin_unlock(&wq->lock); 322 324 atomic_inc(&acct->nr_running); 323 325 atomic_inc(&wq->worker_refs); 324 - return create_io_worker(wq, acct->index); 326 + return create_io_worker(wq, acct); 325 327 } 326 328 327 329 static void io_wq_inc_running(struct io_worker *worker) ··· 341 343 342 344 worker = container_of(cb, struct io_worker, create_work); 343 345 wq = worker->wq; 344 - acct = &wq->acct[worker->create_index]; 346 + acct = worker->acct; 345 347 raw_spin_lock(&wq->lock); 346 348 347 349 if (acct->nr_workers < acct->max_workers) { ··· 350 352 } 351 353 raw_spin_unlock(&wq->lock); 352 354 if (do_create) { 353 - create_io_worker(wq, worker->create_index); 355 + create_io_worker(wq, acct); 354 356 } else { 355 357 atomic_dec(&acct->nr_running); 356 358 io_worker_ref_put(wq); ··· 382 384 383 385 atomic_inc(&wq->worker_refs); 384 386 init_task_work(&worker->create_work, func); 385 - worker->create_index = acct->index; 386 387 if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) { 387 388 /* 388 389 * EXIT may have been set after checking it above, check after ··· 818 821 kfree(worker); 819 822 } 820 823 821 - static bool create_io_worker(struct io_wq *wq, int index) 824 + static bool create_io_worker(struct io_wq *wq, struct io_wq_acct *acct) 822 825 { 823 - struct io_wq_acct *acct = &wq->acct[index]; 824 826 struct io_worker *worker; 825 827 struct task_struct *tsk; 826 828 ··· 838 842 839 843 refcount_set(&worker->ref, 1); 840 844 worker->wq = wq; 845 + worker->acct = acct; 841 846 raw_spin_lock_init(&worker->lock); 842 847 init_completion(&worker->ref_done); 843 - 844 - if (index == IO_WQ_ACCT_BOUND) 845 - set_bit(IO_WORKER_F_BOUND, &worker->flags); 846 848 847 849 tsk = create_io_thread(io_wq_worker, worker, NUMA_NO_NODE); 848 850 if (!IS_ERR(tsk)) { ··· 1170 1176 for (i = 0; i < IO_WQ_ACCT_NR; i++) { 1171 1177 struct io_wq_acct *acct = &wq->acct[i]; 1172 1178 1173 - acct->index = i; 1174 1179 atomic_set(&acct->nr_running, 0); 1175 1180 INIT_WQ_LIST(&acct->work_list); 1176 1181 raw_spin_lock_init(&acct->lock);