mbuf: add bulk free function
v2 cover mbuf: add bulk free function
Add function for freeing a bulk of mbufs.
v2:
* Function is not inline.
* Optimized to free multible mbufs belonging to the same mempool in bulk. Inspired by ixgbe_tx_free_bufs(), but allowing NULL pointers in the array, just like rte_pktmbuf_free() can take a NULL pointer.
* Use unsigned int instead of unsigned. Passes checkpatch, but mismatches the original coding style of the modified files.
* Fixed a typo in the description headline: mempools is plural.
Morten Brørup (2):
mbuf: add bulk free function
mbuf: add bulk free function
lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 11 +++++++++++ 2 files changed, 46 insertions(+)
Signature · 1 line
2.17.1
PATCH v2 1/2 mbuf: add bulk free function
Add function for freeing a bulk of mbufs.
--- lib/librte_mbuf/rte_mbuf.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
lib/librte_mbuf/rte_mbuf.h +17 -0
@@ -1907,6 +1907,23 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) } } +/** +* Free a bulk of mbufs back into their original mempool. +* +* @param mbufs +* Array of pointers to mbufs +* @param count +* Array size +*/ +static inline void +rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned count) +{ +unsigned idx =0 ; + +for (idx =0 ; idx < count; idx++) +rte_pktmbuf_free (mbufs[idx]); +} +/** * Creates a "clone" of the given packet mbuf. *
Signature · 1 line
2.17.1
PATCH v2 2/2 mbuf: add bulk free function
In reply to Morten BrørupAdd function for freeing a bulk of mbufs.
--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)
lib/librte_mbuf/rte_mbuf.c +35 -0
@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{ +struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 ); + m =rte_pktmbuf_prefree_seg (m); +if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) { +rte_mempool_put_bulk (free[0 ]->pool, + (void **)free, nb_free); + nb_free =0 ; + } + + free[nb_free++] = m; + } + +if (nb_free >0 ) +rte_mempool_put_bulk (free[0 ]->pool, (void **)free, nb_free); +} +/* dump a mbuf on console */ void rte_pktmbuf_dump (FILE *f,const struct rte_mbuf *m,unsigned dump_len)
lib/librte_mbuf/rte_mbuf.h +5 -11
@@ -1908,21 +1908,15 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) }/** -* Free a bulk of mbufs back into their original mempool. +* Free a bulk of mbufs back into their original mempools. * * @param mbufs -* Array of pointers to mbufs +* Array of pointers to mbufs. +* The array may contain NULL pointers. * @param count -* Array size +* Array size. */ -static inline void -rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned count) -{ -unsigned idx =0 ; - -for (idx =0 ; idx < count; idx++) -rte_pktmbuf_free (mbufs[idx]); -} +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count);/** * Creates a "clone" of the given packet mbuf.
Signature · 1 line
2.17.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [dpdk-dev] |WARNING| pw59738 [PATCH v2 2/2] mbuf: add bulk free function
Dear Thomas - listed as checkpatch maintainer,
I think this warning is bogus, and is a bug checkpatch.
The line in question was deliberately indented using tabs to the current indentation level, and using spaces for the readability alignment. This makes the code readable in editors with another tab setting than 8 spaces. E.g. 4 spaces is my personal preference.
Med venlig hilsen / kind regards
- Morten Brørup
Quoted 19 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, September 25, 2019 2:06 PM
To: [email protected]
Cc: Morten Brørup
Subject: |WARNING| pw59738 [PATCH v2 2/2] mbuf: add bulk free functionTest-Label: checkpatch
Test-Status: WARNING
http://dpdk.org/patch/59738
_codingstyleissues_ERROR:CODE_INDENT: code indent should use tabs where possible #59: FILE:
lib/librte_mbuf/rte_mbuf.c:272:
+^I^I^I (void **)free, nb_free);$total: 1 errors, 0 warnings, 67 lines checked
Re: [dpdk-dev] |WARNING| pw59738 [PATCH v2 2/2] mbuf: add bulk free function
Quoted 9 lines · On Wed, 25 Sep 2019 14:17:42 +0200 Morten Brørup <[email protected]>…
Dear Thomas - listed as checkpatch maintainer,
I think this warning is bogus, and is a bug checkpatch.
The line in question was deliberately indented using tabs to the current indentation level, and using spaces for the readability alignment. This makes the code readable in editors with another tab setting than 8 spaces. E.g. 4 spaces is my personal preference.
Med venlig hilsen / kind regards
- Morten Brørup
It is understandable that you have personal preferences, but projects like DPDK rely on common style across all code. The collective decision has been made to keep a uniform style similar to the Linux kernel.
No it is not a bug in checkpatch.
Re: [dpdk-dev] |WARNING| pw59738 [PATCH v2 2/2] mbuf: add bulk free function
Quoted 20 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Thursday, September 26, 2019 1:37 AMQuoted 5 lines · On Wed, 25 Sep 2019 14:17:42 +0200 Morten Brørup <[email protected]>…
Dear Thomas - listed as checkpatch maintainer,
I think this warning is bogus, and is a bug checkpatch.
The line in question was deliberately indented using tabs to the
current indentation level, and using spaces for the readability alignment. This makes the code readable in editors with another tab setting than 8 spaces. E.g. 4 spaces is my personal preference.
Quoted 4 lines
Med venlig hilsen / kind regards
- Morten Brørup
Quoted 7 lines
It is understandable that you have personal preferences, but projects like DPDK rely
on common style across all code. The collective decision has been made to keep a
uniform style similar to the Linux kernel.No it is not a bug in checkpatch.
Thank you for the prompt feedback, Stephen.
I thought I could get the best of both worlds with this method of indentation. But since it's against the style guide, I'll change it to comply.
Med venlig hilsen / kind regards
- Morten Brørup
Quoted 29 lines · Morten Brørup
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +13
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{ +struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx];
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 270
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.c +10
-0+if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 ); + m =rte_pktmbuf_prefree_seg (m); +if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) {
Maybe an unlikely() would be in order here?
Quoted 47 lines
lib/librte_mbuf/rte_mbuf.c +12
-0+rte_mempool_put_bulk (free[0 ]->pool, + (void **)free, nb_free); + nb_free =0 ; + } + + free[nb_free++] = m; + } + +if (nb_free >0 ) +rte_mempool_put_bulk (free[0 ]->pool, (void **)free, nb_free); +} +/* dump a mbuf on console */ void rte_pktmbuf_dump (FILE *f,const struct rte_mbuf *m,unsigned dump_len)lib/librte_mbuf/rte_mbuf.h +5
-11@@ -1908,21 +1908,15 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) }/** -* Free a bulk of mbufs back into their original mempool. +* Free a bulk of mbufs back into their original mempools. * * @param mbufs -* Array of pointers to mbufs +* Array of pointers to mbufs. +* The array may contain NULL pointers. * @param count -* Array size +* Array size. */ -static inline void -rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned count) -{ -unsigned idx =0 ; - -for (idx =0 ; idx < count; idx++) -rte_pktmbuf_free (mbufs[idx]); -} +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count);/** * Creates a "clone" of the given packet mbuf.
Quoted 33 lines · Mattias Rönnblom
Quoted 32 lines · Morten Brørup
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +17
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{ +struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 );
Quoted 9 lines
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 270
Quoted 6 lines
lib/librte_mbuf/rte_mbuf.c +6
-0+ m =rte_pktmbuf_prefree_seg (m); +if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) {Maybe an
unlikely()would be in order here?
I'd caution against it, since it can penalize the cold branch a lot. If a branch really is predictable the HW branch predictors generally are good enough to handle it at runtime. So long as a path is a valid path for a runtime app, i.e. not something like a fatal error only ever hit once in an entire run, I'd tend to omit likely()/unlikely() calls unless profiling shows a real performance difference.
/Bruce
Quoted 43 lines · Bruce Richardson
Quoted 33 lines · Mattias Rönnblom
Quoted 32 lines · Morten Brørup
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +17
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{ +struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 );Quoted 9 lines
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 270
Quoted 6 lines
lib/librte_mbuf/rte_mbuf.c +6
-0+ m =rte_pktmbuf_prefree_seg (m); +if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) {Maybe an
unlikely()would be in order here?
Quoted 7 lines
I'd caution against it, since it can penalize the cold branch a lot. If a branch really is predictable the HW branch predictors generally are good enough to handle it at runtime. So long as a path is a valid path for a runtime app, i.e. not something like a fatal error only ever hit once in an entire run, I'd tend to omit likely()/unlikely() calls unless profiling shows a real performance difference.
Let's see if I understand you: your worry is that wrapping that expression in an unlikely() will lead to code that is slower (than w/o the hint), if during runtime the probability turns out to be 50/50?
Wouldn't leaving out unlikely() just lead to the compiler using its fancy heuristics in an attempt to come to a conclusion, what path is the more likely?
About HW branch prediction - I'm sure it's good, but still the compiler needs to decided which code code path requires a branch, and which need not. Even if HW branch prediction successfully predicted a branch being taken, actually branching is going to be somewhat more expensive than to not branch?
Quoted 52 lines · Mattias Rönnblom
Quoted 43 lines · Bruce Richardson
Quoted 33 lines · Mattias Rönnblom
Quoted 32 lines · Morten Brørup
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +17
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{ +struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 );Quoted 9 lines
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 270
Quoted 6 lines
lib/librte_mbuf/rte_mbuf.c +6
-0+ m =rte_pktmbuf_prefree_seg (m); +if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) {Maybe an
unlikely()would be in order here?Quoted 7 lines
I'd caution against it, since it can penalize the cold branch a lot. If a branch really is predictable the HW branch predictors generally are good enough to handle it at runtime. So long as a path is a valid path for a runtime app, i.e. not something like a fatal error only ever hit once in an entire run, I'd tend to omit likely()/unlikely() calls unless profiling shows a real performance difference.
Quoted 4 lines
Let's see if I understand you: your worry is that wrapping that expression in an
unlikely()will lead to code that is slower (than w/o the hint), if during runtime the probability turns out to be 50/50?
While not an expert, I believe that the use of likely/unlikely can cause the unexpected part of the branch to be moved to a different part of the code and potentially be more expensive to call, meaning that the performance may be poorer even if the probability is lower than 50/50.
Quoted 9 lines
Wouldn't leaving out
unlikely()just lead to the compiler using its fancy heuristics in an attempt to come to a conclusion, what path is the more likely?About HW branch prediction - I'm sure it's good, but still the compiler needs to decided which code code path requires a branch, and which need not. Even if HW branch prediction successfully predicted a branch being taken, actually branching is going to be somewhat more expensive than to not branch?
The cost difference between a taken and untaken branch should be unnoticable so long as the branch is correctly predicted - which if does always go one way, it will be each time each time after the first. Overall, though, I suspect the presence of likely/unlikely is going to make any real difference, so I'd therefore err on the side of leaving it out in the absense of evidence that it helps in some cases.
/Bruce
Quoted 24 lines · Morten Brørup
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +8
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 265
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.c +10
-0+struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 ); + m =rte_pktmbuf_prefree_seg (m);
Who cares about next segments if any? It looks like nobody.
Quoted 41 lines
lib/librte_mbuf/rte_mbuf.c +17
-0+if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) { +rte_mempool_put_bulk (free[0 ]->pool, + (void **)free, nb_free); + nb_free =0 ; + } + + free[nb_free++] = m; + } + +if (nb_free >0 ) +rte_mempool_put_bulk (free[0 ]->pool, (void **)free, nb_free); +} +/* dump a mbuf on console */ void rte_pktmbuf_dump (FILE *f,const struct rte_mbuf *m,unsigned dump_len)lib/librte_mbuf/rte_mbuf.h +4
-5@@ -1908,21 +1908,15 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) }/** -* Free a bulk of mbufs back into their original mempool. +* Free a bulk of mbufs back into their original mempools. * * @param mbufs -* Array of pointers to mbufs +* Array of pointers to mbufs. +* The array may contain NULL pointers. * @param count -* Array size +* Array size. */ -static inline void -rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned count)
lib/librte_mbuf/rte_mbuf.h static inline void rte_pktmbuf_free(struct rte_mbuf *m) · line 1922
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +1
-6-{ -unsigned idx =0 ; - -for (idx =0 ; idx < count; idx++) -rte_pktmbuf_free (mbufs[idx]); -} +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count);/** * Creates a "clone" of the given packet mbuf.
Is it just a mistake that two patches are not squashed?
Quoted 98 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Andrew Rybchenko
Sent: Thursday, September 26, 2019 11:27 AM
To: Morten Brørup; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 2/2] mbuf: add bulk free functionlib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int
Quoted 13 lines · Morten Brørup
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +0
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int
is_header,Quoted 11 lines
lib/librte_mbuf/rte_mbuf.c +8
-0return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count) +{lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 265
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.c +10
-0+struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 ); + m =rte_pktmbuf_prefree_seg (m);Who cares about next segments if any? It looks like nobody.
lib/librte_mbuf/rte_mbuf.h static inline void rte_pktmbuf_free(struct
Quoted 25 lines
lib/librte_mbuf/rte_mbuf.c +17
-0+if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) { +rte_mempool_put_bulk (free[0 ]->pool, + (void **)free, nb_free); + nb_free =0 ; + } + + free[nb_free++] = m; + } + +if (nb_free >0 ) +rte_mempool_put_bulk (free[0 ]->pool, (void **)free, nb_free); +} +/* dump a mbuf on console */ void rte_pktmbuf_dump (FILE *f,const struct rte_mbuf *m,unsigned dump_len)lib/librte_mbuf/rte_mbuf.h +0
-0@@ -1908,21 +1908,15 @@ static inline void rte_pktmbuf_free(struct
rte_mbuf*m)Quoted 24 lines
lib/librte_mbuf/rte_mbuf.h +5
-11}/** -* Free a bulk of mbufs back into their original mempool. +* Free a bulk of mbufs back into their original mempools. * * @param mbufs -* Array of pointers to mbufs +* Array of pointers to mbufs. +* The array may contain NULL pointers. * @param count -* Array size +* Array size. */ -static inline void -rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned count) -{ -unsigned idx =0 ; - -for (idx =0 ; idx < count; idx++) -rte_pktmbuf_free (mbufs[idx]); -} +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count);
Quoted 5 lines
lib/librte_mbuf/rte_mbuf.h static inline void rte_pktmbuf_free(struct rte_mbuf *m) · line 1922
Quoted 2 lines
lib/librte_mbuf/rte_mbuf.h +0
-0/** * Creates a "clone" of the given packet mbuf. Is it just a mistake that two patches are not squashed?
Yes. Plenty of rookie git mistakes by my hand.
We don't use git in-house, and I have no git experience. So I'm trying my best, relying on the DPDK Contributor guide and git documentation. :-)
Med venlig hilsen / kind regards
- Morten Brørup
Hi Morten,
Quoted 14 lines
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +0
-0
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header, · line 254
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.c +7
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header,return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count)
As I can see you forgot to handle situation with multi-segs packet. This one is still I a good one to have, I think.
But probably it should be named rte_pktmbuf_free_seg_bulk() to avoid any confusion.
Konstantin
Quoted 64 lines
lib/librte_mbuf/rte_mbuf.c +28
-0+{ +struct rte_mbuf *m, *free[RTE_PKTMBUF_FREE_BULK_SZ ]; +unsigned int idx, nb_free =0 ; + +for (idx =0 ; idx < count; idx++) { + m = mbufs[idx]; +if (unlikely (m ==NULL )) +continue ; + +__rte_mbuf_sanity_check (m,1 ); + m =rte_pktmbuf_prefree_seg (m); +if (unlikely (m ==NULL )) +continue ; + +if (nb_free >=RTE_PKTMBUF_FREE_BULK_SZ || + (nb_free >0 && m->pool != free[0 ]->pool)) { +rte_mempool_put_bulk (free[0 ]->pool, + (void **)free, nb_free); + nb_free =0 ; + } + + free[nb_free++] = m; + } + +if (nb_free >0 ) +rte_mempool_put_bulk (free[0 ]->pool, (void **)free, nb_free); +} +/* dump a mbuf on console */ void rte_pktmbuf_dump (FILE *f,const struct rte_mbuf *m,unsigned dump_len)lib/librte_mbuf/rte_mbuf.h +5
-12@@ -1908,21 +1908,15 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) }/** -* Free a bulk of mbufs back into their original mempool. +* Free a bulk of mbufs back into their original mempools. * * @param mbufs -* Array of pointers to mbufs +* Array of pointers to mbufs. +* The array may contain NULL pointers. * @param count -* Array size +* Array size. */ -static inline void -rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned count) -{ -unsigned idx =0 ; - -for (idx =0 ; idx < count; idx++) -rte_pktmbuf_free (mbufs[idx]); -} +void rte_pktmbuf_free_bulk (struct rte_mbuf **mbufs,unsigned int count);/** * Creates a "clone" of the given packet mbuf. -- 2.17.1
Quoted 35 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ananyev, Konstantin
Sent: Thursday, September 26, 2019 12:23 PMHi Morten,
lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int
Quoted 14 lines
Add function for freeing a bulk of mbufs.
Signed-off-by Morten Brørup <[email protected]>--- lib/librte_mbuf/rte_mbuf.c | 35 +++++++++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 16 +++++----------- 2 files changed, 40 insertions(+), 11 deletions(-)lib/librte_mbuf/rte_mbuf.c +0
-0@@ -245,6 +245,41 @@ int rte_mbuf_check(const struct rte_mbuf *m, int
is_header,lib/librte_mbuf/rte_mbuf.c int rte_mbuf_check(const struct rte_mbuf *m, int is_header,
Quoted 10 lines
lib/librte_mbuf/rte_mbuf.c +7
-0return 0 ; } +/** +* Maximum bulk of mbufs rte_pktmbuf_free_bulk() returns to mempool. +*/ +#define RTE_PKTMBUF_FREE_BULK_SZ 64 + +/* Free a bulk of mbufs back into their original mempools. */ +void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned intcount)
Quoted 6 lines
As I can see you forgot to handle situation with multi-segs packet. This one is still I a good one to have, I think.
But probably it should be namedrte_pktmbuf_free_seg_bulk()to avoid any confusion.
Konstantin
Thanks for spotting this bug, Konstantin! I have submitted an updated patch.
I get your point about having two separate functions, and as you can see from my patch, they turned out quite different.
However, am not sure where the rte_pktmbuf_free_seg_bulk() would be used. And I don't think we should add functions to the mbuf library unless we have at least one viable use case.
E.g. refer the ixgbe driver that kicked off the modification to use rte_mempool_put_bulk() instead of a simple loop around rte_pktmbuf_free(). The driver is not using an array of mbufs; it is using an array of its own structure, with one the fields pointing to an mbuf.
Med venlig hilsen / kind regards
- Morten Brørup