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.

  1. Edit /usr/include/bits/types.h to define __FD_SETSIZE to at least the amount of filedescriptors you'd like to support.
  2. 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.
  3. Configure, build and install Squid
  4. 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)

  1. Fetch a recent version of the kernel source
  2. Fetch Alan Cox -ac Linux kernel patch, available on kernel.org in /pub/linux/kernel/alan/2.2/
  3. Unpack the sources and apply the -ac patch.
  4. 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)
  5. 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.
  6. Rebuild and install the modified kernel and modules
  7. Set the user process limits to the number you'd like to support ("ulimit -HSn 16384")
  8. Rebuild Squid (make clean; ./configure ...; make install). It should pick up the limit imposed by both ulimit and FD_SETSIZE.
  9. 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.
  10. 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 <hno@squid-cache.org>.

Squid Now! Cache Now! Valid HTML 4.0! SourceForge