VSCode出现"Visual Studio Code is unable to watch for file changes in this large workspace"警告的解决方法

今天,在使用VSCode打开Apollo项目文件夹时,弹出一条警告信息:“Visual Studio Code is unable to watch for file changes in this large workspace”,如下图所示:
1
点击进入VSCode的帮助网站,提示内容如下:

"Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC)
When you see this notification, it indicates that the VS Code file watcher is running out of handles because the workspace is large and contains many files. The current limit can be viewed by running:
cat /proc/sys/fs/inotify/max_user_watches
The limit can be increased to its maximum by editing /etc/sysctl.conf and adding this line to the end of the file:
fs.inotify.max_user_watches=524288
The new value can then be loaded in by running sudo sysctl -p. Note that Arch Linux works a little differently, view this page for advice.
While 524288 is the maximum number of files that can be watched, if you're in an environment that is particularly memory constrained, you may wish to lower the number. Each file watch takes up 540 bytes (32-bit) or ~1kB (64-bit), so assuming that all 524288 watches are consumed that results in an upper bound of around 256MB (32-bit) or 512MB (64-bit).

上述内容的大意是指,目前文件监控的实际数目已超出当前设置值。可以通过修改配置文件的方式,增加文件监控数目,来避免出现警告信息。524288是可设置的最大文件监控数目,一般情况下不应当设置这么大的值,因为每监控一个文件大约会消耗540字节(32位机)或1kB(64位机)的内存,监控524288个文件则大约会消耗256MB(32位机)或512MB(64位机)的内存。
下面将操作方法记录下来,以便今后备查。

1. 检查现有文件监控数目

cat /proc/sys/fs/inotify/max_user_watches

上述命令在我的机器上显示的结果是:8192,这是Ubuntu 16.04系统的默认值。

2. 修改文件监控数目

综合考虑实际需监控文件的数目和内存消耗情况,我将新的文件监控数目设置为:81920,即原来监控数目的10倍。我使用vi对配置文件进行编辑:

sudo vi /etc/sysctl.conf

在该配置文件的最后一行加上下述语句:

fs.inotify.max_user_watches=81920

3. 让配置文件中的新文件监控数目生效

sudo sysctl -p

输出结果为:

fs.inotify.max_user_watches = 81920

重新打开VSCode,只要当前文件夹内文件数目不超过81920个,就不会再出现警告信息了。

发布了83 篇原创文章 · 获赞 267 · 访问量 43万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览