[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen stable-4.4] tools/xenconsoled: Increase file descriptor limit



commit a490f8df8c989483624ebd6befb63377be55722b
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Mar 2 15:04:37 2015 +0000
Commit:     Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Tue Jun 23 11:53:05 2015 +0100

    tools/xenconsoled: Increase file descriptor limit
    
    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, attempt to increase the limit.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
    (cherry picked from commit 588df84c0d702e835e526ecef3af6c5444857558)
    (cherry picked from commit 9d5b2b01024d18b2135c1b0deebb8bfbf5dced5f)
---
 tools/console/daemon/main.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/tools/console/daemon/main.c b/tools/console/daemon/main.c
index 92d2fc4..11de5c9 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,41 @@ static void version(char *name)
        printf("Xen Console Daemon 3.0\n");
 }
 
+static void increase_fd_limit(void)
+{
+       /*
+        * We require many file descriptors:
+        * - per domain: pty master, pty slave, logfile and evtchn
+        * - misc extra: hypervisor log, privcmd, gntdev, std...
+        *
+        * Allow a generous 1000 for misc, and calculate the maximum possible
+        * number of fds which could be used.
+        */
+       unsigned min_fds = (DOMID_FIRST_RESERVED * 4) + 1000;
+       struct rlimit lim, new = { min_fds, min_fds };
+
+       if (getrlimit(RLIMIT_NOFILE, &lim) < 0) {
+               fprintf(stderr, "Failed to obtain fd limit: %s\n",
+                       strerror(errno));
+               exit(1);
+       }
+
+       /* Do we already have sufficient? Great! */
+       if (lim.rlim_cur >= min_fds)
+               return;
+
+       /* Try to increase our limit. */
+       if (setrlimit(RLIMIT_NOFILE, &new) < 0)
+               syslog(LOG_WARNING,
+                      "Unable to increase fd limit from {%llu, %llu} to "
+                      "{%llu, %llu}: (%s) - May run out with lots of domains",
+                      (unsigned long long)lim.rlim_cur,
+                      (unsigned long long)lim.rlim_max,
+                      (unsigned long long)new.rlim_cur,
+                      (unsigned long long)new.rlim_max,
+                      strerror(errno));
+}
+
 int main(int argc, char **argv)
 {
        const char *sopts = "hVvit:o:";
@@ -154,6 +190,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");
        }
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.4

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.