From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by dpdk.org (Postfix) with ESMTP id 2FC59F8C0 for ; Wed, 18 Jan 2017 10:23:15 +0100 (CET) Received: by mail-lf0-f47.google.com with SMTP id k86so5693050lfi.0 for ; Wed, 18 Jan 2017 01:23:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brain4net.com; s=google; h=from:to:cc:subject:date:message-id; bh=0QBLvXoHH76njj9gtnkTjbvj5mnqPNYR9nStJFaduY8=; b=NNRE+v/tkgEFXEk04rLJNvTCsA6LaFx9vHgDwEaa2V/KV10Yp1WstPdmvLngIdJ/Hq KddSxMHGaTs/tzP0CE0c4Jw/KDpWKQx6KunXFPBUrZ2qBCYp6gwbf87hrFYRzxckkHrl pWoj9m9Y1HBpdCGr616RiJDy+79QPOMk9ZZdg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0QBLvXoHH76njj9gtnkTjbvj5mnqPNYR9nStJFaduY8=; b=Bvoz8J4qH56UYK0AZjLC5IuVKfAAQOABi207WicJfFyuqfi3PlbaXyDAev8dh3f65K brrOko0crtw9R9SZF8Wh9Q3T6hv2jZDufJvRYCCaxcVaE7Uh6HDU1rwPG3afauzAhgL1 ODpQDE6LpIdtRdthzs/s8DvKlh8Y6Fo38A6ETWe5BNO0qn86fykIn6mLiW5QZHB9Iodl Lv7OqHoBI5STwheB4DBHkMd5BNryjIawlBXb/JtyB8SrC9Qe5vZZsLH7sA0vb/IXwZRQ Wt4qAjo0KzwcU3f4Cf6b1EGQATO8PXeIC1DPOcohMetaLjvxskerEeoOfgIsRmp7arL7 1qtw== X-Gm-Message-State: AIkVDXIalVGmHo0DVryjmnPQS4OF616uZNsDrDIiAakGiI7jvns4+ufeGR5vDAEqWWbbE/7E X-Received: by 10.46.77.149 with SMTP id c21mr1013902ljd.69.1484731394762; Wed, 18 Jan 2017 01:23:14 -0800 (PST) Received: from localhost.localdomain ([91.201.72.212]) by smtp.gmail.com with ESMTPSA id a78sm10120196ljb.47.2017.01.18.01.23.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 01:23:14 -0800 (PST) From: Sergey Vyazmitinov To: olivier.matz@6wind.com Cc: konstantin.ananyev@intel.com, stephen@networkplumber.org, yuanhan.liu@linux.intel.com, ferruh.yigit@intel.com, dev@dpdk.org, Sergey Vyazmitinov Date: Wed, 18 Jan 2017 16:23:06 +0700 Message-Id: <1484731386-3752-1-git-send-email-s.vyazmitinov@brain4net.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] kni: add bulk function to free mbufs 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, 18 Jan 2017 09:23:15 -0000 Suggested-by: Stephen Hemminger Signed-off-by: Sergey Vyazmitinov --- v3: * Fixed issue with possible different mempools in buffer list. * Fixed issue with wrong rte_pktmbuf_alloc_bulk function return value processing in the kni_allocate_mbufs. --- lib/librte_mbuf/rte_mbuf.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 4476d75..69d314f 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -306,6 +306,9 @@ extern "C" { /** Alignment constraint of mbuf private area. */ #define RTE_MBUF_PRIV_ALIGN 8 +/** Maximum number of mbufs freed in bulk. */ +#define RTE_MBUF_BULK_FREE 64 + /** * Get the name of a RX offload flag * @@ -1261,6 +1264,52 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) } /** + * Free n packets mbuf back into its original mempool. + * + * Free each mbuf, and all its segments in case of chained buffers. Each + * segment is added back into its original mempool. + * + * @param mp + * The packets mempool. + * @param mbufs + * The packets mbufs array to be freed. + * @param n + * Number of packets. + */ +static inline void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, + unsigned int n) +{ + void *tofree[RTE_MBUF_BULK_FREE]; + struct rte_mempool *mp = NULL; + unsigned int i, count = 0; + + for (i = 0; i < n; i++) { + struct rte_mbuf *m, *m_next; + + for (m = mbufs[i]; m; m = m_next) { + m_next = m->next; + + if (count > 0 && + (unlikely(m->pool != mp || + count == RTE_MBUF_BULK_FREE))) { + rte_mempool_put_bulk(mp, tofree, count); + count = 0; + } + + mp = m->pool; + + if (likely(__rte_pktmbuf_prefree_seg(m) != NULL)) { + m->next = NULL; + tofree[count++] = m; + } + } + } + + if (likely(count > 0)) + rte_mempool_put_bulk(mp, tofree, count); +} + +/** * Creates a "clone" of the given packet mbuf. * * Walks through all segments of the given packet mbuf, and for each of them: -- 2.7.4