From 9f9aa8f2a69d2adacee58a575be24ae5bb58c69c Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Wed, 17 Nov 2021 07:34:56 -0800 Subject: [PATCH] [Linux] Avoid duplicating inotify watches in forked AssetBuilder processes (#5683) The AssetProcessor on Linux uses `inotify` to monitor for file updates. The AssetProcessor also uses a `ProcessWatcher` to launch child AssetBuilder processes. `ProcessWatcher` accomplishes this by calling `fork()`, which duplicates the current process, then calling `exec()`. The `fork()` call also appears to duplicate any inotify fds. This results in the subprocess consuming duplicate inotify watches, which is a limited system resource (Ubunut 20 defaults `/proc/sys/fs/inotify/max_user_watches` to 65536). The AssetProcessor still has issues with this max, but this should free up at least half of the uses. Signed-off-by: Chris Burel --- .../Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp b/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp index 2d3e671999..b7f7affd6d 100644 --- a/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp +++ b/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp @@ -32,7 +32,8 @@ struct FolderRootWatch::PlatformImplementation { if (m_iNotifyHandle < 0) { - m_iNotifyHandle = inotify_init(); + // The CLOEXEC flag prevents the inotify watchers from copying on fork/exec + m_iNotifyHandle = inotify_init1(IN_CLOEXEC); } return (m_iNotifyHandle >= 0); }