From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by dpdk.org (Postfix) with ESMTP id CD7F93237 for ; Fri, 13 Jul 2018 18:31:13 +0200 (CEST) Received: by mail-ed1-f46.google.com with SMTP id g12-v6so25017870edi.9 for ; Fri, 13 Jul 2018 09:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=R8R5prnDevvMRXOGwsaB3HicGCIrBaQzbkrp3ykxjXw=; b=KgX/Ieh/6XOHcWMuC+kBkHegUqGHGogREc9M9M84eJ99kZhMmi+aNIRIEits4MaT7d qAMgT1uP6mwe5lEn/5t8rkhR0Ltn1aZADUb+zFSKTRvRwGS/iHMgT63hr/WS89rGSCfM +2+snNAApLfglziwN1E57GLXeQJsuxeDWrzJUaSczaaYEdiZEBdV0L5I/YWG01MyOR60 Xj8QWXh27tVhEivgvEfFii0NaJapZ6GCaKgjTcz3YSl2SItI1DBnahpzVtbdDi9o0457 JVTxKEXjg89iiMWVcuPEC7lsAZgtvSmZd3r0xcr4v+Ew4a1dxAzLvW8Q0htV51BYhtMz zhAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=R8R5prnDevvMRXOGwsaB3HicGCIrBaQzbkrp3ykxjXw=; b=HPyy5pTxfcqP5oT/yfhhp4Dawr1w693vcJI8DpQLWAHhWU5hBHQ/yYaj0r+fZSJGoe ZvTsFYVwrqCa+PSPTruX942Riw98iFV1yRDQxuaUgKPdO5NwlcKc/+mC17Q4HsEB9IuD MjY3jjZlPZMeZ555fxnTvLwp7Xp3WEJTouTWbs7iOFrN8dJcl1Cq8V4a+0E4Zt7EHcj3 Bk9REcwIEaCfCD6Pogs42OwUhEKVxLJCXmgHdyWfimanBwxHWwIkvCvjJVprBwBSyISJ CUuJr5UlVA6K9Mt5o2YUCAhTIRzagMa7z+NGEN4nnJgdFGT89nuu6POro6qO/QiFSYT9 jQGw== X-Gm-Message-State: AOUpUlHgYNktB3WgBipkK9YW5vj0H4QdX/k+OUb6Z9A3vhFVsLmhXOiZ fjssUDTmILFB3CgjXHxYvKG+TmwlFCPhuJ8QFmBhmg== X-Google-Smtp-Source: AAOMgpcvJQTkQ7sQpMsVMLDkx6neWHdhzjLBbAex43Y01hkhpT6kzt+G4lT4c7EtV40nfT3S8jPtC62Q4dnq0dwbX4M= X-Received: by 2002:a50:f098:: with SMTP id v24-v6mr7961050edl.90.1531499470599; Fri, 13 Jul 2018 09:31:10 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:b194:0:0:0:0:0 with HTTP; Fri, 13 Jul 2018 09:31:10 -0700 (PDT) In-Reply-To: References: From: Alejandro Lucero Date: Fri, 13 Jul 2018 17:31:10 +0100 Message-ID: To: Anatoly Burakov Cc: dev , srinath.mannam@broadcom.com, scott.branden@broadcom.com, Ajit Khaparde Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [RFC 06/11] malloc: enable allocating from named heaps 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: Fri, 13 Jul 2018 16:31:14 -0000 On Fri, Jul 6, 2018 at 2:17 PM, Anatoly Burakov wrote: > Add new malloc API to allocate memory from heap referenced to by > specified name. > > Signed-off-by: Anatoly Burakov > --- > lib/librte_eal/common/include/rte_malloc.h | 25 ++++++++++++++++++++++ > lib/librte_eal/common/malloc_heap.c | 2 +- > lib/librte_eal/common/malloc_heap.h | 6 ++++++ > lib/librte_eal/common/rte_malloc.c | 11 ++++++++++ > lib/librte_eal/rte_eal_version.map | 1 + > 5 files changed, 44 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/common/include/rte_malloc.h > b/lib/librte_eal/common/include/rte_malloc.h > index 7cbcd3184..f1bcd9b65 100644 > --- a/lib/librte_eal/common/include/rte_malloc.h > +++ b/lib/librte_eal/common/include/rte_malloc.h > @@ -213,6 +213,31 @@ rte_zmalloc_socket(const char *type, size_t size, > unsigned align, int socket); > void * > rte_calloc_socket(const char *type, size_t num, size_t size, unsigned > align, int socket); > > +/** > + * This function allocates memory from a specified named heap. > + * > + * @param name > + * Name of the heap to allocate from. > + * @param type > + * A string identifying the type of allocated objects (useful for debug > + * purposes, such as identifying the cause of a memory leak). Can be > NULL. > + * @param size > + * Size (in bytes) to be allocated. > + * @param align > + * If 0, the return is a pointer that is suitably aligned for any kind > of > + * variable (in the same manner as malloc()). > + * Otherwise, the return is a pointer that is a multiple of *align*. In > + * this case, it must be a power of two. (Minimum alignment is the > + * cacheline size, i.e. 64-bytes) > + * @return > + * - NULL on error. Not enough memory, or invalid arguments (size is 0, > + * align is not a power of two). > + * - Otherwise, the pointer to the allocated object. > + */ > +__rte_experimental void * > +rte_malloc_from_heap(const char *heap_name, const char *type, size_t size, > + unsigned int align); > + > /** > * Frees the memory space pointed to by the provided pointer. > * > diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/ > malloc_heap.c > index 8437d33b3..a33acc252 100644 > --- a/lib/librte_eal/common/malloc_heap.c > +++ b/lib/librte_eal/common/malloc_heap.c > @@ -494,7 +494,7 @@ alloc_more_mem_on_socket(struct malloc_heap *heap, > size_t size, int socket, > } > > /* this will try lower page sizes first */ > -static void * > +void * > malloc_heap_alloc_on_heap_id(const char *type, size_t size, > unsigned int heap_id, unsigned int flags, size_t align, > size_t bound, bool contig) > diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/ > malloc_heap.h > index 4f3137260..a7e408c99 100644 > --- a/lib/librte_eal/common/malloc_heap.h > +++ b/lib/librte_eal/common/malloc_heap.h > @@ -29,6 +29,12 @@ void * > malloc_heap_alloc(const char *type, size_t size, int socket, unsigned int > flags, > size_t align, size_t bound, bool contig); > > +/* allocate from specified heap id */ > +void * > +malloc_heap_alloc_on_heap_id(const char *type, size_t size, > + unsigned int heap_id, unsigned int flags, size_t align, > + size_t bound, bool contig); > + > int > malloc_heap_find_named_heap_idx(const char *name); > > diff --git a/lib/librte_eal/common/rte_malloc.c > b/lib/librte_eal/common/rte_malloc.c > index 2508abdb1..215876a59 100644 > --- a/lib/librte_eal/common/rte_malloc.c > +++ b/lib/librte_eal/common/rte_malloc.c > @@ -55,6 +55,17 @@ rte_malloc_socket(const char *type, size_t size, > unsigned int align, > align == 0 ? 1 : align, 0, false); > } > > +void * > +rte_malloc_from_heap(const char *heap_name, const char *type, size_t size, > + unsigned int align) > +{ > + int heap_idx = malloc_heap_find_named_heap_idx(heap_name); > + if (heap_idx < 0) > + return NULL; > error log? > + return malloc_heap_alloc_on_heap_id(type, size, heap_idx, 0, > + align == 0 ? 1 : align, 0, false); > +} > + > /* > * Allocate memory on default heap. > */ > diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_ > version.map > index 786df1e39..716a7585d 100644 > --- a/lib/librte_eal/rte_eal_version.map > +++ b/lib/librte_eal/rte_eal_version.map > @@ -278,6 +278,7 @@ EXPERIMENTAL { > rte_fbarray_set_used; > rte_log_register_type_and_pick_level; > rte_malloc_dump_heaps; > + rte_malloc_from_heap; > rte_malloc_get_stats_from_heap; > rte_mem_alloc_validator_register; > rte_mem_alloc_validator_unregister; > -- > 2.17.1 >