From: Ian Jackson Subject: Re: [PATCH v4] tools/xenconsoled: Increase file descriptor limit Date: Fri, 27 Feb 2015 16:13:41 +0000 Message-ID: <21744.38837.455720.204222@mariner.uk.xensource.com> References: <1425053045-17592-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1425053045-17592-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Wei Liu , Ian Campbell , Xen-devel List-Id: xen-devel@lists.xenproject.org Andrew Cooper writes ("[PATCH v4] 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. ... There's still a lot of code here I think we can do without. Why do we care about the system maximum ? > + /* > + * Will min_fds fit within our current hard limit? > + * (likely on *BSD, unlikely on Linux) > + * If so, raise our soft limit. > + */ > + if (min_fds <= lim.rlim_max) { > + struct rlimit new = { > + .rlim_cur = min_fds, > + .rlim_max = lim.rlim_max, > + }; > + > + if (setrlimit(RLIMIT_NOFILE, &new) < 0) > + syslog(LOG_WARNING, > + "Unable to increase fd soft limit: %lu -> %u, " > + "hard %lu (%s) - May run out with lots of domains", > + lim.rlim_cur, min_fds, lim.rlim_max, > + strerror(errno)); > + } else { > + /* > + * Lets hope that, as a root process, we have sufficient > + * privilege to up the hard limit. > + */ > + struct rlimit new = { .rlim_cur = min_fds, .rlim_max = min_fds }; > + > + if (setrlimit(RLIMIT_NOFILE, &new) < 0) > + syslog(LOG_WARNING, > + "Unable to increase fd hard limit: %lu -> %u (%s)" > + " - May run out with lots of domains", > + lim.rlim_max, min_fds, strerror(errno)); > + } This is very repetitive. The only difference between the two branches is (a) the value of .rlim_max and (b) the log message. (b) can be dealt with by making the log message depend only on the contents of new. Ian.