Score:3

Why I got Failed to allocate directory watch: Too many open files?

ug flag

I tried update on 22.04

Failed to allocate directory watch: Too many open files
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:2 https://apt.releases.hashicorp.com jammy InRelease                                                         
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]                                        
Hit:4 https://deb.nodesource.com/node_18.x jammy InRelease 

sysctl fs.inotify.max_user_instances
fs.inotify.max_user_instances = 128

How should sysctl fs.inotify look like?

Raffa avatar
jp flag
Is this Ubuntu OS used for virtualization i.e. do you run virtual machines/containers on it? as this is one possible cause
Raffa avatar
jp flag
Also what does `sysctl fs.inotify.max_user_instances` return?
Richard Rublev avatar
ug flag
@Raffa Yes,i do run virtual machines/containers on it.
Score:4
jp flag

The inotify API provides a mechanism for monitoring filesystem events. Inotify can be used to monitor individual files, or to monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.

It's needed by both system and user-space applications that involve directories/files operations in order for those applications to know, confirm or fulfill their goal directories/files changes ... For example: APT when updating its cached packages information(i.e syncronizing) downloads compressed archives that it needs to wait until a close_write event is reported on those archives indicating that they have finished downloading and it is safe to proceed to extracting them (this is particularly important when a multitude of those archives are downloaded in parallel for example).

Furthermore,

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.

It need system resources to run and do its(singular form is for simplifying writing but those are actually multiple instances and multiple more watches) job … And being such a kernel subsystem and by nature makes it utilize, among other resources, the so called kernel memory which is a part of the total available system memory that is reserved for the kernel's use and kept off-limit from e.g. user-space applications and it is also limited in size ... Therefore, and out of necessity the usage of this kernel memory must be strictly managed not allowing a certain subsystem to overtake it and thus negatively affecting the system stability ... Hence, the limits imposed on inotify that you can view like so:

$ sysctl fs.inotify
fs.inotify.max_queued_events = 16384
`fs.inotify.max_user_instances` = 128
fs.inotify.max_user_watches = 65536

These limits can actually (safely in most cases) be increased if needed ... If you are seeing the error message indicating reaching the limit when you run a new application like in your case, then it's most likely that fs.inotify.max_user_instances is the one that is causing this ... You can temporarily increase it to e.g. 256 like so:

sudo sysctl -w fs.inotify.max_user_instances=256

This will take effect immediately but will be reset after reboot ... It's advised for testing the stability of the system first ... If, however, you decide that you need that set permanently and survive reboots, then you can edit /etc/sysctl.conf and add it as a new line like so:

fs.inotify.max_user_instances=256
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.