summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2003-10-21 22:55:47 +0000
committerthorpej <thorpej@NetBSD.org>2003-10-21 22:55:47 +0000
commit4011fcfefd5fc87f11d246469f14a3dba3f9d2eb (patch)
tree35b7c6d89721a96448f0fed5303e5023737ab1cb
parent9dec5da8e89524af4c9bbc038b880c0d701c8be2 (diff)
Cache the "adjusted" value of sb_max when sb_max is changed, in order
to avoid doing quad math in sbreserve(). Change suggested by Simon Burge, and code inspired by a similar change in FreeBSD.
-rw-r--r--sys/conf/param.c6
-rw-r--r--sys/kern/kern_sysctl.c11
-rw-r--r--sys/kern/uipc_socket.c8
-rw-r--r--sys/kern/uipc_socket2.c28
-rw-r--r--sys/sys/socketvar.h3
5 files changed, 38 insertions, 18 deletions
diff --git a/sys/conf/param.c b/sys/conf/param.c
index bd9dd62d904..91264ba03da 100644
--- a/sys/conf/param.c
+++ b/sys/conf/param.c
@@ -1,4 +1,4 @@
-/* $NetBSD: param.c,v 1.41 2003/08/07 16:30:49 agc Exp $ */
+/* $NetBSD: param.c,v 1.42 2003/10/21 22:55:47 thorpej Exp $ */
/*
* Copyright (c) 1980, 1986, 1989 Regents of the University of California.
@@ -37,10 +37,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: param.c,v 1.41 2003/08/07 16:30:49 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: param.c,v 1.42 2003/10/21 22:55:47 thorpej Exp $");
#include "opt_rtc_offset.h"
-#include "opt_sb_max.h"
#include "opt_sysv.h"
#include "opt_sysvparam.h"
@@ -108,7 +107,6 @@ int maxproc = NPROC;
int desiredvnodes = NVNODE;
int maxfiles = MAXFILES;
int ncallout = 16 + NPROC; /* size of callwheel (rounded to ^2) */
-u_long sb_max = SB_MAX; /* maximum socket buffer size */
int fscale = FSCALE; /* kernel uses `FSCALE', user uses `fscale' */
/*
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 49af3e705cc..3c10a5fd265 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sysctl.c,v 1.150 2003/10/19 01:44:49 simonb Exp $ */
+/* $NetBSD: kern_sysctl.c,v 1.151 2003/10/21 22:55:47 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.150 2003/10/19 01:44:49 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.151 2003/10/21 22:55:47 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_insecure.h"
@@ -619,11 +619,8 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
int new_sbmax = sb_max;
error = sysctl_int(oldp, oldlenp, newp, newlen, &new_sbmax);
- if (newp && !error) {
- if (new_sbmax < (16 * 1024)) /* sanity */
- return (EINVAL);
- sb_max = new_sbmax;
- }
+ if (newp && error == 0)
+ error = sb_max_set(new_sbmax);
return (error);
}
case KERN_TKSTAT:
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index a9959b6e4d2..2842e40f18c 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_socket.c,v 1.90 2003/09/22 12:59:58 christos Exp $ */
+/* $NetBSD: uipc_socket.c,v 1.91 2003/10/21 22:55:47 thorpej Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.90 2003/09/22 12:59:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.91 2003/10/21 22:55:47 thorpej Exp $");
#include "opt_sock_counters.h"
#include "opt_sosend_loan.h"
@@ -126,6 +126,10 @@ void
soinit(void)
{
+ /* Set the initial adjusted socket buffer size. */
+ if (sb_max_set(sb_max))
+ panic("bad initial sb_max value: %lu\n", sb_max);
+
pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0,
"sockpl", NULL);
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index 25c5576112d..ac35c237c35 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_socket2.c,v 1.57 2003/09/22 12:59:59 christos Exp $ */
+/* $NetBSD: uipc_socket2.c,v 1.58 2003/10/21 22:55:47 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
@@ -32,9 +32,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.57 2003/09/22 12:59:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.58 2003/10/21 22:55:47 thorpej Exp $");
#include "opt_mbuftrace.h"
+#include "opt_sb_max.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -59,6 +60,9 @@ const char netcls[] = "netcls";
const char netio[] = "netio";
const char netlck[] = "netlck";
+u_long sb_max = SB_MAX; /* maximum socket buffer size */
+static u_long sb_max_adj; /* adjusted sb_max */
+
/*
* Procedures to manipulate state flags of socket
* and do appropriate wakeups. Normal sequence from the
@@ -354,6 +358,22 @@ sowakeup(struct socket *so, struct sockbuf *sb, int code)
*/
int
+sb_max_set(u_long new_sbmax)
+{
+ int s;
+
+ if (new_sbmax < (16 * 1024))
+ return (EINVAL);
+
+ s = splsoftnet();
+ sb_max = new_sbmax;
+ sb_max_adj = (u_quad_t)new_sbmax * MCLBYTES / (MSIZE + MCLBYTES);
+ splx(s);
+
+ return (0);
+}
+
+int
soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
{
@@ -383,8 +403,8 @@ int
sbreserve(struct sockbuf *sb, u_long cc)
{
- if (cc == 0 ||
- (u_quad_t) cc > (u_quad_t) sb_max * MCLBYTES / (MSIZE + MCLBYTES))
+ KDASSERT(sb_max_adj != 0);
+ if (cc == 0 || cc > sb_max_adj)
return (0);
sb->sb_hiwat = cc;
sb->sb_mbmax = min(cc * 2, sb_max);
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
index 02445d552ec..a6d36069f59 100644
--- a/sys/sys/socketvar.h
+++ b/sys/sys/socketvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: socketvar.h,v 1.67 2003/09/06 22:01:21 christos Exp $ */
+/* $NetBSD: socketvar.h,v 1.68 2003/10/21 22:55:47 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1993
@@ -299,6 +299,7 @@ void sbrelease(struct sockbuf *);
int sbreserve(struct sockbuf *, u_long);
int sbwait(struct sockbuf *);
int sb_lock(struct sockbuf *);
+int sb_max_set(u_long);
void soinit(void);
int soabort(struct socket *);
int soaccept(struct socket *, struct mbuf *);