Skip to contentSkip to conversation

netlink: wake up netlink listeners sooner

PATCH In review Stephen Hemminger 2 participants 2 messages Dec 21, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 netlink: wake up netlink listeners sooner

A netlink listening task (such as Quagga/zebra) can easily get overrun when lots of events happen such as a link state transition with full BGP route table. This happens because the sender does not yield to the receiver (unless socket queue is full). The problem is exacerbated because it is typical for listeners to set large receive buffer to attempt to keep up.

This patch changes it to yield sooner at halfway instead. Still not a cure-all for listener overrun if listener is slow, but works much reliably.

net/netlink/af_netlink.c +1 -1
@@ -960,7 +960,7 @@ static int netlink_broadcast_deliver(str
 		skb_set_owner_r(skb, sk);
 		skb_queue_tail(&sk->sk_receive_queue, skb);
 		sk->sk_data_ready(sk, skb->len);
-		return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf;
+		return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf / 2;
 	}
 	return -1;
 }
maintainer
#1 lore raw

From: Stephen Hemminger <[email protected]>
Date: Wed, 21 Dec 2011 13:49:44 -0800

net/netlink/af_netlink.c static int netlink_broadcast_deliver(str · line 964

Quoted 7 lines
net/netlink/af_netlink.c +1 -1
@@ -960,7 +960,7 @@ static int netlink_broadcast_deliver(str
 		skb_set_owner_r(skb, sk);
 		skb_queue_tail(&sk->sk_receive_queue, skb);
 		sk->sk_data_ready(sk, skb->len);
-		return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf;
+		return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf / 2;
 	}

Please mirror the logic we use in the generic socket code to do this on the send side, namely use something like:

		return (atomic_read(&sk->sk_rmem_alloc) << 1) > sk->sk_rcvbuf;

because sk_rcvbuf is an int and this "/ 2" expression will generate a really silly sequence of multiple shifts, adds, and comparisons in order to handle negative values correctly.