From 35606d39dd5d7e03148c0260985fef32328970e8 Mon Sep 17 00:00:00 2001 From: msmith Date: Wed, 3 Feb 1999 08:59:30 +0000 Subject: Make TCBHASHSIZE a boot-time tunable as well, taking its value from the variable net.inet.tcp.tcbhashsize. Requested by: David Filo --- sys/netinet/tcp_subr.c | 18 ++++++++++++++---- sys/netinet/tcp_timewait.c | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'sys/netinet') diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 12ca025..9063c86 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 - * $Id: tcp_subr.c,v 1.48 1998/11/15 21:35:09 guido Exp $ + * $Id: tcp_subr.c,v 1.49 1998/12/07 21:58:42 archie Exp $ */ #include "opt_compat.h" @@ -93,6 +93,9 @@ static void tcp_notify __P((struct inpcb *, int)); /* * Target size of TCP PCB hash tables. Must be a power of two. + * + * Note that this can be overridden by the kernel environment + * variable net.inet.tcp.tcbhashsize */ #ifndef TCBHASHSIZE #define TCBHASHSIZE 512 @@ -124,14 +127,21 @@ struct inp_tp { void tcp_init() { - + int hashsize; + tcp_iss = random(); /* wrong, but better than a constant */ tcp_ccgen = 1; tcp_cleartaocache(); LIST_INIT(&tcb); tcbinfo.listhead = &tcb; - tcbinfo.hashbase = hashinit(TCBHASHSIZE, M_PCB, &tcbinfo.hashmask); - tcbinfo.porthashbase = hashinit(TCBHASHSIZE, M_PCB, + if (!(getenv_int("net.inet.tcp.tcbhashsize", &hashsize))) + hashsize = TCBHASHSIZE; + if ((1 << ffs(hashsize)) != hashsize) { + printf("WARNING: TCB hash size not a power of 2\n"); + hashsize = 512; /* safe default */ + } + tcbinfo.hashbase = hashinit(hashsize, M_PCB, &tcbinfo.hashmask); + tcbinfo.porthashbase = hashinit(hashsize, M_PCB, &tcbinfo.porthashmask); tcbinfo.ipi_zone = zinit("tcpcb", sizeof(struct inp_tp), maxsockets, ZONE_INTERRUPT, 0); diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c index 12ca025..9063c86 100644 --- a/sys/netinet/tcp_timewait.c +++ b/sys/netinet/tcp_timewait.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 - * $Id: tcp_subr.c,v 1.48 1998/11/15 21:35:09 guido Exp $ + * $Id: tcp_subr.c,v 1.49 1998/12/07 21:58:42 archie Exp $ */ #include "opt_compat.h" @@ -93,6 +93,9 @@ static void tcp_notify __P((struct inpcb *, int)); /* * Target size of TCP PCB hash tables. Must be a power of two. + * + * Note that this can be overridden by the kernel environment + * variable net.inet.tcp.tcbhashsize */ #ifndef TCBHASHSIZE #define TCBHASHSIZE 512 @@ -124,14 +127,21 @@ struct inp_tp { void tcp_init() { - + int hashsize; + tcp_iss = random(); /* wrong, but better than a constant */ tcp_ccgen = 1; tcp_cleartaocache(); LIST_INIT(&tcb); tcbinfo.listhead = &tcb; - tcbinfo.hashbase = hashinit(TCBHASHSIZE, M_PCB, &tcbinfo.hashmask); - tcbinfo.porthashbase = hashinit(TCBHASHSIZE, M_PCB, + if (!(getenv_int("net.inet.tcp.tcbhashsize", &hashsize))) + hashsize = TCBHASHSIZE; + if ((1 << ffs(hashsize)) != hashsize) { + printf("WARNING: TCB hash size not a power of 2\n"); + hashsize = 512; /* safe default */ + } + tcbinfo.hashbase = hashinit(hashsize, M_PCB, &tcbinfo.hashmask); + tcbinfo.porthashbase = hashinit(hashsize, M_PCB, &tcbinfo.porthashmask); tcbinfo.ipi_zone = zinit("tcpcb", sizeof(struct inp_tp), maxsockets, ZONE_INTERRUPT, 0); -- cgit v1.1