git: 87ef3067acbd - main - tcp lro: use hashalloc(9)

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Sun, 12 Apr 2026 17:40:01 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=87ef3067acbddbf85f0bdef6d53bdde2b51cbc50

commit 87ef3067acbddbf85f0bdef6d53bdde2b51cbc50
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-04-12 17:26:12 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-04-12 17:26:12 +0000

    tcp lro: use hashalloc(9)
    
    Reviewed by:            tuexen, rrs
    Differential Revision:  https://reviews.freebsd.org/D56177
---
 sys/netinet/tcp_lro.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/sys/netinet/tcp_lro.c b/sys/netinet/tcp_lro.c
index 59358db6ecf9..06280bce2279 100644
--- a/sys/netinet/tcp_lro.c
+++ b/sys/netinet/tcp_lro.c
@@ -44,6 +44,7 @@
 #include <sys/socketvar.h>
 #include <sys/sockbuf.h>
 #include <sys/sysctl.h>
+#include <sys/hash.h>
 
 #include <net/if.h>
 #include <net/if_var.h>
@@ -190,13 +191,19 @@ tcp_lro_init_args(struct lro_ctrl *lc, struct ifnet *ifp,
 	LIST_INIT(&lc->lro_free);
 	LIST_INIT(&lc->lro_active);
 
-	/* create hash table to accelerate entry lookup */
-	lc->lro_hash = phashinit_flags(lro_entries, M_LRO, &lc->lro_hashsz,
-	    HASH_NOWAIT);
+	/* Create hash table to accelerate entry lookup. */
+	struct hashalloc_args ha = {
+		.size = lro_entries,
+		.mtype = M_LRO,
+		.mflags = M_NOWAIT,
+		.type = HASH_TYPE_PRIME,
+	};
+	lc->lro_hash = hashalloc(&ha);
 	if (lc->lro_hash == NULL) {
 		memset(lc, 0, sizeof(*lc));
 		return (ENOMEM);
 	}
+	lc->lro_hashsz = ha.size;
 
 	/* compute size to allocate */
 	size = (lro_mbufs * sizeof(struct lro_mbuf_sort)) +
@@ -206,7 +213,11 @@ tcp_lro_init_args(struct lro_ctrl *lc, struct ifnet *ifp,
 
 	/* check for out of memory */
 	if (lc->lro_mbuf_data == NULL) {
-		free(lc->lro_hash, M_LRO);
+		struct hashalloc_args ha = {
+			.size = lc->lro_hashsz,
+			.mtype = M_LRO,
+		};
+		hashfree(lc->lro_hash, &ha);
 		memset(lc, 0, sizeof(*lc));
 		return (ENOMEM);
 	}
@@ -503,8 +514,11 @@ tcp_lro_free(struct lro_ctrl *lc)
 		lro_free_mbuf_chain(le->m_head);
 	}
 
-	/* free hash table */
-	free(lc->lro_hash, M_LRO);
+	struct hashalloc_args ha = {
+		.size = lc->lro_hashsz,
+		.mtype = M_LRO,
+	};
+	hashfree(lc->lro_hash, &ha);
 	lc->lro_hash = NULL;
 	lc->lro_hashsz = 0;