From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id 89C602A5B for ; Mon, 23 Jan 2017 13:59:51 +0100 (CET) Received: by mail-wm0-f51.google.com with SMTP id c206so153951607wme.0 for ; Mon, 23 Jan 2017 04:59:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SOxVBepvY/OYCXQcgvfXqWkOOeSHHdFgLj9/rKhEKAE=; b=awv8DO9xu7pLuuJE9c0IxdEjxp2xAm4M+i8j9qnfihwlqbqioGNRfcOIoFTj9eqBSD +yVpsjiMYjuMJcYpbHShqZttNpKBBzdTpw45BFGD45LBiS8xtvc/OG6UI5XwmjyjYKrc HqwR5STHqo/7qMb/DEE4+/lO6lREWOvHL30aP0MbQw7j766YT+qsT/h3MSUdSJZoyT+l xRtb/CakoNv7F2iB0mE8bEjVfTl7Lms74wfmjCuhAi74LI3kx62OyKyizKoCBJ7M4wIX fM7BUXcGI8EPikTJwKl1zCSIy6wWJMJbJa9Nroqv0qF7COnN54jbbSAtC6EjLY5QFU/o C0hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SOxVBepvY/OYCXQcgvfXqWkOOeSHHdFgLj9/rKhEKAE=; b=aHNjGgtD7bke7I8wPoybymOKH1o7opdzLdNxhCvlNijuM9gNcFCzGG+iHeMd73eV38 rzvS0CpeaRfsPTf9iJIuwkxXlC/oQ2eXdNftCOjKq27E3Lc3zIjFQVUtsQqWT10p9TPm e0joEmelWqo+W2zyLhkNtEjOTw9A66JKGECe6e39E316hN3y4PDehk3GH3CvmGN+Jute 5055xE8VpT/D/8Q55ER5IqIMXA+oB+oiwsqJ1u4ARmMxMDtL31T35JkfConeVLZz51kp j1vX7D7+Ja0YKibt0xgkH9KfTsgKDxif4SRFo/kCfDbJQmwN7j5Iv0LIIroG4Ewfsy+Z CPww== X-Gm-Message-State: AIkVDXK806OVdadrYxlkFIYdiaESmn/ot+mT6W6BjJyHY/1NAREGC5j9VcK02iFc+0MZdKAd X-Received: by 10.223.171.22 with SMTP id q22mr28568655wrc.27.1485176391177; Mon, 23 Jan 2017 04:59:51 -0800 (PST) Received: from platinum (2a01cb0c03c651000226b0fffeed02fc.ipv6.abo.wanadoo.fr. [2a01:cb0c:3c6:5100:226:b0ff:feed:2fc]) by smtp.gmail.com with ESMTPSA id o132sm20933594wmo.17.2017.01.23.04.59.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jan 2017 04:59:50 -0800 (PST) Date: Mon, 23 Jan 2017 13:59:47 +0100 From: Olivier Matz To: Sergey Vyazmitinov Cc: konstantin.ananyev@intel.com, stephen@networkplumber.org, yuanhan.liu@linux.intel.com, ferruh.yigit@intel.com, dev@dpdk.org, mirqus@gmail.com Message-ID: <20170123135947.0e5cbe83@platinum> In-Reply-To: <1484801219-1312-2-git-send-email-s.vyazmitinov@brain4net.com> References: <1484801219-1312-1-git-send-email-s.vyazmitinov@brain4net.com> <1484801219-1312-2-git-send-email-s.vyazmitinov@brain4net.com> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [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: Mon, 23 Jan 2017 12:59:51 -0000 Hi, On Thu, 19 Jan 2017 11:46:58 +0700, Sergey Vyazmitinov wrote: > 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. This parameter was removed, it could be removed from the API comment. > + * @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) I suggest we could use mbuf instead of pktmbuf in the function name. It's a bit shorter, and the function would also apply on ctrlmbuf. Also, the struct rte_mbuf **mbufs could probably be replaced by struct rte_mbuf * const *mbufs. > +{ > + 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. > * The function looks good to me, thank you. It looks also better than what I've suggested in [1], since it properly manage mbuf chains. On the other hand, I think my proposal could also help in drivers, where segments are already unchained. I'll submit it in a RFC. [1] http://dpdk.org/ml/archives/dev/2017-January/054538.html One more thing, maybe it's worth adding a basic test in app/test/test_mbuf.c. Thanks, Olivier