diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-10-15 01:44:11 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-10-20 06:02:23 -0400 |
commit | 27b75c95f10d249574d9c4cb9dab878107faede8 (patch) | |
tree | 466656d86aaa395951e12b50903e730203c5f86f /net/core/dst.c | |
parent | e6484930d7c73d324bccda7d43d131088da697b9 (diff) |
net: avoid RCU for NOCACHE dst
There is no point using RCU for dst we allocate for a very short time
(used once).
Change dst_release() to take DST_NOCACHE into account, but also change
skb_dst_set_noref() to force a refcount increment for such dst.
This is a _huge_ gain, because we dont waste memory to store xx thousand
of dsts. Instead of queueing them to RCU, we can free them instantly.
CPU caches can stay hot, re-using same memory blocks to hold temporary
dsts.
Note : remove unneeded smp_mb__before_atomic_dec(); in dst_release(),
since atomic_dec_return() implies a full memory barrier.
Stress test, 160.000.000 udp frames sent, IP route cache disabled
(DDOS).
Before:
real 0m38.091s
user 0m13.189s
sys 7m53.018s
After:
real 0m29.946s
user 0m12.157s
sys 7m40.605s
For reference, if IP route cache was enabled :
real 0m32.030s
user 0m10.521s
sys 8m15.243s
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/dst.c')
-rw-r--r-- | net/core/dst.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/net/core/dst.c b/net/core/dst.c index 32e542d7f472..8abe628b79f1 100644 --- a/net/core/dst.c +++ b/net/core/dst.c | |||
@@ -271,13 +271,40 @@ void dst_release(struct dst_entry *dst) | |||
271 | if (dst) { | 271 | if (dst) { |
272 | int newrefcnt; | 272 | int newrefcnt; |
273 | 273 | ||
274 | smp_mb__before_atomic_dec(); | ||
275 | newrefcnt = atomic_dec_return(&dst->__refcnt); | 274 | newrefcnt = atomic_dec_return(&dst->__refcnt); |
276 | WARN_ON(newrefcnt < 0); | 275 | WARN_ON(newrefcnt < 0); |
276 | if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) { | ||
277 | dst = dst_destroy(dst); | ||
278 | if (dst) | ||
279 | __dst_free(dst); | ||
280 | } | ||
277 | } | 281 | } |
278 | } | 282 | } |
279 | EXPORT_SYMBOL(dst_release); | 283 | EXPORT_SYMBOL(dst_release); |
280 | 284 | ||
285 | /** | ||
286 | * skb_dst_set_noref - sets skb dst, without a reference | ||
287 | * @skb: buffer | ||
288 | * @dst: dst entry | ||
289 | * | ||
290 | * Sets skb dst, assuming a reference was not taken on dst | ||
291 | * skb_dst_drop() should not dst_release() this dst | ||
292 | */ | ||
293 | void skb_dst_set_noref(struct sk_buff *skb, struct dst_entry *dst) | ||
294 | { | ||
295 | WARN_ON(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); | ||
296 | /* If dst not in cache, we must take a reference, because | ||
297 | * dst_release() will destroy dst as soon as its refcount becomes zero | ||
298 | */ | ||
299 | if (unlikely(dst->flags & DST_NOCACHE)) { | ||
300 | dst_hold(dst); | ||
301 | skb_dst_set(skb, dst); | ||
302 | } else { | ||
303 | skb->_skb_refdst = (unsigned long)dst | SKB_DST_NOREF; | ||
304 | } | ||
305 | } | ||
306 | EXPORT_SYMBOL(skb_dst_set_noref); | ||
307 | |||
281 | /* Dirty hack. We did it in 2.2 (in __dst_free), | 308 | /* Dirty hack. We did it in 2.2 (in __dst_free), |
282 | * we have _very_ good reasons not to repeat | 309 | * we have _very_ good reasons not to repeat |
283 | * this mistake in 2.3, but we have no choice | 310 | * this mistake in 2.3, but we have no choice |