tail: inotify cannot be used, reverting to polling: Too many open files

Solution 1:

This was solved for me by following the instructions on http://peter-butkovic.blogspot.com/2013/08/tail-inotify-resources-exhausted.html

Permanent solution (preserved across restarts) Adding line:

fs.inotify.max_user_watches=1048576

to:

/etc/sysctl.conf

fixed the limit value permanently (even between restarts).

then do a

sysctl -p

Solution 2:

I think that answer is not complete (it doesn't say anything about the maximum limit of files open on the system).

There are two limits regarding the maximum number of open files:

  1. Maximum limit of files open per process.

    • You can see which is the value of this limit using: ulimit -n
    • You can change this limit using: ulimit -n new_limit_number
    • Here is a command to get the top 10 processes having many files open:

      lsof | awk '{ print $2; }' | sort -rn | uniq -c | sort -rn | head
      
  2. Maximum limit of files open per system.

    • You can see which is the value of this limit using: cat /proc/sys/fs/file-max
    • You can change this limit using: echo new_limit_number > /proc/sys/fs/file-max
    • Count all open file handles: lsof | wc -l

Solution 3:

Most likely, you've run out of your inotify watches. Probably, you're running some file synchronization tools(eg. Dropbox) in background?

In Linux, the internal implementation of tail -f command uses the inotify mechanism by default, so as to monitor file changes. If you've run out of all the inotify watches(8192 by default), then inotify -f have to switch to polling to detect changes to that file.

Of course, you can modify the maximum number of inotify watches.

reference:
http://www.quora.com/How-is-tail-f-implemented
http://peter-butkovic.blogspot.com/2013/08/tail-inotify-resources-exhausted.html
https://serverfault.com/questions/510708/tail-inotify-cannot-be-used-reverting-to-polling-too-many-open-files