Skip to content

Instantly share code, notes, and snippets.

@tbjgolden
Last active November 27, 2024 14:22
Show Gist options
  • Save tbjgolden/c53ca37f3bc2fab8c930183310918c8c to your computer and use it in GitHub Desktop.
Save tbjgolden/c53ca37f3bc2fab8c930183310918c8c to your computer and use it in GitHub Desktop.
[Arch Linux] [Manjaro] How to avoid "Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC)

To avoid this error, we need to increase the inotify watcher limit.

The way to do this is different on Arch based distributions than other Linux distributions.

Instructions for Arch Linux/Manjaro

Check for an already existing inotify config file (recent versions of Manjaro include one)

ls /etc/sysctl.d/*-max_user_watches.conf

a) If no output

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max_user_watches.conf && sudo sysctl --system

b) If the command outputs a file

(in the rare case where it outputs multiple files, continue using the last one in the list)

# replace `/etc/sysctl.d/50-max_user_watches.conf` with the file returned from the previous `ls` command
echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/50-max_user_watches.conf && sudo sysctl --system

Check it's working

cat /proc/sys/fs/inotify/max_user_watches

Expected output: 524288

Credits

@retry19
Copy link

retry19 commented Nov 13, 2020

when run this command

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/50-max-user-watches.conf && sudo sysctl --system

display output is

fs.inotify.max_user_watches=524288
* Applying /usr/lib/sysctl.d/10-manjaro.conf ...
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 524288
* Applying /etc/sysctl.d/100-manjaro.conf ...
vm.swappiness = 10
* Applying /usr/lib/sysctl.d/50-coredump.conf ...
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
fs.suid_dumpable = 2
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 2
sysctl: setting key "net.ipv4.conf.all.rp_filter": Invalid argument
net.ipv4.conf.default.accept_source_route = 0
sysctl: setting key "net.ipv4.conf.all.accept_source_route": Invalid argument
net.ipv4.conf.default.promote_secondaries = 1
sysctl: setting key "net.ipv4.conf.all.promote_secondaries": Invalid argument
net.ipv4.ping_group_range = 0 2147483647
net.core.default_qdisc = fq_codel
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
fs.protected_regular = 1
fs.protected_fifos = 1
* Applying /etc/sysctl.d/50-max-user-watches.conf ...
fs.inotify.max_user_watches = 524288
* Applying /etc/sysctl.d/50-max_user_watches.conf ...
fs.inotify.max_user_watches = 16384
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
kernel.pid_max = 4194304
* Applying /usr/lib/sysctl.d/60-libvirtd.conf ...
fs.aio-max-nr = 1048576

then, after run this command to check it's work or not

cat /proc/sys/fs/inotify/max_user_watches

output is still 16384

how to make it work?

@ntropy83
Copy link

when run this command

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/50-max-user-watches.conf && sudo sysctl --system

display output is

fs.inotify.max_user_watches=524288
* Applying /usr/lib/sysctl.d/10-manjaro.conf ...
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 524288
* Applying /etc/sysctl.d/100-manjaro.conf ...
vm.swappiness = 10
* Applying /usr/lib/sysctl.d/50-coredump.conf ...
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
fs.suid_dumpable = 2
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 2
sysctl: setting key "net.ipv4.conf.all.rp_filter": Invalid argument
net.ipv4.conf.default.accept_source_route = 0
sysctl: setting key "net.ipv4.conf.all.accept_source_route": Invalid argument
net.ipv4.conf.default.promote_secondaries = 1
sysctl: setting key "net.ipv4.conf.all.promote_secondaries": Invalid argument
net.ipv4.ping_group_range = 0 2147483647
net.core.default_qdisc = fq_codel
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
fs.protected_regular = 1
fs.protected_fifos = 1
* Applying /etc/sysctl.d/50-max-user-watches.conf ...
fs.inotify.max_user_watches = 524288
* Applying /etc/sysctl.d/50-max_user_watches.conf ...
fs.inotify.max_user_watches = 16384
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
kernel.pid_max = 4194304
* Applying /usr/lib/sysctl.d/60-libvirtd.conf ...
fs.aio-max-nr = 1048576

then, after run this command to check it's work or not

cat /proc/sys/fs/inotify/max_user_watches

output is still 16384

how to make it work?

There seems to be an issue with the naming of the file. Check your /etc/sysctl.d folder for the exact name of the file, mine was: 50_max_user_watches.conf with underscores instead of hyphens. So this should work:

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/50_max_user_watches.conf && sudo sysctl --system

@retry19
Copy link

retry19 commented Nov 19, 2020

when run this command

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/50-max-user-watches.conf && sudo sysctl --system

display output is

fs.inotify.max_user_watches=524288
* Applying /usr/lib/sysctl.d/10-manjaro.conf ...
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 524288
* Applying /etc/sysctl.d/100-manjaro.conf ...
vm.swappiness = 10
* Applying /usr/lib/sysctl.d/50-coredump.conf ...
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
fs.suid_dumpable = 2
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 2
sysctl: setting key "net.ipv4.conf.all.rp_filter": Invalid argument
net.ipv4.conf.default.accept_source_route = 0
sysctl: setting key "net.ipv4.conf.all.accept_source_route": Invalid argument
net.ipv4.conf.default.promote_secondaries = 1
sysctl: setting key "net.ipv4.conf.all.promote_secondaries": Invalid argument
net.ipv4.ping_group_range = 0 2147483647
net.core.default_qdisc = fq_codel
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
fs.protected_regular = 1
fs.protected_fifos = 1
* Applying /etc/sysctl.d/50-max-user-watches.conf ...
fs.inotify.max_user_watches = 524288
* Applying /etc/sysctl.d/50-max_user_watches.conf ...
fs.inotify.max_user_watches = 16384
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
kernel.pid_max = 4194304
* Applying /usr/lib/sysctl.d/60-libvirtd.conf ...
fs.aio-max-nr = 1048576

then, after run this command to check it's work or not

cat /proc/sys/fs/inotify/max_user_watches

output is still 16384
how to make it work?

There seems to be an issue with the naming of the file. Check your /etc/sysctl.d folder for the exact name of the file, mine was: 50_max_user_watches.conf with underscores instead of hyphens. So this should work:

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/50_max_user_watches.conf && sudo sysctl --system

oh.. i see, thanks it work for me. I'm sorry I not thorough

@ousid
Copy link

ousid commented Nov 23, 2020

Nice one!
It's Working for me, thanks

@alejandroferrin
Copy link

Hi, the commands worked but every time I restart the PC the value it comes back to 16384.

@douglara
Copy link

douglara commented Dec 9, 2020

Hi, the commands worked but every time I restart the PC the value it comes back to 16384.

Try this:

cd /etc/sysctl.d/
sudo nano 90-inotify.conf
Insert
fs.inotify.max_user_watches=524288

Update current session: sudo sysctl --system or reboot

@alejandroferrin
Copy link

Try this:

cd /ect/sysctl.d/
sudo nano 90-inotify.conf
Insert
fs.inotify.max_user_watches=524288

Update current session: sudo sysctl --system or reboot

Hi! thks for the response, I went to the sysctl.d folder and there was no 90-inofify.conf but 50-max_user_watches.conf instead. I changed te value on fs.inotify.max_user_watches = 524288 and reboot.
Good solution so far!!

@tbjgolden
Copy link
Author

@alejandroferrin - what distro, version and desktop environment are you running?
Also noticed you had a typo above 90-inofify.conf instead of 90-inotify.conf - might this have caused it?

@tbjgolden
Copy link
Author

also I think @douglara had his own typo

cd /ect/sysctl.d/ # <-- should be /etc/sysctl.d/
sudo nano 90-inotify.conf

@douglara
Copy link

also I think @douglara had his own typo

cd /ect/sysctl.d/ # <-- should be /etc/sysctl.d/
sudo nano 90-inotify.conf

Well analyzed @tbjgolden hehe thanks!

@alejandroferrin
Copy link

@alejandroferrin - what distro, version and desktop environment are you running?
Also noticed you had a typo above 90-inofify.conf instead of 90-inotify.conf - might this have caused it?

Hi, I'm using Manjaro with 5.9.11 kernel version and KDE Plasma 5.20.4 as desktop.
I think the typo was not related with the issue, as I said above I could solve the problem by changing the content in 50-max_user_watches.conf
Regards.

@tbjgolden
Copy link
Author

@alejandroferrin
Oh cool - also using Plasma!
Yeah the reason this is so painful is that Manjaro has a file 50-max_user_watches.conf preconfigured, but Arch doesn't.
The original instuctions for this for Arch was to create a 40-max_user_watches.conf but the existing config overrides it (50 > 40) on Manjaro.

Ultimately finding the existing definition in 50-max_user_watches.conf oughta do the trick 👍

@rdricco
Copy link

rdricco commented Jan 12, 2021

Worked here on Manjaro but I needed to delete the files with typo

@darshansiddu01
Copy link

How to make this change when on linux not running as root user.
I'm connecting to remote development environment using Remote-SSH extension

@cascadingstyletrees
Copy link

cascadingstyletrees commented Nov 5, 2021

How to make this change when on linux not running as root user. I'm connecting to remote development environment using Remote-SSH extension

Pretty sure you need privileged access, kernel changes generally require root, unless you have a really permissive system.

@carlosSoto2
Copy link

Works

@MelinaMontes
Copy link

It works perfect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment