containerd 1.7 Gives Containers a Billion-File Limit, So Code Sized by It Can Exhaust a Node's RAM

Kubernetes Linux

A process inherits its open-files limit (RLIMIT_NOFILE) from its parent, and containers are no exception: a container's processes start with the limits of the containerd service that launched them. containerd 1.7's systemd unit sets LimitNOFILE=infinity, which systemd turns into the kernel's fs.nr_open, 1073741816. So every container on such a node starts with a limit of about a billion file descriptors, soft and hard.

Most programs never notice: the limit is a ceiling, not an allocation. The trouble starts with code that sizes a table by the limit, one slot per possible descriptor. With the usual 1024 that's a few kilobytes; with a billion it's tens of gigabytes, allocated in seconds.

What It Looks Like

On my GPU node (15 GiB RAM, no swap, as Kubernetes nodes usually run), the full nvidia-smi inside a Debian container connected to nvidia-persistenced for the persistence-mode column, read the open-files limit, and mapped about 54 GB. The kernel didn't kill it in time. The node thrashed instead:

  • ping still answered (the kernel was fine), SSH timed out during the banner, the kubelet stopped reporting and the node went NotReady;
  • no kernel trace at all: nothing was stuck or spinning in the kernel, so lockup and hung-task detectors had nothing to report;
  • the output stopped right after the table header, which made it look like a GPU hang.

nvidia-smi -L never touched that path, and the same command on the host ran with the host's usual limits. NVIDIA has acknowledged the nvidia-persistenced side of the bug and suggests a lower hard limit (524288) until a fixed driver ships.

The Fix

Give containerd the same limits as any other service, with a systemd drop-in, then restart it:

# /etc/systemd/system/containerd.service.d/10-limitnofile.conf
[Service]
LimitNOFILE=1024:524288
  • Soft 1024, hard 524288: programs that need more descriptors raise their own soft limit up to the hard one, as Go programs do automatically.
  • Running containers keep their old limit until they're recreated; containerd's unit uses KillMode=process, so the restart doesn't stop them.
  • containerd 2.x removed the explicit LimitNOFILE from its unit, so containers get systemd's defaults.
  • Check from a new container: ulimit -Sn; ulimit -Hn.

References

Review cards

Flashcard Why does a container on a containerd 1.7 node start with an open-files limit of about a billion?

Containers inherit containerd's limits, and its systemd unit sets LimitNOFILE=infinity, which systemd turns into the kernel's fs.nr_open (1073741816).

Flashcard How can a high open-files limit use up a node's RAM when no file is opened?

Some code allocates a table with one slot per possible descriptor, sized from the limit. At a billion descriptors that's tens of gigabytes, allocated at once.

Quiz A node answers ping, SSH times out at the banner, and no kernel trace or lockup panic appears. Which cause fits best?
  • A GPU stuck on the PCIe bus with the CPUs spinning in the driver
  • Memory exhaustion without swap: user space thrashes while the kernel still runs
  • A kernel panic that rebooted the node

A spinning kernel would trip the lockup detector; a panic would reboot. Thrashing leaves the kernel alive and user space starved, with nothing to log.

Flashcard What does the containerd drop-in `LimitNOFILE=1024:524288` change, and for which containers?

Soft limit 1024 and hard limit 524288, like other services. Only containers created after containerd restarts get it; running ones keep the old limit until recreated.