From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Nicolas Chautru <nicolas.chautru@intel.com>,
Akhil Goyal <gakhil@marvell.com>,
Fan Zhang <fanzhang.oss@gmail.com>,
Anatoly Burakov <anatoly.burakov@intel.com>,
Jingjing Wu <jingjing.wu@intel.com>,
Volodymyr Fialko <vfialko@marvell.com>,
Yipeng Wang <yipeng1.wang@intel.com>,
Maxime Coquelin <maxime.coquelin@redhat.com>,
Chenbo Xia <chenbox@nvidia.com>
Subject: [PATCH 20/20] examples: use rte_pktmbuf_free_bulk
Date: Fri, 8 May 2026 13:33:41 -0700 [thread overview]
Message-ID: <20260508203607.1003036-21-stephen@networkplumber.org> (raw)
In-Reply-To: <20260508203607.1003036-1-stephen@networkplumber.org>
Replace open-coded loop with rte_pktmbuf_free_bulk().
Generated by devtools/cocci/free_bulk.cocci.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
examples/bbdev_app/main.c | 4 +---
examples/l2fwd-crypto/main.c | 4 ++--
.../client_server_mp/mp_client/client.c | 7 +++----
.../multi_process/client_server_mp/mp_server/main.c | 5 ++---
examples/ntb/ntb_fwd.c | 12 +++++-------
examples/packet_ordering/main.c | 5 +----
examples/server_node_efd/efd_node/node.c | 7 +++----
examples/server_node_efd/efd_server/main.c | 5 ++---
examples/vhost/main.c | 3 +--
9 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/examples/bbdev_app/main.c b/examples/bbdev_app/main.c
index 03f15f91cc..4602f8012d 100644
--- a/examples/bbdev_app/main.c
+++ b/examples/bbdev_app/main.c
@@ -291,9 +291,7 @@ print_mac(unsigned int portid, struct rte_ether_addr *bbdev_ports_eth_address)
static inline void
pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
{
- unsigned int i;
- for (i = 0; i < nb_to_free; ++i)
- rte_pktmbuf_free(mbufs[i]);
+ rte_pktmbuf_free_bulk(mbufs, nb_to_free);
}
static inline void
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index a441312f55..3b2c23f29a 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -931,8 +931,8 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
RTE_CRYPTO_OP_TYPE_SYMMETRIC,
ops_burst, nb_rx) !=
nb_rx) {
- for (j = 0; j < nb_rx; j++)
- rte_pktmbuf_free(pkts_burst[j]);
+ rte_pktmbuf_free_bulk(pkts_burst,
+ nb_rx);
nb_rx = 0;
}
diff --git a/examples/multi_process/client_server_mp/mp_client/client.c b/examples/multi_process/client_server_mp/mp_client/client.c
index 087c38ef73..9353ab7fda 100644
--- a/examples/multi_process/client_server_mp/mp_client/client.c
+++ b/examples/multi_process/client_server_mp/mp_client/client.c
@@ -117,15 +117,14 @@ parse_app_args(int argc, char *argv[])
*/
static void
flush_tx_error_callback(struct rte_mbuf **unsent, uint16_t count,
- void *userdata) {
- int i;
+ void *userdata)
+{
uint16_t port_id = (uintptr_t)userdata;
tx_stats->tx_drop[port_id] += count;
/* free the mbufs which failed from transmit */
- for (i = 0; i < count; i++)
- rte_pktmbuf_free(unsent[i]);
+ rte_pktmbuf_free_bulk(unsent, count);
}
diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c
index 691d453d0e..aa8b759aca 100644
--- a/examples/multi_process/client_server_mp/mp_server/main.c
+++ b/examples/multi_process/client_server_mp/mp_server/main.c
@@ -195,7 +195,6 @@ clear_stats(void)
static void
flush_rx_queue(uint16_t client)
{
- uint16_t j;
struct client *cl;
if (cl_rx_buf[client].count == 0)
@@ -204,8 +203,8 @@ flush_rx_queue(uint16_t client)
cl = &clients[client];
if (rte_ring_enqueue_bulk(cl->rx_q, (void **)cl_rx_buf[client].buffer,
cl_rx_buf[client].count, NULL) == 0){
- for (j = 0; j < cl_rx_buf[client].count; j++)
- rte_pktmbuf_free(cl_rx_buf[client].buffer[j]);
+ rte_pktmbuf_free_bulk(cl_rx_buf[client].buffer,
+ cl_rx_buf[client].count);
cl->stats.rx_drop += cl_rx_buf[client].count;
}
else
diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c
index 33f3c1ef17..fe2b1e6b2b 100644
--- a/examples/ntb/ntb_fwd.c
+++ b/examples/ntb/ntb_fwd.c
@@ -253,8 +253,7 @@ cmd_send_parsed(void *parsed_result,
(void *)queue_id);
if (ret < 0) {
printf("Enqueue failed with err %d\n", ret);
- for (j = 0; j < nb_pkt; j++)
- rte_pktmbuf_free(mbuf_send[j]);
+ rte_pktmbuf_free_bulk(mbuf_send, nb_pkt);
goto clean;
}
nb_tx = ret;
@@ -387,8 +386,8 @@ start_iofwd_per_lcore(void *param)
if (ret < 0) {
printf("Enqueue failed with err %d\n",
ret);
- for (j = 0; j < nb_rx; j++)
- rte_pktmbuf_free(pkts_burst[j]);
+ rte_pktmbuf_free_bulk(pkts_burst,
+ nb_rx);
goto clean;
}
nb_tx = ret;
@@ -476,7 +475,7 @@ start_txonly_per_lcore(void *param)
struct ntb_fwd_lcore_conf *conf = param;
struct ntb_fwd_stream fs;
uint16_t nb_pkt, nb_tx;
- int i, j, ret;
+ int i, ret;
for (i = 0; i < NTB_MAX_PKT_BURST; i++)
ntb_buf[i] = (struct rte_rawdev_buf *)
@@ -517,8 +516,7 @@ start_txonly_per_lcore(void *param)
nb_pkt, (void *)(size_t)fs.qp_id);
if (ret < 0) {
printf("Enqueue failed with err %d\n", ret);
- for (j = 0; j < nb_pkt; j++)
- rte_pktmbuf_free(pkts_burst[j]);
+ rte_pktmbuf_free_bulk(pkts_burst, nb_pkt);
goto clean;
}
nb_tx = ret;
diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c
index 748fe0826a..f2097a90d4 100644
--- a/examples/packet_ordering/main.c
+++ b/examples/packet_ordering/main.c
@@ -128,10 +128,7 @@ get_previous_lcore_id(unsigned int id)
static inline void
pktmbuf_free_bulk(struct rte_mbuf *mbuf_table[], unsigned n)
{
- unsigned int i;
-
- for (i = 0; i < n; i++)
- rte_pktmbuf_free(mbuf_table[i]);
+ rte_pktmbuf_free_bulk(mbuf_table, n);
}
/* display usage */
diff --git a/examples/server_node_efd/efd_node/node.c b/examples/server_node_efd/efd_node/node.c
index fc2aa5ffef..5805e049b2 100644
--- a/examples/server_node_efd/efd_node/node.c
+++ b/examples/server_node_efd/efd_node/node.c
@@ -121,15 +121,14 @@ parse_app_args(int argc, char *argv[])
*/
static void
flush_tx_error_callback(struct rte_mbuf **unsent, uint16_t count,
- void *userdata) {
- int i;
+ void *userdata)
+{
uint16_t port_id = (uintptr_t)userdata;
tx_stats->tx_drop[port_id] += count;
/* free the mbufs which failed from transmit */
- for (i = 0; i < count; i++)
- rte_pktmbuf_free(unsent[i]);
+ rte_pktmbuf_free_bulk(unsent, count);
}
diff --git a/examples/server_node_efd/efd_server/main.c b/examples/server_node_efd/efd_server/main.c
index 70a7372d4a..384bcfa780 100644
--- a/examples/server_node_efd/efd_server/main.c
+++ b/examples/server_node_efd/efd_server/main.c
@@ -218,7 +218,6 @@ clear_stats(void)
static void
flush_rx_queue(uint16_t node)
{
- uint16_t j;
struct node *cl;
if (cl_rx_buf[node].count == 0)
@@ -227,8 +226,8 @@ flush_rx_queue(uint16_t node)
cl = &nodes[node];
if (rte_ring_enqueue_bulk(cl->rx_q, (void **)cl_rx_buf[node].buffer,
cl_rx_buf[node].count, NULL) != cl_rx_buf[node].count){
- for (j = 0; j < cl_rx_buf[node].count; j++)
- rte_pktmbuf_free(cl_rx_buf[node].buffer[j]);
+ rte_pktmbuf_free_bulk(cl_rx_buf[node].buffer,
+ cl_rx_buf[node].count);
cl->stats.rx_drop += cl_rx_buf[node].count;
} else
cl->stats.rx += cl_rx_buf[node].count;
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index ac888348d2..79561d6de0 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1006,8 +1006,7 @@ unlink_vmdq(struct vhost_dev *vdev)
(uint16_t)vdev->vmdq_rx_q, pkts_burst, MAX_PKT_BURST);
while (rx_count) {
- for (i = 0; i < rx_count; i++)
- rte_pktmbuf_free(pkts_burst[i]);
+ rte_pktmbuf_free_bulk(pkts_burst, rx_count);
rx_count = rte_eth_rx_burst(ports[0],
(uint16_t)vdev->vmdq_rx_q, pkts_burst, MAX_PKT_BURST);
--
2.53.0
prev parent reply other threads:[~2026-05-08 20:38 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 20:33 [PATCH 00/20] pktmbuf free bulk cleanups Stephen Hemminger
2026-05-08 20:33 ` [PATCH 01/20] devtools/cocci: add transform for rte_pktmbuf_free_bulk Stephen Hemminger
2026-05-08 20:33 ` [PATCH 02/20] eventdev: use rte_pktmbuf_free_bulk Stephen Hemminger
2026-05-08 20:33 ` [PATCH 03/20] gso: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 04/20] ip_frag: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 05/20] pipeline: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 06/20] port: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 07/20] net/af_xdp: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 08/20] net/cnxk: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 09/20] net/pfe: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 10/20] net/virtio: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 11/20] net/zxdh: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 12/20] app/compress-perf: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 13/20] mbuf: allow NULL array in rte_pktmbuf_free_bulk Stephen Hemminger
2026-05-09 8:47 ` Morten Brørup
2026-05-09 15:46 ` Stephen Hemminger
2026-05-10 12:31 ` Morten Brørup
2026-05-10 15:21 ` Stephen Hemminger
2026-05-08 20:33 ` [PATCH 14/20] net/zxdh: remove unnecessary null check Stephen Hemminger
2026-05-08 20:33 ` [PATCH 15/20] net/ice: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 16/20] net/bnxt: " Stephen Hemminger
2026-05-08 20:33 ` [PATCH 17/20] test: use rte_pktmbuf_free_bulk Stephen Hemminger
2026-05-08 20:33 ` [PATCH 18/20] app/test-dma-perf: remove unnecessary null check Stephen Hemminger
2026-05-11 1:16 ` fengchengwen
2026-05-08 20:33 ` [PATCH 19/20] app/test-compress-perf: " Stephen Hemminger
2026-05-08 20:33 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260508203607.1003036-21-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=anatoly.burakov@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=fanzhang.oss@gmail.com \
--cc=gakhil@marvell.com \
--cc=jingjing.wu@intel.com \
--cc=maxime.coquelin@redhat.com \
--cc=nicolas.chautru@intel.com \
--cc=vfialko@marvell.com \
--cc=yipeng1.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox