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 48D71A04B1; Thu, 5 Nov 2020 12:34:25 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 26A20BE69; Thu, 5 Nov 2020 12:34:24 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id DB67BBE59 for ; Thu, 5 Nov 2020 12:34:22 +0100 (CET) IronPort-SDR: fPuPd0DWf3IdmYQm/QOTK4fI2N+G+7rwq6Pe4sGxaEgEpfFdhF4ECMfRo7w97jVSeXEclmOUzx TEAK2b+jixAg== X-IronPort-AV: E=McAfee;i="6000,8403,9795"; a="148645677" X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="148645677" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 03:34:21 -0800 IronPort-SDR: Tec49H0WCrJyaQkQbi+Rutg+rM2p6rG28ZEvmLLnGhe4REwgW4CNOTjk8thWKO4rALjZfRaSz+ hVV9XdQrZ6+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="527934857" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2020 03:34:20 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX606.amr.corp.intel.com (10.22.229.19) 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 03:34:20 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX609.amr.corp.intel.com (10.22.229.22) 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 03:34:20 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx601.amr.corp.intel.com (10.22.229.14) 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 03:34:19 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.47) by edgegateway.intel.com (134.134.137.103) 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 03:34:19 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UgHR3hOPaTgnm7SePeAAH4mLXV5ShCI2kZlAQGNC5SPg2mB12h2YmbNB2MG2awXci4Qh1a8sU7AydYOdZkIpP0rtafKEgb33E3BZdYmqFFi7xW/7/ZNE0CKuSpl7E2hc1sSzxnmccGjZLSG4lxUafqOwo3iIeIYPZpKW1Ib/MblAtBAM5P3qFe6gJbtbKJcmgbDyAEP0kp9Va375Vhz7smSwzhNs94hkLe0ET66Y5L4k0Un66JQaV/hJAzMG8770y8WlfOZEgmKCMN7CTKy7ZPJDtcTF9a3Rb3bpkoW9W2OOAc7KIPekEIbvnsqjAK3MERSNF9i16vaJpR86pdXwfw== 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=r2LxA9y6Lk4/PhMjEIJ1F4IR9EEjpIE2ytk9qPHwmWI=; b=YWoNkIICPGXv9/JaTERZqMt35YKbTzUOt6qUsGakkjEst8S64ySNxJZFEf29Ad2rxuBkib/UAmrKecsSFMt5JmDr1cSchtCS9/ecJkRKFz/k/XOsSG8YWgcs0xBGDh/HJjHoVqr5VwtlIHQwmqYdaNnRbTesosAiJZVJCl7Yap6BHrxQl+kORjcY+rHZ4oi2pTjg3bYG3XeTN/JjJfMg0EZiaPW5QzoPjWFhf8PdVBZPVr75Mi1GELmsb0dax+Ig7yszBX8kmpQC9Dcf9TH1ArSeyYe/+I3uN9WB20HkMIpc0ShCiEG8slVCS57l2+xVoHJ3i9+0rcGOh/LVLRrh7g== 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=r2LxA9y6Lk4/PhMjEIJ1F4IR9EEjpIE2ytk9qPHwmWI=; b=km06cMElqtsc4V9shW1fiyl5v2cs2ZtTRDXXgE+a7ij4GYO00INIQhTjG2hO8mU9GMN3p+M21GTyKMKUBdz3+y1bQSDZ3K6efUy/zLymFkl7BJWGx5FzVkiQjxK0bkHfs8LbTVW3cSJ6bNR63lxj1FhM5FbEDeQIhKm1peH7Ybk= Received: from BYAPR11MB3301.namprd11.prod.outlook.com (2603:10b6:a03:7f::26) by BYAPR11MB3224.namprd11.prod.outlook.com (2603:10b6:a03:77::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19; Thu, 5 Nov 2020 11:34:19 +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 11:34:19 +0000 From: "Ananyev, Konstantin" To: Olivier Matz , Andrew Rybchenko CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] mbuf: fix reset on mbuf free Thread-Index: AQHWssw9/Ru+bbJv2UmxCtlz1ORQn6m4ql1ggAB/kQCAAAtLgIAADCkAgAAdJVA= Date: Thu, 5 Nov 2020 11:34:18 +0000 Message-ID: References: <20201104170007.8026-1-olivier.matz@6wind.com> <20201105074626.GL1898@platinum> <10b675b5-c376-746f-9ae2-210685b0b05d@oktetlabs.ru> <20201105091022.GO1898@platinum> In-Reply-To: <20201105091022.GO1898@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: 5598430e-bee9-4e77-2eee-08d8817ebbe5 x-ms-traffictypediagnostic: BYAPR11MB3224: 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: iRhzlzmBty+EzK+KLE7L4CVZJw9+6nVTq5Urx+czIhOzvd0IWmvqWmBLag8IGso6hG+3mNkNUxUB9kA2BUOan6dEVGVUz6sA8txXY48j69Vbgu4gxgVVdpDYC8yxmJ2cZ6bN++w5+g0OJ8eJbmpYJEXKtXQrRIhIyUP7fzKd8rT0u+A8NGe7WilYhF1VVuiAsdqHjFZRvWWITsJ/cTlKRDo50CfeHWZo9DSSTAGcydmYAGB/awy9Ufok4YnvGyjUsqkpfrbCfOIdPWuKGItboC8x6lm4zRNsfN+6qOBPP0WJd5w2avkpXzBFc9WraujB8Lavot6okR2ZHkiX51Njig== 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)(39860400002)(366004)(346002)(376002)(396003)(136003)(66446008)(64756008)(52536014)(110136005)(66476007)(478600001)(316002)(8676002)(66946007)(76116006)(5660300002)(2906002)(4326008)(83380400001)(33656002)(8936002)(66556008)(71200400001)(186003)(9686003)(53546011)(26005)(7696005)(6506007)(86362001)(55016002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: kjCkqB5pam0YXTITiw8GKb54PIKvHt8KBs64DlHPqhJNXzyWTZyHtuw7RWjRWJrlMWB12AWFVreILZCoKxxRAKYzmWvEL3laVxgNwsmS5NGcoa56abxUAxxvvqWVX9WLC4s4L7g44DYICxm88eYavdEiBf2vpEeeGnRSek0/vaImIt2QYq4Y9nZnoUKwkk5qjGt0qPy2kVu0TDqatytGt6pCwZ/3WQYPYM4fIvZZiH+7A3d5CaBGL9iewoRPCZxLOp8fDpI8qCb31WJppWi2/WQzJi7OgzB4L+Qrs7aCHyYyE6RJtbfUOt8z2ma/AbccIFyMKOQo/ew62lPT3vFW3IT2Wvg2GgxlHk/XtD+NODhjjfBFiJimsw9A+yYu7j4oXSHwjE8WrY+EcV2+LkTs5sjmzQkuIH/o0lGCJFqoRwaOLotofZHQWz928zfPM+QWCdoEmgFaNcc4xalo6ygS0RtNbf8lR11+zZdT6EM+6GRwMCdvI+I4PI6R/2LONVQtIAr6vOUFbzPieESak24hClL819a8NfFSw4T5QZb+omPOuge8jC1zA6WG3F6cELrLHAqx+36W8nd9KnQQfDbVCE2kbsVrpMoi1sZbowl6kE8gnO6eRuHZsX09721jDo6YDTEKYoe7aA1vCpOZaoi2ug== 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: 5598430e-bee9-4e77-2eee-08d8817ebbe5 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2020 11:34:18.9677 (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: ZfeQ7snflE91GRyeI4aKdIRSH0RFJhuohQvFwdS3S0yZReLNUa+6hxRpceXrL1btbQrO8bbBw5rte6wi2UOl/k136FmwIbKRZL3PBmy0lIs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3224 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" > 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 wrote: > > >> > > >> Hi Olivier, > > >> > > >>> m->nb_seg must be reset on mbuf free whatever the value of m->next, > > >>> because it can happen that m->nb_seg is !=3D 1. For instance in thi= s > > >>> 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 second > > >>> 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.=20 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 > I think the approach from > this patch is safer. It might be easier from perspective that changes in less places are require= d, Though I think that this patch will introduce some performance drop. As now each mbuf_prefree_seg() will cause update of 2 cache lines unconditi= onally. =20 > By the way, for 21.11, if we are able to do some optimizations and have > both pool (index?) and next in the first cache line, we may reconsider > the fact that next and nb_segs are already set for new allocated mbufs, > because it is not straightforward either. My suggestion - let's put future optimization discussion aside for now, and concentrate on that particular patch.=20 >=20 > > > After this operation, we have 2 mbuf chain: > > > - m0 with 2 segments, the last one has next=3DNULL but nb_seg=3D2 > > > - 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 fir= st > > > segment, and there is nothing saying it should be set to 1. Typically= , > > > 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_mbuf.= 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, voi= d *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_mbuf.= 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 > > >> > >