This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9f2f8879a6c29570e623b963abefa970bce61b8d Author: dengwenqi <[email protected]> AuthorDate: Wed Nov 11 19:30:38 2026 +0800 fs/inotify: skip the global lock when nobody watches Every read() and write() on a file that can generate inotify events takes g_inotify.lock only to call notify_check_mask(). While another thread holds the lock for a path event (lib_realpath() in notify_open(), for example), unrelated readers and writers queue up behind it even though no watch exists. Read the counters without the lock and return early when no watch is interested. The loads are aligned uint32_t reads, and the race with a concurrent inotify_add_watch() or inotify_rm_watch() is the one that already existed between the unlock after the check and the lock taken again to queue the event. Signed-off-by: dengwenqi <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/vfs/fs_inotify.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/vfs/fs_inotify.c b/fs/vfs/fs_inotify.c index ea2193ce00e..5724ce0e882 100644 --- a/fs/vfs/fs_inotify.c +++ b/fs/vfs/fs_inotify.c @@ -984,10 +984,13 @@ static inline void notify_queue_filep_event(FAR struct file *filep, return; } - nxmutex_lock(&g_inotify.lock); - ret = notify_check_mask(mask); - nxmutex_unlock(&g_inotify.lock); - if (ret < 0) + /* Checked without g_inotify.lock so that readers and writers do not + * queue behind a path event holding it. The counters are aligned + * uint32_t loads; racing a concurrent watch add/remove is the same + * race as the one between this check and the lock taken below. + */ + + if (notify_check_mask(mask) < 0) { return; }
