From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BC25BA04B1; Thu, 5 Nov 2020 14:14:15 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1B836BE99; Thu, 5 Nov 2020 14:14:14 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 4DE60BE89 for ; Thu, 5 Nov 2020 14:14:12 +0100 (CET) IronPort-SDR: WMNBPy+Qlf2zsIh6AGP+PDz3NFqp2SmUK9xOBi5E2mN6+o+AhStQA8X81NcKNYHM3u/SapK5w5 GTZq3xsRjIUA== X-IronPort-AV: E=McAfee;i="6000,8403,9795"; a="187285702" X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="187285702" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 05:14:09 -0800 IronPort-SDR: mEaucZu2r+y6kEkdU+xOo+P3RS9SuBR1T5Nz3pLRljp5sQHiTSU/fUpkTmbgRC2400a24aXFjs Fcb/Dw2iaIeQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="321215583" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by orsmga003.jf.intel.com with ESMTP; 05 Nov 2020 05:14:09 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 5 Nov 2020 05:14:08 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 5 Nov 2020 05:14:08 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.103) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Thu, 5 Nov 2020 05:14:08 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M1VqE1/fC/nZKBXzVnoM1qvtfQhYbyHwEtYgHwYvgEjHCCyn3p8xqMfH+wwN7e9IWhw3agpcgTPAqs6g/WP3NGIqoJA3Jtzk4tQKHvBQVNGPqjwRHxvTWqK4pWs+MhlJSf1oicLrkNi4fNfBmmHTHou/o2KEZXnBb/SyEWFEupDReSqe+OEEJaN8uSjMzPr+/ixuh2r/qkt8qY4C5+ySs7ZAObWDqH9GW0+RFOZoA7qmM0KJr8iMRtzYXb6Jhl7qAsfZchsVbjsIncQHx7lDMdepuZ4CMzAjKy7pnKqGPPbcgG6MhrRWn/EIagOWnjOzzPfgQckJikruW24gPYJz4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rn5gfPTGGT9ujXenNxspNhmsLQPgENyPesdFw3Fjwu0=; b=aLuzMq4VhT93KYVKldqfq81+O040feTKbuWkVMdSaLSPocNI8uUFcujM2USNqWgqX6MgadLTYr9CBgzXt1sM6f24iMQuPhv8szTL6pHIOJ+1tPc6snKB80GmktUf0NOEPOulsbeXzevd0OVi0i+7GrOrBD6Dsxa6C0mu8RXWqxQiu4h0eztgt/PRDUPwpAZXZIvS285R1fhc6+1d+IOvUg9sucHaeFYtoOmIEjdI016rnpPWTKEaLKr1A2oOZLTosj5+F0XLaegjdrRw8PEOw/OA5aXt87zBrMSKd2bPt6+bxwQh6XkKRIozzin5YcWUgT3kw7m8dqG9bfAPyxp+qw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rn5gfPTGGT9ujXenNxspNhmsLQPgENyPesdFw3Fjwu0=; b=lVCJvgR3oasAeZWq0j0WqDEwF/DPuzQSgTFW0hFvJJKvz93JURqgXgdQR4ZqoZk6fDq4VsEi3ml4Mw/6sE0W7Q0HH4ixj5sYcxIvjXFM0T5FRzasC5bW5xU3wXVKYeqK3h0miNMgCwOu9XsgWhHZjQE1AXSq/newYKmxGtn7AbM= Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26) by BY5PR11MB4243.namprd11.prod.outlook.com (2603:10b6:a03:1c8::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Thu, 5 Nov 2020 13:14:07 +0000 Received: from BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f5a4:3f6b:ade3:296b]) by BYAPR11MB3301.namprd11.prod.outlook.com ([fe80::f5a4:3f6b:ade3:296b%3]) with mapi id 15.20.3499.032; Thu, 5 Nov 2020 13:14:07 +0000 From: "Ananyev, Konstantin" To: Olivier Matz CC: Andrew Rybchenko , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] mbuf: fix reset on mbuf free Thread-Index: AQHWssw9/Ru+bbJv2UmxCtlz1ORQn6m4ql1ggAB/kQCAAAtLgIAADCkAgAAdJVCAABslAIAACA7w Date: Thu, 5 Nov 2020 13:14:07 +0000 Message-ID: References: <20201104170007.8026-1-olivier.matz@6wind.com> <20201105074626.GL1898@platinum> <10b675b5-c376-746f-9ae2-210685b0b05d@oktetlabs.ru> <20201105091022.GO1898@platinum> <20201105123150.GP1898@platinum> In-Reply-To: <20201105123150.GP1898@platinum> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [46.7.39.127] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2d25f226-37de-4b1c-fb9e-08d8818cad4d x-ms-traffictypediagnostic: BY5PR11MB4243: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vQ5ITURdRboq/LdbmrghKYCISdD9clckfn1aADuO55+TxAx1Am2aLke/SxGH0evOTH+iNLlpBtORh7oOqJzHGS1QJOH4z4oz6M31Ynz6AvwjlN/Y6dC9blQ1CUlBNwGIt4qOmrKKutvaStLJGETFW8UWKlw4/p4ULlgyRQyxaP4LsJZAOsh8py0hcCYvTshBvS3radw9CX+/edd6hXUBPUar8RvN66mauxqcYYH/JAbVNW1CieTsSZQL+YB+EBLQ9RSN4XrTc3rUXbQP8RGvjw1RwAGwJbgc9Nx0L365mI3wth1y0fRGa4TE+L0dzcMVMSBDsqB6b5+DSfylBV4Gxw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3301.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(346002)(376002)(396003)(136003)(39860400002)(26005)(7696005)(66476007)(478600001)(66446008)(71200400001)(186003)(64756008)(76116006)(316002)(6506007)(66556008)(8676002)(33656002)(54906003)(4326008)(6916009)(53546011)(2906002)(66946007)(5660300002)(86362001)(9686003)(52536014)(83380400001)(8936002)(55016002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: g+u6cV2DzHPpkOiUIXIn9lvoXs7z+fQeMpqIrYBk8d/NF6QdS6IlI2HDT6YHIVc7MI4Q8GMEVGFEkNq951un/IUng4ZnNutAjJTcrED8jz3d7RF9JGuZ7VqZiA00zkla7sqZjLknvLPKsL7MdDuManT8Yo4fzvhlrNCgb1bsWPrFIs/UKqadlf2xBB35+8EENt88p2VEqOxvoblL6AqTHSRwNpet8N8H1+jUWwBgpXGiVSB0RQc1anKOtUsyLMkjb2rFRjsDpBxdcBO2WNB2x6cAvfdDfdLux3EysFqF6ksUZpskLUBOxClx2yKelxXh7SW7N1eHylSF20HwRI+Qn8V7Cz8B/xy0zu24OvsudeOCHP6wTBHS/8xNoYwGcY5/isYd8PtIYxzkej+UcCvdObCPK0sTRZcCRwrTDxjjqYV5qjCoIJSPV/29Dh8YaE3ynqHXcUpkM8HEjkC+HpnSJlgb5Dh6wNa5I/XZv2Wr9r7cy5QN0wiBhWQ95uJN1W6zyV/Lg6+Ru44YvcMZpzv5XnbCA7axOyKZ1G/zm7lsIDPmp4HqWkVz4Qj6A9I42ANIjVLx1ZkKlVECOrKCY9ymWDJ7I/cGP6XOWQy07OdwXjHYgQ1SubLzN29KieNPsOwzw3hYh+9lKhFV3Fu3/nbF8g== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3301.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d25f226-37de-4b1c-fb9e-08d8818cad4d X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2020 13:14:07.5319 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: AnVOs+8a5skmMhb+7a8DffigYotmO+GH4faMH/C/vpiJaCsB46GGzpO8h/18xytnlsEyavjDwzrI9VZ6HhrC7Yp7psu3y3WB+MaGjExfkok= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB4243 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH] mbuf: fix reset on mbuf free X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" >=20 > On Thu, Nov 05, 2020 at 11:34:18AM +0000, Ananyev, Konstantin wrote: > > > > > > > On Thu, Nov 05, 2020 at 11:26:51AM +0300, Andrew Rybchenko wrote: > > > > On 11/5/20 10:46 AM, Olivier Matz wrote: > > > > > On Thu, Nov 05, 2020 at 12:15:49AM +0000, Ananyev, Konstantin wro= te: > > > > >> > > > > >> Hi Olivier, > > > > >> > > > > >>> m->nb_seg must be reset on mbuf free whatever the value of m->n= ext, > > > > >>> because it can happen that m->nb_seg is !=3D 1. For instance in= this > > > > >>> case: > > > > >>> > > > > >>> m1 =3D rte_pktmbuf_alloc(mp); > > > > >>> rte_pktmbuf_append(m1, 500); > > > > >>> m2 =3D rte_pktmbuf_alloc(mp); > > > > >>> rte_pktmbuf_append(m2, 500); > > > > >>> rte_pktmbuf_chain(m1, m2); > > > > >>> m0 =3D rte_pktmbuf_alloc(mp); > > > > >>> rte_pktmbuf_append(m0, 500); > > > > >>> rte_pktmbuf_chain(m0, m1); > > > > >>> > > > > >>> As rte_pktmbuf_chain() does not reset nb_seg in the initial m1 > > > > >>> segment (this is not required), after this code the mbuf chain > > > > >>> have 3 segments: > > > > >>> - m0: next=3Dm1, nb_seg=3D3 > > > > >>> - m1: next=3Dm2, nb_seg=3D2 > > > > >>> - m2: next=3DNULL, nb_seg=3D1 > > > > >>> > > > > >>> Freeing this mbuf chain will not restore nb_seg=3D1 in the seco= nd > > > > >>> segment. > > > > >> > > > > >> Hmm, not sure why is that? > > > > >> You are talking about freeing m1, right? > > > > >> rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > > > > >> { > > > > >> ... > > > > >> if (m->next !=3D NULL) { > > > > >> m->next =3D NULL; > > > > >> m->nb_segs =3D 1; > > > > >> } > > > > >> > > > > >> m1->next !=3D NULL, so it will enter the if() block, > > > > >> and will reset both next and nb_segs. > > > > >> What I am missing here? > > > > >> Thinking in more generic way, that change: > > > > >> - if (m->next !=3D NULL) { > > > > >> - m->next =3D NULL; > > > > >> - m->nb_segs =3D 1; > > > > >> - } > > > > >> + m->next =3D NULL; > > > > >> + m->nb_segs =3D 1; > > > > > > > > > > Ah, sorry. I oversimplified the example and now it does not > > > > > show the issue... > > > > > > > > > > The full example also adds a split() to break the mbuf chain > > > > > between m1 and m2. The kind of thing that would be done for > > > > > software TCP segmentation. > > > > > > > > > > > > > If so, may be the right solution is to care about nb_segs > > > > when next is set to NULL on split? Any place when next is set > > > > to NULL. Just to keep the optimization in a more generic place. > > > > > > > The problem with that approach is that there are already several > > > existing split() or trim() implementations in different DPDK-based > > > applications. For instance, we have some in 6WINDGate. If we force > > > applications to set nb_seg to 1 when resetting next, it has to be > > > documented because it is not straightforward. > > > > I think it is better to go that way. > > From my perspective it seems natural to reset nb_seg at same time > > we reset next, otherwise inconsistency will occur. >=20 > While it is not explicitly stated for nb_segs, to me it was clear that > nb_segs is only valid in the first segment, like for many fields (port, > ol_flags, vlan, rss, ...). >=20 > If we say that nb_segs has to be valid in any segments, it means that > chain() or split() will have to update it in all segments, which is not > efficient. Why in all? We can state that nb_segs on non-first segment should always equal 1. As I understand in that case, both split() and chain() have to update nb_se= gs only for head mbufs, rest ones will remain untouched. =20 >=20 > Saying that nb_segs has to be valid for the first and last segment seems > really odd to me. What is the logic behind that except keeping this test > as is? >=20 > In any case, it has to be better documented. >=20 >=20 > Olivier >=20 >=20 > > > I think the approach from > > > this patch is safer. > > > > It might be easier from perspective that changes in less places are req= uired, > > Though I think that this patch will introduce some performance drop. > > As now each mbuf_prefree_seg() will cause update of 2 cache lines uncon= ditionally. > > > > > By the way, for 21.11, if we are able to do some optimizations and ha= ve > > > both pool (index?) and next in the first cache line, we may reconside= r > > > the fact that next and nb_segs are already set for new allocated mbuf= s, > > > because it is not straightforward either. > > > > My suggestion - let's put future optimization discussion aside for now, > > and concentrate on that particular patch. > > > > > > > > > > After this operation, we have 2 mbuf chain: > > > > > - m0 with 2 segments, the last one has next=3DNULL but nb_seg=3D= 2 > > > > > - new_m with 1 segment > > > > > > > > > > Freeing m0 will not restore nb_seg=3D1 in the second segment. > > > > > > > > > >> Assumes that it is ok to have an mbuf with > > > > >> nb_seg > 1 and next =3D=3D NULL. > > > > >> Which seems wrong to me. > > > > > > > > > > I don't think it is wrong: nb_seg is just ignored when not in the= first > > > > > segment, and there is nothing saying it should be set to 1. Typic= ally, > > > > > rte_pktmbuf_chain() does not change it, and I guess it's the same= for > > > > > many similar functions in applications. > > > > > > > > > > Olivier > > > > > > > > > >> > > > > >> > > > > >>> This is expected that mbufs stored in pool have their > > > > >>> nb_seg field set to 1. > > > > >>> > > > > >>> Fixes: 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool") > > > > >>> Cc: stable@dpdk.org > > > > >>> > > > > >>> Signed-off-by: Olivier Matz > > > > >>> --- > > > > >>> lib/librte_mbuf/rte_mbuf.c | 6 ++---- > > > > >>> lib/librte_mbuf/rte_mbuf.h | 12 ++++-------- > > > > >>> 2 files changed, 6 insertions(+), 12 deletions(-) > > > > >>> > > > > >>> diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_m= buf.c > > > > >>> index 8a456e5e64..e632071c23 100644 > > > > >>> --- a/lib/librte_mbuf/rte_mbuf.c > > > > >>> +++ b/lib/librte_mbuf/rte_mbuf.c > > > > >>> @@ -129,10 +129,8 @@ rte_pktmbuf_free_pinned_extmem(void *addr,= void *opaque) > > > > >>> > > > > >>> rte_mbuf_ext_refcnt_set(m->shinfo, 1); > > > > >>> m->ol_flags =3D EXT_ATTACHED_MBUF; > > > > >>> - if (m->next !=3D NULL) { > > > > >>> - m->next =3D NULL; > > > > >>> - m->nb_segs =3D 1; > > > > >>> - } > > > > >>> + m->next =3D NULL; > > > > >>> + m->nb_segs =3D 1; > > > > >>> rte_mbuf_raw_free(m); > > > > >>> } > > > > >>> > > > > >>> diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_m= buf.h > > > > >>> index a1414ed7cd..ef5800c8ef 100644 > > > > >>> --- a/lib/librte_mbuf/rte_mbuf.h > > > > >>> +++ b/lib/librte_mbuf/rte_mbuf.h > > > > >>> @@ -1329,10 +1329,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf = *m) > > > > >>> return NULL; > > > > >>> } > > > > >>> > > > > >>> - if (m->next !=3D NULL) { > > > > >>> - m->next =3D NULL; > > > > >>> - m->nb_segs =3D 1; > > > > >>> - } > > > > >>> + m->next =3D NULL; > > > > >>> + m->nb_segs =3D 1; > > > > >>> > > > > >>> return m; > > > > >>> > > > > >>> @@ -1346,10 +1344,8 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf = *m) > > > > >>> return NULL; > > > > >>> } > > > > >>> > > > > >>> - if (m->next !=3D NULL) { > > > > >>> - m->next =3D NULL; > > > > >>> - m->nb_segs =3D 1; > > > > >>> - } > > > > >>> + m->next =3D NULL; > > > > >>> + m->nb_segs =3D 1; > > > > >>> rte_mbuf_refcnt_set(m, 1); > > > > >>> > > > > >>> return m; > > > > >>> -- > > > > >>> 2.25.1 > > > > >> > > > >