Skip to contentSkip to conversation

fragment: add fast path

PATCH Superseded Changli Gao 5 participants 13 messages Jun 14, 2010

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fragment: add fast path

add fast path

As the fragments are usually in order, it is likely the new fragments are at the end of the inet_frag_queue. In the fast path, we check if the skb at the end of the inet_frag_queue is the prev we expect.

----

 include/net/inet_frag.h |    1 +
 net/ipv4/ip_fragment.c  |   17 +++++++++++++++++
 net/ipv6/reassembly.c   |   16 ++++++++++++++++
 3 files changed, 34 insertions(+)
include/net/inet_frag.h +1 -0
index 39f2dc9..16ff29a 100644
@@ -20,6 +20,7 @@ struct inet_frag_queue {
 	atomic_t		refcnt;
 	struct timer_list	timer;      /* when will this queue expire? */
 	struct sk_buff		*fragments; /* list of received fragments */
+	struct sk_buff		*fragments_tail;
 	ktime_t			stamp;
 	int			len;        /* total length of orig datagram */
 	int			meat;
net/ipv4/ip_fragment.c +17 -0
index 75347ea..d8c36d4 100644
@@ -317,6 +317,7 @@ static int ip_frag_reinit(struct ipq *qp)
 	qp->q.len = 0;
 	qp->q.meat = 0;
 	qp->q.fragments = NULL;
+	qp->q.fragments_tail = NULL;
 	qp->iif = 0;
 
 	return 0;
@@ -389,6 +390,16 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
 	 * in the chain of fragments so far.  We must know where to put
 	 * this fragment, right?
 	 */
+	prev = qp->q.fragments_tail;
+	if (prev) {
+		if (FRAG_CB(prev)->offset < offset) {
+			next = NULL;
+			goto found;
+		}
+	} else {
+		next = NULL;
+		goto found;
+	}
 	prev = NULL;
 	for (next = qp->q.fragments; next != NULL; next = next->next) {
 		if (FRAG_CB(next)->offset >= offset)
@@ -396,6 +407,7 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
 		prev = next;
 	}
 
+found:
 	/* We found where to put this one.  Check for overlap with
 	 * preceding fragment, and, if needed, align things so that
 	 * any overlaps are eliminated.
@@ -454,6 +466,8 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
 
 	/* Insert this fragment in the chain of fragments. */
 	skb->next = next;
+	if (!next)
+		qp->q.fragments_tail = skb;
 	if (prev)
 		prev->next = skb;
 	else
@@ -507,6 +521,8 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
 			goto out_nomem;
 
 		fp->next = head->next;
+		if (!fp->next)
+			qp->q.fragments_tail = fp;
 		prev->next = fp;
 
 		skb_morph(head, qp->q.fragments);
@@ -578,6 +594,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
 	iph->tot_len = htons(len);
 	IP_INC_STATS_BH(net, IPSTATS_MIB_REASMOKS);
 	qp->q.fragments = NULL;
+	qp->q.fragments_tail = NULL;
 	return 0;
 
 out_nomem:
net/ipv6/reassembly.c +16 -0
index 6d4292f..dc15624 100644
@@ -336,6 +336,16 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
 	 * in the chain of fragments so far.  We must know where to put
 	 * this fragment, right?
 	 */
+	prev = fq->q.fragments_tail;
+	if (prev) {
+		if (FRAG6_CB(prev)->offset < offset) {
+			next = NULL;
+			goto found;
+		}
+	} else {
+		next = NULL;
+		goto found;
+	}
 	prev = NULL;
 	for(next = fq->q.fragments; next != NULL; next = next->next) {
 		if (FRAG6_CB(next)->offset >= offset)
@@ -343,6 +353,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
 		prev = next;
 	}
 
+found:
 	/* We found where to put this one.  Check for overlap with
 	 * preceding fragment, and, if needed, align things so that
 	 * any overlaps are eliminated.
@@ -400,6 +411,8 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
 
 	/* Insert this fragment in the chain of fragments. */
 	skb->next = next;
+	if (!next)
+		fq->q.fragments_tail = skb;
 	if (prev)
 		prev->next = skb;
 	else
@@ -466,6 +479,8 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
 			goto out_oom;
 
 		fp->next = head->next;
+		if (!fp->next)
+			fq->q.fragments_tail = fp;
 		prev->next = fp;
 
 		skb_morph(head, fq->q.fragments);
@@ -553,6 +568,7 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
 	IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMOKS);
 	rcu_read_unlock();
 	fq->q.fragments = NULL;
+	fq->q.fragments_tail = NULL;
 	return 1;
 
 out_oversize:
maintainer
#1 lore raw

From: Changli Gao <[email protected]>
Date: Mon, 14 Jun 2010 07:16:35 +0800

Quoted 1 line

As the fragments are usually in order,

In what universe does this happen "usually"?

Linux has been outputting fragments in reverse order for more than 10 years.

I'm not applying this patch.

#2 lore raw
Quoted 10 lines · David Miller

From: Changli Gao <[email protected]>
Date: Mon, 14 Jun 2010 07:16:35 +0800

Quoted 1 line

As the fragments are usually in order,

In what universe does this happen "usually"?

Linux has been outputting fragments in reverse order for more than 10 years.

I have tested next-next-2.6 and darwin, and found they are both send fragments in order:

Darwin:

Darwin localhost 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386 i386

09:53:26.891820 IP (tos 0x0, ttl 64, id 19628, offset 0, flags [+], proto UDP (17), length 1500) 10.13.3.10.52189 > 10.13.150.1.8888: UDP, length 8192
09:53:26.892048 IP (tos 0x0, ttl 64, id 19628, offset 1480, flags [+], proto UDP (17), length 1500) 10.13.3.10 > 10.13.150.1: udp 09:53:26.892229 IP (tos 0x0, ttl 64, id 19628, offset 2960, flags [+], proto UDP (17), length 1500) 10.13.3.10 > 10.13.150.1: udp 09:53:26.892397 IP (tos 0x0, ttl 64, id 19628, offset 4440, flags [+], proto UDP (17), length 1500) 10.13.3.10 > 10.13.150.1: udp 09:53:26.892529 IP (tos 0x0, ttl 64, id 19628, offset 5920, flags [+], proto UDP (17), length 1500) 10.13.3.10 > 10.13.150.1: udp 09:53:26.892670 IP (tos 0x0, ttl 64, id 19628, offset 7400, flags [none], proto UDP (17), length 820) 10.13.3.10 > 10.13.150.1: udp

Linux:

Linux localhost 2.6.35-rc1 #88 SMP Sun Jun 13 14:25:07 CST 2010 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz GenuineIntel GNU/Linux

08:01:53.730902 IP (tos 0x0, ttl 64, id 1263, offset 0, flags [+], proto UDP (17), length 1500) 10.13.150.50.45295 > 10.13.150.1.8888:
UDP, length 8192
08:01:53.730955 IP (tos 0x0, ttl 64, id 1263, offset 1480, flags [+], proto UDP (17), length 1500) 10.13.150.50 > 10.13.150.1: udp 08:01:53.731113 IP (tos 0x0, ttl 64, id 1263, offset 2960, flags [+], proto UDP (17), length 1500) 10.13.150.50 > 10.13.150.1: udp 08:01:53.731139 IP (tos 0x0, ttl 64, id 1263, offset 4440, flags [+], proto UDP (17), length 1500) 10.13.150.50 > 10.13.150.1: udp 08:01:53.731280 IP (tos 0x0, ttl 64, id 1263, offset 5920, flags [+], proto UDP (17), length 1500) 10.13.150.50 > 10.13.150.1: udp 08:01:53.731306 IP (tos 0x0, ttl 64, id 1263, offset 7400, flags [none], proto UDP (17), length 820) 10.13.150.50 > 10.13.150.1: udp

Later I'll test Windows.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#3 lore raw

NIC?

--yoshfuji

Quoted 55 lines · Changli Gao
Quoted 10 lines · David Miller

From: Changli Gao<[email protected]>
Date: Mon, 14 Jun 2010 07:16:35 +0800

Quoted 1 line

As the fragments are usually in order,

In what universe does this happen "usually"?

Linux has been outputting fragments in reverse order for more than 10 years.

I have tested next-next-2.6 and darwin, and found they are both send fragments in order:

Darwin:

Darwin localhost 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386 i386

09:53:26.891820 IP (tos 0x0, ttl 64, id 19628, offset 0, flags [+], proto UDP (17), length 1500) 10.13.3.10.52189> 10.13.150.1.8888: UDP, length 8192
09:53:26.892048 IP (tos 0x0, ttl 64, id 19628, offset 1480, flags [+], proto UDP (17), length 1500) 10.13.3.10> 10.13.150.1: udp 09:53:26.892229 IP (tos 0x0, ttl 64, id 19628, offset 2960, flags [+], proto UDP (17), length 1500) 10.13.3.10> 10.13.150.1: udp 09:53:26.892397 IP (tos 0x0, ttl 64, id 19628, offset 4440, flags [+], proto UDP (17), length 1500) 10.13.3.10> 10.13.150.1: udp 09:53:26.892529 IP (tos 0x0, ttl 64, id 19628, offset 5920, flags [+], proto UDP (17), length 1500) 10.13.3.10> 10.13.150.1: udp 09:53:26.892670 IP (tos 0x0, ttl 64, id 19628, offset 7400, flags [none], proto UDP (17), length 820) 10.13.3.10> 10.13.150.1: udp

Linux:

Linux localhost 2.6.35-rc1 #88 SMP Sun Jun 13 14:25:07 CST 2010 x86_64 Intel(R) Core(TM)2 Duo CPU E6550 @ 2.33GHz GenuineIntel GNU/Linux

08:01:53.730902 IP (tos 0x0, ttl 64, id 1263, offset 0, flags [+], proto UDP (17), length 1500) 10.13.150.50.45295> 10.13.150.1.8888:
UDP, length 8192
08:01:53.730955 IP (tos 0x0, ttl 64, id 1263, offset 1480, flags [+], proto UDP (17), length 1500) 10.13.150.50> 10.13.150.1: udp 08:01:53.731113 IP (tos 0x0, ttl 64, id 1263, offset 2960, flags [+], proto UDP (17), length 1500) 10.13.150.50> 10.13.150.1: udp 08:01:53.731139 IP (tos 0x0, ttl 64, id 1263, offset 4440, flags [+], proto UDP (17), length 1500) 10.13.150.50> 10.13.150.1: udp 08:01:53.731280 IP (tos 0x0, ttl 64, id 1263, offset 5920, flags [+], proto UDP (17), length 1500) 10.13.150.50> 10.13.150.1: udp 08:01:53.731306 IP (tos 0x0, ttl 64, id 1263, offset 7400, flags [none], proto UDP (17), length 820) 10.13.150.50> 10.13.150.1: udp

Later I'll test Windows.

#5 lore raw
In reply to Changli Gao
Quoted 3 lines · Changli Gao

Later I'll test Windows.

Windows also sends fragments in order.

10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 0, flags [+], proto UDP (17), length 1452) 221.238.33.71.4194 > 202.113.29.4.8888:
UDP, length 32768
10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 1432, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 2864, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 4296, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 5728, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 7160, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 8592, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 10024, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 11456, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 12888, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 14320, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.064453 IP (tos 0x0, ttl 128, id 35511, offset 15752, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 17184, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 18616, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 20048, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 21480, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 22912, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 24344, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 25776, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 27208, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 28640, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 30072, flags [+], proto UDP (17), length 1452) 221.238.33.71 > 202.113.29.4: udp 10:40:29.066406 IP (tos 0x0, ttl 128, id 35511, offset 31504, flags [none], proto UDP (17), length 1292) 221.238.33.71 > 202.113.29.4: udp

Signature · 2 lines
Regards,
Changli Gao([email protected])
#6 lore raw
In reply to David Miller
Quoted 8 lines · David Miller
Quoted 1 line

As the fragments are usually in order,

In what universe does this happen "usually"?

Linux has been outputting fragments in reverse order for more than 10 years.

I'm not applying this patch.

Dave, I know we've been sending in reverse order, of course. And, as far as I know, it seems Linux is the only implementation which sends fragments in reverse order.

This is receiving side. I think we should accept the fact that Linux is not the only implementation, no?

--yoshfuji

#8 lore raw
In reply to Changli Gao
Quoted 38 lines · Changli Gao

add fast path

As the fragments are usually in order, it is likely the new fragments are at the end of the inet_frag_queue. In the fast path, we check if the skb at the end of the inet_frag_queue is the prev we expect.

----

 include/net/inet_frag.h |    1 +
 net/ipv4/ip_fragment.c  |   17 +++++++++++++++++
 net/ipv6/reassembly.c   |   16 ++++++++++++++++
 3 files changed, 34 insertions(+)
include/net/inet_frag.h +1 -0
index 39f2dc9..16ff29a 100644
@@ -20,6 +20,7 @@ struct inet_frag_queue {
 	atomic_t		refcnt;
 	struct timer_list	timer;      /* when will this queue expire? */
 	struct sk_buff		*fragments; /* list of received fragments */
+	struct sk_buff		*fragments_tail;
 	ktime_t			stamp;
 	int			len;        /* total length of orig datagram */
 	int			meat;
net/ipv4/ip_fragment.c +1 -0
index 75347ea..d8c36d4 100644
@@ -317,6 +317,7 @@ static int ip_frag_reinit(struct ipq *qp)
 	qp->q.len = 0;
 	qp->q.meat = 0;
 	qp->q.fragments = NULL;
+	qp->q.fragments_tail = NULL;
 	qp->iif = 0;
 
 	return 0;
@@ -389,6 +390,16 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
 	 * in the chain of fragments so far.  We must know where to put

net/ipv4/ip_fragment.c static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) · line 400

Quoted 10 lines
net/ipv4/ip_fragment.c +8 -0
 	 * this fragment, right?
 	 */
+	prev = qp->q.fragments_tail;
+	if (prev) {
+		if (FRAG_CB(prev)->offset < offset) {
+			next = NULL;
+			goto found;
+		}
+	} else {
+		next = NULL;

How can this chunk be a win ? queue is empty anyway. You add tests and slow the 'other path'

net/ipv4/ip_fragment.c static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) · line 402

Quoted 2 lines
net/ipv4/ip_fragment.c +2 -0
+		goto found;
+	}

Quite frankly, one easy way to speedup things would be to move 'offset' from ipfrag_skb_cb close to skb->next field so that only one cache line per frag is used during lookup.

I am not sure why we need "struct inet_skb_parm h;" field in struct ipfrag_skb_cb...

I probably need to wakeup this monday morning ?

Untested patch follows, only compiled.

[PATCH] frags: Remove unecessary bits

While trying to move 'offset' to the beginning of frag CB, I found inet_skb_parm field was unused.

---

net/ipv4/ip_fragment.c +0 -1
index 75347ea..0f51ae0 100644
@@ -55,7 +55,6 @@ static int sysctl_ipfrag_max_dist __read_mostly = 64;
 
 struct ipfrag_skb_cb
 {
-	struct inet_skb_parm	h;
 	int			offset;
 };
 
net/ipv6/reassembly.c +0 -1
index 6d4292f..122e0be 100644
@@ -57,7 +57,6 @@
 
 struct ip6frag_skb_cb
 {
-	struct inet6_skb_parm	h;
 	int			offset;
 };
 
#9 lore raw
Quoted 36 lines · Eric Dumazet
Quoted 35 lines · Changli Gao

add fast path

As the fragments are usually in order, it is likely the new fragments are at the end of the inet_frag_queue. In the fast path, we check if the skb at the end of the inet_frag_queue is the prev we expect.

----
 include/net/inet_frag.h |    1 +
 net/ipv4/ip_fragment.c  |   17 +++++++++++++++++
 net/ipv6/reassembly.c   |   16 ++++++++++++++++

 3 files changed, 34 insertions(+)
include/net/inet_frag.h +0 -0
index 39f2dc9..16ff29a 100644
@@ -20,6 +20,7 @@ struct inet_frag_queue {
       atomic_t                refcnt;

      struct timer_list       timer;      /* when will this queue expire? */ struct sk_buff          *fragments; /* list of received fragments */
+     struct sk_buff          *fragments_tail;
      ktime_t                 stamp;
      int                     len;        /* total length of orig datagram */ int                     meat;

net/ipv4/ip_fragment.c +1 -0
index 75347ea..d8c36d4 100644
@@ -317,6 +317,7 @@ static int ip_frag_reinit(struct ipq *qp)
       qp->q.len = 0;
       qp->q.meat = 0;
       qp->q.fragments = NULL;
+     qp->q.fragments_tail = NULL;
       qp->iif = 0;
 
Quoted 19 lines

net/ipv4/ip_fragment.c static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb) · line 400

Quoted 13 lines
net/ipv4/ip_fragment.c +8 -0
       return 0;
@@ -389,6 +390,16 @@ static int ip_frag_queue(struct ipq *qp, struct sk_buff *skb)
        * in the chain of fragments so far.  We must know where to put
        * this fragment, right?
        */
+     prev = qp->q.fragments_tail;
+     if (prev) {
+             if (FRAG_CB(prev)->offset < offset) {
+                     next = NULL;
+                     goto found;
+             }
+     } else {
+             next = NULL;

How can this chunk be a win ? queue is empty anyway. You add tests and slow the 'other path'

Quoted 2 lines
net/ipv4/ip_fragment.c +2 -0
+             goto found;
+     }

Without this branch. prev needs to be initialized to zero again(of course, we can avoid this by moving prev = NULL in the previous branch). next needs an assignment, and a duplicate check if the the queue is empty, which is already known in the above branch. Sorry, but I can't see which path I slow.

        prev = NULL;
        for (next = qp->q.fragments; next != NULL; next = next->next) {
                if (FRAG_CB(next)->offset >= offset)
                        break;  /* bingo! */
                prev = next;
        }
Signature · 2 lines
Regards,
Changli Gao([email protected])
#7 lore raw
In reply to YOSHIFUJI Hideaki
Quoted 7 lines · YOSHIFUJI Hideaki
Quoted 5 lines · David Miller
Quoted 1 line

As the fragments are usually in order,

In what universe does this happen "usually"?
Linux has been outputting fragments in reverse order for more than 10 years.
I'm not applying this patch.

Quoted 8 lines

Dave, I know we've been sending in reverse order, of course. And, as far as I know, it seems Linux is the only implementation which sends fragments in reverse order.

This is receiving side. I think we should accept the fact that Linux is not the only implementation, no?

--yoshfuji

Group,

With respect to IPv4 and PATH MTU, aren't we unlikely to generate packet frags?

With respect to IPv6, aren't frags are less likely (intermediate nodes are not allowed to frag (rfc 2460, sect 4.5 Frag header)) as I would expect the source to use the PATH MTU?

Thus, a faster path is to support the largest Jumbo MTUs (MTU >=9000: 16,110 : 14,336 : 10,240) where possible for bulk data transfers with proper page orders, IMO.

Mitchell Erblich

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw
In reply to Eric Dumazet
Quoted 8 lines

I am not sure why we need "struct inet_skb_parm h;" field in struct ipfrag_skb_cb...

I probably need to wakeup this monday morning ?

Untested patch follows, only compiled.

Oh well, I see light now I woke up ;)

Quoted 7 lines

[PATCH] frags: Remove unecessary bits

While trying to move 'offset' to the beginning of frag CB, I found inet_skb_parm field was unused.

---

Wrong patch of course.

We need some comment or document better why its there..

#10 lore raw
In reply to Changli Gao
Quoted 8 lines

Without this branch. prev needs to be initialized to zero again(of course, we can avoid this by moving prev = NULL in the previous branch). next needs an assignment, and a duplicate check if the the queue is empty, which is already known in the above branch. Sorry, but I can't see which path I slow.

Quoted 7 lines
        prev = NULL;
        for (next = qp->q.fragments; next != NULL; next = next->next) {
                if (FRAG_CB(next)->offset >= offset)
                        break;  /* bingo! */
                prev = next;
        }

Concept of 'fast path' has changed over years. It used to be cpu instructions and cycles, its now number of memory transactions.

The only thing we need to address are the cache lines we must bring into cpu caches, and keep code short.

These days, one cache line miss -> more than one hundred instructions that could be done during cpu stall. cpu cycles are cheap if code already in instruction cache.

Adding a test to avoid entering a NULL loop (no fragment is stored yet) just bloats the code, making it larger than necessary.

You dont need the else branch :

if (prev) {
	if (FRAG_CB(prev)->offset < offset) {
		next = NULL;
		goto found;
	}
else {
	next = NULL;
	goto found;
}

Just write :

next = NULL;
if (prev && FRAG_CB(prev)->offset < offset)

	goto found;
#11 lore raw
Quoted 27 lines · Eric Dumazet

Concept of 'fast path' has changed over years. It used to be cpu instructions and cycles, its now number of memory transactions.

The only thing we need to address are the cache lines we must bring into cpu caches, and keep code short.

These days, one cache line miss -> more than one hundred instructions that could be done during cpu stall. cpu cycles are cheap if code already in instruction cache.

Adding a test to avoid entering a NULL loop (no fragment is stored yet) just bloats the code, making it larger than necessary.

You dont need the else branch :

if (prev) {
       if (FRAG_CB(prev)->offset < offset) {
               next = NULL;
               goto found;
       }
else {
       next = NULL;
       goto found;
}

Quoted 6 lines

Just write :

next = NULL;
if (prev && FRAG_CB(prev)->offset < offset)
       goto found;

Thanks:

I think the following code is better:

if (!prev || FRAG_CB(prev)->offset < offset) {
      next = NULL;
      goto found;
}
Signature · 2 lines
Regards,
Changli Gao([email protected])