Subject: Re: [PATCH/RFC] make unregister_netdev() delete more than 4 interfaces per second

From: Eric Dumazet <[email-masked]>
Date: Sun, 18 Oct 2009 19:51:56 +0200

Benjamin LaHaise a écrit :
> On Sun, Oct 18, 2009 at 06:26:22AM +0200, Eric Dumazet wrote:
>> Unfortunatly this slow down fast path by an order of magnitude.
>>
>> atomic_dec() is pretty cheap (and eventually could use a per_cpu thing,
>> now we have a new and sexy per_cpu allocator), but atomic_dec_and_test()
>> is not that cheap and more important forbids a per_cpu conversion.
> 
> dev_put() is not a fast path by any means.  atomic_dec_and_test() costs 
> the same as atomic_dec() on any modern CPU -- the cost is in the cacheline 
> bouncing and serialisation both require.  The case of the device count 
> becoming 0 is quite rare -- any device with a route on it will never hit 
> a reference count of 0.

You forgot af_packet sendmsg() users, and heavy routers where route cache
is stressed or disabled. I know several of them, they even added mmap TX 
support to get better performance. They will be disapointed by your patch.

atomic_dec_and_test() is definitly more expensive, because of strong barrier
semantics and added test after the decrement.
refcnt being close to zero or not has not impact, even on 2 years old cpus.

Machines hardly had to dismantle a netdevice in a normal lifetime, so maybe
we were lazy with this insane msleep(250). This came from old linux times,
when cpus were soooo slow and programers soooo lazy :)

The msleep(250) should be tuned first. Then if this is really necessary
to dismantle 100.000 netdevices per second, we might have to think a bit more.

Just try msleep(1 or 2), it should work quite well.