From 1e7c10072c319324a85a4b7d3f3e7626a0fcc5fa Mon Sep 17 00:00:00 2001 From: xujing Date: Sat, 12 Oct 2024 11:43:42 +0800 Subject: [PATCH] mount: optimize mountinfo traversal by decoupling device discovery (cherry picked from commit 6887b918443912bf1c901ac4f530ff93b1d77eb8) --- ...ountinfo-traversal-by-decoupling-dev.patch | 50 +++++++++++++++++++ systemd.spec | 12 +++-- 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch diff --git a/backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch b/backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch new file mode 100644 index 00000000..daa0afac --- /dev/null +++ b/backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch @@ -0,0 +1,50 @@ +From 00ad3f02275b507a753495ace5e5f84cb38b604d Mon Sep 17 00:00:00 2001 +From: Chen Guanqiao +Date: Wed, 2 Oct 2024 13:10:21 +0800 +Subject: [PATCH] mount: optimize mountinfo traversal by decoupling device + discovery + +In mount_load_proc_self_mountinfo(), device_found_node() is synchronously called +during the traversal of mountinfo entries. When there are a large number of +mount points, and the device types are not significantly different, this results +in excessive time consumption during device discovery, causing a performance +bottleneck. This issue is particularly prominent on servers with a large number +of cores in IDC. + +This patch decouples device discovery from the mountinfo traversal process, +avoiding redundant device operations. As a result, it significantly improves +performance, especially in environments with numerous mount points. + +Signed-off-by: Chen Guanqiao +--- + src/core/mount.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/src/core/mount.c b/src/core/mount.c +index 28701df231..5261b80957 100644 +--- a/src/core/mount.c ++++ b/src/core/mount.c +@@ -1857,6 +1857,7 @@ static int mount_setup_unit( + static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { + _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL; + _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL; ++ _cleanup_set_free_ Set *devices = NULL; + int r; + + assert(m); +@@ -1883,7 +1884,11 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { + if (!device || !path) + continue; + +- device_found_node(m, device, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT); ++ /* Just to achieve device name uniqueness. Note that the suppresion of the duplicate ++ * processing is merely an optimization, hence in case of OOM (unlikely) we'll just process ++ * it twice. */ ++ if (set_put_strdup_full(&devices, &path_hash_ops_free, device) != 0) ++ device_found_node(m, device, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT); + + (void) mount_setup_unit(m, device, path, options, fstype, set_flags); + } +-- +2.33.0 + diff --git a/systemd.spec b/systemd.spec index fb73ed61..05ab7002 100644 --- a/systemd.spec +++ b/systemd.spec @@ -25,7 +25,7 @@ Name: systemd Url: https://systemd.io/ Version: 255 -Release: 22 +Release: 23 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -66,9 +66,10 @@ Patch6012: backport-unit-check-for-correct-function-in-vtable.patch Patch6013: backport-fix-homed-log-message-typo-error.patch Patch6014: backport-bash-completion-add-systemctl-service-log-level-target.patch Patch6015: backport-fix-log-message-not-match-glob-patterns-passed-to-disable-command.patch -Patch6016: backport-main-pass-the-right-error-variable.patch -Patch6017: backport-sd-event-fix-fd-leak-when-fd-is-owned-by-IO-event-source.patch -Patch6018: backport-fix-cgtop-sscanf-return-code-checks.patch +Patch6016: backport-main-pass-the-right-error-variable.patch +Patch6017: backport-sd-event-fix-fd-leak-when-fd-is-owned-by-IO-event-source.patch +Patch6018: backport-fix-cgtop-sscanf-return-code-checks.patch +Patch6019: backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch Patch9008: update-rtc-with-system-clock-when-shutdown.patch Patch9009: udev-add-actions-while-rename-netif-failed.patch @@ -1658,6 +1659,9 @@ fi %{_unitdir}/veritysetup.target %changelog +* Tue Nov 05 2024 xujing - 255-23 +- DESC:optimize mountinfo traversal by decoupling device discovery + * Mon Sep 23 2024 xujing - 255-22 - DESC:fix cgroup v2 cpuset function error and optimize the code of cpuset and freezer -- Gitee