[lkml]   [2003]   [Aug]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectHelp! How to increase linux per-machine, per-user and per-process resource limits??
Hi, all,

I encounter problems of how to increase Linux sytem-wide(per-machine),
per-user and per-process resource limits, I mean, the open file limit, inode
limit, and concurrent process limit.

I'm running Redhat Linux 8.0 and a generic 2.4.20 kernel downloaded
directly from

After searched internet for related information/solution, I still can not
get a clear idea about how to do the above work correctly, or accurately.
The following are my questions, please help me to clarify/fix the problems.

1, system-wide open file limit: this limit seems controlled by the line
"#define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */" in
header file /usr/src/linux/include/linux/fs.h. But after the kernel
recompiled|installed|rebooted, we see a smaller number in

[root@ops-test1 root]# cat /proc/sys/fs/file-max
[root@ops-test1 root]#

The following is from the file

file-nr and file-max

The kernel allocates file handles dynamically, but doesn't
free them again at
this time.

The value in file-max denotes the maximum number of
file handles that the
Linux kernel will allocate. When you get a lot of error
messages about running
out of file handles, you might want to raise this limit.
The default value is
4096. To change it, just write the new number into the file:

# cat /proc/sys/fs/file-max
# echo 8192 > /proc/sys/fs/file-max
# cat /proc/sys/fs/file-max

The following is from the proc(5) manual page,

The file file-max is a system-wide limit on the number of
files for all processes. (See also setrlimit(2), which can
used by a process to set the per-process limit,
on the number of files it may open.) If you get lots of
messages about running out of file handles, try increasing

echo 100000 > /proc/sys/fs/file-max

The kernel constant NR_OPEN imposes an upper limit on the
that may be placed in file-max.

If you increase file-max, be sure to increase inode-max to
times the new value of file-max, or you will run out of

So, since I NR_OPEN is (1024*1024) in kernel source code, I should get a a
failure return when trying to input a >1048576 (=1024*1024) number into the
/proc/sys/fs/file-max, right? But actually, it works there.

[root@ops-test1 root]# uname -a
Linux 2.4.20-v5 #3 SMP Thu May 1
17:37:52 PDT 2003 i686 i686 i386 GNU/Linux
[root@ops-test1 root]# cat /proc/sys/fs/file-max
[root@ops-test1 root]# echo 104857700 >
[root@ops-test1 root]# cat /proc/sys/fs/file-max
[root@ops-test1 root]#

2, for system-wide inode limit, I don't know where it is defined. It is said
that the parameter is dynamically adjustable through file
/proc/sys/fs/inode-max, But actually, the file /proc/sys/fs/inode-max
doesn't exist at all!

The following is from proc(5) manual page as well.

The file inode-max contains the maximum number of
inodes. On some (2.4) systems, it may not be present.
value should be 3-4 times larger than the value in
since stdin, stdout and network sockets also need an inode
handle them. When you regularly run out of inodes, you need
increase this value.

[root@ops-test1 fs]# ls /proc/sys/fs/inode*
/proc/sys/fs/inode-nr /proc/sys/fs/inode-state
[root@ops-test1 fs]# cat /proc/sys/fs/inode-nr
129329 61
[root@ops-test1 fs]# cat /proc/sys/fs/inode-state
129329 61 0 0 0 0 0
[root@ops-test1 fs]#

3, for system-wide process limit, I mean, the total number of maximum
concurrently running processes, is not defined anywhere in kernel source
tree?? or not dynamically adjustable? I can not find any helpful information
on this.

4, for per-user limits, It's said that we can add related entries in
/etc/security/limits.conf for control purposes. But in this file, we can
only increase limit on open file limit and maximum processes limit. and even
worse, one question and two problem described below comes with it.Please
advice me on how to do it in a accurate way.

bash-2.05b# ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 6143
virtual memory (kbytes, -v) unlimited

4a, The default per-user maxproc limit is related to physical memory
installed, the algorithm seems coded in /usr/src/linux/kernel/fork.c, which
is attached below:

void __init fork_init(unsigned long mempages)
* The default maximum number of threads is set to a
* value: the thread structures can take up at most
* of memory.
max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) /

init_task.rlim[RLIMIT_NPROC].rlim_cur =
init_task.rlim[RLIMIT_NPROC].rlim_max =
as a consequence of the above, maxproc per user is set to 512 for machines
with 64M memory, or 2048 for 256M, 4096 for 512M, and then at last 7168 for
>=896M, where comes the number 896M?

4b, I changed the file /etc/security/limits.conf , added the following two
lines into it, setting both hard/soft limits:
* - nofile 1048576
* - nproc 1048576

But I have to reboot machine to let the newly increased limits to kick in.
Even worse is, these new limts only take effect in local sessions only! if
you login through ssh remote session, you still get the original smaller

4c, to let remote session through ssh use the newly increased limits, I
have to maunally edit file /etc/rc.d/rc script, and add the following lines
to the end:
ulimit -n 1048576
ulimit -u 1048576
Since all the booting scripts at all runlevels under /etc/rc.d/rc*.d are
started by script /etc/rc.d/rc, this fix the problem on 4b problem above,
But we need another reboot again. and I don't know whether this is a good
way to do it. Please advice.

5, For per-process open-file limit, inode limit and proc limit, I can ONLY
find some info about open-file limit, which seems controlled by a parameter
NR_FILE the same file /usr/src/linux/include/linux/fs.h, the following is
from the file /usr/src/linux/include/linux/fs.h ( the limit is increases to
8 times of original value)

* It's silly to have NR_OPEN bigger than NR_FILE, but you
can change
* the file limit at runtime and only root can increase the
* nr_file rlimit, so it's safe to set up a ridiculously
high absolute
* upper limit on files-per-process.
* Some programs (notably those using select()) may have to
* recompiled to take full advantage of the new limits..

#define NR_FILE 65536 /* this can well be larger on a
larger system */
#define NR_RESERVED_FILES 100 /* reserved for root */
#define NR_SUPER 4096

I don't know how to adjust the value on-line through /proc interface, or
even worse, I don't know where I can see the current value at all. It's
quite easy to confusion the per-process limits with per-user limits, Any
suggestions? or the per-user limits and per-process limits are the same?
while the latter seems untrue..

--Guolin Cheng

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:47    [W:0.050 / U:27.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site