Diagnose inotify exhaustion and verify file events
A file has been written, but the directory synchronization tool does nothing. Restarting the service briefly restores normal operation, then changes start going unnoticed again. If the logs show No space left on device, first determine whether the failed operation was a file write or a file watch registration. The former may involve storage; the latter may involve inotify limits. They cannot be fixed with the same cleanup steps.
This article uses Ubuntu Server 24.04 LTS, the system-provided Python 3, and the /proc interfaces for diagnosis. After paying for a Tbps dedicated server, retrieve its credentials from the control panel and connect over SSH. Run every check inside the system where the watching application actually runs.
Identify the failing operation first
inotify delivers file and directory changes to an instance's event queue. An instance can hold multiple watches, but watching a directory is not automatically recursive: synchronization tools typically traverse the directory tree and register a separate watch for each subdirectory. When code repositories, dependency caches, and generated directories share a tree, even a handful of processes can consume a large number of watches.
First, save the complete error message, process ID, affected path, and triggering action. Then read the limits:
sysctl fs.inotify.max_user_watches \
fs.inotify.max_user_instances \
fs.inotify.max_queued_events
df -h /srv
df -i /srv
Replace /srv with the directory containing the affected path. Use df to check storage space and inodes; it cannot establish whether any inotify quota remains.
If inotify_add_watch returns ENOSPC, the watch limit for the same real user ID may have been reached, or the kernel may be unable to allocate the required resources. If inotify_init1 returns EMFILE, check both the per-user instance limit and the process's file descriptor limit. Do not increase the watch limit simply because an error occurred.
“The disk is not full” rules out only one category of causes. “The limit has already been increased” does not mean the application has retried its failed watch registrations.
Find the processes consuming watches
Run the following read-only script as an administrator with permission to inspect the target processes. It counts inotify instance references and watch entries in visible file descriptors without reading application file contents.
sudo python3 - <<'PY'
from pathlib import Path
rows = []
skipped = 0
for proc in Path("/proc").iterdir():
if not proc.name.isdigit():
continue
try:
uid = next(
line.split()[1]
for line in (proc / "status").read_text().splitlines()
if line.startswith("Uid:")
)
name = (proc / "comm").read_text().strip()
instances = 0
watches = 0
for fd in (proc / "fd").iterdir():
if "inotify" not in fd.readlink().as_posix():
continue
info = (proc / "fdinfo" / fd.name).read_text()
instances += 1
watches += sum(
line.startswith("inotify ")
for line in info.splitlines()
)
if instances:
rows.append((watches, instances, proc.name, uid, name))
except (OSError, StopIteration):
skipped += 1
print("WATCHES INSTANCE_REFS PID RUID COMMAND")
for row in sorted(rows, reverse=True):
print(*row)
print("SKIPPED_PROCESSES", skipped)
PY
Review the results by real UID, not just by the account you are currently logged in as. Services sharing an account compete for the same per-user quota. In container environments, also consider user namespace mappings when determining ownership: identical usernames inside containers do not necessarily represent the same host identity.
These numbers are diagnostic clues, not an exact accounting ledger. Inherited or duplicated descriptors may reference the same instance, so adding them together can double-count usage. Process exits and permission restrictions can also leave gaps. Check the skipped-process count reported by the script, inspect the main suspects again, and record when the sample was taken.
Narrow the scope before raising limits
Start with the tool's own recursive scope and exclusion rules. Dependency download directories, old build output, caches, and backup copies should not be scanned indiscriminately if they are not involved in synchronization or hot reload. Exclusions must match the application's requirements; do not exclude genuine input directories merely to reduce the count.
Next, check whether duplicate watching processes are running for the same task. Stop only instances confirmed to be redundant, rather than terminating services in bulk by process name. Record watch counts and application behavior before and after the changes to confirm that the reduction actually comes from narrowing the scope.
If the legitimate directory tree still exceeds the budget, increase the relevant limit in a controlled way. The following interactive commands save the original value and ask for a new limit that you have assessed beforehand:
old=$(sysctl -n fs.inotify.max_user_watches)
printf 'Original watches limit: %s\n' "$old"
read -r -p 'New watches limit: ' new
if [[ "$new" =~ ^[1-9][0-9]*$ ]]; then
sudo sysctl -w "fs.inotify.max_user_watches=$new"
fi
The new value should cover the actual directory count with room for growth, while you monitor kernel memory pressure. The quota does not reserve all that memory in advance, but raising it increases the amount that can be allocated. Do not copy an arbitrary large number unrelated to your workload, or change all three parameters at once and lose track of cause and effect.
Once the temporary change has been verified, write the confirmed value to a separate /etc/sysctl.d/60-file-watch.conf file. Rolling back requires restoring both the running value and the persistent configuration. Deleting the configuration file does not automatically lower the current setting.
Verify events with real file operations
First, have the application retry the watch registrations that previously failed. If necessary, restart only the relevant watching service. Then perform a complete lifecycle test in a test directory already covered by the watch scope:
testdir=$(mktemp -d /srv/watch-input/.watch-check.XXXXXX)
printf 'first\n' > "$testdir/input.txt"
printf 'second\n' >> "$testdir/input.txt"
mv "$testdir/input.txt" "$testdir/renamed.txt"
rm "$testdir/renamed.txt"
rmdir "$testdir"
Before running the commands, confirm that /srv/watch-input is an approved test location. If the tool takes time to register a new directory, wait for registration to finish before performing the file operations. This avoids mistaking a registration race for a quota problem.
Judge success by the application's results, not by demanding one notification for every system call. Adjacent events of the same type may be coalesced, and editors may save through a temporary file followed by a rename. A synchronization tool should ultimately reflect the correct contents; a hot-reload application should handle the file that actually replaces the original, rather than recognizing only writes to the original path.
Also check whether the application recognizes IN_Q_OVERFLOW. A queue overflow means events have already been lost. Continuing to read the remaining events cannot reconstruct the full state; a directory rescan or an equivalent consistency-recovery mechanism is required. Increasing max_queued_events affects only instances created afterward and cannot recover notifications already lost.
Keep evidence for follow-up verification
After making changes, save the original and final settings, the main consuming processes, the exclusion rules, and the test results. Check again after one complete real workload cycle. A running process does not prove its watches are still effective, and continuously growing usage may indicate that the application is not releasing obsolete watches.
The final check has four parts: registration errors no longer occur; the watch count matches the directory tree's scale; creation, appending, renaming, and deletion produce the correct application results; and a rescan mechanism is available after events are lost from the queue. If only the first three conditions are met, a burst of writes can still leave synchronization permanently out of step.
The goal is not to “raise the limit until the errors stop.” It is to establish an explainable watch budget and demonstrate that file changes reach the application's processing logic.
Frequently asked questions
Does No space left on device during watch registration require disk cleanup?
Not necessarily. When inotify_add_watch returns ENOSPC, check watch usage for the real user ID and max_user_watches, while also considering kernel resource allocation failure. Disk cleanup addresses the problem only when writes are actually constrained by disk space.
Will increasing an inotify limit restore watching automatically?
Not reliably. The application may need to retry failed registrations or restart its watcher. After IN_Q_OVERFLOW, it must rescan directories to rebuild consistent state before validating fresh changes.
AMD EPYC 7543P Dedicated Server
From $463/mo