dovecot: Grow file descriptors to 64k at startup, and drop them ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Aug 24 20:49:40 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/0e08960275f8
changeset: 6313:0e08960275f8
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 24 20:49:33 2007 +0300
description:
Grow file descriptors to 64k at startup, and drop them for login and imap
processes.

diffstat:

4 files changed, 14 insertions(+), 3 deletions(-)
dovecot-example.conf       |    2 --
src/master/login-process.c |    4 ++++
src/master/mail-process.c  |    5 ++++-
src/master/main.c          |    6 ++++++

diffs (82 lines):

diff -r 05aabdc581b1 -r 0e08960275f8 dovecot-example.conf
--- a/dovecot-example.conf	Fri Aug 24 20:00:14 2007 +0300
+++ b/dovecot-example.conf	Fri Aug 24 20:49:33 2007 +0300
@@ -164,8 +164,6 @@
 # Maximum number of connections allowed per each login process. This setting
 # is used only if login_process_per_connection=no. Once the limit is reached,
 # the process notifies master so that it can create a new login process.
-# You should make sure that the process has at least
-# 16 + login_max_connections * 2 available file descriptors.
 #login_max_connections = 256
 
 # Greeting message for clients.
diff -r 05aabdc581b1 -r 0e08960275f8 src/master/login-process.c
--- a/src/master/login-process.c	Fri Aug 24 20:00:14 2007 +0300
+++ b/src/master/login-process.c	Fri Aug 24 20:49:33 2007 +0300
@@ -682,6 +682,10 @@ static pid_t create_login_process(struct
 	}
 
 	restrict_process_size(group->set->login_process_size, (unsigned int)-1);
+	if (group->set->login_process_per_connection)
+		restrict_fd_limit(16 + 2);
+	else
+		restrict_fd_limit(16 + 2*group->set->login_max_connections);
 
 	/* make sure we don't leak syslog fd, but do it last so that
 	   any errors above will be logged */
diff -r 05aabdc581b1 -r 0e08960275f8 src/master/mail-process.c
--- a/src/master/mail-process.c	Fri Aug 24 20:00:14 2007 +0300
+++ b/src/master/mail-process.c	Fri Aug 24 20:49:33 2007 +0300
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Timo Sirainen */
+/* Copyright (C) 2002 Timo Sirainen */
 
 #include "common.h"
 #include "array.h"
@@ -27,6 +27,8 @@
 #  include <sys/resource.h>
 #endif
 
+/* 1024 should be more than enough */
+#define MAIL_PROCESS_FD_LIMIT 1024
 /* Timeout chdir() completely after this many seconds */
 #define CHDIR_TIMEOUT 30
 /* Give a warning about chdir() taking a while if it took longer than this
@@ -824,6 +826,7 @@ create_mail_process(enum process_type pr
 
 	if (set->mail_drop_priv_before_exec)
 		restrict_access_by_env(TRUE);
+	restrict_fd_limit(MAIL_PROCESS_FD_LIMIT);
 
 	client_process_exec(set->mail_executable, title);
 	i_fatal_status(FATAL_EXEC, "execv(%s) failed: %m",
diff -r 05aabdc581b1 -r 0e08960275f8 src/master/main.c
--- a/src/master/main.c	Fri Aug 24 20:00:14 2007 +0300
+++ b/src/master/main.c	Fri Aug 24 20:49:33 2007 +0300
@@ -8,6 +8,7 @@
 #include "env-util.h"
 #include "fd-close-on-exec.h"
 #include "write-full.h"
+#include "restrict-process-size.h"
 
 #include "askpass.h"
 #include "auth-process.h"
@@ -27,6 +28,10 @@
 #include <syslog.h>
 #include <sys/stat.h>
 
+/* Try to raise our fd limit this high at startup. If the limit is already
+   higher, it's not dropped. */
+#define DOVECOT_MASTER_FD_MIN_LIMIT 65536
+
 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf";
 
 struct ioloop *ioloop;
@@ -172,6 +177,7 @@ static void create_pid_file(const char *
 
 static void main_init(bool log_error)
 {
+	(void)restrict_raise_fd_limit(DOVECOT_MASTER_FD_MIN_LIMIT);
 	drop_capabilities();
 
 	/* deny file access from everyone else except owner */


More information about the dovecot-cvs mailing list