Subject: Re: sosend_loan tweak
To: None <jonathan@dsg.stanford.edu>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-net
Date: 06/14/2006 23:54:24
--NextPart-20060614235037-1897400
Content-Type: Text/Plain; charset=us-ascii

hi,

> Or if you don't want to put the setsockopt()s into your application,
> how about changing the default watermarks to be more friendly to sosend()?

how about the attached patch?
i'll commit it unless anyone objects.

YAMAMOTO Takashi

--NextPart-20060614235037-1897400
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="a.diff"

Index: kern/uipc_socket2.c
===================================================================
--- kern/uipc_socket2.c	(revision 1673)
+++ kern/uipc_socket2.c	(revision 1674)
@@ -385,7 +385,7 @@ soreserve(struct socket *so, u_long sndc
 	if (so->so_rcv.sb_lowat == 0)
 		so->so_rcv.sb_lowat = 1;
 	if (so->so_snd.sb_lowat == 0)
-		so->so_snd.sb_lowat = MCLBYTES;
+		so->so_snd.sb_lowat = MAX(MCLBYTES, sock_loan_thresh);
 	if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
 		so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
 	return (0);
Index: kern/uipc_socket.c
===================================================================
--- kern/uipc_socket.c	(revision 1673)
+++ kern/uipc_socket.c	(revision 1674)
@@ -130,9 +130,9 @@ EVCNT_ATTACH_STATIC(sosend_kvalimit);
 static struct callback_entry sokva_reclaimerentry;
 
 #ifdef SOSEND_NO_LOAN
-int use_sosend_loan = 0;
+int sock_loan_thresh = INT_MAX;
 #else
-int use_sosend_loan = 1;
+int sock_loan_thresh = 4096;
 #endif
 
 static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER;
@@ -145,7 +145,6 @@ int somaxkva = SOMAXKVA;
 static int socurkva;
 static int sokvawaiters;
 
-#define	SOCK_LOAN_THRESH	4096
 #define	SOCK_LOAN_CHUNK		65536
 
 static size_t sodopendfree(void);
@@ -844,9 +843,8 @@ sosend(struct socket *so, struct mbuf *a
 					mlen = MLEN;
 				}
 				MCLAIM(m, so->so_snd.sb_mowner);
-				if (use_sosend_loan &&
-				    uio->uio_iov->iov_len >= SOCK_LOAN_THRESH &&
-				    space >= SOCK_LOAN_THRESH &&
+				if (uio->uio_iov->iov_len >= sock_loan_thresh &&
+				    space >= sock_loan_thresh &&
 				    (len = sosend_loan(so, uio, m,
 						       space)) != 0) {
 					SOSEND_COUNTER_INCR(&sosend_loan_big);
Index: sys/socketvar.h
===================================================================
--- sys/socketvar.h	(revision 1673)
+++ sys/socketvar.h	(revision 1674)
@@ -255,6 +255,7 @@ do {									\
 #ifdef _KERNEL
 extern u_long		sb_max;
 extern int		somaxkva;
+extern int		sock_loan_thresh;
 /* to catch callers missing new second argument to sonewconn: */
 #define	sonewconn(head, connstatus)	sonewconn1((head), (connstatus))
 

--NextPart-20060614235037-1897400--