1

There seems to be a hardcoded upper limit on the maximum open file descriptors (process limit) of 1048576 is that correct?

Incase this has changed recently, my version:

Linux mq981 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 13:41:29 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
0
1
cat /proc/sys/fs/nr_open

You can change it by writing to that file, it's not hardcoded.

The actual upper limit you can set it to is much larger.

6
  • Hey, that is funny; different types of integer for more or less the same. – Ljm Dullaart Jan 20 at 13:14
  • What's funny? On a 32bit platform, INT_MAX pointers ((2^31 - 1) * 4) is larger than SIZE_MAX and won't fit into an array. – Uncle Billy Jan 20 at 13:16
  • what is line 25 saying? – Peter Prographo Jan 21 at 14:44
  • How? ``` sudo echo 2000000 > /proc/sys/fs/nr_open -bash: /proc/sys/fs/nr_open: Permission denied ``` – guesty Jan 21 at 14:49
  • 1
    @guesty try sudo sh -c 'echo 2000000 > /proc/sys/fs/nr_open'. (There may be simpler ways, but I'm not using sudo, ever). Your command fails because it's your shell (running as a regular user) which handles any redirections and tries to open that file BEFORE running the sudo command. – Uncle Billy Jan 21 at 16:12
1

It is not so hard coded as you state. The maximum number for your system is

 cat /proc/sys/fs/file-max 

For me, that would be 3257198. If you are adventurous (changing kernel parameters on the fly, mmmmmm), you can change that number.

The absolute maximum is given by the fact that this is a long integer in C, and the maximum would therefore be 2147483647.

On a per process basis, the maximum is

cat /proc/sys/fs/nr_open

(on my system also your 1048576).

Technically, this is an unsigned long (see fs.h; search for unsigned long max_files; in the struct files_stat_struct. But, your number of open files per process must be below the system-wide maximum, so it should be below 2147483647 or below your cat /proc/sys/fs/file-max vaule.

2
  • That's the per-system, not the per-process limit. Go read Documentation/admin-guide/sysctl/fs.rst – Uncle Billy Jan 20 at 12:53
  • It's not true that the nr. of files opened by a process should be below sys-max. It's both that multiple file descriptors can refer to the same file handle and that privileged processes are not subject to that sys-max limit. That limit is completely irrelevant in the context of this question. – Uncle Billy Jan 20 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.