Skip to content

Instantly share code, notes, and snippets.

@obeleh
Last active April 28, 2022 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obeleh/683fdc7d5572d791ac74e311ea010cce to your computer and use it in GitHub Desktop.
Save obeleh/683fdc7d5572d791ac74e311ea010cce to your computer and use it in GitHub Desktop.
Max Open Files

Unfortunately this is still in a state of trial and error. What I can describe are the steps that I took to get it work and the steps that I took to validate it works:

Source articles for this article:

First off... There are multiple levels where you can specify the maximum nr of open files:

  • Based on user
  • Soft limit / hard limit
  • Based on process

As the user:

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 509342
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536     # <-----------
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 509342
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

And based on the process:

ps | grep kabisa # and take the correct PID
cat /proc/<pid>/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             509342               509342               processes
Max open files            65535                65535                files          # <----------------
Max locked memory         16777216             16777216             bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       509342               509342               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

As long as this doesn't give a high enough number it's not going to work

Several ways to set the max open files. I don't know which one is not necessary. I know at least of 1 that is necessary.

/etc/sysctl.conf

sudo vim /etc/sysctl.conf

Add the following line to it

fs.file-max = 65535

And then run

sudo sysctl -p

/etc/security/limits.conf

sudo vim /etc/security/limits.conf

Add the following lines to it

*    soft nofile 65536
*    hard nofile 65536
kabisa soft nofile 65536
kabisa hard nofile 65536
root soft nofile 65536
root hard nofile 65536

/etc/pam.d/common-session

sudo vim /etc/pam.d/common-session

Add the following line

session required pam_limits.so

/etc/systemd/user.conf

sudo vim /etc/systemd/user.conf

Add the following line

DefaultLimitNOFILE=65535

/etc/systemd/system.conf

Without this one it didn't work!

sudo vim /etc/systemd/system.conf

Add the following line

DefaultLimitNOFILE=65535

Now reboot and check the proc filesystem for the process limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment