From owner-freebsd-net@FreeBSD.ORG Mon Dec 19 14:45:45 2005 Return-Path: X-Original-To: net@FreeBSD.org Delivered-To: freebsd-net@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1C3F016A41F; Mon, 19 Dec 2005 14:45:45 +0000 (GMT) (envelope-from glebius@FreeBSD.org) Received: from cell.sick.ru (cell.sick.ru [217.72.144.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5A45E43D5E; Mon, 19 Dec 2005 14:45:43 +0000 (GMT) (envelope-from glebius@FreeBSD.org) Received: from cell.sick.ru (glebius@localhost [127.0.0.1]) by cell.sick.ru (8.13.3/8.13.3) with ESMTP id jBJEjdq1071660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 19 Dec 2005 17:45:40 +0300 (MSK) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.sick.ru (8.13.3/8.13.1/Submit) id jBJEjdDF071658; Mon, 19 Dec 2005 17:45:39 +0300 (MSK) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.sick.ru: glebius set sender to glebius@FreeBSD.org using -f Date: Mon, 19 Dec 2005 17:45:39 +0300 From: Gleb Smirnoff To: net@FreeBSD.org Message-ID: <20051219144539.GY41381@FreeBSD.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZJcv+A0YCCLh2VIg" Content-Disposition: inline User-Agent: Mutt/1.5.6i Cc: sam@FreeBSD.org Subject: allocate VLAN tags from UMA X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Dec 2005 14:45:45 -0000 --ZJcv+A0YCCLh2VIg Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Colleagues, I've made a patch, implementing Sam's advice to allocate VLAN tags for hwvlantagging capable drivers from UMA zone. The patch gives 6% improvement on a singlethreaded UDP flood. Unfortunately I don't have enough hardware to test it under two simultaneous floods. It probably should give even more improvement in this case. x head-flood + mtag-flood +--------------------------------------------------------------------------+ |x x x x x x + + + ++ +| | |____________A___M________| |________A___M____| | +--------------------------------------------------------------------------+ N Min Max Median Avg Stddev x 6 242001 253604 250265 248885.17 4568.0712 + 6 258408 267557 264955 263794.5 3132.2551 Difference at 95.0% confidence 14909.3 +/- 5037.97 5.99045% +/- 2.02421% (Student's t, pooled s = 3916.52) The problem with the patch is the namespace pollution - vlan UMA zone is declared in kern_mbuf.c and mtag cookie is declared in mbuf.h. I can't make then private to if_vlan.c, because this will make NIC drivers dependent on vlan(4). Can we accept this? -- Totus tuus, Glebius. GLEBIUS-RIPN GLEB-RIPE --ZJcv+A0YCCLh2VIg Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename=vlan-uma-mtag Index: sys/mbuf.h =================================================================== RCS file: /home/ncvs/src/sys/sys/mbuf.h,v retrieving revision 1.184 diff -u -r1.184 mbuf.h --- sys/mbuf.h 10 Dec 2005 15:21:04 -0000 1.184 +++ sys/mbuf.h 19 Dec 2005 13:07:05 -0000 @@ -758,6 +758,10 @@ #define PACKET_TAG_IPOPTIONS 27 /* Saved IP options */ #define PACKET_TAG_CARP 28 /* CARP info */ +/* Specific cookies and tags. */ +#define MTAG_VLAN 1035328035 +#define MTAG_VLAN_TAG 0 /* tag of VLAN interface */ + /* Packet tag routines. */ struct m_tag *m_tag_alloc(u_int32_t, int, int, int); void m_tag_delete(struct mbuf *, struct m_tag *); @@ -768,6 +772,9 @@ int m_tag_copy_chain(struct mbuf *, struct mbuf *, int); void m_tag_delete_nonpersistent(struct mbuf *); +/* Specific tags routines. */ +struct m_tag *mt_vlan_alloc(int flags); + /* * Initialize the list of tags associated with an mbuf. */ Index: kern/kern_mbuf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_mbuf.c,v retrieving revision 1.17 diff -u -r1.17 kern_mbuf.c --- kern/kern_mbuf.c 10 Dec 2005 15:21:04 -0000 1.17 +++ kern/kern_mbuf.c 19 Dec 2005 13:06:17 -0000 @@ -133,6 +133,7 @@ uma_zone_t zone_jumbo9; uma_zone_t zone_jumbo16; uma_zone_t zone_ext_refcnt; +uma_zone_t zone_mtag_vlan; /* * Local prototypes. @@ -225,6 +226,12 @@ NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT); + zone_mtag_vlan = uma_zcreate("mtag_vlan", + sizeof(struct m_tag) + sizeof(u_int), + NULL, NULL, + NULL, NULL, + UMA_ALIGN_INT, 0); + /* uma_prealloc() goes here... */ /* @@ -511,6 +518,25 @@ return (0); } +static void +mt_vlan_free(struct m_tag *mtag) +{ + uma_zfree(zone_mtag_vlan, mtag); +} + +struct m_tag * +mt_vlan_alloc(int flags) +{ + struct m_tag *mtag; + + mtag = uma_zalloc(zone_mtag_vlan, flags); + if (mtag) { + m_tag_setup(mtag, MTAG_VLAN, MTAG_VLAN_TAG, sizeof(u_int)); + mtag->m_tag_free = mt_vlan_free; + } + return (mtag); +} + /* * This is the protocol drain routine. * Index: net/if_vlan.c =================================================================== RCS file: /home/ncvs/src/sys/net/if_vlan.c,v retrieving revision 1.93 diff -u -r1.93 if_vlan.c --- net/if_vlan.c 28 Nov 2005 12:46:35 -0000 1.93 +++ net/if_vlan.c 19 Dec 2005 12:51:23 -0000 @@ -507,10 +507,7 @@ * packet tag that holds it. */ if (p->if_capenable & IFCAP_VLAN_HWTAGGING) { - struct m_tag *mtag = m_tag_alloc(MTAG_VLAN, - MTAG_VLAN_TAG, - sizeof(u_int), - M_NOWAIT); + struct m_tag *mtag = mt_vlan_alloc(M_NOWAIT); if (mtag == NULL) { ifp->if_oerrors++; m_freem(m); Index: net/if_vlan_var.h =================================================================== RCS file: /home/ncvs/src/sys/net/if_vlan_var.h,v retrieving revision 1.23 diff -u -r1.23 if_vlan_var.h --- net/if_vlan_var.h 18 Dec 2005 18:24:27 -0000 1.23 +++ net/if_vlan_var.h 19 Dec 2005 13:01:03 -0000 @@ -93,8 +93,6 @@ * Note that a driver must indicate it supports hardware VLAN * tagging by marking IFCAP_VLAN_HWTAGGING in if_capabilities. */ -#define MTAG_VLAN 1035328035 -#define MTAG_VLAN_TAG 0 /* tag of VLAN interface */ /* * This macro must expand to a lvalue so that it can be used @@ -103,9 +101,7 @@ #define VLAN_TAG_VALUE(_mt) (*(u_int *)((_mt) + 1)) #define VLAN_INPUT_TAG(_ifp, _m, _t) do { \ - struct m_tag *mtag; \ - mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \ - sizeof (u_int), M_NOWAIT); \ + struct m_tag *mtag = mt_vlan_alloc(M_NOWAIT); \ if (mtag != NULL) { \ VLAN_TAG_VALUE(mtag) = (_t); \ m_tag_prepend((_m), mtag); \ --ZJcv+A0YCCLh2VIg--