netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] udp: ipv4: do not waste time in __udp4_lib_mcast_demux_lookup
@ 2014-06-12 23:13 Eric Dumazet
  2014-06-13 22:39 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2014-06-12 23:13 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Shawn Bohrer, David Held, Willem de Bruijn

From: Eric Dumazet <edumazet@google.com>

Its too easy to add thousand of UDP sockets on a particular bucket,
and slow down an innocent multicast receiver.

Early demux is supposed to be an optimization, we should avoid spending
too much time in it.

It is interesting to note __udp4_lib_demux_lookup() only tries to
match first socket in the chain.

10 is the threshold we already have in __udp4_lib_lookup() to switch
to secondary hash.

Fixes: 421b3885bf6d5 ("udp: ipv4: Add udp early demux")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: David Held <drheld@google.com>
Cc: Shawn Bohrer <sbohrer@rgmadvisors.com>
---
 net/ipv4/udp.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 185ed3e59802..7064dbfa8101 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1861,6 +1861,10 @@ static struct sock *__udp4_lib_mcast_demux_lookup(struct net *net,
 	unsigned int count, slot = udp_hashfn(net, hnum, udp_table.mask);
 	struct udp_hslot *hslot = &udp_table.hash[slot];
 
+	/* Do not bother scanning a too big list */
+	if (hslot->count > 10)
+		return NULL;
+
 	rcu_read_lock();
 begin:
 	count = 0;

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

* Re: [PATCH] udp: ipv4: do not waste time in __udp4_lib_mcast_demux_lookup
  2014-06-12 23:13 [PATCH] udp: ipv4: do not waste time in __udp4_lib_mcast_demux_lookup Eric Dumazet
@ 2014-06-13 22:39 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-06-13 22:39 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, sbohrer, drheld, willemb

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 12 Jun 2014 16:13:06 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> Its too easy to add thousand of UDP sockets on a particular bucket,
> and slow down an innocent multicast receiver.
> 
> Early demux is supposed to be an optimization, we should avoid spending
> too much time in it.
> 
> It is interesting to note __udp4_lib_demux_lookup() only tries to
> match first socket in the chain.
> 
> 10 is the threshold we already have in __udp4_lib_lookup() to switch
> to secondary hash.
> 
> Fixes: 421b3885bf6d5 ("udp: ipv4: Add udp early demux")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: David Held <drheld@google.com>

Applied and queued up for -stable, thanks Eric.

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

end of thread, other threads:[~2014-06-13 22:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-12 23:13 [PATCH] udp: ipv4: do not waste time in __udp4_lib_mcast_demux_lookup Eric Dumazet
2014-06-13 22:39 ` 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).