From 0c0c85ed9dab7d958712401631c750472eded707 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 23 Jun 2020 11:32:35 +0200 Subject: [PATCH] BUG/MINOR: tasks: make sure never to exceed max_processed We want to be sure not to exceed max_processed. It can actually go slightly negative due to the rounding applied to ratios, but we must refrain from processing too many tasks if it's already low. This became particularly relevant since recent commit 5c8be272c ("MEDIUM: tasks: also process late wakeups in process_runnable_tasks()") which was merged into 2.2-dev10. No backport is needed. --- src/task.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/task.c b/src/task.c index 500223f18..2097555f1 100644 --- a/src/task.c +++ b/src/task.c @@ -448,8 +448,10 @@ void process_runnable_tasks() LIST_SPLICE_END_DETACHED(&sched->tasklets[TL_URGENT], (struct list *)tmp_list); /* run up to max_processed/3 urgent tasklets */ - done = run_tasks_from_list(&tt->tasklets[TL_URGENT], (max_processed + 2) / 3); - max_processed -= done; + if (max_processed > 0) { + done = run_tasks_from_list(&tt->tasklets[TL_URGENT], (max_processed + 2) / 3); + max_processed -= done; + } /* pick up to max_processed/2 (~=3/4*(max_processed-done)) regular tasks from prio-ordered run queues */ @@ -518,15 +520,19 @@ void process_runnable_tasks() } /* run between 0.4*max_processed and max_processed/2 regular tasks */ - done = run_tasks_from_list(&tt->tasklets[TL_NORMAL], (3 * max_processed + 3) / 4); - max_processed -= done; + if (max_processed > 0) { + done = run_tasks_from_list(&tt->tasklets[TL_NORMAL], (3 * max_processed + 3) / 4); + max_processed -= done; + } /* run between max_processed/4 and max_processed bulk tasklets */ - done = run_tasks_from_list(&tt->tasklets[TL_BULK], max_processed); - max_processed -= done; + if (max_processed > 0) { + done = run_tasks_from_list(&tt->tasklets[TL_BULK], max_processed); + max_processed -= done; + } /* some tasks may have woken other ones up */ - if (max_processed && thread_has_tasks()) + if (max_processed > 0 && thread_has_tasks()) goto not_done_yet; if (!LIST_ISEMPTY(&sched->tasklets[TL_URGENT]) |