dryang / rpms / systemd

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