infra: defend against OOM and fork limits

This commit is contained in:
Thomas Schoebel-Theuer 2021-11-18 15:53:05 +01:00
parent 1f64238160
commit ae79f46a3e
1 changed files with 11 additions and 2 deletions

View File

@ -702,17 +702,26 @@ typedef enum {
({ \
brick_thread_t *_thr = NULL; \
int _max_retry = 3; \
int _nr_retry = 0; \
\
while (_max_retry-- > 0) { \
for (;;) { \
int _err; \
\
flush_signals(current); \
_thr = kthread_create(_thread_fn, _data, _fmt, ##_args); \
if (likely(!IS_ERR(_thr))) \
break; \
brick_yield(); \
_err = PTR_ERR(_thr); \
if (_err == -EAGAIN || _err == -EINTR) \
if (_err == -EAGAIN || \
_err == -ENOMEM || \
_err == -EINTR || \
_max_retry-- > 0) { \
brick_msleep(_nr_retry++); \
if (_nr_retry > 1000) \
_nr_retry = 1000; \
continue; \
} \
BRICK_ERR("cannot create thread '%s', status = %d\n", _fmt, _err); \
_thr = NULL; \
break; \