Henrik Nordström's Squid work -> Large filedescriptors on Linux 2.2
How to get many filedescriptors on Linux 2.2.X
Linux 2.2.12 + glibc 2.1.1 and later
Linux kernel 2.2.12 and later supports "unlimited" number of open files without patching. So does most of glibc-2.1.1 and later (all areas touched by Squid is safe from what I can tell, even more so in later glibc releases). But you still need to take some actions as the kernel defaults to only allow processes to use up to 1024 filedescriptors, and Squid picks up the limit at build time.
- Edit /usr/include/bits/types.h to define __FD_SETSIZE to at least the amount of filedescriptors you'd like to support.
- Before configuring Squid run "
ulimit -HSn ####" (where #### is the number of filedescriptors you need to support). Be sure to run "make clean" before configure if you have already run configure as the script might otherwise have cached the prior result.
- Configure, build and install Squid
- Make sure your script for starting Squid contains the above
ulimit command to raise the filedescriptor limit. You may also need to allow a larger port span for outgoing connections (set in /proc/sys/net/ipv4/, like in "
echo 1024 32768 > /proc/sys/net/ipv4/ip_local_port_range")
If running things as root is not an option then get your sysadmin to install a the needed ulimit command in /etc/inittscript (see man initscript), install a patched kernel where INR_OPEN in include/linux/fs.h is changed to at least the amount you need or have them install a small suid program which sets the limit. (source attached: setfilelimit.c)
Older Linux relases (2.2.10 and earlier)
- Fetch a recent version of the kernel source
- Fetch Alan Cox -ac Linux kernel patch, available on kernel.org in /pub/linux/kernel/alan/2.2/
- Unpack the sources and apply the -ac patch.
- Run "make menuconfig" from a Linux console to configure the kernel (I had some problems with "make xconfig" after applying the 2.2.10-ac10 patch.. YMM)
- Edit include/linux/posix_types.h and /usr/include/bits/types.h to define __FD_SETSIZE to at least the amount of filedescriptors you'd like to support.
- Rebuild and install the modified kernel and modules
- Set the user process limits to the number you'd like to support ("ulimit -HSn 16384")
- Rebuild Squid (make clean; ./configure ...; make install). It should pick up the limit imposed by both ulimit and FD_SETSIZE.
- Start Squid and it should now be running with more filedescriptors. Remember to put the "ulimit -HSn XXX" command in your script which starts Squid.
- It may also be required to also rebuild glibc with a higher __FD_SETSIZE to avoid any suprices from the library when running with more than 1024 filedescriptors. However as this is a fairly complicated process don't do it unless you experience some problems which may be related to this. A couple of important things (for example threads and DNS resolving) depends on the size FD_SETSIZE being larger than the highest active filedescriptor... The minimum you should do is to make sure you are using a up to date version of glibc if you do not feel comfortable with rebuilding it from source as the later version have fixed most issues with large filedescriptors (a quick audit of RedHat glibc-2.1.1-6 showed no problems in any areas Squid 2.2.X depends on, but DNS may fail for the upcoming Squid-2.3 release).
© 1999-2000 Henrik Nordström <firstname.lastname@example.org>.