16 Star 9 Fork 98

src-openEuler/systemd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-mount-optimize-mountinfo-traversal-by-decoupling-dev.patch 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
From 00ad3f02275b507a753495ace5e5f84cb38b604d Mon Sep 17 00:00:00 2001
From: Chen Guanqiao <chen.chenchacha@foxmail.com>
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 <chen.chenchacha@foxmail.com>
---
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/systemd.git
git@gitee.com:src-openeuler/systemd.git
src-openeuler
systemd
systemd
master

搜索帮助