Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jun 2001 22:28:54 +0200 (MEST)
From:      Sascha Schumann <sascha@schumann.cx>
To:        Alfred Perlstein <bright@rush.net>
Cc:        Valentin Nechayev <netch@iv.nn.kiev.ua>, <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: poll(2)'s arbitrary limit
Message-ID:  <Pine.LNX.4.33.0106172157290.6072-200000@rossini.schumann.cx>
In-Reply-To: <20010617155740.O1832@superconductor.rush.net>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
> >     I've been using kern.maxproc=kern.maxprocfiles=2*32768 for my
> >     tests and that worked successfully.
>
> Ok, so then we don't need to change FreeBSD?

    Well, it would be cool, if an administrator could impose a
    more restrictive limit on the maximum number of open fds
    while still allowing applications to poll large sets of fds.

    For example, the appended patch adds kern.maxfilesperpoll
    which is used in place of the current check in poll().  This
    could be used to fine-tune servers for specific
    configurations more easily.  At the same time, it would get
    rid of the (per the sys_generic.c comment) "bogus" relation
    between fd limits and the limits imposed by poll(2).

    - Sascha                                     Experience IRCG
      http://schumann.cx/                http://schumann.cx/ircg


[-- Attachment #2 --]
--- ./conf/param.c~	Sun Jun 17 22:04:18 2001
+++ ./conf/param.c	Sun Jun 17 22:08:25 2001
@@ -69,6 +69,7 @@
 int	maxprocperuid = NPROC-1;		/* maximum # of processes per user */
 int	maxfiles = MAXFILES;			/* system wide open files limit */
 int	maxfilesperproc = MAXFILES;		/* per-process open files limit */
+int	maxfilesperpoll = MAXFILES;		/* maximum files per poll */
 int	ncallout = 16 + NPROC + MAXFILES;	/* maximum # of timer events */
 int	mbuf_wait = 32;				/* mbuf sleep time in ticks */
 
--- ./kern/kern_descrip.c~	Sun Jun 17 22:03:29 2001
+++ ./kern/kern_descrip.c	Sun Jun 17 22:05:36 2001
@@ -1454,6 +1454,9 @@
 SYSCTL_PROC(_kern, KERN_FILE, file, CTLTYPE_OPAQUE|CTLFLAG_RD,
     0, 0, sysctl_kern_file, "S,file", "Entire file table");
 
+SYSCTL_INT(_kern, KERN_MAXFILESPERPOLL, maxfilesperpoll, CTLFLAG_RW, 
+    &maxfilesperpoll, 0, "Maximum files per poll");
+
 SYSCTL_INT(_kern, KERN_MAXFILESPERPROC, maxfilesperproc, CTLFLAG_RW, 
     &maxfilesperproc, 0, "Maximum files allowed open per process");
 
--- ./kern/sys_generic.c~	Sun Jun 17 22:06:12 2001
+++ ./kern/sys_generic.c	Sun Jun 17 22:06:32 2001
@@ -851,14 +851,7 @@
 	size_t ni;
 
 	nfds = SCARG(uap, nfds);
-	/*
-	 * This is kinda bogus.  We have fd limits, but that is not
-	 * really related to the size of the pollfd array.  Make sure
-	 * we let the process use at least FD_SETSIZE entries and at
-	 * least enough for the current limits.  We want to be reasonably
-	 * safe, but not overly restrictive.
-	 */
-	if (nfds > p->p_rlimit[RLIMIT_NOFILE].rlim_cur && nfds > FD_SETSIZE)
+	if (nfds > maxfilesperpoll)
 		return (EINVAL);
 	ni = nfds * sizeof(struct pollfd);
 	if (ni > sizeof(smallbits))
--- ./sys/file.h~	Sun Jun 17 22:09:53 2001
+++ ./sys/file.h	Sun Jun 17 22:10:18 2001
@@ -106,6 +106,7 @@
 extern struct fileops badfileops;
 extern int maxfiles;		/* kernel limit on number of open files */
 extern int maxfilesperproc;	/* per process limit on number of open files */
+extern int maxfilesperpoll;	/* maximum number of fds per poll */
 extern int nfiles;		/* actual number of open files */
 
 static __inline void fhold __P((struct file *fp));
--- ./sys/sysctl.h~	Sun Jun 17 22:02:18 2001
+++ ./sys/sysctl.h	Sun Jun 17 22:10:37 2001
@@ -329,6 +329,7 @@
 #define	KERN_USRSTACK		33	/* int: address of USRSTACK */
 #define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
 #define KERN_MAXID		35      /* number of valid kern ids */
+#define	KERN_MAXFILESPERPOLL	36	/* int: max files per poll */
 
 #define CTL_KERN_NAMES { \
 	{ 0, 0 }, \
@@ -359,6 +360,7 @@
 	{ "ntp_pll", CTLTYPE_NODE }, \
 	{ "bootfile", CTLTYPE_STRING }, \
 	{ "maxfilesperproc", CTLTYPE_INT }, \
+	{ "maxfilesperpoll", CTLTYPE_INT }, \
 	{ "maxprocperuid", CTLTYPE_INT }, \
 	{ "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
 	{ "ipc", CTLTYPE_NODE }, \

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.33.0106172157290.6072-200000>