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 B161734EF for ; Thu, 3 May 2018 12:11:49 +0200 (CEST) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w43A8qCG146905 for ; Thu, 3 May 2018 06:11:49 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hr08rgkdf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 03 May 2018 06:11:48 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 3 May 2018 11:11:46 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 3 May 2018 11:11:44 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w43ABhVM12255510; Thu, 3 May 2018 10:11:43 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC12911C04A; Thu, 3 May 2018 11:03:17 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACFED11C050; Thu, 3 May 2018 11:03:16 +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:16 +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:36 +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-0040-0000-0000-000004547F7F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18050310-0041-0000-0000-000020F8A50C 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 2/2] eal/malloc: fix heap index to correctly insert memseg 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:50 -0000 From: Gowrishankar Muthukrishnan When there are multiple memsegs created and adding new memseg would cause bigger heap size, its index in free_head list should be based on new size of heap. Currently, only the size of elem is accounted as in malloc_elem_free_list_insert. As heap total size gets bigger, list of those memsegs should be at the right index, so that malloc_heap_alloc would find suitable element for the requested memory size by applications. Fixes: b0489e7bca ("malloc: fix linear complexity") Cc: stable@dpdk.org Signed-off-by: Gowrishankar Muthukrishnan --- Eg. Below heap is in one numa socket, for the size of 1G (i.e 64*16MB). All corresponding malloc_elem are always added in heap index 8, as their size is always 16MB (and due to which, index is also 8 always). free_head = {{lh_first = 0x0}, {lh_first = 0x0}, {lh_first = 0x0}, { lh_first = 0x0}, {lh_first = 0x0}, {lh_first = 0x0}, {lh_first = 0x0}, { lh_first = 0x0}, {lh_first = 0x7efd3f000000}, {lh_first = 0x0}, {lh_first = 0x0}, { lh_first = 0x0}, {lh_first = 0x0}}, alloc_count = 6, total_size = 1073733632}, Ideally, this list of memsegs should ideally be at slot 12, as they grow heap for 1G. --- lib/librte_eal/common/malloc_heap.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c index 1cacf7f..f686e5e 100644 --- a/lib/librte_eal/common/malloc_heap.c +++ b/lib/librte_eal/common/malloc_heap.c @@ -105,10 +105,32 @@ ms->len - MALLOC_ELEM_OVERHEAD); end_elem = RTE_PTR_ALIGN_FLOOR(end_elem, RTE_CACHE_LINE_SIZE); const size_t elem_size = (uintptr_t)end_elem - (uintptr_t)start_elem; + size_t cur_idx, new_idx, heap_size; malloc_elem_init(start_elem, heap, ms, elem_size); malloc_elem_mkend(end_elem, start_elem); + + /* Compare heap index based on its current size as well as + * its new size with memseg added. If new size needs new index + * move its free_head to the new slot. + */ + cur_idx = malloc_elem_free_list_index(heap->total_size); + heap_size = heap->total_size + elem_size; + new_idx = malloc_elem_free_list_index(heap_size); + if (cur_idx != new_idx) { + heap->free_head[new_idx] = heap->free_head[cur_idx]; + memset(&heap->free_head[cur_idx], + 0, sizeof(heap->free_head[cur_idx])); + } + + /* malloc_elem_free_list_insert calculates index based on + * elem->size, hence we set elem->size as new heap size, + * while inserting this elem. After that, we reset elem->size + * to its original value. A minor hack though!. + */ + start_elem->size = heap_size; malloc_elem_free_list_insert(start_elem); + start_elem->size = elem_size; heap->total_size += elem_size; } -- 1.9.1