This error may be new or familiar to you when working with VS Code or Node.js application. This is because the default number of file watchers is small on most Linux distributions if not all. I am using Manjaro, so I will show you how to fix the Error ENOSPC System limit for number of file watchers reached.
Note: It can be applied to any Arch based distribution.
There is another way to fix it if you are using web-pack, but our focus here is on the system itself.
Open terminal app and paste or type the following command.
cat /proc/sys/fs/inotify/max_user_watches
This will print the current watchers number.
Let’s fix it
The max value can go up to 524288 and if used max, that means you will be using around 512MB of 64-bit kernel memory.
Each inotify watch uses 1080 bytes on 64-bit architectures. So keep in mind that there is a cost of memory. That is a trade off if it is a development machine.
Let’s add to the Kernel parameters under /proc/sys. This will last till you reboot your system.
sudo sysctl -w fs.inotify.max_user_watches=524288
Run the command below to see the watchers new value and check if the error is gone now.
cat /proc/sys/fs/inotify/max_user_watches
If the error is gone, we can add this permanently to a new file in /etc/sysctl.d/.
echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf
The above command will create a file in /etc/sysctl.d/ and add the watchers count to it.
Last thing is to reload systemd settings to activate this new change. To reload systemd, you can either reboot the machine or just run the following command.
sudo sysctl -p /etc/sysctl.conf
I hope it was useful in some way. 🙂