7

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.

6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.