tipc: improve interaction socket-link
Subsystems (3)
cover tipc: improve interaction socket-link
We fix a very real starvation problem that may occur when a link encounters send buffer congestion. At the same time we make the interaction between the socket and link layer simpler and more consistent.
Jon Maloy (3):
tipc: unify tipc_wait_for_sndpkt() and tipc_wait_for_sndmsg()
functions
tipc: modify struct tipc_plist to be more versatile
tipc: reduce risk of user starvation during link congestion
net/tipc/bcast.c | 6 +- net/tipc/link.c | 75 ++++----- net/tipc/msg.h | 2 - net/tipc/name_table.c | 100 +++++++---- net/tipc/name_table.h | 21 +-- net/tipc/node.c | 15 +- net/tipc/socket.c | 449 ++++++++++++++++++++++---------------------------- 7 files changed, 319 insertions(+), 349 deletions(-)
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
PATCH 1/3 tipc: unify tipc_wait_for_sndpkt() and tipc_wait_for_sndmsg() functions
The functions tipc_wait_for_sndpkt() and tipc_wait_for_sndmsg() are very similar. The latter function is also called from two locations, and there will be more in the coming commits, which will all need to test on different conditions.
Instead of making yet another duplicates of the function, we now introduce a new macro tipc_wait_for_cond() where the wakeup condition can be stated as an argument to the call. This macro replaces all current and future uses of the two functions, which can now be eliminated.
--- net/tipc/socket.c | 108 +++++++++++++++++++++++++----------------------------- 1 file changed, 49 insertions(+), 59 deletions(-)
net/tipc/socket.c +49 -59
@@ -110,7 +110,6 @@ static void tipc_write_space(struct sock *sk);static void tipc_sock_destruct (struct sock *sk);static int tipc_release (struct socket *sock);static int tipc_accept (struct socket *sock,struct socket *new_sock,int flags); -static int tipc_wait_for_sndmsg (struct socket *sock,long *timeo_p);static void tipc_sk_timeout (unsigned long data);static int tipc_sk_publish (struct tipc_sock *tsk,uint scope,struct tipc_name_seq const *seq);
@@ -334,6 +333,49 @@ static int tipc_set_sk_state(struct sock *sk, int state)return res; } +static int tipc_sk_sock_err (struct socket *sock,long *timeout) +{ +struct sock *sk = sock->sk; +int err =sock_error (sk); +int typ = sock->type; + +if (err) +return err; +if (typ ==SOCK_STREAM || typ ==SOCK_SEQPACKET ) { +if (sk->sk_state ==TIPC_DISCONNECTING ) +return -EPIPE ; +else if (!tipc_sk_connected (sk)) +return -ENOTCONN ; + } +if (!*timeout) +return -EAGAIN ; +if (signal_pending (current)) +return sock_intr_errno (*timeout); + +return 0 ; +} + +#define tipc_wait_for_cond (sock_, timeout_, condition_) \ +({ \ + int rc_ = 0; \ + int done_ = 0; \ + \ + while (!(condition_) && !done_) { \ + struct sock *sk_ = sock->sk; \ + DEFINE_WAIT_FUNC(wait_, woken_wake_function); \ + \ + rc_ = tipc_sk_sock_err(sock_, timeout_); \ + if (rc_) \ + break; \ + prepare_to_wait(sk_sleep(sk_), &wait_, \ + TASK_INTERRUPTIBLE); \ + done_ = sk_wait_event(sk_, timeout_, \ + (condition_), &wait_); \ + remove_wait_queue(sk_sleep(sk_), &wait_); \ + } \ + rc_; \ +}) +/** * tipc_sk_create - create a TIPC socket * @net: network namespace (must be default network)
@@ -721,7 +763,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,if (rc == -ELINKCONG ) { tsk->link_cong =1 ; - rc =tipc_wait_for_sndmsg (sock, &timeo); + rc =tipc_wait_for_cond (sock, &timeo, !tsk->link_cong);if (!rc)continue ; }
@@ -830,31 +872,6 @@ static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb,kfree_skb (skb); } -static int tipc_wait_for_sndmsg (struct socket *sock,long *timeo_p) -{ -DEFINE_WAIT_FUNC (wait, woken_wake_function); -struct sock *sk = sock->sk; -struct tipc_sock *tsk =tipc_sk (sk); -int done; - -do { -int err =sock_error (sk); -if (err) -return err; -if (sk->sk_shutdown &SEND_SHUTDOWN ) -return -EPIPE ; -if (!*timeo_p) -return -EAGAIN ; -if (signal_pending (current)) -return sock_intr_errno (*timeo_p); - -add_wait_queue (sk_sleep (sk), &wait); - done =sk_wait_event (sk, timeo_p, !tsk->link_cong, &wait); -remove_wait_queue (sk_sleep (sk), &wait); - }while (!done); -return 0 ; -} -/** * tipc_sendmsg - send message in connectionless manner * @sock: socket structure
@@ -970,7 +987,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz) }if (rc == -ELINKCONG ) { tsk->link_cong =1 ; - rc =tipc_wait_for_sndmsg (sock, &timeo); + rc =tipc_wait_for_cond (sock, &timeo, !tsk->link_cong);if (!rc)continue ; }
@@ -985,36 +1002,6 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz)return rc; } -static int tipc_wait_for_sndpkt (struct socket *sock,long *timeo_p) -{ -DEFINE_WAIT_FUNC (wait, woken_wake_function); -struct sock *sk = sock->sk; -struct tipc_sock *tsk =tipc_sk (sk); -int done; - -do { -int err =sock_error (sk); -if (err) -return err; -if (sk->sk_state ==TIPC_DISCONNECTING ) -return -EPIPE ; -else if (!tipc_sk_connected (sk)) -return -ENOTCONN ; -if (!*timeo_p) -return -EAGAIN ; -if (signal_pending (current)) -return sock_intr_errno (*timeo_p); - -add_wait_queue (sk_sleep (sk), &wait); - done =sk_wait_event (sk, timeo_p, - (!tsk->link_cong && - !tsk_conn_cong (tsk)) || - !tipc_sk_connected (sk), &wait); -remove_wait_queue (sk_sleep (sk), &wait); - }while (!done); -return 0 ; -} -/** * tipc_send_stream - send stream-oriented data * @sock: socket structure
@@ -1109,7 +1096,10 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz) tsk->link_cong =1 ; } - rc =tipc_wait_for_sndpkt (sock, &timeo); + rc =tipc_wait_for_cond (sock, &timeo, + (!tsk->link_cong && + !tsk_conn_cong (tsk) && +tipc_sk_connected (sk))); }while (!rc);__skb_queue_purge (&pktchain);
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
PATCH 2/3 tipc: modify struct tipc_plist to be more versatile
In reply to Jon MaloyDuring multicast reception we currently use a simple linked list with push/pop semantics to store port numbers.
We now see a need for a more generic list for storing values of type u32. We therefore make some modifications to this list, while replacing the prefix 'tipc_plist_' with 'u32_'. We also add a couple of new functions which will come to use in the next commits.
--- net/tipc/name_table.c | 100 ++++++++++++++++++++++++++++++++++++-------------- net/tipc/name_table.h | 21 ++++------- net/tipc/socket.c | 8 ++-- 3 files changed, 83 insertions(+), 46 deletions(-)
net/tipc/name_table.c +72 -28
@@ -608,7 +608,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,* Returns non-zero if any off-node ports overlap */ int tipc_nametbl_mc_translate (struct net *net,u32 type,u32 lower,u32 upper, -u32 limit,struct tipc_plist *dports) +u32 limit,struct list_head *dports) {struct name_seq *seq;struct sub_seq *sseq;
@@ -633,7 +633,7 @@ int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper, info = sseq->info;list_for_each_entry (publ, &info->node_list, node_list) {if (publ->scope <= limit) -tipc_plist_push (dports, publ->ref); +u32_push (dports, publ->ref); }if (info->cluster_list_size != info->node_list_size)
@@ -1022,40 +1022,84 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)return skb->len; } -void tipc_plist_push (struct tipc_plist *pl,u32 port) +struct u32_item { +struct list_head list; +u32 value; +}; + +bool u32_find (struct list_head *l,u32 value) { -struct tipc_plist *nl; +struct u32_item *item; -if (likely (!pl->port)) { - pl->port = port; -return ; +list_for_each_entry (item, l, list) { +if (item->value == value) +return true; } -if (pl->port == port) -return ; -list_for_each_entry (nl, &pl->list, list) { -if (nl->port == port) -return ; +return false; +} + +bool u32_push (struct list_head *l,u32 value) +{ +struct u32_item *item; + +list_for_each_entry (item, l, list) { +if (item->value == value) +return false; + } + item =kmalloc (sizeof (*item),GFP_ATOMIC ); +if (unlikely (!item)) +return false; + + item->value = value; +list_add (&item->list, l); +return true; +} + +u32 u32_pop (struct list_head *l) +{ +struct u32_item *item; +u32 value =0 ; + +if (list_empty (l)) +return 0 ; + item =list_first_entry (l,typeof (*item), list); + value = item->value; +list_del (&item->list); +kfree (item); +return value; +} + +bool u32_del (struct list_head *l,u32 value) +{ +struct u32_item *item, *tmp; + +list_for_each_entry_safe (item, tmp, l, list) { +if (item->value != value) +continue ; +list_del (&item->list); +kfree (item); +return true; } - nl =kmalloc (sizeof (*nl),GFP_ATOMIC ); -if (nl) { - nl->port = port; -list_add (&nl->list, &pl->list); +return false; +} + +void u32_list_purge (struct list_head *l) +{ +struct u32_item *item, *tmp; + +list_for_each_entry_safe (item, tmp, l, list) { +list_del (&item->list); +kfree (item); } } -u32 tipc_plist_pop (struct tipc_plist *pl) +int u32_list_len (struct list_head *l) { -struct tipc_plist *nl; -u32 port =0 ; +struct u32_item *item; +int i =0 ; -if (likely (list_empty (&pl->list))) { - port = pl->port; - pl->port =0 ; -return port; +list_for_each_entry (item, l, list) { + i++; } - nl =list_first_entry (&pl->list,typeof (*nl), list); - port = nl->port; -list_del (&nl->list); -kfree (nl); -return port; +return i; }
net/tipc/name_table.h +7 -14
@@ -99,7 +99,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);u32 tipc_nametbl_translate (struct net *net,u32 type,u32 instance,u32 *node);int tipc_nametbl_mc_translate (struct net *net,u32 type,u32 lower,u32 upper, -u32 limit,struct tipc_plist *dports); +u32 limit,struct list_head *dports);struct publication *tipc_nametbl_publish (struct net *net,u32 type,u32 lower,u32 upper,u32 scope,u32 port_ref,u32 key);
@@ -116,18 +116,11 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s);int tipc_nametbl_init (struct net *net);void tipc_nametbl_stop (struct net *net); -struct tipc_plist { -struct list_head list; -u32 port; -}; - -static inline void tipc_plist_init (struct tipc_plist *pl) -{ -INIT_LIST_HEAD (&pl->list); - pl->port =0 ; -} - -void tipc_plist_push (struct tipc_plist *pl,u32 port); -u32 tipc_plist_pop (struct tipc_plist *pl); +bool u32_push (struct list_head *l,u32 value); +u32 u32_pop (struct list_head *l); +bool u32_find (struct list_head *l,u32 value); +bool u32_del (struct list_head *l,u32 value); +void u32_list_purge (struct list_head *l); +int u32_list_len (struct list_head *l);#endif
net/tipc/socket.c +4 -4
@@ -788,7 +788,7 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, struct sk_buff_head *inputq) {struct tipc_msg *msg; -struct tipc_plist dports; +struct list_head dports;u32 portid;u32 scope =TIPC_CLUSTER_SCOPE ;struct sk_buff_head tmpq;
@@ -796,7 +796,7 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,struct sk_buff *skb, *_skb;__skb_queue_head_init (&tmpq); -tipc_plist_init (&dports); +INIT_LIST_HEAD (&dports); skb =tipc_skb_peek (arrvq, &inputq->lock);for (; skb; skb =tipc_skb_peek (arrvq, &inputq->lock)) {
@@ -810,8 +810,8 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq,tipc_nametbl_mc_translate (net,msg_nametype (msg),msg_namelower (msg),msg_nameupper (msg), scope, &dports); - portid =tipc_plist_pop (&dports); -for (; portid; portid =tipc_plist_pop (&dports)) { + portid =u32_pop (&dports); +for (; portid; portid =u32_pop (&dports)) { _skb =__pskb_copy (skb, hsz,GFP_ATOMIC );if (_skb) {msg_set_destport (buf_msg (_skb), portid);
Signature · 1 line
2.7.4
PATCH 3/3 tipc: reduce risk of user starvation during link congestion
In reply to Jon MaloyThe socket code currently handles link congestion by either blocking and trying to send again when the congestion has abated, or just returning to the user with -EAGAIN and let him re-try later.
This mechanism is prone to starvation, because the wakeup algorithm is non-atomic. During the time the link issues a wakeup signal, until the socket wakes up and re-attempts sending, other senders may have come in between and occupied the free buffer space in the link. This in turn may lead to a socket having to make many send attempts before it is successful. In extremely loaded systems we have observed latency times of several seconds before a low-priority socket is able to send out a message.
In this commit, we simplify this mechanism and reduce the risk of the described scenario happening. When a message is attempted sent via a congested link, we now let it be added to the link's backlog queue anyway, thus permitting an oversubscription of one message per source socket. We still create a wakeup item and return an error code, hence instructing the sender to block or stop sending. Only when enough space has been freed up in the link's backlog queue do we issue a wakeup event that allows the sender to continue with the next message, if any.
The fact that a socket now can consider a message sent even when the link returns a congestion code means that the sending socket code can be simplified. Also, since this is a good opportunity to get rid of the obsolete 'mtu change' condition in the three socket send functions, we now choose to refactor those functions completely.
--- net/tipc/bcast.c | 6 +- net/tipc/link.c | 75 +++++------- net/tipc/msg.h | 2 - net/tipc/node.c | 15 +-- net/tipc/socket.c | 347 ++++++++++++++++++++++++------------------------------ 5 files changed, 194 insertions(+), 251 deletions(-)
net/tipc/bcast.c +3 -3
@@ -174,7 +174,7 @@ static void tipc_bcbase_xmit(struct net *net, struct sk_buff_head *xmitq)* and to identified node local sockets * @net: the applicable net namespace * @list: chain of buffers containing message -* Consumes the buffer chain, except when returning -ELINKCONG +* Consumes the buffer chain. * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE */ int tipc_bcast_xmit (struct net *net,struct sk_buff_head *list)
@@ -197,7 +197,7 @@ int tipc_bcast_xmit(struct net *net, struct sk_buff_head *list)tipc_bcast_unlock (net);/* Don't send to local node if adding to link failed */ -if (unlikely (rc)) { +if (unlikely (rc && (rc != -ELINKCONG ))) {__skb_queue_purge (&rcvq);return rc; }
@@ -206,7 +206,7 @@ int tipc_bcast_xmit(struct net *net, struct sk_buff_head *list)tipc_bcbase_xmit (net, &xmitq);tipc_sk_mcast_rcv (net, &rcvq, &inputq);__skb_queue_purge (list); -return 0 ; +return rc; }/* tipc_bcast_rcv - receive a broadcast packet, and deliver to rcv link
net/tipc/link.c +32 -43
133 lines not on this page · raw message
net/tipc/msg.h +0 -2
@@ -98,8 +98,6 @@ struct tipc_skb_cb {u32 bytes_read;struct sk_buff *tail;bool validated; -bool wakeup_pending; -u16 chain_sz;u16 chain_imp;u16 ackers; };
net/tipc/node.c +5 -10
@@ -1167,7 +1167,7 @@ static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)* @list: chain of buffers containing message * @dnode: address of destination node * @selector: a number used for deterministic link selection -* Consumes the buffer chain, except when returning -ELINKCONG +* Consumes the buffer chain. * Returns 0 if success, otherwise: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE,-ENOBUF */ int tipc_node_xmit(struct net *net, struct sk_buff_head *list,
@@ -1206,10 +1206,10 @@ int tipc_node_xmit(struct net *net, struct sk_buff_head *list,spin_unlock_bh (&le->lock);tipc_node_read_unlock (n); -if (likely (rc ==0 )) -tipc_bearer_xmit (net, bearer_id, &xmitq, &le->maddr); -else if (rc == -ENOBUFS ) +if (unlikely (rc == -ENOBUFS ))tipc_node_link_down (n, bearer_id, false); +else +tipc_bearer_xmit (net, bearer_id, &xmitq, &le->maddr);tipc_node_put (n);
@@ -1221,20 +1221,15 @@ int tipc_node_xmit(struct net *net, struct sk_buff_head *list,* messages, which will not be rejected * The only exception is datagram messages rerouted after secondary * lookup, which are rare and safe to dispose of anyway. -* TODO: Return real return value, and let callers use -* tipc_wait_for_sendpkt() where applicable */ int tipc_node_xmit_skb (struct net *net,struct sk_buff *skb,u32 dnode,u32 selector) {struct sk_buff_head head; -int rc;skb_queue_head_init (&head);__skb_queue_tail (&head, skb); - rc =tipc_node_xmit (net, &head, dnode, selector); -if (rc == -ELINKCONG ) -kfree_skb (skb); +tipc_node_xmit (net, &head, dnode, selector);return 0 ; }
net/tipc/socket.c +154 -193
525 lines not on this page · raw message
Signature · 1 line
2.7.4
David Miller
maintainerFrom: Jon Maloy <[email protected]>
Date: Tue, 3 Jan 2017 10:26:45 -0500
Quoted 4 lines
We fix a very real starvation problem that may occur when a link encounters send buffer congestion. At the same time we make the interaction between the socket and link layer simpler and more consistent.
This doesn't apply to net-next, also the Date in your emails is 10 days in the past. What's going on here?
Quoted 16 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of David Miller
Sent: Monday, 16 January, 2017 14:45
To: Jon Maloy <[email protected]>
Cc: [email protected]; [email protected]; Parthasarathy Bhuvaragan <[email protected]>; Ying Xue <[email protected]>; [email protected]; tipc- [email protected]
Subject: Re: [net-next 0/3] tipc: improve interaction socket-linkFrom: Jon Maloy <[email protected]>
Date: Tue, 3 Jan 2017 10:26:45 -0500
Quoted 7 lines
Quoted 4 lines
We fix a very real starvation problem that may occur when a link encounters send buffer congestion. At the same time we make the interaction between the socket and link layer simpler and more consistent.
This doesn't apply to net-next, also the Date in your emails is 10 days in the past. What's going on here?
I don't know. This series was sent in on Jan 3rd, and applied by you the same day. Maybe the mail server decided to send you a duplicate?
///jon
David Miller
maintainerFrom: Jon Maloy <[email protected]>
Date: Mon, 16 Jan 2017 20:35:08 +0000
Quoted 21 lines
Quoted 21 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of David Miller
Sent: Monday, 16 January, 2017 14:45
To: Jon Maloy <[email protected]>
Cc: [email protected]; [email protected]; Parthasarathy Bhuvaragan <[email protected]>; Ying Xue <[email protected]>; [email protected]; tipc- [email protected]
Subject: Re: [net-next 0/3] tipc: improve interaction socket-linkFrom: Jon Maloy <[email protected]>
Date: Tue, 3 Jan 2017 10:26:45 -0500Quoted 4 lines
We fix a very real starvation problem that may occur when a link encounters send buffer congestion. At the same time we make the interaction between the socket and link layer simpler and more consistent.
Quoted 4 lines
Quoted 2 lines
This doesn't apply to net-next, also the Date in your emails is 10 days in the past. What's going on here?
I don't know. This series was sent in on Jan 3rd, and applied by you the same day. Maybe the mail server decided to send you a duplicate?
If you look in the headers, they have "Received-by: " fields with January 13th in the date. So something pushed them out again.
Really strange...