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 E871146290 for ; Sat, 22 Feb 2025 05:53:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 77831410E8; Sat, 22 Feb 2025 05:53:05 +0100 (CET) Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by mails.dpdk.org (Postfix) with ESMTP id 1E7174025E for ; Sat, 22 Feb 2025 05:53:04 +0100 (CET) Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2fc0026eb79so5731343a91.0 for ; Fri, 21 Feb 2025 20:53:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740199983; x=1740804783; darn=dpdk.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=9L/AceEfaAgisQB97fxSlKmgxmWmyDH7iMenLNeYxhU=; b=HTu2v8jA/VQJPOK09FNJPnhsMiuo9R3fUBb8X2Fx/xdG+LblTUpvxfuSrO0LpLmlr8 H/Kf2LhD3S9NXU1/KixXCDRq3xeOdDDIERPNEVRme3dTlF5it30ZN+L7MGkmITm7AxUR T84smUxtgOsyCakiVOYYZ/oPiRBQBiHqE51CId+VId58vp92aapMEp/Hahgn10b6JHIc P8eR4THxJ28QK4yw7TvMNOf+gsDybxWmQrRFslZj0m0fJp5VoRBA99Ig1tKzMLZdflID VVO0fHncRD19G3eeK2C9lrJlg7nYJlP9Qi+dzE2l8Wd6YQ8KXeHAJWrW/6xzxxa8st7S mKkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740199983; x=1740804783; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9L/AceEfaAgisQB97fxSlKmgxmWmyDH7iMenLNeYxhU=; b=lgX8HfwsgmEoFbTpmp6bU50Mz0NiGqCgaRtU8oPjHCUot3XNe96nKD0/xykkVZeSJF K8fy/gljepyndoYQQuE5/3rtrd2DcFBjESiHIbo1xfbFAfL+v8QqYOSoLzd9b0hJiVFH AMKFFABgY4LOflN09CoX2qq/EVmVI+an2klWHNrlQSgqWGDM3+KN3f9GLlkozUZwnZ8k 4zMR/++UEErp7UhX+qRu1qYN/17Jm4cD02/73xsRxlNQusEGzSiE+aCHHTEh2sQlCQb9 fRprikiophaiNFDBsNUYhD7OVF/hvtUUb5d7YIEIGyB8lOXkfAPjgCYmAls0oaY4H/YO GwPA== X-Gm-Message-State: AOJu0YxQIaAemOFH21upUxQpoAi170p0gapYuuh/NFZI6k7S+4i0Di45 RVDqb5rZLWGPwuBtueJ7Oq1GXuGVz3UJsRMz9NEJmtzz+Rxoy9XwJ2FAMuRZY3PxjtsSFK5dR6p NzpTl8peRxFYxZFrz/YShgHiHkNb7VMwX X-Gm-Gg: ASbGncueJhQ6qJzvL0LoC/xIfBtX8j6aPSEzv6aprP3J35J8tdRJtFfC/+85QhFn+Tu ORVrlGHSKOYLxgKGtuZL/sVV1tGqM7pgb4Fo7UqkfYvjchd1nqr5OWjm7/Pcc31TToAnf7rwIHv x5l3HVbU8EnKQaJBR1VQHxJoh+Bqu6YbWusE0r9Lg6Xg== X-Google-Smtp-Source: AGHT+IEYB6uePvEtPeYA1V5OYjNAINt3gJ6IVZwbI6/PiFYQNhi4FqwhhVvmJyFKaNeOhYIzu7qI8B/B0tMbsyOEq+M= X-Received: by 2002:a17:90b:2241:b0:2ef:2f49:7d7f with SMTP id 98e67ed59e1d1-2fce78c7f73mr11077709a91.18.1740199983017; Fri, 21 Feb 2025 20:53:03 -0800 (PST) MIME-Version: 1.0 References: <20250221104606.60dafc66@hermes.local> In-Reply-To: <20250221104606.60dafc66@hermes.local> From: Lokesh Chakka Date: Sat, 22 Feb 2025 10:22:51 +0530 X-Gm-Features: AWEUYZn0vEGGH7VXNEC2dqrOZJYQcrUhjF0URZ2SZlKRXLe4f0QIzvlhc5Jy3AU Message-ID: Subject: Re: mbuf validity in conjunction with ref cnt To: Stephen Hemminger Cc: users Content-Type: multipart/alternative; boundary="000000000000d37432062eb3e186" X-BeenThere: users@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK usage discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: users-bounces@dpdk.org --000000000000d37432062eb3e186 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable My objective is to reuse mbuf unlimited number of times for a configurable amount of time. rte_pktmbuf_alloc // after here refcnt is 1 refcnt_update ( , 1) //after here refcnt is 2 while( time still exists ) { tx_burst } Will this approach work with all drivers/cards ? Thanks & Regards -- Lokesh Chakka. On Sat, Feb 22, 2025 at 12:16=E2=80=AFAM Stephen Hemminger < stephen@networkplumber.org> wrote: > On Fri, 21 Feb 2025 13:09:34 +0530 > Lokesh Chakka wrote: > > > Hello, > > > > I've created mbuf using rte_pktmbuf_alloc. > > Just after creating mbuf rte_mbuf_refcnt_read is giving 1. > > > > After rte_eth_tx_burst, rte_mbuf_refcnt_read is giving 1. > > > > Even > > rte_eth_tx_burst > > sleep(10); > > rte_mbuf_refcnt_read > > is still giving 1 > > > > Even > > rte_eth_tx_burst > > sleep(10); > > rte_mbuf_refcnt_read // is still giving 1 > > rte_pktmbuf_free > > sleep(10); > > rte_mbuf_refcnt_read // is still giving 1 > > > > Does it mean mbuf can be reused like > > while(1) > > { > > rte_eth_tx_burst > > } > > > > > > Thanks & Regards > > -- > > Lokesh Chakka. > > Once you gave the mbuf to the driver, with a refcnt of 1 it > means the driver will free it. Any later reference is a use after free. > The driver will free it at an undetermined time after sending. > Some drivers defer the free until a later reclaim cycle (next send). > > When mbuf is freed, the refcnt does not > go to zero, it just moves into the mbuf free pool. > Read the the source for more details. > > There is no callback in DPDK for when mbuf is actually sent or freed. > > --000000000000d37432062eb3e186 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
My objective is to reuse mbuf unlimited number of tim= es for a configurable amount of time.

rte_pktmbuf_alloc // after here refcnt is 1
refcnt_updat= e ( , 1) //after here refcnt is 2
while( time still exists )
{
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tx_burst
}
=

Will this approach work with all drivers/ca= rds ?

Thanks & Regards
--
Lokesh Chakka= .


On Sat, Feb 22, 2025 at 12:16=E2=80=AFAM Stephen Hemminge= r <stephen@networkplumber.= org> wrote:
On Fri, 21 Feb 2025 13:09:34 +0530
Lokesh Chakka <lvenkatakumarchakka@gmail.com> wrote:

> Hello,
>
> I've created mbuf using rte_pktmbuf_alloc.
> Just after creating mbuf rte_mbuf_refcnt_read is giving 1.
>
> After rte_eth_tx_burst, rte_mbuf_refcnt_read is giving 1.
>
> Even
>=C2=A0 =C2=A0 =C2=A0 =C2=A0rte_eth_tx_burst
>=C2=A0 =C2=A0 =C2=A0 =C2=A0sleep(10);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 rte_mbuf_refcnt_read
> is still giving 1
>
> Even
>=C2=A0 =C2=A0 =C2=A0 =C2=A0rte_eth_tx_burst
>=C2=A0 =C2=A0 =C2=A0 =C2=A0sleep(10);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 rte_mbuf_refcnt_read // is still giving 1 >=C2=A0 =C2=A0 =C2=A0 =C2=A0 rte_pktmbuf_free
>=C2=A0 =C2=A0 =C2=A0 =C2=A0sleep(10);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 rte_mbuf_refcnt_read // is still giving 1 >
> Does it mean mbuf can be reused like
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0while(1)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rt= e_eth_tx_burst
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
>
>
> Thanks & Regards
> --
> Lokesh Chakka.

Once you gave the mbuf to the driver, with a refcnt of 1 it
means the driver will free it. Any later reference is a use after free.
The driver will free it at an undetermined time after sending.
Some drivers defer the free until a later reclaim cycle (next send).

When mbuf is freed, the refcnt does not
go to zero, it just moves into the mbuf free pool.
Read the the source for more details.

There is no callback in DPDK for when mbuf is actually sent or freed.

--000000000000d37432062eb3e186--