From: wessels <> Date: Wed, 18 Feb 1998 06:28:22 +0000 (+0000) Subject: From Henrik X-Git-Tag: SQUID_3_0_PRE1~4077 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b23e11440ee30f54c794cdfdc07790e905bf3a6;p=thirdparty%2Fsquid.git From Henrik This patch adds a automatic adjustment of RESERVED_FD when we fail to create sockets. This functionality mentioned in the comments in comm_open, but there was no code implementing it... --- diff --git a/src/comm.cc b/src/comm.cc index e32cba8739..a2522853ed 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.227 1998/02/10 21:44:31 wessels Exp $ + * $Id: comm.cc,v 1.228 1998/02/17 23:28:22 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -251,6 +251,7 @@ comm_open(int sock_type, default: debug(50, 0) ("comm_open: socket failure: %s\n", xstrerror()); } + fdAdjustReserved(); return -1; } /* update fdstat */ @@ -383,10 +384,12 @@ commResetFD(ConnectStateData * cs) fd2 = socket(AF_INET, SOCK_STREAM, 0); if (fd2 < 0) { debug(5, 0) ("commResetFD: socket: %s\n", xstrerror()); + fdAdjustReserved(); return 0; } if (dup2(fd2, cs->fd) < 0) { debug(5, 0) ("commResetFD: dup2: %s\n", xstrerror()); + fdAdjustReserved(); return 0; } close(fd2); diff --git a/src/fd.cc b/src/fd.cc index 1096b29e49..122775255c 100644 --- a/src/fd.cc +++ b/src/fd.cc @@ -1,6 +1,6 @@ /* - * $Id: fd.cc,v 1.20 1998/02/10 21:44:33 wessels Exp $ + * $Id: fd.cc,v 1.21 1998/02/17 23:28:23 wessels Exp $ * * DEBUG: section 51 Filedescriptor Functions * AUTHOR: Duane Wessels @@ -140,3 +140,32 @@ fdNFree(void) { return Squid_MaxFD - Number_FD; } + +/* Called when we runs out of file descriptors */ +void +fdAdjustReserved(void) +{ + int new; + int x; + static time_t last = 0; + /* + * don't update too frequently + */ + if (last + 5 > squid_curtime) + return; + /* + * Calculate a new reserve, based on current usage and a small extra + */ + new = Squid_MaxFD - Number_FD + XMIN(25, Squid_MaxFD / 16); + if (new <= RESERVED_FD) + return; + x = Squid_MaxFD - 20 - XMIN(25, Squid_MaxFD / 16); + if (new > x) { + /* perhaps this should be fatal()? -DW */ + debug(51, 0) ("WARNING: This machine has a serious shortage of filedescriptors.\n"); + new = x; + } + debug(51, 0) ("Reserved FD adjusted from %d to %d due to failures\n", + RESERVED_FD, new); + RESERVED_FD = new; +} diff --git a/src/protos.h b/src/protos.h index ac4256396d..0e07f57947 100644 --- a/src/protos.h +++ b/src/protos.h @@ -148,6 +148,7 @@ extern void fd_bytes(int fd, int len, unsigned int type); extern void fdFreeMemory(void); extern void fdDumpOpen(void); extern int fdNFree(void); +extern void fdAdjustReserved(void); extern fileMap *file_map_create(int); extern int file_map_allocate(fileMap *, int);