From owner-freebsd-net@FreeBSD.ORG Wed Jan 1 01:12:00 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DA77995D for ; Wed, 1 Jan 2014 01:12:00 +0000 (UTC) Received: from mail-qc0-x233.google.com (mail-qc0-x233.google.com [IPv6:2607:f8b0:400d:c01::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 997891F45 for ; Wed, 1 Jan 2014 01:12:00 +0000 (UTC) Received: by mail-qc0-f179.google.com with SMTP id i8so12660213qcq.10 for ; Tue, 31 Dec 2013 17:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type; bh=qlOFNI/WtzvCkfkcEJfJkOOe90mnPKPMxQ3Y6xI9s54=; b=ODko2XKvsV6hOgUlx2qd4JLlt0jbQxMcfc/GU0aQbQvtMlP/kgGQn4H/HTex0Hkv0+ EC212bcQ9/KWo6YJZ25HoSNU6r7bwL2YxQf9Atk5IWaoHj8bKLDyH9UMb+bJ4bQxZpad HwtqQy2yOC2+5uW7c1txgAJFjhN7sfiVbaVDNf/E6MCpOs6nIKa3EAXQU7Am/vwkHTu3 0eEyduccdPMo+wkhZg1K123fUAKWl7qApNCeaK0YgFOwi1Vfh3/2IpnZMMjnVJIVx0eG HlnQ0ZVUr3aFXL6O37xE7cIVMyTZwyyvoBvL6Mak9VeDcK3aqfNjIiCbPiL+brfPrb6d +L0Q== MIME-Version: 1.0 X-Received: by 10.49.38.37 with SMTP id d5mr126612394qek.17.1388538719777; Tue, 31 Dec 2013 17:11:59 -0800 (PST) Sender: adrian.chadd@gmail.com Received: by 10.224.52.8 with HTTP; Tue, 31 Dec 2013 17:11:59 -0800 (PST) In-Reply-To: References: Date: Tue, 31 Dec 2013 17:11:59 -0800 X-Google-Sender-Auth: RcTz4B47JL2_bwrJvR1iayFdcKQ Message-ID: Subject: Re: ipv6 lock contention with parallel socket io From: Adrian Chadd To: FreeBSD Net Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jan 2014 01:12:00 -0000 btw - just committed this to -HEAD. I'll MFC it to stable/10 in a few days if noone raises any objections. Thanks, -a On 31 December 2013 09:53, Adrian Chadd wrote: > On 30 December 2013 23:35, Adrian Chadd wrote: >> Hi, >> >> I've noticed a bunch of lock contention occurs when doing highly >> parallel (> 4096 sockets) TCP IPv6 traffic. >> >> The contention is here: >> > [snip] > >> >> .. it's the IF_ADATA lock surrounding the lla_lookup() calls. >> >> Now: >> >> * is there any reason this isn't an rmlock? >> * the instance early on in nd6_output_lle() isn't taking the read >> lock, it's taking the full lock. Is there any reason for this? >> >> I don't have much experience or time to spend on optimising the ipv6 >> code to scale better but this seems like one of those things that'll >> bite us in the ass as the amount of ipv6 deployed increases. >> >> Does anyone have any ideas/suggestions on how we could improve things? > > This improves things quite a bit - from 1.9gbyte/sec @ 100% cpu usage > to 2.7gbyte/sec @ 85% CPU usage. It's not perfect - the lock > contention is still there - but it's much less of an issue now. > > Are there any issues with it? > > Index: sys/netinet6/nd6.c > =================================================================== > --- sys/netinet6/nd6.c (revision 259475) > +++ sys/netinet6/nd6.c (working copy) > @@ -1891,9 +1891,9 @@ > flags = ((m != NULL) || (lle != NULL)) ? LLE_EXCLUSIVE : 0; > if (ln == NULL) { > retry: > - IF_AFDATA_LOCK(ifp); > + IF_AFDATA_RLOCK(ifp); > ln = lla_lookup(LLTABLE6(ifp), flags, (struct sockaddr *)dst); > - IF_AFDATA_UNLOCK(ifp); > + IF_AFDATA_RUNLOCK(ifp); > if ((ln == NULL) && nd6_is_addr_neighbor(dst, ifp)) { > /* > * Since nd6_is_addr_neighbor() internally > calls nd6_lookup(), > > > Thanks, > > > > -a