19
19
#include "io-wq.h"
20
20
21
21
#define WORKER_IDLE_TIMEOUT (5 * HZ)
22
+ #define WORKER_INIT_LIMIT 3
22
23
23
24
enum {
24
25
IO_WORKER_F_UP = 1 , /* up and active */
@@ -54,6 +55,7 @@ struct io_worker {
54
55
unsigned long create_state ;
55
56
struct callback_head create_work ;
56
57
int create_index ;
58
+ int init_retries ;
57
59
58
60
union {
59
61
struct rcu_head rcu ;
@@ -732,14 +734,16 @@ static bool io_wq_work_match_all(struct io_wq_work *work, void *data)
732
734
return true;
733
735
}
734
736
735
- static inline bool io_should_retry_thread (long err )
737
+ static inline bool io_should_retry_thread (struct io_worker * worker , long err )
736
738
{
737
739
/*
738
740
* Prevent perpetual task_work retry, if the task (or its group) is
739
741
* exiting.
740
742
*/
741
743
if (fatal_signal_pending (current ))
742
744
return false;
745
+ if (worker -> init_retries ++ >= WORKER_INIT_LIMIT )
746
+ return false;
743
747
744
748
switch (err ) {
745
749
case - EAGAIN :
@@ -766,7 +770,7 @@ static void create_worker_cont(struct callback_head *cb)
766
770
io_init_new_worker (wqe , worker , tsk );
767
771
io_worker_release (worker );
768
772
return ;
769
- } else if (!io_should_retry_thread (PTR_ERR (tsk ))) {
773
+ } else if (!io_should_retry_thread (worker , PTR_ERR (tsk ))) {
770
774
struct io_wqe_acct * acct = io_wqe_get_acct (worker );
771
775
772
776
atomic_dec (& acct -> nr_running );
@@ -831,7 +835,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
831
835
tsk = create_io_thread (io_wqe_worker , worker , wqe -> node );
832
836
if (!IS_ERR (tsk )) {
833
837
io_init_new_worker (wqe , worker , tsk );
834
- } else if (!io_should_retry_thread (PTR_ERR (tsk ))) {
838
+ } else if (!io_should_retry_thread (worker , PTR_ERR (tsk ))) {
835
839
kfree (worker );
836
840
goto fail ;
837
841
} else {
0 commit comments