All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thread-pool: Allow at least 1 thread in thread_pool_adjust_max_threads_to_work()
@ 2026-05-21 19:06 Maciej S. Szmigiero
  2026-05-22 13:48 ` Fabiano Rosas
  2026-05-26 20:33 ` Peter Xu
  0 siblings, 2 replies; 6+ messages in thread
From: Maciej S. Szmigiero @ 2026-05-21 19:06 UTC (permalink / raw)
  To: Peter Xu, Fabiano Rosas; +Cc: qemu-devel

From: "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>

thread_pool_adjust_max_threads_to_work() is supposed to give each task its
own thread by setting the pool max thread count limit accordingly.

However, if there aren't any tasks currently in the pool the pool max
thread count will be set to 0, which will trigger an assertion failure
in thread_pool_set_max_threads() - because setting this value would
completely block the pool by not allowing it to process any submitted
tasks.

This also can happen if a task is submitted via
thread_pool_submit_immediate() to an empty pool but the task completes so
quickly that by the time this function calls
thread_pool_adjust_max_threads_to_work() the pool again has no unfinished
tasks in it.

Fix this by making sure that the pool is allowed to create at least 1
thread.

Fixes: b5aa74968b27 ("thread-pool: Implement generic (non-AIO) pool support")
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
---
 util/thread-pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/thread-pool.c b/util/thread-pool.c
index 8f8cb38d5ce0..4e75191c983e 100644
--- a/util/thread-pool.c
+++ b/util/thread-pool.c
@@ -493,5 +493,5 @@ bool thread_pool_adjust_max_threads_to_work(ThreadPool *pool)
 {
     QEMU_LOCK_GUARD(&pool->cur_work_lock);
 
-    return thread_pool_set_max_threads(pool, pool->cur_work);
+    return thread_pool_set_max_threads(pool, MAX(pool->cur_work, 1));
 }


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-28 22:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21 19:06 [PATCH] thread-pool: Allow at least 1 thread in thread_pool_adjust_max_threads_to_work() Maciej S. Szmigiero
2026-05-22 13:48 ` Fabiano Rosas
2026-05-26 20:33 ` Peter Xu
2026-05-26 21:06   ` Maciej S. Szmigiero
2026-05-26 22:48     ` Peter Xu
2026-05-28 22:37       ` Maciej S. Szmigiero

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.