Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jan 2005 03:28:15 +0000
From:      "Christian S.J. Peron" <csjp@FreeBSD.org>
To:        ipfw@freebsd.org
Cc:        rwatson@freebsd.org
Subject:   [patch] changed state allocations to use UMA
Message-ID:  <20050102032815.GA58777@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

I have generated a patch which changes the state allocation in IPFW
from malloc(9) to uma_zcreate(9).

This should minimize memory wastage associated with firewall
states and improve the performance of state creation, destruction
and in lookups.

Anyone have any problems with this patch being committed?

http://people.freebsd.org/~csjp/ip_fw2.c.uma_zone.1104636041.diff

Index: ip_fw2.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_fw2.c,v
retrieving revision 1.85
diff -u -r1.85 ip_fw2.c
--- ip_fw2.c	10 Dec 2004 02:17:18 -0000	1.85
+++ ip_fw2.c	2 Jan 2005 03:21:04 -0000
@@ -101,6 +101,7 @@
 static int verbose_limit;
 
 static struct callout ipfw_timeout;
+static uma_zone_t ipfw_dyn_rule_zone;
 #define	IPFW_DEFAULT_RULE	65535
 
 /*
@@ -782,7 +783,7 @@
 	else								\
 		head = q = q->next;					\
 	dyn_count--;							\
-	free(old_q, M_IPFW); }
+	uma_zfree(ipfw_dyn_rule_zone, old_q); }
 
 #define TIME_LEQ(a,b)       ((int)((a)-(b)) <= 0)
 
@@ -1058,7 +1059,7 @@
 	}
 	i = hash_packet(id);
 
-	r = malloc(sizeof *r, M_IPFW, M_NOWAIT | M_ZERO);
+	r = uma_zalloc(ipfw_dyn_rule_zone, M_NOWAIT | M_ZERO);
 	if (r == NULL) {
 		printf ("ipfw: sorry cannot allocate state\n");
 		return NULL;
@@ -3504,6 +3505,9 @@
 	layer3_chain.busy_count = 0;
 	cv_init(&layer3_chain.cv, "Condition variable for IPFW rw locks");
 	IPFW_LOCK_INIT(&layer3_chain);
+	ipfw_dyn_rule_zone = uma_zcreate("IPFW dynamic rule zone",
+	    sizeof(ipfw_dyn_rule), NULL, NULL, NULL, NULL,
+	    UMA_ALIGN_PTR, 0);
 	IPFW_DYN_LOCK_INIT();
 	callout_init(&ipfw_timeout, debug_mpsafenet ? CALLOUT_MPSAFE : 0);
 
@@ -3585,6 +3589,7 @@
 		reap_rules(reap);
 	flush_tables();
 	IPFW_DYN_LOCK_DESTROY();
+	uma_zdestroy(ipfw_dyn_rule_zone);
 	IPFW_LOCK_DESTROY(&layer3_chain);
 	printf("IP firewall unloaded\n");
 }

-- 
Christian S.J. Peron
csjp@FreeBSD.ORG
FreeBSD Committer



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050102032815.GA58777>