Skip to contentSkip to conversation

mbuf: fix reset on mbuf free

PATCH Superseded Olivier Matz 14 participants 74 messages Nov 4, 2020 – Jul 28, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mbuf: fix reset on mbuf free

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore nb_seg=1 in the second segment. This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -8
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
Signature · 1 line
2.25.1
#1 lore raw

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.
Konstantin

Quoted 61 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#2 lore raw
Quoted 36 lines · Konstantin

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#3 lore raw
Quoted 48 lines · Olivier Matz
Quoted 36 lines · Konstantin

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 7 lines

Ah, sorry. I oversimplified the example and now it does not show the issue...

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 81 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#4 lore raw
Quoted 52 lines · Andrew Rybchenko
Quoted 51 lines · Olivier Matz
Quoted 36 lines · Konstantin

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

Quoted 8 lines
Quoted 4 lines

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

The problem with that approach is that there are already several existing split() or trim() implementations in different DPDK-based applications. For instance, we have some in 6WINDGate. If we force applications to set nb_seg to 1 when resetting next, it has to be documented because it is not straightforward. I think the approach from this patch is safer.

By the way, for 21.11, if we are able to do some optimizations and have both pool (index?) and next in the first cache line, we may reconsider the fact that next and nb_segs are already set for new allocated mbufs, because it is not straightforward either.

Quoted 82 lines
Quoted 81 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#5 lore raw
Quoted 65 lines · Andrew Rybchenko
Quoted 52 lines · Olivier Matz
Quoted 51 lines · Konstantin
Quoted 36 lines

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

Quoted 8 lines
Quoted 4 lines

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 5 lines

The problem with that approach is that there are already several existing split() or trim() implementations in different DPDK-based applications. For instance, we have some in 6WINDGate. If we force applications to set nb_seg to 1 when resetting next, it has to be documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same time we reset next, otherwise inconsistency will occur.

Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places are required, Though I think that this patch will introduce some performance drop. As now each mbuf_prefree_seg() will cause update of 2 cache lines unconditionally.

Quoted 4 lines

By the way, for 21.11, if we are able to do some optimizations and have both pool (index?) and next in the first cache line, we may reconsider the fact that next and nb_segs are already set for new allocated mbufs, because it is not straightforward either.

My suggestion - let's put future optimization discussion aside for now, and concentrate on that particular patch.

Quoted 83 lines
Quoted 83 lines
Quoted 82 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#6 lore raw
Quoted 71 lines · Konstantin
Quoted 65 lines · Andrew Rybchenko
Quoted 52 lines · Olivier Matz
Quoted 51 lines · Konstantin
Quoted 36 lines

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

Quoted 8 lines
Quoted 4 lines

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 5 lines

The problem with that approach is that there are already several existing split() or trim() implementations in different DPDK-based applications. For instance, we have some in 6WINDGate. If we force applications to set nb_seg to 1 when resetting next, it has to be documented because it is not straightforward.

Quoted 3 lines

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same time we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was clear that nb_segs is only valid in the first segment, like for many fields (port, ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it means that chain() or split() will have to update it in all segments, which is not efficient.

Saying that nb_segs has to be valid for the first and last segment seems really odd to me. What is the logic behind that except keeping this test as is?

In any case, it has to be better documented.

Olivier

Quoted 98 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places are required, Though I think that this patch will introduce some performance drop. As now each mbuf_prefree_seg() will cause update of 2 cache lines unconditionally.

Quoted 4 lines

By the way, for 21.11, if we are able to do some optimizations and have both pool (index?) and next in the first cache line, we may reconsider the fact that next and nb_segs are already set for new allocated mbufs, because it is not straightforward either.

My suggestion - let's put future optimization discussion aside for now, and concentrate on that particular patch.

Quoted 83 lines
Quoted 83 lines
Quoted 82 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#7 lore raw
Quoted 79 lines · Konstantin
Quoted 71 lines
Quoted 65 lines · Andrew Rybchenko
Quoted 52 lines · Olivier Matz
Quoted 51 lines · Konstantin
Quoted 36 lines

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

Quoted 8 lines
Quoted 4 lines

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 5 lines

The problem with that approach is that there are already several existing split() or trim() implementations in different DPDK-based applications. For instance, we have some in 6WINDGate. If we force applications to set nb_seg to 1 when resetting next, it has to be documented because it is not straightforward.

Quoted 3 lines

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same time we reset next, otherwise inconsistency will occur.

Quoted 7 lines

While it is not explicitly stated for nb_segs, to me it was clear that nb_segs is only valid in the first segment, like for many fields (port, ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it means that chain() or split() will have to update it in all segments, which is not efficient.

Why in all?
We can state that nb_segs on non-first segment should always equal 1. As I understand in that case, both split() and chain() have to update nb_segs only for head mbufs, rest ones will remain untouched.

Quoted 109 lines

Saying that nb_segs has to be valid for the first and last segment seems really odd to me. What is the logic behind that except keeping this test as is?

In any case, it has to be better documented.

Olivier

Quoted 98 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places are required, Though I think that this patch will introduce some performance drop. As now each mbuf_prefree_seg() will cause update of 2 cache lines unconditionally.

Quoted 4 lines

By the way, for 21.11, if we are able to do some optimizations and have both pool (index?) and next in the first cache line, we may reconsider the fact that next and nb_segs are already set for new allocated mbufs, because it is not straightforward either.

My suggestion - let's put future optimization discussion aside for now, and concentrate on that particular patch.

Quoted 83 lines
Quoted 83 lines
Quoted 82 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#8 lore raw
Quoted 83 lines · Konstantin
Quoted 83 lines · Konstantin
Quoted 71 lines
Quoted 65 lines · Andrew Rybchenko
Quoted 52 lines · Olivier Matz
Quoted 51 lines · Konstantin
Quoted 36 lines

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

Quoted 8 lines
Quoted 4 lines

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 5 lines

The problem with that approach is that there are already several existing split() or trim() implementations in different DPDK-based applications. For instance, we have some in 6WINDGate. If we force applications to set nb_seg to 1 when resetting next, it has to be documented because it is not straightforward.

Quoted 3 lines

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same time we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was clear that nb_segs is only valid in the first segment, like for many fields (port, ol_flags, vlan, rss, ...).

Quoted 8 lines
Quoted 3 lines

If we say that nb_segs has to be valid in any segments, it means that chain() or split() will have to update it in all segments, which is not efficient.

Why in all?
We can state that nb_segs on non-first segment should always equal 1. As I understand in that case, both split() and chain() have to update nb_segs only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m->nb_segs for non-first segment. We don't have that kind of constraints for other fields.

Quoted 110 lines
Quoted 110 lines

Saying that nb_segs has to be valid for the first and last segment seems really odd to me. What is the logic behind that except keeping this test as is?

In any case, it has to be better documented.

Olivier

Quoted 98 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places are required, Though I think that this patch will introduce some performance drop. As now each mbuf_prefree_seg() will cause update of 2 cache lines unconditionally.

Quoted 4 lines

By the way, for 21.11, if we are able to do some optimizations and have both pool (index?) and next in the first cache line, we may reconsider the fact that next and nb_segs are already set for new allocated mbufs, because it is not straightforward either.

My suggestion - let's put future optimization discussion aside for now, and concentrate on that particular patch.

Quoted 83 lines
Quoted 83 lines
Quoted 82 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#9 lore raw
Quoted 88 lines
Quoted 88 lines
Quoted 87 lines · Konstantin
Quoted 71 lines
Quoted 65 lines · Andrew Rybchenko
Quoted 52 lines · Olivier Matz
Quoted 51 lines · Konstantin
Quoted 36 lines

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

Quoted 8 lines
Quoted 4 lines

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 5 lines

The problem with that approach is that there are already several existing split() or trim() implementations in different DPDK-based applications. For instance, we have some in 6WINDGate. If we force applications to set nb_seg to 1 when resetting next, it has to be documented because it is not straightforward.

Quoted 3 lines

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same time we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was clear that nb_segs is only valid in the first segment, like for many fields (port, ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it means that chain() or split() will have to update it in all segments, which is not efficient.

Quoted 7 lines
Quoted 4 lines

Why in all?
We can state that nb_segs on non-first segment should always equal 1. As I understand in that case, both split() and chain() have to update nb_segs only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m->nb_segs for non-first segment. We don't have that kind of constraints for other fields.

True, we don't. But this is one of the fields we consider critical for proper work of mbuf alloc/free mechanism.

Quoted 112 lines
Quoted 112 lines
Quoted 112 lines

Saying that nb_segs has to be valid for the first and last segment seems really odd to me. What is the logic behind that except keeping this test as is?

In any case, it has to be better documented.

Olivier

Quoted 98 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places are required, Though I think that this patch will introduce some performance drop. As now each mbuf_prefree_seg() will cause update of 2 cache lines unconditionally.

Quoted 4 lines

By the way, for 21.11, if we are able to do some optimizations and have both pool (index?) and next in the first cache line, we may reconsider the fact that next and nb_segs are already set for new allocated mbufs, because it is not straightforward either.

My suggestion - let's put future optimization discussion aside for now, and concentrate on that particular patch.

Quoted 83 lines
Quoted 83 lines
Quoted 82 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#10 lore raw
Quoted 119 lines

From: dev [mailto:[email protected]] On Behalf Of Ananyev, Konstantin
Sent: Thursday, November 5, 2020 2:56 PM

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Thu, Nov 05, 2020 at 11:34:18AM +0000, Ananyev, Konstantin

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Thu, Nov 05, 2020 at 11:26:51AM +0300, Andrew Rybchenko

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Olivier Matz
Quoted 1 line

On Thu, Nov 05, 2020 at 12:15:49AM +0000, Ananyev,

Quoted 4 lines · Konstantin
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Olivier,

Quoted 1 line

m->nb_seg must be reset on mbuf free whatever the value

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is != 1. For

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset nb_seg in the

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this code the

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore nb_seg=1 in

the second

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 1 line

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Ah, sorry. I oversimplified the example and now it does

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break the mbuf

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that would be done

for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a more generic

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are already

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in different DPDK-

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in 6WINDGate. If we

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting next, it has

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was clear

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for many fields

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it means

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all segments, which

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should always equal

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain() have to

update nb_segs

Quoted 2 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Quoted 8 lines
Quoted 1 line

Well, anyway, I think it's strange to have a constraint on m->nb_segs

for

Quoted 1 line

non-first segment. We don't have that kind of constraints for other

fields.

True, we don't. But this is one of the fields we consider critical for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first segments will provide any benefits.

E.g. the second segment of a three-segment chain will still have m->next != NULL, so it cannot be used as a gate to prevent accessing m->next.

I might have overlooked something, though.

Quoted 132 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Saying that nb_segs has to be valid for the first and last

segment seems

Quoted 1 line
Quoted 1 line
Quoted 1 line

really odd to me. What is the logic behind that except keeping

this test

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

as is?

In any case, it has to be better documented.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Olivier

Quoted 4 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places

are required,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though I think that this patch will introduce some performance

drop.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As now each mbuf_prefree_seg() will cause update of 2 cache

lines unconditionally.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

By the way, for 21.11, if we are able to do some

optimizations and have

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

both pool (index?) and next in the first cache line, we may

reconsider

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the fact that next and nb_segs are already set for new

allocated mbufs,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

because it is not straightforward either.

My suggestion - let's put future optimization discussion aside

for now,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and concentrate on that particular patch.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but

nb_seg=2

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second

segment.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when

not in the first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment, and there is nothing saying it should be set to

1. Typically,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

rte_pktmbuf_chain() does not change it, and I guess it's

the same for

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

many similar functions in applications.

Olivier

Quoted 6 lines
Quoted 6 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in

pool")

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines

index 8a456e5e64..e632071c23 100644

lib/librte_mbuf/rte_mbuf.c +0 -0
@@ -129,10 +129,8 @@

rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
lib/librte_mbuf/rte_mbuf.c +2 -4
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_mbuf/rte_mbuf.h rte_pktmbuf_prefree_seg(struct

Quoted 4 lines

index a1414ed7cd..ef5800c8ef 100644

lib/librte_mbuf/rte_mbuf.h +0 -0
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct

rte_mbuf *m)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +2 -4
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

lib/librte_mbuf/rte_mbuf.h rte_pktmbuf_prefree_seg(struct

Quoted 3 lines
lib/librte_mbuf/rte_mbuf.h +0 -0
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct

rte_mbuf *m)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
lib/librte_mbuf/rte_mbuf.h +2 -5
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#11 lore raw
Quoted 107 lines
Quoted 107 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Hi Olivier,

Quoted 1 line

m->nb_seg must be reset on mbuf free whatever the value

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is != 1. For

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset nb_seg in the

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this code the

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore nb_seg=1 in

the second

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 1 line

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Ah, sorry. I oversimplified the example and now it does

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break the mbuf

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that would be done

for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a more generic

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are already

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in different DPDK-

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in 6WINDGate. If we

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting next, it has

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at same

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was clear

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for many fields

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it means

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all segments, which

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should always equal

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain() have to

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m->nb_segs

for

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

non-first segment. We don't have that kind of constraints for other

fields.

True, we don't. But this is one of the fields we consider critical for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first segments will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain write-free.

Quoted 138 lines

E.g. the second segment of a three-segment chain will still have m->next != NULL, so it cannot be used as a gate to prevent accessing m-

Quoted 1 line

next.

I might have overlooked something, though.

Quoted 132 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Saying that nb_segs has to be valid for the first and last

segment seems

Quoted 1 line
Quoted 1 line
Quoted 1 line

really odd to me. What is the logic behind that except keeping

this test

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

as is?

In any case, it has to be better documented.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Olivier

Quoted 4 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less places

are required,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though I think that this patch will introduce some performance

drop.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As now each mbuf_prefree_seg() will cause update of 2 cache

lines unconditionally.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

By the way, for 21.11, if we are able to do some

optimizations and have

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

both pool (index?) and next in the first cache line, we may

reconsider

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the fact that next and nb_segs are already set for new

allocated mbufs,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

because it is not straightforward either.

My suggestion - let's put future optimization discussion aside

for now,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and concentrate on that particular patch.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but

nb_seg=2

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second

segment.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when

not in the first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment, and there is nothing saying it should be set to

1. Typically,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

rte_pktmbuf_chain() does not change it, and I guess it's

the same for

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

many similar functions in applications.

Olivier

Quoted 6 lines
Quoted 6 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in

pool")

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines

index 8a456e5e64..e632071c23 100644

lib/librte_mbuf/rte_mbuf.c +0 -0
@@ -129,10 +129,8 @@

rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
lib/librte_mbuf/rte_mbuf.c +2 -4
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_mbuf/rte_mbuf.h rte_pktmbuf_prefree_seg(struct

Quoted 4 lines

index a1414ed7cd..ef5800c8ef 100644

lib/librte_mbuf/rte_mbuf.h +0 -0
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct

rte_mbuf *m)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +2 -4
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

lib/librte_mbuf/rte_mbuf.h rte_pktmbuf_prefree_seg(struct

Quoted 3 lines
lib/librte_mbuf/rte_mbuf.h +0 -0
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct

rte_mbuf *m)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
lib/librte_mbuf/rte_mbuf.h +2 -5
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#12 lore raw
Quoted 134 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:55 AM

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

Quoted 1 line

m->nb_seg must be reset on mbuf free whatever the

value

Quoted 16 lines
Quoted 16 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is != 1. For

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset nb_seg in the

initial m1

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this code the

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore nb_seg=1

in

Quoted 24 lines
Quoted 24 lines

the second

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 1 line

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Ah, sorry. I oversimplified the example and now it

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break the

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that would be

done

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

software TCP segmentation.

If so, may be the right solution is to care about

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any place when next

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a more

generic

Quoted 6 lines
Quoted 6 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are already

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in different

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in 6WINDGate. If

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting next, it

has

Quoted 5 lines
Quoted 5 lines

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at

same

Quoted 4 lines
Quoted 4 lines

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for many

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it

means

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all segments,

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should always

equal

Quoted 9 lines
Quoted 6 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain() have to

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m-

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of constraints for

other

Quoted 6 lines
Quoted 5 lines

fields.

True, we don't. But this is one of the fields we consider critical for proper work of mbuf alloc/free mechanism.

Quoted 6 lines
Quoted 1 line

I am not sure that requiring m->nb_segs == 1 on non-first segments

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain write- free.

I see. Then I agree with Konstantin that alternative solutions should be considered.

The benefit regarding free()'ing non-segmented mbufs - which is a very common operation - certainly outweighs the cost of requiring split()/chain() operations to set the new head mbuf's nb_segs = 1.

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break the ABI, we are forced to accept the patch.

Unless the techboard accepts to break the ABI in order to avoid the performance cost of this patch.

Quoted 153 lines
Quoted 15 lines

E.g. the second segment of a three-segment chain will still have m- next != NULL, so it cannot be used as a gate to prevent accessing m-

Quoted 1 line

next.

I might have overlooked something, though.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Saying that nb_segs has to be valid for the first and last

segment seems

Quoted 1 line
Quoted 1 line
Quoted 1 line

really odd to me. What is the logic behind that except

keeping

Quoted 6 lines
Quoted 6 lines

this test

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

as is?

In any case, it has to be better documented.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Olivier

Quoted 4 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less

places

Quoted 2 lines
Quoted 2 lines

are required,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though I think that this patch will introduce some

performance

Quoted 7 lines
Quoted 7 lines

drop.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As now each mbuf_prefree_seg() will cause update of 2 cache

lines unconditionally.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

By the way, for 21.11, if we are able to do some

optimizations and have

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

both pool (index?) and next in the first cache line, we

may

Quoted 6 lines
Quoted 6 lines

reconsider

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the fact that next and nb_segs are already set for new

allocated mbufs,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

because it is not straightforward either.

My suggestion - let's put future optimization discussion

aside

Quoted 9 lines
Quoted 9 lines

for now,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and concentrate on that particular patch.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but

nb_seg=2

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- new_m with 1 segment

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Freeing m0 will not restore nb_seg=1 in the second

segment.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored

when

Quoted 2 lines
Quoted 2 lines

not in the first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment, and there is nothing saying it should be set

to

Quoted 2 lines
Quoted 2 lines

1. Typically,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

rte_pktmbuf_chain() does not change it, and I guess

it's

Quoted 8 lines
Quoted 8 lines

the same for

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

many similar functions in applications.

Olivier

Quoted 3 lines
Quoted 3 lines

This is expected that mbufs stored in pool have

their

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while

in

Quoted 4 lines
Quoted 4 lines

pool")

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Signed-off-by Olivier Matz

<[email protected]>

Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines

index 8a456e5e64..e632071c23 100644

lib/librte_mbuf/rte_mbuf.c +0 -0
@@ -129,10 +129,8 @@

rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
lib/librte_mbuf/rte_mbuf.c +2 -4
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines

index a1414ed7cd..ef5800c8ef 100644

lib/librte_mbuf/rte_mbuf.h +0 -0
@@ -1329,10 +1329,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 11 lines
Quoted 11 lines

rte_mbuf *m)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +2 -4
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

lib/librte_mbuf/rte_mbuf.h

Quoted 3 lines
lib/librte_mbuf/rte_mbuf.h +0 -0
 		return m;
 
@@ -1346,10 +1344,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 17 lines
Quoted 17 lines

rte_mbuf *m)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
lib/librte_mbuf/rte_mbuf.h +2 -5
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#13 lore raw
Quoted 143 lines · Morten Brørup
Quoted 134 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:55 AM

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

Quoted 1 line

m->nb_seg must be reset on mbuf free whatever the

value

Quoted 16 lines
Quoted 16 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is != 1. For

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset nb_seg in the

initial m1

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this code the

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore nb_seg=1

in

Quoted 24 lines
Quoted 24 lines

the second

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 1 line

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Ah, sorry. I oversimplified the example and now it

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break the

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that would be

done

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

software TCP segmentation.

If so, may be the right solution is to care about

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any place when next

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a more

generic

Quoted 6 lines
Quoted 6 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are already

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in different

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in 6WINDGate. If

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting next, it

has

Quoted 5 lines
Quoted 5 lines

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at

same

Quoted 4 lines
Quoted 4 lines

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it was

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for many

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments, it

means

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all segments,

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should always

equal

Quoted 9 lines
Quoted 6 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain() have to

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m-

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of constraints for

other

Quoted 6 lines
Quoted 5 lines

fields.

True, we don't. But this is one of the fields we consider critical for proper work of mbuf alloc/free mechanism.

Quoted 6 lines
Quoted 1 line

I am not sure that requiring m->nb_segs == 1 on non-first segments

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain write- free.

I see. Then I agree with Konstantin that alternative solutions should be considered.

Quoted 7 lines

The benefit regarding free()'ing non-segmented mbufs - which is a very common operation - certainly outweighs the cost of requiring split()/chain() operations to set the new head mbuf's nb_segs = 1.

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break the ABI, we are forced to accept the patch.

Unless the techboard accepts to break the ABI in order to avoid the performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

Let's sumarize: splitting a mbuf chain and freeing it causes subsequent mbuf allocation to return a mbuf which is not correctly initialized. There are 2 options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in the first segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the number of segments in the first mbuf, should be 1 in the last segment, ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim. From afar, I see at least mbuf_cut_seg_ofs() in DPDK. Some external applications may have to be patched (for instance, I already found 3 places in 6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance, because the (implicit) behavior is unchanged.

Whatever the solution, some documentation has to be added.

Olivier

Quoted 155 lines
Quoted 154 lines
Quoted 16 lines

E.g. the second segment of a three-segment chain will still have m- next != NULL, so it cannot be used as a gate to prevent accessing m-

Quoted 1 line

next.

I might have overlooked something, though.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Saying that nb_segs has to be valid for the first and last

segment seems

Quoted 1 line
Quoted 1 line
Quoted 1 line

really odd to me. What is the logic behind that except

keeping

Quoted 6 lines
Quoted 6 lines

this test

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

as is?

In any case, it has to be better documented.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Olivier

Quoted 4 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in less

places

Quoted 2 lines
Quoted 2 lines

are required,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though I think that this patch will introduce some

performance

Quoted 7 lines
Quoted 7 lines

drop.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As now each mbuf_prefree_seg() will cause update of 2 cache

lines unconditionally.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

By the way, for 21.11, if we are able to do some

optimizations and have

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

both pool (index?) and next in the first cache line, we

may

Quoted 6 lines
Quoted 6 lines

reconsider

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the fact that next and nb_segs are already set for new

allocated mbufs,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

because it is not straightforward either.

My suggestion - let's put future optimization discussion

aside

Quoted 9 lines
Quoted 9 lines

for now,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and concentrate on that particular patch.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but

nb_seg=2

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

- new_m with 1 segment

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Freeing m0 will not restore nb_seg=1 in the second

segment.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored

when

Quoted 2 lines
Quoted 2 lines

not in the first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment, and there is nothing saying it should be set

to

Quoted 2 lines
Quoted 2 lines

1. Typically,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

rte_pktmbuf_chain() does not change it, and I guess

it's

Quoted 8 lines
Quoted 8 lines

the same for

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

many similar functions in applications.

Olivier

Quoted 3 lines
Quoted 3 lines

This is expected that mbufs stored in pool have

their

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_seg field set to 1.

Fixes: 8f094a9ac5d7 ("mbuf: set mbuf fields while

in

Quoted 4 lines
Quoted 4 lines

pool")

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Cc: [email protected]

Signed-off-by: Olivier Matz

<[email protected]>

Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

---
lib/librte_mbuf/rte_mbuf.c | 6 ++----
lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/lib/librte_mbuf/rte_mbuf.c

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index 8a456e5e64..e632071c23 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -129,10 +129,8 @@

rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

rte_mbuf_ext_refcnt_set(m->shinfo, 1);
m->ol_flags = EXT_ATTACHED_MBUF;
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;
rte_mbuf_raw_free(m);
}

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

diff --git a/lib/librte_mbuf/rte_mbuf.h

b/lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index a1414ed7cd..ef5800c8ef 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1329,10 +1329,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 11 lines
Quoted 11 lines

rte_mbuf *m)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

return NULL;
}

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

return m;

@@ -1346,10 +1344,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 17 lines
Quoted 17 lines

rte_mbuf *m)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

return NULL;
}

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;
rte_mbuf_refcnt_set(m, 1);

return m;
--
2.25.1

#14 lore raw
Quoted 175 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, November 6, 2020 9:21 AM

Quoted 6 lines · Morten Brørup
Quoted 6 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:55 AM

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free whatever

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is != 1.

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset nb_seg in

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this code

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore

nb_seg=1

Quoted 14 lines
Quoted 14 lines

in

Quoted 13 lines
Quoted 13 lines

the second

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

m1->next != NULL, so it will enter the if()

block,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now

it

Quoted 8 lines
Quoted 8 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break the

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that would

be

Quoted 8 lines
Quoted 8 lines

done

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

software TCP segmentation.

If so, may be the right solution is to care about

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any place when

next

Quoted 8 lines
Quoted 8 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a more

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting next,

it

Quoted 11 lines
Quoted 11 lines

has

Quoted 5 lines
Quoted 5 lines

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at

same

Quoted 4 lines
Quoted 4 lines

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it

was

Quoted 8 lines
Quoted 8 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for many

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments,

it

Quoted 3 lines
Quoted 3 lines

means

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 6 lines
Quoted 6 lines

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain() have

to

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m-

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of constraints for

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we consider

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative solutions should

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which is a

very common operation - certainly outweighs the cost of requiring split()/chain() operations to set the new head mbuf's nb_segs = 1.

Quoted 3 lines

Nonetheless, the bug needs to be fixed somehow.

Quoted 8 lines
Quoted 1 line

If we can't come up with a better solution that doesn't break the

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to avoid the

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based on TX immediately following RX, so cache misses in TX may go by unnoticed because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at TX.

Please consider testing the performance difference with the mbuf being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 26 lines

Let's sumarize: splitting a mbuf chain and freeing it causes subsequent mbuf
allocation to return a mbuf which is not correctly initialized. There are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in the first segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the number of segments in the first mbuf, should be 1 in the last segment, ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim. From
afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3 places in 6WIND code base without a deep search).

Quoted 8 lines

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option will go into 20.11 and stable releases of older versions, so I stand by my acknowledgment of the patch.

Which reminds me: Consider reporting the bug in Bugzilla.

Quoted 170 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

E.g. the second segment of a three-segment chain will still have

m-

Quoted 1 line
Quoted 1 line
Quoted 1 line

next != NULL, so it cannot be used as a gate to prevent accessing

m-

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line

next.

I might have overlooked something, though.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Saying that nb_segs has to be valid for the first and

last

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

segment seems

Quoted 1 line
Quoted 1 line
Quoted 1 line

really odd to me. What is the logic behind that except

keeping

Quoted 6 lines
Quoted 6 lines

this test

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

as is?

In any case, it has to be better documented.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Olivier

Quoted 4 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in

less

Quoted 6 lines
Quoted 6 lines

places

Quoted 2 lines
Quoted 2 lines

are required,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though I think that this patch will introduce some

performance

Quoted 2 lines
Quoted 2 lines

drop.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As now each mbuf_prefree_seg() will cause update of 2

cache

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lines unconditionally.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

By the way, for 21.11, if we are able to do some

optimizations and have

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

both pool (index?) and next in the first cache line,

we

Quoted 3 lines
Quoted 3 lines

may

Quoted 2 lines
Quoted 2 lines

reconsider

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the fact that next and nb_segs are already set for

new

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allocated mbufs,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

because it is not straightforward either.

My suggestion - let's put future optimization

discussion

Quoted 7 lines
Quoted 7 lines

aside

Quoted 6 lines
Quoted 6 lines

for now,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and concentrate on that particular patch.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL

but

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

nb_seg=2

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the

second

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

segment.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored

when

Quoted 2 lines
Quoted 2 lines

not in the first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment, and there is nothing saying it should be

set

Quoted 3 lines
Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines

1. Typically,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

rte_pktmbuf_chain() does not change it, and I

guess

Quoted 8 lines
Quoted 8 lines

it's

Quoted 7 lines
Quoted 7 lines

the same for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

many similar functions in applications.

Olivier

Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

This is expected that mbufs stored in pool have

their

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_seg field set to 1.

Fixes: 8f094a9ac5d7 ("mbuf: set mbuf fields

while

Quoted 10 lines
Quoted 10 lines

in

Quoted 4 lines
Quoted 4 lines

pool")

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Cc: [email protected]

Signed-off-by: Olivier Matz

<[email protected]>

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

---
lib/librte_mbuf/rte_mbuf.c | 6 ++----
lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
2 files changed, 6 insertions(+), 12

deletions(-)

Quoted 60 lines
Quoted 59 lines
Quoted 20 lines
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

diff --git a/lib/librte_mbuf/rte_mbuf.c

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index 8a456e5e64..e632071c23 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -129,10 +129,8 @@

rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

rte_mbuf_ext_refcnt_set(m->shinfo, 1);
m->ol_flags = EXT_ATTACHED_MBUF;
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;
rte_mbuf_raw_free(m);
}

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

diff --git a/lib/librte_mbuf/rte_mbuf.h

b/lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index a1414ed7cd..ef5800c8ef 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1329,10 +1329,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 11 lines
Quoted 11 lines

rte_mbuf *m)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

return NULL;
}

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

return m;

@@ -1346,10 +1344,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 17 lines
Quoted 17 lines

rte_mbuf *m)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines

return NULL;
}

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;
rte_mbuf_refcnt_set(m, 1);

return m;
--
2.25.1

#15 lore raw
Quoted 218 lines · Morten Brørup
Quoted 175 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, November 6, 2020 9:21 AM

Quoted 6 lines · Morten Brørup
Quoted 6 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:55 AM

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free whatever

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is != 1.

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset nb_seg in

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this code

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore

nb_seg=1

Quoted 14 lines
Quoted 14 lines

in

Quoted 13 lines
Quoted 13 lines

the second

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

m1->next != NULL, so it will enter the if()

block,

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now

it

Quoted 8 lines
Quoted 8 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break the

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that would

be

Quoted 8 lines
Quoted 8 lines

done

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

software TCP segmentation.

If so, may be the right solution is to care about

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any place when

next

Quoted 8 lines
Quoted 8 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a more

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting next,

it

Quoted 11 lines
Quoted 11 lines

has

Quoted 5 lines
Quoted 5 lines

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset nb_seg at

same

Quoted 4 lines
Quoted 4 lines

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me it

was

Quoted 8 lines
Quoted 8 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for many

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any segments,

it

Quoted 3 lines
Quoted 3 lines

means

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 6 lines
Quoted 6 lines

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain() have

to

Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint on m-

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of constraints for

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we consider

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative solutions should

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which is a

very common operation - certainly outweighs the cost of requiring split()/chain() operations to set the new head mbuf's nb_segs = 1.

Quoted 3 lines

Nonetheless, the bug needs to be fixed somehow.

Quoted 8 lines
Quoted 1 line

If we can't come up with a better solution that doesn't break the

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to avoid the

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based on TX immediately following RX, so cache misses in TX may go by unnoticed because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at TX.

Please consider testing the performance difference with the mbuf being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 30 lines

Let's sumarize: splitting a mbuf chain and freeing it causes subsequent mbuf
allocation to return a mbuf which is not correctly initialized. There are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in the first segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the number of segments in the first mbuf, should be 1 in the last segment, ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim. From
afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3 places in 6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Quoted 6 lines
Quoted 4 lines

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option will go into 20.11 and stable releases of older versions, so I stand by my acknowledgment of the patch.

If we are affraid about 20.11 performance (it is legitimate, few days before the release), we can target 21.02. After all, everybody lives with this bug since 2017, so there is no urgency. If accepted and well tested, it can be backported in stable branches.

Quoted 173 lines

Which reminds me: Consider reporting the bug in Bugzilla.

Quoted 170 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

E.g. the second segment of a three-segment chain will still have

m-

Quoted 1 line
Quoted 1 line
Quoted 1 line

next != NULL, so it cannot be used as a gate to prevent accessing

m-

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line

next.

I might have overlooked something, though.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Saying that nb_segs has to be valid for the first and

last

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

segment seems

Quoted 1 line
Quoted 1 line
Quoted 1 line

really odd to me. What is the logic behind that except

keeping

Quoted 6 lines
Quoted 6 lines

this test

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

as is?

In any case, it has to be better documented.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Olivier

Quoted 4 lines
Quoted 2 lines

I think the approach from
this patch is safer.

It might be easier from perspective that changes in

less

Quoted 6 lines
Quoted 6 lines

places

Quoted 2 lines
Quoted 2 lines

are required,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though I think that this patch will introduce some

performance

Quoted 2 lines
Quoted 2 lines

drop.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As now each mbuf_prefree_seg() will cause update of 2

cache

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lines unconditionally.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

By the way, for 21.11, if we are able to do some

optimizations and have

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

both pool (index?) and next in the first cache line,

we

Quoted 3 lines
Quoted 3 lines

may

Quoted 2 lines
Quoted 2 lines

reconsider

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the fact that next and nb_segs are already set for

new

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allocated mbufs,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

because it is not straightforward either.

My suggestion - let's put future optimization

discussion

Quoted 7 lines
Quoted 7 lines

aside

Quoted 6 lines
Quoted 6 lines

for now,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and concentrate on that particular patch.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL

but

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

nb_seg=2

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the

second

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

segment.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored

when

Quoted 2 lines
Quoted 2 lines

not in the first

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment, and there is nothing saying it should be

set

Quoted 3 lines
Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines

1. Typically,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

rte_pktmbuf_chain() does not change it, and I

guess

Quoted 8 lines
Quoted 8 lines

it's

Quoted 7 lines
Quoted 7 lines

the same for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

many similar functions in applications.

Olivier

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

This is expected that mbufs stored in pool have

their

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_seg field set to 1.

Fixes: 8f094a9ac5d7 ("mbuf: set mbuf fields

while

Quoted 10 lines
Quoted 10 lines

in

Quoted 4 lines
Quoted 4 lines

pool")

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Cc: [email protected]

Signed-off-by: Olivier Matz

<[email protected]>

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

---
lib/librte_mbuf/rte_mbuf.c | 6 ++----
lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
2 files changed, 6 insertions(+), 12

deletions(-)

Quoted 60 lines
Quoted 59 lines
Quoted 20 lines
Quoted 20 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

diff --git a/lib/librte_mbuf/rte_mbuf.c

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index 8a456e5e64..e632071c23 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -129,10 +129,8 @@

rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

rte_mbuf_ext_refcnt_set(m->shinfo, 1);
m->ol_flags = EXT_ATTACHED_MBUF;
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;
rte_mbuf_raw_free(m);
}

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

diff --git a/lib/librte_mbuf/rte_mbuf.h

b/lib/librte_mbuf/rte_mbuf.h

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

index a1414ed7cd..ef5800c8ef 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1329,10 +1329,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 11 lines
Quoted 11 lines

rte_mbuf *m)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

return NULL;
}

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

return m;

@@ -1346,10 +1344,8 @@

rte_pktmbuf_prefree_seg(struct

Quoted 17 lines
Quoted 17 lines

rte_mbuf *m)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

return NULL;
}

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;
rte_mbuf_refcnt_set(m, 1);

return m;
--
2.25.1

#16 lore raw
Quoted 257 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, November 6, 2020 11:05 AM

Quoted 10 lines · Morten Brørup
Quoted 10 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, November 6, 2020 9:21 AM

Quoted 6 lines · Morten Brørup
Quoted 6 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:55 AM

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is !=

1.

Quoted 13 lines
Quoted 13 lines

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset

nb_seg in

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this

code

Quoted 35 lines
Quoted 35 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore

nb_seg=1

Quoted 14 lines
Quoted 14 lines

in

Quoted 13 lines
Quoted 13 lines

the second

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

m1->next != NULL, so it will enter the if()

block,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Ah, sorry. I oversimplified the example and

now

Quoted 6 lines
Quoted 6 lines

it

Quoted 5 lines
Quoted 5 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that

would

Quoted 7 lines
Quoted 7 lines

be

Quoted 6 lines
Quoted 6 lines

done

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

software TCP segmentation.

If so, may be the right solution is to care

about

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any place

when

Quoted 4 lines
Quoted 4 lines

next

Quoted 3 lines
Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a

more

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

Quoted 8 lines
Quoted 8 lines

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting

next,

Quoted 7 lines
Quoted 7 lines

it

Quoted 6 lines
Quoted 6 lines

has

Quoted 5 lines
Quoted 5 lines

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset

nb_seg at

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

same

Quoted 4 lines
Quoted 4 lines

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me

it

Quoted 4 lines
Quoted 4 lines

was

Quoted 3 lines
Quoted 3 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for

many

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any

segments,

Quoted 7 lines
Quoted 7 lines

it

Quoted 3 lines
Quoted 3 lines

means

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 2 lines
Quoted 2 lines

which

Quoted 1 line
Quoted 1 line

is not

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain()

have

Quoted 5 lines
Quoted 5 lines

to

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint

on m-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of constraints

for

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we consider

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative solutions

should

Quoted 6 lines
Quoted 6 lines

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which is a

very common operation - certainly outweighs the cost of requiring split()/chain() operations to set the new head mbuf's nb_segs = 1.

Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break the

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to avoid

the

Quoted 6 lines
Quoted 4 lines

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based on

TX immediately following RX, so cache misses in TX may go by unnoticed because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at TX.

Quoted 2 lines

Please consider testing the performance difference with the mbuf

being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 3 lines
Quoted 3 lines

Let's sumarize: splitting a mbuf chain and freeing it causes

subsequent

Quoted 2 lines
Quoted 2 lines

mbuf
allocation to return a mbuf which is not correctly initialized.

There

Quoted 6 lines
Quoted 6 lines

are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in the

first

Quoted 10 lines
Quoted 10 lines

segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the number of segments in the first mbuf, should be 1 in the last segment, ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim.

From

Quoted 4 lines
Quoted 4 lines

afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3 places

in

Quoted 11 lines
Quoted 10 lines

6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Whatever the solution, some documentation has to be added.

Olivier

Quoted 8 lines
Quoted 1 line

Unfortunately, I don't think that anything but the first option will

go into 20.11 and stable releases of older versions, so I stand by my acknowledgment of the patch.

If we are affraid about 20.11 performance (it is legitimate, few days before the release), we can target 21.02. After all, everybody lives with this bug since 2017, so there is no urgency. If accepted and well tested, it can be backported in stable branches.

+1

Good thinking, Olivier!

#17 lore raw
Quoted 251 lines
Quoted 251 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is !=

1.

Quoted 13 lines
Quoted 13 lines

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset

nb_seg in

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after this

code

Quoted 35 lines
Quoted 35 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not restore

nb_seg=1

Quoted 14 lines
Quoted 14 lines

in

Quoted 13 lines
Quoted 13 lines

the second

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

m1->next != NULL, so it will enter the if()

block,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Ah, sorry. I oversimplified the example and

now

Quoted 6 lines
Quoted 6 lines

it

Quoted 5 lines
Quoted 5 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to break

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that

would

Quoted 7 lines
Quoted 7 lines

be

Quoted 6 lines
Quoted 6 lines

done

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

software TCP segmentation.

If so, may be the right solution is to care

about

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any place

when

Quoted 4 lines
Quoted 4 lines

next

Quoted 3 lines
Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a

more

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there are

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

Quoted 8 lines
Quoted 8 lines

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when resetting

next,

Quoted 7 lines
Quoted 7 lines

it

Quoted 6 lines
Quoted 6 lines

has

Quoted 5 lines
Quoted 5 lines

to be

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset

nb_seg at

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

same

Quoted 4 lines
Quoted 4 lines

time

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

we reset next, otherwise inconsistency will occur.

While it is not explicitly stated for nb_segs, to me

it

Quoted 4 lines
Quoted 4 lines

was

Quoted 3 lines
Quoted 3 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like for

many

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any

segments,

Quoted 7 lines
Quoted 7 lines

it

Quoted 3 lines
Quoted 3 lines

means

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 2 lines
Quoted 2 lines

which

Quoted 1 line
Quoted 1 line

is not

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment should

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and chain()

have

Quoted 5 lines
Quoted 5 lines

to

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

update nb_segs

Quoted 3 lines
Quoted 1 line

only for head mbufs, rest ones will remain untouched.

Well, anyway, I think it's strange to have a constraint

on m-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of constraints

for

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we consider

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will remain

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative solutions

should

Quoted 6 lines
Quoted 6 lines

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which is a

very common operation - certainly outweighs the cost of requiring split()/chain() operations to set the new head mbuf's nb_segs = 1.

Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break the

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to avoid

the

Quoted 6 lines
Quoted 4 lines

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based on

TX immediately following RX, so cache misses in TX may go by unnoticed because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at TX.

Quoted 2 lines

Please consider testing the performance difference with the mbuf

being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 3 lines
Quoted 3 lines

Let's sumarize: splitting a mbuf chain and freeing it causes

subsequent

Quoted 2 lines
Quoted 2 lines

mbuf
allocation to return a mbuf which is not correctly initialized.

There

Quoted 6 lines
Quoted 6 lines

are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in the

first

Quoted 10 lines
Quoted 10 lines

segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the number of segments in the first mbuf, should be 1 in the last segment, ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim.

From

Quoted 4 lines
Quoted 4 lines

afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3 places

in

Quoted 6 lines
Quoted 6 lines

6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Quoted 6 lines
Quoted 4 lines

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option will

go into 20.11 and stable releases of older versions, so I stand by my acknowledgment of the patch.

Quoted 8 lines
Quoted 4 lines

If we are affraid about 20.11 performance (it is legitimate, few days before the release), we can target 21.02. After all, everybody lives with this bug since 2017, so there is no urgency. If accepted and well tested, it can be backported in stable branches.

+1

Good thinking, Olivier!

Looking at the changes once again, it probably can be reworked a bit:

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }

+ if (m->next != NULL)
+ m->next = NULL;
+ if (m->nb_segs != 1)
+ m->nb_segs = 1;

That way we add one more condition checking, but I suppose it shouldn't be that perf critical.
That way for direct,non-segmented mbuf it still should be write-free. Except cases as you described above: chain(), then split().

Of-course we still need to do perf testing for that approach too. So if your preference it to postpone it till 21.02 - that's ok for me. Konstantin

#18 lore raw
Quoted 313 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:54 PM

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is

!=

Quoted 14 lines
Quoted 14 lines

1.

Quoted 13 lines
Quoted 13 lines

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset

nb_seg in

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after

this

Quoted 9 lines
Quoted 9 lines

code

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not

restore

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

nb_seg=1

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

the second

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf

*m)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

m1->next != NULL, so it will enter the

if()

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

block,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that

change:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example

and

Quoted 7 lines
Quoted 7 lines

now

Quoted 6 lines
Quoted 6 lines

it

Quoted 5 lines
Quoted 5 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to

break

Quoted 7 lines
Quoted 7 lines

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that

would

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line
Quoted 1 line

done

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

software TCP segmentation.

If so, may be the right solution is to care

about

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any

place

Quoted 11 lines
Quoted 11 lines

when

Quoted 4 lines
Quoted 4 lines

next

Quoted 3 lines
Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a

more

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there

are

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when

resetting

Quoted 4 lines
Quoted 4 lines

next,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

has

Quoted 1 line
Quoted 1 line

to be

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset

nb_seg at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

same

Quoted 2 lines
Quoted 2 lines

time

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

we reset next, otherwise inconsistency will

occur.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

While it is not explicitly stated for nb_segs, to

me

Quoted 5 lines
Quoted 5 lines

it

Quoted 4 lines
Quoted 4 lines

was

Quoted 3 lines
Quoted 3 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like

for

Quoted 10 lines
Quoted 10 lines

many

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any

segments,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

means

Quoted 1 line
Quoted 1 line

that

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 6 lines
Quoted 6 lines

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment

should

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and

chain()

Quoted 4 lines
Quoted 4 lines

have

Quoted 3 lines
Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

update nb_segs

Quoted 1 line
Quoted 1 line

only for head mbufs, rest ones will remain

untouched.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Well, anyway, I think it's strange to have a

constraint

Quoted 4 lines
Quoted 4 lines

on m-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of

constraints

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we

consider

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will

remain

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative

solutions

Quoted 4 lines
Quoted 4 lines

should

Quoted 3 lines
Quoted 3 lines

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which

is a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

very common operation - certainly outweighs the cost of

requiring

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

split()/chain() operations to set the new head mbuf's nb_segs =

1.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to

avoid

Quoted 7 lines
Quoted 7 lines

the

Quoted 6 lines
Quoted 4 lines

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based

on

Quoted 1 line
Quoted 1 line

TX immediately following RX, so cache misses in TX may go by

unnoticed

Quoted 2 lines
Quoted 2 lines

because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at

TX.

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

Please consider testing the performance difference with the mbuf

being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 3 lines
Quoted 3 lines

Let's sumarize: splitting a mbuf chain and freeing it causes

subsequent

Quoted 2 lines
Quoted 2 lines

mbuf
allocation to return a mbuf which is not correctly initialized.

Quoted 7 lines
Quoted 7 lines

There

Quoted 6 lines
Quoted 6 lines

are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in

the

Quoted 7 lines
Quoted 7 lines

first

Quoted 6 lines
Quoted 6 lines

segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the

number of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segments in the first mbuf, should be 1 in the last

segment,

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim.

From

Quoted 4 lines
Quoted 4 lines

afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3

places

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option

will

Quoted 1 line
Quoted 1 line

go into 20.11 and stable releases of older versions, so I stand by

my

Quoted 3 lines
Quoted 3 lines

acknowledgment of the patch.

If we are affraid about 20.11 performance (it is legitimate, few

days

Quoted 1 line
Quoted 1 line

before the release), we can target 21.02. After all, everybody

lives

Quoted 1 line
Quoted 1 line

with this bug since 2017, so there is no urgency. If accepted and

well

Quoted 5 lines
Quoted 1 line

tested, it can be backported in stable branches.

+1

Good thinking, Olivier!

Looking at the changes once again, it probably can be reworked a bit:

(quoted diff) +4 -4
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
 
+	if (m->next != NULL)
+		m->next = NULL;
+	if (m->nb_segs != 1)
+		m->nb_segs = 1;
Quoted 8 lines

That way we add one more condition checking, but I suppose it shouldn't be that perf critical.
That way for direct,non-segmented mbuf it still should be write-free. Except cases as you described above: chain(), then split().

Of-course we still need to do perf testing for that approach too. So if your preference it to postpone it till 21.02 - that's ok for me. Konstantin

With this suggestion, I cannot imagine any performance drop for direct, non-segmented mbufs: It now reads m->nb_segs, residing in the mbuf's first cache line, but the function already reads m->refcnt in the first cache line; so no cache misses are introduced.

#19 lore raw
Quoted 318 lines · Morten Brørup
Quoted 318 lines

From: Ananyev, Konstantin [mailto:[email protected]]
Sent: Friday, November 6, 2020 12:54 PM

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is

!=

Quoted 14 lines
Quoted 14 lines

1.

Quoted 13 lines
Quoted 13 lines

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset

nb_seg in

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line
Quoted 1 line

segment (this is not required), after

this

Quoted 9 lines
Quoted 9 lines

code

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not

restore

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

nb_seg=1

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

the second

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf

*m)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

m1->next != NULL, so it will enter the

if()

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

block,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that

change:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example

and

Quoted 7 lines
Quoted 7 lines

now

Quoted 6 lines
Quoted 6 lines

it

Quoted 5 lines
Quoted 5 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to

break

Quoted 7 lines
Quoted 7 lines

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that

would

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line
Quoted 1 line

done

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

software TCP segmentation.

If so, may be the right solution is to care

about

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any

place

Quoted 11 lines
Quoted 11 lines

when

Quoted 4 lines
Quoted 4 lines

next

Quoted 3 lines
Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a

more

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there

are

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when

resetting

Quoted 4 lines
Quoted 4 lines

next,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

has

Quoted 1 line
Quoted 1 line

to be

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset

nb_seg at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

same

Quoted 2 lines
Quoted 2 lines

time

Quoted 1 line
Quoted 1 line
Quoted 1 line

we reset next, otherwise inconsistency will

occur.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

While it is not explicitly stated for nb_segs, to

me

Quoted 5 lines
Quoted 5 lines

it

Quoted 4 lines
Quoted 4 lines

was

Quoted 3 lines
Quoted 3 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like

for

Quoted 10 lines
Quoted 10 lines

many

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any

segments,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

means

Quoted 1 line
Quoted 1 line

that

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 6 lines
Quoted 6 lines

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

efficient.

Why in all?
We can state that nb_segs on non-first segment

should

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and

chain()

Quoted 4 lines
Quoted 4 lines

have

Quoted 3 lines
Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

update nb_segs

Quoted 1 line
Quoted 1 line

only for head mbufs, rest ones will remain

untouched.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Well, anyway, I think it's strange to have a

constraint

Quoted 4 lines
Quoted 4 lines

on m-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of

constraints

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we

consider

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will

remain

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative

solutions

Quoted 4 lines
Quoted 4 lines

should

Quoted 3 lines
Quoted 3 lines

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which

is a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

very common operation - certainly outweighs the cost of

requiring

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

split()/chain() operations to set the new head mbuf's nb_segs =

1.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to

avoid

Quoted 7 lines
Quoted 7 lines

the

Quoted 6 lines
Quoted 4 lines

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based

on

Quoted 1 line
Quoted 1 line

TX immediately following RX, so cache misses in TX may go by

unnoticed

Quoted 2 lines
Quoted 2 lines

because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at

TX.

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

Please consider testing the performance difference with the mbuf

being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 3 lines
Quoted 3 lines

Let's sumarize: splitting a mbuf chain and freeing it causes

subsequent

Quoted 2 lines
Quoted 2 lines

mbuf
allocation to return a mbuf which is not correctly initialized.

Quoted 7 lines
Quoted 7 lines

There

Quoted 6 lines
Quoted 6 lines

are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in

the

Quoted 7 lines
Quoted 7 lines

first

Quoted 6 lines
Quoted 6 lines

segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the

number of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segments in the first mbuf, should be 1 in the last

segment,

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim.

From

Quoted 4 lines
Quoted 4 lines

afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3

places

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option

will

Quoted 1 line
Quoted 1 line

go into 20.11 and stable releases of older versions, so I stand by

my

Quoted 3 lines
Quoted 3 lines

acknowledgment of the patch.

If we are affraid about 20.11 performance (it is legitimate, few

days

Quoted 1 line
Quoted 1 line

before the release), we can target 21.02. After all, everybody

lives

Quoted 1 line
Quoted 1 line

with this bug since 2017, so there is no urgency. If accepted and

well

Quoted 5 lines
Quoted 1 line

tested, it can be backported in stable branches.

+1

Good thinking, Olivier!

Looking at the changes once again, it probably can be reworked a bit:

(quoted diff) +4 -4
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
 
+	if (m->next != NULL)
+		m->next = NULL;
+	if (m->nb_segs != 1)
+		m->nb_segs = 1;

That way we add one more condition checking, but I suppose it shouldn't be that perf critical.
That way for direct,non-segmented mbuf it still should be write-free. Except cases as you described above: chain(), then split().

Quoted 5 lines
Quoted 3 lines

Of-course we still need to do perf testing for that approach too. So if your preference it to postpone it till 21.02 - that's ok for me. Konstantin

With this suggestion, I cannot imagine any performance drop for direct, non-segmented mbufs: It now reads m->nb_segs, residing in the mbuf's first cache line, but the function already reads m->refcnt in the first cache line; so no cache misses are introduced.

+1

#20 lore raw
Quoted 318 lines
Quoted 318 lines
Quoted 318 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line
Quoted 1 line

because it can happen that m->nb_seg is

!=

Quoted 14 lines
Quoted 14 lines

1.

Quoted 13 lines
Quoted 13 lines

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines
Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset

nb_seg in

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line
Quoted 1 line

segment (this is not required), after

this

Quoted 9 lines
Quoted 9 lines

code

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines
Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not

restore

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

nb_seg=1

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

the second

Quoted 5 lines
Quoted 5 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf

*m)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

m1->next != NULL, so it will enter the

if()

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

block,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that

change:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example

and

Quoted 7 lines
Quoted 7 lines

now

Quoted 6 lines
Quoted 6 lines

it

Quoted 5 lines
Quoted 5 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines

show the issue...

The full example also adds a split() to

break

Quoted 7 lines
Quoted 7 lines

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line
Quoted 1 line

between m1 and m2. The kind of thing that

would

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line
Quoted 1 line

done

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines

software TCP segmentation.

If so, may be the right solution is to care

about

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any

place

Quoted 11 lines
Quoted 11 lines

when

Quoted 4 lines
Quoted 4 lines

next

Quoted 3 lines
Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line
Quoted 1 line

to NULL. Just to keep the optimization in a

more

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines
Quoted 3 lines

The problem with that approach is that there

are

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line
Quoted 1 line

existing split() or trim() implementations in

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line
Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line
Quoted 1 line

applications to set nb_seg to 1 when

resetting

Quoted 4 lines
Quoted 4 lines

next,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

has

Quoted 1 line
Quoted 1 line

to be

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset

nb_seg at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

same

Quoted 2 lines
Quoted 2 lines

time

Quoted 1 line
Quoted 1 line

we reset next, otherwise inconsistency will

occur.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

While it is not explicitly stated for nb_segs, to

me

Quoted 5 lines
Quoted 5 lines

it

Quoted 4 lines
Quoted 4 lines

was

Quoted 3 lines
Quoted 3 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line

nb_segs is only valid in the first segment, like

for

Quoted 10 lines
Quoted 10 lines

many

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines
Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any

segments,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

means

Quoted 1 line
Quoted 1 line

that

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 6 lines
Quoted 6 lines

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines
Quoted 4 lines

efficient.

Why in all?
We can state that nb_segs on non-first segment

should

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line
Quoted 1 line

As I understand in that case, both split() and

chain()

Quoted 4 lines
Quoted 4 lines

have

Quoted 3 lines
Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

update nb_segs

Quoted 1 line
Quoted 1 line

only for head mbufs, rest ones will remain

untouched.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Well, anyway, I think it's strange to have a

constraint

Quoted 4 lines
Quoted 4 lines

on m-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of

constraints

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we

consider

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will

remain

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative

solutions

Quoted 4 lines
Quoted 4 lines

should

Quoted 3 lines
Quoted 3 lines

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which

is a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

very common operation - certainly outweighs the cost of

requiring

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

split()/chain() operations to set the new head mbuf's nb_segs =

1.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to

avoid

Quoted 7 lines
Quoted 7 lines

the

Quoted 6 lines
Quoted 4 lines

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based

on

Quoted 1 line
Quoted 1 line

TX immediately following RX, so cache misses in TX may go by

unnoticed

Quoted 2 lines
Quoted 2 lines

because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at

TX.

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

Please consider testing the performance difference with the mbuf

being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 3 lines
Quoted 3 lines

Let's sumarize: splitting a mbuf chain and freeing it causes

subsequent

Quoted 2 lines
Quoted 2 lines

mbuf
allocation to return a mbuf which is not correctly initialized.

Quoted 7 lines
Quoted 7 lines

There

Quoted 6 lines
Quoted 6 lines

are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in

the

Quoted 7 lines
Quoted 7 lines

first

Quoted 6 lines
Quoted 6 lines

segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the

number of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segments in the first mbuf, should be 1 in the last

segment,

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim.

From

Quoted 4 lines
Quoted 4 lines

afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3

places

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option

will

Quoted 1 line
Quoted 1 line

go into 20.11 and stable releases of older versions, so I stand by

my

Quoted 3 lines
Quoted 3 lines

acknowledgment of the patch.

If we are affraid about 20.11 performance (it is legitimate, few

days

Quoted 1 line
Quoted 1 line

before the release), we can target 21.02. After all, everybody

lives

Quoted 1 line
Quoted 1 line

with this bug since 2017, so there is no urgency. If accepted and

well

Quoted 5 lines
Quoted 1 line

tested, it can be backported in stable branches.

+1

Good thinking, Olivier!

Looking at the changes once again, it probably can be reworked a bit:

(quoted diff) +4 -4
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
 
+	if (m->next != NULL)
+		m->next = NULL;
+	if (m->nb_segs != 1)
+		m->nb_segs = 1;

That way we add one more condition checking, but I suppose it shouldn't be that perf critical.
That way for direct,non-segmented mbuf it still should be write-free. Except cases as you described above: chain(), then split().

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Of-course we still need to do perf testing for that approach too. So if your preference it to postpone it till 21.02 - that's ok for me. Konstantin

With this suggestion, I cannot imagine any performance drop for direct, non-segmented mbufs: It now reads m->nb_segs, residing in the

mbuf's first cache line, but the function already reads m->refcnt in the first cache line; so no cache misses are introduced.

+1

I don't expect perf drop with that approach either. But some perf testing still needs to be done, just in case 😊

#21 lore raw
Quoted 323 lines · Konstantin
Quoted 323 lines
Quoted 323 lines
Quoted 313 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Hi Olivier,

m->nb_seg must be reset on mbuf free

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 3 lines

value

Quoted 2 lines
Quoted 2 lines

of m->next,

Quoted 1 line

because it can happen that m->nb_seg is

!=

Quoted 14 lines
Quoted 14 lines

1.

Quoted 13 lines
Quoted 13 lines

For

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

instance in this

Quoted 11 lines

case:

m1 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m1, 500);
m2 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m2, 500);
rte_pktmbuf_chain(m1, m2);
m0 = rte_pktmbuf_alloc(mp);
rte_pktmbuf_append(m0, 500);
rte_pktmbuf_chain(m0, m1);

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As rte_pktmbuf_chain() does not reset

nb_seg in

Quoted 3 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

initial m1

Quoted 1 line

segment (this is not required), after

this

Quoted 9 lines
Quoted 9 lines

code

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mbuf chain

Quoted 6 lines

have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Freeing this mbuf chain will not

restore

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

nb_seg=1

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

the second

Quoted 5 lines

segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf

*m)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

{
...
if (m->next != NULL) {
m->next = NULL;
m->nb_segs = 1;
}

m1->next != NULL, so it will enter the

if()

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

block,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that

change:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example

and

Quoted 7 lines
Quoted 7 lines

now

Quoted 6 lines
Quoted 6 lines

it

Quoted 5 lines
Quoted 5 lines

does

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines

show the issue...

The full example also adds a split() to

break

Quoted 7 lines
Quoted 7 lines

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mbuf

Quoted 2 lines
Quoted 2 lines

chain

Quoted 1 line

between m1 and m2. The kind of thing that

would

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line
Quoted 1 line

done

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines

software TCP segmentation.

If so, may be the right solution is to care

about

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

nb_segs

Quoted 1 line
Quoted 1 line
Quoted 1 line

when next is set to NULL on split? Any

place

Quoted 11 lines
Quoted 11 lines

when

Quoted 4 lines
Quoted 4 lines

next

Quoted 3 lines
Quoted 3 lines

is

Quoted 2 lines
Quoted 2 lines

set

Quoted 1 line

to NULL. Just to keep the optimization in a

more

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

generic

Quoted 4 lines
Quoted 4 lines

place.

Quoted 3 lines

The problem with that approach is that there

are

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

already

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

several

Quoted 1 line

existing split() or trim() implementations in

different

Quoted 3 lines
Quoted 3 lines

DPDK-

Quoted 2 lines
Quoted 2 lines

based

Quoted 1 line

applications. For instance, we have some in

6WINDGate. If

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines

force

Quoted 1 line

applications to set nb_seg to 1 when

resetting

Quoted 4 lines
Quoted 4 lines

next,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

has

Quoted 1 line
Quoted 1 line

to be

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

documented because it is not straightforward.

I think it is better to go that way.
From my perspective it seems natural to reset

nb_seg at

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

same

Quoted 2 lines
Quoted 2 lines

time

Quoted 1 line

we reset next, otherwise inconsistency will

occur.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

While it is not explicitly stated for nb_segs, to

me

Quoted 5 lines
Quoted 5 lines

it

Quoted 4 lines
Quoted 4 lines

was

Quoted 3 lines
Quoted 3 lines

clear

Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line

nb_segs is only valid in the first segment, like

for

Quoted 10 lines
Quoted 10 lines

many

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

fields

Quoted 4 lines
Quoted 4 lines

(port,

Quoted 3 lines

ol_flags, vlan, rss, ...).

If we say that nb_segs has to be valid in any

segments,

Quoted 3 lines
Quoted 3 lines

it

Quoted 2 lines
Quoted 2 lines

means

Quoted 1 line
Quoted 1 line

that

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

chain() or split() will have to update it in all

segments,

Quoted 6 lines
Quoted 6 lines

which

Quoted 5 lines
Quoted 5 lines

is not

Quoted 4 lines

efficient.

Why in all?
We can state that nb_segs on non-first segment

should

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

always

Quoted 3 lines
Quoted 3 lines

equal

Quoted 2 lines
Quoted 2 lines

1.

Quoted 1 line

As I understand in that case, both split() and

chain()

Quoted 4 lines
Quoted 4 lines

have

Quoted 3 lines
Quoted 3 lines

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

update nb_segs

Quoted 1 line

only for head mbufs, rest ones will remain

untouched.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Well, anyway, I think it's strange to have a

constraint

Quoted 4 lines
Quoted 4 lines

on m-

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

nb_segs

Quoted 2 lines

for

Quoted 1 line

non-first segment. We don't have that kind of

constraints

Quoted 5 lines
Quoted 5 lines

for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

other

Quoted 3 lines
Quoted 3 lines

fields.

True, we don't. But this is one of the fields we

consider

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

critical

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

for proper work of mbuf alloc/free mechanism.

I am not sure that requiring m->nb_segs == 1 on non-first

segments

Quoted 4 lines
Quoted 4 lines

will provide any benefits.

It would make this patch unneeded.
So, for direct, non-segmented mbufs pktmbuf_free() will

remain

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

write-

Quoted 3 lines
Quoted 1 line

free.

I see. Then I agree with Konstantin that alternative

solutions

Quoted 4 lines
Quoted 4 lines

should

Quoted 3 lines
Quoted 3 lines

be considered.

Quoted 2 lines

The benefit regarding free()'ing non-segmented mbufs - which

is a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

very common operation - certainly outweighs the cost of

requiring

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

split()/chain() operations to set the new head mbuf's nb_segs =

1.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Nonetheless, the bug needs to be fixed somehow.

If we can't come up with a better solution that doesn't break

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ABI, we are forced to accept the patch.

Quoted 2 lines

Unless the techboard accepts to break the ABI in order to

avoid

Quoted 7 lines
Quoted 7 lines

the

Quoted 6 lines
Quoted 4 lines

performance cost of this patch.

Did someone notice a performance drop with this patch? On my side, I don't see any regression on a L3 use case.

I am afraid that the DPDK performance regression tests are based

on

Quoted 1 line
Quoted 1 line

TX immediately following RX, so cache misses in TX may go by

unnoticed

Quoted 2 lines
Quoted 2 lines

because RX warmed up the cache for TX already. And similarly for RX reusing mbufs that have been warmed up by the preceding free() at

TX.

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

Please consider testing the performance difference with the mbuf

being completely cold at TX, and going completely cold again before being reused for RX.

Quoted 3 lines
Quoted 3 lines

Let's sumarize: splitting a mbuf chain and freeing it causes

subsequent

Quoted 2 lines
Quoted 2 lines

mbuf
allocation to return a mbuf which is not correctly initialized.

Quoted 7 lines
Quoted 7 lines

There

Quoted 6 lines
Quoted 6 lines

are 2
options to fix it:

1/ change the mbuf free function (this patch)

- m->nb_segs would behave like many other field: valid in

the

Quoted 7 lines
Quoted 7 lines

first

Quoted 6 lines
Quoted 6 lines

segment, ignored in other segments
- may impact performance (suspected)

2/ change all places where a mbuf chain is split, or trimmed

- m->nb_segs would have a specific behavior: count the

number of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

segments in the first mbuf, should be 1 in the last

segment,

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

ignored in other ones.
- no code change in mbuf library, so no performance impact
- need to patch all places where we do a mbuf split or trim.

From

Quoted 4 lines
Quoted 4 lines

afar,
I see at least mbuf_cut_seg_ofs() in DPDK. Some external
applications
may have to be patched (for instance, I already found 3

places

Quoted 7 lines
Quoted 7 lines

in

Quoted 6 lines
Quoted 6 lines

6WIND code base without a deep search).

In my opinion, 1/ is better, except we notice a significant performance,
because the (implicit) behavior is unchanged.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Whatever the solution, some documentation has to be added.

Olivier

Unfortunately, I don't think that anything but the first option

will

Quoted 1 line
Quoted 1 line

go into 20.11 and stable releases of older versions, so I stand by

my

Quoted 3 lines
Quoted 3 lines

acknowledgment of the patch.

If we are affraid about 20.11 performance (it is legitimate, few

days

Quoted 1 line
Quoted 1 line

before the release), we can target 21.02. After all, everybody

lives

Quoted 1 line
Quoted 1 line

with this bug since 2017, so there is no urgency. If accepted and

well

Quoted 5 lines
Quoted 1 line

tested, it can be backported in stable branches.

+1

Good thinking, Olivier!

Looking at the changes once again, it probably can be reworked a bit:

(quoted diff) +4 -4
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
 
+	if (m->next != NULL)
+		m->next = NULL;
+	if (m->nb_segs != 1)
+		m->nb_segs = 1;
Quoted 8 lines

That way we add one more condition checking, but I suppose it shouldn't be that perf critical.
That way for direct,non-segmented mbuf it still should be write-free. Except cases as you described above: chain(), then split().

Of-course we still need to do perf testing for that approach too. So if your preference it to postpone it till 21.02 - that's ok for me. Konstantin

With this suggestion, I cannot imagine any performance drop for direct, non-segmented mbufs: It now reads m->nb_segs, residing in the

Quoted 6 lines
Quoted 3 lines

mbuf's first cache line, but the function already reads m->refcnt in the first cache line; so no cache misses are introduced.

+1

I don't expect perf drop with that approach either. But some perf testing still needs to be done, just in case 😊

I also agree with your suggestion Konstantin.
Let's postpone it right after 20.11 so we have more time to test. I'll send a v2.

Olivier

#22 lore raw
In reply to Olivier Matz
Quoted 68 lines

From: dev [mailto:[email protected]] On Behalf Of Olivier Matz
Sent: Thursday, November 5, 2020 8:46 AM

Quoted 36 lines · Konstantin

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

Quoted 6 lines

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

And while you are at it, please consider extending the description of the two mbuf fields with their invariants:
1. nb_segs is only valid for the first segment of a multi-segment packet.
2. next is NULL for non-segmented packets.

Quoted 68 lines
Quoted 9 lines
Quoted 9 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
Quoted 7 lines

Review

Quoted 7 lines
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines

lib/librte_mbuf/rte_mbuf.c rte_pktmbuf_free_pinned_extmem(void *addr,

Quoted 4 lines

index 8a456e5e64..e632071c23 100644

lib/librte_mbuf/rte_mbuf.c +0 -0
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr,

void *opaque)

Quoted 12 lines
Quoted 12 lines
lib/librte_mbuf/rte_mbuf.c +2 -4
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.h

Quoted 32 lines
Quoted 31 lines

index a1414ed7cd..ef5800c8ef 100644

lib/librte_mbuf/rte_mbuf.h +4 -9
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#23 lore raw
Quoted 73 lines · Morten Brørup
Quoted 73 lines

From: dev [mailto:[email protected]] On Behalf Of Olivier Matz
Sent: Thursday, November 5, 2020 8:46 AM

Quoted 36 lines · Konstantin

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Ah, sorry. I oversimplified the example and now it does not show the issue...

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Quoted 7 lines
Quoted 1 line

Olivier

And while you are at it, please consider extending the description of the two mbuf fields with their invariants:
1. nb_segs is only valid for the first segment of a multi-segment packet.
2. next is NULL for non-segmented packets.

Good point, will add it in v2.

Quoted 70 lines
Quoted 69 lines
Quoted 10 lines
Quoted 10 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
Quoted 7 lines

Review

Quoted 7 lines
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.c

Quoted 4 lines

lib/librte_mbuf/rte_mbuf.c rte_pktmbuf_free_pinned_extmem(void *addr,

Quoted 4 lines

index 8a456e5e64..e632071c23 100644

lib/librte_mbuf/rte_mbuf.c +0 -0
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr,

void *opaque)

Quoted 12 lines
Quoted 12 lines
lib/librte_mbuf/rte_mbuf.c +2 -4
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_mbuf/rte_mbuf.h

Quoted 32 lines
Quoted 31 lines

index a1414ed7cd..ef5800c8ef 100644

lib/librte_mbuf/rte_mbuf.h +4 -9
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#24 lore raw
In reply to Olivier Matz

Just resend with lost Cc restored.

Quoted 48 lines · Olivier Matz
Quoted 36 lines · Konstantin

Hi Olivier,

Quoted 20 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 2 lines

Freeing this mbuf chain will not restore nb_seg=1 in the second segment.

Hmm, not sure why is that?
You are talking about freeing m1, right?
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)

{
	...
	if (m->next != NULL) {
                        m->next = NULL;
                        m->nb_segs = 1;
                }
Quoted 10 lines

m1->next != NULL, so it will enter the if() block, and will reset both next and nb_segs.
What I am missing here?
Thinking in more generic way, that change:
- if (m->next != NULL) {
- m->next = NULL;
- m->nb_segs = 1;
- }
+ m->next = NULL;
+ m->nb_segs = 1;

Quoted 7 lines

Ah, sorry. I oversimplified the example and now it does not show the issue...

The full example also adds a split() to break the mbuf chain between m1 and m2. The kind of thing that would be done for software TCP segmentation.

If so, may be the right solution is to care about nb_segs when next is set to NULL on split? Any place when next is set to NULL. Just to keep the optimization in a more generic place.

Quoted 81 lines

After this operation, we have 2 mbuf chain:
- m0 with 2 segments, the last one has next=NULL but nb_seg=2
- new_m with 1 segment

Freeing m0 will not restore nb_seg=1 in the second segment.

Quoted 3 lines

Assumes that it is ok to have an mbuf with
nb_seg > 1 and next == NULL.
Which seems wrong to me.

I don't think it is wrong: nb_seg is just ignored when not in the first segment, and there is nothing saying it should be set to 1. Typically, rte_pktmbuf_chain() does not change it, and I guess it's the same for many similar functions in applications.

Olivier

Quoted 64 lines
Quoted 63 lines

This is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c |  6 ++----
 lib/librte_mbuf/rte_mbuf.h | 12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -4
index 8a456e5e64..e632071c23 100644
@@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
-		m->next = NULL;
-		m->nb_segs = 1;
-	}
+	m->next = NULL;
+	m->nb_segs = 1;
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -9
index a1414ed7cd..ef5800c8ef 100644
@@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 
 		return m;
 
@@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
-			m->next = NULL;
-			m->nb_segs = 1;
-		}
+		m->next = NULL;
+		m->nb_segs = 1;
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
--

2.25.1

#25 lore raw
In reply to Olivier Matz

Hi Olivier,

Quoted 7 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Olivier Matz
Sent: Wednesday, November 4, 2020 7:00 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [dpdk-dev] [PATCH] mbuf: fix reset on mbuf free

I can reproduce the failure in "ci/iol-mellanox-Performance" locally also with this patch.
I see a 2 mpps degradation with single core on ConnectX-5. Packet size is 64B. Testpmd command:
"""
dpdk-testpmd -n 4 -w 0000:82:00.1 -w 0000:82:00.0 -c 0x9000 -- --burst=64 --mbcache=512 -i --nb-cores=1 --txd=256 --rxd=256 """

Regards,
Ali

#26 lore raw

PATCH v2 1/1 mbuf: fix reset on mbuf free

In reply to Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.c      |  4 ++--
 lib/librte_mbuf/rte_mbuf.h      |  8 ++++----
 lib/librte_mbuf/rte_mbuf_core.h | 13 +++++++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -2
index 7d09ee2939..5f77840557 100644
@@ -129,10 +129,10 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
+	if (m->next != NULL)
 		m->next = NULL;
+	if (m->nb_segs != 1)
 		m->nb_segs = 1;
-	}
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -4
index c4c9ebfaa0..8c1097ed76 100644
@@ -1340,10 +1340,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 
 		return m;
 
@@ -1357,10 +1357,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
lib/librte_mbuf/rte_mbuf_core.h +11 -2
index 567551deab..78a1fcc8ff 100644
@@ -495,7 +495,12 @@ struct rte_mbuf {
 	 * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
 	 */
 	uint16_t refcnt;
-	uint16_t nb_segs;         /**< Number of segments. */
+
+	/**
+	 * Number of segments. Only valid for the first segment of an mbuf
+	 * chain.
+	 */
+	uint16_t nb_segs;
 
 	/** Input port (16 bits to support more than 256 virtual ports).
 	 * The event eth Tx adapter uses this field to specify the output port.
@@ -591,7 +596,11 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+	/**
+	 * Next segment of scattered packet. Must be NULL in the last segment or
+	 * in case of non-segmented packet.
+	 */
+	struct rte_mbuf *next;
 
 	/* fields to support TX offloads */
 	RTE_STD_C11
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#27 lore raw
Quoted 22 lines

From: dev [mailto:[email protected]] On Behalf Of Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 4 lines

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2

I think you mean:

- m0: next=m1, nb_seg=2 //< nb_seg corrected
- m1: next=NULL, nb_seg=2 //< next corrected

Quoted 11 lines

- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

The code looks good, so:

Acked-by
#28 lore raw
Quoted 40 lines · Morten Brørup
Quoted 23 lines

From: dev [mailto:[email protected]] On Behalf Of Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 4 lines

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2

I think you mean:

- m0: next=m1, nb_seg=2 //< nb_seg corrected
- m1: next=NULL, nb_seg=2 //< next corrected

Quoted 7 lines

- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Quoted 7 lines
Quoted 4 lines
Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

The code looks good, so:

#29 lore raw

PATCH v3 1/1 mbuf: fix reset on mbuf free

In reply to Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

---

v3
* fix commit log again (thanks Morten for spotting it)

v2
* avoid write access if uneeded (suggested by Konstantin)
* enhance comments in mbuf header file (suggested by Morten)
* fix commit log

 lib/librte_mbuf/rte_mbuf.c      |  4 ++--
 lib/librte_mbuf/rte_mbuf.h      |  8 ++++----
 lib/librte_mbuf/rte_mbuf_core.h | 13 +++++++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -2
index 7d09ee2939..5f77840557 100644
@@ -129,10 +129,10 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
+	if (m->next != NULL)
 		m->next = NULL;
+	if (m->nb_segs != 1)
 		m->nb_segs = 1;
-	}
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -4
index c4c9ebfaa0..8c1097ed76 100644
@@ -1340,10 +1340,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 
 		return m;
 
@@ -1357,10 +1357,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
lib/librte_mbuf/rte_mbuf_core.h +11 -2
index 567551deab..78a1fcc8ff 100644
@@ -495,7 +495,12 @@ struct rte_mbuf {
 	 * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
 	 */
 	uint16_t refcnt;
-	uint16_t nb_segs;         /**< Number of segments. */
+
+	/**
+	 * Number of segments. Only valid for the first segment of an mbuf
+	 * chain.
+	 */
+	uint16_t nb_segs;
 
 	/** Input port (16 bits to support more than 256 virtual ports).
 	 * The event eth Tx adapter uses this field to specify the output port.
@@ -591,7 +596,11 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+	/**
+	 * Next segment of scattered packet. Must be NULL in the last segment or
+	 * in case of non-segmented packet.
+	 */
+	struct rte_mbuf *next;
 
 	/* fields to support TX offloads */
 	RTE_STD_C11
Signature · 1 line
2.29.2
#30 lore raw

Hi Olivier,

Quoted 10 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Wednesday, January 6, 2021 3:34 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Ali Alnubani <[email protected]>; [email protected]; [email protected]; Ajit Khaparde <[email protected]>
Subject: [PATCH v3] mbuf: fix reset on mbuf free

Even though the performance tests on Mellanox NICs are passing, I see a performance drop of up to 0.5 mpps with 64B frames (tests only fail for 1 mpps drop or more):
https://mails.dpdk.org/archives/test-report/2021-January/172759.html

I'll verify this on local hardware and reply back.

Regards,
Ali

Acked-by on v3 1/1
#31 lore raw
In reply to Olivier Matz
Quoted 122 lines

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

---

v3
* fix commit log again (thanks Morten for spotting it)

v2
* avoid write access if uneeded (suggested by Konstantin)
* enhance comments in mbuf header file (suggested by Morten)
* fix commit log

 lib/librte_mbuf/rte_mbuf.c      |  4 ++--
 lib/librte_mbuf/rte_mbuf.h      |  8 ++++----
 lib/librte_mbuf/rte_mbuf_core.h | 13 +++++++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)
lib/librte_mbuf/rte_mbuf.c +2 -2
index 7d09ee2939..5f77840557 100644
@@ -129,10 +129,10 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
+	if (m->next != NULL)
 		m->next = NULL;
+	if (m->nb_segs != 1)
 		m->nb_segs = 1;
-	}
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -4
index c4c9ebfaa0..8c1097ed76 100644
@@ -1340,10 +1340,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 
 		return m;
 
@@ -1357,10 +1357,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
lib/librte_mbuf/rte_mbuf_core.h +6 -1
index 567551deab..78a1fcc8ff 100644
@@ -495,7 +495,12 @@ struct rte_mbuf {
 	 * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
 	 */
 	uint16_t refcnt;
-	uint16_t nb_segs;         /**< Number of segments. */
+
+	/**
+	 * Number of segments. Only valid for the first segment of an mbuf
+	 * chain.
+	 */
+	uint16_t nb_segs;
 
 	/** Input port (16 bits to support more than 256 virtual ports).
 	 * The event eth Tx adapter uses this field to specify the output port.
@@ -591,7 +596,11 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 

lib/librte_mbuf/rte_mbuf_core.h struct rte_mbuf {

Quoted 10 lines
lib/librte_mbuf/rte_mbuf_core.h +5 -2
-	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+	/**
+	 * Next segment of scattered packet. Must be NULL in the last segment or
+	 * in case of non-segmented packet.
+	 */
+	struct rte_mbuf *next;
 
 	/* fields to support TX offloads */
 	RTE_STD_C11
--
Quoted 1 line

2.29.2

#32 lore raw

PATCH v4 1/1 mbuf: fix reset on mbuf free

In reply to Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

---

v4
* add a unit test (suggested by David)

v3
* fix commit log again (thanks Morten for spotting it)

v2
* avoid write access if uneeded (suggested by Konstantin)
* enhance comments in mbuf header file (suggested by Morten)
* fix commit log

 app/test/test_mbuf.c            | 69 +++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf.c      |  4 +-
 lib/librte_mbuf/rte_mbuf.h      |  8 ++--
 lib/librte_mbuf/rte_mbuf_core.h | 13 ++++++-
 4 files changed, 86 insertions(+), 8 deletions(-)
app/test/test_mbuf.c +69 -0
index a40f7d4883..ad2cbab600 100644
@@ -2677,6 +2677,70 @@ test_mbuf_dyn(struct rte_mempool *pktmbuf_pool)
 	return -1;
 }
 
+/* check that m->nb_segs and m->next are reset on mbuf free */
+static int
+test_nb_segs_and_next_reset(void)
+{
+	struct rte_mbuf *m0 = NULL, *m1 = NULL, *m2 = NULL;
+	struct rte_mempool *pool = NULL;
+
+	pool = rte_pktmbuf_pool_create("test_mbuf_reset",
+			3, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
+	if (pool == NULL)
+		GOTO_FAIL("Failed to create mbuf pool");
+
+	/* alloc mbufs */
+	m0 = rte_pktmbuf_alloc(pool);
+	m1 = rte_pktmbuf_alloc(pool);
+	m2 = rte_pktmbuf_alloc(pool);
+	if (m0 == NULL || m1 == NULL || m2 == NULL)
+		GOTO_FAIL("Failed to allocate mbuf");
+
+	/* append data in all of them */
+	if (rte_pktmbuf_append(m0, 500) == NULL ||
+			rte_pktmbuf_append(m1, 500) == NULL ||
+			rte_pktmbuf_append(m2, 500) == NULL)
+		GOTO_FAIL("Failed to append data in mbuf");
+
+	/* chain them in one mbuf m0 */
+	rte_pktmbuf_chain(m1, m2);
+	rte_pktmbuf_chain(m0, m1);
+	if (m0->nb_segs != 3 || m0->next != m1 || m1->next != m2 ||
+			m2->next != NULL) {
+		m1 = m2 = NULL;
+		GOTO_FAIL("Failed to chain mbufs");
+	}
+
+	/* split m0 chain in two, between m1 and m2 */
+	m0->nb_segs = 2;
+	m1->next = NULL;
+	m2->nb_segs = 1;
+
+	/* free the 2 mbuf chains m0 and m2  */
+	rte_pktmbuf_free(m0);
+	rte_pktmbuf_free(m2);
+
+	/* realloc the 3 mbufs */
+	m0 = rte_mbuf_raw_alloc(pool);
+	m1 = rte_mbuf_raw_alloc(pool);
+	m2 = rte_mbuf_raw_alloc(pool);
+	if (m0 == NULL || m1 == NULL || m2 == NULL)
+		GOTO_FAIL("Failed to reallocate mbuf");
+
+	/* ensure that m->next and m->nb_segs are reset allocated mbufs */
+	if (m0->nb_segs != 1 || m0->next != NULL ||
+			m1->nb_segs != 1 || m1->next != NULL ||
+			m2->nb_segs != 1 || m2->next != NULL)
+		GOTO_FAIL("nb_segs or next was not reset properly");
+
+	return 0;
+
+fail:
+	if (pool != NULL)
+		rte_mempool_free(pool);
+	return -1;
+}
+
 static int
 test_mbuf(void)
 {
@@ -2867,6 +2931,11 @@ test_mbuf(void)
 		goto err;
 	}
 
+	/* test reset of m->nb_segs and m->next on mbuf free */
+	if (test_nb_segs_and_next_reset() < 0) {
+		printf("test_nb_segs_and_next_reset() failed\n");
+		goto err;
+	}
 
 	ret = 0;
 err:
lib/librte_mbuf/rte_mbuf.c +2 -2
index 7d09ee2939..5f77840557 100644
@@ -129,10 +129,10 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
+	if (m->next != NULL)
 		m->next = NULL;
+	if (m->nb_segs != 1)
 		m->nb_segs = 1;
-	}
 	rte_mbuf_raw_free(m);
 }
 
lib/librte_mbuf/rte_mbuf.h +4 -4
index c4c9ebfaa0..8c1097ed76 100644
@@ -1340,10 +1340,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 
 		return m;
 
@@ -1357,10 +1357,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
lib/librte_mbuf/rte_mbuf_core.h +11 -2
index 567551deab..78a1fcc8ff 100644
@@ -495,7 +495,12 @@ struct rte_mbuf {
 	 * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
 	 */
 	uint16_t refcnt;
-	uint16_t nb_segs;         /**< Number of segments. */
+
+	/**
+	 * Number of segments. Only valid for the first segment of an mbuf
+	 * chain.
+	 */
+	uint16_t nb_segs;
 
 	/** Input port (16 bits to support more than 256 virtual ports).
 	 * The event eth Tx adapter uses this field to specify the output port.
@@ -591,7 +596,11 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+	/**
+	 * Next segment of scattered packet. Must be NULL in the last segment or
+	 * in case of non-segmented packet.
+	 */
+	struct rte_mbuf *next;
 
 	/* fields to support TX offloads */
 	RTE_STD_C11
Signature · 1 line
2.29.2
#33 lore raw
Quoted 35 lines · Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
Quoted 8 lines

---

v4
* add a unit test (suggested by David)

Olivier,

Thanks, for adding it.

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Thanks.

Signature · 1 line
David Marchand
#34 lore raw

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers?
Even though the check iol-intel-Performance isn't failing, I can see that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-January/173927.html

Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-January/173919.html

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Thanks,
Ali

#35 lore raw

Hi,
(Sorry had to resend this to some recipients due to mail server problems).

Just confirming that I can still reproduce the regression with single core and 64B frames on other servers.

- Ali

Quoted 43 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can see that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-January/173927.html

Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-January/173919.html

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Thanks,
Ali

#36 lore raw

Hi Ali,

Quoted 4 lines · Ali Alnubani

Hi,
(Sorry had to resend this to some recipients due to mail server problems).

Just confirming that I can still reproduce the regression with single core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the amount of performance loss in percent, and confirm the test case? (I suppose it is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

Quoted 46 lines

- Ali

Quoted 43 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can see that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-January/173927.html

Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-January/173919.html

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Thanks,
Ali

#37 lore raw

Could someone at Intel please update the test script to provide output according to the test plan? Or delegate to the right person.

According to the test plan, the information requested by Olivier should be in the test output already:
http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test_plan.rst?h=next

PS: I can't find out who is the maintainer of the test plan, so I'm randomly pointing my finger at the test plan doc copyright holder. :-)

Med venlig hilsen / kind regards
- Morten Brørup

Quoted 91 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 9:32 AM
To: Ali Alnubani
Cc: David Marchand; Ferruh Yigit; [email protected]; dev; Andrew Rybchenko; Ananyev, Konstantin; Morten Brørup; [email protected]; dpdk stable; Ajit Khaparde; Slava Ovsiienko; Alexander Kozyrev
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 2 lines · Ali Alnubani

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines

Just confirming that I can still reproduce the regression with single

core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the amount of performance loss in percent, and confirm the test case? (I suppose it
is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry
for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

Quoted 28 lines

- Ali

Quoted 25 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can

see that the

Quoted 1 line
Quoted 1 line

throughput differences from expected for this patch are less than

those of

Quoted 1 line
Quoted 1 line

another patch that was tested only 20 minutes earlier. Both patches

were

Quoted 3 lines
Quoted 3 lines

applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks

to me

Quoted 3 lines
Quoted 3 lines

that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel

NICs and

Quoted 4 lines
Quoted 4 lines

rerun the test on this patch?

Thanks,
Ali

#38 lore raw
Quoted 7 lines · Morten Brørup

Could someone at Intel please update the test script to provide output according to the test plan? Or delegate to the right person.

According to the test plan, the information requested by Olivier should be in the test output already:
http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test_plan.rst?h=next

PS: I can't find out who is the maintainer of the test plan, so I'm randomly pointing my finger at the test plan doc copyright holder. :-)

Hi Morten,

Ali has a request to update the expected baseline, to be able to detect the performance drops, let me internally figure out who can do this.

And do you have any other request, or asking same thing?

Quoted 96 lines

Med venlig hilsen / kind regards
- Morten Brørup

Quoted 91 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 9:32 AM
To: Ali Alnubani
Cc: David Marchand; Ferruh Yigit; [email protected]; dev; Andrew Rybchenko; Ananyev, Konstantin; Morten Brørup; [email protected]; dpdk stable; Ajit Khaparde; Slava Ovsiienko; Alexander Kozyrev
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 2 lines · Ali Alnubani

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines

Just confirming that I can still reproduce the regression with single

core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the amount of performance loss in percent, and confirm the test case? (I suppose it
is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry
for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

Quoted 28 lines

- Ali

Quoted 25 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can

see that the

Quoted 1 line
Quoted 1 line

throughput differences from expected for this patch are less than

those of

Quoted 1 line
Quoted 1 line

another patch that was tested only 20 minutes earlier. Both patches

were

Quoted 3 lines
Quoted 3 lines

applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks

to me

Quoted 3 lines
Quoted 3 lines

that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel

NICs and

Quoted 4 lines
Quoted 4 lines

rerun the test on this patch?

Thanks,
Ali

#39 lore raw
Quoted 17 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Tuesday, January 19, 2021 1:01 PM

Quoted 1 line · Morten Brørup

Could someone at Intel please update the test script to provide

output according to the test plan? Or delegate to the right person.

Quoted 2 lines

According to the test plan, the information requested by Olivier

should be in the test output already:

Quoted 1 line

http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test
_plan.rst?h=next

Quoted 2 lines

PS: I can't find out who is the maintainer of the test plan, so I'm

randomly pointing my finger at the test plan doc copyright holder. :-)

Quoted 1 line
Quoted 8 lines

Hi Morten,

Ali has a request to update the expected baseline, to be able to detect the
performance drops, let me internally figure out who can do this.

And do you have any other request, or asking same thing?

Hi Ferruh,

I am asking for something else:

The test script does not provide the output that its documentation says that it does.

Apparently, the test script for nic_single_core_perf produces an output table with these four columns (as seen at https://lab.dpdk.org/results/dashboard/patchsets/15142/#env-18):

   +--------+--------------------+-----------------------+------------------------------+
   | Result | frame_size (bytes) | txd/rxd (descriptors) | throughput Difference (Mpps) |
   +--------+--------------------+-----------------------+------------------------------+
   | PASS   | 64                 | 512                   | 1.57100                      |
   +--------+--------------------+-----------------------+------------------------------+
   | PASS   | 64                 | 2048                  | 1.87500                      |
   +--------+--------------------+-----------------------+------------------------------+

But the test plan documentation (at http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test_plan.rst) says that this output should be produced:

   +------------+---------+-------------+---------+---------------------+
   | Frame Size | TXD/RXD |  Throughput |   Rate  | Expected Throughput |
   +------------+---------+-------------+---------+---------------------+
   |     64     |   512   | xxxxxx Mpps |   xxx % |     xxx    Mpps     |
   +------------+---------+-------------+---------+---------------------+
   |     64     |   2048  | xxxxxx Mpps |   xxx % |     xxx    Mpps     |
   +------------+---------+-------------+---------+---------------------+

Olivier and I am saying that only showing the Throughput Difference (Mpps) does not provide any perspective to the result.

I am requesting that the Expected Throughput (Mpps) should be shown in the result too, as documented in the test plan.

Quoted 104 lines
Quoted 9 lines

Med venlig hilsen / kind regards
- Morten Brørup

Quoted 5 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 9:32 AM
To: Ali Alnubani
Cc: David Marchand; Ferruh Yigit; [email protected]; dev;

Andrew

Quoted 1 line
Quoted 1 line

Rybchenko; Ananyev, Konstantin; Morten Brørup;

[email protected];

Quoted 6 lines
Quoted 6 lines

dpdk stable; Ajit Khaparde; Slava Ovsiienko; Alexander Kozyrev
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 6 lines
Quoted 6 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines

Just confirming that I can still reproduce the regression with

single

Quoted 3 lines
Quoted 3 lines

core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount

Quoted 1 line
Quoted 1 line

of performance loss in percent, and confirm the test case? (I

suppose

Quoted 40 lines
Quoted 40 lines

it
is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry
for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

Quoted 24 lines

- Ali

Quoted 21 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can

see that the

Quoted 1 line
Quoted 1 line

throughput differences from expected for this patch are less than

those of

Quoted 1 line
Quoted 1 line

another patch that was tested only 20 minutes earlier. Both

patches

Quoted 4 lines
Quoted 4 lines

were

Quoted 3 lines
Quoted 3 lines

applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-

Quoted 8 lines
Quoted 8 lines

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it

looks

Quoted 10 lines
Quoted 9 lines

to me

Quoted 3 lines
Quoted 3 lines

that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel

NICs and

Quoted 4 lines
Quoted 4 lines

rerun the test on this patch?

Thanks,
Ali

#40 lore raw
Quoted 52 lines · Morten Brørup
Quoted 17 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Tuesday, January 19, 2021 1:01 PM

Quoted 1 line · Morten Brørup

Could someone at Intel please update the test script to provide

output according to the test plan? Or delegate to the right person.

Quoted 2 lines

According to the test plan, the information requested by Olivier

should be in the test output already:

Quoted 1 line

http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test
_plan.rst?h=next

Quoted 2 lines

PS: I can't find out who is the maintainer of the test plan, so I'm

randomly pointing my finger at the test plan doc copyright holder. :-)

Quoted 1 line
Quoted 8 lines

Hi Morten,

Ali has a request to update the expected baseline, to be able to detect the
performance drops, let me internally figure out who can do this.

And do you have any other request, or asking same thing?

Hi Ferruh,

I am asking for something else:

The test script does not provide the output that its documentation says that it does.

Apparently, the test script for nic_single_core_perf produces an output table with these four columns (as seen at https://lab.dpdk.org/results/dashboard/patchsets/15142/#env-18):

    +--------+--------------------+-----------------------+------------------------------+
    | Result | frame_size (bytes) | txd/rxd (descriptors) | throughput Difference (Mpps) |
    +--------+--------------------+-----------------------+------------------------------+
    | PASS   | 64                 | 512                   | 1.57100                      |
    +--------+--------------------+-----------------------+------------------------------+
    | PASS   | 64                 | 2048                  | 1.87500                      |
    +--------+--------------------+-----------------------+------------------------------+

But the test plan documentation (at http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test_plan.rst) says that this output should be produced:

    +------------+---------+-------------+---------+---------------------+
    | Frame Size | TXD/RXD |  Throughput |   Rate  | Expected Throughput |
    +------------+---------+-------------+---------+---------------------+
    |     64     |   512   | xxxxxx Mpps |   xxx % |     xxx    Mpps     |
    +------------+---------+-------------+---------+---------------------+
    |     64     |   2048  | xxxxxx Mpps |   xxx % |     xxx    Mpps     |
    +------------+---------+-------------+---------+---------------------+
Quoted 4 lines

Olivier and I am saying that only showing the Throughput Difference (Mpps) does not provide any perspective to the result.

I am requesting that the Expected Throughput (Mpps) should be shown in the result too, as documented in the test plan.

Ahh, this has a history, when the initial community lab infrastructure prepared some vendor(s) didn't want to show the actual throughput numbers.

That is why this diff and baseline introduced, and this is the how current infrastructure works. So this is not something related to Intel.

And as you can imagine this is not a technical issue, some companies seems not willing to share their performance numbers via community lab, and I don't know if something changed here in last a few years.

Quoted 105 lines
Quoted 104 lines
Quoted 9 lines

Med venlig hilsen / kind regards
- Morten Brørup

Quoted 5 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 9:32 AM
To: Ali Alnubani
Cc: David Marchand; Ferruh Yigit; [email protected]; dev;

Andrew

Quoted 1 line
Quoted 1 line

Rybchenko; Ananyev, Konstantin; Morten Brørup;

[email protected];

Quoted 6 lines
Quoted 6 lines

dpdk stable; Ajit Khaparde; Slava Ovsiienko; Alexander Kozyrev
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 6 lines
Quoted 6 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines

Just confirming that I can still reproduce the regression with

single

Quoted 3 lines
Quoted 3 lines

core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount

Quoted 1 line
Quoted 1 line

of performance loss in percent, and confirm the test case? (I

suppose

Quoted 40 lines
Quoted 40 lines

it
is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry
for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

Quoted 24 lines

- Ali

Quoted 21 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can

see that the

Quoted 1 line
Quoted 1 line

throughput differences from expected for this patch are less than

those of

Quoted 1 line
Quoted 1 line

another patch that was tested only 20 minutes earlier. Both

patches

Quoted 4 lines
Quoted 4 lines

were

Quoted 3 lines
Quoted 3 lines

applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-

Quoted 8 lines
Quoted 8 lines

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it

looks

Quoted 10 lines
Quoted 9 lines

to me

Quoted 3 lines
Quoted 3 lines

that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel

NICs and

Quoted 4 lines
Quoted 4 lines

rerun the test on this patch?

Thanks,
Ali

#41 lore raw
Quoted 93 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 3:03 PM

Quoted 11 lines · Morten Brørup
Quoted 11 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Tuesday, January 19, 2021 1:01 PM

Quoted 1 line · Morten Brørup

Could someone at Intel please update the test script to provide

output according to the test plan? Or delegate to the right person.

Quoted 2 lines

According to the test plan, the information requested by Olivier

should be in the test output already:

Quoted 1 line

http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test

Quoted 4 lines
Quoted 4 lines

_plan.rst?h=next

Quoted 2 lines

PS: I can't find out who is the maintainer of the test plan, so I'm

randomly pointing my finger at the test plan doc copyright holder.

:-)

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Hi Morten,

Ali has a request to update the expected baseline, to be able to

detect

Quoted 11 lines
Quoted 5 lines

the
performance drops, let me internally figure out who can do this.

And do you have any other request, or asking same thing?

Hi Ferruh,

I am asking for something else:

The test script does not provide the output that its documentation

says that it does.

Quoted 2 lines

Apparently, the test script for nic_single_core_perf produces an

output table with these four columns (as seen at
https://lab.dpdk.org/results/dashboard/patchsets/15142/#env-18):

Quoted 2 lines
    +--------+--------------------+-----------------------+----------

--------------------+

Quoted 1 line

| Result | frame_size (bytes) | txd/rxd (descriptors) |

throughput Difference (Mpps) |

Quoted 1 line
    +--------+--------------------+-----------------------+----------

--------------------+

Quoted 1 line
    | PASS   | 64                 | 512                   | 1.57100

|

Quoted 1 line
    +--------+--------------------+-----------------------+----------

--------------------+

Quoted 1 line
    | PASS   | 64                 | 2048                  | 1.87500

|

Quoted 1 line
    +--------+--------------------+-----------------------+----------

--------------------+

Quoted 2 lines

But the test plan documentation (at

http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test
_plan.rst) says that this output should be produced:

Quoted 2 lines
    +------------+---------+-------------+---------+-----------------

----+

Quoted 1 line

| Frame Size | TXD/RXD | Throughput | Rate | Expected

Throughput |

Quoted 1 line
    +------------+---------+-------------+---------+-----------------

----+

Quoted 1 line

| 64 | 512 | xxxxxx Mpps | xxx % | xxx Mpps

|

Quoted 1 line
    +------------+---------+-------------+---------+-----------------

----+

Quoted 1 line

| 64 | 2048 | xxxxxx Mpps | xxx % | xxx Mpps

|

Quoted 1 line
    +------------+---------+-------------+---------+-----------------

----+

Quoted 2 lines

Olivier and I am saying that only showing the Throughput Difference

(Mpps) does not provide any perspective to the result.

Quoted 2 lines

I am requesting that the Expected Throughput (Mpps) should be shown

in the result too, as documented in the test plan.

Quoted 1 line

Ahh, this has a history, when the initial community lab infrastructure prepared
some vendor(s) didn't want to show the actual throughput numbers.

That is why this diff and baseline introduced, and this is the how current
infrastructure works. So this is not something related to Intel.

Quoted 6 lines

And as you can imagine this is not a technical issue, some companies seems not
willing to share their performance numbers via community lab, and I don't know
if something changed here in last a few years.

That explains it!

If those companies still want to keep the community lab performance data hidden (which I don't object to), wouldn't it be better if the performance test scripts output the deviation from the expected throughput in percent (with one or two decimals after the comma) instead of in Mpps?

Quoted 111 lines
Quoted 35 lines
Quoted 35 lines
Quoted 10 lines

Med venlig hilsen / kind regards
- Morten Brørup

Quoted 5 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 9:32 AM
To: Ali Alnubani
Cc: David Marchand; Ferruh Yigit; [email protected]; dev;

Andrew

Quoted 1 line
Quoted 1 line

Rybchenko; Ananyev, Konstantin; Morten Brørup;

[email protected];

Quoted 6 lines
Quoted 6 lines

dpdk stable; Ajit Khaparde; Slava Ovsiienko; Alexander Kozyrev
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 6 lines
Quoted 6 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines

Just confirming that I can still reproduce the regression with

single

Quoted 3 lines
Quoted 3 lines

core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount

Quoted 1 line
Quoted 1 line

of performance loss in percent, and confirm the test case? (I

suppose

Quoted 3 lines
Quoted 3 lines

it
is testpmd io forward).

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry
for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

to

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

the added value of fixing a bug

Regards,
Olivier

Quoted 3 lines

- Ali

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

<[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf

free

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi,
Adding Ferruh and Zhaoyan,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel

servers?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Even though the check iol-intel-Performance isn't failing, I can

see that the

Quoted 1 line
Quoted 1 line

throughput differences from expected for this patch are less

than

Quoted 28 lines
Quoted 27 lines
Quoted 2 lines
Quoted 2 lines

those of

Quoted 1 line
Quoted 1 line

another patch that was tested only 20 minutes earlier. Both

patches

Quoted 4 lines
Quoted 4 lines

were

Quoted 3 lines
Quoted 3 lines

applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-

Quoted 8 lines
Quoted 8 lines

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it

looks

Quoted 10 lines
Quoted 9 lines

to me

Quoted 3 lines
Quoted 3 lines

that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel

NICs and

Quoted 4 lines
Quoted 4 lines

rerun the test on this patch?

Thanks,
Ali

#42 lore raw
Quoted 100 lines · Morten Brørup
Quoted 93 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 3:03 PM

Quoted 11 lines · Morten Brørup
Quoted 11 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Tuesday, January 19, 2021 1:01 PM

Quoted 1 line · Morten Brørup

Could someone at Intel please update the test script to provide

output according to the test plan? Or delegate to the right person.

Quoted 2 lines

According to the test plan, the information requested by Olivier

should be in the test output already:

Quoted 1 line

http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test

Quoted 4 lines
Quoted 4 lines

_plan.rst?h=next

Quoted 2 lines

PS: I can't find out who is the maintainer of the test plan, so I'm

randomly pointing my finger at the test plan doc copyright holder.

:-)

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

Hi Morten,

Ali has a request to update the expected baseline, to be able to

detect

Quoted 11 lines
Quoted 5 lines

the
performance drops, let me internally figure out who can do this.

And do you have any other request, or asking same thing?

Hi Ferruh,

I am asking for something else:

The test script does not provide the output that its documentation

says that it does.

Quoted 2 lines

Apparently, the test script for nic_single_core_perf produces an

output table with these four columns (as seen at
https://lab.dpdk.org/results/dashboard/patchsets/15142/#env-18):

Quoted 2 lines
     +--------+--------------------+-----------------------+----------

--------------------+

Quoted 1 line

| Result | frame_size (bytes) | txd/rxd (descriptors) |

throughput Difference (Mpps) |

Quoted 1 line
     +--------+--------------------+-----------------------+----------

--------------------+

Quoted 1 line
     | PASS   | 64                 | 512                   | 1.57100

|

Quoted 1 line
     +--------+--------------------+-----------------------+----------

--------------------+

Quoted 1 line
     | PASS   | 64                 | 2048                  | 1.87500

|

Quoted 1 line
     +--------+--------------------+-----------------------+----------

--------------------+

Quoted 2 lines

But the test plan documentation (at

http://git.dpdk.org/tools/dts/tree/test_plans/nic_single_core_perf_test
_plan.rst) says that this output should be produced:

Quoted 2 lines
     +------------+---------+-------------+---------+-----------------

----+

Quoted 1 line

| Frame Size | TXD/RXD | Throughput | Rate | Expected

Throughput |

Quoted 1 line
     +------------+---------+-------------+---------+-----------------

----+

Quoted 1 line

| 64 | 512 | xxxxxx Mpps | xxx % | xxx Mpps

|

Quoted 1 line
     +------------+---------+-------------+---------+-----------------

----+

Quoted 1 line

| 64 | 2048 | xxxxxx Mpps | xxx % | xxx Mpps

|

Quoted 1 line
     +------------+---------+-------------+---------+-----------------

----+

Quoted 2 lines

Olivier and I am saying that only showing the Throughput Difference

(Mpps) does not provide any perspective to the result.

Quoted 2 lines

I am requesting that the Expected Throughput (Mpps) should be shown

in the result too, as documented in the test plan.

Quoted 1 line

Ahh, this has a history, when the initial community lab infrastructure prepared
some vendor(s) didn't want to show the actual throughput numbers.

That is why this diff and baseline introduced, and this is the how current
infrastructure works. So this is not something related to Intel.

Quoted 6 lines

And as you can imagine this is not a technical issue, some companies seems not
willing to share their performance numbers via community lab, and I don't know
if something changed here in last a few years.

Quoted 4 lines

That explains it!

If those companies still want to keep the community lab performance data hidden (which I don't object to), wouldn't it be better if the performance test scripts output the deviation from the expected throughput in percent (with one or two decimals after the comma) instead of in Mpps?

Sounds reasonable, I assume there is a reason behind it but I don't remember, cc'ed lab.

Quoted 112 lines
Quoted 111 lines
Quoted 35 lines
Quoted 35 lines
Quoted 10 lines

Med venlig hilsen / kind regards
- Morten Brørup

Quoted 5 lines

-----Original Message-----
From: Olivier Matz [mailto:[email protected]]
Sent: Tuesday, January 19, 2021 9:32 AM
To: Ali Alnubani
Cc: David Marchand; Ferruh Yigit; [email protected]; dev;

Andrew

Quoted 1 line
Quoted 1 line

Rybchenko; Ananyev, Konstantin; Morten Brørup;

[email protected];

Quoted 6 lines
Quoted 6 lines

dpdk stable; Ajit Khaparde; Slava Ovsiienko; Alexander Kozyrev
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 6 lines
Quoted 6 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines

Just confirming that I can still reproduce the regression with

single

Quoted 3 lines
Quoted 3 lines

core and 64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount

Quoted 1 line
Quoted 1 line

of performance loss in percent, and confirm the test case? (I

suppose

Quoted 3 lines
Quoted 3 lines

it
is testpmd io forward).

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry
for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

to

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

the added value of fixing a bug

Regards,
Olivier

Quoted 3 lines

- Ali

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

<[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf

free

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi,
Adding Ferruh and Zhaoyan,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel

servers?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Even though the check iol-intel-Performance isn't failing, I can

see that the

Quoted 1 line
Quoted 1 line

throughput differences from expected for this patch are less

than

Quoted 28 lines
Quoted 27 lines
Quoted 2 lines
Quoted 2 lines

those of

Quoted 1 line
Quoted 1 line

another patch that was tested only 20 minutes earlier. Both

patches

Quoted 4 lines
Quoted 4 lines

were

Quoted 3 lines
Quoted 3 lines

applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-

Quoted 8 lines
Quoted 8 lines

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it

looks

Quoted 10 lines
Quoted 9 lines

to me

Quoted 3 lines
Quoted 3 lines

that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel

NICs and

Quoted 4 lines
Quoted 4 lines

rerun the test on this patch?

Thanks,
Ali

#43 lore raw
In reply to Olivier Matz

Hi, All

Could we postpose this patch at least to rc2? We would like to conduct more investigations?

With best regards, Slava

Quoted 116 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Tuesday, January 19, 2021 10:32
To: Ali Alnubani <[email protected]>
Cc: David Marchand <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>; Slava Ovsiienko <[email protected]>; Alexander Kozyrev <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

Quoted 4 lines · Ali Alnubani

Hi,
(Sorry had to resend this to some recipients due to mail server problems).

Just confirming that I can still reproduce the regression with single core and

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the amount of performance loss in percent, and confirm the test case? (I suppose it is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

Quoted 34 lines

- Ali

Quoted 31 lines

-----Original Message-----
From: Ali Alnubani <[email protected]>
Sent: Friday, January 15, 2021 8:39 PM
To: David Marchand <[email protected]>; Olivier Matz <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]
Cc: dev <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Morten Brørup <[email protected]>; [email protected]; dpdk stable <[email protected]>; Ajit Khaparde <[email protected]>
Subject: Re: [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can see that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fma
ils.dpdk.org%2Farchives%2Ftest-report%2F2021-

January%2F173927.html&a

Quoted 1 line
Quoted 1 line

mp;data=04%7C01%7Cviacheslavo%40nvidia.com%7Ce2d18a8563fb42dfaba40 8d

Quoted 1 line
Quoted 1 line

8bc54c83b%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C63746641 96385

Quoted 1 line
Quoted 1 line

80374%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2lu MzIiLC

Quoted 1 line
Quoted 1 line

JBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=VGvj%2F5GcAOxof6C mlZkq

Quoted 5 lines
Quoted 5 lines

KXKOL52GctXcuL5RJXr1y8g%3D&amp;reserved=0

Quoted 1 line

| 64 | 512 | 1.571 |

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fma
ils.dpdk.org%2Farchives%2Ftest-report%2F2021-

January%2F173919.html&a

Quoted 1 line
Quoted 1 line

mp;data=04%7C01%7Cviacheslavo%40nvidia.com%7Ce2d18a8563fb42dfaba40 8d

Quoted 1 line
Quoted 1 line

8bc54c83b%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C63746641 96385

Quoted 1 line
Quoted 1 line

80374%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2lu MzIiLC

Quoted 1 line
Quoted 1 line

JBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=XSirRbm5G0WwfxySe b0ALp

Quoted 11 lines
Quoted 11 lines

owVosqoY6Nlv4UZCd1CZM%3D&amp;reserved=0

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Thanks,
Ali

#44 lore raw

What's the follow-up for this patch?

19/01/2021 15:04, Slava Ovsiienko:

Quoted 29 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to conduct more investigations?

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 22 lines · Ali Alnubani
Quoted 4 lines

Hi,
(Sorry had to resend this to some recipients due to mail server problems).

Just confirming that I can still reproduce the regression with single core and

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the amount of performance loss in percent, and confirm the test case? (I suppose it is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry for that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

Regards,
Olivier

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Thanks,
Ali

#45 lore raw

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 22 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 21 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to conduct more investigations?

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 14 lines · Ali Alnubani
Quoted 4 lines

Hi,
(Sorry had to resend this to some recipients due to mail server problems).

Just confirming that I can still reproduce the regression with single core and

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the amount of performance loss in percent, and confirm the test case? (I suppose it is testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon (sorry for that). So I see at least these 2 options:

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared to the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Thanks,
Ali

#46 lore raw
Quoted 46 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to

conduct more investigations?

Quoted 7 lines
Quoted 7 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 3 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the regression with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon

(sorry for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces, optimization patches are welcome later. We shouldn't wait for it.

If the patch is not applied, the documentation must be updated to mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Generally, there could be some performance to gain by not supporting segmented packets at all, as a compile time option. But that is a different discussion.

-Morten

#47 lore raw

30/07/2021 16:35, Morten Brørup:

Quoted 56 lines
Quoted 46 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to

conduct more investigations?

Quoted 7 lines
Quoted 7 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 3 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the regression with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon

(sorry for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces, optimization patches are welcome later. We shouldn't wait for it.

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Yes, would be good to document the known issue,
no matter how old it is.

Quoted 4 lines

Generally, there could be some performance to gain by not supporting segmented packets at all, as a compile time option. But that is a different discussion.

-Morten

#48 lore raw

Hi,

Quoted 64 lines · Thomas Monjalon

30/07/2021 16:35, Morten Brørup:

Quoted 56 lines
Quoted 46 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to

conduct more investigations?

Quoted 7 lines
Quoted 7 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 3 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the regression with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon

(sorry for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces, optimization patches are welcome later. We shouldn't wait for it.

Quoted 7 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Yes, would be good to document the known issue,
no matter how old it is.

The problem description could be something like this:

It is expected that free mbufs have their field m->nb_seg set to 1, so that when it is allocated, the user does not need to set its value. The mbuf free functions are responsible of resetting this field to 1 before returning the mbuf to the pool.

When a multi-segment mbuf is freed, the m->nb_seg field is not reset to 1 for the last segment of the chain. On next allocation of this segment, if the field is not explicitly reset by the user, an invalid mbuf can be created, and can cause an undefined behavior.

Quoted 7 lines
Quoted 4 lines

Generally, there could be some performance to gain by not supporting segmented packets at all, as a compile time option. But that is a different discussion.

-Morten

#49 lore raw
Quoted 101 lines

From: dev [mailto:[email protected]] On Behalf Of Olivier Matz
Sent: Friday, 30 July 2021 17.15

Hi,

Quoted 10 lines · Thomas Monjalon

30/07/2021 16:35, Morten Brørup:

Quoted 9 lines
Quoted 9 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic

yet.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't

know how

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like

to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

conduct more investigations?

Quoted 5 lines
Quoted 5 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 1 line

On Mon, Jan 18, 2021 at 05:52:32PM +0000, Ali Alnubani

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail

server

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the regression

with

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is

the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on

this soon

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

(sorry for

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to

analyze

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

and optimize
- apply the patch if the performance loss is acceptable

compared

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines
Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces,

optimization patches are welcome later. We shouldn't wait for it.

Quoted 5 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to

mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Quoted 3 lines

Yes, would be good to document the known issue,
no matter how old it is.

The problem description could be something like this:

It is expected that free mbufs have their field m->nb_seg set to 1,
so
that when it is allocated, the user does not need to set its value. The mbuf free functions are responsible of resetting this
field
to 1 before returning the mbuf to the pool.

Quoted 5 lines

When a multi-segment mbuf is freed, the m->nb_seg field is not reset to 1 for the last segment of the chain. On next allocation of this segment, if the field is not explicitly reset by the user, an invalid mbuf can be created, and can cause an undefined behavior.

And it needs to be put somewhere very prominent if we expect the users to read it.

Would adding an RTE_VERIFY() - instead of fixing the bug - cause a regression? If not, then any affected user will know what went wrong and where. This would still be an improvement, if the bugfix patch cannot be applied.

Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

Generally, there could be some performance to gain by not

supporting segmented packets at all, as a compile time option. But that is a different discussion.

Quoted 6 lines
Quoted 3 lines

-Morten

#50 lore raw

PATCH 1/1 doc: add known issue with mbuf segment

In reply to Olivier Matz

A bug with segmented packets has been discovered but the agreement to apply the fix is not concluded at the time of DPDK 21.08 release. This bug seems to be in DPDK for many years and should be fixed in 21.11.

---
 doc/guides/rel_notes/release_21_08.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_21_08.rst +12 -0
index d7559ec6bf..14e32585b8 100644
@@ -251,6 +251,18 @@ Known Issues
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* **Last mbuf segment not implicitly reset.**
+
+  It is expected that free mbufs have their field ``nb_seg`` set to 1,
+  so that when it is allocated, the user does not need to set its value.
+  The mbuf free functions are responsible of resetting this field to 1
+  before returning the mbuf to the pool.
+
+  When a multi-segment mbuf is freed, the field ``nb_seg`` is not reset
+  to 1 for the last segment of the chain. On next allocation of this segment,
+  if the field is not explicitly reset by the user,
+  an invalid mbuf can be created, and can cause an undefined behavior.
+
 
 Tested Platforms
 ----------------
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#51 lore raw

Re: [dpdk-dev] [PATCH] doc: add known issue with mbuf segment

Quoted 7 lines · Thomas Monjalon

A bug with segmented packets has been discovered but the agreement to apply the fix is not concluded at the time of DPDK 21.08 release. This bug seems to be in DPDK for many years and should be fixed in 21.11.

Quoted 30 lines
---
 doc/guides/rel_notes/release_21_08.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_21_08.rst +12 -1
index d7559ec6bf..14e32585b8 100644
@@ -251,6 +251,18 @@ Known Issues
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* **Last mbuf segment not implicitly reset.**
+
+  It is expected that free mbufs have their field ``nb_seg`` set to 1,
+  so that when it is allocated, the user does not need to set its value.
+  The mbuf free functions are responsible of resetting this field to 1
+  before returning the mbuf to the pool.
+
+  When a multi-segment mbuf is freed, the field ``nb_seg`` is not reset
+  to 1 for the last segment of the chain. On next allocation of this segment,
+  if the field is not explicitly reset by the user,
+  an invalid mbuf can be created, and can cause an undefined behavior.
+
 
 Tested Platforms
 ----------------
--

2.31.1

Acked-by on v1 1/1
#52 lore raw

Re: [dpdk-dev] [PATCH] doc: add known issue with mbuf segment

In reply to Thomas Monjalon
Quoted 36 lines

From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Wednesday, 4 August 2021 15.30

A bug with segmented packets has been discovered but the agreement to apply the fix is not concluded at the time of DPDK 21.08 release. This bug seems to be in DPDK for many years and should be fixed in 21.11.

---
 doc/guides/rel_notes/release_21_08.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_21_08.rst +4 -0
index d7559ec6bf..14e32585b8 100644
@@ -251,6 +251,18 @@ Known Issues
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* **Last mbuf segment not implicitly reset.**
+
+  It is expected that free mbufs have their field ``nb_seg`` set to 1,
+  so that when it is allocated, the user does not need to set its

value.

doc/guides/rel_notes/release_21_08.rst +4 -0
+  The mbuf free functions are responsible of resetting this field to 1
+  before returning the mbuf to the pool.
+
+  When a multi-segment mbuf is freed, the field ``nb_seg`` is not

reset
+ to 1 for the last segment of the chain. On next allocation of this segment,

doc/guides/rel_notes/release_21_08.rst Known Issues · line 265

Quoted 3 lines
doc/guides/rel_notes/release_21_08.rst +3 -0
+  if the field is not explicitly reset by the user,
+  an invalid mbuf can be created, and can cause an undefined behavior.
+

I have a couple of suggestions:

1. Add that this bug was present in previous DPDK releases for many years. If possible, mention which release introduced the bug.

We don't want users to choose to stay on older release, thinking that it does not have this bug.

Also, if a user experiences unexplainable problems with segmented packets an older DPDK release, he might get lucky and find these release notes, which could reveal the root cause of the problems he is experiencing.

2. Add a link to the patch that fixes the bug. It will let users affected by the bug easily fix it (possibly at the expense of degraded performance).

With those two additions,

-Morten

#53 lore raw

Re: [dpdk-dev] [PATCH] doc: add known issue with mbuf segment

05/08/2021 08:08, Morten Brørup:

Quoted 44 lines
Quoted 36 lines

From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Wednesday, 4 August 2021 15.30

A bug with segmented packets has been discovered but the agreement to apply the fix is not concluded at the time of DPDK 21.08 release. This bug seems to be in DPDK for many years and should be fixed in 21.11.

---
 doc/guides/rel_notes/release_21_08.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_21_08.rst +4 -0
index d7559ec6bf..14e32585b8 100644
@@ -251,6 +251,18 @@ Known Issues
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* **Last mbuf segment not implicitly reset.**
+
+  It is expected that free mbufs have their field ``nb_seg`` set to 1,
+  so that when it is allocated, the user does not need to set its

value.

doc/guides/rel_notes/release_21_08.rst +4 -0
+  The mbuf free functions are responsible of resetting this field to 1
+  before returning the mbuf to the pool.
+
+  When a multi-segment mbuf is freed, the field ``nb_seg`` is not

reset
+ to 1 for the last segment of the chain. On next allocation of this segment,

doc/guides/rel_notes/release_21_08.rst Known Issues · line 265

Quoted 3 lines
doc/guides/rel_notes/release_21_08.rst +3 -0
+  if the field is not explicitly reset by the user,
+  an invalid mbuf can be created, and can cause an undefined behavior.
+

I have a couple of suggestions:

1. Add that this bug was present in previous DPDK releases for many years. If possible, mention which release introduced the bug.

Quoted 8 lines

We don't want users to choose to stay on older release, thinking that it does not have this bug.

Also, if a user experiences unexplainable problems with segmented packets an older DPDK release, he might get lucky and find these release notes, which could reveal the root cause of the problems he is experiencing.

2. Add a link to the patch that fixes the bug. It will let users affected by the bug easily fix it (possibly at the expense of degraded performance).

With those two additions,

Applied with the suggested additions:

+  This issue has a root cause in DPDK 17.05, meaning it is 4 years old.
+  A fix is available and discussed but not merged in DPDK 21.08:
+  https://patches.dpdk.org/patch/86458/
#54 lore raw

Re: [dpdk-dev] [PATCH] doc: add known issue with mbuf segment

Quoted 75 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Friday, 6 August 2021 16.21

05/08/2021 08:08, Morten Brørup:

Quoted 1 line
Quoted 1 line

From: dev [mailto:[email protected]] On Behalf Of Thomas

Monjalon

Quoted 4 lines
Quoted 4 lines

Sent: Wednesday, 4 August 2021 15.30

A bug with segmented packets has been discovered but the agreement to apply the fix is not concluded at the time of DPDK 21.08

release.

Quoted 18 lines
Quoted 18 lines

This bug seems to be in DPDK for many years and should be fixed in 21.11.

---
 doc/guides/rel_notes/release_21_08.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)
doc/guides/rel_notes/release_21_08.rst +0 -0
index d7559ec6bf..14e32585b8 100644
@@ -251,6 +251,18 @@ Known Issues
    Also, make sure to start the actual text at the margin.
    =======================================================
 
Quoted 3 lines

doc/guides/rel_notes/release_21_08.rst Known Issues

Quoted 3 lines
doc/guides/rel_notes/release_21_08.rst +3 -0
+* **Last mbuf segment not implicitly reset.**
+
+  It is expected that free mbufs have their field ``nb_seg`` set

to 1,

Quoted 3 lines
Quoted 3 lines
doc/guides/rel_notes/release_21_08.rst +1 -0
+  so that when it is allocated, the user does not need to set its

value.
+ The mbuf free functions are responsible of resetting this field

to 1

Quoted 5 lines
Quoted 5 lines
doc/guides/rel_notes/release_21_08.rst +3 -0
+  before returning the mbuf to the pool.
+
+  When a multi-segment mbuf is freed, the field ``nb_seg`` is not

reset
+ to 1 for the last segment of the chain. On next allocation of

this

Quoted 3 lines

doc/guides/rel_notes/release_21_08.rst

Quoted 3 lines

segment,

doc/guides/rel_notes/release_21_08.rst +2 -0
+  if the field is not explicitly reset by the user,
+  an invalid mbuf can be created, and can cause an undefined

behavior.

Quoted 6 lines
Quoted 2 lines

+

I have a couple of suggestions:

1. Add that this bug was present in previous DPDK releases for many

years. If possible, mention which release introduced the bug.

Quoted 2 lines

We don't want users to choose to stay on older release, thinking that

it does not have this bug.

Quoted 2 lines

Also, if a user experiences unexplainable problems with segmented

packets an older DPDK release, he might get lucky and find these release notes, which could reveal the root cause of the problems he is experiencing.

Quoted 2 lines

2. Add a link to the patch that fixes the bug. It will let users

affected by the bug easily fix it (possibly at the expense of degraded performance).

Quoted 3 lines

With those two additions,

Applied with the suggested additions:

+ This issue has a root cause in DPDK 17.05, meaning it is 4 years old.

Review

Quoted 2 lines
(quoted diff) +2 -0
+  A fix is available and discussed but not merged in DPDK 21.08:
+  https://patches.dpdk.org/patch/86458/

Perfect! Thanks.

-Morten

#55 lore raw
In reply to Thomas Monjalon

Follow-up again:
We have added a note in 21.08, we should fix it in 21.11. If there are no counter proposal, I suggest applying this patch, no matter the performance regression.

30/07/2021 16:54, Thomas Monjalon:

Quoted 73 lines

30/07/2021 16:35, Morten Brørup:

Quoted 56 lines
Quoted 46 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to

conduct more investigations?

Quoted 7 lines
Quoted 7 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 3 lines · Ali Alnubani
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the regression with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon

(sorry for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces, optimization patches are welcome later. We shouldn't wait for it.

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Yes, would be good to document the known issue,
no matter how old it is.

Quoted 1 line

Generally, there could be some performance to gain by not supporting segmented packets at all, as a compile time option. But that is a different discussion.

#56 lore raw

Hi,

I've re-read the entire thread.
If I understand correctly, the root problem was (in initial patch):

Quoted 9 lines
  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);
Quoted 7 lines

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

The proposed fix was to ALWAYS set next and nb_seg fields on mbuf_free(), regardless next field content. That would perform unconditional write to mbuf, and might affect the configurations, where are no multi-segment packets at al. mbuf_free() is "backbone" API, it is used by all cases, all scenaries are affected.

As far as I know, the current approach for nb_seg field - it contains other value than 1 only in the first mbuf , for the following segments, it should not be considered at all (only the first segment fields are valid), and it is supposed to contain 1, as it was initially allocated from the pool.

In the example above the problem was introduced by rte_pktmbuf_chain(). Could we consider fixing the rte_pktmbuf_chain() (used in potentially fewer common sceneries) instead of touching the extremely common rte_mbuf_free() ?

With best regards,
Slava

Quoted 108 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, September 28, 2021 11:29
To: Olivier Matz <[email protected]>; Ali Alnubani <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: Morten Brørup <[email protected]>; [email protected]; David Marchand <[email protected]>; Alexander Kozyrev <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Follow-up again:
We have added a note in 21.08, we should fix it in 21.11.
If there are no counter proposal, I suggest applying this patch, no matter the performance regression.

30/07/2021 16:54, Thomas Monjalon:

Quoted 68 lines

30/07/2021 16:35, Morten Brørup:

Quoted 67 lines
Quoted 51 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to

conduct more investigations?

Quoted 8 lines
Quoted 8 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 4 lines · Ali Alnubani
Quoted 3 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Just confirming that I can still reproduce the regression with

single core and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon

(sorry for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces, optimization

patches are welcome later. We shouldn't wait for it.

Quoted 5 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to

mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Quoted 5 lines

Yes, would be good to document the known issue, no matter how old it is.

Quoted 1 line

Generally, there could be some performance to gain by not supporting

segmented packets at all, as a compile time option. But that is a different discussion.

#57 lore raw
Quoted 23 lines

Hi,

I've re-read the entire thread.
If I understand correctly, the root problem was (in initial patch):

Quoted 9 lines
  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);
Quoted 7 lines

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Quoted 3 lines

The proposed fix was to ALWAYS set next and nb_seg fields on mbuf_free(), regardless next field content. That would perform unconditional write to mbuf,

I don't think it is a correct understanding see below.

Current code:

if (m->next != NULL) {
       m->next = NULL;
      m->nb_segs = 1;
}

Proposed code:
if (m->next != NULL)

     m->next = NULL;
if (m->nb_segs != 1)
    m->nb_segs = 1;

So what this patch adds: one more load and compare. Note that load is from the first mbuf cache line, which already has to be in the L1 cache by that time.

As I remember the reported slowdown is really tiny. My vote would be to go ahead with this patch.

Quoted 125 lines

and might affect the configurations, where are no multi-segment packets at al. mbuf_free() is "backbone" API, it is used by all cases, all scenaries are affected.

As far as I know, the current approach for nb_seg field - it contains other value than 1 only in the first mbuf , for the following segments, it should not be considered at all (only the first segment fields are valid), and it is supposed to contain 1, as it was initially allocated from the pool.

In the example above the problem was introduced by rte_pktmbuf_chain(). Could we consider fixing the rte_pktmbuf_chain() (used in potentially fewer common sceneries) instead of touching the extremely common rte_mbuf_free() ?

With best regards,
Slava

Quoted 108 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, September 28, 2021 11:29
To: Olivier Matz <[email protected]>; Ali Alnubani <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: Morten Brørup <[email protected]>; [email protected]; David Marchand <[email protected]>; Alexander Kozyrev <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Follow-up again:
We have added a note in 21.08, we should fix it in 21.11.
If there are no counter proposal, I suggest applying this patch, no matter the performance regression.

30/07/2021 16:54, Thomas Monjalon:

Quoted 68 lines

30/07/2021 16:35, Morten Brørup:

Quoted 67 lines
Quoted 51 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

Quoted 1 line · Thomas Monjalon

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic yet.

In my initial tests, in our lab, I didn't notice any performance regression, but Ali has seen an impact (0.5M PPS, but I don't know how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like to

conduct more investigations?

Quoted 8 lines
Quoted 8 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 4 lines · Ali Alnubani
Quoted 3 lines

Hi,
(Sorry had to resend this to some recipients due to mail server

problems).

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Just confirming that I can still reproduce the regression with

single core and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what is the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case? (I

suppose it is

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on this soon

(sorry for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to analyze and optimize
- apply the patch if the performance loss is acceptable compared

Quoted 9 lines

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces, optimization

patches are welcome later. We shouldn't wait for it.

Quoted 5 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to

mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this patch.

Quoted 5 lines

Yes, would be good to document the known issue, no matter how old it is.

Quoted 1 line

Generally, there could be some performance to gain by not supporting

segmented packets at all, as a compile time option. But that is a different discussion.

#58 lore raw
In reply to Slava Ovsiienko
Quoted 42 lines

From: dev [mailto:[email protected]] On Behalf Of Slava Ovsiienko
Sent: Tuesday, 28 September 2021 11.01

Hi,

I've re-read the entire thread.
If I understand correctly, the root problem was (in initial patch):

Quoted 10 lines
  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1

segment

Quoted 6 lines

(this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

The proposed fix was to ALWAYS set next and nb_seg fields on mbuf_free(),
regardless next field content. That would perform unconditional write to mbuf, and might affect the configurations, where are no multi- segment
packets at al. mbuf_free() is "backbone" API, it is used by all cases, all
scenaries are affected.

As far as I know, the current approach for nb_seg field - it contains other
value than 1 only in the first mbuf , for the following segments, it should
not be considered at all (only the first segment fields are valid), and it is
supposed to contain 1, as it was initially allocated from the pool.

Quoted 7 lines

In the example above the problem was introduced by rte_pktmbuf_chain(). Could we consider fixing the rte_pktmbuf_chain() (used in potentially fewer common sceneries) instead of touching the extremely common rte_mbuf_free() ?

With best regards,
Slava

Great idea, Slava!

Changing the invariant for 'nb_segs', so it must be 1, except in the first segment of a segmented packet.

Thinking further about it, perhaps we can achieve even higher performance by a minor additional modification: Use 0 instead of 1? Or offset 'nb_segs' by -1, so it reflects the number of additional segments?

And perhaps combining the invariants for 'nb_segs' and 'next' could provide even more performance improvements. I don't know, just sharing a thought.

Anyway, I vote for fixing the bug. One way or the other!

-Morten

Quoted 117 lines
Quoted 8 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, September 28, 2021 11:29

Follow-up again:
We have added a note in 21.08, we should fix it in 21.11. If there are no counter proposal, I suggest applying this patch, no

matter the

Quoted 11 lines

performance regression.

30/07/2021 16:54, Thomas Monjalon:

Quoted 7 lines

30/07/2021 16:35, Morten Brørup:

Quoted 6 lines
Quoted 6 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

On Sat, Jul 24, 2021 at 10:47:34AM +0200, Thomas Monjalon

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic

yet.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

In my initial tests, in our lab, I didn't notice any

performance

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

regression, but Ali has seen an impact (0.5M PPS, but I don't

know

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

how much in percent).

Quoted 4 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 3 lines

Hi, All

Could we postpose this patch at least to rc2? We would like

to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

conduct more investigations?

Quoted 5 lines
Quoted 5 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 1 line

On Mon, Jan 18, 2021 at 05:52:32PM +0000, Ali Alnubani

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to

mail

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the

regression

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case?

(I

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on

this

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

soon

(sorry for

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to

analyze

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and optimize
- apply the patch if the performance loss is acceptable compared

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces,

optimization

Quoted 8 lines

patches are welcome later. We shouldn't wait for it.

Quoted 5 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 1 line

If the patch is not applied, the documentation must be updated to

mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this

patch.

Quoted 2 lines
Quoted 2 lines

Yes, would be good to document the known issue, no matter how old

it

Quoted 3 lines
Quoted 3 lines

is.

Quoted 1 line

Generally, there could be some performance to gain by not

supporting

Quoted 1 line

segmented packets at all, as a compile time option. But that is a

different

Quoted 4 lines

discussion.

#59 lore raw

Hi Olivier,

I wanted to retest the patch on latest main, but it no longer applies, could you please rebase it?

Thanks,
Ali

Quoted 196 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Tuesday, September 28, 2021 12:40 PM
To: Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Olivier Matz <[email protected]>; Ali Alnubani <[email protected]>
Cc: [email protected]; David Marchand <[email protected]>; Alexander Kozyrev <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Quoted 37 lines

From: dev [mailto:[email protected]] On Behalf Of Slava Ovsiienko
Sent: Tuesday, 28 September 2021 11.01

Hi,

I've re-read the entire thread.
If I understand correctly, the root problem was (in initial patch):

Quoted 10 lines
  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1

segment

Quoted 6 lines

(this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

The proposed fix was to ALWAYS set next and nb_seg fields on mbuf_free(), regardless next field content. That would perform unconditional write to mbuf, and might affect the configurations, where are no multi- segment packets at al. mbuf_free() is "backbone" API, it is used by all cases, all scenaries are affected.

As far as I know, the current approach for nb_seg field - it contains other value than 1 only in the first mbuf , for the following segments, it should not be considered at all (only the first segment fields are valid), and it is supposed to contain 1, as it was initially allocated from the pool.

Quoted 7 lines

In the example above the problem was introduced by rte_pktmbuf_chain(). Could we consider fixing the rte_pktmbuf_chain() (used in potentially fewer common sceneries) instead of touching the extremely common rte_mbuf_free() ?

With best regards,
Slava

Great idea, Slava!

Changing the invariant for 'nb_segs', so it must be 1, except in the first segment of a segmented packet.

Thinking further about it, perhaps we can achieve even higher performance by a minor additional modification: Use 0 instead of 1? Or offset 'nb_segs' by -1, so it reflects the number of additional segments?

And perhaps combining the invariants for 'nb_segs' and 'next' could provide even more performance improvements. I don't know, just sharing a thought.

Anyway, I vote for fixing the bug. One way or the other!

-Morten

Quoted 121 lines
Quoted 8 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, September 28, 2021 11:29

Follow-up again:
We have added a note in 21.08, we should fix it in 21.11. If there are no counter proposal, I suggest applying this patch, no

matter the

Quoted 11 lines

performance regression.

30/07/2021 16:54, Thomas Monjalon:

Quoted 7 lines

30/07/2021 16:35, Morten Brørup:

Quoted 6 lines
Quoted 6 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

On Sat, Jul 24, 2021 at 10:47:34AM +0200, Thomas Monjalon

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic

yet.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

In my initial tests, in our lab, I didn't notice any

performance

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

regression, but Ali has seen an impact (0.5M PPS, but I don't

know

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

how much in percent).

Quoted 5 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 4 lines

Hi, All

Could we postpose this patch at least to rc2? We would like

to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

conduct more investigations?

Quoted 5 lines
Quoted 5 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 1 line

On Mon, Jan 18, 2021 at 05:52:32PM +0000, Ali Alnubani

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to

mail

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the

regression

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case?

(I

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on

this

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

soon

(sorry for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to

analyze

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and optimize
- apply the patch if the performance loss is acceptable compared

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces,

optimization

Quoted 9 lines

patches are welcome later. We shouldn't wait for it.

Quoted 6 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 2 lines

If the patch is not applied, the documentation must be updated to

mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this

patch.

Quoted 2 lines
Quoted 2 lines

Yes, would be good to document the known issue, no matter how old

it

Quoted 3 lines
Quoted 3 lines

is.

Quoted 1 line

Generally, there could be some performance to gain by not

supporting

Quoted 1 line

segmented packets at all, as a compile time option. But that is a

different

Quoted 4 lines

discussion.

#60 lore raw

Hi Ali,

Quoted 3 lines · Ali Alnubani

Hi Olivier,

I wanted to retest the patch on latest main, but it no longer applies, could you please rebase it?

I rebased the patch:
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

Thanks,
Olivier

Quoted 201 lines

Thanks,
Ali

Quoted 196 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Tuesday, September 28, 2021 12:40 PM
To: Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Olivier Matz <[email protected]>; Ali Alnubani <[email protected]>
Cc: [email protected]; David Marchand <[email protected]>; Alexander Kozyrev <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Quoted 37 lines

From: dev [mailto:[email protected]] On Behalf Of Slava Ovsiienko
Sent: Tuesday, 28 September 2021 11.01

Hi,

I've re-read the entire thread.
If I understand correctly, the root problem was (in initial patch):

Quoted 10 lines
  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1

segment

Quoted 6 lines

(this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

The proposed fix was to ALWAYS set next and nb_seg fields on mbuf_free(), regardless next field content. That would perform unconditional write to mbuf, and might affect the configurations, where are no multi- segment packets at al. mbuf_free() is "backbone" API, it is used by all cases, all scenaries are affected.

As far as I know, the current approach for nb_seg field - it contains other value than 1 only in the first mbuf , for the following segments, it should not be considered at all (only the first segment fields are valid), and it is supposed to contain 1, as it was initially allocated from the pool.

Quoted 7 lines

In the example above the problem was introduced by rte_pktmbuf_chain(). Could we consider fixing the rte_pktmbuf_chain() (used in potentially fewer common sceneries) instead of touching the extremely common rte_mbuf_free() ?

With best regards,
Slava

Great idea, Slava!

Changing the invariant for 'nb_segs', so it must be 1, except in the first segment of a segmented packet.

Thinking further about it, perhaps we can achieve even higher performance by a minor additional modification: Use 0 instead of 1? Or offset 'nb_segs' by -1, so it reflects the number of additional segments?

And perhaps combining the invariants for 'nb_segs' and 'next' could provide even more performance improvements. I don't know, just sharing a thought.

Anyway, I vote for fixing the bug. One way or the other!

-Morten

Quoted 121 lines
Quoted 8 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, September 28, 2021 11:29

Follow-up again:
We have added a note in 21.08, we should fix it in 21.11. If there are no counter proposal, I suggest applying this patch, no

matter the

Quoted 11 lines

performance regression.

30/07/2021 16:54, Thomas Monjalon:

Quoted 7 lines

30/07/2021 16:35, Morten Brørup:

Quoted 6 lines
Quoted 6 lines

From: Olivier Matz [mailto:[email protected]]
Sent: Friday, 30 July 2021 14.37

Hi Thomas,

On Sat, Jul 24, 2021 at 10:47:34AM +0200, Thomas Monjalon

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

What's the follow-up for this patch?

Unfortunatly, I still don't have the time to work on this topic

yet.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

In my initial tests, in our lab, I didn't notice any

performance

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

regression, but Ali has seen an impact (0.5M PPS, but I don't

know

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

how much in percent).

Quoted 5 lines

19/01/2021 15:04, Slava Ovsiienko:

Quoted 4 lines

Hi, All

Could we postpose this patch at least to rc2? We would like

to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

conduct more investigations?

Quoted 5 lines
Quoted 5 lines

With best regards, Slava

From: Olivier Matz <[email protected]>

Quoted 1 line

On Mon, Jan 18, 2021 at 05:52:32PM +0000, Ali Alnubani

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hi,
(Sorry had to resend this to some recipients due to

mail

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

server

problems).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Just confirming that I can still reproduce the

regression

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

with

single core and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

64B frames on other servers.

Many thanks for the feedback. Can you please detail what

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

the

amount of

Quoted 1 line
Quoted 1 line
Quoted 1 line

performance loss in percent, and confirm the test case?

(I

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

suppose it is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

testpmd io forward).

Unfortunatly, I won't be able to spend a lot of time on

this

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

soon

(sorry for

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

that). So I see at least these 2 options:

- postpone the patch again, until I can find more time to

analyze

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

and optimize
- apply the patch if the performance loss is acceptable compared

to

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

the added value of fixing a bug

[...]

Statu quo...

Olivier

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The decision should be simple:

Does the DPDK project support segmented packets?
If yes, then apply the patch to fix the bug!

If anyone seriously cares about the regression it introduces,

optimization

Quoted 9 lines

patches are welcome later. We shouldn't wait for it.

Quoted 6 lines

You're right, but the regression is flagged to a 4-years old patch, that's why I don't consider it as urgent.

Quoted 2 lines

If the patch is not applied, the documentation must be updated to

mention that we are releasing DPDK with a known bug: that segmented packets are handled incorrectly in the scenario described in this

patch.

Quoted 2 lines
Quoted 2 lines

Yes, would be good to document the known issue, no matter how old

it

Quoted 3 lines
Quoted 3 lines

is.

Quoted 1 line

Generally, there could be some performance to gain by not

supporting

Quoted 1 line

segmented packets at all, as a compile time option. But that is a

different

Quoted 4 lines

discussion.

#61 lore raw
Quoted 19 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Thursday, September 30, 2021 12:39 AM
To: Ali Alnubani <[email protected]>
Cc: [email protected]; David Marchand <[email protected]>; Alexander Kozyrev <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Slava Ovsiienko <[email protected]>; [email protected]; Morten Brørup <[email protected]>; Andrew Rybchenko <[email protected]>; Ananyev, Konstantin <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [dpdk-stable] [PATCH v4] mbuf: fix reset on mbuf free

Hi Ali,

On Wed, Sep 29, 2021 at 08:03:17AM +0000, Ali Alnubani wrote:

Quoted 9 lines
Quoted 3 lines

Hi Olivier,

I wanted to retest the patch on latest main, but it no longer applies, could

you please rebase it?

I rebased the patch:
https://patchwork.dpdk.org/project/dpdk/patch/20210929213707.17727-1-
[email protected]/

Thanks for the update,
I tested v5 on main (84b3e4555a1f) and the regression we previously saw no longer reproduces.

Will the patch be backported to 20.11? I can still reproduce a 2% drop in single core packet forwarding performance with v4 applied on v20.11.3.

Testpmd: dpdk-testpmd -n 4 -a 0000:82:00.0 -a 0000:82:00.1 -c 0x9000 -- -i --nb-cores=1 --txd=256 --rxd=256 --auto-start Traffic generator is TREX with pattern (Ether / IP / UDP).
Drop is from ~50.5 mpps to ~49.5 mpps.

OS: 18.04.5 LTS
Device: ConnectX-5
MLNX_OFED: MLNX_OFED_LINUX-5.4-1.0.3.0
Firmware: 16.31.1014

Regards,
Ali

#62 lore raw

30/09/2021 15:29, Ali Alnubani:

Quoted 7 lines

From: Olivier Matz <[email protected]>

Quoted 6 lines · Ali Alnubani
Quoted 3 lines

Hi Olivier,

I wanted to retest the patch on latest main, but it no longer applies, could

you please rebase it?

Quoted 8 lines
Quoted 3 lines

I rebased the patch:
https://patchwork.dpdk.org/project/dpdk/patch/20210929213707.17727-1-
[email protected]/

Thanks for the update,
I tested v5 on main (84b3e4555a1f) and the regression we previously saw no longer reproduces.

Will the patch be backported to 20.11? I can still reproduce a 2% drop in single core packet forwarding performance with v4 applied on v20.11.3.

As any significant fix, we must backport, or at least, try. If there is a real issue in a stable branch, we'll discuss it in the test&release process of this branch.

#63 lore raw
In reply to Ali Alnubani
Quoted 14 lines · Ali Alnubani

Hi,
Adding Ferruh and Zhaoyan,

Quoted 4 lines

Ali,

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers?
Even though the check iol-intel-Performance isn't failing, I can see that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

https://mails.dpdk.org/archives/test-report/2021-January/173927.html

Quoted 9 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-January/173919.html

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks to me that this patch caused a regression in Intel hardware as well.

Can someone update the baseline's expected values for the Intel NICs and rerun the test on this patch?

Zhaoyan said that the baseline is calculated dynamically,
what I understand is baseline set based on previous days performance result, so it shouldn't require updating.

But cc'ed the lab for more details.

#64 lore raw
Quoted 29 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Thursday, January 21, 2021 10:19 AM

Quoted 5 lines · Ali Alnubani

Hi,
Adding Ferruh and Zhaoyan,

Quoted 2 lines

Ali,

Quoted 7 lines
Quoted 2 lines

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can see

that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

Quoted 8 lines

https://mails.dpdk.org/archives/test-report/2021-January/173927.html

Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-January/173919.html

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks

to me that this patch caused a regression in Intel hardware as well.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

Can someone update the baseline's expected values for the Intel NICs

and rerun the test on this patch?

Quoted 1 line

Zhaoyan said that the baseline is calculated dynamically, what I understand is baseline set based on previous days performance result, so
it shouldn't require updating.

That sounds smart!

Perhaps another reference baseline could be added, for informational purposes only:
Deviation from the performance of the last official release.

Quoted 2 lines

But cc'ed the lab for more details.

#65 lore raw

Hi All,

Trying to follow the specific conversation. It is correct, the lab does not list the specific throughput values achieved by the hardware, as that data can be sensitive to the hardware vendors, etc. The purpose of the lab is to check for degradations caused by patches, so the difference is really the important factor. The comparison is against a prior run on the same hardware, via the DPDK main branch, so any delta should be caused by the specific patch changes (excluding statistical "wiggle").

If the group would prefer, we could calculate additional references if desired (i.e. difference from the last official release, or a monthly run of the current, etc.). We just need the community to define their needs, and we can add this to the development queue.

Cheers,
Lincoln

Quoted 48 lines · Morten Brørup
Quoted 29 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Thursday, January 21, 2021 10:19 AM

Quoted 5 lines · Ali Alnubani

Hi,
Adding Ferruh and Zhaoyan,

Quoted 2 lines

Ali,

Quoted 7 lines
Quoted 2 lines

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can see

that the throughput differences from expected for this patch are less than those of another patch that was tested only 20 minutes earlier. Both patches were applied to the same tree:

Quoted 8 lines

https://mails.dpdk.org/archives/test-report/2021-January/173927.html

Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-January/173919.html

Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it looks

to me that this patch caused a regression in Intel hardware as well.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

Can someone update the baseline's expected values for the Intel NICs

and rerun the test on this patch?

Quoted 1 line

Zhaoyan said that the baseline is calculated dynamically, what I understand is baseline set based on previous days performance result, so
it shouldn't require updating.

That sounds smart!

Perhaps another reference baseline could be added, for informational purposes only:
Deviation from the performance of the last official release.

Quoted 2 lines

But cc'ed the lab for more details.

Signature · 7 lines
*Lincoln Lavoie*
Senior Engineer, Broadband Technologies
21 Madbury Rd., Ste. 100, Durham, NH 03824
[email protected]
https://www.iol.unh.edu
+1-603-674-2755 (m)
<https://www.iol.unh.edu>
#66 lore raw
Quoted 6 lines

From: dev [mailto:[email protected]] On Behalf Of Lincoln Lavoie
Sent: Thursday, January 21, 2021 5:35 PM
To: Morten Brørup

Hi All,

Quoted 14 lines

Trying to follow the specific conversation. It is correct, the lab does
not list the specific throughput values achieved by the hardware, as that
data can be sensitive to the hardware vendors, etc. The purpose of the lab
is to check for degradations caused by patches, so the difference is really
the important factor. The comparison is against a prior run on the same
hardware, via the DPDK main branch, so any delta should be caused by the
specific patch changes (excluding statistical "wiggle").

Thank you for clarifying, Lincoln.

This sounds like a perfect solution to the meet the purpose.

I request that you change the output to show the relative difference (i.e. percentage above/below baseline), instead of the absolute difference (i.e. number of packets per second).

By showing a percentage, anyone reading the test report can understand if the difference is insignificant, or big enough to require further discussion before accepting the patch. Showing the difference in packets per second requires the reader of the test report to have prior knowledge about the expected performance.

Quoted 7 lines

If the group would prefer, we could calculate additional references if desired (i.e. difference from the last official release, or a monthly run
of the current, etc.). We just need the community to define their needs,
and we can add this to the development queue.

I retract my suggestion about adding additional references. You clearly explained how your baselining works, and I think it fully serves the needs of a regression test.

So please just put this small change in your development queue: Output the difference in percent with a few decimals after the comma, instead of the difference in packets per second.

For readability, performance drops should be shown as negative values, and increases as positive, e.g.:

Difference = (NewPPS - BaselinePPS) / BaselinePPS * 100.00 %.

If we want to compare performance against official releases, current or older, it should go elsewhere, not in the continuous testing environment. E.g. the release notes could include a report showing differences from the last few official releases. But that is a task for another day.

Quoted 74 lines

Cheers,
Lincoln

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Thursday, January 21, 2021 10:19 AM

Quoted 5 lines · Ali Alnubani

Hi,
Adding Ferruh and Zhaoyan,

Quoted 2 lines

Ali,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can

see

Quoted 1 line
Quoted 1 line

that the throughput differences from expected for this patch are

less

Quoted 1 line
Quoted 1 line

than those of another patch that was tested only 20 minutes

earlier.

Quoted 3 lines
Quoted 3 lines

Both patches were applied to the same tree:

Quoted 2 lines

https://mails.dpdk.org/archives/test-report/2021-

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it

looks

Quoted 1 line
Quoted 1 line

to me that this patch caused a regression in Intel hardware as

well.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Can someone update the baseline's expected values for the Intel

NICs

Quoted 5 lines
Quoted 5 lines

and rerun the test on this patch?

Quoted 1 line

Zhaoyan said that the baseline is calculated dynamically, what I understand is baseline set based on previous days

performance

Quoted 13 lines
Quoted 2 lines

result, so
it shouldn't require updating.

That sounds smart!

Perhaps another reference baseline could be added, for informational purposes only:
Deviation from the performance of the last official release.

Quoted 2 lines

But cc'ed the lab for more details.

--
*Lincoln Lavoie*
Senior Engineer, Broadband Technologies
21 Madbury Rd., Ste. 100, Durham, NH 03824
[email protected]
https://www.iol.unh.edu
+1-603-674-2755 (m)
<https://www.iol.unh.edu>

#67 lore raw

Hi,

This seems like a good task for us to do. I will see what it would take in order to convert the difference into a decimal-formatted percentage.
I have put this into bugzilla to keep track of this issue:
https://bugs.dpdk.org/show_bug.cgi?id=626

Thanks,
Brandon

Quoted 125 lines · Morten Brørup
Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Lincoln Lavoie
Sent: Thursday, January 21, 2021 5:35 PM
To: Morten Brørup

Hi All,

Quoted 14 lines

Trying to follow the specific conversation. It is correct, the lab does
not list the specific throughput values achieved by the hardware, as that
data can be sensitive to the hardware vendors, etc. The purpose of the lab
is to check for degradations caused by patches, so the difference is really
the important factor. The comparison is against a prior run on the same
hardware, via the DPDK main branch, so any delta should be caused by the
specific patch changes (excluding statistical "wiggle").

Thank you for clarifying, Lincoln.

This sounds like a perfect solution to the meet the purpose.

I request that you change the output to show the relative difference (i.e. percentage above/below baseline), instead of the absolute difference (i.e. number of packets per second).

By showing a percentage, anyone reading the test report can understand if the difference is insignificant, or big enough to require further discussion before accepting the patch. Showing the difference in packets per second requires the reader of the test report to have prior knowledge about the expected performance.

Quoted 7 lines

If the group would prefer, we could calculate additional references if desired (i.e. difference from the last official release, or a monthly run
of the current, etc.). We just need the community to define their needs,
and we can add this to the development queue.

I retract my suggestion about adding additional references. You clearly explained how your baselining works, and I think it fully serves the needs of a regression test.

So please just put this small change in your development queue: Output the difference in percent with a few decimals after the comma, instead of the difference in packets per second.

For readability, performance drops should be shown as negative values, and increases as positive, e.g.:

Difference = (NewPPS - BaselinePPS) / BaselinePPS * 100.00 %.

If we want to compare performance against official releases, current or older, it should go elsewhere, not in the continuous testing environment. E.g. the release notes could include a report showing differences from the last few official releases. But that is a task for another day.

Quoted 74 lines

Cheers,
Lincoln

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Thursday, January 21, 2021 10:19 AM

Quoted 5 lines · Ali Alnubani

Hi,
Adding Ferruh and Zhaoyan,

Quoted 2 lines

Ali,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

You reported some performance regression, did you confirm it? If I get no reply by monday, I'll proceed with this patch.

Sure I'll confirm by Monday.

Doesn't the regression also reproduce on the Lab's Intel servers? Even though the check iol-intel-Performance isn't failing, I can

see

Quoted 1 line
Quoted 1 line

that the throughput differences from expected for this patch are

less

Quoted 1 line
Quoted 1 line

than those of another patch that was tested only 20 minutes

earlier.

Quoted 3 lines
Quoted 3 lines

Both patches were applied to the same tree:

Quoted 2 lines

https://mails.dpdk.org/archives/test-report/2021-

January/173927.html

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 1.571 |

https://mails.dpdk.org/archives/test-report/2021-

January/173919.html

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

| 64 | 512 | 2.698 |

Assuming that pw86457 doesn't have an effect on this test, it

looks

Quoted 1 line
Quoted 1 line

to me that this patch caused a regression in Intel hardware as

well.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Can someone update the baseline's expected values for the Intel

NICs

Quoted 5 lines
Quoted 5 lines

and rerun the test on this patch?

Quoted 1 line

Zhaoyan said that the baseline is calculated dynamically, what I understand is baseline set based on previous days

performance

Quoted 13 lines
Quoted 2 lines

result, so
it shouldn't require updating.

That sounds smart!

Perhaps another reference baseline could be added, for informational purposes only:
Deviation from the performance of the last official release.

Quoted 2 lines

But cc'ed the lab for more details.

--
*Lincoln Lavoie*
Senior Engineer, Broadband Technologies
21 Madbury Rd., Ste. 100, Durham, NH 03824
[email protected]
https://www.iol.unh.edu
+1-603-674-2755 (m)
<https://www.iol.unh.edu>

Signature · 9 lines
Brandon Lo

UNH InterOperability Laboratory

21 Madbury Rd, Suite 100, Durham, NH 03824

[email protected]

www.iol.unh.edu
#68 lore raw
In reply to Lincoln Lavoie
Quoted 6 lines · Lincoln Lavoie

Hi All,

Trying to follow the specific conversation.  It is correct, the lab does not list the specific throughput values achieved by the hardware, as that data can be sensitive to the hardware vendors, etc. The purpose of the lab is to check for degradations caused by patches, so the difference is really the important factor.  The comparison is against a prior run on the same hardware, via the DPDK main branch, so any delta should be caused by the specific patch changes (excluding statistical "wiggle").

If the group would prefer, we could calculate additional references if desired (i.e. difference from the last official release, or a monthly run of the current, etc.).  We just need the community to define their needs, and we can add this to the development queue.

Hi Brandon,

Can you also put above to the backlog, to display the performance difference to the a fixed point, like a previous release or a previous LTS?

Thanks,
ferruh

Quoted 66 lines

Cheers,
Lincoln

On Thu, Jan 21, 2021 at 4:29 AM Morten Brørup <[email protected] <mailto:[email protected]>> wrote:

> From: dev [mailto:[email protected] <mailto:[email protected]>] On
Behalf Of Ferruh Yigit
> Sent: Thursday, January 21, 2021 10:19 AM
>
> On 1/15/2021 6:39 PM, Ali Alnubani wrote:
> > Hi,
> > Adding Ferruh and Zhaoyan,
> >
> >> Ali,
> >>
> >> You reported some performance regression, did you confirm it? > >> If I get no reply by monday, I'll proceed with this patch. > >
> > Sure I'll confirm by Monday.
> >
> > Doesn't the regression also reproduce on the Lab's Intel servers? > > Even though the check iol-intel-Performance isn't failing, I can see > that the throughput differences from expected for this patch are less > than those of another patch that was tested only 20 minutes earlier. > Both patches were applied to the same tree:
> >
> > https://mails.dpdk.org/archives/test-report/2021-January/173927.html
<https://mails.dpdk.org/archives/test-report/2021-January/173927.html>
> >> | 64         | 512     | 1.571                               | > >
> > https://mails.dpdk.org/archives/test-report/2021-January/173919.html
<https://mails.dpdk.org/archives/test-report/2021-January/173919.html>
> >> | 64         | 512     | 2.698                               | > >
> > Assuming that pw86457 doesn't have an effect on this test, it looks > to me that this patch caused a regression in Intel hardware as well. > >
> > Can someone update the baseline's expected values for the Intel NICs > and rerun the test on this patch?
> >
>
> Zhaoyan said that the baseline is calculated dynamically,
> what I understand is baseline set based on previous days performance > result, so
> it shouldn't require updating.

That sounds smart!

Perhaps another reference baseline could be added, for informational purposes only:
Deviation from the performance of the last official release.

>
> But cc'ed the lab for more details.

Signature · 7 lines
*Lincoln Lavoie*
Senior Engineer, Broadband Technologies
21 Madbury Rd., Ste. 100, Durham, NH 03824
[email protected] <mailto:[email protected]>
https://www.iol.unh.edu <https://www.iol.unh.edu>
+1-603-674-2755 (m)
<https://www.iol.unh.edu>
#69 lore raw
In reply to Olivier Matz
Quoted 2 lines

From: dev [mailto:[email protected]] On Behalf Of Olivier Matz
Sent: Wednesday, 13 January 2021 14.28

[snip]

Quoted 26 lines
Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

---

v4
* add a unit test (suggested by David)

v3
* fix commit log again (thanks Morten for spotting it)

v2
* avoid write access if uneeded (suggested by Konstantin)
* enhance comments in mbuf header file (suggested by Morten)
* fix commit log

 app/test/test_mbuf.c            | 69 +++++++++++++++++++++++++++++++++
 lib/librte_mbuf/rte_mbuf.c      |  4 +-
 lib/librte_mbuf/rte_mbuf.h      |  8 ++--
 lib/librte_mbuf/rte_mbuf_core.h | 13 ++++++-
 4 files changed, 86 insertions(+), 8 deletions(-)

[snip]

Quoted 38 lines
lib/librte_mbuf/rte_mbuf.c +2 -2
index 7d09ee2939..5f77840557 100644
@@ -129,10 +129,10 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void
 *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
+	if (m->next != NULL)
 		m->next = NULL;
+	if (m->nb_segs != 1)
 		m->nb_segs = 1;
-	}
 	rte_mbuf_raw_free(m);
 }
lib/librte_mbuf/rte_mbuf.h +2 -2
index c4c9ebfaa0..8c1097ed76 100644
@@ -1340,10 +1340,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 
 		return m;
 
@@ -1357,10 +1357,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}

lib/librte_mbuf/rte_mbuf.h rte_pktmbuf_prefree_seg(struct rte_mbuf *m) · line 1366

Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +2 -2
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;

Olivier, have you considered if Konstantin's suggestion (to avoid write access if unneeded) could be applied to any of the other functions in rte_mbuf.h, e.g. __rte_pktmbuf_free_direct()?

#70 lore raw

PATCH v5 1/1 mbuf: fix reset on mbuf free

In reply to Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 app/test/test_mbuf.c     | 69 ++++++++++++++++++++++++++++++++++++++++
 lib/mbuf/rte_mbuf.c      |  4 +--
 lib/mbuf/rte_mbuf.h      |  8 ++---
 lib/mbuf/rte_mbuf_core.h | 13 ++++++--
 4 files changed, 86 insertions(+), 8 deletions(-)
app/test/test_mbuf.c +69 -0
index 9a248dfaea..a4e32e933a 100644
@@ -2684,6 +2684,70 @@ test_mbuf_dyn(struct rte_mempool *pktmbuf_pool)
 	return -1;
 }
 
+/* check that m->nb_segs and m->next are reset on mbuf free */
+static int
+test_nb_segs_and_next_reset(void)
+{
+	struct rte_mbuf *m0 = NULL, *m1 = NULL, *m2 = NULL;
+	struct rte_mempool *pool = NULL;
+
+	pool = rte_pktmbuf_pool_create("test_mbuf_reset",
+			3, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
+	if (pool == NULL)
+		GOTO_FAIL("Failed to create mbuf pool");
+
+	/* alloc mbufs */
+	m0 = rte_pktmbuf_alloc(pool);
+	m1 = rte_pktmbuf_alloc(pool);
+	m2 = rte_pktmbuf_alloc(pool);
+	if (m0 == NULL || m1 == NULL || m2 == NULL)
+		GOTO_FAIL("Failed to allocate mbuf");
+
+	/* append data in all of them */
+	if (rte_pktmbuf_append(m0, 500) == NULL ||
+			rte_pktmbuf_append(m1, 500) == NULL ||
+			rte_pktmbuf_append(m2, 500) == NULL)
+		GOTO_FAIL("Failed to append data in mbuf");
+
+	/* chain them in one mbuf m0 */
+	rte_pktmbuf_chain(m1, m2);
+	rte_pktmbuf_chain(m0, m1);
+	if (m0->nb_segs != 3 || m0->next != m1 || m1->next != m2 ||
+			m2->next != NULL) {
+		m1 = m2 = NULL;
+		GOTO_FAIL("Failed to chain mbufs");
+	}
+
+	/* split m0 chain in two, between m1 and m2 */
+	m0->nb_segs = 2;
+	m1->next = NULL;
+	m2->nb_segs = 1;
+
+	/* free the 2 mbuf chains m0 and m2  */
+	rte_pktmbuf_free(m0);
+	rte_pktmbuf_free(m2);
+
+	/* realloc the 3 mbufs */
+	m0 = rte_mbuf_raw_alloc(pool);
+	m1 = rte_mbuf_raw_alloc(pool);
+	m2 = rte_mbuf_raw_alloc(pool);
+	if (m0 == NULL || m1 == NULL || m2 == NULL)
+		GOTO_FAIL("Failed to reallocate mbuf");
+
+	/* ensure that m->next and m->nb_segs are reset allocated mbufs */
+	if (m0->nb_segs != 1 || m0->next != NULL ||
+			m1->nb_segs != 1 || m1->next != NULL ||
+			m2->nb_segs != 1 || m2->next != NULL)
+		GOTO_FAIL("nb_segs or next was not reset properly");
+
+	return 0;
+
+fail:
+	if (pool != NULL)
+		rte_mempool_free(pool);
+	return -1;
+}
+
 static int
 test_mbuf(void)
 {
@@ -2874,6 +2938,11 @@ test_mbuf(void)
 		goto err;
 	}
 
+	/* test reset of m->nb_segs and m->next on mbuf free */
+	if (test_nb_segs_and_next_reset() < 0) {
+		printf("test_nb_segs_and_next_reset() failed\n");
+		goto err;
+	}
 
 	ret = 0;
 err:
lib/mbuf/rte_mbuf.c +2 -2
index f7e3c1a187..f145cd800a 100644
@@ -134,10 +134,10 @@ rte_pktmbuf_free_pinned_extmem(void *addr, void *opaque)
 
 	rte_mbuf_ext_refcnt_set(m->shinfo, 1);
 	m->ol_flags = EXT_ATTACHED_MBUF;
-	if (m->next != NULL) {
+	if (m->next != NULL)
 		m->next = NULL;
+	if (m->nb_segs != 1)
 		m->nb_segs = 1;
-	}
 	rte_mbuf_raw_free(m);
 }
 
lib/mbuf/rte_mbuf.h +4 -4
index a555f216ae..dded3dd70c 100644
@@ -1346,10 +1346,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 
 		return m;
 
@@ -1363,10 +1363,10 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 				return NULL;
 		}
 
-		if (m->next != NULL) {
+		if (m->next != NULL)
 			m->next = NULL;
+		if (m->nb_segs != 1)
 			m->nb_segs = 1;
-		}
 		rte_mbuf_refcnt_set(m, 1);
 
 		return m;
lib/mbuf/rte_mbuf_core.h +11 -2
index 9d8e3ddc86..9ef807daaa 100644
@@ -508,7 +508,12 @@ struct rte_mbuf {
 	 * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
 	 */
 	uint16_t refcnt;
-	uint16_t nb_segs;         /**< Number of segments. */
+
+	/**
+	 * Number of segments. Only valid for the first segment of an mbuf
+	 * chain.
+	 */
+	uint16_t nb_segs;
 
 	/** Input port (16 bits to support more than 256 virtual ports).
 	 * The event eth Tx adapter uses this field to specify the output port.
@@ -604,7 +609,11 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
+	/**
+	 * Next segment of scattered packet. Must be NULL in the last segment or
+	 * in case of non-segmented packet.
+	 */
+	struct rte_mbuf *next;
 
 	/* fields to support TX offloads */
 	RTE_STD_C11
Signature · 1 line
2.30.2
Tested-by on v5 1/1
#71 lore raw
Quoted 40 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Thursday, September 30, 2021 12:37 AM
To: [email protected]
Cc: [email protected]; [email protected]; Ali Alnubani <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Slava Ovsiienko <[email protected]>
Subject: [PATCH v5] mbuf: fix reset on mbuf free

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Quoted 8 lines
Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

---

Tested-by Ali Alnubani on v5 1/1 Applied
#72 lore raw
In reply to Olivier Matz
Quoted 32 lines · Olivier Matz

m->nb_seg must be reset on mbuf free whatever the value of m->next, because it can happen that m->nb_seg is != 1. For instance in this case:

  m1 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m1, 500);
  m2 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m2, 500);
  rte_pktmbuf_chain(m1, m2);
  m0 = rte_pktmbuf_alloc(mp);
  rte_pktmbuf_append(m0, 500);
  rte_pktmbuf_chain(m0, m1);

As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 segment (this is not required), after this code the mbuf chain have 3 segments:
- m0: next=m1, nb_seg=3
- m1: next=m2, nb_seg=2
- m2: next=NULL, nb_seg=1

Then split this chain between m1 and m2, it would result in 2 packets:
- first packet
- m0: next=m1, nb_seg=2
- m1: next=NULL, nb_seg=2
- second packet
- m2: next=NULL, nb_seg=1

Freeing the first packet will not restore nb_seg=1 in the second segment. This is an issue because it is expected that mbufs stored in pool have their nb_seg field set to 1.

Quoted 7 lines
Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

Applied, thanks.

Signature · 1 line
David Marchand
#73 lore raw

CI performance test results might be misleading

I know it's too late for this patch [1], but I am afraid it was performance tested using test-pmd with RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE [2], so the test didn't involve the function fixed by this patch: rte_pktmbuf_prefree_seg().

If so, the performance test results were completely irrelevant. The same goes for other patches related to code bypassed by RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE.

RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE is a performance optimization with many application limitations, and should not be enabled for performance testing in the CI environment. Alternatively, performance testing can be performed both with and without this optimization.

[1] https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
[2] http://git.dpdk.org/dpdk/commit/app/test-pmd/testpmd.c?id=07e5f7bd65718461e4c63757248b9c7bab08341f