From 43bbeff601ed510936ac51b572d24388107f033b Mon Sep 17 00:00:00 2001 From: Amir Goldstein Date: Fri, 9 Dec 2022 11:50:26 +0200 Subject: [PATCH] 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 fsnotify(). Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 8bfd690e9f10..ae74f6e60c64 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -190,13 +190,15 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, struct qstr *file_name = NULL; int ret = 0; - /* - * Do inode/sb/mount care about parent and name info on non-dir? - * Do they care about any event at all? - */ - if (!inode->i_fsnotify_marks && !inode->i_sb->s_fsnotify_marks && - (!mnt || !mnt->mnt_fsnotify_marks) && !parent_watched) - return 0; + /* Optimize the likely case of parent not watching */ + if (likely(!parent_watched)) { + __u32 marks_mask = inode->i_fsnotify_mask | + inode->i_sb->s_fsnotify_mask | + (mnt ? mnt->mnt_fsnotify_mask : 0); + + if (!(mask & marks_mask)) + return 0; + } parent = NULL; parent_needed = fsnotify_event_needs_parent(inode, mnt, mask); -- 2.34.1