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 E9C20A00BE for ; Sat, 13 Jun 2020 17:58:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CE3441B91B; Sat, 13 Jun 2020 17:58:24 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id A5F995323; Sat, 13 Jun 2020 17:58:22 +0200 (CEST) IronPort-SDR: dJhTQPtAmNDteTh91/hPiFrKk7SKdbanjMP5zWFIKS3y35C+To7JqfjasvOrSesEyuGt5b3u7e ctcuVV2JvO3A== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 08:58:21 -0700 IronPort-SDR: fi80MMwmvzjKO1T9yi9vB0n7sukaH4LUF1+RLeOeJ6vCH5vNi0AwpZv4HzzGd3jNs0Yn0clZx4 ITwbZSS+QeLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,507,1583222400"; d="scan'208";a="448663744" Received: from yexl-server.sh.intel.com ([10.67.116.183]) by orsmga005.jf.intel.com with ESMTP; 13 Jun 2020 08:58:20 -0700 From: Xiaolong Ye To: Olivier Matz , Thomas Monjalon , Konstantin Ananyev Cc: dev@dpdk.org, Xiaolong Ye , stable@dpdk.org Date: Sat, 13 Jun 2020 23:49:19 +0800 Message-Id: <20200613154922.42379-4-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200613154922.42379-1-xiaolong.ye@intel.com> References: <20200613154922.42379-1-xiaolong.ye@intel.com> Subject: [dpdk-stable] [PATCH 3/5] mbuf: fix free_space setting for dynamic field X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" The value free_space[i] is used to save the size of biggest aligned element that can fit in the zone, current implementation has one flaw, for example, if user registers dynfield1 (size = 4, align = 4, req = 124) first, the free_space would be as below after registration: 0070: 08 08 08 08 08 08 08 08 0078: 08 08 08 08 00 00 00 00 Then if user continues to register dynfield2 (size = 4, align = 4), free_space would become: 0070: 00 00 00 00 04 04 04 04 0078: 04 04 04 04 00 00 00 00 Further request dynfield3 (size = 8, align = 8) would fail to register due to alignment requirement can't be satisfied, though there is enough space remained in mbuf. This patch fixes above issue by saving alignment only in aligned zone, after the fix, above registrations order can be satisfied, free_space would be like: After dynfield1 registration: 0070: 08 08 08 08 08 08 08 08 0078: 04 04 04 04 00 00 00 00 After dynfield2 registration: 0070: 08 08 08 08 08 08 08 08 0078: 00 00 00 00 00 00 00 00 After dynfield3 registration: 0070: 00 00 00 00 00 00 00 00 0078: 00 00 00 00 00 00 00 00 This patch also reduces iterations in process_score() by jumping align steps in each loop. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Cc: stable@dpdk.org Signed-off-by: Xiaolong Ye --- lib/librte_mbuf/rte_mbuf_dyn.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index de7d2eb9a5..fd51e1b68e 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -67,13 +67,16 @@ process_score(void) shm->free_space[i] = 1; } - for (off = 0; off < sizeof(struct rte_mbuf); off++) { + off = 0; + while (off < sizeof(struct rte_mbuf)) { /* get the size of the free zone */ for (size = 0; (off + size) < sizeof(struct rte_mbuf) && shm->free_space[off + size]; size++) ; - if (size == 0) + if (size == 0) { + off++; continue; + } /* get the alignment of biggest object that can fit in * the zone at this offset. @@ -84,8 +87,10 @@ process_score(void) ; /* save it in free_space[] */ - for (i = off; i < off + size; i++) + for (i = off; i < off + align; i++) shm->free_space[i] = RTE_MAX(align, shm->free_space[i]); + + off += align; } } -- 2.17.1