]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2398. [bug] Improve file descriptor management. New,
authorMark Andrews <marka@isc.org>
Thu, 4 Sep 2008 08:11:25 +0000 (08:11 +0000)
committerMark Andrews <marka@isc.org>
Thu, 4 Sep 2008 08:11:25 +0000 (08:11 +0000)
                        temporary, named.conf option reserved-sockets,
                        default 512. [RT #18344]
: ----------------------------------------------------------------------

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

diff --git a/CHANGES b/CHANGES
index edefddcb1c22aaa82e92b674369a60a849a92257..37a4322d928ec0bb470aaaab14fa24d2e192f789 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 2399.  [bug]           Abort timeout queries to reduce the number of open
                        UDP sockets. [RT #18367]
 
+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 9b0c98070aaa09c4caa2a5865c7d755bfffaa547..b57b24a0f722b655c5310c6b21eb9b2fd3d12acd 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: config.c,v 1.11.2.4.8.38 2008/07/20 23:45:41 tbox Exp $ */
+/* $Id: config.c,v 1.11.2.4.8.39 2008/09/04 08:11:24 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..a75f8ff31b50daa2727d7f31476e5379d03b598d 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.14 2008/09/04 08:11:24 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 62a680b8fdcab42718de33e208132c86a94047e3..819b2e9d2b1feb38e185028f62cd1bf1dc549b18 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: server.c,v 1.339.2.15.2.82 2008/08/01 02:12:46 jinmei Exp $ */
+/* $Id: server.c,v 1.339.2.15.2.83 2008/09/04 08:11:24 marka Exp $ */
 
 #include <config.h>
 
@@ -33,6 +33,7 @@
 #include <isc/portset.h>
 #include <isc/print.h>
 #include <isc/resource.h>
+#include <isc/socket.h>
 #include <isc/stdio.h>
 #include <isc/string.h>
 #include <isc/task.h>
@@ -2183,29 +2184,31 @@ 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 *usev4ports, *avoidv4ports, *usev6ports, *avoidv6ports;
-       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, udpport_low, udpport_high;
+       int i;
        isc_portset_t *v4portset = NULL;
        isc_portset_t *v6portset = NULL;
        isc_resourcevalue_t nfiles;
-       int i;
+       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;
+       unsigned int maxsocks;
 
        ns_aclconfctx_init(&aclconfctx);
        ISC_LIST_INIT(viewlist);
@@ -2291,22 +2294,42 @@ load_configuration(const char *filename, ns_server_t *server,
         * but may cause subsequent runtime failures for a busy recursive
         * server.
         */
+       result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &maxsocks);
+       if (result != ISC_R_SUCCESS)
+               maxsocks = 0;
        result = isc_resource_getcurlimit(isc_resource_openfiles, &nfiles);
-       if (result == ISC_R_SUCCESS) {
-               unsigned int maxsocks;
-
-               result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &maxsocks);
-               if (result == ISC_R_SUCCESS &&
-                   (isc_resourcevalue_t)maxsocks > nfiles) {
-                       isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
-                                     NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
-                                     "max open files "
-                                     "(%" ISC_PRINT_QUADFORMAT "u)"
-                                     " is smaller than max sockets (%u)",
-                                     nfiles, maxsocks);
-               }
+       if (result == ISC_R_SUCCESS && (isc_resourcevalue_t)maxsocks > nfiles) {
+               isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
+                             NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
+                             "max open files (%" ISC_PRINT_QUADFORMAT "u)"
+                             " is smaller than max sockets (%u)",
+                             nfiles, maxsocks);
        }
 
+       /*
+        * 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 (maxsocks != 0) {
+               if (maxsocks < 128U)                    /* Prevent underflow. */
+                       reserved = 0;
+               else if (reserved > maxsocks - 128U)    /* Minimum UDP space. */
+                       reserved = maxsocks - 128;
+       }
+       /* Minimum TCP/stdio space. */
+       if (reserved < 128U)
+               reserved = 128;
+       if (reserved + 128U > maxsocks && maxsocks != 0) {
+               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 'maxsockets'");
+       }
+       isc__socketmgr_setreserved(ns_g_socketmgr, reserved);
+       
        /*
         * Configure various server options.
         */
index 31de57cf7518b5fd58b99f392cc2301ea197be68..1cb411aad6b94d44fc83aa897f78442fca9aa2e4 100644 (file)
@@ -18,7 +18,7 @@
  - PERFORMANCE OF THIS SOFTWARE.
 -->
 
-<!-- File: $Id: Bv9ARM-book.xml,v 1.155.2.27.2.93 2008/07/27 04:46:38 marka Exp $ -->
+<!-- File: $Id: Bv9ARM-book.xml,v 1.155.2.27.2.94 2008/09/04 08:11:24 marka Exp $ -->
 
 <book>
 <title>BIND 9 Administrator Reference Manual</title>
@@ -2907,6 +2907,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>
@@ -4205,6 +4206,25 @@ 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
+                 maxsockets (-S).  This option may be removed in the future.
+                 </para>
+                 <para>
+                 This option has little effect on Windows.
+                 </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 b185e8c66e926b30cedba33fe6b23515803fb804..b37e3403297a8846ae4b2c5bdbaf5d473e8b4d66 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.h,v 1.54.12.14 2008/08/21 00:13:49 jinmei Exp $ */
+/* $Id: socket.h,v 1.54.12.15 2008/09/04 08:11:24 marka Exp $ */
 
 #ifndef ISC_SOCKET_H
 #define ISC_SOCKET_H 1
@@ -774,6 +774,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 cc0301cb864d01aa34dfe737fcbd39fbc70f7fc2..1b15751c1b4f9d18abcae5156c2d36836d7224d0 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.207.2.19.2.54 2008/08/21 00:13:49 jinmei Exp $ */
+/* $Id: socket.c,v 1.207.2.19.2.55 2008/09/04 08:11:25 marka Exp $ */
 
 #include <config.h>
 
@@ -333,6 +333,7 @@ struct isc_socketmgr {
        fd_set                  *write_fds_copy;
        int                     maxfd;
 #endif /* USE_SELECT */
+       int                     reserved;       /* unlocked */
 #ifdef ISC_PLATFORM_USETHREADS
        isc_thread_t            watcher;
        isc_condition_t         shutdown_ok;
@@ -1803,9 +1804,18 @@ opensocket(isc_socketmgr_t *manager, isc_socket_t *sock) {
 
 #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 && sock->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;
@@ -3017,6 +3027,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.
  */
@@ -3271,6 +3289,7 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
        /* zero-clear so that necessary cleanup on failure will be easy */
        memset(manager, 0, sizeof(*manager));
        manager->maxsocks = maxsocks;
+       manager->reserved = 0;
        manager->fds = isc_mem_get(mctx,
                                   manager->maxsocks * sizeof(isc_socket_t *));
        if (manager->fds == NULL) {
@@ -3347,7 +3366,6 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
        if (result != ISC_R_SUCCESS)
                goto cleanup;
        memset(manager->fdstate, 0, manager->maxsocks * sizeof(int));
-
 #ifdef ISC_PLATFORM_USETHREADS
        /*
         * Start up the select/poll thread.
index 44103e69863793e9ca56f90efa9a1b6abd493d72..2a1f938ecec6eea46c98877c3f4e743bda4a831d 100644 (file)
@@ -33,6 +33,7 @@ isc__mem_putanddetach
 isc__mem_strdup
 isc__mempool_get
 isc__mempool_put
+isc__socketmgr_setreserved
 isc__strerror
 isc_app_block
 isc_app_finish
@@ -297,8 +298,8 @@ isc_ratelimiter_setinterval
 isc_ratelimiter_setpertic
 isc_ratelimiter_shutdown
 isc_region_compare
-isc_resource_getlimit
 isc_resource_getcurlimit
+isc_resource_getlimit
 isc_resource_setlimit
 isc_result_register
 isc_result_totext
index 00937ee56c6927c64fce1409bc1b03be536084db..574be91759e094024fecdbd76f1273cec0368d82 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.5.2.13.2.37 2008/08/21 00:13:49 jinmei Exp $ */
+/* $Id: socket.c,v 1.5.2.13.2.38 2008/09/04 08:11:25 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
@@ -3446,6 +3446,13 @@ isc_socket_filter(isc_socket_t *sock, const char *filter) {
        return (ISC_R_NOTIMPLEMENTED);
 }
 
+void
+isc__socketmgr_setreserved(isc_socketmgr_t *manager, isc_uint32_t reserved) {
+       UNUSED(manager);
+       UNUSED(reserved);
+}
+
+
 /*
  * Set up to listen on a given socket.  We do this by creating an internal
  * event that will be dispatched when the socket has read activity.  The
index 24ff59a66c47b6dad54813c25fee64b963da7f3a..65b4e4e57e722570f41768280827bf74be1acf8a 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: namedconf.c,v 1.21.44.39 2008/06/25 23:45:37 tbox Exp $ */
+/* $Id: namedconf.c,v 1.21.44.40 2008/09/04 08:11:25 marka Exp $ */
 
 #include <config.h>
 
@@ -653,6 +653,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 },