From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AABC246099; Thu, 16 Jan 2025 04:50:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D6114025F; Thu, 16 Jan 2025 04:50:56 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 2CB1040156 for ; Thu, 16 Jan 2025 04:50:55 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-216395e151bso7329695ad.0 for ; Wed, 15 Jan 2025 19:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1736999454; x=1737604254; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=pyat8ba0f+zxXXiglTBvYGfJtCUSiuoRXBs/zsfboXA=; b=IcreFGtjN7ccpvoFVz+GhAM/C5PbH4lhDrCOLNXjcc/h3bhPwmIYSq+eY7BgwDEWEx nKjT9YiUCAwbTVYd/RnP0+oPu9UpHZuf+pMf+59tl0XAz00CSPoLEQgu0AP6vKdjF8E0 dwP8FEzVrh6L0I0SS/sb4KVEvdIIIAjR+o6SDf1NOaZqYabb4RWP2+cWdqe8VtLC1gAH 6ZiVjeoPSR8HIiZUMu10kKjd01VesqLK3JfHm5OFhkROmclH7ZTkQf2cOZJd206++fA7 zMmdjC/jlDCTJzWfxb2/6I12th6rOx1RGsPm9xAihgIvoT8N00mvFp1iBtW1EooCMTns Qbcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736999454; x=1737604254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pyat8ba0f+zxXXiglTBvYGfJtCUSiuoRXBs/zsfboXA=; b=ovSQTgCymnSV/dnyQCN2aH7Qm5Fq2rc4fG9cbsONqW/qw0UtpqeQ8fWZuTRNrYuHjN mowpz3X+Gc8AbQ4fzzTJn46PPyOGJ1scvzp6+/QB6za0vlpJn5DfgxzjMG9QSw5zFI2s 950w8pM5p7ty2u9OoidcXCnreEbU74ACBsv1bTxBrycgAMU5PS5u1eJ1G7tJU0yTi6+p tabywqbnyTTH7PZp/67vQoS+3zOrCRJKhMPk8yQuEFYO42jFvKJpkmSFI5bu5l/luH1v yDdU2UmatI6wE8zD9/5YlMkZ41cu/gmi383iVE2ZqA+inbKFiBX8wllx2jt/9ctM7Kmh b5iA== X-Gm-Message-State: AOJu0YxOvd6G37mY910BwNmzxkscyWgzAgLslDohRB69LzhsgJX5bIYB OrYArY6kzDR6kOiBQ9PecZk5hoR1dQ4FoMPHJVnqtPNPvdI286A8sbV4fVhC/LqBJ09pOenXjsj EYJM= X-Gm-Gg: ASbGncvVytsRYuotlR9PJZ+D+GHmD7BSmWmDIzbwOvtp9QrmDJkeGqsCROMkMh3skoR 0FtEn7Ac6by4XJUEqrduf9eD4u+Rya3jKHmDhtZZTUKyP/OskRRoldp1k8Lz8ooR6ryfsiSFC4V Tu1RO5P+4/8/+1Zc2Kpf2hKqWmaLdMN82nTlt4Q3aaL6dyiquzOcYURWdbEfcgI1nYapZ4CS08W YSSk129V5XoO/G+c9H8TssaWRNvGTh0nUcYuL900xFHuh1pb137tcyBzlYpti2yxqqToTak34m1 THKly2m1Zj0UzaKUFXZUIGKujHENrzL2DQ== X-Google-Smtp-Source: AGHT+IG60TR/ImevdP7FT8++TVbId127VZu13E3xf7JKbAvxIruu2IZLwav/PyBgQHR7g/6aIER03Q== X-Received: by 2002:a17:902:cecf:b0:216:5cc8:44e7 with SMTP id d9443c01a7336-21bf0d31063mr81829555ad.25.1736999454094; Wed, 15 Jan 2025 19:50:54 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f10de57sm90079635ad.22.2025.01.15.19.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 19:50:53 -0800 (PST) Date: Wed, 15 Jan 2025 19:50:51 -0800 From: Stephen Hemminger To: huangdengdui Cc: Subject: Re: [PATCH v2] mbuf: add fast free bulk function Message-ID: <20250115195051.1b10a775@hermes.local> In-Reply-To: <02835d2e-6acb-45df-8897-4590360be861@huawei.com> References: <20250114162544.125448-1-mb@smartsharesystems.com> <20250114163951.125667-1-mb@smartsharesystems.com> <02835d2e-6acb-45df-8897-4590360be861@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, 15 Jan 2025 14:52:16 +0800 huangdengdui wrote: > On 2025/1/15 0:39, Morten Br=C3=B8rup wrote: > > mbuf: add fast free bulk function > >=20 > > When putting an mbuf back into its mempool, there are certain requireme= nts > > to the mbuf. Specifically, some of its fields must be initialized. > >=20 > > These requirements are in fact invariants about free mbufs, held in > > mempools, and thus also apply when allocating an mbuf from a mempool. > > With this in mind, the additional assertions in rte_mbuf_raw_free() were > > moved to __rte_mbuf_raw_sanity_check(). > > Furthermore, the assertion regarding pinned external buffer was enhance= d; > > it now also asserts that the referenced pinned external buffer has > > refcnt =3D=3D 1. > >=20 > > The description of RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE was updated to > > include the remaining requirements, which were missing here. > >=20 > > And finally: > > A new rte_mbuf_fast_free_bulk() inline function was added for the benef= it > > of ethdev drivers supporting fast release of mbufs. > > It asserts these requirements and that the mbufs belong to the specified > > mempool, and then calls rte_mempool_put_bulk(). > >=20 > > Signed-off-by: Morten Br=C3=B8rup > > --- > > v2: > > * Fixed missing inline. > > --- > > lib/ethdev/rte_ethdev.h | 6 ++++-- > > lib/mbuf/rte_mbuf.h | 39 +++++++++++++++++++++++++++++++++++++-- > > 2 files changed, 41 insertions(+), 4 deletions(-) > >=20 > > diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h > > index 1f71cad244..e9267fca79 100644 > > --- a/lib/ethdev/rte_ethdev.h > > +++ b/lib/ethdev/rte_ethdev.h > > @@ -1612,8 +1612,10 @@ struct rte_eth_conf { > > #define RTE_ETH_TX_OFFLOAD_MULTI_SEGS RTE_BIT64(15) > > /** > > * Device supports optimization for fast release of mbufs. > > - * When set application must guarantee that per-queue all mbufs comes = from > > - * the same mempool and has refcnt =3D 1. > > + * When set application must guarantee that per-queue all mbufs come f= rom the same mempool, > > + * are direct, have refcnt=3D1, next=3DNULL and nb_segs=3D1, as done b= y rte_pktmbuf_prefree_seg(). > > + * > > + * @see rte_mbuf_fast_free_bulk() > > */ > > #define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE RTE_BIT64(16) > > #define RTE_ETH_TX_OFFLOAD_SECURITY RTE_BIT64(17) > > diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h > > index 0d2e0e64b3..7590d82689 100644 > > --- a/lib/mbuf/rte_mbuf.h > > +++ b/lib/mbuf/rte_mbuf.h > > @@ -568,6 +568,10 @@ __rte_mbuf_raw_sanity_check(__rte_unused const str= uct rte_mbuf *m) > > RTE_ASSERT(rte_mbuf_refcnt_read(m) =3D=3D 1); > > RTE_ASSERT(m->next =3D=3D NULL); > > RTE_ASSERT(m->nb_segs =3D=3D 1); > > + RTE_ASSERT(!RTE_MBUF_CLONED(m)); > > + RTE_ASSERT(!RTE_MBUF_HAS_EXTBUF(m) || > > + (RTE_MBUF_HAS_PINNED_EXTBUF(m) && > > + rte_mbuf_ext_refcnt_read(m->shinfo) =3D=3D 1)); > > __rte_mbuf_sanity_check(m, 0); > > } > > =20 > > @@ -623,12 +627,43 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc= (struct rte_mempool *mp) > > static __rte_always_inline void > > rte_mbuf_raw_free(struct rte_mbuf *m) > > { > > - RTE_ASSERT(!RTE_MBUF_CLONED(m) && > > - (!RTE_MBUF_HAS_EXTBUF(m) || RTE_MBUF_HAS_PINNED_EXTBUF(m))); > > __rte_mbuf_raw_sanity_check(m); > > rte_mempool_put(m->pool, m); > > } > > =20 > > +/** > > + * Put a bulk of mbufs allocated from the same mempool back into the m= empool. > > + * > > + * The caller must ensure that the mbufs come from the specified mempo= ol, > > + * are direct and properly reinitialized (refcnt=3D1, next=3DNULL, nb_= segs=3D1), as done by > > + * rte_pktmbuf_prefree_seg(). > > + * > > + * This function should be used with care, when optimization is > > + * required. For standard needs, prefer rte_pktmbuf_free_bulk(). > > + * > > + * @see RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE > > + * > > + * @param mp > > + * The mempool to which the mbufs belong. > > + * @param mbufs > > + * Array of pointers to packet mbufs. > > + * The array must not contain NULL pointers. > > + * @param count > > + * Array size. > > + */ > > +static __rte_always_inline void > > +rte_mbuf_fast_free_bulk(struct rte_mempool *mp, struct rte_mbuf **mbuf= s, unsigned int count) > > +{ > > + for (unsigned int idx =3D 0; idx < count; idx++) { > > + const struct rte_mbuf *m =3D mbufs[idx]; > > + RTE_ASSERT(m !=3D NULL); > > + RTE_ASSERT(m->pool =3D=3D mp); > > + __rte_mbuf_raw_sanity_check(m); > > + } =20 >=20 > Is there some way to avoid executing a loop in non-debug mode? Like the f= ollowing or other better way >=20 > #ifdef RTE_LIBRTE_MBUF_DEBUG > { > for (unsigned int idx =3D 0; idx < count; idx++) { > const struct rte_mbuf *m =3D mbufs[idx]; > RTE_ASSERT(m !=3D NULL); > RTE_ASSERT(m->pool =3D=3D mp); > __rte_mbuf_raw_sanity_check(m); > } > } > #endif I suspect compiler will optimize it way to nothing and drop the loop. Use godbolt to see. > > + > > + rte_mempool_put_bulk(mp, (void **)mbufs, count); =20 >=20 > Can the mp be obtained from the mbuf? Yes, see rte_pktmbuf_free >=20 > > +} > > + > > /** > > * The packet mbuf constructor. > > * =20