Skip to content

Commit efdf518

Browse files
committed
io-wq: perform both unstarted and started work cancelations in one go
Rather than split these into two separate lookups and matches, combine them into one loop. This will become important when we can guarantee that we don't have a window where a pending work item isn't discoverable in either state. Signed-off-by: Jens Axboe <[email protected]>
1 parent 36e4c58 commit efdf518

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

fs/io-wq.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,27 +1072,25 @@ enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
10721072
* First check pending list, if we're lucky we can just remove it
10731073
* from there. CANCEL_OK means that the work is returned as-new,
10741074
* no completion will be posted for it.
1075-
*/
1076-
for_each_node(node) {
1077-
struct io_wqe *wqe = wq->wqes[node];
1078-
1079-
raw_spin_lock(&wqe->lock);
1080-
io_wqe_cancel_pending_work(wqe, &match);
1081-
raw_spin_unlock(&wqe->lock);
1082-
if (match.nr_pending && !match.cancel_all)
1083-
return IO_WQ_CANCEL_OK;
1084-
}
1085-
1086-
/*
1087-
* Now check if a free (going busy) or busy worker has the work
1075+
*
1076+
* Then check if a free (going busy) or busy worker has the work
10881077
* currently running. If we find it there, we'll return CANCEL_RUNNING
10891078
* as an indication that we attempt to signal cancellation. The
10901079
* completion will run normally in this case.
1080+
*
1081+
* Do both of these while holding the wqe->lock, to ensure that
1082+
* we'll find a work item regardless of state.
10911083
*/
10921084
for_each_node(node) {
10931085
struct io_wqe *wqe = wq->wqes[node];
10941086

10951087
raw_spin_lock(&wqe->lock);
1088+
io_wqe_cancel_pending_work(wqe, &match);
1089+
if (match.nr_pending && !match.cancel_all) {
1090+
raw_spin_unlock(&wqe->lock);
1091+
return IO_WQ_CANCEL_OK;
1092+
}
1093+
10961094
io_wqe_cancel_running_work(wqe, &match);
10971095
raw_spin_unlock(&wqe->lock);
10981096
if (match.nr_running && !match.cancel_all)

0 commit comments

Comments
 (0)