DEV Community

Cover image for Ubuntu Increase Inotify Watcher (File Watch Limit)
Rubin
Rubin

Posted on

Ubuntu Increase Inotify Watcher (File Watch Limit)

Technical Details

Possible cause of Vue.js hot reload or LiveReload not working and failed file watchers on IDE

Listen uses inotify by default on Linux to monitor directories for changes. It's not uncommon to encounter a system limit on the number of files you can monitor. For example, Ubuntu Lucid's (64bit) inotify limit is set to 8192.

The current default is 8192 (see fs/notify/inotify/inotify_user.c in the kernel source), you can verify this by printing the file to stdout:

cat /proc/sys/fs/inotify/max_user_watches
8192
Enter fullscreen mode Exit fullscreen mode

You can bump the number up, for example, doubling this to 16384, using:

echo 16384 | sudo tee /proc/sys/fs/inotify/max_user_watches
Enter fullscreen mode Exit fullscreen mode

bear in mind that inotify watches do consume memory, I think it's around 160 bytes per watch on 64 bit systems.

To set this permanently, add an entry to /etc/sysctl.conf, for example:

echo fs.inotify.max_user_watches=16384 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Enter fullscreen mode Exit fullscreen mode

..or manually edit /etc/sysctl.conf (you need root privileges to update it) and then run

sudo sysctl -p
Enter fullscreen mode Exit fullscreen mode

Top comments (7)

Collapse
 
eclecticcoding profile image
Chuck

You what its worth the inotify number is much higher in Ubuntu/POP_OS 19.10 (64bit): 65536

Informative post.

Collapse
 
dcuttridge profile image
Daniel Cuttridge

Thanks for the help! Question: Is there any real downside to continuing to increase this number? Would it not be better to clear the watch list at some point? Or is that not possible? Thanks again!

Collapse
 
ninofiliu profile image
Nino Filiu

There is no downside, or to be more precise it depends on the program using these watchers, however there are limits explained in this unix stack exchange answer

Collapse
 
ankurk91 profile image
Ankur K

Please mention if we need to restart the computer after the change.

Collapse
 
crazyoptimist profile image
crazyoptimist • Edited

echo fs.inotify.max_user_watches=16384
This sets the number for the current shell session, and as the config file is written, so it will also work on the next boot. So no need to reboot.

Collapse
 
aybee5 profile image
Ibrahim Abdullahi Aliyu

is there any downside for making it permanent in respect to your system performance?

Collapse
 
crazyoptimist profile image
crazyoptimist

No downside from my experience, even with much higher number.