Stop apps from choking on too many open files
Performance Tuning & Kernel Parameters (Sysctl)
Stop apps from choking on too many open files
🧩 The Challenge
Ever had an app start spitting out “Too many open files” errors, even when `df -h` tells you there’s plenty of space? Happens to the best of us. That server’s not out of disk, it’s out of *filing cabinets* for all those connections and files.
💡 The Fix
Bumping up the kernel’s global file descriptor limit usually fixes this. It’s a quick `sysctl` change that prevents your services from dying under load.
# Check current limit
sysctl fs.file-max
# Increase limit (e.g., to 1,048,576)
sysctl -w fs.file-max=1048576
# Make permanent (add to /etc/sysctl.d/99-myapp.conf or /etc/sysctl.conf)
echo "fs.file-max = 1048576" | sudo tee /etc/sysctl.d/99-myapp.conf
sysctl -p /etc/sysctl.d/99-myapp.conf
⚙️ Why It Works
Every file, every socket connection, every pipe counts as a file descriptor to the kernel. Hit the system-wide maximum, and new requests simply can’t get through, regardless of per-process limits. Raising this number gives the kernel more breathing room.
🚀 Pro-Tip: Don’t forget `ulimit -n` for *individual processes*. This `sysctl` sets the system’s ceiling.
Linux Tips & Tricks | © ngelinux.com | 9/15/2026
