1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-08 20:58:20 +03:00

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>
(cherry picked from commit 00ad3f02275b507a753495ace5e5f84cb38b604d)
(cherry picked from commit 44e1774660fcddcfefcf153cc3c189ea35572d63)
(cherry picked from commit ea35f88ae763b4f99d57c4ec7fd0d3aa6351a352)
(cherry picked from commit 7ed40368310297c2321be0aaf08526b3d390c75b)
This commit is contained in:
Chen Guanqiao 2024-10-02 13:10:21 +08:00 committed by Luca Boccassi
parent e218821b4c
commit 39f4a5abbe

View File

@ -1813,6 +1813,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);
@ -1839,7 +1840,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);
}