EMLINK
Linux / POSIXERRORCriticalFile SystemHIGH confidence

Too Many Links

Production Risk

Rare outside backup and deduplication tools.

What this means

EMLINK (errno 31) is returned when creating a hard link would exceed the maximum link count for a file (typically 65535 on ext4), or when creating a directory would exceed the maximum number of subdirectories a parent directory can have.

Why it happens
  1. 1Creating more than 65535 hard links to a single file on ext4
  2. 2Creating more than 65000 subdirectories in a single directory on ext4 (the parent's link count would overflow)
  3. 3Backup tools that create large numbers of hard links for deduplication
How to reproduce

Hard-link based backup tools creating too many links.

trigger — this will error
trigger — this will error
// C: link() returns EMLINK
link("source.txt", "hardlink65536.txt");
// Returns -1, errno = EMLINK

expected output

link: Too many links (EMLINK)

Fix

Split large hard-link sets across multiple directories

WHEN When backup or dedup tools create too many hard links

Split large hard-link sets across multiple directories
# Structure backup data across multiple directories:
/backup/2024-01/ → links to pool
/backup/2024-02/ → links to pool (different pool dir if needed)

Why this works

Spread hard links across multiple directories to stay within the per-inode link count limit. For very large datasets, consider filesystems with higher limits like XFS or btrfs.

Version notes
ext4

Maximum hard link count per inode is 65000 (soft) to 65535 (hard).

Sources
Official documentation ↗

Linux Programmer Manual link(2)

link(2)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors