gvfs-udisks2-volume-monitor still has high cpu usage
I'm running microk8s locally on my developer machine and the deployments create a bunch of mounts:
$ mount | wc -l
642
Most of these shouldn't be interesting to the volume monitor:
$ mount | grep microk8s | wc -l
510
However, even when these mounts are excluded (e.g. with the x-gvfs-hide
mount option), CPU usage of the volume-monitor is still unacceptably high (constant ~90% CPU usage).
I've backported the fix from #713 (closed) (I'm on Ubuntu 24.04) but I'm still seeing high CPU usage.
Recording the process with sudo perf record -p <pid>
gives the following report (excerpt):
# Samples: 82 of event 'cpu_atom/cycles/P'
# Event count (approx.): 3006878784
#
# Children Self Samples Command Shared Object Symbol
# ........ ........ ............ ............... ........................... ...................................
#
99.04% 0.00% 0 gvfs-udisks2-vo gvfs-udisks2-volume-monitor [.] should_include_volume
|
---should_include_volume
g_unix_mount_at
|
|--87.10%--0x735301978d2e
| |
| |--79.85%--0x735301490c76
| | mnt_table_parse_file
| | |
| | |--64.03%--mnt_table_parse_stream
| | | |
| | | |--45.00%--__getdelim
| | | | |
| | | | |--43.96%--_IO_file_underflow@@GLIBC_2.2.5
| | | | | read
The problem is should_include_volume_check_mount_points
calls g_unix_mount_at
in a loop for each mount, and g_unix_mount_at
parses the mount table and does string comparisons on each row to find the correct mount, which burns a lot of CPU.
I think the improvement for this is fairly trivial, get all mounts once with g_unix_mounts_get
and reference those instead.
I'll raise a PR, but this is my first contribution to a GNOME project (and my first contribution in C for 20 years), so please do point me at anything I've missed.