Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I notice that on a new CentOS image that I just booted up off of EC2 that the ulimit default is 1024 open files, but /proc/sys/fs/file-max is set at 761,408 and I'm wondering how these two limits work together. I'm guessing that ulimit -n is a per-user limit of number of file descriptors while /proc/sys/fs/file-max is system-wide? If that's the case, say I've logged in twice as the same user -- does each logged-in user have a 1024 limit on number of open files, or is it a limit of 1024 combined open files between each of those logged-in users?

And is there much performance impact to setting your max file descriptors to a very high number, if your system isn't ever opening very many files?

share|improve this question
    
Added tags: bash linux kernel system-resources –  Warner Mar 15 '10 at 16:56

2 Answers 2

up vote 9 down vote accepted

file-max is the maximum File Descriptors (FD) enforced on a kernel level, which cannot be surpassed by all users without increasing. The ulimit is enforced on a user level, which can be less than the file-max.

The limitation of ulimit is per unique user. So user1, regardless of how many times logged in or processes running, would be limited to 1024. It's combined.

There is no performance impact risk by increasing file-max. Modern distributions have the maximum FD set pretty high, whereas in the past it required kernel recompilation and modification to increase past 1024. I wouldn't increase system-wide unless you have a technical need.

The per-user configuration often needs tuned for serving a particular daemon be it either a database or a Web server. If you remove the limit entirely, that daemon could potentially exhaust all available system resources, which would render the system in a state of failure.

share|improve this answer
    
Is my understanding correct, that the per-user limits set using ulimit are the same for all users? Is there a way to use different values per user or not? –  Oliver May 15 '13 at 17:16
    
Yes, the settings can be set both globally and on a per user basis. –  Warner Jul 17 '13 at 13:48
    
If i get your post right, this is not true. It is per process spawned by user xy, and this is limited by the filesystem maximum defined in /etc/sysctl.conf –  Jeredepp Oct 9 '13 at 13:20
    
The ulimit limit is not per user, but per process! See unix.stackexchange.com/questions/55319/… –  Tonin Mar 28 at 15:57

The limitation of ulimit is per unique user. So user1, regardless of how many times logged in or processes running, would be limited to 1024. It's combined.

I am not sure if I completely understand the meaning of that sentence (English is not my mother tongue) If that sentence means the ulimit configuration for file descriptors is not a per-process limitation, the accepted answer (AFAIK) is wrong.

What I mean is, if some user has launched 4 processes and the ulimit configuration for FDs is 1024, each process may open 1024 FDs. The user is not going to be limited to 1024 FDs but the processes which are launched by that user.

For example:

me@superme:~$ ulimit -n
1024
me@superme:~$ lsof | grep me | wc -l
8145

Here a perl example where we reach the limit (it is a per-process limit):

#!/usr/bin/perl

$count = 0;
@filedescriptors;

while ($count <= 1024) {
    $FILE = ${count};
    open $FILE, ">", "/tmp/example$count" or die "\n\n FDs: $count $!";
    push(@filedescriptors, $FILE);
    $count ++;
}

Result:

FDs: 1021 Too many open files at ./test.pl line 8.

1021 because there were 3 open file descriptors before reaching the while loop (stdout, stdin and stderr)

Sorry if I am completely wrong or I misunderstood the answer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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