在 Ubuntu 16.04 上达到了 inotify 手表的用户限制

And*_*rea 57 tail inotify 16.04

我刚刚安装了 Ubuntu 16.04,当我启动SmartGit时收到此警告:

IOException: User limit of inotify watches reached
Run Code Online (Sandbox Code Playgroud)

此外,我收到此警告启动tail -f

tail: inotify resources exhausted 

tail: inotify cannot be used, reverting to polling
Run Code Online (Sandbox Code Playgroud)

我在 Ubuntu 14.04 上从来没有遇到过这个错误,我在新 Ubuntu 上使用的应用程序和文件与我在以前的版本中使用的完全一样。

唯一相关的区别是我在 PC 上添加了一个额外的硬盘,并配置了 Ubuntu 的备份工具。这个问题是否与第二个磁盘或备份工具有关?

Col*_*ing 96

Xenial 上的当前默认值为 8192(请参阅内核源代码中的 fs/notify/inotify/inotify_user.c),您可以通过将文件打印到 stdout 来验证这一点:

cat /proc/sys/fs/inotify/max_user_watches
8192
Run Code Online (Sandbox Code Playgroud)

您可以增加数字,例如,使用以下方法将其翻倍至 16384:

echo 16384 | sudo tee /proc/sys/fs/inotify/max_user_watches
Run Code Online (Sandbox Code Playgroud)

请记住,inotify 手表确实会消耗内存,我认为在 64 位系统上每个手表大约 160 字节。

要永久设置此项,请在 /etc/sysctl.conf 中添加一个条目,例如:

echo fs.inotify.max_user_watches=16384 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Run Code Online (Sandbox Code Playgroud)

..或手动编辑/etc/sysctl.conf(您需要root权限才能更新)然后运行sudo sysctl -p


Ani*_*kur 23

上面的答案很好用,但它并没有解释为什么我在这里寻找完整答案的尝试 -

为什么?

同步文件的程序(例如 dropbox、git 等)使用 inotify 来通知文件系统的更改。可以通过以下方式查看限制 -

cat /proc/sys/fs/inotify/max_user_watches
Run Code Online (Sandbox Code Playgroud)

对我来说,它显示100000。当此限制不足以监视目录中的所有文件时,它会引发此错误。


增加 inotify 观察者的数量(简短版本):

如果您运行的是Debian、RedHat 或其他类似的 Linux 发行版,请在终端中运行以下命令:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Run Code Online (Sandbox Code Playgroud)

如果您正在运行ArchLinux,请改为运行以下命令(请参阅此处了解原因):

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
Run Code Online (Sandbox Code Playgroud)

然后将其粘贴到您的终端中并按回车键运行它。


技术细节:

在 Linux 上,Listen 默认使用 inotify 来监视目录的变化。遇到系统限制您可以监视的文件数量的情况并不少见。例如,Ubuntu Lucid(64 位)的 inotify 限制设置为 8192。

您可以通过执行以下命令获取当前的 inotify 文件监视限制:

$ cat /proc/sys/fs/inotify/max_user_watches
Run Code Online (Sandbox Code Playgroud)

当此限制不足以监视目录中的所有文件时,必须增加此限制才能使侦听正常工作。

您可以临时设置新的限制:

$ sudo sysctl fs.inotify.max_user_watches=524288
$ sudo sysctl -p
Run Code Online (Sandbox Code Playgroud)

如果您想让您的限制永久化,请使用:

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -p
Run Code Online (Sandbox Code Playgroud)

如果 Listen 一直在抱怨,您可能还需要注意 max_queued_events 和 max_user_instances 的值。

来源:https : //github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers