Speaking of newer kernels, Linux v6.2-rc1 was tagged two days ago. It comes with a much faster way to count open files for a process.

Previously the only way to do this was to getdents() for /proc/<pid>/fd, which generated a dentry for every open file one the fly, and then count the number of files in the directory.

Linux v6.2 allows you to stat /proc/pid/fd and get the number of open files in the "size" field.

Counting 1 million open files: 725ms -> 0.2ms 📉

Follow

@mastodon Is there a reason to read the count other than monitoring how close something is to the fd limit?

@robryk, that's usually the main reason, same as with memory monitoring.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.