When running PhotoStructure, VS Code, Docker, or other development tools, you may encounter errors like:
ENOSPC: System limit for number of file watchers reachedEMFILE: Too many open files
This happens when your system runs out of inotify resources, which Linux uses to monitor file changes.
Check Current Limits
# View current limits
cat /proc/sys/fs/inotify/max_user_watches
cat /proc/sys/fs/inotify/max_user_instances
# See how many watchers are in use
lsof 2>/dev/null | grep inotify | wc -l
Typical defaults are 65,536 watches and 128 instances. Heavy IDE usage can exhaust these.
The Fix
You need to increase max_user_watches and/or max_user_instances.
Ubuntu 24.04+ and Modern Distros
Modern systems use /etc/sysctl.d/ for configuration. Create a new file:
sudo tee /etc/sysctl.d/60-inotify.conf << EOF
fs.inotify.max_user_watches = 524288
fs.inotify.max_user_instances = 512
EOF
# Apply changes
sudo sysctl --system
Older Ubuntu/Debian (pre-24.04)
Edit /etc/sysctl.conf directly:
# Add these lines to /etc/sysctl.conf
echo "fs.inotify.max_user_watches = 524288" | sudo tee -a /etc/sysctl.conf
echo "fs.inotify.max_user_instances = 512" | sudo tee -a /etc/sysctl.conf
# Apply changes
sudo sysctl -p
Which Method Should I Use?
Check if your system uses a symlink:
ls -la /etc/sysctl.d/99-sysctl.conf
If you see 99-sysctl.conf -> ../sysctl.conf, your system links to /etc/sysctl.conf, so editing that file works. Otherwise, use the /etc/sysctl.d/ approach.
Verify the Changes
cat /proc/sys/fs/inotify/max_user_watches
# Should show: 524288
cat /proc/sys/fs/inotify/max_user_instances
# Should show: 512
macOS
macOS uses FSEvents instead of inotify. If you hit limits:
sudo launchctl limit maxfiles 524288 1048576
To make it permanent, create /Library/LaunchDaemons/limit.maxfiles.plist.
Windows
Windows uses ReadDirectoryChangesW and doesn’t have the same hard limits. If you encounter issues, try closing unused applications or restarting.
Memory Impact
Each inotify watch uses about 1KB of kernel memory. With 524,288 watches, that’s roughly 500MB maximum (though actual usage is typically much lower).