summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2013-02-07 11:06:43 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2013-02-07 11:06:43 +0000
commitccc3b0acfd84f697d85577c0cad9be6252bea471 (patch)
tree609e4358952c4c63a3fcf6515a8782c08eea17c3
parent4d99011eaa1fc81387a4fea40f668600f4c97461 (diff)
convert mbuf tags to use pool(9) as a backend storage;
ok markus claudio haesbaert henning
-rw-r--r--sys/kern/uipc_mbuf.c7
-rw-r--r--sys/kern/uipc_mbuf2.c12
-rw-r--r--sys/sys/malloc.h7
-rw-r--r--sys/sys/mbuf.h10
4 files changed, 26 insertions, 10 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 4ec2bed41f1..0589ef9fa7c 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.167 2012/09/26 14:53:23 markus Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.168 2013/02/07 11:06:42 mikeb Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -99,6 +99,7 @@
struct mbstat mbstat; /* mbuf stats */
struct pool mbpool; /* mbuf pool */
+struct pool mtagpool;
/* mbuf cluster pools */
u_int mclsizes[] = {
@@ -150,6 +151,10 @@ mbinit(void)
pool_set_constraints(&mbpool, &kp_dma_contig);
pool_setlowat(&mbpool, mblowat);
+ pool_init(&mtagpool, PACKET_TAG_MAXSIZE + sizeof(struct m_tag),
+ 0, 0, 0, "mtagpl", NULL);
+ pool_setipl(&mtagpool, IPL_NET);
+
for (i = 0; i < nitems(mclsizes); i++) {
snprintf(mclnames[i], sizeof(mclnames[0]), "mcl%dk",
mclsizes[i] >> 10);
diff --git a/sys/kern/uipc_mbuf2.c b/sys/kern/uipc_mbuf2.c
index cca045d841b..dd954e78a74 100644
--- a/sys/kern/uipc_mbuf2.c
+++ b/sys/kern/uipc_mbuf2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf2.c,v 1.35 2011/11/30 10:26:56 dlg Exp $ */
+/* $OpenBSD: uipc_mbuf2.c,v 1.36 2013/02/07 11:06:42 mikeb Exp $ */
/* $KAME: uipc_mbuf2.c,v 1.29 2001/02/14 13:42:10 itojun Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */
@@ -68,6 +68,8 @@
#include <sys/malloc.h>
#include <sys/mbuf.h>
+extern struct pool mtagpool;
+
/* can't call it m_dup(), as freebsd[34] uses m_dup() with different arg */
static struct mbuf *m_dup1(struct mbuf *, int, int, int);
@@ -256,7 +258,9 @@ m_tag_get(int type, int len, int wait)
if (len < 0)
return (NULL);
- t = malloc(sizeof(struct m_tag) + len, M_PACKET_TAGS, wait);
+ if (len > PACKET_TAG_MAXSIZE)
+ panic("requested tag size for pool %#x is too big", type);
+ t = pool_get(&mtagpool, wait == M_WAITOK ? PR_WAITOK : PR_NOWAIT);
if (t == NULL)
return (NULL);
t->m_tag_id = type;
@@ -280,7 +284,7 @@ m_tag_delete(struct mbuf *m, struct m_tag *t)
struct m_tag *p;
SLIST_REMOVE(&m->m_pkthdr.tags, t, m_tag, m_tag_link);
- free(t, M_PACKET_TAGS);
+ pool_put(&mtagpool, t);
SLIST_FOREACH(p, &m->m_pkthdr.tags, m_tag_link)
tagsset |= p->m_tag_id;
@@ -296,7 +300,7 @@ m_tag_delete_chain(struct mbuf *m)
while ((p = SLIST_FIRST(&m->m_pkthdr.tags)) != NULL) {
SLIST_REMOVE_HEAD(&m->m_pkthdr.tags, m_tag_link);
- free(p, M_PACKET_TAGS);
+ pool_put(&mtagpool, p);
}
m->m_pkthdr.tagsset = 0;
}
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index 80e4c10c18c..04144461ad8 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: malloc.h,v 1.100 2012/04/06 15:10:40 jsing Exp $ */
+/* $OpenBSD: malloc.h,v 1.101 2013/02/07 11:06:42 mikeb Exp $ */
/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */
/*
@@ -143,8 +143,7 @@
#define M_CRYPTO_DATA 108 /* Crypto framework data buffers (keys etc.) */
/* 109 - free */
#define M_CREDENTIALS 110 /* IPsec-related credentials and ID info */
-#define M_PACKET_TAGS 111 /* Packet-attached information */
-/* 112-113 - free */
+/* 111-113 - free */
#define M_EMULDATA 114 /* Per-process emulation data */
/* 115-122 - free */
@@ -284,7 +283,7 @@
"crypto data", /* 108 M_CRYPTO_DATA */ \
NULL, \
"IPsec creds", /* 110 M_CREDENTIALS */ \
- "packet tags", /* 111 M_PACKET_TAGS */ \
+ NULL, \
NULL, \
NULL, \
"emuldata", /* 114 M_EMULDATA */ \
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 3267b2aa732..b5ec6425338 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.h,v 1.160 2013/01/16 10:38:27 deraadt Exp $ */
+/* $OpenBSD: mbuf.h,v 1.161 2013/02/07 11:06:42 mikeb Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
@@ -451,5 +451,13 @@ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
#define PACKET_TAG_PIPEX 0x0400 /* pipex session cache */
#define PACKET_TAG_PF_REASSEMBLED 0x0800 /* pf reassembled ipv6 packet */
+/*
+ * Maximum tag payload length (that is excluding the m_tag structure).
+ * Please make sure to update this value when increasing the payload
+ * length for an existing packet tag type or when adding a new one that
+ * has payload larger than the value below.
+ */
+#define PACKET_TAG_MAXSIZE 40
+
#endif /* _KERNEL */
#endif /* _SYS_MBUF_H_ */