arp(8) performance - use if_nameindex() instead of if_indextoname()

Nick Rogers ncrogers at gmail.com
Wed Apr 23 00:03:02 UTC 2014


On Sat, Apr 5, 2014 at 1:44 PM, George Neville-Neil
<gnn at neville-neil.com> wrote:
>
> On Mar 27, 2014, at 16:59 , Vladislav Prodan <universite at ukr.net> 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 at vm ~/arp]# ifconfig -a | grep vlan | grep interface | wc -l
>>> 1500
>>>
>>> [root at vm ~/arp]# arp -na | wc -l
>>> 1503
>>>
>>> [root at vm ~/arp]# time /usr/sbin/arp.old -na > /dev/null
>>>
>>> real 0m5.529s
>>> user 0m0.813s
>>> sys 0m4.231s
>>>
>>> [root at vm ~/arp]# time /usr/sbin/arp -na > /dev/null
>>>
>>> real 0m0.011s
>>> user 0m0.008s
>>> sys 0m0.002s
>>> [root at 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’ll look at this patch and either update or commit it after some private testing.

I noticed you committed it. Thanks!

>
> Best
> George
>
>


More information about the freebsd-hackers mailing list