]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2398. [bug] Improve file descriptor management. New,
authorMark Andrews <marka@isc.org>
Wed, 23 Jul 2008 12:03:53 +0000 (12:03 +0000)
committerMark Andrews <marka@isc.org>
Wed, 23 Jul 2008 12:03:53 +0000 (12:03 +0000)
                        temporary, named.conf option reserved-sockets,
                        default 512. [RT #18344]

13 files changed:
CHANGES
bin/named/config.c
bin/named/named.conf.docbook
bin/named/server.c
doc/arm/Bv9ARM-book.xml
lib/isc/include/isc/resource.h
lib/isc/include/isc/socket.h
lib/isc/unix/resource.c
lib/isc/unix/socket.c
lib/isc/win32/libisc.def
lib/isc/win32/resource.c
lib/isc/win32/socket.c
lib/isccfg/namedconf.c

diff --git a/CHANGES b/CHANGES
index 99ccd51a754ec92cfbf609f7949ff49a1c42c235..b18fb847ad95b28edd6af821a7f16c2c4ba90a96 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+2398.  [bug]           Improve file descriptor management.  New,
+                       temporary, named.conf option reserved-sockets,
+                       default 512. [RT #18344]
+
 2396.  [bug]           Don't set SO_REUSEADDR for randomized ports.
                        [RT #18336]
 
index 2fe3bff67f96f696f24e6283296523c64367be33..cafb78cfac45ee560259a54f31420ba42f0b2538 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: config.c,v 1.11.2.4.8.36.4.1 2008/07/23 11:16:05 marka Exp $ */
+/* $Id: config.c,v 1.11.2.4.8.36.4.2 2008/07/23 12:03:52 marka Exp $ */
 
 #include <config.h>
 
@@ -94,6 +94,7 @@ options {\n\
        use-id-pool true;\n\
        use-ixfr true;\n\
        edns-udp-size 4096;\n\
+       reserved-sockets 512;\n\
 \n\
        /* view */\n\
        allow-notify {none;};\n\
index ff9ae4bce1a6f81de44ea99c2801fb24f7cb6ad5..da7d019f4f56322a0c216b3762af571909ee0e9a 100644 (file)
@@ -17,7 +17,7 @@
  - PERFORMANCE OF THIS SOFTWARE.
 -->
 
-<!-- $Id: named.conf.docbook,v 1.1.4.13 2007/08/28 07:19:08 tbox Exp $ -->
+<!-- $Id: named.conf.docbook,v 1.1.4.13.4.1 2008/07/23 12:03:52 marka Exp $ -->
 
 <refentry>
   <refentryinfo>
@@ -201,6 +201,7 @@ options {
        port <replaceable>integer</replaceable>;
        querylog <replaceable>boolean</replaceable>;
        recursing-file <replaceable>quoted_string</replaceable>;
+       reserved-sockets <replaceable>integer</replaceable>;
        random-device <replaceable>quoted_string</replaceable>;
        recursive-clients <replaceable>integer</replaceable>;
        serial-query-rate <replaceable>integer</replaceable>;
index c705af0ddcb1569d36fe8eec467f682ad3129c16..f52576369f14b211aaae5648afd8e5a5cd399ad9 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: server.c,v 1.339.2.15.2.78.4.1 2008/05/22 21:11:14 each Exp $ */
+/* $Id: server.c,v 1.339.2.15.2.78.4.2 2008/07/23 12:03:52 marka Exp $ */
 
 #include <config.h>
 
@@ -2153,26 +2153,28 @@ static isc_result_t
 load_configuration(const char *filename, ns_server_t *server,
                   isc_boolean_t first_time)
 {
-       isc_result_t result;
-       cfg_parser_t *parser = NULL;
        cfg_obj_t *config;
-       const cfg_obj_t *options;
-       const cfg_obj_t *views;
+       cfg_parser_t *parser = NULL;
+       const cfg_listelt_t *element;
+       const cfg_obj_t *builtin_views;
+       const cfg_obj_t *maps[3];
        const cfg_obj_t *obj;
+       const cfg_obj_t *options;
        const cfg_obj_t *v4ports, *v6ports;
-       const cfg_obj_t *maps[3];
-       const cfg_obj_t *builtin_views;
-       const cfg_listelt_t *element;
+       const cfg_obj_t *views;
        dns_view_t *view = NULL;
        dns_view_t *view_next;
-       dns_viewlist_t viewlist;
        dns_viewlist_t tmpviewlist;
-       ns_aclconfctx_t aclconfctx;
-       isc_uint32_t interface_interval;
-       isc_uint32_t heartbeat_interval;
-       isc_uint32_t udpsize;
+       dns_viewlist_t viewlist;
        in_port_t listen_port;
        int i;
+       isc_resourcevalue_t files;
+       isc_result_t result;
+       isc_uint32_t heartbeat_interval;
+       isc_uint32_t interface_interval;
+       isc_uint32_t reserved;
+       isc_uint32_t udpsize;
+       ns_aclconfctx_t aclconfctx;
 
        ns_aclconfctx_init(&aclconfctx);
        ISC_LIST_INIT(viewlist);
@@ -2261,6 +2263,43 @@ load_configuration(const char *filename, ns_server_t *server,
         */
        set_limits(maps);
 
+       /*
+        * Sanity check on "files" limit.
+        */
+       result = isc_resource_curlimit(isc_resource_openfiles, &files);
+       if (result == ISC_R_SUCCESS && files < FD_SETSIZE) {
+               isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
+                             NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
+                             "the 'files' limit (%" ISC_PRINT_QUADFORMAT "u) "
+                             "is less than FD_SETSIZE (%d), increase "
+                             "'files' in named.conf or recompile with a "
+                             "smaller FD_SETSIZE.", files, FD_SETSIZE);
+               if (files > FD_SETSIZE)
+                       files = FD_SETSIZE;
+       } else
+               files = FD_SETSIZE;
+
+       /*
+        * Set the number of socket reserved for TCP, stdio etc.
+        */
+       obj = NULL;
+       result = ns_config_get(maps, "reserved-sockets", &obj);
+       INSIST(result == ISC_R_SUCCESS);
+       reserved = cfg_obj_asuint32(obj);
+       if (files < 128U)                       /* Prevent underflow. */
+               reserved = 0;
+       else if (reserved > files - 128U)       /* Mimimum UDP space. */
+               reserved = files - 128;
+       if (reserved < 128U)                    /* Mimimum TCP/stdio space. */
+               reserved = 128;
+       if (reserved + 128U > files) {
+               isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
+                              NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
+                             "less than 128 UDP sockets available after "
+                             "applying 'reserved-sockets' and 'files'");
+       }
+       isc__socketmgr_setreserved(ns_g_socketmgr, reserved);
+       
        /*
         * Configure various server options.
         */
index 710cd36c1d1dc59d8a5b85ab57f16cf9a732da22..41837c6a9a1c16effeec29d389cc869ab0da8700 100644 (file)
@@ -18,7 +18,7 @@
  - PERFORMANCE OF THIS SOFTWARE.
 -->
 
-<!-- File: $Id: Bv9ARM-book.xml,v 1.155.2.27.2.88.2.1 2008/05/22 21:11:14 each Exp $ -->
+<!-- File: $Id: Bv9ARM-book.xml,v 1.155.2.27.2.88.2.2 2008/07/23 12:03:52 marka Exp $ -->
 
 <book>
 <title>BIND 9 Administrator Reference Manual</title>
@@ -2878,6 +2878,7 @@ statement in the <filename>named.conf</filename> file:</para>
     <optional> max-transfer-idle-in <replaceable>number</replaceable>; </optional>
     <optional> max-transfer-idle-out <replaceable>number</replaceable>; </optional>
     <optional> tcp-clients <replaceable>number</replaceable>; </optional>
+    <optional> reserved-sockets <replaceable>number</replaceable>; </optional>
     <optional> recursive-clients <replaceable>number</replaceable>; </optional>
     <optional> serial-query-rate <replaceable>number</replaceable>; </optional>
     <optional> serial-queries <replaceable>number</replaceable>; </optional>
@@ -4072,6 +4073,23 @@ connections that the server will accept.
 The default is <literal>100</literal>.</para>
 </listitem></varlistentry>
 
+             <varlistentry>
+               <term><command>reserved-sockets</command></term>
+               <listitem>
+                 <para>
+                 The number of file descriptors reserved for TCP, stdio,
+                 etc.  This needs to be big enough to cover the number of
+                 interfaces named listens on, tcp-clients as well as
+                 to provide room for outgoing TCP queries and incoming zone
+                 transfers.  The default is <literal>512</literal>.
+                 The minimum value is <literal>128</literal> and the
+                 maximum value is <literal>128</literal> less than
+                 'files' or FD_SETSIZE (whichever is smaller).  This
+                 option may be removed in the future.
+                 </para>
+               </listitem>
+             </varlistentry>
+
 <varlistentry><term><command>max-cache-size</command></term>
 <listitem><para>The maximum amount of memory to use for the
 server's cache, in bytes.  When the amount of data in the cache
index 2c2a82981c564d2c98a047b3217b273c7204f326..d3d98a8eb346c087f59da89e6b0626e0c4a168d5 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: resource.h,v 1.4.206.1 2004/03/06 08:14:47 marka Exp $ */
+/* $Id: resource.h,v 1.4.206.1.34.1 2008/07/23 12:03:53 marka Exp $ */
 
 #ifndef ISC_RESOURCE_H
 #define ISC_RESOURCE_H 1
@@ -79,6 +79,19 @@ isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value);
  *     ISC_R_NOTIMPLEMENTED    'resource' is not a type known by the OS.
  */
 
+isc_result_t
+isc_resource_curlimit(isc_resource_t resource, isc_resourcevalue_t *value);
+/*
+ * Get the current limit on a resource.
+ *
+ * Requires:
+ *     'resource' is a valid member of the isc_resource_t enumeration.
+ *
+ * Returns:
+ *     ISC_R_SUCCESS           Success.
+ *     ISC_R_NOTIMPLEMENTED    'resource' is not a type known by the OS.
+ */
+
 ISC_LANG_ENDDECLS
 
 #endif /* ISC_RESOURCE_H */
index d7aee1d934f009dce945caaf357d21505fa1856b..4fbff59df894859f5e85958bfaff35cbb01cb09d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.h,v 1.54.12.7.4.2 2008/07/23 07:28:11 tbox Exp $ */
+/* $Id: socket.h,v 1.54.12.7.4.3 2008/07/23 12:03:53 marka Exp $ */
 
 #ifndef ISC_SOCKET_H
 #define ISC_SOCKET_H 1
@@ -701,6 +701,12 @@ isc_socket_ipv6only(isc_socket_t *sock, isc_boolean_t yes);
  *     'sock' is a valid socket.
  */
 
+void
+isc__socketmgr_setreserved(isc_socketmgr_t *mgr, isc_uint32_t);
+/*%<
+ * Temporary.  For use by named only.
+ */
+
 ISC_LANG_ENDDECLS
 
 #endif /* ISC_SOCKET_H */
index 717f079da7078c57673f3fb560c90d51a7649c1e..b40878a0638d60a43f6a0e0a4ed56e0c5174d970 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: resource.c,v 1.11.206.3.4.1 2008/07/23 11:18:40 marka Exp $ */
+/* $Id: resource.c,v 1.11.206.3.4.2 2008/07/23 12:03:53 marka Exp $ */
 
 #include <config.h>
 
@@ -186,3 +186,20 @@ isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
 
        return (result);
 }
+
+isc_result_t
+isc_resource_curlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
+       int unixresult;
+       int unixresource;
+       struct rlimit rl;
+       isc_result_t result;
+
+       result = resource2rlim(resource, &unixresource);
+       if (result == ISC_R_SUCCESS) {
+               unixresult = getrlimit(unixresource, &rl);
+               INSIST(unixresult == 0);
+               *value = rl.rlim_cur;
+       }
+
+       return (result);
+}
index 2e8f67f6c1df3c6594e71c4f9e180ae60550cc33..f8c54ee9bf89b424c4cfa098e5edc3e58671a777 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.207.2.19.2.35.4.1 2008/07/22 04:16:14 marka Exp $ */
+/* $Id: socket.c,v 1.207.2.19.2.35.4.2 2008/07/23 12:03:53 marka Exp $ */
 
 #include <config.h>
 
@@ -197,6 +197,7 @@ struct isc_socketmgr {
        isc_socket_t           *fds[FD_SETSIZE];
        int                     fdstate[FD_SETSIZE];
        int                     maxfd;
+       int                     reserved;       /* unlocked */
 #ifdef ISC_PLATFORM_USETHREADS
        isc_thread_t            watcher;
        isc_condition_t         shutdown_ok;
@@ -1452,9 +1453,18 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
 
 #ifdef F_DUPFD
        /*
-        * Leave a space for stdio to work in.
+        * Leave a space for stdio and TCP to work in.
         */
-       if (sock->fd >= 0 && sock->fd < 20) {
+       if (manager->reserved != 0 && type == isc_sockettype_udp &&
+           sock->fd >= 0 && sock->fd < manager->reserved) {
+               int new, tmp;
+               new = fcntl(sock->fd, F_DUPFD, manager->reserved);
+               tmp = errno;
+               (void)close(sock->fd);
+               errno = tmp;
+               sock->fd = new;
+               err = "isc_socket_create: fcntl/reserved";
+       } else if (sock->fd >= 0 && sock->fd < 20) {
                int new, tmp;
                new = fcntl(sock->fd, F_DUPFD, 20);
                tmp = errno;
@@ -2370,6 +2380,14 @@ watcher(void *uap) {
 }
 #endif /* ISC_PLATFORM_USETHREADS */
 
+void
+isc__socketmgr_setreserved(isc_socketmgr_t *manager, isc_uint32_t reserved) {
+
+       REQUIRE(VALID_MANAGER(manager));
+
+       manager->reserved = reserved;
+}
+
 /*
  * Create a new socket manager.
  */
@@ -2453,6 +2471,7 @@ isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) {
 #else /* ISC_PLATFORM_USETHREADS */
        manager->maxfd = 0;
 #endif /* ISC_PLATFORM_USETHREADS */
+       manager->reserved = 0;
        memset(manager->fdstate, 0, sizeof(manager->fdstate));
 
 #ifdef ISC_PLATFORM_USETHREADS
index 897dd4d0df4b32c42029462cd9f364cf1a5cd041..e880b624a50ed699b6298d1c7a9edb71a0556f4b 100644 (file)
@@ -33,6 +33,7 @@ isc__mem_putanddetach
 isc__mem_strdup
 isc__mempool_get
 isc__mempool_put
+isc__socketmgr_setminudp
 isc__strerror
 isc_app_block
 isc_app_finish
index fd76482ef6a4b998c61a1480c47e2e2668ea92cd..385615cc1252e4fc6f788a95f5460b757d12adaf 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: resource.c,v 1.2.12.6 2007/08/28 07:19:17 tbox Exp $ */
+/* $Id: resource.c,v 1.2.12.6.4.1 2008/07/23 12:03:53 marka Exp $ */
 
 #include <config.h>
 
@@ -65,3 +65,13 @@ isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
        *value = WIN32_MAX_OPEN_FILES;
        return (ISC_R_SUCCESS);
 }
+
+isc_result_t
+isc_resource_curlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
+
+       if (resource != isc_resource_openfiles)
+               return (ISC_R_NOTIMPLEMENTED);
+
+       *value = WIN32_MAX_OPEN_FILES;
+       return (ISC_R_SUCCESS);
+}
index 082478f7251da3d77573e1e25128339e27304b0c..fd1fc34ef320bcf7a28270d6b9243d7b47a7a70a 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.5.2.13.2.24.4.2 2008/07/23 07:28:12 tbox Exp $ */
+/* $Id: socket.c,v 1.5.2.13.2.24.4.3 2008/07/23 12:03:53 marka Exp $ */
 
 /* This code has been rewritten to take advantage of Windows Sockets
  * I/O Completion Ports and Events. I/O Completion Ports is ONLY
@@ -3806,3 +3806,9 @@ isc_socket_ipv6only(isc_socket_t *sock, isc_boolean_t yes) {
        }
 #endif
 }
+
+void
+isc__socketmgr_setreserved(isc_socketmgr_t *manager, isc_uint32_t reserved) {
+       UNUSED(manager);
+       UNUSED(reserved);
+}
index 1943af3dbebfde11e15be8fd7e67674cb02b6835..622d76aef790ac4611f8a459e95d8af051542fef 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: namedconf.c,v 1.21.44.36 2008/01/24 23:45:28 tbox Exp $ */
+/* $Id: namedconf.c,v 1.21.44.36.2.1 2008/07/23 12:03:53 marka Exp $ */
 
 #include <config.h>
 
@@ -601,6 +601,7 @@ options_clauses[] = {
        { "recursing-file", &cfg_type_qstring, 0 },
        { "random-device", &cfg_type_qstring, 0 },
        { "recursive-clients", &cfg_type_uint32, 0 },
+       { "reserved-sockets", &cfg_type_uint32, 0 },
        { "serial-queries", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE },
        { "serial-query-rate", &cfg_type_uint32, 0 },
        { "server-id", &cfg_type_serverid, 0 },