DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yongseok Koh <yskoh@mellanox.com>
To: Anatoly Burakov <anatoly.burakov@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	Shahaf Shuler <shahafs@mellanox.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	"shreyansh.jain@nxp.com" <shreyansh.jain@nxp.com>
Subject: Re: [dpdk-dev] [PATCH 1/4] malloc: separate creating memseg list and malloc heap
Date: Fri, 14 Dec 2018 09:33:38 +0000	[thread overview]
Message-ID: <20181214093328.GA12221@mtidpdk.mti.labs.mlnx> (raw)
In-Reply-To: <a1ea86b9cc3a88e028f9ea6603ff69ca61565b41.1543495935.git.anatoly.burakov@intel.com>

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.
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---

Acked-by: Yongseok Koh <yskoh@mellanox.com>

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(-)
> 
> 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;
>  }
>  
> -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 = rte_eal_get_configuration()->mem_config;
>  	char fbarray_name[RTE_FBARRAY_NAME_LEN];
> @@ -1117,17 +1118,17 @@ malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr,
>  	if (msl == NULL) {
>  		RTE_LOG(ERR, EAL, "Couldn't find empty memseg list\n");
>  		rte_errno = ENOSPC;
> -		return -1;
> +		return NULL;
>  	}
>  
>  	snprintf(fbarray_name, sizeof(fbarray_name) - 1, "%s_%p",
> -			heap->name, va_addr);
> +			seg_name, va_addr);
>  
>  	/* 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 = &msl->memseg_arr;
>  
> @@ -1143,32 +1144,39 @@ malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr,
>  		ms->len = page_sz;
>  		ms->nchannel = rte_memory_get_nchannel();
>  		ms->nrank = rte_memory_get_nrank();
> -		ms->socket_id = heap->socket_id;
> +		ms->socket_id = socket_id;
>  	}
>  
>  	/* set up the memseg list */
>  	msl->base_va = va_addr;
>  	msl->page_sz = page_sz;
> -	msl->socket_id = heap->socket_id;
> +	msl->socket_id = socket_id;
>  	msl->len = seg_len;
>  	msl->version = 0;
>  	msl->external = 1;
>  
> +	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);
>  
>  	/* 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);
>  
> -	heap->total_size += seg_len;
> +	heap->total_size += msl->len;
>  
>  	/* all done! */
>  	RTE_LOG(DEBUG, EAL, "Added segment for heap %s starting at %p\n",
> -			heap->name, va_addr);
> +			heap->name, msl->base_va);
>  
>  	/* 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);
>  
>  	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 char *heap_name);
>  int
>  malloc_heap_destroy(struct malloc_heap *heap);
>  
> +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);
>  
>  int
>  malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,
> diff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_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, void *va_addr, size_t len,
>  {
>  	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
>  	struct malloc_heap *heap = NULL;
> +	struct rte_memseg_list *msl;
>  	unsigned int n;
>  	int ret;
>  
> @@ -373,9 +374,15 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,
>  		goto unlock;
>  	}
>  
> +	msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n, page_sz,
> +			heap_name, heap->socket_id);
> +	if (msl == NULL) {
> +		ret = -1;
> +		goto unlock;
> +	}
> +
>  	rte_spinlock_lock(&heap->lock);
> -	ret = malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n,
> -			page_sz);
> +	ret = malloc_heap_add_external_memory(heap, msl);
>  	rte_spinlock_unlock(&heap->lock);
>  
>  unlock:
> -- 
> 2.17.1

  reply	other threads:[~2018-12-14  9:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 13:48 [dpdk-dev] [PATCH 0/4] Allow using external memory without malloc Anatoly Burakov
2018-11-29 13:48 ` [dpdk-dev] [PATCH 1/4] malloc: separate creating memseg list and malloc heap Anatoly Burakov
2018-12-14  9:33   ` Yongseok Koh [this message]
2018-11-29 13:48 ` [dpdk-dev] [PATCH 2/4] malloc: separate destroying memseg list and heap data Anatoly Burakov
2018-12-14  9:34   ` Yongseok Koh
2018-11-29 13:48 ` [dpdk-dev] [PATCH 3/4] mem: allow registering external memory areas Anatoly Burakov
2018-12-14  9:55   ` Yongseok Koh
2018-12-14 11:03     ` Burakov, Anatoly
2018-11-29 13:48 ` [dpdk-dev] [PATCH 4/4] mem: allow usage of non-heap external memory in multiprocess Anatoly Burakov
2018-12-14  9:56   ` Yongseok Koh
2018-12-02  5:48 ` [dpdk-dev] [PATCH 0/4] Allow using external memory without malloc Shahaf Shuler
2018-12-02 23:28   ` Yongseok Koh
2018-12-03 10:23     ` Burakov, Anatoly
2018-12-12 12:55       ` Yongseok Koh
2018-12-12 13:17         ` Burakov, Anatoly
2018-12-14 11:50 ` [dpdk-dev] [PATCH v2 " Anatoly Burakov
2018-12-20 15:32   ` [dpdk-dev] [PATCH v3 " Anatoly Burakov
2018-12-20 16:16     ` Stephen Hemminger
2018-12-20 17:18       ` Thomas Monjalon
2018-12-21  9:17         ` Burakov, Anatoly
2018-12-20 17:17     ` Thomas Monjalon
2018-12-20 15:32   ` [dpdk-dev] [PATCH v3 1/4] malloc: separate creating memseg list and malloc heap Anatoly Burakov
2018-12-20 15:32   ` [dpdk-dev] [PATCH v3 2/4] malloc: separate destroying memseg list and heap data Anatoly Burakov
2018-12-20 15:32   ` [dpdk-dev] [PATCH v3 3/4] mem: allow registering external memory areas Anatoly Burakov
2018-12-20 15:32   ` [dpdk-dev] [PATCH v3 4/4] mem: allow usage of non-heap external memory in multiprocess Anatoly Burakov
2018-12-14 11:50 ` [dpdk-dev] [PATCH v2 1/4] malloc: separate creating memseg list and malloc heap Anatoly Burakov
2018-12-14 11:50 ` [dpdk-dev] [PATCH v2 2/4] malloc: separate destroying memseg list and heap data Anatoly Burakov
2018-12-14 11:50 ` [dpdk-dev] [PATCH v2 3/4] mem: allow registering external memory areas Anatoly Burakov
2018-12-14 11:50 ` [dpdk-dev] [PATCH v2 4/4] mem: allow usage of non-heap external memory in multiprocess Anatoly Burakov

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=20181214093328.GA12221@mtidpdk.mti.labs.mlnx \
    --to=yskoh@mellanox.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=shahafs@mellanox.com \
    --cc=shreyansh.jain@nxp.com \
    --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).