Commit bdcd3ea
io_uring: fix poll_list race for SETUP_IOPOLL|SETUP_SQPOLL
After making ext4 support iopoll method:
let ext4_file_operations's iopoll method be iomap_dio_iopoll(),
we found fio can easily hang in fio_ioring_getevents() with below fio
job:
rm -f testfile; sync;
sudo fio -name=fiotest -filename=testfile -iodepth=128 -thread
-rw=write -ioengine=io_uring -hipri=1 -sqthread_poll=1 -direct=1
-bs=4k -size=10G -numjobs=8 -runtime=2000 -group_reporting
with IORING_SETUP_SQPOLL and IORING_SETUP_IOPOLL enabled.
There are two issues that results in this hang, one reason is that
when IORING_SETUP_SQPOLL and IORING_SETUP_IOPOLL are enabled, fio
does not use io_uring_enter to get completed events, it relies on
kernel io_sq_thread to poll for completed events.
Another reason is that there is a race: when io_submit_sqes() in
io_sq_thread() submits a batch of sqes, variable 'inflight' will
record the number of submitted reqs, then io_sq_thread will poll for
reqs which have been added to poll_list. But note, if some previous
reqs have been punted to io worker, these reqs will won't be in
poll_list timely. io_sq_thread() will only poll for a part of previous
submitted reqs, and then find poll_list is empty, reset variable
'inflight' to be zero. If app just waits these deferred reqs and does
not wake up io_sq_thread again, then hang happens.
For app that entirely relies on io_sq_thread to poll completed requests,
let io_iopoll_req_issued() wake up io_sq_thread properly when adding new
element to poll_list, and when io_sq_thread prepares to sleep, check
whether poll_list is empty again, if not empty, continue to poll.
Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>1 parent 41726c9 commit bdcd3ea
1 file changed
Lines changed: 27 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1821 | 1821 | | |
1822 | 1822 | | |
1823 | 1823 | | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
1824 | 1828 | | |
1825 | 1829 | | |
1826 | 1830 | | |
| |||
5086 | 5090 | | |
5087 | 5091 | | |
5088 | 5092 | | |
5089 | | - | |
5090 | 5093 | | |
5091 | | - | |
| 5094 | + | |
5092 | 5095 | | |
5093 | 5096 | | |
5094 | 5097 | | |
5095 | 5098 | | |
5096 | 5099 | | |
5097 | 5100 | | |
5098 | 5101 | | |
5099 | | - | |
| 5102 | + | |
5100 | 5103 | | |
5101 | 5104 | | |
5102 | 5105 | | |
5103 | | - | |
| 5106 | + | |
5104 | 5107 | | |
5105 | 5108 | | |
5106 | | - | |
5107 | | - | |
5108 | | - | |
5109 | | - | |
5110 | | - | |
5111 | | - | |
5112 | | - | |
5113 | | - | |
5114 | | - | |
5115 | | - | |
5116 | | - | |
5117 | | - | |
5118 | | - | |
5119 | | - | |
5120 | | - | |
5121 | | - | |
5122 | | - | |
5123 | | - | |
5124 | | - | |
5125 | | - | |
5126 | | - | |
5127 | | - | |
5128 | | - | |
5129 | | - | |
5130 | | - | |
| 5109 | + | |
| 5110 | + | |
| 5111 | + | |
| 5112 | + | |
5131 | 5113 | | |
| 5114 | + | |
5132 | 5115 | | |
5133 | 5116 | | |
5134 | 5117 | | |
| |||
5157 | 5140 | | |
5158 | 5141 | | |
5159 | 5142 | | |
5160 | | - | |
| 5143 | + | |
5161 | 5144 | | |
5162 | 5145 | | |
5163 | 5146 | | |
| |||
5167 | 5150 | | |
5168 | 5151 | | |
5169 | 5152 | | |
| 5153 | + | |
| 5154 | + | |
| 5155 | + | |
| 5156 | + | |
| 5157 | + | |
| 5158 | + | |
| 5159 | + | |
| 5160 | + | |
| 5161 | + | |
| 5162 | + | |
| 5163 | + | |
| 5164 | + | |
| 5165 | + | |
5170 | 5166 | | |
5171 | 5167 | | |
5172 | 5168 | | |
| |||
5194 | 5190 | | |
5195 | 5191 | | |
5196 | 5192 | | |
5197 | | - | |
5198 | | - | |
| 5193 | + | |
5199 | 5194 | | |
5200 | 5195 | | |
5201 | 5196 | | |
| |||
0 commit comments