Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Linux - set maximum open files to unlimited. Possible?

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.

like image 217
Dave Avatar asked Jul 31 '09 14:07

Dave


People also ask

What is the maximum number of open files in Linux?

This procedure specifies the open-file limit on Linux or Unix platforms. The open-file limit is a setting that controls the maximum number of open files for individual users (such as non-root users). The default open-file limit is typically 1024.

How many open files limit set on user level Linux?

ulimit command :ulimit -n –> It will display number of open files limit. ulimit -c –> It display the size of core file. umilit -u –> It will display the maximum user process limit for the logged in user. ulimit -f –> It will display the maximum file size that the user can have.


2 Answers

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.

like image 109
mark4o Avatar answered Oct 23 '22 10:10

mark4o


Try the line

<domain>    -

replacing <domain> with the username, in the simplest case.

The limits.conf man page says

-
    for enforcing both soft and hard resource limits together.

    Note, if you specify a type of '-' but neglect to supply the
    item and value fields then the module will never enforce any
    limits on the specified user/group etc. .
like image 25
serv-inc Avatar answered Oct 23 '22 09:10

serv-inc