本文主要是介绍limit of inotify,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文可解决函数inotify_add_watch发生ENOSPC错误的问题。
-------------------------------------------------------------------------------------------
Problem
When dropbox or guard says like:
Unable to monitor filesystem Please run: echo 100000 | sudo tee /proc/sys/fs/inotify/max_user_watches and restart Dropbox to correct the problem.
No space left on device - Failed to watch "…": The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource. (Errno::ENOSPC)
Solution
man inotify(7) says:
The following interfaces can be used to limit the amount of kernel memory consumed by inotify:
/proc/sys/fs/inotify/max_queued_events
The value in this file is used when an application calls inotify_init(2) to set an upper limit on the number of events that can be queued to the corresponding inotify instance. Events in excess of this limit are dropped, but an IN_Q_OVERFLOW event is always generated.
/proc/sys/fs/inotify/max_user_instances
This specifies an upper limit on the number of inotify instances that can be created per real user ID.
/proc/sys/fs/inotify/max_user_watches
This specifies an upper limit on the number of watches that can be created per real user ID.
In this case, Dropbox and guard have to use many watches, so do this and increase max_user_watches
.
# Check current maximum
$ cat /proc/sys/fs/inotify/max_user_watches
8192
# Increase the maximum
$ echo 100000|sudo tee /proc/sys/fs/inotify/max_user_watches
Password:
100000
# Check
$ cat /proc/sys/fs/inotify/max_user_watches
100000
Doing the above increases max_user_watches
temporally.
To increase max_user_watches
at boot, edit /etc/sysctl.conf
and add fs.inotify.max_user_watches=100000
or fix fs.inotify.max_user_watches=
to 100000
.
(Note: I’m using gentoo so some other distros may have another way to do this…)
本文转自:http://blog.sorah.jp/2012/01/24/inotify-limitation
这篇关于limit of inotify的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!