[max open file and file descriptor]
-- san2@2005.10.28
process limits <= user limits <= kernel limits
1. process limits
linux-2.4.x/include/linux/limits.h
{
NR_OPEN // max open files per a process
OPEN_MAX // max open FD number per a process, refer FD_SETSIZE
}
/usr/include/bits/types.h or /usr/include/bits/typesizes.h
{
__FD_SETSIZE
}
2. user limits
linux-2.4.x/include/linux/fs.h
{
INR_OPEN // max open files per a user, same as `ulimit -n'
}
ulimit
{
ulimit -n // max open files, same as INR_OPEN
ulimit -u // refer NR_OPEN
}
3. kernel limits
linux-2.4.x/include/linux/fs.h
{
NR_FILE // max open files at same time
}
/proc/sys/fs/file-max
{
file-max // max open files
}
4. tuning
1) /proc/sys/fs/file-max or fs.file-max in /etc/sysctl.conf file
- file-max: phycical memory(KB) / 8KB
- file-max: physical memory(KB) * 10% (recommand)
- fs.file-max setting
512M => 65536
1G => 102400
2G => 204800
4G => 409600
2) The size of `fd_set' becomes about 8KB of memory.
3) if `process limits == user limits', then
FD=16384
4) compile application
bash: export CPPFLAGS="-DFD_SETSIZE=16384"
csh: setenv CPPFLAGS "-DFD_SETSIZE=16384" |