Changing the folder watch limit (inotify)

Inotify (inode notify) is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications. 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.

How can I tell if I am out of inotify watches?

  • Start tail with the -f (follow) option on any old file, e.g. tail -f /var/log/dmes. If you are out of watches, it will fail with a somewhat cryptic error like ‘tail: inotify resources exhausted’ or tail: cannot watch ‘/var/log/dmsg’: No space left on device
  • sudo apt-get install inotify-tools.  inotifywatch -v /home/your-username/.profile. If you have reached your maximum limit in inotify watches it will return something like: Failed to watch /home/your-username/.profile; upper limit on inotify watches reached! Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches’

Can you increase the watches? By how much? Any tradeoffs?
Short answer: Sure, no sweat.

  • Each used inotify watch takes up 540 bytes (32-bit system), or 1 kB (double – on 64-bit)
  • This comes out of kernel memory, which is unswappable
  • Assuming you set the max at 524288, and all were used, you’d be using approx. 256MB / 512MB of 32-bit/64-bit kernel memory
  • What’s the max value? I guess none, in theory, as long as you have enough RAM. In practice, 524288 has been officially recommended by apps, and people have been setting it to 2 million, with the accompanying memory usage, of course

How can I increase the amount of inotify watches?

You can find the system limits by reading /proc/sys/fs/inotify/max_user_instances (maximum number of inotify ‘objects’) and /proc/sys/fs/inotify/max_user_watches (maximum number of files watched).

If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p