git: 379f41a117eb - stable/13 - tcp: Simplify the initialization of loader tunable 'net.inet.tcp.tcbhashsize'

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Mon, 16 Oct 2023 15:44:37 UTC
The branch stable/13 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=379f41a117eb8aaf1dd43414658606d2ef0534a7

commit 379f41a117eb8aaf1dd43414658606d2ef0534a7
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-10-08 10:03:59 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-10-16 15:38:26 +0000

    tcp: Simplify the initialization of loader tunable 'net.inet.tcp.tcbhashsize'
    
    No functional change intended.
    
    Reviewed by:    cc, rscheff, #transport
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D41998
    
    (cherry picked from commit 38ecc80b2a4e5e11ece83ca4df63632f0b6fa394)
    (cherry picked from commit 3a97686fc11ae51ceb4004c07702a8a20f71410d)
---
 sys/netinet/tcp_subr.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 905a72dd1f91..9bf02d21a307 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -299,8 +299,17 @@ static int	tcp_log_debug = 0;
 SYSCTL_INT(_net_inet_tcp, OID_AUTO, log_debug, CTLFLAG_RW,
     &tcp_log_debug, 0, "Log errors caused by incoming TCP segments");
 
-static int	tcp_tcbhashsize;
-SYSCTL_INT(_net_inet_tcp, OID_AUTO, tcbhashsize, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
+/*
+ * 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");
 
 static int	do_tcpdrain = 1;
@@ -1052,16 +1061,6 @@ tcp_default_fb_fini(struct tcpcb *tp, int tcb_is_purged)
 	return;
 }
 
-/*
- * 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
-
 /*
  * XXX
  * Callouts should be moved into struct tcp directly.  They are currently
@@ -1374,11 +1373,8 @@ deregister_tcp_functions(struct tcp_function_block *blk, bool quiesce,
 void
 tcp_init(void)
 {
-	const char *tcbhash_tuneable;
 	int hashsize;
 
-	tcbhash_tuneable = "net.inet.tcp.tcbhashsize";
-
 #ifdef TCP_HHOOK
 	if (hhook_head_register(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN,
 	    &V_tcp_hhh[HHOOK_TCP_EST_IN], HHOOK_NOWAIT|HHOOK_HEADISINVNET) != 0)
@@ -1392,8 +1388,7 @@ tcp_init(void)
 		printf("%s: WARNING: unable to initialise TCP stats\n",
 		    __func__);
 #endif
-	hashsize = TCBHASHSIZE;
-	TUNABLE_INT_FETCH(tcbhash_tuneable, &hashsize);
+	hashsize = tcp_tcbhashsize;
 	if (hashsize == 0) {
 		/*
 		 * Auto tune the hash size based on maxsockets.
@@ -1410,7 +1405,7 @@ tcp_init(void)
 			hashsize = 512;
 		if (bootverbose && IS_DEFAULT_VNET(curvnet))
 			printf("%s: %s auto tuned to %d\n", __func__,
-			    tcbhash_tuneable, hashsize);
+			    "net.inet.tcp.tcbhashsize", hashsize);
 	}
 	/*
 	 * We require a hashsize to be a power of two.