1 --- squid-2.5.STABLE12/configure.in.fdc 2005-10-22 11:56:01.000000000 +0200
2 +++ squid-2.5.STABLE12/configure.in 2005-12-06 14:07:43.000000000 +0100
7 +AM_CONDITIONAL(USE_FD_CONFIG, false)
8 +AC_ARG_ENABLE(fd-config,
9 +[ --enable-fd-config Enable filedesc config to limit bandwidth usage],
10 +[ if test "$enableval" = "yes" ; then
11 + echo "Filedesc config enabled"
12 + AC_DEFINE(FD_CONFIG)
13 + AM_CONDITIONAL(USE_FD_CONFIG, true)
17 dnl This is a developer only option. Developers know how to set defines
19 dnl AC_ARG_ENABLE(mem-gen-trace,
20 --- squid-2.5.STABLE12/include/autoconf.h.in.fdc 2005-09-13 02:12:34.000000000 +0200
21 +++ squid-2.5.STABLE12/include/autoconf.h.in 2005-12-06 14:07:43.000000000 +0100
26 + * Filedesc managment
31 * If you want to log User-Agent request header values, define this.
32 * By default, they are written to useragent.log in the Squid log
34 --- squid-2.5.STABLE12/acconfig.h~ 2004-06-01 10:34:19.000000000 +0200
35 +++ squid-2.5.STABLE12/acconfig.h 2006-03-05 02:00:21.000000000 +0100
40 + * Filedesc managment
45 * If you want to log User-Agent request header values, define this.
46 * By default, they are written to useragent.log in the Squid log
48 --- squid-2.5.STABLE12/src/cf.data.pre.fdc 2005-12-06 14:07:43.000000000 +0100
49 +++ squid-2.5.STABLE12/src/cf.data.pre 2005-12-06 14:07:43.000000000 +0100
50 @@ -4161,4 +4161,13 @@
51 If set to "off" then such HTTP errors will cause the request
52 or response to be rejected.
59 +LOC: Config.max_filedesc
61 + The maximum number of open file descriptors.
64 --- squid-2.5.STABLE12/src/tools.c.fdc 2005-12-06 14:07:43.000000000 +0100
65 +++ squid-2.5.STABLE12/src/tools.c 2005-12-06 14:09:02.000000000 +0100
67 if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
68 debug(50, 0) ("setrlimit: RLIMIT_NOFILE: %s\n", xstrerror());
70 - rl.rlim_cur = Squid_MaxFD;
71 + rl.rlim_max = rl.rlim_cur = SQUID_NUMFD;
73 if (rl.rlim_cur > rl.rlim_max)
74 - Squid_MaxFD = rl.rlim_cur = rl.rlim_max;
75 + rl.rlim_cur = rl.rlim_max;
77 if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
78 snprintf(tmp_error_buf, ERROR_BUF_SZ,
79 "setrlimit: RLIMIT_NOFILE: %s", xstrerror());
81 if (getrlimit(RLIMIT_OFILE, &rl) < 0) {
82 debug(50, 0) ("setrlimit: RLIMIT_NOFILE: %s\n", xstrerror());
84 - rl.rlim_cur = Squid_MaxFD;
85 + rl.rlim_max = rl.rlim_cur = SQUID_NUMFD;
87 if (rl.rlim_cur > rl.rlim_max)
88 - Squid_MaxFD = rl.rlim_cur = rl.rlim_max;
89 + rl.rlim_cur = rl.rlim_max;
91 if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
92 snprintf(tmp_error_buf, ERROR_BUF_SZ,
93 "setrlimit: RLIMIT_OFILE: %s", xstrerror());
94 --- squid-2.5.STABLE12/src/structs.h.fdc 2005-09-03 11:14:43.000000000 +0200
95 +++ squid-2.5.STABLE12/src/structs.h 2005-12-06 14:07:43.000000000 +0100
97 char *store_dir_select_algorithm;
98 int sleep_after_fork; /* microseconds */
99 external_acl *externalAclHelperList;
105 struct _SquidConfig2 {
106 --- /dev/null 2005-12-06 14:01:02.632036776 +0100
107 +++ squid-2.5.STABLE12/src/bit_array.h 2005-12-06 14:07:43.000000000 +0100
111 +#ifndef __BIT_ARRAY_H__
112 +#define __BIT_ARRAY_H__
114 +#if !BIT_ARRAY_ACTIVE
116 +#define BIT_ARRAY fd_set
117 +#define BA_INIT(arr,len)
118 +#define BA_FREE(arr)
120 +#define BA_ZERO(arr) FD_ZERO(&arr)
121 +#define BA_SET(fd,arr) FD_SET(fd,&arr)
122 +#define BA_CLR(fd,arr) FD_CLR(fd,&arr)
123 +#define BA_ISSET(fd,arr) FD_ISSET(fd,&arr)
127 +typedef struct _BIT_ARRAY {
136 +#define BA_INIT(arr,lenght) \
138 + int i,tmp = sizeof((arr).p_pool[0])*8; \
140 + for(i = 2, (arr).base_shift = 1; i < tmp; i *= 2) \
141 + (arr).base_shift++; \
142 + (arr).offset_mask = (i-1); \
144 + (arr).len = lenght / (sizeof((arr).p_pool[0])*8) + 1; \
145 + (arr).p_pool = xmalloc(sizeof((arr).p_pool[0])*(arr).len); \
149 +#define BA_FREE(arr) \
151 + if((arr).p_pool) { \
152 + xfree((arr).p_pool); \
153 + (arr).p_pool = NULL; \
159 +#define BA_ZERO(arr) { memset((arr).p_pool, 0, sizeof((arr).p_pool[0])*(arr).len); }
160 +#define BA_SET(fdsp, arr) { (arr).p_pool[(fdsp)>>(arr).base_shift]|=(0x1<<((fdsp)&(arr).offset_mask)); }
161 +#define BA_CLR(fdsp, arr) { (arr).p_pool[(fdsp)>>(arr).base_shift]&=(~(0x1<<((fdsp)&(arr).offset_mask))); }
162 +#define BA_ISSET(fdsp, arr) ((arr).p_pool[(fdsp)>>(arr).base_shift]&(0x1<<((fdsp)&(arr).offset_mask)))
164 +#endif // BIT_ARRAY_ACTIVE
166 +#endif //__BIT_ARRAY_H__
167 --- squid-2.5.STABLE12/src/fd.c.fdc 2003-12-14 13:30:36.000000000 +0100
168 +++ squid-2.5.STABLE12/src/fd.c 2005-12-06 14:07:43.000000000 +0100
173 - assert(fd < Squid_MaxFD);
174 + assert(fd < SQUID_NUMFD);
175 if (fd > Biggest_FD) {
177 * assert that we are not closing a FD bigger than
182 - for (i = 0; i < Squid_MaxFD; i++) {
183 + for (i = 0; i < SQUID_NUMFD; i++) {
191 - return Squid_MaxFD - Number_FD - Opening_FD;
192 + return SQUID_NUMFD - Number_FD - Opening_FD;
196 @@ -204,10 +204,10 @@
198 * Calculate a new reserve, based on current usage and a small extra
200 - new = Squid_MaxFD - Number_FD + XMIN(25, Squid_MaxFD / 16);
201 + new = SQUID_NUMFD - Number_FD + XMIN(25, SQUID_NUMFD / 16);
202 if (new <= RESERVED_FD)
204 - x = Squid_MaxFD - 20 - XMIN(25, Squid_MaxFD / 16);
205 + x = SQUID_NUMFD - 20 - XMIN(25, SQUID_NUMFD / 16);
207 /* perhaps this should be fatal()? -DW */
208 debug(51, 0) ("WARNING: This machine has a serious shortage of filedescriptors.\n");
209 --- squid-2.5.STABLE12/src/mem.c.fdc 2001-09-07 20:02:45.000000000 +0200
210 +++ squid-2.5.STABLE12/src/mem.c 2005-12-06 14:07:43.000000000 +0100
211 @@ -224,13 +224,13 @@
212 memDataInit(MEM_HTTP_HDR_CONTENT_RANGE, "HttpHdrContRange", sizeof(HttpHdrContRange), 0);
213 memDataInit(MEM_INTLIST, "intlist", sizeof(intlist), 0);
214 memDataInit(MEM_MEMOBJECT, "MemObject", sizeof(MemObject),
217 memDataInit(MEM_MEM_NODE, "mem_node", sizeof(mem_node), 0);
218 memDataInit(MEM_NETDBENTRY, "netdbEntry", sizeof(netdbEntry), 0);
219 memDataInit(MEM_NET_DB_NAME, "net_db_name", sizeof(net_db_name), 0);
220 memDataInit(MEM_RELIST, "relist", sizeof(relist), 0);
221 memDataInit(MEM_REQUEST_T, "request_t", sizeof(request_t),
224 memDataInit(MEM_STOREENTRY, "StoreEntry", sizeof(StoreEntry), 0);
225 memDataInit(MEM_WORDLIST, "wordlist", sizeof(wordlist), 0);
226 memDataInit(MEM_CLIENT_INFO, "ClientInfo", sizeof(ClientInfo), 0);
227 --- squid-2.5.STABLE12/src/comm_select.c.fdc 2003-05-11 19:30:13.000000000 +0200
228 +++ squid-2.5.STABLE12/src/comm_select.c 2005-12-06 14:07:43.000000000 +0100
231 static struct timeval zero_tv;
233 -static fd_set global_readfds;
234 -static fd_set global_writefds;
236 static int nwritefds;
237 +static BIT_ARRAY global_readfds;
238 +static BIT_ARRAY global_writefds;
241 * Automatic tuning for incoming requests:
242 @@ -171,13 +171,39 @@
248 +static int *slowfdarr = NULL;
249 +static int slowfdmax;
251 +static int slowfdarr[SQUID_NUMFD];
252 +static int slowfdmax = SQUID_NUMFD;
255 static int slowfdcnt = 0;
256 -static int slowfdarr[SQUID_MAXFD];
260 +comm_slow_fd_init(int fd_num)
262 + slowfdarr = xmalloc(sizeof(slowfdarr[0])*fd_num);
263 + slowfdmax = fd_num;
268 +comm_slow_fd_destroy(void)
272 + slowfdmax = slowfdcnt = 0;
277 commAddSlowFd(int fd)
279 - assert(slowfdcnt < SQUID_MAXFD);
280 + assert(slowfdcnt < slowfdmax);
281 slowfdarr[slowfdcnt++] = fd;
288 - struct pollfd pfds[SQUID_MAXFD];
290 + struct pollfd *pfds = NULL;
292 + struct pollfd pfds[SQUID_NUMFD];
302 static time_t last_timeout = 0;
303 double timeout = current_dtime + (msec / 1000.0);
305 + pfds = xmalloc(sizeof(pfds[0])*SQUID_NUMFD);
308 + BA_INIT(slowfds,SQUID_NUMFD);
311 #if !ALARM_UPDATES_TIME
314 /* Handle any fs callbacks that need doing */
320 if (commCheckICPIncoming)
321 comm_poll_icp_incoming();
325 events |= POLLRDNORM;
326 - FD_SET(i, &slowfds);
327 + BA_SET(i, slowfds);
334 assert(shutting_down);
341 return COMM_SHUTDOWN;
346 debug(5, 0) ("comm_poll: poll failure: %s\n", xstrerror());
347 assert(errno != EINVAL);
358 if (NULL == (hdl = F->read_handler))
361 - else if (FD_ISSET(fd, &slowfds))
362 + else if (BA_ISSET(fd, slowfds))
366 @@ -518,10 +566,22 @@
368 statCounter.select_time += (current_dtime - start);
378 while (timeout > current_dtime);
379 debug(5, 8) ("comm_poll: time out: %ld.\n", (long int) squid_curtime);
399 struct timeval poll_time;
400 double timeout = current_dtime + (msec / 1000.0);
403 + BA_INIT(slowfds,SQUID_NUMFD);
406 #if !ALARM_UPDATES_TIME
409 start = current_dtime;
415 /* Handle any fs callbacks that need doing */
421 - FD_SET(fd, &slowfds);
422 + BA_SET(fd, slowfds);
428 if (nreadfds + nwritefds == 0) {
429 assert(shutting_down);
433 return COMM_SHUTDOWN;
435 if (msec > MAX_POLL_TIME)
437 debug(50, 0) ("comm_select: select failure: %s\n",
439 examine_select(&readfds, &writefds);
447 if (NULL == (hdl = F->read_handler))
450 - else if (FD_ISSET(fd, &slowfds))
451 + else if (BA_ISSET(fd, slowfds))
455 @@ -901,10 +966,16 @@
457 statCounter.select_time += (current_dtime - start);
464 while (timeout > current_dtime);
465 debug(5, 8) ("comm_select: time out: %d\n", (int) squid_curtime);
472 @@ -950,8 +1021,12 @@
473 cachemgrRegister("comm_incoming",
474 "comm_incoming() stats",
475 commIncomingStats, 0, 1);
476 - FD_ZERO(&global_readfds);
477 - FD_ZERO(&global_writefds);
479 + BA_INIT(global_readfds,SQUID_NUMFD);
480 + BA_INIT(global_writefds,SQUID_NUMFD);
482 + BA_ZERO(global_readfds);
483 + BA_ZERO(global_writefds);
484 nreadfds = nwritefds = 0;
490 debug(5, 0) ("examine_select: Examining open file descriptors...\n");
491 - for (fd = 0; fd < Squid_MaxFD; fd++) {
492 + for (fd = 0; fd < SQUID_NUMFD; fd++) {
495 tv.tv_sec = tv.tv_usec = 0;
496 @@ -1085,11 +1160,11 @@
498 commUpdateReadBits(int fd, PF * handler)
500 - if (handler && !FD_ISSET(fd, &global_readfds)) {
501 - FD_SET(fd, &global_readfds);
502 + if (handler && !BA_ISSET(fd, global_readfds)) {
503 + BA_SET(fd, global_readfds);
505 - } else if (!handler && FD_ISSET(fd, &global_readfds)) {
506 - FD_CLR(fd, &global_readfds);
507 + } else if (!handler && BA_ISSET(fd, global_readfds)) {
508 + BA_CLR(fd, global_readfds);
512 @@ -1097,11 +1172,11 @@
514 commUpdateWriteBits(int fd, PF * handler)
516 - if (handler && !FD_ISSET(fd, &global_writefds)) {
517 - FD_SET(fd, &global_writefds);
518 + if (handler && !BA_ISSET(fd, global_writefds)) {
519 + BA_SET(fd, global_writefds);
521 - } else if (!handler && FD_ISSET(fd, &global_writefds)) {
522 - FD_CLR(fd, &global_writefds);
523 + } else if (!handler && BA_ISSET(fd, global_writefds)) {
524 + BA_CLR(fd, global_writefds);
528 --- squid-2.5.STABLE12/src/globals.h.fdc 2005-06-14 00:26:21.000000000 +0200
529 +++ squid-2.5.STABLE12/src/globals.h 2005-12-06 14:07:43.000000000 +0100
531 extern int NDnsServersAlloc; /* 0 */
532 extern int NHttpSockets; /* 0 */
533 extern int RESERVED_FD;
534 -extern int Squid_MaxFD; /* SQUID_MAXFD */
535 extern int config_lineno; /* 0 */
536 extern int debugLevels[MAX_DEBUG_SECTIONS];
537 extern int do_mallinfo; /* 0 */
538 --- squid-2.5.STABLE12/src/ident.c.fdc 2001-04-14 02:03:23.000000000 +0200
539 +++ squid-2.5.STABLE12/src/ident.c 2005-12-06 14:07:43.000000000 +0100
543 ident_hash = hash_create((HASHCMP *) strcmp,
544 - hashPrime(Squid_MaxFD / 8),
545 + hashPrime(SQUID_NUMFD / 8),
549 --- squid-2.5.STABLE12/src/snmp_agent.c.fdc 2004-06-01 00:39:00.000000000 +0200
550 +++ squid-2.5.STABLE12/src/snmp_agent.c 2005-12-06 14:07:43.000000000 +0100
553 case PERF_SYS_CURUNUSED_FD:
554 Answer = snmp_var_new_integer(Var->name, Var->name_length,
555 - (snint) Squid_MaxFD - Number_FD,
556 + (snint) SQUID_NUMFD - Number_FD,
559 case PERF_SYS_CURRESERVED_FD:
560 --- squid-2.5.STABLE12/src/comm.c.fdc 2005-09-10 12:17:55.000000000 +0200
561 +++ squid-2.5.STABLE12/src/comm.c 2005-12-06 14:07:43.000000000 +0100
566 - * NOTE: set the listen queue to Squid_MaxFD/4 and rely on the kernel to
567 + * NOTE: set the listen queue to Squid_MAXFD/4 and rely on the kernel to
568 * impose an upper limit. Solaris' listen(3n) page says it has
569 * no limit on this parameter, but sys/socket.h sets SOMAXCONN
570 * to 5. HP-UX currently has a limit of 20. SunOS is 5 and
572 comm_listen(int sock)
575 - if ((x = listen(sock, Squid_MaxFD >> 2)) < 0) {
576 + if ((x = listen(sock, SQUID_NUMFD >> 2)) < 0) {
577 debug(50, 0) ("comm_listen: listen(%d, %d): %s\n",
585 debug(5, 3) ("commSetTimeout: FD %d timeout %d\n", fd, timeout);
587 - assert(fd < Squid_MaxFD);
588 + assert(fd < SQUID_NUMFD);
590 assert(F->flags.open);
594 debug(5, 5) ("comm_close: FD %d\n", fd);
596 - assert(fd < Squid_MaxFD);
597 + assert(fd < SQUID_NUMFD);
600 if (F->flags.closing)
601 @@ -862,12 +862,12 @@
605 - fd_table = xcalloc(Squid_MaxFD, sizeof(fde));
606 + fd_table = xcalloc(SQUID_NUMFD, sizeof(fde));
607 /* XXX account fd_table */
608 /* Keep a few file descriptors free so that we don't run out of FD's
609 * after accepting a client but before it opens a socket or a file.
610 * Since Squid_MaxFD can be as high as several thousand, don't waste them */
611 - RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
612 + RESERVED_FD = XMIN(100, SQUID_NUMFD / 4);
613 CBDATA_INIT_TYPE(ConnectStateData);
614 comm_write_pool = memPoolCreate("CommWriteStateData", sizeof(CommWriteStateData));
615 conn_close_pool = memPoolCreate("close_handler", sizeof(close_handler));
616 --- squid-2.5.STABLE12/src/ipc.c.fdc 2001-10-17 22:25:02.000000000 +0200
617 +++ squid-2.5.STABLE12/src/ipc.c 2005-12-06 14:07:43.000000000 +0100
621 /* Make sure all other filedescriptors are closed */
622 - for (x = 3; x < SQUID_MAXFD; x++)
623 + for (x = 3; x < SQUID_NUMFD; x++)
627 --- squid-2.5.STABLE12/src/main.c.fdc 2005-06-27 23:24:28.000000000 +0200
628 +++ squid-2.5.STABLE12/src/main.c 2005-12-06 14:09:21.000000000 +0100
634 + comm_slow_fd_destroy();
637 authenticateShutdown();
638 externalAclShutdown();
644 + comm_slow_fd_init(SQUID_NUMFD);
646 serverConnectionsOpen();
647 if (theOutIcpConnection >= 0) {
648 if (!Config2.Accel.on || Config.onoff.accel_with_proxy)
652 debug(1, 1) ("Process ID %d\n", (int) getpid());
653 - debug(1, 1) ("With %d file descriptors available\n", Squid_MaxFD);
654 + debug(1, 1) ("With %d file descriptors available\n", SQUID_NUMFD);
656 if (!configured_once)
657 disk_init(); /* disk_init must go before ipcache_init() */
663 + comm_slow_fd_init(SQUID_NUMFD);
666 authenticateInit(&Config.authConfig);
672 - if (FD_SETSIZE < Squid_MaxFD)
673 - Squid_MaxFD = FD_SETSIZE;
675 #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_)
676 if ((WIN32_init_err = WIN32_Subsystem_Init()))
683 /* send signal to running copy and exit */
684 if (opt_send_signal != -1) {
685 /* chroot if configured to run inside chroot */
692 /* init comm module */
696 releaseServerSockets();
697 commCloseAllSockets();
699 + comm_slow_fd_destroy();
701 authenticateShutdown();
704 --- squid-2.5.STABLE12/src/stat.c.fdc 2005-03-29 11:52:00.000000000 +0200
705 +++ squid-2.5.STABLE12/src/stat.c 2005-12-06 14:07:43.000000000 +0100
709 storeAppendPrintf(sentry, "---- ------ ---- -------- -------- --------------------- ------------------------------\n");
710 - for (i = 0; i < Squid_MaxFD; i++) {
711 + for (i = 0; i < SQUID_NUMFD; i++) {
717 storeAppendPrintf(sentry, "File descriptor usage for %s:\n", appname);
718 storeAppendPrintf(sentry, "\tMaximum number of file descriptors: %4d\n",
721 storeAppendPrintf(sentry, "\tLargest file desc currently in use: %4d\n",
723 storeAppendPrintf(sentry, "\tNumber of file desc currently in use: %4d\n",
724 @@ -1026,7 +1026,7 @@
725 statHistEnumInit(&C->comm_icp_incoming, INCOMING_ICP_MAX);
726 statHistEnumInit(&C->comm_dns_incoming, INCOMING_DNS_MAX);
727 statHistEnumInit(&C->comm_http_incoming, INCOMING_HTTP_MAX);
728 - statHistIntInit(&C->select_fds_hist, 256); /* was SQUID_MAXFD, but it is way too much. It is OK to crop this statistics */
729 + statHistIntInit(&C->select_fds_hist, 256); /* was SQUID_NUMFD, but it is way too much. It is OK to crop this statistics */
732 /* add special cases here as they arrive */
733 --- squid-2.5.STABLE12/src/delay_pools.c.fdc 2005-10-20 19:30:31.000000000 +0200
734 +++ squid-2.5.STABLE12/src/delay_pools.c 2005-12-06 14:07:43.000000000 +0100
736 typedef union _delayPool delayPool;
738 static delayPool *delay_data = NULL;
739 -static fd_set delay_no_delay;
740 +static BIT_ARRAY delay_no_delay;
741 static time_t delay_pools_last_update = 0;
742 static hash_table *delay_id_ptr_hash = NULL;
743 static long memory_used = 0;
747 delay_pools_last_update = getCurrentTime();
748 - FD_ZERO(&delay_no_delay);
749 + BA_INIT(delay_no_delay,SQUID_NUMFD);
750 + BA_ZERO(delay_no_delay);
751 cachemgrRegister("delay", "Delay Pool Levels", delayPoolStats, 0, 1);
755 hashFreeItems(delay_id_ptr_hash, delayIdZero);
756 hashFreeMemory(delay_id_ptr_hash);
757 delay_id_ptr_hash = NULL;
758 + BA_FREE(delay_no_delay);
762 @@ -283,19 +285,19 @@
764 delaySetNoDelay(int fd)
766 - FD_SET(fd, &delay_no_delay);
767 + BA_SET(fd, delay_no_delay);
771 delayClearNoDelay(int fd)
773 - FD_CLR(fd, &delay_no_delay);
774 + BA_CLR(fd, delay_no_delay);
778 delayIsNoDelay(int fd)
780 - return FD_ISSET(fd, &delay_no_delay);
781 + return BA_ISSET(fd, delay_no_delay);
785 --- squid-2.5.STABLE12/src/squid.h.fdc 2005-03-26 03:50:53.000000000 +0100
786 +++ squid-2.5.STABLE12/src/squid.h 2005-12-06 14:07:43.000000000 +0100
788 #include "cache_snmp.h"
796 +#define SQUID_NUMFD (Config.max_filedesc)
797 +#define BIT_ARRAY_ACTIVE 1
799 +#define SQUID_NUMFD SQUID_MAXFD
800 +#define BIT_ARRAY_ACTIVE 0
803 +#include "bit_array.h"