views:

3089

answers:

2

Is it possible to set the maximum number of open files to some "infinite" value or must it be a number?

I had a requirement to set the descriptor limit for a daemon user to be "unlimited" and I'm trying to determine if that's possible or how to do it. I've seen some mailing lists refer to a "max" value that can be used (as in: "myuser hard nofile max", but so far the man pages and references I've consulted don't back that up.

If I can't use 'max' or similar, I'd like to know how to determine what the max number of files is (theoretically) so I have some basis for whatever number I pick. I don't want to use 100000000 or something if there's a more reasonable way to get an upper bound.

I'm using RHEL 5 if it's important.

Update: I'm an idiot when it comes to writing questions. Ideally I'd like to do this in the limits.conf file (which is where "max" would come from). Does that change any answers?


Thanks for the comments. This is for a JBOSS instance and not a daemon I'm writing so I don't know if setrlimit() is useful to me. However, Jefromi - I do like the definition of Infinity :) I saw a post that suggests a file descriptor is "two shorts and a pointer" so I should be able to calculate the approximate upper bound.

+1  A: 

http://www.techiesabode.com/article/read_article_w.php?article_id=2

This link has contradictory viewpoints, but at least one poster says the limit can be reset on the fly. Of course you have to remember that a computer can't have an "infinite" number of files open due to finite memory.

Arthur Kalliokoski
Yes, there is a very solid upper limit here: the amount of memory divided by the size of a file descriptor. You can't come any closer to unlimited than that.
Jefromi
Another limit is imposed by the fact that the descriptor has a fixed width in memory. I am not sure which of the two limits you'd hit first, though.
Sinan Taifour
Also, the hard-limit can only be increased if you run as the privileged (root) user. The default hard limit for max open file-descriptors is 1024.
Kjetil Jorgensen
+4  A: 

POSIX allows you to set the RLIMIT_NOFILE resource limit to RLIM_INFINITY using setrlimit(). What this means is that the system will not enforce this resource limit. Of course, you will still be limited by the implementation (e.g. MAXINT) and any other resource limitations (e.g. available memory).

Update: RHEL 5 has a maximum value of 1048576 (220) for this limit (NR_OPEN in /usr/include/linux/fs.h), and will not accept any larger value including infinity, even for root. So on RHEL 5 you can use this value in /etc/security/limits.conf and that is as close as you are going to get to infinity.

Not long ago a Linux kernel patch was applied to allow this limit to be set to infinity, however it has since been reverted as a result of unintended consequences.

mark4o