Blame SOURCES/0037-core-make-sure-we-don-t-throttle-change-signal-gener.patch

a3e2b5
From 0412acb95ffac94d5916ee19991cc7194e55953c Mon Sep 17 00:00:00 2001
a3e2b5
From: Lennart Poettering <lennart@poettering.net>
a3e2b5
Date: Tue, 13 Nov 2018 12:48:49 +0100
a3e2b5
Subject: [PATCH] core: make sure we don't throttle change signal generator
a3e2b5
 when a reload is pending
a3e2b5
a3e2b5
Fixes: #10627
a3e2b5
(cherry picked from commit b8d381c47776ea0440af175cbe0c02cb743bde08)
a3e2b5
a3e2b5
Resolves: #1647359
a3e2b5
---
a3e2b5
 src/core/manager.c | 64 ++++++++++++++++++++++++++++------------------
a3e2b5
 1 file changed, 39 insertions(+), 25 deletions(-)
a3e2b5
a3e2b5
diff --git a/src/core/manager.c b/src/core/manager.c
a3e2b5
index a24bfcacdf..3b2fe11e87 100644
a3e2b5
--- a/src/core/manager.c
a3e2b5
+++ b/src/core/manager.c
a3e2b5
@@ -2074,56 +2074,70 @@ static unsigned manager_dispatch_dbus_queue(Manager *m) {
a3e2b5
 
a3e2b5
         assert(m);
a3e2b5
 
a3e2b5
+        /* Avoid recursion */
a3e2b5
         if (m->dispatching_dbus_queue)
a3e2b5
                 return 0;
a3e2b5
 
a3e2b5
-        /* Anything to do at all? */
a3e2b5
-        if (!m->dbus_unit_queue && !m->dbus_job_queue && !m->send_reloading_done && !m->pending_reload_message)
a3e2b5
-                return 0;
a3e2b5
+        /* When we are reloading, let's not wait with generating signals, since we need to exit the manager as quickly
a3e2b5
+         * as we can. There's no point in throttling generation of signals in that case. */
a3e2b5
+        if (MANAGER_IS_RELOADING(m) || m->send_reloading_done || m->pending_reload_message)
a3e2b5
+                budget = (unsigned) -1; /* infinite budget in this case */
a3e2b5
+        else {
a3e2b5
+                /* Anything to do at all? */
a3e2b5
+                if (!m->dbus_unit_queue && !m->dbus_job_queue)
a3e2b5
+                        return 0;
a3e2b5
 
a3e2b5
-        /* Do we have overly many messages queued at the moment? If so, let's not enqueue more on top, let's sit this
a3e2b5
-         * cycle out, and process things in a later cycle when the queues got a bit emptier. */
a3e2b5
-        if (manager_bus_n_queued_write(m) > MANAGER_BUS_BUSY_THRESHOLD)
a3e2b5
-                return 0;
a3e2b5
+                /* Do we have overly many messages queued at the moment? If so, let's not enqueue more on top, let's
a3e2b5
+                 * sit this cycle out, and process things in a later cycle when the queues got a bit emptier. */
a3e2b5
+                if (manager_bus_n_queued_write(m) > MANAGER_BUS_BUSY_THRESHOLD)
a3e2b5
+                        return 0;
a3e2b5
 
a3e2b5
-        /* Only process a certain number of units/jobs per event loop iteration. Even if the bus queue wasn't overly
a3e2b5
-         * full before this call we shouldn't increase it in size too wildly in one step, and we shouldn't monopolize
a3e2b5
-         * CPU time with generating these messages. Note the difference in counting of this "budget" and the
a3e2b5
-         * "threshold" above: the "budget" is decreased only once per generated message, regardless how many
a3e2b5
-         * busses/direct connections it is enqueued on, while the "threshold" is applied to each queued instance of bus
a3e2b5
-         * message, i.e. if the same message is enqueued to five busses/direct connections it will be counted five
a3e2b5
-         * times. This difference in counting ("references" vs. "instances") is primarily a result of the fact that
a3e2b5
-         * it's easier to implement it this way, however it also reflects the thinking that the "threshold" should put
a3e2b5
-         * a limit on used queue memory, i.e. space, while the "budget" should put a limit on time. Also note that
a3e2b5
-         * the "threshold" is currently chosen much higher than the "budget". */
a3e2b5
-        budget = MANAGER_BUS_MESSAGE_BUDGET;
a3e2b5
+                /* Only process a certain number of units/jobs per event loop iteration. Even if the bus queue wasn't
a3e2b5
+                 * overly full before this call we shouldn't increase it in size too wildly in one step, and we
a3e2b5
+                 * shouldn't monopolize CPU time with generating these messages. Note the difference in counting of
a3e2b5
+                 * this "budget" and the "threshold" above: the "budget" is decreased only once per generated message,
a3e2b5
+                 * regardless how many busses/direct connections it is enqueued on, while the "threshold" is applied to
a3e2b5
+                 * each queued instance of bus message, i.e. if the same message is enqueued to five busses/direct
a3e2b5
+                 * connections it will be counted five times. This difference in counting ("references"
a3e2b5
+                 * vs. "instances") is primarily a result of the fact that it's easier to implement it this way,
a3e2b5
+                 * however it also reflects the thinking that the "threshold" should put a limit on used queue memory,
a3e2b5
+                 * i.e. space, while the "budget" should put a limit on time. Also note that the "threshold" is
a3e2b5
+                 * currently chosen much higher than the "budget". */
a3e2b5
+                budget = MANAGER_BUS_MESSAGE_BUDGET;
a3e2b5
+        }
a3e2b5
 
a3e2b5
         m->dispatching_dbus_queue = true;
a3e2b5
 
a3e2b5
-        while (budget > 0 && (u = m->dbus_unit_queue)) {
a3e2b5
+        while (budget != 0 && (u = m->dbus_unit_queue)) {
a3e2b5
 
a3e2b5
                 assert(u->in_dbus_queue);
a3e2b5
 
a3e2b5
                 bus_unit_send_change_signal(u);
a3e2b5
-                n++, budget--;
a3e2b5
+                n++;
a3e2b5
+
a3e2b5
+                if (budget != (unsigned) -1)
a3e2b5
+                        budget--;
a3e2b5
         }
a3e2b5
 
a3e2b5
-        while (budget > 0 && (j = m->dbus_job_queue)) {
a3e2b5
+        while (budget != 0 && (j = m->dbus_job_queue)) {
a3e2b5
                 assert(j->in_dbus_queue);
a3e2b5
 
a3e2b5
                 bus_job_send_change_signal(j);
a3e2b5
-                n++, budget--;
a3e2b5
+                n++;
a3e2b5
+
a3e2b5
+                if (budget != (unsigned) -1)
a3e2b5
+                        budget--;
a3e2b5
         }
a3e2b5
 
a3e2b5
         m->dispatching_dbus_queue = false;
a3e2b5
 
a3e2b5
-        if (budget > 0 && m->send_reloading_done) {
a3e2b5
+        if (m->send_reloading_done) {
a3e2b5
                 m->send_reloading_done = false;
a3e2b5
                 bus_manager_send_reloading(m, false);
a3e2b5
-                n++, budget--;
a3e2b5
+                n++;
a3e2b5
         }
a3e2b5
 
a3e2b5
-        if (budget > 0 && m->pending_reload_message) {
a3e2b5
+        if (m->pending_reload_message) {
a3e2b5
                 bus_send_pending_reload_message(m);
a3e2b5
                 n++;
a3e2b5
         }