netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] neigh: reduce arp latency
@ 2011-08-09 15:40 Eric Dumazet
  2011-08-09 17:06 ` Julian Anastasov
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2011-08-09 15:40 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Remove the artificial HZ latency on arp resolution.

Instead of firing a timer in one jiffy (up to 10 ms if HZ=100), lets
send the ARP message immediately.

Before patch :

# arp -d 192.168.20.108 ; ping -c 3 192.168.20.108
PING 192.168.20.108 (192.168.20.108) 56(84) bytes of data.
64 bytes from 192.168.20.108: icmp_seq=1 ttl=64 time=9.91 ms
64 bytes from 192.168.20.108: icmp_seq=2 ttl=64 time=0.065 ms
64 bytes from 192.168.20.108: icmp_seq=3 ttl=64 time=0.061 ms

After patch :

$ arp -d 192.168.20.108 ; ping -c 3 192.168.20.108
PING 192.168.20.108 (192.168.20.108) 56(84) bytes of data.
64 bytes from 192.168.20.108: icmp_seq=1 ttl=64 time=0.152 ms
64 bytes from 192.168.20.108: icmp_seq=2 ttl=64 time=0.064 ms
64 bytes from 192.168.20.108: icmp_seq=3 ttl=64 time=0.074 ms

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/core/neighbour.c |   32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 8fab9b0..d99f908 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -844,6 +844,19 @@ static void neigh_invalidate(struct neighbour *neigh)
 	skb_queue_purge(&neigh->arp_queue);
 }
 
+static void neigh_probe(struct neighbour *neigh)
+	__releases(neigh->lock)
+{
+	struct sk_buff *skb = skb_peek(&neigh->arp_queue);
+	/* keep skb alive even if arp_queue overflows */
+	if (skb)
+		skb = skb_copy(skb, GFP_ATOMIC);
+	write_unlock(&neigh->lock);
+	neigh->ops->solicit(neigh, skb);
+	atomic_inc(&neigh->probes);
+	kfree_skb(skb);
+}
+
 /* Called when a timer expires for a neighbour entry. */
 
 static void neigh_timer_handler(unsigned long arg)
@@ -920,14 +933,7 @@ static void neigh_timer_handler(unsigned long arg)
 			neigh_hold(neigh);
 	}
 	if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
-		struct sk_buff *skb = skb_peek(&neigh->arp_queue);
-		/* keep skb alive even if arp_queue overflows */
-		if (skb)
-			skb = skb_copy(skb, GFP_ATOMIC);
-		write_unlock(&neigh->lock);
-		neigh->ops->solicit(neigh, skb);
-		atomic_inc(&neigh->probes);
-		kfree_skb(skb);
+		neigh_probe(neigh);
 	} else {
 out:
 		write_unlock(&neigh->lock);
@@ -943,6 +949,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
 {
 	int rc;
 	unsigned long now;
+	bool immediate_probe = false;
 
 	write_lock_bh(&neigh->lock);
 
@@ -957,7 +964,8 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
 			atomic_set(&neigh->probes, neigh->parms->ucast_probes);
 			neigh->nud_state     = NUD_INCOMPLETE;
 			neigh->updated = jiffies;
-			neigh_add_timer(neigh, now + 1);
+			neigh_add_timer(neigh, now + HZ);
+			immediate_probe = true;
 		} else {
 			neigh->nud_state = NUD_FAILED;
 			neigh->updated = jiffies;
@@ -989,7 +997,11 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
 		rc = 1;
 	}
 out_unlock_bh:
-	write_unlock_bh(&neigh->lock);
+	if (immediate_probe)
+		neigh_probe(neigh);
+	else
+		write_unlock(&neigh->lock);
+	local_bh_enable();
 	return rc;
 }
 EXPORT_SYMBOL(__neigh_event_send);



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] neigh: reduce arp latency
  2011-08-09 15:40 [PATCH net-next] neigh: reduce arp latency Eric Dumazet
@ 2011-08-09 17:06 ` Julian Anastasov
  2011-08-09 18:15   ` [PATCH v2 " Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Julian Anastasov @ 2011-08-09 17:06 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev


	Hello,

On Tue, 9 Aug 2011, Eric Dumazet wrote:

> Remove the artificial HZ latency on arp resolution.
> 
> Instead of firing a timer in one jiffy (up to 10 ms if HZ=100), lets
> send the ARP message immediately.
> 
> @@ -957,7 +964,8 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
>  			atomic_set(&neigh->probes, neigh->parms->ucast_probes);
>  			neigh->nud_state     = NUD_INCOMPLETE;
>  			neigh->updated = jiffies;
> -			neigh_add_timer(neigh, now + 1);
> +			neigh_add_timer(neigh, now + HZ);

	To be correct with old NUD_INCOMPLETE logic may be we can use 
max(neigh->parms->retrans_time, HZ/2) here instead of HZ?

> +			immediate_probe = true;
>  		} else {
>  			neigh->nud_state = NUD_FAILED;
>  			neigh->updated = jiffies;

Regards

--
Julian Anastasov <ja@ssi.bg>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 net-next] neigh: reduce arp latency
  2011-08-09 17:06 ` Julian Anastasov
@ 2011-08-09 18:15   ` Eric Dumazet
  2011-08-12  9:57     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2011-08-09 18:15 UTC (permalink / raw)
  To: Julian Anastasov; +Cc: David Miller, netdev

Le mardi 09 août 2011 à 20:06 +0300, Julian Anastasov a écrit :

> 	To be correct with old NUD_INCOMPLETE logic may be we can use 
> max(neigh->parms->retrans_time, HZ/2) here instead of HZ?
> 

Thanks Julian a lot for reviewing, here is v2 adressing this point.

[PATCH v2 net-next] neigh: reduce arp latency

Remove the artificial HZ latency on arp resolution.

Instead of firing a timer in one jiffy (up to 10 ms if HZ=100), lets
send the ARP message immediately.

Before patch :

# arp -d 192.168.20.108 ; ping -c 3 192.168.20.108
PING 192.168.20.108 (192.168.20.108) 56(84) bytes of data.
64 bytes from 192.168.20.108: icmp_seq=1 ttl=64 time=9.91 ms
64 bytes from 192.168.20.108: icmp_seq=2 ttl=64 time=0.065 ms
64 bytes from 192.168.20.108: icmp_seq=3 ttl=64 time=0.061 ms

After patch :

$ arp -d 192.168.20.108 ; ping -c 3 192.168.20.108
PING 192.168.20.108 (192.168.20.108) 56(84) bytes of data.
64 bytes from 192.168.20.108: icmp_seq=1 ttl=64 time=0.152 ms
64 bytes from 192.168.20.108: icmp_seq=2 ttl=64 time=0.064 ms
64 bytes from 192.168.20.108: icmp_seq=3 ttl=64 time=0.074 ms

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 net/core/neighbour.c |   40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 8fab9b0..4002261 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -844,6 +844,19 @@ static void neigh_invalidate(struct neighbour *neigh)
 	skb_queue_purge(&neigh->arp_queue);
 }
 
+static void neigh_probe(struct neighbour *neigh)
+	__releases(neigh->lock)
+{
+	struct sk_buff *skb = skb_peek(&neigh->arp_queue);
+	/* keep skb alive even if arp_queue overflows */
+	if (skb)
+		skb = skb_copy(skb, GFP_ATOMIC);
+	write_unlock(&neigh->lock);
+	neigh->ops->solicit(neigh, skb);
+	atomic_inc(&neigh->probes);
+	kfree_skb(skb);
+}
+
 /* Called when a timer expires for a neighbour entry. */
 
 static void neigh_timer_handler(unsigned long arg)
@@ -920,14 +933,7 @@ static void neigh_timer_handler(unsigned long arg)
 			neigh_hold(neigh);
 	}
 	if (neigh->nud_state & (NUD_INCOMPLETE | NUD_PROBE)) {
-		struct sk_buff *skb = skb_peek(&neigh->arp_queue);
-		/* keep skb alive even if arp_queue overflows */
-		if (skb)
-			skb = skb_copy(skb, GFP_ATOMIC);
-		write_unlock(&neigh->lock);
-		neigh->ops->solicit(neigh, skb);
-		atomic_inc(&neigh->probes);
-		kfree_skb(skb);
+		neigh_probe(neigh);
 	} else {
 out:
 		write_unlock(&neigh->lock);
@@ -942,7 +948,7 @@ out:
 int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
 {
 	int rc;
-	unsigned long now;
+	bool immediate_probe = false;
 
 	write_lock_bh(&neigh->lock);
 
@@ -950,14 +956,16 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
 	if (neigh->nud_state & (NUD_CONNECTED | NUD_DELAY | NUD_PROBE))
 		goto out_unlock_bh;
 
-	now = jiffies;
-
 	if (!(neigh->nud_state & (NUD_STALE | NUD_INCOMPLETE))) {
 		if (neigh->parms->mcast_probes + neigh->parms->app_probes) {
+			unsigned long next, now = jiffies;
+
 			atomic_set(&neigh->probes, neigh->parms->ucast_probes);
 			neigh->nud_state     = NUD_INCOMPLETE;
-			neigh->updated = jiffies;
-			neigh_add_timer(neigh, now + 1);
+			neigh->updated = now;
+			next = now + max(neigh->parms->retrans_time, HZ/2);
+			neigh_add_timer(neigh, next);
+			immediate_probe = true;
 		} else {
 			neigh->nud_state = NUD_FAILED;
 			neigh->updated = jiffies;
@@ -989,7 +997,11 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
 		rc = 1;
 	}
 out_unlock_bh:
-	write_unlock_bh(&neigh->lock);
+	if (immediate_probe)
+		neigh_probe(neigh);
+	else
+		write_unlock(&neigh->lock);
+	local_bh_enable();
 	return rc;
 }
 EXPORT_SYMBOL(__neigh_event_send);



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 net-next] neigh: reduce arp latency
  2011-08-09 18:15   ` [PATCH v2 " Eric Dumazet
@ 2011-08-12  9:57     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2011-08-12  9:57 UTC (permalink / raw)
  To: eric.dumazet; +Cc: ja, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 09 Aug 2011 20:15:58 +0200

> Le mardi 09 août 2011 à 20:06 +0300, Julian Anastasov a écrit :
> 
>> 	To be correct with old NUD_INCOMPLETE logic may be we can use 
>> max(neigh->parms->retrans_time, HZ/2) here instead of HZ?
>> 
> 
> Thanks Julian a lot for reviewing, here is v2 adressing this point.
> 
> [PATCH v2 net-next] neigh: reduce arp latency
> 
> Remove the artificial HZ latency on arp resolution.
> 
> Instead of firing a timer in one jiffy (up to 10 ms if HZ=100), lets
> send the ARP message immediately.
> 
> Before patch :
> 
> # arp -d 192.168.20.108 ; ping -c 3 192.168.20.108
> PING 192.168.20.108 (192.168.20.108) 56(84) bytes of data.
> 64 bytes from 192.168.20.108: icmp_seq=1 ttl=64 time=9.91 ms
> 64 bytes from 192.168.20.108: icmp_seq=2 ttl=64 time=0.065 ms
> 64 bytes from 192.168.20.108: icmp_seq=3 ttl=64 time=0.061 ms
> 
> After patch :
> 
> $ arp -d 192.168.20.108 ; ping -c 3 192.168.20.108
> PING 192.168.20.108 (192.168.20.108) 56(84) bytes of data.
> 64 bytes from 192.168.20.108: icmp_seq=1 ttl=64 time=0.152 ms
> 64 bytes from 192.168.20.108: icmp_seq=2 ttl=64 time=0.064 ms
> 64 bytes from 192.168.20.108: icmp_seq=3 ttl=64 time=0.074 ms
> 
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-08-12  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-09 15:40 [PATCH net-next] neigh: reduce arp latency Eric Dumazet
2011-08-09 17:06 ` Julian Anastasov
2011-08-09 18:15   ` [PATCH v2 " Eric Dumazet
2011-08-12  9:57     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).