fsnotify: optimize the case of no parent watcher
authorAmir Goldstein <amir73il@gmail.com>
Tue, 16 Jan 2024 11:32:47 +0000 (13:32 +0200)
committerJan Kara <jack@suse.cz>
Wed, 24 Jan 2024 15:26:03 +0000 (16:26 +0100)
commit082fd1ea1f98e6bb1189213a2404ddd774de3843
treec000bfff67879692051bb885f536a28024547aae
parent615d300648869c774bd1fe54b4627bb0c20faed4
fsnotify: optimize the case of no parent watcher

If parent inode is not watching, check for the event in masks of
sb/mount/inode masks early to optimize out most of the code in
__fsnotify_parent() and avoid calling fsnotify().

Jens has reported that this optimization improves BW and IOPS in an
io_uring benchmark by more than 10% and reduces perf reported CPU usage.

before:

+    4.51%  io_uring  [kernel.vmlinux]  [k] fsnotify
+    3.67%  io_uring  [kernel.vmlinux]  [k] __fsnotify_parent

after:

+    2.37%  io_uring  [kernel.vmlinux]  [k] __fsnotify_parent

Reported-and-tested-by: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/linux-fsdevel/b45bd8ff-5654-4e67-90a6-aad5e6759e0b@kernel.dk/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Message-Id: <20240116113247.758848-1-amir73il@gmail.com>
fs/notify/fsnotify.c