Repository navigation
workqueue: fix threads stall when running with io_submit_mode offload - #2053
Merged
Merged
Conversation
When starting a submit worker, start_worker() sets the worker state to
IDLE immediately after pthread_create():
sw->flags = SW_F_IDLE;
However, worker_thread() may run and set SW_F_RUNNING very early in its
own startup path:
pthread_mutex_lock(&sw->lock);
sw->flags |= SW_F_RUNNING;
if (ret)
sw->flags |= SW_F_ERROR;
pthread_mutex_unlock(&sw->lock);
If worker_thread() wins the race and sets SW_F_RUNNING before
start_worker() assigns SW_F_IDLE, the unconditional assignment in
start_worker() clobbers previously set bits and leaves the worker flags
as *only* SW_F_IDLE. As a result, workqueue_init() waits forever for all
workers to report SW_F_RUNNING:
thread_main()
-> rate_submit_init()
-> workqueue_init()
...
running = 0;
for (i = 0; i < wq->max_workers; i++) {
pthread_mutex_lock(&sw->lock);
if (sw->flags & SW_F_RUNNING)
running++;
if (sw->flags & SW_F_ERROR)
error++;
pthread_mutex_unlock(&sw->lock);
}
if (error || running == wq->max_workers)
break;
pthread_cond_wait(&wq->flush_cond, &wq->flush_lock);
Because SW_F_RUNNING was overwritten, `running` never reaches
`wq->max_workers`, and the init loop blocks on `flush_cond` indefinitely.
Signed-off-by: Chana Zaks <chana.zaks@sandisk.com>
Signed-off-by: Tomas Winkler <tomas.winkler@sandisk.com>
Owner
|
Nice work! Great description and the fix looks obviously correct. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When starting a submit worker, start_worker() sets the worker state to IDLE immediately after pthread_create():
sw->flags = SW_F_IDLE;
However, worker_thread() may run and set SW_F_RUNNING very early in its own startup path:
If worker_thread() wins the race and sets SW_F_RUNNING before start_worker() assigns SW_F_IDLE, the unconditional assignment in start_worker() clobbers previously set bits and leaves the worker flags as only SW_F_IDLE. As a result, workqueue_init() waits forever for all workers to report SW_F_RUNNING:
Because SW_F_RUNNING was overwritten,
runningnever reacheswq->max_workers, and the init loop blocks onflush_condindefinitely.Please confirm that your commit message(s) follow these guidelines:
aren't something like a URL at 72-74 chars.
Reminders:
cconv.c and bump FIO_SERVER_VER in server.h
FIO_IOOPS_VERSION in ioengines.h.