ccfeeef59d
Backport the patches for this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1819868 We met such an issue: When testing a large number of pods (> 230), occasionally observed a number of issues related to systemd process: systemd ran continually 90-100% cpu usage systemd memory usage started increasing rapidly (20GB/hour) systemctl commands would always timeout (Failed to get properties: Connection timed out) sm services failed and can't recover: open-ldap, registry-token-server, docker-distribution, etcd new pods can't start, and got stuck in state ContainerCreating Those patches work to prevent excessive /proc/1/mountinfo reparsing. It has been verified that those patches can improve this performance greatly. 16 commits are listed in sequence (from [1] to [16]) at below link for the issue: https://github.com/systemd-rhel/rhel-8/pull/154/commits [16](10)core: prevent excessive /proc/self/mountinfo parsing [15][Dropped-6]test: add ratelimiting test [14](9)sd-event: add ability to ratelimit event sources [13](8)sd-event: increase n_enabled_child_sources just once [12](7)sd-event: update state at the end in event_source_enable [11](6)sd-event: remove earliest_index/latest_index into common part of event source objects [10][Dropped-5]sd-event: follow coding style with naming return parameter [9] [Dropped-4]sd-event: ref event loop while in sd_event_prepare() ot sd_event_run() [8] (5)sd-event: refuse running default event loops in any other thread than the one they are default for [7] [Dropped-3]sd-event: let's suffix last_run/last_log with "_usec" [6] [Dropped-2]sd-event: fix delays assert brain-o (#17790) [5] (4)sd-event: split out code to add/remove timer event sources to earliest/latest prioq [4] (3)sd-event: split clock data allocation out of sd_event_add_time() [3] [Dropped-1]sd-event: mention that two debug logged events are ignored [2] (2)sd-event: split out enable and disable codepaths from sd_event_source_set_enabled() [1] (1)sd-event: split out helper functions for reshuffling prioqs I ported 10 of them back (from (1) to (10)) to fix this issue and dropped the other 6 (from [Dropped-1] to [Dropped-6]) for those reasons: [Dropped-1]Only changes error log. [Dropped-2]Fixes a bug introduced in a commit which doesn't exist in this version. [Dropped-3]Only changes vars' names and there is no functional change. [Dropped-4]More commits are needed for merging it, while I don't see any help on adding the rate-limiting ability. [Dropped-5]Change coding style for a function which isn't really used by anyone. [Dropped-6]Add test cases. Closes-Bug: #1924686 Signed-off-by: Li Zhou <li.zhou@windriver.com> Change-Id: Ia4c8f162cb1a47b40d1b26cf4d604976b97e92d6
121 lines
3.7 KiB
Diff
121 lines
3.7 KiB
Diff
From dad1d000b493f98f4f5eaf4bfa34c8617f41970f Mon Sep 17 00:00:00 2001
|
|
From: Lennart Poettering <lennart@poettering.net>
|
|
Date: Mon, 23 Nov 2020 15:25:35 +0100
|
|
Subject: [PATCH 10/20] sd-event: split out code to add/remove timer event
|
|
sources to earliest/latest prioq
|
|
|
|
Just some refactoring that makes code prettier, and will come handy
|
|
later, because we can reuse these functions at more places.
|
|
|
|
(cherry picked from commit 1e45e3fecc303e7ae9946220c742f69675e99c34)
|
|
|
|
Related: #1819868
|
|
|
|
[commit 88b2618e4de850060a1c5c22b049e6de0578fbb5 from
|
|
https://github.com/systemd-rhel/rhel-8/]
|
|
|
|
Signed-off-by: Li Zhou <li.zhou@windriver.com>
|
|
---
|
|
src/libsystemd/sd-event/sd-event.c | 57 +++++++++++++++++++++---------
|
|
1 file changed, 41 insertions(+), 16 deletions(-)
|
|
|
|
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
|
|
index 8e6536f..e0e0eaa 100644
|
|
--- a/src/libsystemd/sd-event/sd-event.c
|
|
+++ b/src/libsystemd/sd-event/sd-event.c
|
|
@@ -809,6 +809,19 @@ static void event_source_time_prioq_reshuffle(sd_event_source *s) {
|
|
d->needs_rearm = true;
|
|
}
|
|
|
|
+static void event_source_time_prioq_remove(
|
|
+ sd_event_source *s,
|
|
+ struct clock_data *d) {
|
|
+
|
|
+ assert(s);
|
|
+ assert(d);
|
|
+
|
|
+ prioq_remove(d->earliest, s, &s->time.earliest_index);
|
|
+ prioq_remove(d->latest, s, &s->time.latest_index);
|
|
+ s->time.earliest_index = s->time.latest_index = PRIOQ_IDX_NULL;
|
|
+ d->needs_rearm = true;
|
|
+}
|
|
+
|
|
static void source_disconnect(sd_event_source *s) {
|
|
sd_event *event;
|
|
|
|
@@ -833,13 +846,8 @@ static void source_disconnect(sd_event_source *s) {
|
|
case SOURCE_TIME_REALTIME_ALARM:
|
|
case SOURCE_TIME_BOOTTIME_ALARM: {
|
|
struct clock_data *d;
|
|
-
|
|
- d = event_get_clock_data(s->event, s->type);
|
|
- assert(d);
|
|
-
|
|
- prioq_remove(d->earliest, s, &s->time.earliest_index);
|
|
- prioq_remove(d->latest, s, &s->time.latest_index);
|
|
- d->needs_rearm = true;
|
|
+ assert_se(d = event_get_clock_data(s->event, s->type));
|
|
+ event_source_time_prioq_remove(s, d);
|
|
break;
|
|
}
|
|
|
|
@@ -1087,6 +1095,30 @@ static int setup_clock_data(sd_event *e, struct clock_data *d, clockid_t clock)
|
|
return 0;
|
|
}
|
|
|
|
+static int event_source_time_prioq_put(
|
|
+ sd_event_source *s,
|
|
+ struct clock_data *d) {
|
|
+
|
|
+ int r;
|
|
+
|
|
+ assert(s);
|
|
+ assert(d);
|
|
+
|
|
+ r = prioq_put(d->earliest, s, &s->time.earliest_index);
|
|
+ if (r < 0)
|
|
+ return r;
|
|
+
|
|
+ r = prioq_put(d->latest, s, &s->time.latest_index);
|
|
+ if (r < 0) {
|
|
+ assert_se(prioq_remove(d->earliest, s, &s->time.earliest_index) > 0);
|
|
+ s->time.earliest_index = PRIOQ_IDX_NULL;
|
|
+ return r;
|
|
+ }
|
|
+
|
|
+ d->needs_rearm = true;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
_public_ int sd_event_add_time(
|
|
sd_event *e,
|
|
sd_event_source **ret,
|
|
@@ -1113,8 +1145,7 @@ _public_ int sd_event_add_time(
|
|
type = clock_to_event_source_type(clock);
|
|
assert_return(type >= 0, -ENOTSUP);
|
|
|
|
- d = event_get_clock_data(e, type);
|
|
- assert(d);
|
|
+ assert_se(d = event_get_clock_data(e, type));
|
|
|
|
r = setup_clock_data(e, d, clock);
|
|
if (r < 0)
|
|
@@ -1131,13 +1162,7 @@ _public_ int sd_event_add_time(
|
|
s->userdata = userdata;
|
|
s->enabled = SD_EVENT_ONESHOT;
|
|
|
|
- d->needs_rearm = true;
|
|
-
|
|
- r = prioq_put(d->earliest, s, &s->time.earliest_index);
|
|
- if (r < 0)
|
|
- goto fail;
|
|
-
|
|
- r = prioq_put(d->latest, s, &s->time.latest_index);
|
|
+ r = event_source_time_prioq_put(s, d);
|
|
if (r < 0)
|
|
goto fail;
|
|
|
|
--
|
|
2.17.1
|
|
|