PERFORCE change 42098 for review

Robert Watson rwatson at FreeBSD.org
Tue Nov 11 20:32:52 PST 2003


http://perforce.freebsd.org/chv.cgi?CH=42098

Change 42098 by rwatson at rwatson_tislabs on 2003/11/11 20:32:06

	Switch Biba and MLS to using UMA zones to allocate labels from,
	rather than malloc(), which should give more efficient use of
	memory.

Affected files ...

.. //depot/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c#231 edit
.. //depot/projects/trustedbsd/mac/sys/security/mac_mls/mac_mls.c#186 edit

Differences ...

==== //depot/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c#231 (text+ko) ====

@@ -77,6 +77,7 @@
 #include <netinet/in.h>
 #include <netinet/ip_var.h>
 
+#include <vm/uma.h>
 #include <vm/vm.h>
 
 #include <sys/mac_policy.h>
@@ -130,7 +131,7 @@
 static int	mac_biba_slot;
 #define	SLOT(l)	((struct mac_biba *)LABEL_TO_SLOT((l), mac_biba_slot).l_ptr)
 
-MALLOC_DEFINE(M_MACBIBA, "biba label", "MAC/Biba labels");
+static uma_zone_t	zone_biba;
 
 static __inline int
 biba_bit_set_empty(u_char *set) {
@@ -145,11 +146,8 @@
 static struct mac_biba *
 biba_alloc(int flag)
 {
-	struct mac_biba *mac_biba;
 
-	mac_biba = malloc(sizeof(struct mac_biba), M_MACBIBA, M_ZERO | flag);
-
-	return (mac_biba);
+	return (uma_zalloc(zone_biba, flag));
 }
 
 static void
@@ -157,7 +155,7 @@
 {
 
 	if (mac_biba != NULL)
-		free(mac_biba, M_MACBIBA);
+		uma_zfree(zone_biba, mac_biba);
 	else
 		atomic_add_int(&destroyed_not_inited, 1);
 }
@@ -498,6 +496,8 @@
 mac_biba_init(struct mac_policy_conf *conf)
 {
 
+	zone_biba = uma_zcreate("mac_biba", sizeof(struct mac_biba), NULL,
+	    NULL, NULL, NULL, UMA_ALIGN_PTR, M_ZERO);
 }
 
 /*

==== //depot/projects/trustedbsd/mac/sys/security/mac_mls/mac_mls.c#186 (text+ko) ====

@@ -77,6 +77,7 @@
 #include <netinet/in.h>
 #include <netinet/ip_var.h>
 
+#include <vm/uma.h>
 #include <vm/vm.h>
 
 #include <sys/mac_policy.h>
@@ -118,7 +119,7 @@
 static int	mac_mls_slot;
 #define	SLOT(l)	((struct mac_mls *)LABEL_TO_SLOT((l), mac_mls_slot).l_ptr)
 
-MALLOC_DEFINE(M_MACMLS, "mls label", "MAC/MLS labels");
+static uma_zone_t	zone_mls;
 
 static __inline int
 mls_bit_set_empty(u_char *set) {
@@ -133,11 +134,8 @@
 static struct mac_mls *
 mls_alloc(int flag)
 {
-	struct mac_mls *mac_mls;
 
-	mac_mls = malloc(sizeof(struct mac_mls), M_MACMLS, M_ZERO | flag);
-
-	return (mac_mls);
+	return (uma_zalloc(zone_mls, flag));
 }
 
 static void
@@ -145,7 +143,7 @@
 {
 
 	if (mac_mls != NULL)
-		free(mac_mls, M_MACMLS);
+		uma_zfree(zone_mls, mac_mls);
 	else
 		atomic_add_int(&destroyed_not_inited, 1);
 }
@@ -463,6 +461,8 @@
 mac_mls_init(struct mac_policy_conf *conf)
 {
 
+	zone_mls = uma_zcreate("mac_mls", sizeof(struct mac_mls), NULL,
+	    NULL, NULL, NULL, UMA_ALIGN_PTR, M_ZERO);
 }
 
 /*


More information about the p4-projects mailing list