From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 5F51C1B298 for ; Wed, 14 Feb 2018 15:16:16 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2018 06:16:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,512,1511856000"; d="scan'208";a="201088062" Received: from irsmsx108.ger.corp.intel.com ([163.33.3.3]) by orsmga005.jf.intel.com with ESMTP; 14 Feb 2018 06:16:13 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.221]) by IRSMSX108.ger.corp.intel.com ([169.254.11.9]) with mapi id 14.03.0319.002; Wed, 14 Feb 2018 14:16:12 +0000 From: "Ananyev, Konstantin" To: "Ananyev, Konstantin" , "Richardson, Bruce" CC: Yongseok Koh , Olivier Matz , "dev@dpdk.org" Thread-Topic: [dpdk-dev] Accessing 2nd cacheline in rte_pktmbuf_prefree_seg() Thread-Index: AQHTpRxoSpjpp7VOiUGxw51sLWTbeaOjOjMAgACJaVCAAAlJYIAAAuaAgAAEvKCAABlU8A== Date: Wed, 14 Feb 2018 14:16:12 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725890572F6D@irsmsx105.ger.corp.intel.com> References: <97910E4F-11F5-4BDB-A460-2656B88EA87D@mellanox.com> <2601191342CEEE43887BDE71AB97725890572EA2@irsmsx105.ger.corp.intel.com> <2601191342CEEE43887BDE71AB97725890572EC6@irsmsx105.ger.corp.intel.com> <20180214121157.GA3116@bricha3-MOBL3.ger.corp.intel.com> <2601191342CEEE43887BDE71AB97725890572EF7@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB97725890572EF7@irsmsx105.ger.corp.intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNTcxNmY3NDYtODVhYi00NGZiLWI3NzktZDA3YzkzZDY5M2ZkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6Inp0dzVYcG5TZFJCTzcrUW04ejVjQTBvWTNrc0R6WUZhaWxMNktiUklxaDQ9In0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] Accessing 2nd cacheline in rte_pktmbuf_prefree_seg() 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: , X-List-Received-Date: Wed, 14 Feb 2018 14:16:17 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ananyev, Konstantin > Sent: Wednesday, February 14, 2018 12:35 PM > To: Richardson, Bruce > Cc: Yongseok Koh ; Olivier Matz ; dev@dpdk.org > Subject: Re: [dpdk-dev] Accessing 2nd cacheline in rte_pktmbuf_prefree_se= g() >=20 >=20 >=20 > > -----Original Message----- > > From: Richardson, Bruce > > Sent: Wednesday, February 14, 2018 12:12 PM > > To: Ananyev, Konstantin > > Cc: Yongseok Koh ; Olivier Matz ; dev@dpdk.org > > Subject: Re: [dpdk-dev] Accessing 2nd cacheline in rte_pktmbuf_prefree_= seg() > > > > On Wed, Feb 14, 2018 at 12:03:55PM +0000, Ananyev, Konstantin wrote: > > > > > > > > > > -----Original Message----- > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ananyev, Konst= antin > > > > Sent: Wednesday, February 14, 2018 11:48 AM > > > > To: Yongseok Koh ; Olivier Matz > > > > Cc: dev@dpdk.org > > > > Subject: Re: [dpdk-dev] Accessing 2nd cacheline in rte_pktmbuf_pref= ree_seg() > > > > > > > > Hi Yongseok, > > > > > > > > > > On Feb 13, 2018, at 2:45 PM, Yongseok Koh = wrote: > > > > > > > > > > > > Hi Olivier > > > > > > > > > > > > I'm wondering why rte_pktmbuf_prefree_seg() checks m->next inst= ead of > > > > > > m->nb_segs? As 'next' is in the 2nd cacheline, checking nb_segs= seems beneficial > > > > > > to the cases where almost mbufs have single segment. > > > > > > > > > > > > A customer reported high rate of cache misses in the code and I= thought the > > > > > > following patch could be helpful. I haven't had them try it yet= but just wanted > > > > > > to hear from you. > > > > > > > > > > > > I'd appreciate if you can review this idea. > > > > > > > > > > > > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_m= buf.h > > > > > > index 62740254d..96edbcb9e 100644 > > > > > > --- a/lib/librte_mbuf/rte_mbuf.h > > > > > > +++ b/lib/librte_mbuf/rte_mbuf.h > > > > > > @@ -1398,7 +1398,7 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *= m) > > > > > > if (RTE_MBUF_INDIRECT(m)) > > > > > > rte_pktmbuf_detach(m); > > > > > > > > > > > > - if (m->next !=3D NULL) { > > > > > > + if (m->nb_segs > 1) { > > > > > > m->next =3D NULL; > > > > > > m->nb_segs =3D 1; > > > > > > } > > > > > > @@ -1410,7 +1410,7 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *= m) > > > > > > if (RTE_MBUF_INDIRECT(m)) > > > > > > rte_pktmbuf_detach(m); > > > > > > > > > > > > - if (m->next !=3D NULL) { > > > > > > + if (m->nb_segs > 1) { > > > > > > m->next =3D NULL; > > > > > > m->nb_segs =3D 1; > > > > > > } > > > > > > > > > > Well, m->pool in the 2nd cacheline has to be accessed anyway in o= rder to put it back to the mempool. > > > > > It looks like the cache miss is unavoidable. > > > > > > > > As a thought: in theory PMD can store pool pointer together with ea= ch mbuf it has to free, > > > > then it could be something like: > > > > > > > > if (rte_pktmbuf_prefree_seg(m[x] !=3D NULL) > > > > rte_mempool_put(pool[x], m[x]); > > > > > > > > Then what you suggested above might help. > > > > > > After another thought - we have to check m->next not m->nb_segs. > > > There could be a situations where nb_segs=3D=3D1, but m->next !=3D NU= LL > > > (2-nd segment of the 3 segment packet for example). > > > So probably we have to keep it as it is. > > > Sorry for the noise > > > Konstantin > > > > It's still worth considering as an option. We could check nb_segs for > > the first segment of a packet and thereafter iterate using the next > > pointer. >=20 > In multi-seg case PMD frees segments (not packets). > It could happen that first segment would be already freed while the secon= d > still not. >=20 > > It means that your idea of storing the pool pointer for each > > mbuf becomes useful for single-segment packets. >=20 > But then we'll have to support 2 different flavors of prefree_seg(). > Alternative would be to change all PMDs multi-seg TX so when first segmen= t is > going to be freed we update nb_segs for the second and so on. > Both options seems like too much hassle. >=20 As a side thought what probably can be done to minimize access to 2-nd mbuf's cache line at PMD tx free: Introduce something like that: static __rte_always_inline struct rte_mepool * xxx_prefree_seg(struct rte_mbuf *m) { if (rte_mbuf_refcnt_read(m) =3D=3D 1 && RTE_MBUF_DIRECT(m)) { if (m->next !=3D NULL) { m->next =3D NULL; m->nb_segs =3D 1; } return m->pool; } return NULL; } Then at tx_burst() before doing actual TX PMD can call that function and store it's return value along with mbuf: .. m[x] =3D pkt; pool[x] =3D xxx_prefree_seg(m[x]); Then at free time, we can do something ilike: If (pool[x] !=3D NULL)=20 rte_mempool_put(pool[x], m[x]); else rte_pktmbuf_free_seg(m[x]); We still access m->next but doing that before actual TX is done. Hopefully there would be more chances that m->next is still in the cache at that moment. In theory, that might help for most common case when we have direct mbufs with refcnt=3D=3D1. Though for indirect/refcnt>1 mbufs there would be extra overhead. Konstantin