public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] change pts allocation behaviour in
@ 2004-05-07  8:42 Steve Young
  2004-05-07  9:48 ` [PATCH] change pts allocation behaviour in tty_io.c, v2 Steve Young
  2004-05-07 11:14 ` [PATCH] change pts allocation behaviour in Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Steve Young @ 2004-05-07  8:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm

  Hello,

  Here is a patch to change the way ptses are allocated.  It applies against
2.6.6-rc3.  Basically it tries to humour old glibc by always obtaining a pts
in the range of 0-255 first.  However, if that fails, then it will search the
higher ranges.  The net effect should be that old glibc users won't notice
problems until they try and get more than 256 concurrent ptses (which would
break under the first-fit scheme anyway), yet we reduce the average number of 
iterations required to find a new pts when a lot are in use.  In the very
worst case of only one pts available, this still performs no worse than
the either the old or more recent allocation schemes.

  Thanks,
  Steve.

diff -ur linux-2.6.5-virgin/drivers/char/tty_io.c linux-2.6.5-deflowered/drivers/char/tty_io.c
--- linux-2.6.5-virgin/drivers/char/tty_io.c	2004-05-07 02:07:45.486690184 -0600
+++ linux-2.6.5-deflowered/drivers/char/tty_io.c	2004-05-07 01:57:19.447753528 -0600
@@ -1362,14 +1362,24 @@
 #ifdef CONFIG_UNIX98_PTYS
 	if (device == MKDEV(TTYAUX_MAJOR,2)) {
 		/* find a device that is not in use. */
-		static int next_ptmx_dev = 0;
+		static int next_ptmx_dev = MAX_PREFERRED_PTY;
 		retval = -1;
 		driver = ptm_driver;
+		/* first, try for a pty < 256 for old glibc that doesn't support
+		 * larger pts numbers */
+		for (index = 0; index < MAX_PREFERRED_PTY && driver->refcount < pty_limit; index++) {
+			if (!init_dev(driver, index, &tty)) 
+				goto ptmx_found;
+		}
+		/* nothing below MAX_PREFERRED_PTY, try something higher */
 		while (driver->refcount < pty_limit) {
 			index = next_ptmx_dev;
 			next_ptmx_dev = (next_ptmx_dev+1) % driver->num;
-			if (!init_dev(driver, index, &tty))
+			if (!next_ptmx_dev) 
+				next_ptmx_dev = MAX_PREFERRED_PTY;
+			if (!init_dev(driver, index, &tty)) {
 				goto ptmx_found; /* ok! */
+			}
 		}
 		return -EIO; /* no free ptys */
 	ptmx_found:
diff -ur linux-2.6.5-virgin/include/linux/tty.h linux-2.6.5-deflowered/include/linux/tty.h
--- linux-2.6.5-virgin/include/linux/tty.h	2004-05-07 02:07:47.386401384 -0600
+++ linux-2.6.5-deflowered/include/linux/tty.h	2004-05-07 01:43:55.000000000 -0600
@@ -35,6 +35,7 @@
 #define NR_UNIX98_PTY_DEFAULT	4096      /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX	(1 << MINORBITS) /* Absolute limit */
 #define NR_LDISCS		16
+#define MAX_PREFERRED_PTY	256			/* we prefer to allocate ptys beneath this number */
 
 /*
  * These are set up by the setup-routine at boot-time:

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-05-07 19:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-07  8:42 [PATCH] change pts allocation behaviour in Steve Young
2004-05-07  9:48 ` [PATCH] change pts allocation behaviour in tty_io.c, v2 Steve Young
2004-05-07 11:14 ` [PATCH] change pts allocation behaviour in Andrew Morton
2004-05-07 11:52   ` Steve Young
2004-05-07 19:09     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox