brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: fs.inotify.max_user_watches fixes 'no space left' errors from file watchers on Linux

Linux
~/tips/tip-linux-inotify-max-user-watches

cat /proc/sys/fs/inotify/max_user_watches

Raise the inotify watch limit when an editor, sync tool or dev server cannot watch your files.

An error like System limit for number of file watchers reached, or a confusing No space left on device while the disk has plenty of room, often comes from inotify. Every watched folder uses a watch, and the number per user is limited.

Check the current limit:

cat /proc/sys/fs/inotify/max_user_watches

Syncthing, VS Code, dev servers and media scanners all watch folders, and each folder costs one watch. A big project folder with node_modules or a large photo library can use up a low limit quickly. Raise it, and keep it after a reboot:

echo 'fs.inotify.max_user_watches = 524288' | sudo tee /etc/sysctl.d/90-inotify.conf
sudo sysctl -p /etc/sysctl.d/90-inotify.conf

The inotify(7) man page lists this file, along with max_user_instances, the number of inotify instances a user may create. If the error mentions too many open files or instances rather than watches, that second limit is the one to raise.

Each watch costs a bit of kernel memory that cannot be swapped out, so I would not set an enormous number just because you can. Newer kernels already pick a default based on the amount of RAM, which is why you may find a high value there already.

And sometimes the right fix is to watch less. Most tools can exclude folders such as node_modules, .git or a cache directory, which saves watches and CPU time. The limit counts per user, so several programs running as the same user share it.

Further reading: inotify(7) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link