Hello,

there is an updated patch, it should meets your criteria...

Martin

* The stuff eleminating SQUID_MAXFD dependencies in arrays etc.

* The directive for setting the fd limit

* Checks in comm_select_init or similar to lower Squid_MaxFD if it's
above what the select loop implementation can handle. This means
comm_select.c and comm_select_win32.c limiting Squid_MaxFD to
FD_SETSIZE. (eleminating the similar check from main.c). Some thinking
needed to get rid of comm_select dependencies.. (probably a new
comm_select_fdlimit call needed before comm_init)

* Moving the FD_SETSIZE override from squid.h to comm_select.c before
include of squid.h..

* After this SQUID_MAXFD should only be referenced from the FD_SETSIZE
override in comm_select.c.

Regards
Henrik

--- squid-2.6.STABLE1/configure.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/configure	2006-07-26 09:58:41.000000000 +0200
@@ -2970,6 +2970,34 @@
   AMDEP_FALSE=
 fi
 
+if false; then
+  USE_FD_CONFIG_TRUE=
+  USE_FD_CONFIG_FALSE='#'
+else
+  USE_FD_CONFIG_TRUE='#'
+  USE_FD_CONFIG_FALSE=
+fi
+# Check whether --enable-fd-config or --disable-fd-config was given.
+if test "${enable_fd_config+set}" = set; then
+  enableval="$enable_fd_config"
+   if test "$enableval" = "yes" ; then
+    echo "File descriptor config enabled"
+    cat >> confdefs.h <<\EOF
+#define FD_CONFIG 1
+EOF
+
+    
+
+if true; then
+  USE_FD_CONFIG_TRUE=
+  USE_FD_CONFIG_FALSE='#'
+else
+  USE_FD_CONFIG_TRUE='#'
+  USE_FD_CONFIG_FALSE=
+fi
+  fi
+
+fi
 
 
 
--- squid-2.6.STABLE1/include/autoconf.h.in.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/include/autoconf.h.in	2006-07-26 09:58:41.000000000 +0200
@@ -36,6 +36,9 @@
 /* Traffic management via "delay pools". */
 #undef DELAY_POOLS
 
+/* Filedesc managment */
+#undef FD_CONFIG
+
 /* Enable following X-Forwarded-For headers */
 #undef FOLLOW_X_FORWARDED_FOR
 
--- squid-2.6.STABLE1/configure.in.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/configure.in	2006-07-26 09:58:41.000000000 +0200
@@ -501,6 +501,16 @@
   fi
 ])
 
+AM_CONDITIONAL(USE_FD_CONFIG, false)
+AC_ARG_ENABLE(fd-config,
+[  --enable-fd-config    Enable filedesc config to configure maximal number of used filedescriptors],
+[ if test "$enableval" = "yes" ; then
+    echo "Filedesc config enabled"
+    AC_DEFINE(FD_CONFIG)
+    AM_CONDITIONAL(USE_FD_CONFIG, true)
+  fi
+])
+
 dnl This is a developer only option. Developers know how to set defines
 dnl
 dnl AC_ARG_ENABLE(mem-gen-trace,
--- squid-2.6.STABLE1/src/cf.data.pre.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/src/cf.data.pre	2006-07-26 10:05:54.000000000 +0200
@@ -5027,4 +5027,23 @@
 	or response to be rejected.
 DOC_END
 
+NAME: max_filedesc
+IFDEF: FD_CONFIG
+TYPE: int
+DEFAULT: 1024
+LOC: Config.max_filedesc
+DOC_START
+	The maximum number of open file descriptors.
+        
+	WARNING: Changes of this value isn't respected by reconfigure 
+	command. This value should be changed only if there isn't 
+	any active squid process.
+
+	NOTE: This option is only supported by system with poll()
+	or epoll(). You can set this value by --with-maxfd during 
+	compilation on system whith uses select().
+	
+	The maximum value for max_filedesc is set by --with-maxfd during
+	compilation.
+DOC_END
 EOF
--- squid-2.6.STABLE1/src/comm_poll.c.fd	2006-06-25 17:53:14.000000000 +0200
+++ squid-2.6.STABLE1/src/comm_poll.c	2006-07-26 09:58:41.000000000 +0200
@@ -152,13 +152,31 @@
 }
 
 #if DELAY_POOLS
+
+static int *slowfdarr = NULL;
+static int slowfdmax;
 static int slowfdcnt = 0;
-static int slowfdarr[SQUID_MAXFD];
+
+void
+comm_slow_fd_init(int fd_num)
+{
+    slowfdarr = xmalloc(sizeof(slowfdarr[0])*fd_num);
+    slowfdmax = fd_num;
+    slowfdcnt = 0;
+}
+
+void
+comm_slow_fd_destroy(void)
+{
+    xfree(slowfdarr);
+    slowfdarr = NULL;
+    slowfdmax = slowfdcnt = 0;
+}
 
 static void
 commAddSlowFd(int fd)
 {
-    assert(slowfdcnt < SQUID_MAXFD);
+    assert(slowfdcnt < slowfdmax);
     slowfdarr[slowfdcnt++] = fd;
 }
 
@@ -286,9 +304,9 @@
 int
 comm_select(int msec)
 {
-    struct pollfd pfds[SQUID_MAXFD];
+    struct pollfd pfds[Squid_MaxFD];
 #if DELAY_POOLS
-    char slowfds[SQUID_MAXFD];
+    char slowfds[Squid_MaxFD];
 #endif
     int fd;
     unsigned int i;
--- squid-2.6.STABLE1/src/comm_epoll.c.fd	2006-06-27 15:09:43.000000000 +0200
+++ squid-2.6.STABLE1/src/comm_epoll.c	2006-07-26 09:58:41.000000000 +0200
@@ -86,6 +86,21 @@
     safe_free(epoll_state);
 }
 
+#if DELAY_POOLS
+
+/* dummy functions... */
+void
+comm_slow_fd_init(int fd_num)
+{
+}
+
+void
+comm_slow_fd_destroy(void)
+{
+}
+
+#endif
+
 void
 commSetEvents(int fd, int need_read, int need_write)
 {
--- squid-2.6.STABLE1/src/main.c.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/src/main.c	2006-07-26 09:58:41.000000000 +0200
@@ -601,6 +601,9 @@
 #if DELAY_POOLS
 	delayPoolsInit();
 #endif
+#if DELAY_POOLS
+	comm_slow_fd_init(Squid_MaxFD);
+#endif
 	fwdInit();
     }
 #if USE_WCCP
@@ -664,8 +667,6 @@
 #endif
 
     debug_log = stderr;
-    if (FD_SETSIZE < Squid_MaxFD)
-	Squid_MaxFD = FD_SETSIZE;
 
 #ifdef _SQUID_WIN32_
     if ((WIN32_init_err = WIN32_Subsystem_Init(&argc, &argv)))
@@ -748,6 +749,8 @@
     /* Make sure the OS allows core dumps if enabled in squid.conf */
     enableCoredumps();
 
+    setMaxFD();
+
 #if TEST_ACCESS
     comm_init();
     comm_select_init();
@@ -781,7 +784,6 @@
     }
     if (!opt_no_daemon)
 	watch_child(argv);
-    setMaxFD();
 
     /* init comm module */
     comm_init();
@@ -1086,6 +1088,9 @@
 #endif
     releaseServerSockets();
     commCloseAllSockets();
+#if DELAY_POOLS
+    comm_slow_fd_destroy();
+#endif
     authenticateShutdown();
 #if USE_UNLINKD
     unlinkdClose();
--- squid-2.6.STABLE1/src/structs.h.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/src/structs.h	2006-07-26 09:58:41.000000000 +0200
@@ -805,6 +805,9 @@
 #endif
     time_t refresh_stale_window;
     int umask;
+#if FD_CONFIG
+    int max_filedesc;
+#endif
 };
 
 struct _SquidConfig2 {
--- squid-2.6.STABLE1/src/tools.c.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/src/tools.c	2006-07-26 09:58:41.000000000 +0200
@@ -757,6 +757,21 @@
 void
 setMaxFD(void)
 {
+
+/* Set up number of used filedescriptors from config file */
+/* Override the default settings Squid_MaxFD = FD_SETSIZE */
+#if FD_CONFIG
+    Squid_MaxFD = Config.max_filedesc;
+
+    /* don't exceed limit which was set during compilation */
+    if(SQUID_MAXFD < Squid_MaxFD)
+	Squid_MaxFD = SQUID_MAXFD;
+#else
+    /* don't exceed FD_SETSIZE */
+    if(FD_SETSIZE < Squid_MaxFD)
+	Squid_MaxFD = FD_SETSIZE;
+#endif
+
 #if HAVE_SETRLIMIT
     /* try to use as many file descriptors as possible */
     /* System V uses RLIMIT_NOFILE and BSD uses RLIMIT_OFILE */
--- squid-2.6.STABLE1/src/comm_select_win32.c.fd	2006-06-11 19:06:25.000000000 +0200
+++ squid-2.6.STABLE1/src/comm_select_win32.c	2006-07-26 09:58:41.000000000 +0200
@@ -34,6 +34,10 @@
 
 #include "squid.h"
 
+#if FD_CONFIG
+#error "Filedescriptor configuration isn't supported by this module!"
+#endif
+
 static int MAX_POLL_TIME = 1000;	/* see also comm_quick_poll_required() */
 
 /* STATIC */
@@ -144,13 +148,31 @@
 }
 
 #if DELAY_POOLS
+
+static int *slowfdarr = NULL;
+static int slowfdmax;
 static int slowfdcnt = 0;
-static int slowfdarr[SQUID_MAXFD];
+
+void
+comm_slow_fd_init(int fd_num)
+{
+    slowfdarr = xmalloc(sizeof(slowfdarr[0])*fd_num);
+    slowfdmax = fd_num;
+    slowfdcnt = 0;
+}
+
+void
+comm_slow_fd_destroy(void)
+{
+    xfree(slowfdarr);
+    slowfdarr = NULL;
+    slowfdmax = slowfdcnt = 0;
+}
 
 static void
 commAddSlowFd(int fd)
 {
-    assert(slowfdcnt < SQUID_MAXFD);
+    assert(slowfdcnt < slowfdmax);
     slowfdarr[slowfdcnt++] = fd;
 }
 
--- squid-2.6.STABLE1/src/comm_select.c.fd	2006-06-08 14:53:20.000000000 +0200
+++ squid-2.6.STABLE1/src/comm_select.c	2006-07-26 09:58:41.000000000 +0200
@@ -38,6 +38,10 @@
 #include <sys/select.h>
 #endif
 
+#if FD_CONFIG
+#error "Filedescriptor configuration isn't supported by this module!"
+#endif
+
 static int MAX_POLL_TIME = 1000;	/* see also comm_quick_poll_required() */
 
 #ifndef        howmany
@@ -157,13 +161,31 @@
 }
 
 #if DELAY_POOLS
+
+static int *slowfdarr = NULL;
+static int slowfdmax;
 static int slowfdcnt = 0;
-static int slowfdarr[SQUID_MAXFD];
+
+void
+comm_slow_fd_init(int fd_num)
+{
+    slowfdarr = xmalloc(sizeof(slowfdarr[0])*fd_num);
+    slowfdmax = fd_num;
+    slowfdcnt = 0;
+}
+
+void
+comm_slow_fd_destroy(void)
+{
+    xfree(slowfdarr);
+    slowfdarr = NULL;
+    slowfdmax = slowfdcnt = 0;
+}
 
 static void
 commAddSlowFd(int fd)
 {
-    assert(slowfdcnt < SQUID_MAXFD);
+    assert(slowfdcnt < slowfdmax);
     slowfdarr[slowfdcnt++] = fd;
 }
 
--- squid-2.6.STABLE1/src/squid.h.fd	2006-06-08 14:53:20.000000000 +0200
+++ squid-2.6.STABLE1/src/squid.h	2006-07-26 09:58:41.000000000 +0200
@@ -409,6 +409,10 @@
 #include "cache_snmp.h"
 #endif
 
+#if !USE_POLL && !USE_EPOLL
+#undef FD_CONFIG
+#endif
+
 #include "hash.h"
 #include "rfc1035.h"
 
--- squid-2.6.STABLE1/src/stat.c.fd	2006-07-26 09:58:41.000000000 +0200
+++ squid-2.6.STABLE1/src/stat.c	2006-07-26 09:58:41.000000000 +0200
@@ -1031,7 +1031,7 @@
     statHistEnumInit(&C->comm_icp_incoming, INCOMING_ICP_MAX);
     statHistEnumInit(&C->comm_dns_incoming, INCOMING_DNS_MAX);
     statHistEnumInit(&C->comm_http_incoming, INCOMING_HTTP_MAX);
-    statHistIntInit(&C->select_fds_hist, 256);	/* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */
+    statHistIntInit(&C->select_fds_hist, 256);	/* was Squid_MaxFD, but it is way too much. It is OK to crop this statistics */
 }
 
 /* add special cases here as they arrive */

Reply via email to