DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Nam Tran <hoangnamtran18122005@gmail.com>
Cc: "Morten Brørup" <mb@smartsharesystems.com>, dev@dpdk.org
Subject: Re: [PATCH] mbuf: avoid temporary array for bulk free
Date: Tue, 22 Sep 2026 06:54:37 -0700	[thread overview]
Message-ID: <20260922065437.2e3f5c15@phoenix.local> (raw)
In-Reply-To: <20260922012856.30090-1-hoangnamtran18122005@gmail.com>

On Mon, 21 Sep 2026 21:28:56 -0400
Nam Tran <hoangnamtran18122005@gmail.com> wrote:

> rte_pktmbuf_free_bulk() currently stages freeable mbufs in a
> temporary array before returning them to their mempool. For flat
> packet arrays, this requires copying pointers even though the
> original array already contains contiguous freeable mbufs.
> 
> Track contiguous same-pool runs in the input array and pass them
> directly to rte_mbuf_raw_free_bulk(). Flush a run when encountering
> a NULL mbuf, an mbuf retained by reference counting, or a pool
> change. Preserve the existing array-based implementation as the
> fallback for chained packets.
> 
> On an ARM64 Linux test environment, same-binary A/B measurements
> using rte_rdtsc showed lower median timer ticks per call for flat
> bulk frees:
> 
>   burst  32:  2.05 ->  1.50
>   burst  64:  5.16 ->  4.52
>   burst 128: 11.16 ->  6.90
>   burst 256: 26.46 -> 19.73
> 
> This corresponds to reductions of approximately 12% to 38% across
> the tested burst sizes.
> 
> Add coverage for NULL entries, mixed mempools, and shared mbufs.
> 
> Signed-off-by: Nam Tran <hoangnamtran18122005@gmail.com>
> ---

More detailed AI review (Claude Opus 5)

Subject: Re: [PATCH] mbuf: avoid temporary array for bulk free

Warning:

lib/mbuf/rte_mbuf.c: runs are unbounded. The old code flushed at
RTE_PKTMBUF_FREE_PENDING_SZ (64). Now a same-pool run can be the whole
burst, and rte_mempool_do_generic_put() sends any n > cache->size / 2
straight to rte_mempool_ops_enqueue_bulk(), bypassing the per-lcore
cache. With a 256 entry cache, a 256 burst that previously went into
the cache in 64 entry chunks now hits the ring every time. That is
cheap on a single lcore, which is what the benchmark measured, but is
shared ring traffic with multiple lcores, and hands back cold objects
instead of keeping hot ones in cache. Cap run_count at
RTE_PKTMBUF_FREE_PENDING_SZ and flush when reached.

Benchmark: rte_rdtsc() on arm64 reads the generic timer (cntvct_el0)
unless built with PMU support; a delta of ~0.5 ticks per call is at
the resolution limit. Please state the timer frequency, the mempool
cache size used, the number of lcores, and include x86 results. The
test pools in test_mbuf.c have no cache, so they do not exercise the
cache path at all.

Info:

The flush sequence is open coded four times, and
rte_mbuf_raw_free_bulk() is __rte_always_inline, so the function body
grows accordingly. A small static helper or restructuring the loop so
NULL, not-freed, and pool-change share one flush point would be
cleaner.

Tests: add a case that mixes flat and chained packets in one array
(flat run pending when the chain is hit, then flat after it), and one
with an indirect (cloned) mbuf in the flat path. Current tests do not
cover the transition into __rte_pktmbuf_free_bulk_fallback() with a
non-empty run, which is the new logic most likely to break.

Nit: the blank line added after "m = mbufs[idx];" in the fallback is
unrelated churn.

  parent reply	other threads:[~2026-09-22 13:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  1:28 [PATCH] mbuf: avoid temporary array for bulk free Nam Tran
2026-09-22 10:59 ` Morten Brørup
2026-09-22 13:54 ` Stephen Hemminger [this message]
2026-09-29  0:25 ` [PATCH v2] " Nam Tran
2026-09-29  4:39   ` Morten Brørup
2026-10-05  6:47   ` [EXTERNAL] " Ashwin Sekhar
2026-10-05  7:45   ` Konstantin Ananyev

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=20260922065437.2e3f5c15@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=hoangnamtran18122005@gmail.com \
    --cc=mb@smartsharesystems.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