message reassembly improvements
Subsystems (3)
cover message reassembly improvements
We introduce a new defragmentation algorithm that improves performance and eliminates the risk of causing out-of-memory situations.
Erik Hugne (3):
tipc: don't reroute message fragments
tipc: message reassembly using fragment chain
tipc: reassembly failures should cause link reset
net/tipc/bcast.c | 16 ++++-- net/tipc/link.c | 161 +++++++++++++++--------------------------------------- net/tipc/link.h | 20 +++++-- net/tipc/msg.h | 12 ---- net/tipc/node.c | 7 ++- net/tipc/node.h | 6 +- 6 files changed, 77 insertions(+), 145 deletions(-)
Signature · 9 lines
1.7.9.5 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
PATCH 1/3 tipc: don't reroute message fragments
From: Erik Hugne <[email protected]>
When a message fragment is received in a broadcast or unicast link, the reception code will append the fragment payload to a big reassembly buffer through a call to the function tipc_recv_fragm(). However, after the return of that call, the logics goes on and passes the fragment buffer to the function tipc_net_route_msg(), which will simply drop it. This behavior is a remnant from the now obsolete multi-cluster functionality, and has no relevance in the current code base.
Although currently harmless, this unnecessary call would be fatal after applying the next patch in this series, which introduces a completely new defragmentation algorithm. So we change the code to eliminate the redundant call.
--- net/tipc/bcast.c | 6 ++++-- net/tipc/link.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
net/tipc/bcast.c +4 -2
@@ -487,11 +487,13 @@ receive:spin_lock_bh (&bc_lock);bclink_accept_pkt (node, seqno); bcl->stats.recv_fragments++; -if (ret >0 ) +if (ret >0 ) { bcl->stats.recv_fragmented++; +spin_unlock_bh (&bc_lock); + goto receive; + }spin_unlock_bh (&bc_lock);tipc_node_unlock (node); -tipc_net_route_msg (buf); }else if (msg_user (msg) ==NAME_DISTRIBUTOR ) {spin_lock_bh (&bc_lock);bclink_accept_pkt (node, seqno);
net/tipc/link.c +1 -1
@@ -1638,7 +1638,7 @@ deliver: }if (ret ==-1 ) l_ptr->next_in_no--; -break ; +continue ;case CHANGEOVER_PROTOCOL : type =msg_type (msg); if (link_recv_changeover_msg(&l_ptr,
Signature · 9 lines
1.7.9.5 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
PATCH 2/3 tipc: message reassembly using fragment chain
In reply to Jon MaloyFrom: Erik Hugne <[email protected]>
When the first fragment of a long data data message is received on a link, a reassembly buffer large enough to hold the data from this and all subsequent fragments of the message is allocated. The payload of each new fragment is copied into this buffer upon arrival. When the last fragment is received, the reassembled message is delivered upwards to the port/socket layer.
Not only is this an inefficient approach, but it may also cause bursts of reassembly failures in low memory situations. since we may fail to allocate the necessary large buffer in the first place. Furthermore, after 100 subsequent such failures the link will be reset, something that in reality aggravates the situation.
To remedy this problem, this patch introduces a different approach. Instead of allocating a big reassembly buffer, we now append the arriving fragments to a reassembly chain on the link, and deliver the whole chain up to the socket layer once the last fragment has been received. This is safe because the retransmission layer of a TIPC link always delivers packets in strict uninterrupted order, to the reassembly layer as to all other upper layers. Hence there can never be more than one fragment chain pending reassembly at any given time in a link, and we can trust (but still verify) that the fragments will be chained up in the correct order.
--- net/tipc/bcast.c | 12 +++-- net/tipc/link.c | 157 +++++++++++++++--------------------------------------- net/tipc/link.h | 20 ++++--- net/tipc/msg.h | 12 ----- net/tipc/node.c | 7 +-- net/tipc/node.h | 6 ++- 6 files changed, 72 insertions(+), 142 deletions(-)
net/tipc/bcast.c +8 -4
@@ -480,15 +480,19 @@ receive:tipc_node_unlock (node);tipc_link_recv_bundle (buf); }else if (msg_user (msg) ==MSG_FRAGMENTER ) { -int ret =tipc_link_recv_fragment (&node->bclink.defragm, - &buf, &msg); -if (ret <0 ) +int ret =tipc_link_recv_fragment ( + &node->bclink.reasm_head, + &node->bclink.reasm_tail, + &buf); +if (ret ==LINK_REASM_ERROR ) goto unlock;spin_lock_bh (&bc_lock);bclink_accept_pkt (node, seqno); bcl->stats.recv_fragments++; -if (ret >0 ) { +if (ret ==LINK_REASM_COMPLETE ) { bcl->stats.recv_fragmented++; +/* Point msg to inner header */ + msg =buf_msg (buf);spin_unlock_bh (&bc_lock); goto receive; }
net/tipc/link.c +42 -115
185 lines not on this page · raw message
net/tipc/link.h +14 -6
@@ -41,6 +41,12 @@#include "node.h" /* +* Link reassembly status codes +*/ +#define LINK_REASM_ERROR -1 +#define LINK_REASM_COMPLETE 1 + +/* * Out-of-range value for link sequence numbers */ #define INVALID_LINK_SEQ 0x10000
@@ -134,7 +140,8 @@ struct tipc_stats {* @next_out: ptr to first unsent outbound message in queue * @waiting_ports: linked list of ports waiting for link congestion to abate * @long_msg_seq_no: next identifier to use for outbound fragmented messages -* @defragm_buf: list of partially reassembled inbound message fragments +* @reasm_head: list head of partially reassembled inbound message fragments +* @reasm_tail: last fragment received * @stats: collects statistics regarding link activity */ struct tipc_link {
@@ -196,9 +203,10 @@ struct tipc_link {struct sk_buff *next_out;struct list_head waiting_ports; -/* Fragmentation/defragmentation */ +/* Fragmentation/reassembly */ u32 long_msg_seq_no; -struct sk_buff *defragm_buf; +struct sk_buff *reasm_head; +struct sk_buff *reasm_tail;/* Statistics */ struct tipc_stats stats;
@@ -229,9 +237,9 @@ int tipc_link_send_sections_fast(struct tipc_port *sender,struct iovec const *msg_sect, unsigned int len, u32 destnode);void tipc_link_recv_bundle (struct sk_buff *buf); -int tipc_link_recv_fragment (struct sk_buff **pending, -struct sk_buff **fb, -struct tipc_msg **msg); +int tipc_link_recv_fragment (struct sk_buff **reasm_head, +struct sk_buff **reasm_tail, +struct sk_buff **fbuf);void tipc_link_send_proto_msg (struct tipc_link *l_ptr,u32 msg_typ,int prob,u32 gap,u32 tolerance,u32 priority,u32 acked_mtu);
net/tipc/msg.h +0 -12
@@ -554,12 +554,6 @@ static inline void msg_set_last_bcast(struct tipc_msg *m, u32 n)msg_set_bits (m,4 ,16 ,0xffff , n); } - -static inline u32 msg_fragm_no (struct tipc_msg *m) -{ -return msg_bits (m,4 ,16 ,0xffff ); -} -static inline void msg_set_fragm_no (struct tipc_msg *m,u32 n) {msg_set_bits (m,4 ,16 ,0xffff , n);
@@ -576,12 +570,6 @@ static inline void msg_set_next_sent(struct tipc_msg *m, u32 n)msg_set_bits (m,4 ,0 ,0xffff , n); } - -static inline u32 msg_long_msgno (struct tipc_msg *m) -{ -return msg_bits (m,4 ,0 ,0xffff ); -} -static inline void msg_set_long_msgno (struct tipc_msg *m,u32 n) {msg_set_bits (m,4 ,0 ,0xffff , n);
net/tipc/node.c +4 -3
@@ -298,9 +298,10 @@ static void node_lost_contact(struct tipc_node *n_ptr) } n_ptr->bclink.deferred_size =0 ; -if (n_ptr->bclink.defragm) { -kfree_skb (n_ptr->bclink.defragm); - n_ptr->bclink.defragm =NULL ; +if (n_ptr->bclink.reasm_head) { +kfree_skb (n_ptr->bclink.reasm_head); + n_ptr->bclink.reasm_head =NULL ; + n_ptr->bclink.reasm_tail =NULL ; }tipc_bclink_remove_node (n_ptr->addr);
net/tipc/node.h +4 -2
@@ -74,7 +74,8 @@* @deferred_size: number of OOS b'cast messages in deferred queue * @deferred_head: oldest OOS b'cast message received from node * @deferred_tail: newest OOS b'cast message received from node -* @defragm: list of partially reassembled b'cast message fragments from node +* @reasm_head: broadcast reassembly queue head from node +* @reasm_tail: last broadcast fragment received from node * @recv_permitted: true if node is allowed to receive b'cast messages */ struct tipc_node {
@@ -98,7 +99,8 @@ struct tipc_node {u32 deferred_size;struct sk_buff *deferred_head;struct sk_buff *deferred_tail; -struct sk_buff *defragm; +struct sk_buff *reasm_head; +struct sk_buff *reasm_tail;bool recv_permitted; } bclink; };
Signature · 9 lines
1.7.9.5 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
PATCH 3/3 tipc: reassembly failures should cause link reset
In reply to Jon MaloyFrom: Erik Hugne <[email protected]>
If appending a received fragment to the pending fragment chain in a unicast link fails, the current code tries to force a retransmission of the fragment by decrementing the 'next received sequence number' field in the link. This is done under the assumption that the failure is caused by an out-of-memory situation, an assumption that does not hold true after the previous patch in this series.
A failure to append a fragment can now only be caused by a protocol violation by the sending peer, and it must hence be assumed that it is either malicious or buggy. Either way, the correct behavior is now to reset the link instead of trying to revert its sequence number. So, this is what we do in this commit.
--- net/tipc/link.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/link.c +1 -1
@@ -1634,7 +1634,7 @@ deliver: goto deliver; }if (ret ==LINK_REASM_ERROR ) - l_ptr->next_in_no--; +tipc_link_reset (l_ptr);tipc_node_unlock (n_ptr);continue ;case CHANGEOVER_PROTOCOL :
Signature · 9 lines
1.7.9.5 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
David Miller
maintainerRe: [PATCH net-next 2/3] tipc: message reassembly using fragment chain
In reply to Jon MaloyFrom: Jon Maloy <[email protected]>
Date: Sat, 26 Oct 2013 14:41:02 -0400
net/tipc/bcast.c receive: · line 486
Quoted 4 lines
net/tipc/bcast.c +4
-0+int ret =tipc_link_recv_fragment ( + &node->bclink.reasm_head, + &node->bclink.reasm_tail, + &buf);
This is not the correct way to indent a function call that spans multiple lines. In such a situation the arguments that appear on the second and subsequent lines must start at the first column after the openning parenthesis of the function call.
Like this:
func(a, b, c, d, e, f);
Please audit this in your entire set of patches and resubmit, thanks.
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
Re: [PATCH net-next 2/3] tipc: message reassembly using fragment chain
Quoted 12 lines · David Miller
From: Jon Maloy <[email protected]>
Date: Sat, 26 Oct 2013 14:41:02 -0400net/tipc/bcast.c receive: · line 486
Quoted 4 lines
net/tipc/bcast.c +4
-0+int ret =tipc_link_recv_fragment ( + &node->bclink.reasm_head, + &node->bclink.reasm_tail, + &buf);This is not the correct way to indent a function call that spans multiple lines. In such a situation the arguments that appear on the second and subsequent lines must start at the first column after the openning parenthesis of the function call.
Quoted 7 lines
Like this:
func(a, b, c, d, e, f);Please audit this in your entire set of patches and resubmit, thanks.
Doing as David says here means that some lines will be >80 chars. This was the reason for the somewhat strange indentation. I tried to rename the function to tipc_link_rcv_fragm(), but one line was still too long. The problem we have goes deeper.
In Linus' coding style manual I read that the 80 char limit is a hard limit, a limit we violate in several places. One offender is that we have too many indentation levels, at least in tipc_recv_msg() and probably in some other places. This is sensitive code, that I don't feel for touching right now. A more low hanging fruit is our local variable names:
names such as l_ptr, n_ptr, b_ptr is exactly what Linus characterizes as "brain dead Hungarian style", and I never liked that naming anyway. For me l, n, and b is good enough as long as the context is clear.
But, doing so, at least in tipc_recv_msg(), would require another, separate, patch, and it would lead to style inconsistency.
In brief, I am at loss about to proceed here, and I am not going to submit this patch again until I have some feedback from somebody who can tell me what is the right thing to do. Maybe > 80 chars is fine for now?
///jon
Re: [PATCH net-next 2/3] tipc: message reassembly using fragment chain
Quoted 35 lines · Jon Maloy
Quoted 12 lines · David Miller
From: Jon Maloy <[email protected]>
Date: Sat, 26 Oct 2013 14:41:02 -0400net/tipc/bcast.c receive: · line 486
Quoted 4 lines
net/tipc/bcast.c +4
-0+int ret =tipc_link_recv_fragment ( + &node->bclink.reasm_head, + &node->bclink.reasm_tail, + &buf);This is not the correct way to indent a function call that spans multiple lines. In such a situation the arguments that appear on the second and subsequent lines must start at the first column after the openning parenthesis of the function call.
Quoted 7 lines
Like this:
func(a, b, c, d, e, f);Please audit this in your entire set of patches and resubmit, thanks.
Doing as David says here means that some lines will be >80 chars. This was the reason for the somewhat strange indentation. I tried to rename the function to
tipc_link_rcv_fragm(), but one line was still too long. The problem we have goes deeper.In Linus' coding style manual I read that the 80 char limit is a hard limit, a limit we violate in several places. One offender is that we have too many indentation levels, at least in
tipc_recv_msg()and probably in some other places. This is sensitive code, that I don't feel for touching right now. A more low hanging fruit is our local variable names:
names such asl_ptr,n_ptr,b_ptris exactly what Linus characterizes as "brain dead Hungarian style", and I never liked that naming anyway. For me l, n, and b is good enough as long as the context is clear.
Quoted 7 lines
But, doing so, at least in
tipc_recv_msg(), would require another, separate, patch, and it would lead to style inconsistency.In brief, I am at loss about to proceed here, and I am not going to submit this patch again until I have some feedback from somebody who can tell me what is the right thing to do. Maybe > 80 chars is fine for now?
It's hard completely resolve the issue by simply changing variable names. So in my opinion, this is not a simple code style problem any more. As tipc_recv_msg() is too complex, it includes at least three embedded loops so that it doesn't remain too much space for functions in the most inner loop. This is the key point.
Therefore, the best method is to divide tipc_recv_msg() into several smaller functions to simplify the current implementation. But it's not an easy job. Actually I ever tried to do it, but I gave up lastly because I did not find one perfect solution about how to divide it.
Regards,
Ying
Quoted 5 lines
///jon
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
David Miller
maintainerRe: [PATCH net-next 2/3] tipc: message reassembly using fragment chain
From: Ying Xue <[email protected]>
Date: Tue, 29 Oct 2013 09:56:56 +0800
Quoted 4 lines
Therefore, the best method is to divide
tipc_recv_msg()into several smaller functions to simplify the current implementation. But it's not an easy job. Actually I ever tried to do it, but I gave up lastly because I did not find one perfect solution about how to divide it.
But you're going to have to find a way, this indent level is out of control.
Re: [PATCH net-next 2/3] tipc: message reassembly using fragment chain
Quoted 12 lines · David Miller
From: Ying Xue <[email protected]>
Date: Tue, 29 Oct 2013 09:56:56 +0800Quoted 4 lines
Therefore, the best method is to divide
tipc_recv_msg()into several smaller functions to simplify the current implementation. But it's not an easy job. Actually I ever tried to do it, but I gave up lastly because I did not find one perfect solution about how to divide it.But you're going to have to find a way, this indent level is out of control.
By simply adjusting the order of branch blocks, this is what I can figure out the simplest method to resolve the issue now :)
Please review below change. If it's fine, I will send one formal patch. (Below change still follows original code logic)
net/tipc/link.c +72 -75
@@ -1592,97 +1592,94 @@ void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *b_ptr)/* Now (finally!) process the incoming message */ protocol_check: -if (likely (link_working_working (l_ptr))) { -if (likely (seq_no ==mod (l_ptr->next_in_no))) { - l_ptr->next_in_no++; -if (unlikely (l_ptr->oldest_deferred_in)) - head =link_insert_deferred_queue (l_ptr, - head); -deliver: -if (likely (msg_isdata (msg))) { -tipc_node_unlock (n_ptr); -tipc_port_recv_msg (buf); -continue ; - } -switch (msg_user (msg)) { -int ret; -case MSG_BUNDLER : - l_ptr->stats.recv_bundles++; - l_ptr->stats.recv_bundled += -msg_msgcnt (msg); -tipc_node_unlock (n_ptr); -tipc_link_recv_bundle (buf); -continue ; -case NAME_DISTRIBUTOR : - n_ptr->bclink.recv_permitted = true; -tipc_node_unlock (n_ptr); -tipc_named_recv (buf); -continue ; -case BCAST_PROTOCOL : -tipc_link_recv_sync (n_ptr, buf); -tipc_node_unlock (n_ptr); -continue ; -case CONN_MANAGER : -tipc_node_unlock (n_ptr); -tipc_port_recv_proto_msg (buf); -continue ; -case MSG_FRAGMENTER : - l_ptr->stats.recv_fragments++; - ret =tipc_link_recv_fragment ( - &l_ptr->defragm_buf, - &buf, &msg); -if (ret ==1 ) { - l_ptr->stats.recv_fragmented++; - goto deliver; - } -if (ret ==-1 ) - l_ptr->next_in_no--; -break ; -case CHANGEOVER_PROTOCOL : - type =msg_type (msg); -if (link_recv_changeover_msg (&l_ptr, - &buf)) { - msg =buf_msg (buf); - seq_no =msg_seqno (msg); -if (type ==ORIGINAL_MSG ) - goto deliver; - goto protocol_check; - } -break ; -default : -kfree_skb (buf); - buf =NULL ; -break ; - } +if (unlikely (!link_working_working (l_ptr))) { +if (msg_user (msg) ==LINK_PROTOCOL ) { +link_recv_proto_msg (l_ptr, buf); + head =link_insert_deferred_queue (l_ptr, head); +tipc_node_unlock (n_ptr); +continue ; + } + +/* Traffic message. Conditionally activate link */ +link_state_event (l_ptr,TRAFFIC_MSG_EVT ); + +if (link_working_working (l_ptr)) { +/* Re-insert buffer in front of queue */ + buf->next = head; + head = buf;tipc_node_unlock (n_ptr); -tipc_net_route_msg (buf);continue ; } +tipc_node_unlock (n_ptr); + goto cont; + } + +/* Link is now in state WORKING_WORKING */ +if (unlikely (seq_no !=mod (l_ptr->next_in_no))) {link_handle_out_of_seq_msg (l_ptr, buf); head =link_insert_deferred_queue (l_ptr, head);tipc_node_unlock (n_ptr);continue ; } - -/* Link is not in state WORKING_WORKING */ -if (msg_user (msg) ==LINK_PROTOCOL ) { -link_recv_proto_msg (l_ptr, buf); + l_ptr->next_in_no++; +if (unlikely (l_ptr->oldest_deferred_in)) head =link_insert_deferred_queue (l_ptr, head); +deliver: +if (likely (msg_isdata (msg))) {tipc_node_unlock (n_ptr); +tipc_port_recv_msg (buf);continue ; } - -/* Traffic message. Conditionally activate link */ -link_state_event (l_ptr,TRAFFIC_MSG_EVT ); - -if (link_working_working (l_ptr)) { -/* Re-insert buffer in front of queue */ - buf->next = head; - head = buf; +switch (msg_user (msg)) { +int ret; +case MSG_BUNDLER : + l_ptr->stats.recv_bundles++; + l_ptr->stats.recv_bundled +=msg_msgcnt (msg); +tipc_node_unlock (n_ptr); +tipc_link_recv_bundle (buf); +continue ; +case NAME_DISTRIBUTOR : + n_ptr->bclink.recv_permitted = true; +tipc_node_unlock (n_ptr); +tipc_named_recv (buf); +continue ; +case BCAST_PROTOCOL : +tipc_link_recv_sync (n_ptr, buf); +tipc_node_unlock (n_ptr); +continue ; +case CONN_MANAGER :tipc_node_unlock (n_ptr); +tipc_port_recv_proto_msg (buf);continue ; +case MSG_FRAGMENTER : + l_ptr->stats.recv_fragments++; + ret =tipc_link_recv_fragment (&l_ptr->defragm_buf, + &buf, &msg); +if (ret ==1 ) { + l_ptr->stats.recv_fragmented++; + goto deliver; + } +if (ret ==-1 ) + l_ptr->next_in_no--; +break ; +case CHANGEOVER_PROTOCOL : + type =msg_type (msg); +if (link_recv_changeover_msg (&l_ptr, &buf)) { + msg =buf_msg (buf); + seq_no =msg_seqno (msg); +if (type ==ORIGINAL_MSG ) + goto deliver; + goto protocol_check; + } +break ; +default : +kfree_skb (buf); + buf =NULL ; +break ; }tipc_node_unlock (n_ptr); +tipc_net_route_msg (buf); +continue ; cont:kfree_skb (buf); }
Regards,
Ying