diff --git a/sys/conf/param.c b/sys/conf/param.c index 9765310..003695c 100644 --- a/sys/conf/param.c +++ b/sys/conf/param.c @@ -149,6 +149,11 @@ int mblowat = MBLOWAT; #endif int mcllowat = MCLLOWAT; +#ifndef MTAGLOWAT +#define MTAGLOWAT 4 +#endif +int mtaglowat = MTAGLOWAT; + #if XXX_PRG /* * Values in support of System V compatible shared memory. XXX diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index f2056da..98e17d5 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -89,6 +89,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.163 2015/08/24 22:21:26 pooka Exp $" pool_cache_t mb_cache; /* mbuf cache */ pool_cache_t mcl_cache; /* mbuf cluster cache */ +pool_cache_t mtag_cache;/* m_tag cache */ struct mbstat mbstat; int max_linkhdr; @@ -190,8 +191,13 @@ mbinit(void) IPL_VM, NULL, NULL, NULL); KASSERT(mcl_cache != NULL); + mtag_cache = pool_cache_init(PACKET_TAG_MAXSIZE + sizeof(struct m_tag), + 0, 0, 0, "mtagpl", NULL, IPL_VM, NULL, NULL, NULL); + KASSERT(mtag_cache != NULL); + pool_cache_set_drain_hook(mb_cache, m_reclaim, NULL); pool_cache_set_drain_hook(mcl_cache, m_reclaim, NULL); + pool_cache_set_drain_hook(mtag_cache, m_reclaim, NULL); /* * Set an arbitrary default limit on the number of mbuf clusters. @@ -221,6 +227,7 @@ mbinit(void) */ pool_cache_setlowat(mb_cache, mblowat); pool_cache_setlowat(mcl_cache, mcllowat); + pool_cache_setlowat(mtag_cache, mtaglowat); #ifdef MBUFTRACE { @@ -253,6 +260,7 @@ sysctl_kern_mbuf(SYSCTLFN_ARGS) case MBUF_NMBCLUSTERS: case MBUF_MBLOWAT: case MBUF_MCLLOWAT: + case MBUF_MTAGLOWAT: newval = *(int*)rnode->sysctl_data; break; default: @@ -283,6 +291,10 @@ sysctl_kern_mbuf(SYSCTLFN_ARGS) mcllowat = newval; pool_cache_setlowat(mcl_cache, mcllowat); break; + case MBUF_MTAGLOWAT: + mtaglowat = newval; + pool_cache_setlowat(mtag_cache, mtaglowat); + break; } return (0); @@ -427,6 +439,12 @@ sysctl_kern_mbuf_setup(void) sysctl_kern_mbuf, 0, &mcllowat, 0, CTL_KERN, KERN_MBUF, MBUF_MCLLOWAT, CTL_EOL); sysctl_createv(&mbuf_sysctllog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "mtaglowat", + SYSCTL_DESCR("mtag low water mark"), + sysctl_kern_mbuf, 0, &mtaglowat, 0, + CTL_KERN, KERN_MBUF, MBUF_MTAGLOWAT, CTL_EOL); + sysctl_createv(&mbuf_sysctllog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_STRUCT, "stats", SYSCTL_DESCR("mbuf allocation statistics"), diff --git a/sys/kern/uipc_mbuf2.c b/sys/kern/uipc_mbuf2.c index 2e770ab..cb1debc 100644 --- a/sys/kern/uipc_mbuf2.c +++ b/sys/kern/uipc_mbuf2.c @@ -67,10 +67,8 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_mbuf2.c,v 1.30 2013/10/08 19:59:49 christos Exp #include #include #include -#include #include - -MALLOC_DEFINE(M_PACKET_TAGS, "packet tags", "Packet-attached information"); +#include /* * ensure that [off, off + len) is contiguous on the mbuf chain "m". @@ -260,7 +258,10 @@ m_tag_get(int type, int len, int wait) if (len < 0) return (NULL); - t = malloc(len + sizeof(struct m_tag), M_PACKET_TAGS, wait); + if (len > PACKET_TAG_MAXSIZE) + panic("request tag size for pool %#x is too big", type); + t = pool_cache_get(mtag_cache, + wait == M_NOWAIT ? PR_NOWAIT : PR_WAITOK); if (t == NULL) return (NULL); t->m_tag_id = type; @@ -273,7 +274,7 @@ void m_tag_free(struct m_tag *t) { - free(t, M_PACKET_TAGS); + pool_cache_put(mtag_cache, t); } /* Prepend a packet tag. */ diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 75f4d64..58242db 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -789,7 +789,8 @@ struct mbstat_cpu { #define MBUF_MCLLOWAT 5 /* int: mbuf cluster low water mark */ #define MBUF_STATS 6 /* struct: mbstat */ #define MBUF_MOWNERS 7 /* struct: m_owner[] */ -#define MBUF_MAXID 8 /* number of valid MBUF ids */ +#define MBUF_MTAGLOWAT 8 /* int: mtag low water mark */ +#define MBUF_MAXID 9 /* number of valid MBUF ids */ #define CTL_MBUF_NAMES { \ { 0, 0 }, \ @@ -800,6 +801,7 @@ struct mbstat_cpu { { "mcllowat", CTLTYPE_INT }, \ { 0 /* "stats" */, CTLTYPE_STRUCT }, \ { 0 /* "mowners" */, CTLTYPE_STRUCT }, \ + { "mtaglowat", CTLTYPE_INT }, \ } #ifdef _KERNEL @@ -807,6 +809,7 @@ extern struct mbstat mbstat; extern int nmbclusters; /* limit on the # of clusters */ extern int mblowat; /* mbuf low water mark */ extern int mcllowat; /* mbuf cluster low water mark */ +extern int mtaglowat; /* mtag low water mark */ extern int max_linkhdr; /* largest link-level header */ extern int max_protohdr; /* largest protocol header */ extern int max_hdr; /* largest link+protocol header */ @@ -815,6 +818,7 @@ extern const int msize; /* mbuf base size */ extern const int mclbytes; /* mbuf cluster size */ extern pool_cache_t mb_cache; extern pool_cache_t mcl_cache; +extern pool_cache_t mtag_cache; #ifdef MBUFTRACE LIST_HEAD(mownerhead, mowner); extern struct mownerhead mowners; @@ -917,6 +921,16 @@ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); #define PACKET_TAG_MPLS 29 /* Indicate it's for MPLS */ /* + * 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. + * + * Currently, max size is equals to sizeof(struct tdb_ident). + */ +#define PACKET_TAG_MAXSIZE 36 + +/* * Return the number of bytes in the mbuf chain, m. */ static __inline u_int