I don’t understand the best way to set fs.inotify.max_user_watches with sysctl. In fact, I don’t understand much of what is happening here other than the fact that I need to set the number of files that can be watched by a particular process.
I believe that I can see the max number of users by running this command:
cat /proc/sys/fs/inotify/max_user_watches
My understanding is that some people suggest changing /proc/sys/fs/inotify/max_user_watches by opening /etc/sysctl.conf in an editor and adding this to it:
fs.inotify.max_user_watches=524288
Then run sudo sysctl -p to — presumably — process the changes made to the file.
Others suggest running commands like this:
sudo sysctl -w fs.inotify.max_user_instances=1024 sudo sysctl -w fs.inotify.max_user_watches=12288
I know that -w stands for write, but what is being written and where? Is it just that this command changes /proc/.../max_user_watches?
Which of the two approaches outlined above is best? I understand that 524288 and 12288 are different numbers, but I don’t understand the difference between the effect of running -p and -w.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
sysctl -w writes kernel parameter values to the corresponding keys under /proc/sys:
sudo sysctl -w fs.inotify.max_user_watches=12288
writes 12288 to /proc/sys/fs/inotify/max_user_watches. (It’s not equivalent, it’s exactly that; interested readers can strace it to see for themselves.)
sysctl -p
loads settings from a file, either /etc/sysctl.conf (the default), or whatever file is specified after -p.
The difference between both approaches, beyond the different sources of the parameters and values they write, is that -w only changes the parameters until the next reboot, whereas values stored in /etc/sysctl.conf will be applied again every time the system boots. My usual approach is to use -w to test values, then once I’m sure the new settings are OK, write them to /etc/sysctl.conf or a file under /etc/sysctl.d (usually /etc/sysctl.d/local.conf).
See the sysctl and sysctl.conf manual pages (man sysctl and man sysctl.conf on your system) for details.
Method 2
find /proc/*/fd -lname anon_inode:inotify |
cut -d/ -f3 |
xargs -I '{}' -- ps --no-headers -o '%p %U %c' -p '{}' |
uniq -c |
sort -nr
See the inotify count used.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0