• Hao Xu's avatar
    io-wq: fix potential race of acct->nr_workers · 767a65e9
    Hao Xu authored
    Given max_worker is 1, and we currently have 1 running and it is
    exiting. There may be race like:
     io_wqe_enqueue                   worker1
                                   no work there and timeout
                                   unlock(wqe->lock)
     ->insert work
                                   -->io_worker_exit
     lock(wqe->lock)
     ->if(!nr_workers) //it's still 1
     unlock(wqe->lock)
        goto run_cancel
                                      lock(wqe->lock)
                                      nr_workers--
                                      ->dec_running
                                        ->worker creation fails
                                      unlock(wqe->lock)
    
    We enqueued one work but there is no workers, causes hung.
    Signed-off-by: default avatarHao Xu <haoxu@linux.alibaba.com>
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    767a65e9
io-wq.c 30.9 KB