From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 00:03:02 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AFA70314 for ; Wed, 23 Apr 2014 00:03:02 +0000 (UTC) Received: from mail-vc0-x231.google.com (mail-vc0-x231.google.com [IPv6:2607:f8b0:400c:c03::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6B5431C8B for ; Wed, 23 Apr 2014 00:03:02 +0000 (UTC) Received: by mail-vc0-f177.google.com with SMTP id if17so234815vcb.36 for ; Tue, 22 Apr 2014 17:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=cLsZqV0hJIvYYV56vCz6OT6hCiKjaO2u/N0ZMK6K38s=; b=p1KPVpDI7sDQPskknBBiqyJiKB8mbpfL7VzNOPYCQf0fAVFRyct9OEwKMEcJMtcXwl wcoveVDIZJxznkc7QLMcDll0M46PLUCzKoAsdbtMi1bOHF315OmUBqBsKTH6E/ZSDg65 NdHQ6F8nv8/tYvVsq8vM5qrrZu/arGZzcXpWKR+mchWaKLpk+/aJh5mN8PcKd8fttp4B V6lOnZyaXxdueDocKVLoqmIJSVlHJAHeR5yKfFYGJdjyE28Ts7KsmA0hjqYHubNYWObD uLMj2aOf1pDSVHy6vdKv4GJmEfT7Wgli18+XWko2i0FSBQQ5l5gQsjHZgV3yQH2qt00i xaFw== MIME-Version: 1.0 X-Received: by 10.221.62.131 with SMTP id xa3mr39524794vcb.13.1398211381474; Tue, 22 Apr 2014 17:03:01 -0700 (PDT) Received: by 10.52.106.170 with HTTP; Tue, 22 Apr 2014 17:03:01 -0700 (PDT) In-Reply-To: References: <1395953784.953193393.sslrpyfe@frv35.fwdcdn.com> Date: Tue, 22 Apr 2014 17:03:01 -0700 Message-ID: Subject: Re: arp(8) performance - use if_nameindex() instead of if_indextoname() From: Nick Rogers To: George Neville-Neil Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, Vladislav Prodan X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Apr 2014 00:03:02 -0000 On Sat, Apr 5, 2014 at 1:44 PM, George Neville-Neil wrote: > > On Mar 27, 2014, at 16:59 , Vladislav Prodan wrote: > >> >>> I propose that instead of calling if_indextoname() for every entry, >>> we leverage if_nameindex() to obtain a cache of if_index to if_name >>> mappings, before printing all the entries. This results in a >>> considerable performance improvement for my situation, and also >>> handles the case that was "fixed" in the commit I just mentioned. >>> >>> I took a shot at this and came up with the following diff against >>> HEAD. I used routed's route6d.c as a reference, which is the only >>> thing I could find utilizing if_nameindex(). I am currently using this >>> in production environments with great success. >>> >> >>> The following illustrates the performance improvement: >>> >>> [root@vm ~/arp]# ifconfig -a | grep vlan | grep interface | wc -l >>> 1500 >>> >>> [root@vm ~/arp]# arp -na | wc -l >>> 1503 >>> >>> [root@vm ~/arp]# time /usr/sbin/arp.old -na > /dev/null >>> >>> real 0m5.529s >>> user 0m0.813s >>> sys 0m4.231s >>> >>> [root@vm ~/arp]# time /usr/sbin/arp -na > /dev/null >>> >>> real 0m0.011s >>> user 0m0.008s >>> sys 0m0.002s >>> [root@vm ~/arp]# >>> >>> >>> I realize this may not be the cleanest way of implementing >>> if_nameindex within arp.c. I'm hoping Max Laier or someone else can >>> help me out (again) and get an adequate fix committed. Thanks! >>> >> >> >> Thanks, it works. >> > > I=E2=80=99ll look at this patch and either update or commit it after some= private testing. I noticed you committed it. Thanks! > > Best > George > >