[796] in linux-net channel archive

home help back first fref pref prev next nref lref last post

PATCH: AF_UNIX socket buffer size...

daemon@ATHENA.MIT.EDU (Chad Page)
Sat Jul 29 15:59:08 1995

Date: Fri, 28 Jul 1995 23:21:59 -0700 (PDT)
From: Chad Page <cpage@shell1.best.com>
To: linux-net@vger.rutgers.edu
cc: torvalds@cs.helsinki.fi


	I was scrolling through net/unix/sock.c (trying to figure out 
what was wrong with it - I found tons of E_INVALS... :), and I found a 
rather haunting message saying that 4K was way too little for a buffer, 
and caused tons of context switches in X-Windows.  I decided to modify 
sock.c to use the modern __get_free_pages call (which shows how much 
sock.c has been maintained :) to fix this.  It should now allocate 16K...

	As I mention in the patch, what we should *really* do is rewrite 
all the buffer stuff and make allocations dynamic if possible, which 
would take less memory in many cases than the old 4K scheme (but lose 
some speed with it...)

	Also, is anyone actually rewriting this code?  I might be able to 
begin to hack some of the AF_UNIX code to make it more compliant...

	Enjoy!

	- Chad

--- net/unix/sock.c.1.3.12	Fri Jul 28 23:01:48 1995
+++ net/unix/sock.c	Fri Jul 28 23:12:32 1995
@@ -230,10 +230,11 @@
 }
 
 /*
- *	We allocate a page of data for the socket. This is woefully inadequate and helps cause vast
- *	amounts of excess task switching and blocking when transferring stuff like bitmaps via X.
- *	It doesn't help this problem that the Linux scheduler is desperately in need of a major 
- *	rewrite. Somewhere near 16K would be better maybe 32.
+ *	We now allocate 16K of data for an AF_UNIX socket.  This is too little
+ *	for some cases, and too much in others.  What we really need here
+ *	is a dynamic scheme, but I think that can wait for a true rewrite of
+ *	the UNIX domain socket system... this message used to whine about how
+ * 	4K was far too little for X bitmaps, and said it should be 16-32K. 
  */
 
 static struct unix_proto_data *
@@ -289,7 +290,7 @@
 	{
 		if (upd->buf) 
 		{
-			free_page((unsigned long)upd->buf);
+			free_pages((unsigned long)upd->buf, 2);
 			upd->buf = NULL;
 			upd->bp_head = upd->bp_tail = 0;
 		}
@@ -318,12 +319,12 @@
 
 	if (!(upd = unix_data_alloc())) 
 	{
-		printk("UNIX: create: can't allocate buffer\n");
+		printk("AF_UNIX: create: can't allocate buffer\n");
 		return(-ENOMEM);
 	}
-	if (!(upd->buf = (char*) get_free_page(GFP_USER))) 
+	if (!(upd->buf = (char*) __get_free_pages(GFP_USER, 2, ~0UL))) 
 	{
-		printk("UNIX: create: can't get page!\n");
+		printk("AF_UNIX: create: can't get pages!\n");
 		unix_data_deref(upd);
 		return(-ENOMEM);
 	}
@@ -358,7 +359,7 @@
 
 	if (upd->socket != sock) 
 	{
-		printk("UNIX: release: socket link mismatch!\n");
+		printk("AF_UNIX: release: socket link mismatch!\n");
 		return(-EINVAL);
 	}
 
@@ -403,7 +404,7 @@
 	}
 	if (upd->sockaddr_len || upd->inode) 
 	{
-		/*printk("UNIX: bind: already bound!\n");*/
+		/*printk("AF_UNIX: bind: already bound!\n");*/
 		return(-EINVAL);
 	}
 	memcpy(&upd->sockaddr_un, umyaddr, sockaddr_len);
@@ -425,7 +426,7 @@
 	set_fs(old_fs);
 	if (i < 0) 
 	{
-/*		printk("UNIX: bind: can't open socket %s\n", fname);*/
+/*		printk("AF_UNIX: bind: can't open socket %s\n", fname);*/
 		if(i==-EEXIST)
 			i=-EADDRINUSE;
 		return(i);
@@ -644,7 +645,7 @@
 
 		if (avail <= 0) 
 		{
-			printk("UNIX: read: AVAIL IS NEGATIVE!!!\n");
+			printk("AF_UNIX: read: AVAIL IS NEGATIVE!!!\n");
 			send_sig(SIGKILL, current, 1);
 			return(-EPIPE);
 		}
@@ -725,7 +726,7 @@
 
 		if (space <= 0) 
 		{
-			printk("UNIX: write: SPACE IS NEGATIVE!!!\n");
+			printk("AF_UNIX: write: SPACE IS NEGATIVE!!!\n");
 			send_sig(SIGKILL, current, 1);
 			return(-EPIPE);
 		}
--- include/net/unix.h.1.3.12	Fri Jul 28 22:58:00 1995
+++ include/net/unix.h	Fri Jul 28 23:05:05 1995
@@ -58,7 +58,7 @@
  * note that buffer contents can wraparound, and we can write one byte less
  * than full size to discern full vs empty.
  */
-#define BUF_SIZE		PAGE_SIZE
+#define BUF_SIZE		16384	
 #define UN_BUF_AVAIL(UPD)	(((UPD)->bp_head - (UPD)->bp_tail) & \
 								(BUF_SIZE-1))
 #define UN_BUF_SPACE(UPD)	((BUF_SIZE-1) - UN_BUF_AVAIL(UPD))

home help back first fref pref prev next nref lref last post