- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- What is the default value of
- What is the maximum value of
The default value
fs.nr_openis 1024*1024 = 1048576 defined in kernel code. Below is the snippet from source code.
fs/file.c 27 unsigned int sysctl_nr_open __read_mostly = 1024*1024;
The maximum value of
fs.nr_openis limited to
sysctl_nr_open_maxin kernel, which is 2147483584 on x86_64.
Note: The value of "Max open files"(
ulimit -n) is limited to
In RHEL9, the default value of
fs.nr_openis way larger than what is defined by kernel.
# cat /proc/sys/fs/nr_open 1073741816
The max value gets calculated from following piece of code and assigned to
fs/file.c 27 unsigned int sysctl_nr_open __read_mostly = 1024*1024; 28 unsigned int sysctl_nr_open_min = BITS_PER_LONG; 29 /* our min() is unusable in constant expressions ;-/ */ 30 #define __const_min(x, y) ((x) < (y) ? (x) : (y)) 31 unsigned int sysctl_nr_open_max = 32 __const_min(INT_MAX, ~(size_t)0/sizeof(void *)) & -BITS_PER_LONG;
Lets evaluate this,
include/vdso/limits.h 8 #define INT_MAX ((int)(~0U >> 1)) crash> p ((int)(~0U >> 1)) $39 = 2147483647 crash> p ~(size_t)0/sizeof(void *) $40 = 2305843009213693951 include/asm-generic/bitsperlong.h 8 #ifdef CONFIG_64BIT 9 #define BITS_PER_LONG 64 <=---- 10 #else 11 #define BITS_PER_LONG 32 12 #endif /* CONFIG_64BIT */ __const_min(2147483647,2305843009213693951) & -64 crash> p 2147483647&-64 $41 = 2147483584 [max value]
The reason behind large value of
nr_openin RHEL 9 is due to following commit from systemd.
Below is demonstration on how
nr_openvalue and testing max value of
# ulimit -n 2147483584 -bash: ulimit: open files: cannot modify limit: Operation not permitted # sysctl fs.nr_open fs.nr_open = 1048576 # sysctl -w fs.nr_open=2147483584 fs.nr_open = 2147483584 # ulimit -n 2147483584 # ulimit -n 2147483584 # sysctl -w fs.nr_open=2147483585 sysctl: setting key "fs.nr_open": Invalid argument fs.nr_open = 2147483585
On RHEL 9 if system is booted with
systemd.log_level=debugwe can see that systemd modifies
# journalctl -b|grep nr_open Mar 10 01:40:34 localhost systemd: Setting 'fs/nr_open' to '2147483640'. Mar 10 01:40:34 localhost systemd: Couldn't write fs.nr_open as 2147483640, halving it. Mar 10 01:40:34 localhost systemd: Setting 'fs/nr_open' to '1073741816'. Mar 10 01:40:34 localhost systemd: Successfully bumped fs.nr_open to 1073741816 Mar 10 01:40:36 localhost systemd: Setting 'fs/nr_open' to '2147483640'. Mar 10 01:40:36 localhost systemd: Couldn't write fs.nr_open as 2147483640, halving it.
- Red Hat Enterprise Linux for x86_64
- Learn more
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.