From 9baaac1b6d0076fd5aabb005986328f55b6e9b16 Mon Sep 17 00:00:00 2001 From: zhaoxiaohu Date: Fri, 18 Oct 2024 14:38:42 +0800 Subject: [PATCH] pid1: add env var to override default mount rate limit burst and interval Signed-off-by: zhaoxiaohu --- ...rride-default-mount-rate-limit-burst.patch | 64 ++++++++++++++++ ...de-default-mount-rate-limit-interval.patch | 76 +++++++++++++++++++ systemd.spec | 7 +- 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 backport-pid1-add-env-var-to-override-default-mount-rate-limit-burst.patch create mode 100644 backport-pid1-add-env-var-to-override-default-mount-rate-limit-interval.patch diff --git a/backport-pid1-add-env-var-to-override-default-mount-rate-limit-burst.patch b/backport-pid1-add-env-var-to-override-default-mount-rate-limit-burst.patch new file mode 100644 index 0000000..138b18c --- /dev/null +++ b/backport-pid1-add-env-var-to-override-default-mount-rate-limit-burst.patch @@ -0,0 +1,64 @@ +From 24a4542cfa674ee80b54afcc223f2490a011966b Mon Sep 17 00:00:00 2001 +From: Luca Boccassi +Date: Mon, 5 Dec 2022 21:05:54 +0000 +Subject: [PATCH] pid1: add env var to override default mount rate limit burst + +I am hitting the rate limit on a busy system with low resources, and +it stalls the boot process which is Very Bad (TM). + +Signed-off-by: zhaoxiaohu +--- + docs/ENVIRONMENT.md | 7 +++++++ + src/core/mount.c | 11 ++++++++++- + 2 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md +index 33606fc..4c37e03 100644 +--- a/docs/ENVIRONMENT.md ++++ b/docs/ENVIRONMENT.md +@@ -263,6 +263,13 @@ All tools: + + `systemd-remount-fs`: + ++* `$SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST` — can be set to override the mount ++ units burst rate limit for parsing `/proc/self/mountinfo`. On a system with ++ few resources but many mounts the rate limit may be hit, which will cause the ++ processing of mount units to stall. The burst limit may be adjusted when the ++ default is not appropriate for a given system. Defaults to `5`, accepts ++ positive integers. ++ + * `$SYSTEMD_REMOUNT_ROOT_RW=1` — if set and no entry for the root directory + exists in `/etc/fstab` (this file always takes precedence), then the root + directory is remounted writable. This is primarily used by +diff --git a/src/core/mount.c b/src/core/mount.c +index 11327d4..ead9b46 100644 +--- a/src/core/mount.c ++++ b/src/core/mount.c +@@ -1875,6 +1875,7 @@ static void mount_enumerate(Manager *m) { + mnt_init_debug(0); + + if (!m->mount_monitor) { ++ unsigned mount_rate_limit_burst = 5; + int fd; + + m->mount_monitor = mnt_new_monitor(); +@@ -1914,7 +1915,15 @@ static void mount_enumerate(Manager *m) { + goto fail; + } + +- r = sd_event_source_set_ratelimit(m->mount_event_source, 1 * USEC_PER_SEC, 5); ++ /* Let users override the default (5 in 1s), as it stalls the boot sequence on busy systems. */ ++ const char *e = secure_getenv("SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST"); ++ if (e) { ++ r = safe_atou(e, &mount_rate_limit_burst); ++ if (r < 0) ++ log_debug("Invalid value in $SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST, ignoring: %s", e); ++ } ++ ++ r = sd_event_source_set_ratelimit(m->mount_event_source, 1 * USEC_PER_SEC, mount_rate_limit_burst); + if (r < 0) { + log_error_errno(r, "Failed to enable rate limit for mount events: %m"); + goto fail; +-- +2.33.0 + diff --git a/backport-pid1-add-env-var-to-override-default-mount-rate-limit-interval.patch b/backport-pid1-add-env-var-to-override-default-mount-rate-limit-interval.patch new file mode 100644 index 0000000..e66100d --- /dev/null +++ b/backport-pid1-add-env-var-to-override-default-mount-rate-limit-interval.patch @@ -0,0 +1,76 @@ +From cc2030f928981947db8fb9ec185a82024abab2c4 Mon Sep 17 00:00:00 2001 +From: xujing +Date: Wed, 16 Oct 2024 15:19:09 +0800 +Subject: [PATCH] pid1: add env var to override default mount rate limit + interval + +Similar to 24a4542c. 24a4542c can only be set 1 in 1s at most, +sometimes we may need to set to something else(such as 1 in 2s). +So it's best to let the user decide. + +This also allows users to solve #34690. + +Signed-off-by: xujing +--- + docs/ENVIRONMENT.md | 7 +++++++ + src/core/mount.c | 14 +++++++++++--- + 2 files changed, 18 insertions(+), 3 deletions(-) + +diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md +index 4c37e03..0796eae 100644 +--- a/docs/ENVIRONMENT.md ++++ b/docs/ENVIRONMENT.md +@@ -270,6 +270,13 @@ All tools: + default is not appropriate for a given system. Defaults to `5`, accepts + positive integers. + ++* `$SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_INTERVAL_SEC` — can be set to override the mount ++ units interval rate limit for parsing `/proc/self/mountinfo`. Similar to ++ `$SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST`, the interval limit maybe adjusted when ++ the default is not appropriate for a given system. The default value is 1 and the ++ default application time unit is second, and the time unit can beoverriden as usual ++ by specifying it explicitly, see the systemd.time(7) man page. ++ + * `$SYSTEMD_REMOUNT_ROOT_RW=1` — if set and no entry for the root directory + exists in `/etc/fstab` (this file always takes precedence), then the root + directory is remounted writable. This is primarily used by +diff --git a/src/core/mount.c b/src/core/mount.c +index ead9b46..f4bc6eb 100644 +--- a/src/core/mount.c ++++ b/src/core/mount.c +@@ -1875,6 +1875,7 @@ static void mount_enumerate(Manager *m) { + mnt_init_debug(0); + + if (!m->mount_monitor) { ++ usec_t mount_rate_limit_interval = 1 * USEC_PER_SEC; + unsigned mount_rate_limit_burst = 5; + int fd; + +@@ -1916,14 +1917,21 @@ static void mount_enumerate(Manager *m) { + } + + /* Let users override the default (5 in 1s), as it stalls the boot sequence on busy systems. */ +- const char *e = secure_getenv("SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST"); ++ const char *e = secure_getenv("SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_INTERVAL_SEC"); ++ if (e) { ++ r = parse_sec(e, &mount_rate_limit_interval); ++ if (r < 0) ++ log_debug_errno(r, "Invalid value in $SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_INTERVAL_SEC, ignoring: %s", e); ++ } ++ ++ e = secure_getenv("SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST"); + if (e) { + r = safe_atou(e, &mount_rate_limit_burst); + if (r < 0) +- log_debug("Invalid value in $SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST, ignoring: %s", e); ++ log_debug_errno(r, "Invalid value in $SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST, ignoring: %s", e); + } + +- r = sd_event_source_set_ratelimit(m->mount_event_source, 1 * USEC_PER_SEC, mount_rate_limit_burst); ++ r = sd_event_source_set_ratelimit(m->mount_event_source, mount_rate_limit_interval, mount_rate_limit_burst); + if (r < 0) { + log_error_errno(r, "Failed to enable rate limit for mount events: %m"); + goto fail; +-- +2.33.0 + diff --git a/systemd.spec b/systemd.spec index f263f03..9e955cb 100644 --- a/systemd.spec +++ b/systemd.spec @@ -21,7 +21,7 @@ Name: systemd Url: https://systemd.io/ Version: 249 -Release: 92 +Release: 93 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -664,6 +664,8 @@ Patch6615: backport-pid1-cgroup-show-ignore-EOPNOTSUPP-in-cg_read_pid.patch Patch6616: backport-cgroup-util-introduce-cg_is_threaded.patch Patch6617: backport-core-execute-warn-when-threaded-mode-is-detected.patch Patch6618: backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch +Patch6619: backport-pid1-add-env-var-to-override-default-mount-rate-limit-burst.patch +Patch6620: backport-pid1-add-env-var-to-override-default-mount-rate-limit-interval.patch Patch9001: update-rtc-with-system-clock-when-shutdown.patch Patch9002: udev-add-actions-while-rename-netif-failed.patch @@ -2150,6 +2152,9 @@ grep -q -E '^KEYMAP="?fi-latin[19]"?' /etc/vconsole.conf 2>/dev/null && %{_libdir}/security/pam_systemd.so %changelog +* Fri Oct 18 2024 zhaoxiaohu - 249-93 +- pid1: add env var to override default mount rate limit burst and interval + * Sat Oct 12 2024 xujing - 249-92 - optimize mountinfo traversal by decoupling device discovery -- Gitee