Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The limit of ulimit -Hn

Tags:

linux

ulimit

Using trial and error, I've found the maximum number I can give to ulimit -Hn without getting error is 1048576. Where does that number come from? My sys.fs.file-max is 20000500 (20 million).

like image 441
Yuri Geinish Avatar asked Sep 02 '25 06:09

Yuri Geinish


2 Answers

Actually, this limit can be increased. Set fs.nr_open=5242880 in /etc/sysctl.conf, run sysctl -p and login again. Your limit is now 5 million! Set both this and file-max.

like image 172
user5057802 Avatar answered Sep 04 '25 19:09

user5057802


Actually, this is hardcoded in Linux kernel, in fs/file.c:

int sysctl_nr_open __read_mostly = 1024*1024;

and is equal to just the number you specified.

Related commits that tried to make it infinite:

  • https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=0c2d64fb6cae9aae480f6a46cfe79f8d7d48b59f
  • https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=60fd760fb9ff7034360bab7137c917c0330628c2

Looks like it hasn't been touched ever since.

like image 43
rr- Avatar answered Sep 04 '25 20:09

rr-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!