From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by dpdk.org (Postfix) with ESMTP id 293C82BD5 for ; Thu, 3 May 2018 12:11:47 +0200 (CEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w43A9tx2118859 for ; Thu, 3 May 2018 06:11:46 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hqu66mg9j-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 03 May 2018 06:11:46 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 3 May 2018 11:11:43 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 3 May 2018 11:11:41 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w43ABfSn14483950; Thu, 3 May 2018 10:11:41 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6376E11C052; Thu, 3 May 2018 11:03:15 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 277CD11C04A; Thu, 3 May 2018 11:03:14 +0100 (BST) Received: from chozha.in.ibm.com (unknown [9.124.35.140]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 3 May 2018 11:03:13 +0100 (BST) From: Gowrishankar To: Sergio Gonzalez Monroy Cc: Anatoly Burakov , dev@dpdk.org, Thomas Monjalon , Gowrishankar Muthukrishnan , stable@dpdk.org Date: Thu, 3 May 2018 15:41:35 +0530 X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 18050310-0008-0000-0000-000004F27FA8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050310-0009-0000-0000-00001E86A54C Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-03_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805030095 Subject: [dpdk-dev] [PATCH 1/2] eal/malloc: merge malloc_elems in heap if they are contiguous 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, 03 May 2018 10:11:47 -0000 From: Gowrishankar Muthukrishnan 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 --- 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