]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path: Close inotify FD asynchronously
authorMichal Koutný <mkoutny@suse.com>
Mon, 17 Feb 2025 14:40:24 +0000 (15:40 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 4 Mar 2025 20:37:58 +0000 (21:37 +0100)
inotify FD may take several milliseconds to close.  We measured
daemon-reload

        default: (0.427 ± 0.05) s
        async:   (0.323 ± 0.02) s

with 5 path units out of 422 units. I.e. ~1% of units cause ~25% of
delay, hence this fix seems like low-hanging fruit on the daemon-reload
critical path.

Particular inotify slowness pointed out by @fbuihuu.

src/core/path.c

index c9ea31a74ea89e51e19aa8561c14e151cc64350c..4556dbfc71a0a12443eaf5be9d3c65fd758df417 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/inotify.h>
 #include <unistd.h>
 
+#include "async.h"
 #include "bus-error.h"
 #include "bus-util.h"
 #include "dbus-path.h"
@@ -169,7 +170,7 @@ void path_spec_unwatch(PathSpec *s) {
         assert(s);
 
         s->event_source = sd_event_source_disable_unref(s->event_source);
-        s->inotify_fd = safe_close(s->inotify_fd);
+        s->inotify_fd = asynchronous_close(s->inotify_fd);
 }
 
 int path_spec_fd_event(PathSpec *s, uint32_t revents) {