From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com [209.85.215.45]) by dpdk.org (Postfix) with ESMTP id 78486FB44 for ; Thu, 19 Jan 2017 05:47:10 +0100 (CET) Received: by mail-lf0-f45.google.com with SMTP id n124so27281785lfd.2 for ; Wed, 18 Jan 2017 20:47:10 -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:in-reply-to:references; bh=0QBLvXoHH76njj9gtnkTjbvj5mnqPNYR9nStJFaduY8=; b=I0j2OqApxbakz+oFJ7ozjAp0a7pQENcBh5aMY7JB1j7/sEtbo+eIGguJ+sMv+qbMjL z6X09Omi2csW4LkwMgbKpj/3Bf4XV7tL2cPGa/riQReTakwygy60lgi6lc6hE4fldtWE W0Vltbe6kvQKINLKsbs/EjNHRc00wEa2Y60tM= 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:in-reply-to :references; bh=0QBLvXoHH76njj9gtnkTjbvj5mnqPNYR9nStJFaduY8=; b=AcKP9Jw9YFyt1evtL2g8vsjWI7IQbjR1v7Q1JjtFDluHkkwk64wYAyUcgrBL5uFi2A +iOjEyXmstIkTvtZfkH4axWuB+TeSKOQJDI3wioyvrSc+TwdgDIuKjK652cflb1lIKIu HP+cY0lH1ZQOxdu51XrpSA7A6+LLmDA3zvQTpPbhLLu/yd7B5r2nTU7kW2iA/34YN0Oy Pt5bwatebsbfaOoCiRoyjdl7jUE077/iwMCVXZkQjopvuOraAW7PSJSPZYyv5EeSroAP q3ao9FDByJHpbBdmC8u2zvwU659+2l+h0bAri6n/zqrPo0/vgd9oZ3nnCOIDpjDD/+Bl QL1w== X-Gm-Message-State: AIkVDXKcI588UFRRJe7rLjXi8HbZF2L/DgxcoyXgxb3L4MrSZlLcRx7Iy7713C/XI6hsf9xn X-Received: by 10.25.145.4 with SMTP id t4mr2137151lfd.171.1484801230066; Wed, 18 Jan 2017 20:47:10 -0800 (PST) Received: from localhost.localdomain ([91.201.72.212]) by smtp.gmail.com with ESMTPSA id s63sm1080361lja.49.2017.01.18.20.47.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 20:47:09 -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, mirqus@gmail.com, Sergey Vyazmitinov Date: Thu, 19 Jan 2017 11:46:58 +0700 Message-Id: <1484801219-1312-2-git-send-email-s.vyazmitinov@brain4net.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484801219-1312-1-git-send-email-s.vyazmitinov@brain4net.com> References: <1484801219-1312-1-git-send-email-s.vyazmitinov@brain4net.com> Subject: [dpdk-dev] [PATCH v6 1/2] 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: Thu, 19 Jan 2017 04:47:10 -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