From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by dpdk.org (Postfix) with ESMTP id EBB359AD3 for ; Mon, 16 May 2016 18:53:30 +0200 (CEST) Received: by mail-pf0-f195.google.com with SMTP id y7so16234353pfb.0 for ; Mon, 16 May 2016 09:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Xi5h9+Dj8Q1tCYQlOCehVTBFG1tBNp1TehX/c7sAegw=; b=XfemyQT5bBG0bLvl9t5AaKOYJ3TFBqv1+MozIpUtDvSl1Y0Z+d+cimzrwyvJeMEDm/ CQ2Mph4SlS6Y900KKDfY9FCU9Pe2lUtUcoqPRhFBGxMM41WDbCFCKs9qehBzOUC4QqG4 z8DJwDFuJABXjdQQjsuGvc2LSEFUAsjPIK9DwKjboIWlCZ/5Bof4SibKA542tt99pslV C5yNvANvKEzc+6ZQrur2PPBAwpKSqf11OAw/l1T+LNoLga/dIo89j70J9jk6MKoTBR6U ylDC8muRITwHb69Ou0nzuG1hMrc0NcN3zvIczKCDPKdHuChYmQbg99tiDkleNDh0DeY6 3WlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Xi5h9+Dj8Q1tCYQlOCehVTBFG1tBNp1TehX/c7sAegw=; b=ZABIOAMhMC7oodFhg8nxzAKKEkho0eA3VsKIL/i/uCY09xXvpTHFMtOJo9lx97Juzs MX996xC11Jq01wEq4YACdYoYL+yP3Vf7pliNtLkiMSBQkjOgY83G7e/3D7AUfdJpuR40 YzcRDp54RI+cdKkN3ziigZRe4HY4ZrskpoKHBJQMRp3iQ8EjHE+sz7OMALTP7PpK60Ix gs9qPu9brWDYFZgCC0+nwLT4j68yJU4SR2ksM07/tQpWspwk8fVU3NmvZvDSlgwsCBcH Ao3F76pHTYnpNk3bu7JKWjllozqbYgF8XkOS5OTC2enMJ++fEnhN/6cXzoVJHx4mJyKs 9LaQ== X-Gm-Message-State: AOPr4FWHatSWBDR7+dONUFNgsm2S+Jm8U4I09tgbD5kw/1nj1hNC0W3gMaamJ8Pfl9ibLw== X-Received: by 10.98.99.66 with SMTP id x63mr46902020pfb.132.1463417610345; Mon, 16 May 2016 09:53:30 -0700 (PDT) Received: from localhost.localdomain (183.180.67.214.ap.gmobb-fix.jp. [183.180.67.214]) by smtp.gmail.com with ESMTPSA id zn7sm48578529pac.41.2016.05.16.09.53.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 May 2016 09:53:29 -0700 (PDT) From: Hiroyuki Mikita To: olivier.matz@6wind.com Cc: dev@dpdk.org Date: Tue, 17 May 2016 01:53:20 +0900 Message-Id: <1463417600-20943-1-git-send-email-h.mikita89@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463327436-6863-1-git-send-email-h.mikita89@gmail.com> References: <1463327436-6863-1-git-send-email-h.mikita89@gmail.com> Subject: [dpdk-dev] [PATCH v2] mbuf: decrease refcnt when detaching X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2016 16:53:31 -0000 The rte_pktmbuf_detach() function should decrease refcnt on a direct buffer. Signed-off-by: Hiroyuki Mikita --- v2: * introduced a new function rte_pktmbuf_detach2() which decrease refcnt. * marked rte_pktmbuf_detach() as deprecated. * added comments about refcnt to rte_pktmbuf_attach() and rte_pktmbuf_detach(). * checked refcnt when detaching in unit tests. * added this issue to release notes. app/test/test_mbuf.c | 9 +++++-- doc/guides/rel_notes/release_16_07.rst | 11 ++++----- lib/librte_mbuf/rte_mbuf.h | 43 +++++++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 98ff93a..2bf05eb 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -438,6 +438,7 @@ test_attach_from_different_pool(void) struct rte_mbuf *clone = NULL; struct rte_mbuf *clone2 = NULL; char *data, *c_data, *c_data2; + uint16_t refcnt; /* alloc a mbuf */ m = rte_pktmbuf_alloc(pktmbuf_pool); @@ -508,13 +509,17 @@ test_attach_from_different_pool(void) GOTO_FAIL("invalid refcnt in m\n"); /* detach the clones */ - rte_pktmbuf_detach(clone); + refcnt = rte_pktmbuf_detach2(clone); if (c_data != rte_pktmbuf_mtod(clone, char *)) GOTO_FAIL("clone was not detached properly\n"); + if (refcnt != 2 || rte_mbuf_refcnt_read(m) != 2) + GOTO_FAIL("invalid refcnt in m\n"); - rte_pktmbuf_detach(clone2); + refcnt = rte_pktmbuf_detach2(clone2); if (c_data2 != rte_pktmbuf_mtod(clone2, char *)) GOTO_FAIL("clone2 was not detached properly\n"); + if (refcnt != 1 || rte_mbuf_refcnt_read(m) != 1) + GOTO_FAIL("invalid refcnt in m\n"); /* free the clones and the initial mbuf */ rte_pktmbuf_free(clone2); diff --git a/doc/guides/rel_notes/release_16_07.rst b/doc/guides/rel_notes/release_16_07.rst index f6d543c..9678c1f 100644 --- a/doc/guides/rel_notes/release_16_07.rst +++ b/doc/guides/rel_notes/release_16_07.rst @@ -77,13 +77,10 @@ Other Known Issues ------------ -This section should contain new known issues in this release. Sample format: - -* **Add title in present tense with full stop.** - - Add a short 1-2 sentence description of the known issue in the present - tense. Add information on any known workarounds. - +* The ``rte_pktmbuf_detach()`` function does not decrement the direct + mbuf's reference counter. It leads a memory leak of the direct + mbuf. The workaround is to explicitly decrement the reference + counter or use ``rte_pktmbuf_detach2()``. API Changes ----------- diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 529debb..c0a592d 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1408,6 +1408,7 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool, * * After attachment we refer the mbuf we attached as 'indirect', * while mbuf we attached to as 'direct'. + * The direct mbuf's reference counter is incremented. * Right now, not supported: * - attachment for already indirect mbuf (e.g. - mi has to be direct). * - mbuf we trying to attach (mi) is used by someone else @@ -1459,15 +1460,50 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) /** * Detach an indirect packet mbuf. * + * Note: It is deprecated. + * The direct mbuf's reference counter is not decremented. + * + * - restore original mbuf address and length values. + * - reset pktmbuf data and data_len to their default values. + * All other fields of the given packet mbuf will be left intact. + * + * @param m + * The indirect attached packet mbuf. + */ +static inline void __rte_deprecated rte_pktmbuf_detach(struct rte_mbuf *m) +{ + struct rte_mempool *mp = m->pool; + uint32_t mbuf_size, buf_len, priv_size; + + priv_size = rte_pktmbuf_priv_size(mp); + mbuf_size = sizeof(struct rte_mbuf) + priv_size; + buf_len = rte_pktmbuf_data_room_size(mp); + + m->priv_size = priv_size; + m->buf_addr = (char *)m + mbuf_size; + m->buf_physaddr = rte_mempool_virt2phy(mp, m) + mbuf_size; + m->buf_len = (uint16_t)buf_len; + m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len); + m->data_len = 0; + m->ol_flags = 0; +} + +/** + * Detach an indirect packet mbuf. + * * - restore original mbuf address and length values. * - reset pktmbuf data and data_len to their default values. * All other fields of the given packet mbuf will be left intact. + * - decrement the direct mbuf's reference counter. * * @param m * The indirect attached packet mbuf. + * @return + * The updated value of the direct mbuf's reference counter. */ -static inline void rte_pktmbuf_detach(struct rte_mbuf *m) +static inline uint16_t rte_pktmbuf_detach2(struct rte_mbuf *m) { + struct rte_mbuf *md = rte_mbuf_from_indirect(m); struct rte_mempool *mp = m->pool; uint32_t mbuf_size, buf_len, priv_size; @@ -1482,6 +1518,8 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m) m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len); m->data_len = 0; m->ol_flags = 0; + + return rte_mbuf_refcnt_update(md, -1); } static inline struct rte_mbuf* __attribute__((always_inline)) @@ -1497,8 +1535,7 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m) */ if (RTE_MBUF_INDIRECT(m)) { struct rte_mbuf *md = rte_mbuf_from_indirect(m); - rte_pktmbuf_detach(m); - if (rte_mbuf_refcnt_update(md, -1) == 0) + if (rte_pktmbuf_detach2(m) == 0) __rte_mbuf_raw_free(md); } return m; -- 1.9.1