Page MenuHomeFreeBSD

D62466.1796539896.diff
No OneTemporary

Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None

D62466.1796539896.diff

diff --git a/share/man/man4/tcp.4 b/share/man/man4/tcp.4
--- a/share/man/man4/tcp.4
+++ b/share/man/man4/tcp.4
@@ -1016,14 +1016,16 @@
.It Va tcbhashsize
Size of the
.Tn TCP
-control-block hash table
-(read-only).
-This is tuned using the kernel option
-.Dv TCBHASHSIZE
-or by setting
-.Va net.inet.tcp.tcbhashsize
-in the
-.Xr loader 8 .
+control-block hash table for connected sockets.
+The default automatically tuned value is 1/4 of
+.Va kern.ipc.maxsockets .
+A manually tuned value would be rounded down to closest power of 2.
+.It Va wildhashsize
+Size of the
+.Tn TCP
+control-block hash table for wildcard sockets.
+The default automatically tuned value is number of CPUs in the system.
+A manually tuned value would be rounded down to closest power of 2.
.It Va tolerate_missing_ts
Tolerate the missing of timestamps (RFC 1323/RFC 7323) for
.Tn TCP
diff --git a/share/man/man4/udp.4 b/share/man/man4/udp.4
--- a/share/man/man4/udp.4
+++ b/share/man/man4/udp.4
@@ -130,6 +130,18 @@
MIB, which can be also read or modified with
.Xr sysctl 8 :
.Bl -tag -width ".Va log_in_vain"
+.It Va udbhashsize
+Size of the
+.Tn UDP
+control-block hash table for connected sockets.
+The default value is 128.
+A manually tuned value would be rounded down to closest power of 2.
+.It Va wildhashsize
+Size of the
+.Tn UDP
+control-block hash table for wildcard sockets.
+The default automatically tuned value is number of CPUs in the system.
+A manually tuned value would be rounded down to closest power of 2.
.It Va blackhole
When a datagram is received on a port where there is no socket
listening, do not return an ICMP port unreachable message.
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -611,7 +611,7 @@
#define V_ipport_hilastauto VNET(ipport_hilastauto)
void in_pcbinfo_init(struct inpcbinfo *, struct inpcbstorage *,
- u_int, u_int, u_int, u_int);
+ u_int *, u_int *, u_int *, u_int *);
void in_pcbinfo_destroy(struct inpcbinfo *);
void in_pcbstorage_init(void *);
void in_pcbstorage_destroy(void *);
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -549,11 +549,14 @@
/*
* Initialize an inpcbinfo - a per-VNET instance of connections db.
+ *
+ * NB: hash sizes will be updated to powerof2(). Callers may pass same pointer
+ * to different sizes, but should be ready for the side effect.
*/
void
in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor,
- u_int hash_nelements, u_int wildhash_nelements, u_int porthash_nelements,
- u_int lbgrouphash_nelements)
+ u_int *hash_nelements, u_int *wildhash_nelements, u_int *porthash_nelements,
+ u_int *lbgrouphash_nelements)
{
struct hashalloc_args ha = {
.mtype = M_PCB,
@@ -563,36 +566,42 @@
.lopts = MTX_DEF,
};
+ MPASS(hash_nelements);
+
mtx_init(&pcbinfo->ipi_list_unconn.lock, pcbstor->ips_hashlock_name,
NULL, MTX_DEF);
CK_LIST_INIT(&pcbinfo->ipi_list_unconn.head);
pcbinfo->ipi_count = 0;
- ha.size = hash_nelements;
+ ha.size = *hash_nelements;
ha.lname = "inpcb_exact_bucket";
pcbinfo->ipi_hash_exact = hashalloc(&ha);
pcbinfo->ipi_hashmask = ha.size - 1;
+ *hash_nelements = ha.size;
- if (wildhash_nelements > 0) {
- ha.size = wildhash_nelements;
+ if (wildhash_nelements != NULL) {
+ ha.size = *wildhash_nelements;
ha.lname = "inpcb_wild_bucket";
pcbinfo->ipi_hash_wild = hashalloc(&ha);
pcbinfo->ipi_wildhashmask = ha.size - 1;
+ *wildhash_nelements = ha.size;
} else
pcbinfo->ipi_hash_wild = NULL;
- if (porthash_nelements > 0) {
- ha.size = imin(porthash_nelements, IPPORT_MAX + 1);
+ if (porthash_nelements != NULL) {
+ ha.size = imin(*porthash_nelements, IPPORT_MAX + 1);
ha.lname = "inpcb_port_bucket";
pcbinfo->ipi_porthash = hashalloc(&ha);
pcbinfo->ipi_porthashmask = ha.size - 1;
+ *porthash_nelements = ha.size;
} else
pcbinfo->ipi_porthash = NULL;
- if (lbgrouphash_nelements > 0) {
- ha.size = imin(lbgrouphash_nelements, IPPORT_MAX + 1);
+ if (lbgrouphash_nelements != NULL) {
+ ha.size = imin(*lbgrouphash_nelements, IPPORT_MAX + 1);
ha.lname = "inpcb_lbgroup_bucket";
pcbinfo->ipi_lbgrouphashbase = hashalloc(&ha);
pcbinfo->ipi_lbgrouphashmask = ha.size - 1;
+ *lbgrouphash_nelements = ha.size;
} else
pcbinfo->ipi_lbgrouphashbase = NULL;
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -146,9 +146,9 @@
static void
rip_init(void *arg __unused)
{
-#define INP_PCBHASH_RAW_SIZE 256
- in_pcbinfo_init(&V_ripcbinfo, &ripcbstor, INP_PCBHASH_RAW_SIZE,
- 0, 0, 0);
+ u_int size = 256;
+
+ in_pcbinfo_init(&V_ripcbinfo, &ripcbstor, &size, NULL, NULL, NULL);
}
VNET_SYSINIT(rip_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, rip_init, NULL);
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -62,7 +62,7 @@
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <sys/random.h>
-
+#include <sys/smp.h>
#include <vm/uma.h>
#include <net/route.h>
@@ -256,18 +256,15 @@
SYSCTL_INT(_net_inet_tcp, OID_AUTO, log_debug, CTLFLAG_RW,
&tcp_log_debug, 0, "Log errors caused by incoming TCP segments");
-/*
- * 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 0
-#endif
-static int tcp_tcbhashsize = TCBHASHSIZE;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, tcbhashsize, CTLFLAG_RDTUN,
- &tcp_tcbhashsize, 0, "Size of TCP control-block hashtable");
+VNET_DEFINE_STATIC(u_int, tcp_tcbhashsize);
+#define V_tcp_tcbhashsize VNET(tcp_tcbhashsize)
+SYSCTL_UINT(_net_inet_tcp, OID_AUTO, tcbhashsize, CTLFLAG_VNET | CTLFLAG_RDTUN,
+ &VNET_NAME(tcp_tcbhashsize), 0, "Size of TCP hash table (specific)");
+
+VNET_DEFINE_STATIC(u_int, tcp_wildhashsize);
+#define V_tcp_wildhashsize VNET(tcp_wildhashsize)
+SYSCTL_UINT(_net_inet_tcp, OID_AUTO, wildhashsize, CTLFLAG_VNET | CTLFLAG_RDTUN,
+ &VNET_NAME(tcp_wildhashsize), 0, "Size of TCP hash table (wildcard)");
static int do_tcpdrain = 1;
SYSCTL_INT(_net_inet_tcp, OID_AUTO, do_tcpdrain, CTLFLAG_RW, &do_tcpdrain, 0,
@@ -1141,27 +1138,6 @@
INPCBSTORAGE_DEFINE(tcpcbstor, tcpcb, "tcpinp", "tcp_inpcb", "tcphash");
-/*
- * Take a value and get the next power of 2 that doesn't overflow.
- * Used to size the tcp_inpcb hash buckets.
- */
-static int
-maketcp_hashsize(int size)
-{
- int hashsize;
-
- /*
- * auto tune.
- * get the next power of 2 higher than maxsockets.
- */
- hashsize = 1 << fls(size);
- /* catch overflow, and just go one power of 2 smaller */
- if (hashsize < size) {
- hashsize = 1 << (fls(size) - 1);
- }
- return (hashsize);
-}
-
static volatile int next_tcp_stack_id = 1;
/*
@@ -1435,6 +1411,7 @@
static void
tcp_vnet_init(void *arg __unused)
{
+ u_int porthashsize = IPPORT_MAX + 1;
#ifdef TCP_HHOOK
if (hhook_head_register(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN,
@@ -1449,8 +1426,12 @@
printf("%s: WARNING: unable to initialise TCP stats\n",
__func__);
#endif
- in_pcbinfo_init(&V_tcbinfo, &tcpcbstor, tcp_tcbhashsize,
- tcp_tcbhashsize, tcp_tcbhashsize, tcp_tcbhashsize);
+ if (V_tcp_tcbhashsize == 0)
+ V_tcp_tcbhashsize = maxsockets / 4;
+ if (V_tcp_wildhashsize == 0)
+ V_tcp_wildhashsize = mp_ncpus;
+ in_pcbinfo_init(&V_tcbinfo, &tcpcbstor, &V_tcp_tcbhashsize,
+ &V_tcp_wildhashsize, &porthashsize, &porthashsize);
syncache_init();
tcp_hc_init();
@@ -1472,7 +1453,6 @@
static void
tcp_init(void *arg __unused)
{
- int hashsize;
tcp_reass_global_init();
@@ -1531,46 +1511,6 @@
tcp_pacing_failures = counter_u64_alloc(M_WAITOK);
tcp_dgp_failures = counter_u64_alloc(M_WAITOK);
- hashsize = tcp_tcbhashsize;
- if (hashsize == 0) {
- /*
- * Auto tune the hash size based on maxsockets.
- * A perfect hash would have a 1:1 mapping
- * (hashsize = maxsockets) however it's been
- * suggested that O(2) average is better.
- */
- hashsize = maketcp_hashsize(maxsockets / 4);
- /*
- * Our historical default is 512,
- * do not autotune lower than this.
- */
- if (hashsize < 512)
- hashsize = 512;
- if (bootverbose)
- printf("%s: %s auto tuned to %d\n", __func__,
- "net.inet.tcp.tcbhashsize", hashsize);
- }
- /*
- * We require a hashsize to be a power of two.
- * Previously if it was not a power of two we would just reset it
- * back to 512, which could be a nasty surprise if you did not notice
- * the error message.
- * Instead what we do is clip it to the closest power of two lower
- * than the specified hash value.
- */
- if (!powerof2(hashsize)) {
- int oldhashsize = hashsize;
-
- hashsize = maketcp_hashsize(hashsize);
- /* prevent absurdly low value */
- if (hashsize < 16)
- hashsize = 16;
- printf("%s: WARNING: TCB hash size not a power of 2, "
- "clipped from %d to %d.\n", __func__, oldhashsize,
- hashsize);
- }
- tcp_tcbhashsize = hashsize;
-
#ifdef INET
IPPROTO_REGISTER(IPPROTO_TCP, tcp_input, tcp_ctlinput);
#endif
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -60,7 +60,7 @@
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/systm.h>
-
+#include <sys/smp.h>
#include <vm/uma.h>
#include <net/if.h>
@@ -149,10 +149,6 @@
VNET_DEFINE(struct inpcbinfo, udbinfo);
VNET_DEFINE(struct inpcbinfo, ulitecbinfo);
-#ifndef UDBHASHSIZE
-#define UDBHASHSIZE 128
-#endif
-
VNET_PCPUSTAT_DEFINE(struct udpstat, udpstat); /* from udp_var.h */
VNET_PCPUSTAT_SYSINIT(udpstat);
SYSCTL_VNET_PCPUSTAT(_net_inet_udp, UDPCTL_STATS, stats, struct udpstat,
@@ -169,9 +165,20 @@
INPCBSTORAGE_DEFINE(udplitecbstor, udpcb, "udpliteinp", "udplite_inpcb",
"udplitehash");
+VNET_DEFINE_STATIC(u_int, udp_udbhashsize);
+#define V_udp_udbhashsize VNET(udp_udbhashsize)
+SYSCTL_UINT(_net_inet_udp, OID_AUTO, udbhashsize, CTLFLAG_VNET | CTLFLAG_RDTUN,
+ &VNET_NAME(udp_udbhashsize), 0, "Size of UDP hash table (specific)");
+
+VNET_DEFINE_STATIC(u_int, udp_wildhashsize);
+#define V_udp_wildhashsize VNET(udp_wildhashsize)
+SYSCTL_UINT(_net_inet_udp, OID_AUTO, wildhashsize, CTLFLAG_VNET | CTLFLAG_RDTUN,
+ &VNET_NAME(udp_wildhashsize), 0, "Size of UDP hash table (wildcard)");
+
static void
udp_vnet_init(void *arg __unused)
{
+ u_int porthashsize = IPPORT_MAX + 1;
/*
* For now default to 2-tuple UDP hashing - until the fragment
@@ -180,11 +187,15 @@
* Once we can calculate the flowid that way and re-establish
* a 4-tuple, flip this to 4-tuple.
*/
- in_pcbinfo_init(&V_udbinfo, &udpcbstor, UDBHASHSIZE, UDBHASHSIZE,
- UDBHASHSIZE, UDBHASHSIZE);
+ if (V_udp_udbhashsize == 0)
+ V_udp_udbhashsize = 128;
+ if (V_udp_wildhashsize == 0)
+ V_udp_wildhashsize = mp_ncpus;
+ in_pcbinfo_init(&V_udbinfo, &udpcbstor, &V_udp_udbhashsize,
+ &V_udp_wildhashsize, &porthashsize, &porthashsize);
/* Additional pcbinfo for UDP-Lite */
- in_pcbinfo_init(&V_ulitecbinfo, &udplitecbstor, UDBHASHSIZE,
- UDBHASHSIZE, UDBHASHSIZE, UDBHASHSIZE);
+ in_pcbinfo_init(&V_ulitecbinfo, &udplitecbstor, &V_udp_udbhashsize,
+ &V_udp_wildhashsize, &porthashsize, &porthashsize);
}
VNET_SYSINIT(udp_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH,
udp_vnet_init, NULL);

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 6, 6:51 AM (17 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42248570
Default Alt Text
D62466.1796539896.diff (11 KB)

Event Timeline