From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yongseok Koh Subject: Re: [PATCH 1/4] malloc: separate creating memseg list and malloc heap Date: Fri, 14 Dec 2018 09:33:38 +0000 Message-ID: <20181214093328.GA12221@mtidpdk.mti.labs.mlnx> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "dev@dpdk.org" , Shahaf Shuler , Thomas Monjalon , "shreyansh.jain@nxp.com" To: Anatoly Burakov Return-path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130055.outbound.protection.outlook.com [40.107.13.55]) by dpdk.org (Postfix) with ESMTP id 6659B1B94E for ; Fri, 14 Dec 2018 10:33:43 +0100 (CET) In-Reply-To: Content-Language: en-US Content-ID: <55DC7D17611C7744B355629CC5B9EB06@eurprd05.prod.outlook.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, Nov 29, 2018 at 01:48:32PM +0000, Anatoly Burakov wrote: > Currently, creating external malloc heap involves also creating > a memseg list backing that malloc heap. We need to have them as > separate functions, to allow creating memseg lists without > creating a malloc heap. >=20 > Signed-off-by: Anatoly Burakov > --- Acked-by: Yongseok Koh Thanks > lib/librte_eal/common/malloc_heap.c | 34 ++++++++++++++++++----------- > lib/librte_eal/common/malloc_heap.h | 9 ++++++-- > lib/librte_eal/common/rte_malloc.c | 11 ++++++++-- > 3 files changed, 37 insertions(+), 17 deletions(-) >=20 > diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/= malloc_heap.c > index c6a6d4f6b..25693481f 100644 > --- a/lib/librte_eal/common/malloc_heap.c > +++ b/lib/librte_eal/common/malloc_heap.c > @@ -1095,9 +1095,10 @@ destroy_seg(struct malloc_elem *elem, size_t len) > return 0; > } > =20 > -int > -malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, > - rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz) > +struct rte_memseg_list * > +malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], > + unsigned int n_pages, size_t page_sz, const char *seg_name, > + unsigned int socket_id) > { > struct rte_mem_config *mcfg =3D rte_eal_get_configuration()->mem_config= ; > char fbarray_name[RTE_FBARRAY_NAME_LEN]; > @@ -1117,17 +1118,17 @@ malloc_heap_add_external_memory(struct malloc_hea= p *heap, void *va_addr, > if (msl =3D=3D NULL) { > RTE_LOG(ERR, EAL, "Couldn't find empty memseg list\n"); > rte_errno =3D ENOSPC; > - return -1; > + return NULL; > } > =20 > snprintf(fbarray_name, sizeof(fbarray_name) - 1, "%s_%p", > - heap->name, va_addr); > + seg_name, va_addr); > =20 > /* create the backing fbarray */ > if (rte_fbarray_init(&msl->memseg_arr, fbarray_name, n_pages, > sizeof(struct rte_memseg)) < 0) { > RTE_LOG(ERR, EAL, "Couldn't create fbarray backing the memseg list\n")= ; > - return -1; > + return NULL; > } > arr =3D &msl->memseg_arr; > =20 > @@ -1143,32 +1144,39 @@ malloc_heap_add_external_memory(struct malloc_hea= p *heap, void *va_addr, > ms->len =3D page_sz; > ms->nchannel =3D rte_memory_get_nchannel(); > ms->nrank =3D rte_memory_get_nrank(); > - ms->socket_id =3D heap->socket_id; > + ms->socket_id =3D socket_id; > } > =20 > /* set up the memseg list */ > msl->base_va =3D va_addr; > msl->page_sz =3D page_sz; > - msl->socket_id =3D heap->socket_id; > + msl->socket_id =3D socket_id; > msl->len =3D seg_len; > msl->version =3D 0; > msl->external =3D 1; > =20 > + return msl; > +} > + > +int > +malloc_heap_add_external_memory(struct malloc_heap *heap, > + struct rte_memseg_list *msl) > +{ > /* erase contents of new memory */ > - memset(va_addr, 0, seg_len); > + memset(msl->base_va, 0, msl->len); > =20 > /* now, add newly minted memory to the malloc heap */ > - malloc_heap_add_memory(heap, msl, va_addr, seg_len); > + malloc_heap_add_memory(heap, msl, msl->base_va, msl->len); > =20 > - heap->total_size +=3D seg_len; > + heap->total_size +=3D msl->len; > =20 > /* all done! */ > RTE_LOG(DEBUG, EAL, "Added segment for heap %s starting at %p\n", > - heap->name, va_addr); > + heap->name, msl->base_va); > =20 > /* notify all subscribers that a new memory area has been added */ > eal_memalloc_mem_event_notify(RTE_MEM_EVENT_ALLOC, > - va_addr, seg_len); > + msl->base_va, msl->len); > =20 > return 0; > } > diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/= malloc_heap.h > index e48996d52..255a315b8 100644 > --- a/lib/librte_eal/common/malloc_heap.h > +++ b/lib/librte_eal/common/malloc_heap.h > @@ -39,9 +39,14 @@ malloc_heap_create(struct malloc_heap *heap, const cha= r *heap_name); > int > malloc_heap_destroy(struct malloc_heap *heap); > =20 > +struct rte_memseg_list * > +malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[], > + unsigned int n_pages, size_t page_sz, const char *seg_name, > + unsigned int socket_id); > + > int > -malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr, > - rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz); > +malloc_heap_add_external_memory(struct malloc_heap *heap, > + struct rte_memseg_list *msl); > =20 > int > malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_ad= dr, > diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/r= te_malloc.c > index 0da5ad5e8..66bfe63c3 100644 > --- a/lib/librte_eal/common/rte_malloc.c > +++ b/lib/librte_eal/common/rte_malloc.c > @@ -340,6 +340,7 @@ rte_malloc_heap_memory_add(const char *heap_name, voi= d *va_addr, size_t len, > { > struct rte_mem_config *mcfg =3D rte_eal_get_configuration()->mem_config= ; > struct malloc_heap *heap =3D NULL; > + struct rte_memseg_list *msl; > unsigned int n; > int ret; > =20 > @@ -373,9 +374,15 @@ rte_malloc_heap_memory_add(const char *heap_name, vo= id *va_addr, size_t len, > goto unlock; > } > =20 > + msl =3D malloc_heap_create_external_seg(va_addr, iova_addrs, n, page_sz= , > + heap_name, heap->socket_id); > + if (msl =3D=3D NULL) { > + ret =3D -1; > + goto unlock; > + } > + > rte_spinlock_lock(&heap->lock); > - ret =3D malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n, > - page_sz); > + ret =3D malloc_heap_add_external_memory(heap, msl); > rte_spinlock_unlock(&heap->lock); > =20 > unlock: > --=20 > 2.17.1