Skip to contentSkip to conversation

ip: faster in-order IP fragments

PATCH In review Peter Oskolkov 2 participants 4 messages Aug 11, 2018 – Aug 12, 2018

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

v2 cover ip: faster in-order IP fragments

Added "Signed-off-by" in v2.

Peter Oskolkov (2):
ip: add helpers to process in-order fragments faster.
ip: process in-order fragments efficiently

 include/net/inet_frag.h  |   6 ++
 net/ipv4/inet_fragment.c |   2 +-
 net/ipv4/ip_fragment.c   | 183 ++++++++++++++++++++++++++++++---------
 3 files changed, 149 insertions(+), 42 deletions(-)
Signature · 1 line
2.18.0.597.ga71716f1ad-goog
#1 lore raw

PATCH v2 1/2 ip: add helpers to process in-order fragments faster.

This patch introduces several helper functions/macros that will be used in the follow-up patch. No runtime changes yet.

The new logic (fully implemented in the second patch) is as follows:

* Nodes in the rb-tree will now contain not single fragments, but lists of consecutive fragments ("runs").

* At each point in time, the current "active" run at the tail is maintained/tracked. Fragments that arrive in-order, adjacent to the previous tail fragment, are added to this tail run without triggering the re-balancing of the rb-tree.

* If a fragment arrives out of order with the offset _before_ the tail run, it is inserted into the rb-tree as a single fragment.

* If a fragment arrives after the current tail fragment (with a gap), it starts a new "tail" run, as is inserted into the rb-tree at the end as the head of the new run.

skb->cb is used to store additional information
needed here (suggested by Eric Dumazet).

---
 include/net/inet_frag.h |  6 ++++
 net/ipv4/ip_fragment.c  | 73 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)
include/net/inet_frag.h +6 -0
index b86d14528188..1662cbc0b46b 100644
@@ -57,7 +57,9 @@ struct frag_v6_compare_key {
  * @lock: spinlock protecting this frag
  * @refcnt: reference count of the queue
  * @fragments: received fragments head
+ * @rb_fragments: received fragments rb-tree root
  * @fragments_tail: received fragments tail
+ * @last_run_head: the head of the last "run". see ip_fragment.c
  * @stamp: timestamp of the last received fragment
  * @len: total length of the original datagram
  * @meat: length of received fragments so far
@@ -78,6 +80,7 @@ struct inet_frag_queue {
 	struct sk_buff		*fragments;  /* Used in IPv6. */
 	struct rb_root		rb_fragments; /* Used in IPv4. */
 	struct sk_buff		*fragments_tail;
+	struct sk_buff		*last_run_head;
 	ktime_t			stamp;
 	int			len;
 	int			meat;
@@ -113,6 +116,9 @@ void inet_frag_kill(struct inet_frag_queue *q);
 void inet_frag_destroy(struct inet_frag_queue *q);
 struct inet_frag_queue *inet_frag_find(struct netns_frags *nf, void *key);
 
+/* Free all skbs in the queue; return the sum of their truesizes. */
+unsigned int inet_frag_rbtree_purge(struct rb_root *root);
+
 static inline void inet_frag_put(struct inet_frag_queue *q)
 {
 	if (refcount_dec_and_test(&q->refcnt))
net/ipv4/ip_fragment.c +73 -0

85 lines not on this page · raw message

Signature · 1 line
2.18.0.597.ga71716f1ad-goog
#2 lore raw

PATCH v2 2/2 ip: process in-order fragments efficiently

In reply to Peter Oskolkov

This patch changes the runtime behavior of IP defrag queue:
incoming in-order fragments are added to the end of the current list/"run" of in-order fragments at the tail.

On some workloads, UDP stream performance is substantially improved:

RX: ./udp_stream -F 10 -T 2 -l 60
TX: ./udp_stream -c -H <host> -F 10 -T 5 -l 60

with this patchset applied on a 10Gbps receiver:

throughput=9524.18
throughput_units=Mbit/s

upstream (net-next):

throughput=4608.93
throughput_units=Mbit/s

---
 net/ipv4/inet_fragment.c |   2 +-
 net/ipv4/ip_fragment.c   | 110 ++++++++++++++++++++++++---------------
 2 files changed, 70 insertions(+), 42 deletions(-)
net/ipv4/inet_fragment.c +1 -1
index 6d258a5669e7..bcb11f3a27c0 100644
@@ -146,7 +146,7 @@ void inet_frag_destroy(struct inet_frag_queue *q)
 			fp = xp;
 		} while (fp);
 	} else {
-		sum_truesize = skb_rbtree_purge(&q->rb_fragments);
+		sum_truesize = inet_frag_rbtree_purge(&q->rb_fragments);
 	}
 	sum = sum_truesize + f->qsize;
 
net/ipv4/ip_fragment.c +69 -41

203 lines not on this page · raw message

Signature · 1 line
2.18.0.597.ga71716f1ad-goog