From owner-svn-src-user@FreeBSD.ORG Tue Nov 13 16:48:52 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A8A9274C; Tue, 13 Nov 2012 16:48:52 +0000 (UTC) (envelope-from andre@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 706D98FC12; Tue, 13 Nov 2012 16:48:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qADGmq8v082289; Tue, 13 Nov 2012 16:48:52 GMT (envelope-from andre@svn.freebsd.org) Received: (from andre@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qADGmqMZ082288; Tue, 13 Nov 2012 16:48:52 GMT (envelope-from andre@svn.freebsd.org) Message-Id: <201211131648.qADGmqMZ082288@svn.freebsd.org> From: Andre Oppermann Date: Tue, 13 Nov 2012 16:48:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r242982 - user/andre/tcp_workqueue/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Nov 2012 16:48:52 -0000 Author: andre Date: Tue Nov 13 16:48:52 2012 New Revision: 242982 URL: http://svnweb.freebsd.org/changeset/base/242982 Log: Automatically scale the TCP control block hash that is used for INPCB lookup of incoming TCP packets to about 1/8 of maxsockets. Rename TCBHASHSIZE to TCBMINHASHSIZE to reflect its new purpose. Add TCBPORTHASHSIZE defaulting to 512 for INADDR_ANY listen ports. It is independent of maxsockets. Submitted by: alfred (previous version) Modified: user/andre/tcp_workqueue/sys/netinet/tcp_subr.c Modified: user/andre/tcp_workqueue/sys/netinet/tcp_subr.c ============================================================================== --- user/andre/tcp_workqueue/sys/netinet/tcp_subr.c Tue Nov 13 16:37:24 2012 (r242981) +++ user/andre/tcp_workqueue/sys/netinet/tcp_subr.c Tue Nov 13 16:48:52 2012 (r242982) @@ -229,13 +229,16 @@ static char * tcp_log_addr(struct in_con void *ip4hdr, const void *ip6hdr); /* - * Target size of TCP PCB hash tables. Must be a power of two. + * Minimal 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 +#ifndef TCBMINHASHSIZE +#define TCBMINHASHSIZE 512 +#endif +#ifndef TCBPORTHASHSIZE +#define TCBPORTHASHSIZE 512 #endif /* @@ -285,7 +288,6 @@ tcp_inpcb_init(void *mem, int size, int void tcp_init(void) { - int hashsize; if (hhook_head_register(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, &V_tcp_hhh[HHOOK_TCP_EST_IN], HHOOK_NOWAIT|HHOOK_HEADISINVNET) != 0) @@ -294,15 +296,17 @@ tcp_init(void) &V_tcp_hhh[HHOOK_TCP_EST_OUT], HHOOK_NOWAIT|HHOOK_HEADISINVNET) != 0) printf("%s: WARNING: unable to register helper hook\n", __func__); - hashsize = TCBHASHSIZE; - TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize); - if (!powerof2(hashsize)) { - printf("WARNING: TCB hash size not a power of 2\n"); - hashsize = 512; /* safe default */ - } - in_pcbinfo_init(&V_tcbinfo, "tcp", &V_tcb, hashsize, hashsize, - "tcp_inpcb", tcp_inpcb_init, NULL, UMA_ZONE_NOFREE, - IPI_HASHFIELDS_4TUPLE); + tcp_tcbhashsize = 0x1 << fls((maxsockets / 8) - 1); + TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &tcp_tcbhashsize); + if (!powerof2(tcp_tcbhashsize) || + tcp_tcbhashsize < TCBMINHASHSIZE) { + printf("WARNING: TCB hash size not a power of 2 or too small\n"); + tcp_tcbhashsize = TCBMINHASHSIZE; + } + + in_pcbinfo_init(&V_tcbinfo, "tcp", &V_tcb, tcp_tcbhashsize, + TCBPORTHASHSIZE, "tcp_inpcb", tcp_inpcb_init, NULL, + UMA_ZONE_NOFREE, IPI_HASHFIELDS_4TUPLE); /* * These have to be type stable for the benefit of the timers. @@ -336,7 +340,6 @@ tcp_init(void) tcp_rexmit_min = 1; tcp_rexmit_slop = TCPTV_CPU_VAR; tcp_finwait2_timeout = TCPTV_FINWAIT2_TIMEOUT; - tcp_tcbhashsize = hashsize; TUNABLE_INT_FETCH("net.inet.tcp.soreceive_stream", &tcp_soreceive_stream); if (tcp_soreceive_stream) {