]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2473. [port] linux: raise the limit on open files to the possible
authorMark Andrews <marka@isc.org>
Fri, 24 Oct 2008 01:24:54 +0000 (01:24 +0000)
committerMark Andrews <marka@isc.org>
Fri, 24 Oct 2008 01:24:54 +0000 (01:24 +0000)
                        maximum value before spawning threads; 'files'
                        specified in named.conf doesn't seem to work with
                        threads as expected. [RT #18784]

CHANGES
bin/named/main.c
bin/named/unix/include/named/os.h
bin/named/unix/os.c
bin/named/win32/include/named/os.h
bin/named/win32/os.c

diff --git a/CHANGES b/CHANGES
index 3f157db3596051e07904419b8329b33879f9879d..7ea770698516bcc6b28a9a491f27a7cadb399c89 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+2473.  [port]          linux: raise the limit on open files to the possible
+                       maximum value before spawning threads; 'files'
+                       specified in named.conf doesn't seem to work with
+                       threads as expected. [RT #18784]
+
 2472.  [port]          linux: check the number of available cpu's before
                        calling chroot as it depends on "/proc". [RT #16923]
 
index 5d505f8fd7190a6ef3fc0b5db0dcaf3e31f7e6fb..aa6575aae8bf2977d0f2f0c6f0ba104eab95338f 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: main.c,v 1.165 2008/10/24 01:08:21 marka Exp $ */
+/* $Id: main.c,v 1.166 2008/10/24 01:24:54 marka Exp $ */
 
 /*! \file */
 
@@ -33,6 +33,7 @@
 #include <isc/hash.h>
 #include <isc/os.h>
 #include <isc/platform.h>
+#include <isc/print.h>
 #include <isc/resource.h>
 #include <isc/stdio.h>
 #include <isc/string.h>
@@ -576,6 +577,7 @@ destroy_managers(void) {
 static void
 setup(void) {
        isc_result_t result;
+       isc_resourcevalue_t old_openfiles;
 #ifdef HAVE_LIBSCF
        char *instance = NULL;
 #endif
@@ -691,6 +693,23 @@ setup(void) {
        (void)isc_resource_getlimit(isc_resource_openfiles,
                                    &ns_g_initopenfiles);
 
+       /*
+        * System resources cannot effectively be tuned on some systems.
+        * Raise the limit in such cases for safety.
+        */
+       old_openfiles = ns_g_initopenfiles;
+       ns_os_adjustnofile();
+       (void)isc_resource_getlimit(isc_resource_openfiles,
+                                   &ns_g_initopenfiles);
+       if (old_openfiles != ns_g_initopenfiles) {
+               isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
+                             NS_LOGMODULE_MAIN, ISC_LOG_NOTICE,
+                             "adjusted limit on open files from "
+                             "%" ISC_PRINT_QUADFORMAT "u to "
+                             "%" ISC_PRINT_QUADFORMAT "u",
+                             old_openfiles, ns_g_initopenfiles);
+       }
+
        /*
         * If the named configuration filename is relative, prepend the current
         * directory's name before possibly changing to another directory.
index 9a6b3c6d9d6c04c3130d39e580d4d1c6b616a259..d928edeaddddc773f9c7c9397ff7d1f0137691a5 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.h,v 1.27 2007/06/19 23:46:59 tbox Exp $ */
+/* $Id: os.h,v 1.28 2008/10/24 01:24:54 marka Exp $ */
 
 #ifndef NS_OS_H
 #define NS_OS_H 1
@@ -45,12 +45,14 @@ ns_os_inituserinfo(const char *username);
 void
 ns_os_changeuser(void);
 
+void
+ns_os_adjustnofile(void);
+
 void
 ns_os_minprivs(void);
 
 void
 ns_os_writepidfile(const char *filename, isc_boolean_t first_time);
-
 void
 ns_os_shutdown(void);
 
index 09a503fdb12e9db4d7d0865c03cc6c172a5b9de2..9edf817b030aab1f09608b2c47ba73f36c4eecc5 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.85 2008/10/15 05:00:57 marka Exp $ */
+/* $Id: os.c,v 1.86 2008/10/24 01:24:54 marka Exp $ */
 
 /*! \file */
 
@@ -42,6 +42,7 @@
 #include <isc/buffer.h>
 #include <isc/file.h>
 #include <isc/print.h>
+#include <isc/resource.h>
 #include <isc/result.h>
 #include <isc/strerror.h>
 #include <isc/string.h>
@@ -570,6 +571,24 @@ ns_os_changeuser(void) {
 #endif
 }
 
+void
+ns_os_adjustnofile() {
+#ifdef HAVE_LINUXTHREADS
+       isc_result_t result;
+       isc_resourcevalue_t newvalue;
+
+       /*
+        * Linux: max number of open files specified by one thread doesn't seem
+        * to apply to other threads on Linux.
+        */
+       newvalue = ISC_RESOURCE_UNLIMITED;
+
+       result = isc_resource_setlimit(isc_resource_openfiles, newvalue);
+       if (result != ISC_R_SUCCESS)
+               ns_main_earlywarning("couldn't adjust limit on open files");
+#endif 
+}
+
 void
 ns_os_minprivs(void) {
 #ifdef HAVE_SYS_PRCTL_H
index d8a24fae3b0f68693d483c5c8fa3a93352143ffc..3a16c989eac63af4e1339a5d44c29bb2dba88d6b 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.h,v 1.12 2007/06/19 23:46:59 tbox Exp $ */
+/* $Id: os.h,v 1.13 2008/10/24 01:24:54 marka Exp $ */
 
 #ifndef NS_OS_H
 #define NS_OS_H 1
@@ -43,6 +43,9 @@ ns_os_inituserinfo(const char *username);
 void
 ns_os_changeuser(void);
 
+void
+ns_os_adjustnofile(void);
+
 void
 ns_os_minprivs(void);
 
index 51b4bfde6b4fe5950b7f53aba3df6765c4d7700a..3f8af7c27df34f788a45f7ea03c285916fbf1ee3 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.28 2008/01/18 23:46:57 tbox Exp $ */
+/* $Id: os.c,v 1.29 2008/10/24 01:24:54 marka Exp $ */
 
 #include <config.h>
 #include <stdarg.h>
@@ -165,6 +165,10 @@ void
 ns_os_changeuser(void) {
 }
 
+void
+ns_os_adjustnofile(void) {
+}
+
 void
 ns_os_minprivs(void) {
 }