DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gowrishankar <gowrishankar.m@linux.vnet.ibm.com>
To: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
Cc: Anatoly Burakov <anatoly.burakov@intel.com>,
	dev@dpdk.org, Thomas Monjalon <thomas@monjalon.net>,
	Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] eal/malloc: merge malloc_elems in heap if they are contiguous
Date: Thu,  3 May 2018 15:41:35 +0530	[thread overview]
Message-ID: <ebc0cbca46c5df7ebc1a04717b9bb83f2c2d0204.1525341819.git.gowrishankar.m@linux.vnet.ibm.com> (raw)
In-Reply-To: <cover.1525341819.git.gowrishankar.m@linux.vnet.ibm.com>
In-Reply-To: <cover.1525341819.git.gowrishankar.m@linux.vnet.ibm.com>

From: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>

During malloc heap init, if there are malloc_elems contiguous in
virt addresses, they could be merged so that, merged malloc_elem
would guarantee larger free memory size than its actual hugepage
size, it was created for.

Fixes: fafcc11985 ("mem: rework memzone to be allocated by malloc")
Cc: stable@dpdk.org

Signed-off-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
---
 lib/librte_eal/common/malloc_heap.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c
index 267a4c6..1cacf7f 100644
--- a/lib/librte_eal/common/malloc_heap.c
+++ b/lib/librte_eal/common/malloc_heap.c
@@ -213,7 +213,9 @@
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	unsigned ms_cnt;
-	struct rte_memseg *ms;
+	struct rte_memseg *ms, *prev_ms = NULL;
+	struct malloc_elem *elem, *prev_elem;
+	int ret;
 
 	if (mcfg == NULL)
 		return -1;
@@ -222,6 +224,32 @@
 			(ms_cnt < RTE_MAX_MEMSEG) && (ms->len > 0);
 			ms_cnt++, ms++) {
 		malloc_heap_add_memseg(&mcfg->malloc_heaps[ms->socket_id], ms);
+		elem = (struct malloc_elem *)ms->addr;
+		if (prev_ms != NULL && \
+			(ms->socket_id == prev_ms->socket_id)) {
+			prev_elem = (struct malloc_elem *)prev_ms->addr;
+
+			/* prev_elem and elem to be contiguous for the resize.
+			   Other wise look for prev_elem in iterations */
+			if (elem != RTE_PTR_ADD(prev_elem,
+				prev_elem->size + MALLOC_ELEM_OVERHEAD)) {
+				prev_ms = ms;
+				continue;
+			}
+			/* end BUSY elem pointed by prev_elem can be merged
+			   with prev_elem itself, as it expands it size now.
+			 */
+			prev_elem->size += MALLOC_ELEM_OVERHEAD;
+
+			/* preserve end BUSY elem that points to current elem,
+			   or else free_list will be broken */
+			ret = malloc_elem_resize(prev_elem,
+				prev_elem->size + elem->size - MALLOC_ELEM_OVERHEAD);
+			if (ret < 0)
+				prev_elem = elem;
+		} else {
+			prev_ms = ms;
+		}
 	}
 
 	return 0;
-- 
1.9.1

  reply	other threads:[~2018-05-03 10:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 10:11 [dpdk-dev] [PATCH 0/2] eal/malloc: fix wrong heap initialization over multiple memsegs Gowrishankar
2018-05-03 10:11 ` Gowrishankar [this message]
2018-05-04  9:29   ` [dpdk-dev] [PATCH 1/2] eal/malloc: merge malloc_elems in heap if they are contiguous Burakov, Anatoly
2018-05-04 10:41     ` gowrishankar muthukrishnan
2018-05-04 11:02       ` Burakov, Anatoly
2018-05-03 10:11 ` [dpdk-dev] [PATCH 2/2] eal/malloc: fix heap index to correctly insert memseg Gowrishankar
2018-05-18 13:10 ` [dpdk-dev] [PATCH 0/2] eal/malloc: fix wrong heap initialization over multiple memsegs Thomas Monjalon
2018-05-19  1:35   ` gowrishankar muthukrishnan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ebc0cbca46c5df7ebc1a04717b9bb83f2c2d0204.1525341819.git.gowrishankar.m@linux.vnet.ibm.com \
    --to=gowrishankar.m@linux.vnet.ibm.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=sergio.gonzalez.monroy@intel.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).