]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
From Henrik
authorwessels <>
Wed, 18 Feb 1998 06:28:22 +0000 (06:28 +0000)
committerwessels <>
Wed, 18 Feb 1998 06:28:22 +0000 (06:28 +0000)
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...

src/comm.cc
src/fd.cc
src/protos.h

index e32cba87393bb3a28a80e9efb9e67a201033e000..a2522853ed3773a59dce8b5646cd035e2c4b737f 100644 (file)
@@ -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);
index 1096b29e49c01e81ecf32eb8bb673b2f32233324..122775255c375215e629eb641b438c9135a53a7c 100644 (file)
--- 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;
+}
index ac4256396d97a3f210f554df4c92547c31905147..0e07f57947ae98c8c11e816ce2d108b63053980a 100644 (file)
@@ -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);