From owner-freebsd-net@FreeBSD.ORG Thu Oct 20 08:57:29 2005 Return-Path: X-Original-To: freebsd-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 07D4316A41F; Thu, 20 Oct 2005 08:57:29 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id 00CC643D5A; Thu, 20 Oct 2005 08:57:27 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.3/8.13.3) with ESMTP id j9K8vMHV036651; Thu, 20 Oct 2005 12:57:22 +0400 (MSD) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.3/8.13.3/Submit) id j9K8vMgW036650; Thu, 20 Oct 2005 12:57:22 +0400 (MSD) (envelope-from yar) Date: Thu, 20 Oct 2005 12:57:21 +0400 From: Yar Tikhiy To: Gleb Smirnoff Message-ID: <20051020085721.GC27114@comp.chem.msu.su> References: <20051019102559.GA45909@heff.fud.org.nz> <20051020070054.GZ59364@cell.sick.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051020070054.GZ59364@cell.sick.ru> User-Agent: Mutt/1.5.9i Cc: freebsd-net@FreeBSD.org, ru@FreeBSD.org, Andrew Thompson Subject: Re: vlan patch 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: Thu, 20 Oct 2005 08:57:29 -0000 On Thu, Oct 20, 2005 at 11:00:54AM +0400, Gleb Smirnoff wrote: > > On Wed, Oct 19, 2005 at 11:25:59PM +1300, Andrew Thompson wrote: > A> It has always bugged me how the vlan code traverses the linked-list for > A> each incoming packet to find the right ifvlan, I have this patch which > A> attempts to fix this. > A> > A> What it does is replace the linear search for the vlan with a constant > A> time lookup. It does this by allocating an array for each vlan enabled > A> parent interface so the tag can be directly indexed. > A> > A> This has an overhead of ~16kb on 32bit, this is not too bad as there is > A> usually only one physical interface when using a large number of vlans. > A> > A> I have measured a 1.6% pps increase with 100 vlans, and 8% with 500, and > A> yes, some people use this many in production. > A> > A> It also has the benefit of enforcing unique vlan tags per parent which > A> the current code doesn't do. > > Although the memory overhead is not noticable on modern i386 and amd64 > PCs I don't think that we should waste so much memory. We should keep > in mind the existence of embedded architectures with little memory. Agreed. On amd64 or another 64-bit platform each physical interface carrying vlans will consume 32k of wired kernel memory, which is a rather valuable resource. We may not spend memory in the kernel as generously as in userland programs because it is usually physical memory spent in this case, not virtual one. > In most cases people use 10 - 30 VLANs. I suggest to use a hash, like it I'd rather not limit our consideration by 10-30 VLANs. People are running networks with hundreds of VLANs terminated at a FreeBSD gateway. Perhaps, the hash table should be roughly adjustable to the current number of configured VLANs. > is already done in ng_vlan(4). This hash makes every sixteenth VLAN to fall > into same slot. Since most people allocate VLAN ids contiguously the hash > distribution should be good. Apropos, XOR-folding used in ng_vlan isn't that dumb, it doesn't make every 16th VLAN fall into the same slot. Of course, you will start getting collisions at most on the 16th VLAN added since 16 is the size of the hash table. > Moreover, I suggest Yar and Ruslan to work together and make the hash code > shared between vlan(4) and ng_vlan(4), not copy-and-pasted. The hash code consists of literally a couple of #define's. And the difference between ng_vlan(4) and vlan(4) is that each ng_vlan node gets its own instance of the hash table. OTOH, in vlan(4) we need to decide if the hash table will be per parent interface or a single global instance. In the latter case we could hash by a combination of the VLAN tag and parent's ifindex. Perhaps this approach will yield more CPU cache hits during hash table lookups. In addition, it will be thriftier in using memory. Locking the global hash table should not be an issue as we can use an sx lock in this case for optimal read access. -- Yar