Commit 0eeaaaf0 authored by Mark Andrews's avatar Mark Andrews

2398. [bug] Improve file descriptor management. New,

                        temporary, named.conf option reserved-sockets,
                        default 512. [RT #18344]
parent f5662f41
......@@ -106,14 +106,12 @@
2399. [placeholder]
2398. [placeholder]
2397. [bug] gssapi_functions had too many elements. [RT #18355]
[bug] Improve file descriptor management. New,
2398. [bug] Improve file descriptor management. New,
temporary, named.conf option reserved-sockets,
default 512. [RT #18344]
2397. [bug] gssapi_functions had too many elements. [RT #18355]
2396. [bug] Don't set SO_REUSEADDR for randomized ports.
[RT #18336]
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: config.c,v 1.89 2008/07/20 09:29:52 fdupont Exp $ */
/* $Id: config.c,v 1.90 2008/09/04 05:56:42 marka Exp $ */
/*! \file */
......@@ -100,6 +100,7 @@ options {\n\
edns-udp-size 4096;\n\
max-udp-size 4096;\n\
request-nsid false;\n\
reserved-sockets 512;\n\
\n\
/* view */\n\
allow-notify {none;};\n\
......
......@@ -17,7 +17,7 @@
- PERFORMANCE OF THIS SOFTWARE.
-->
<!-- $Id: named.conf.docbook,v 1.37 2008/04/02 02:37:41 marka Exp $ -->
<!-- $Id: named.conf.docbook,v 1.38 2008/09/04 05:56:42 marka Exp $ -->
<refentry>
<refentryinfo>
<date>Aug 13, 2004</date>
......@@ -202,6 +202,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>;
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: server.c,v 1.513 2008/07/18 01:26:20 marka Exp $ */
/* $Id: server.c,v 1.514 2008/09/04 05:56:42 marka Exp $ */
/*! \file */
......@@ -31,6 +31,7 @@
#include <isc/file.h>
#include <isc/hash.h>
#include <isc/httpd.h>
#include <isc/socket.h>
#include <isc/lex.h>
#include <isc/parseint.h>
#include <isc/portset.h>
......@@ -2883,30 +2884,32 @@ static isc_result_t
load_configuration(const char *filename, ns_server_t *server,
isc_boolean_t first_time)
{
isc_result_t result;
isc_interval_t interval;
cfg_parser_t *parser = NULL;
cfg_aclconfctx_t aclconfctx;
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;
cfg_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_interval_t interval;
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;
unsigned int maxsocks;
cfg_aclconfctx_init(&aclconfctx);
ISC_LIST_INIT(viewlist);
......@@ -2992,22 +2995,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.
*/
......
......@@ -18,7 +18,7 @@
- PERFORMANCE OF THIS SOFTWARE.
-->
<!-- File: $Id: Bv9ARM-book.xml,v 1.364 2008/08/12 14:40:26 jreed Exp $ -->
<!-- File: $Id: Bv9ARM-book.xml,v 1.365 2008/09/04 05:56:42 marka Exp $ -->
<book xmlns:xi="http://www.w3.org/2001/XInclude">
<title>BIND 9 Administrator Reference Manual</title>
......@@ -4562,6 +4562,7 @@ category notify { null; };
<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>
......@@ -6969,6 +6970,25 @@ avoid-v6-udp-ports { 40000; range 50000 60000; };
</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>
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.h,v 1.83 2008/08/20 23:57:59 jinmei Exp $ */
/* $Id: socket.h,v 1.84 2008/09/04 05:56:43 marka Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
......@@ -912,6 +912,12 @@ isc_socketmgr_renderxml(isc_socketmgr_t *mgr, xmlTextWriterPtr writer);
* Render internal statistics and other state into the XML document.
*/
void
isc__socketmgr_setreserved(isc_socketmgr_t *mgr, isc_uint32_t);
/*%<
* Temporary. For use by named only.
*/
#endif /* HAVE_LIBXML2 */
ISC_LANG_ENDDECLS
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.c,v 1.301 2008/08/20 23:57:59 jinmei Exp $ */
/* $Id: socket.c,v 1.302 2008/09/04 05:56:43 marka Exp $ */
/*! \file */
......@@ -349,6 +349,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;
......@@ -1856,9 +1857,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;
......@@ -3257,6 +3267,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.
*/
......@@ -3511,6 +3529,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) {
......@@ -3587,7 +3606,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.
......
......@@ -34,6 +34,7 @@ isc__mem_putanddetach
isc__mem_strdup
isc__mempool_get
isc__mempool_put
isc__socketmgr_setreserved
isc__strerror
isc_app_block
isc_app_finish
......@@ -336,8 +337,8 @@ isc_ratelimiter_setpertic
isc_ratelimiter_shutdown
isc_refcount_init
isc_region_compare
isc_resource_getlimit
isc_resource_getcurlimit
isc_resource_getlimit
isc_resource_setlimit
isc_result_register
isc_result_totext
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.c,v 1.66 2008/08/20 23:57:59 jinmei Exp $ */
/* $Id: socket.c,v 1.67 2008/09/04 05:56:43 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
......@@ -4006,3 +4006,9 @@ void *
isc_socket_gettag(isc_socket_t *socket) {
return (socket->tag);
}
void
isc__socketmgr_setreserved(isc_socketmgr_t *manager, isc_uint32_t reserved) {
UNUSED(manager);
UNUSED(reserved);
}
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: namedconf.c,v 1.89 2008/06/23 23:47:11 tbox Exp $ */
/* $Id: namedconf.c,v 1.90 2008/09/04 05:56:43 marka Exp $ */
/*! \file */
......@@ -692,6 +692,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 },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment