Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a reasonable amount of inotify watches with Linux?

I am working on a daemon that monitors file events via inotify to trigger various types of events when files are accessed. I have read that watches are a little expensive, because the Kernel is storing the full path name of every file being watched.

How many watches would be too many?

Edit: Mostly, I'm wondering .. have you ever seen a noticeable performance hit, if so, at how many watches did it happen? Yes, I have to monitor / recursively (however its a minimal bootstrapped system).

like image 527
Tim Post Avatar asked Feb 11 '09 07:02

Tim Post


People also ask

What is inotify watch limit?

inotify requires kernel resources (memory and processor) for each file it tracks. As a result, the Linux kernel limits the number of file watchers that each user can register. The default settings vary according to the host system distribution; on Ubuntu 20.04 LTS, the default limit is 8,192 watches per instance.

What is inotify in Linux?

inotify (inode notify) is a Linux kernel subsystem created by John McCutchan, which monitors changes to the filesystem, and reports those changes to applications. It can be used to automatically update directory views, reload configuration files, log changes, backup, synchronize, and upload.

What is Max_user_instances?

max_user_instances: This is the maximum number of inotify instances allowed for each user. Most processes will only create a single instance but some may create multiple. This value defaults to 128 for most distributions.


2 Answers

AFAIK the kernel isn't storing the pathname, but the inode. Nevertheless, there are 540 bytes per Watch on a 32bit system. Double as much on 64bit.

I know from Lsyncd (maybe you want to check that out?) people who have a million watches. It just eats a Gigabyte of memory.

like image 65
axkibe Avatar answered Sep 30 '22 23:09

axkibe


You can find the system limits by reading /proc/sys/fs/inotify/max_user_instances (maximum number of inotify "objects") and /proc/sys/fs/inotify/max_user_watches (maximum number of files watched), so if you exceed those numbers, it's too many ;-) The maximum number of watches is usually several tens of thousands or higher - on my system, 262143 - which is probably more than you'd ever need unless you're trying to watch every file in a file system, but you shouldn't be doing that. I would say, just try not to use more inotify watches than you need to, and don't worry about it unless you notice a significant decrease in performance.

like image 41
David Z Avatar answered Sep 30 '22 22:09

David Z