From: Don Slutz <dslutz@verizon.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
Xen-devel <xen-devel@lists.xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Ian Campbell <Ian.Campbell@citrix.com>
Subject: Re: [PATCH v3] tools/xenconsoled: Increase file descriptor limit
Date: Tue, 17 Feb 2015 17:41:57 -0500 [thread overview]
Message-ID: <54E3C3B5.3070707@terremark.com> (raw)
In-Reply-To: <1424195752-10842-1-git-send-email-andrew.cooper3@citrix.com>
On 02/17/15 12:55, Andrew Cooper wrote:
> XenServer's VM density testing uncovered a regression when moving from
> sysvinit to systemd where the file descriptor limit dropped from 4096 to
> 1024. (XenServer had previously inserted a ulimit statement into its
> initscripts.)
>
> One solution is to use LimitNOFILE=4096 in xenconsoled.service to match the
> lost ulimit, but that is only a stopgap solution.
>
> As Xenconsoled genuinely needs a large number of file descriptors if a large
> number of domains are running, and is well behaved with its descriptors,
> attempt to up the limit to the system maximum.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
> CC: Wei Liu <wei.liu2@citrix.com>
>
For what it is worth:
Reviewed-by: Don Slutz <dslutz@verizon.com>
-Don Slutz
> ---
> v3:
> * Hide Linux specific bits in #ifdef __linux__
> v2:
> * Always increase soft limit to hard limit
> * Correct commment regarding number of file descriptors
> * long -> unsigned long as that appears to be the underlying type of an rlim_t
> ---
> tools/console/daemon/main.c | 47 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 47 insertions(+)
>
> diff --git a/tools/console/daemon/main.c b/tools/console/daemon/main.c
> index 92d2fc4..20ffe6b 100644
> --- a/tools/console/daemon/main.c
> +++ b/tools/console/daemon/main.c
> @@ -26,6 +26,7 @@
> #include <string.h>
> #include <signal.h>
> #include <sys/types.h>
> +#include <sys/resource.h>
>
> #include "xenctrl.h"
>
> @@ -55,6 +56,50 @@ static void version(char *name)
> printf("Xen Console Daemon 3.0\n");
> }
>
> +/*
> + * Xenconsoled requires two file descriptors for each PV console (pty and log
> + * file), which can easily exceed the default of 1024 if many guests are
> + * running. Try to set the fd limit to the system maximum, falling back to a
> + * default of 4096.
> + */
> +static void increase_fd_limit(void)
> +{
> + FILE *fs_nr_open;
> + struct rlimit lim;
> + unsigned long nr_open = 4096;
> +
> + if (getrlimit(RLIMIT_NOFILE, &lim) < 0)
> + return;
> +
> + /* Increase the soft limit to the current hard limit. */
> + if (lim.rlim_cur < lim.rlim_max) {
> + lim.rlim_cur = lim.rlim_max;
> + if (setrlimit(RLIMIT_NOFILE, &lim) < 0)
> + return;
> + }
> +
> +#ifdef __linux__
> + /* Attempt to locate the system maximum. */
> + fs_nr_open = fopen("/proc/sys/fs/nr_open", "r");
> + if (fs_nr_open) {
> + unsigned long nr;
> +
> + if (fscanf(fs_nr_open, "%lu", &nr) == 1)
> + nr_open = nr;
> + fclose(fs_nr_open);
> + }
> +#endif
> +
> + /*
> + * In the likely case that we are a root process with
> + * CAP_SYS_RESOURCE, attempt to up our hard limit.
> + */
> + if (nr_open > lim.rlim_max) {
> + lim.rlim_cur = lim.rlim_max = nr_open;
> + setrlimit(RLIMIT_NOFILE, &lim);
> + }
> +}
> +
> int main(int argc, char **argv)
> {
> const char *sopts = "hVvit:o:";
> @@ -154,6 +199,8 @@ int main(int argc, char **argv)
> openlog("xenconsoled", syslog_option, LOG_DAEMON);
> setlogmask(syslog_mask);
>
> + increase_fd_limit();
> +
> if (!is_interactive) {
> daemonize(pidfile ? pidfile : "/var/run/xenconsoled.pid");
> }
>
next prev parent reply other threads:[~2015-02-17 22:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-17 16:21 [PATCH v2] tools/xenconsoled: Increase file descriptor limit Andrew Cooper
2015-02-17 16:28 ` Wei Liu
2015-02-17 16:37 ` Andrew Cooper
2015-02-17 16:48 ` Wei Liu
2015-02-17 17:31 ` Andrew Cooper
2015-02-17 17:58 ` Wei Liu
2015-02-17 17:55 ` [PATCH v3] " Andrew Cooper
2015-02-17 22:41 ` Don Slutz [this message]
2015-02-19 11:04 ` Wei Liu
2015-02-19 16:30 ` Ian Jackson
2015-02-19 17:56 ` Andrew Cooper
2015-02-19 19:04 ` David Vrabel
2015-02-24 11:50 ` Andrew Cooper
2015-02-24 17:37 ` Ian Jackson
2015-02-19 16:25 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54E3C3B5.3070707@terremark.com \
--to=dslutz@verizon.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.