git: 29b4b63c5912 - main - ip_reass: optimize ipreass_drain_vnet()

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Sat, 10 Sep 2022 09:34:39 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=29b4b63c591224912997aa1ee0c5e2b5587be1b6

commit 29b4b63c591224912997aa1ee0c5e2b5587be1b6
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-09-10 09:11:39 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-09-10 09:17:15 +0000

    ip_reass: optimize ipreass_drain_vnet()
    
    - Call ipreass_reschedule() only once per slot [1]
    - Aggregate stats and update them once
    
    Suggested by:   jtl [1]
---
 sys/netinet/ip_reass.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sys/netinet/ip_reass.c b/sys/netinet/ip_reass.c
index aa5c99a3624c..a10dff9c8acb 100644
--- a/sys/netinet/ip_reass.c
+++ b/sys/netinet/ip_reass.c
@@ -633,16 +633,27 @@ ipreass_reschedule(struct ipqbucket *bucket)
 static void
 ipreass_drain_vnet(void)
 {
+	u_int dropped = 0;
 
 	for (int i = 0; i < V_ipq_hashsize; i++) {
+		bool resched;
+
 		IPQ_LOCK(i);
-		while(!TAILQ_EMPTY(&V_ipq[i].head))
-			ipq_drop(&V_ipq[i], TAILQ_FIRST(&V_ipq[i].head));
+		resched = !TAILQ_EMPTY(&V_ipq[i].head);
+		while(!TAILQ_EMPTY(&V_ipq[i].head)) {
+			struct ipq *fp = TAILQ_FIRST(&V_ipq[i].head);
+
+			dropped += fp->ipq_nfrags;
+			ipq_free(&V_ipq[i], fp);
+		}
+		if (resched)
+			ipreass_reschedule(&V_ipq[i]);
 		KASSERT(V_ipq[i].count == 0,
 		    ("%s: V_ipq[%d] count %d (V_ipq=%p)", __func__, i,
 		    V_ipq[i].count, V_ipq));
 		IPQ_UNLOCK(i);
 	}
+	IPSTAT_ADD(ips_fragdropped, dropped);
 }
 
 /*