netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 2/2] udp: udp_lib_get_port start at a different bucket on different processors
@ 2009-12-16 19:24 Lucian Adrian Grijincu
  2009-12-17 14:09 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Lucian Adrian Grijincu @ 2009-12-16 19:24 UTC (permalink / raw)
  To: netdev; +Cc: Octavian Purdila

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]


On SMP, when ports are not allocated randomly, using the same starting
port on all processors will lead to bad performance as all processors
will try to get the same hashbucket spinlock: only one will succeed,
the rest will spin madly.

We solve this problem by making each processor start searching from a
different port. To not skip possibly valid port ranges we renormalize
the hint value too.

Signed-off-by: Lucian Adrian Grijincu <lgrijincu@ixiacom.com>
---
  net/ipv4/udp.c |   12 +++++++++---
  1 files changed, 9 insertions(+), 3 deletions(-)



[-- Attachment #2: 0002-udp-udp_lib_get_port-start-at-a-different-bucket-on-.patch --]
[-- Type: text/x-patch, Size: 984 bytes --]

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index f437d9d..5d17c71 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -219,7 +219,9 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
 			first = (((u64)rand * remaining) >> 32) + low;
 		} else {
 			rand = 1;
-			first = hint;
+			first = hint + smp_processor_id();
+			if (first > high)
+				first = low + (first - low) % remaining;
 		}
 		/*
 		 * force rand to be an odd multiple of UDP_HTABLE_SIZE
@@ -243,8 +245,12 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
 			do {
 				if (low <= snum && snum <= high &&
 				    !test_bit(snum >> udptable->log, bitmap)) {
-					if (unlikely(!sysctl_udp_port_randomization))
-						hint = snum;
+					if (unlikely(!sysctl_udp_port_randomization)) {
+						int cur_hint = snum - smp_processor_id();
+						if (cur_hint < low)
+							cur_hint = high - (low - cur_hint) % remaining;
+						hint = cur_hint;
+					}
 					goto found;
 				}
 				snum += rand;


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

* Re: [RFC 2/2] udp: udp_lib_get_port start at a different bucket on different processors
  2009-12-16 19:24 [RFC 2/2] udp: udp_lib_get_port start at a different bucket on different processors Lucian Adrian Grijincu
@ 2009-12-17 14:09 ` Eric Dumazet
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2009-12-17 14:09 UTC (permalink / raw)
  To: Lucian Adrian Grijincu; +Cc: netdev, Octavian Purdila

Le 16/12/2009 20:24, Lucian Adrian Grijincu a écrit :
> 
> On SMP, when ports are not allocated randomly, using the same starting
> port on all processors will lead to bad performance as all processors
> will try to get the same hashbucket spinlock: only one will succeed,
> the rest will spin madly.
> 
> We solve this problem by making each processor start searching from a
> different port. To not skip possibly valid port ranges we renormalize
> the hint value too.
> 
> Signed-off-by: Lucian Adrian Grijincu <lgrijincu@ixiacom.com>
> ---
>  net/ipv4/udp.c |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)
> 
> 

This makes no sense. You correct a bad performance issue bringed by your previous patch ?

Please submit one patch, with no performance regression.

I suggest you use a per_cpu hint if you really want to be fast...

Thanks

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

end of thread, other threads:[~2009-12-17 14:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-16 19:24 [RFC 2/2] udp: udp_lib_get_port start at a different bucket on different processors Lucian Adrian Grijincu
2009-12-17 14:09 ` Eric Dumazet

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).