get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/32470/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 32470,
    "url": "https://patches.dpdk.org/api/patches/32470/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/5affaa884964f8cd1025e991caf58c67783a52ab.1513681966.git.anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<5affaa884964f8cd1025e991caf58c67783a52ab.1513681966.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/5affaa884964f8cd1025e991caf58c67783a52ab.1513681966.git.anatoly.burakov@intel.com",
    "date": "2017-12-19T11:14:44",
    "name": "[dpdk-dev,RFC,v2,17/23] eal: add backend support for contiguous memory allocation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "0b4609aa98a4d0e9f1d78866a8ceca5087050337",
    "submitter": {
        "id": 4,
        "url": "https://patches.dpdk.org/api/people/4/?format=api",
        "name": "Anatoly Burakov",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/5affaa884964f8cd1025e991caf58c67783a52ab.1513681966.git.anatoly.burakov@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/32470/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/32470/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 4ED2B1B211;\n\tTue, 19 Dec 2017 12:15:28 +0100 (CET)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n\tby dpdk.org (Postfix) with ESMTP id 9FA531B022\n\tfor <dev@dpdk.org>; Tue, 19 Dec 2017 12:14:56 +0100 (CET)",
            "from fmsmga008.fm.intel.com ([10.253.24.58])\n\tby fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t19 Dec 2017 03:14:55 -0800",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga008.fm.intel.com with ESMTP; 19 Dec 2017 03:14:53 -0800",
            "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tvBJBErYk003138; Tue, 19 Dec 2017 11:14:53 GMT",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id vBJBEqsb010302;\n\tTue, 19 Dec 2017 11:14:52 GMT",
            "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with LOCAL id vBJBEqF7010298;\n\tTue, 19 Dec 2017 11:14:52 GMT"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.45,426,1508828400\"; d=\"scan'208\";a=\"3709900\"",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "andras.kovacs@ericsson.com, laszlo.vadkeri@ericsson.com,\n\tkeith.wiles@intel.com, benjamin.walker@intel.com,\n\tbruce.richardson@intel.com, thomas@monjalon.net",
        "Date": "Tue, 19 Dec 2017 11:14:44 +0000",
        "Message-Id": "<5affaa884964f8cd1025e991caf58c67783a52ab.1513681966.git.anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 1.7.0.7",
        "In-Reply-To": [
            "<cover.1513681966.git.anatoly.burakov@intel.com>",
            "<cover.1513681966.git.anatoly.burakov@intel.com>"
        ],
        "References": [
            "<cover.1513681966.git.anatoly.burakov@intel.com>",
            "<cover.1513681966.git.anatoly.burakov@intel.com>"
        ],
        "Subject": "[dpdk-dev] [RFC v2 17/23] eal: add backend support for contiguous\n\tmemory allocation",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "No major changes, just add some checks in a few key places, and\na new parameter to pass around.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_eal/common/eal_common_memzone.c |  16 +++--\n lib/librte_eal/common/malloc_elem.c        | 105 +++++++++++++++++++++++------\n lib/librte_eal/common/malloc_elem.h        |   6 +-\n lib/librte_eal/common/malloc_heap.c        |  54 +++++++++------\n lib/librte_eal/common/malloc_heap.h        |   6 +-\n lib/librte_eal/common/rte_malloc.c         |  38 +++++++----\n 6 files changed, 158 insertions(+), 67 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c\nindex c571145..542ae90 100644\n--- a/lib/librte_eal/common/eal_common_memzone.c\n+++ b/lib/librte_eal/common/eal_common_memzone.c\n@@ -127,7 +127,8 @@ find_heap_max_free_elem(int *s, unsigned align)\n \n static const struct rte_memzone *\n memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,\n-\t\tint socket_id, unsigned flags, unsigned align, unsigned bound)\n+\t\tint socket_id, unsigned flags, unsigned align, unsigned bound,\n+\t\tbool contig)\n {\n \tstruct rte_memzone *mz;\n \tstruct rte_mem_config *mcfg;\n@@ -217,7 +218,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,\n \n \t/* allocate memory on heap */\n \tvoid *mz_addr = malloc_heap_alloc(NULL, requested_len, socket, flags,\n-\t\t\talign, bound);\n+\t\t\talign, bound, contig);\n \n \tif (mz_addr == NULL) {\n \t\trte_errno = ENOMEM;\n@@ -251,7 +252,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,\n static const struct rte_memzone *\n rte_memzone_reserve_thread_safe(const char *name, size_t len,\n \t\t\t\tint socket_id, unsigned flags, unsigned align,\n-\t\t\t\tunsigned bound)\n+\t\t\t\tunsigned bound, bool contig)\n {\n \tstruct rte_mem_config *mcfg;\n \tconst struct rte_memzone *mz = NULL;\n@@ -262,7 +263,7 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len,\n \trte_rwlock_write_lock(&mcfg->mlock);\n \n \tmz = memzone_reserve_aligned_thread_unsafe(\n-\t\tname, len, socket_id, flags, align, bound);\n+\t\tname, len, socket_id, flags, align, bound, contig);\n \n \trte_rwlock_write_unlock(&mcfg->mlock);\n \n@@ -279,7 +280,7 @@ rte_memzone_reserve_bounded(const char *name, size_t len, int socket_id,\n \t\t\t    unsigned flags, unsigned align, unsigned bound)\n {\n \treturn rte_memzone_reserve_thread_safe(name, len, socket_id, flags,\n-\t\t\t\t\t       align, bound);\n+\t\t\t\t\t       align, bound, false);\n }\n \n /*\n@@ -291,7 +292,7 @@ rte_memzone_reserve_aligned(const char *name, size_t len, int socket_id,\n \t\t\t    unsigned flags, unsigned align)\n {\n \treturn rte_memzone_reserve_thread_safe(name, len, socket_id, flags,\n-\t\t\t\t\t       align, 0);\n+\t\t\t\t\t       align, 0, false);\n }\n \n /*\n@@ -303,7 +304,8 @@ rte_memzone_reserve(const char *name, size_t len, int socket_id,\n \t\t    unsigned flags)\n {\n \treturn rte_memzone_reserve_thread_safe(name, len, socket_id,\n-\t\t\t\t\t       flags, RTE_CACHE_LINE_SIZE, 0);\n+\t\t\t\t\t       flags, RTE_CACHE_LINE_SIZE, 0,\n+\t\t\t\t\t       false);\n }\n \n int\ndiff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c\nindex 48ac604..a7d7cef 100644\n--- a/lib/librte_eal/common/malloc_elem.c\n+++ b/lib/librte_eal/common/malloc_elem.c\n@@ -45,6 +45,7 @@\n #include <rte_common.h>\n #include <rte_spinlock.h>\n \n+#include \"eal_memalloc.h\"\n #include \"malloc_elem.h\"\n #include \"malloc_heap.h\"\n \n@@ -122,32 +123,83 @@ malloc_elem_insert(struct malloc_elem *elem)\n }\n \n /*\n+ * Attempt to find enough physically contiguous memory in this block to store\n+ * our data. Assume that element has at least enough space to fit in the data,\n+ * so we just check the page addresses.\n+ */\n+static bool\n+elem_check_phys_contig(const struct rte_memseg_list *msl, void *start,\n+\t\tsize_t size) {\n+\tuint64_t page_sz;\n+\tvoid *aligned_start, *end, *aligned_end;\n+\tsize_t aligned_len;\n+\n+\t/* figure out how many pages we need to fit in current data */\n+\tpage_sz = msl->hugepage_sz;\n+\taligned_start = RTE_PTR_ALIGN_FLOOR(start, page_sz);\n+\tend = RTE_PTR_ADD(start, size);\n+\taligned_end = RTE_PTR_ALIGN_CEIL(end, page_sz);\n+\n+\taligned_len = RTE_PTR_DIFF(aligned_end, aligned_start);\n+\n+\treturn eal_memalloc_is_contig(msl, aligned_start, aligned_len);\n+}\n+\n+/*\n  * calculate the starting point of where data of the requested size\n  * and alignment would fit in the current element. If the data doesn't\n  * fit, return NULL.\n  */\n static void *\n elem_start_pt(struct malloc_elem *elem, size_t size, unsigned align,\n-\t\tsize_t bound)\n+\t\tsize_t bound, bool contig)\n {\n-\tconst size_t bmask = ~(bound - 1);\n-\tuintptr_t end_pt = (uintptr_t)elem +\n-\t\t\telem->size - MALLOC_ELEM_TRAILER_LEN;\n-\tuintptr_t new_data_start = RTE_ALIGN_FLOOR((end_pt - size), align);\n-\tuintptr_t new_elem_start;\n-\n-\t/* check boundary */\n-\tif ((new_data_start & bmask) != ((end_pt - 1) & bmask)) {\n-\t\tend_pt = RTE_ALIGN_FLOOR(end_pt, bound);\n-\t\tnew_data_start = RTE_ALIGN_FLOOR((end_pt - size), align);\n-\t\tif (((end_pt - 1) & bmask) != (new_data_start & bmask))\n-\t\t\treturn NULL;\n-\t}\n+\tsize_t elem_size = elem->size;\n \n-\tnew_elem_start = new_data_start - MALLOC_ELEM_HEADER_LEN;\n+\t/*\n+\t * we're allocating from the end, so adjust the size of element by page\n+\t * size each time\n+\t */\n+\twhile (elem_size >= size) {\n+\t\tconst size_t bmask = ~(bound - 1);\n+\t\tuintptr_t end_pt = (uintptr_t)elem +\n+\t\t\t\telem_size - MALLOC_ELEM_TRAILER_LEN;\n+\t\tuintptr_t new_data_start = RTE_ALIGN_FLOOR((end_pt - size), align);\n+\t\tuintptr_t new_elem_start;\n+\n+\t\t/* check boundary */\n+\t\tif ((new_data_start & bmask) != ((end_pt - 1) & bmask)) {\n+\t\t\tend_pt = RTE_ALIGN_FLOOR(end_pt, bound);\n+\t\t\tnew_data_start = RTE_ALIGN_FLOOR((end_pt - size), align);\n+\t\t\tend_pt = new_data_start + size;\n+\n+\t\t\tif (((end_pt - 1) & bmask) != (new_data_start & bmask))\n+\t\t\t\treturn NULL;\n+\t\t}\n \n-\t/* if the new start point is before the exist start, it won't fit */\n-\treturn (new_elem_start < (uintptr_t)elem) ? NULL : (void *)new_elem_start;\n+\t\tnew_elem_start = new_data_start - MALLOC_ELEM_HEADER_LEN;\n+\n+\t\t/* if the new start point is before the exist start, it won't fit */\n+\t\tif (new_elem_start < (uintptr_t)elem)\n+\t\t\treturn NULL;\n+\n+\t\tif (contig) {\n+\t\t\tsize_t new_data_size = end_pt - new_data_start;\n+\n+\t\t\t/*\n+\t\t\t * if physical contiguousness was requested and we\n+\t\t\t * couldn't fit all data into one physically contiguous\n+\t\t\t * block, try again with lower addresses.\n+\t\t\t */\n+\t\t\tif (!elem_check_phys_contig(elem->msl,\n+\t\t\t\t\t(void*) new_data_start, new_data_size)) {\n+\t\t\t\telem_size -= align;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t}\n+\t\treturn (void *) new_elem_start;\n+\t}\n+\treturn NULL;\n }\n \n /*\n@@ -156,9 +208,9 @@ elem_start_pt(struct malloc_elem *elem, size_t size, unsigned align,\n  */\n int\n malloc_elem_can_hold(struct malloc_elem *elem, size_t size,\tunsigned align,\n-\t\tsize_t bound)\n+\t\tsize_t bound, bool contig)\n {\n-\treturn elem_start_pt(elem, size, align, bound) != NULL;\n+\treturn elem_start_pt(elem, size, align, bound, contig) != NULL;\n }\n \n /*\n@@ -283,9 +335,10 @@ malloc_elem_free_list_remove(struct malloc_elem *elem)\n  */\n struct malloc_elem *\n malloc_elem_alloc(struct malloc_elem *elem, size_t size, unsigned align,\n-\t\tsize_t bound)\n+\t\tsize_t bound, bool contig)\n {\n-\tstruct malloc_elem *new_elem = elem_start_pt(elem, size, align, bound);\n+\tstruct malloc_elem *new_elem = elem_start_pt(elem, size, align, bound,\n+\t\t\tcontig);\n \tconst size_t old_elem_size = (uintptr_t)new_elem - (uintptr_t)elem;\n \tconst size_t trailer_size = elem->size - old_elem_size - size -\n \t\tMALLOC_ELEM_OVERHEAD;\n@@ -508,9 +561,11 @@ malloc_elem_hide_region(struct malloc_elem *elem, void *start, size_t len) {\n  * immediately after it in memory.\n  */\n int\n-malloc_elem_resize(struct malloc_elem *elem, size_t size)\n+malloc_elem_resize(struct malloc_elem *elem, size_t size, bool contig)\n {\n \tconst size_t new_size = size + elem->pad + MALLOC_ELEM_OVERHEAD;\n+\tconst size_t new_data_size = new_size - MALLOC_ELEM_OVERHEAD;\n+\tvoid *data_ptr = RTE_PTR_ADD(elem, MALLOC_ELEM_HEADER_LEN);\n \n \t/* if we request a smaller size, then always return ok */\n \tif (elem->size >= new_size)\n@@ -523,6 +578,12 @@ malloc_elem_resize(struct malloc_elem *elem, size_t size)\n \tif (elem->size + elem->next->size < new_size)\n \t\treturn -1;\n \n+\t/* if physical contiguousness was requested, check that as well */\n+\tif (contig && !elem_check_phys_contig(elem->msl,\n+\t\t\tdata_ptr, new_data_size)) {\n+\t\treturn -1;\n+\t}\n+\n \t/* we now know the element fits, so remove from free list,\n \t * join the two\n \t */\ndiff --git a/lib/librte_eal/common/malloc_elem.h b/lib/librte_eal/common/malloc_elem.h\nindex b47c55e..02d6bd7 100644\n--- a/lib/librte_eal/common/malloc_elem.h\n+++ b/lib/librte_eal/common/malloc_elem.h\n@@ -149,7 +149,7 @@ malloc_elem_insert(struct malloc_elem *elem);\n  */\n int\n malloc_elem_can_hold(struct malloc_elem *elem, size_t size,\n-\t\tunsigned align, size_t bound);\n+\t\tunsigned align, size_t bound, bool contig);\n \n /*\n  * reserve a block of data in an existing malloc_elem. If the malloc_elem\n@@ -157,7 +157,7 @@ malloc_elem_can_hold(struct malloc_elem *elem, size_t size,\n  */\n struct malloc_elem *\n malloc_elem_alloc(struct malloc_elem *elem, size_t size,\n-\t\tunsigned align, size_t bound);\n+\t\tunsigned align, size_t bound, bool contig);\n \n /*\n  * free a malloc_elem block by adding it to the free list. If the\n@@ -175,7 +175,7 @@ malloc_elem_join_adjacent_free(struct malloc_elem *elem);\n  * immediately after it in memory.\n  */\n int\n-malloc_elem_resize(struct malloc_elem *elem, size_t size);\n+malloc_elem_resize(struct malloc_elem *elem, size_t size, bool contig);\n \n void\n malloc_elem_hide_region(struct malloc_elem *elem, void *start, size_t len);\ndiff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c\nindex 0d61704..427f7c6 100644\n--- a/lib/librte_eal/common/malloc_heap.c\n+++ b/lib/librte_eal/common/malloc_heap.c\n@@ -123,7 +123,7 @@ malloc_heap_add_memory(struct malloc_heap *heap, struct rte_memseg_list *msl,\n  */\n static struct malloc_elem *\n find_suitable_element(struct malloc_heap *heap, size_t size,\n-\t\tunsigned flags, size_t align, size_t bound)\n+\t\tunsigned flags, size_t align, size_t bound, bool contig)\n {\n \tsize_t idx;\n \tstruct malloc_elem *elem, *alt_elem = NULL;\n@@ -132,7 +132,8 @@ find_suitable_element(struct malloc_heap *heap, size_t size,\n \t\t\tidx < RTE_HEAP_NUM_FREELISTS; idx++) {\n \t\tfor (elem = LIST_FIRST(&heap->free_head[idx]);\n \t\t\t\t!!elem; elem = LIST_NEXT(elem, free_list)) {\n-\t\t\tif (malloc_elem_can_hold(elem, size, align, bound)) {\n+\t\t\tif (malloc_elem_can_hold(elem, size, align, bound,\n+\t\t\t\t\tcontig)) {\n \t\t\t\tif (check_hugepage_sz(flags, elem->msl->hugepage_sz))\n \t\t\t\t\treturn elem;\n \t\t\t\tif (alt_elem == NULL)\n@@ -155,16 +156,16 @@ find_suitable_element(struct malloc_heap *heap, size_t size,\n  */\n static void *\n heap_alloc(struct malloc_heap *heap, const char *type __rte_unused, size_t size,\n-\t\tunsigned flags, size_t align, size_t bound)\n+\t\tunsigned flags, size_t align, size_t bound, bool contig)\n {\n \tstruct malloc_elem *elem;\n \n \tsize = RTE_CACHE_LINE_ROUNDUP(size);\n \talign = RTE_CACHE_LINE_ROUNDUP(align);\n \n-\telem = find_suitable_element(heap, size, flags, align, bound);\n+\telem = find_suitable_element(heap, size, flags, align, bound, contig);\n \tif (elem != NULL) {\n-\t\telem = malloc_elem_alloc(elem, size, align, bound);\n+\t\telem = malloc_elem_alloc(elem, size, align, bound, contig);\n \n \t\t/* increase heap's count of allocated elements */\n \t\theap->alloc_count++;\n@@ -176,13 +177,13 @@ heap_alloc(struct malloc_heap *heap, const char *type __rte_unused, size_t size,\n static void *\n try_expand_heap(struct malloc_heap *heap, struct rte_memseg_list *msl,\n \t\tconst char *type, size_t size, int socket, unsigned flags,\n-\t\tsize_t align, size_t bound) {\n+\t\tsize_t align, size_t bound, bool contig) {\n \tstruct malloc_elem *elem;\n \tstruct rte_memseg **ms;\n-\tsize_t map_len;\n+\tsize_t map_len, data_start_offset;\n \tvoid *map_addr;\n \tint i, n_pages, allocd_pages;\n-\tvoid *ret;\n+\tvoid *ret, *data_start;\n \n \talign = RTE_MAX(align, MALLOC_ELEM_HEADER_LEN);\n \tmap_len = RTE_ALIGN_CEIL(align + size + MALLOC_ELEM_TRAILER_LEN,\n@@ -200,6 +201,16 @@ try_expand_heap(struct malloc_heap *heap, struct rte_memseg_list *msl,\n \tif (allocd_pages != n_pages)\n \t\tgoto free_ms;\n \n+\t/* check if we wanted contiguous memory but didn't get it */\n+\tdata_start_offset = RTE_ALIGN(MALLOC_ELEM_HEADER_LEN, align);\n+\tdata_start = RTE_PTR_ADD(ms[0]->addr, data_start_offset);\n+\tif (contig && !eal_memalloc_is_contig(msl, data_start,\n+\t\t\tn_pages * msl->hugepage_sz)) {\n+\t\tRTE_LOG(DEBUG, EAL, \"%s(): couldn't allocate physically contiguous space\\n\",\n+\t\t\t\t__func__);\n+\t\tgoto free_pages;\n+\t}\n+\n \tmap_addr = ms[0]->addr;\n \n \t/* add newly minted memsegs to malloc heap */\n@@ -210,7 +221,7 @@ try_expand_heap(struct malloc_heap *heap, struct rte_memseg_list *msl,\n \n \t/* try once more, as now we have allocated new memory */\n \tret = heap_alloc(heap, type, size, flags,\n-\t\t\talign == 0 ? 1 : align, bound);\n+\t\t\talign == 0 ? 1 : align, bound, contig);\n \n \tif (ret == NULL)\n \t\tgoto free_elem;\n@@ -225,7 +236,7 @@ try_expand_heap(struct malloc_heap *heap, struct rte_memseg_list *msl,\n \n \tRTE_LOG(DEBUG, EAL, \"%s(): couldn't allocate, so shrinking heap on socket %d by %zdMB\\n\",\n \t\t__func__, socket, map_len >> 20ULL);\n-\n+free_pages:\n \tfor (i = 0; i < n_pages; i++) {\n \t\teal_memalloc_free_page(ms[i]);\n \t}\n@@ -249,7 +260,7 @@ compare_pagesz(const void *a, const void *b) {\n /* this will try lower page sizes first */\n static void *\n heap_alloc_on_socket(const char *type, size_t size, int socket,\n-\t\tunsigned flags, size_t align, size_t bound) {\n+\t\tunsigned flags, size_t align, size_t bound, bool contig) {\n \tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n \tstruct malloc_heap *heap = &mcfg->malloc_heaps[socket];\n \tstruct rte_memseg_list *requested_msls[RTE_MAX_MEMSEG_LISTS];\n@@ -264,7 +275,7 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \t/* for legacy mode, try once and with all flags */\n \tif (internal_config.legacy_mem) {\n \t\tret = heap_alloc(heap, type, size, flags,\n-\t\t\t\talign == 0 ? 1 : align, bound);\n+\t\t\t\talign == 0 ? 1 : align, bound, contig);\n \t\tgoto alloc_unlock;\n \t}\n \n@@ -274,7 +285,7 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \t * we just need to request more memory first.\n \t */\n \tret = heap_alloc(heap, type, size, size_flags, align == 0 ? 1 : align,\n-\t\t\tbound);\n+\t\t\tbound, contig);\n \tif (ret != NULL)\n \t\tgoto alloc_unlock;\n \n@@ -317,7 +328,7 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \t\t * sizes first, before resorting to best effort allocation.\n \t\t */\n \t\tret = try_expand_heap(heap, msl, type, size, socket, size_flags,\n-\t\t\t\talign, bound);\n+\t\t\t\talign, bound, contig);\n \t\tif (ret != NULL)\n \t\t\tgoto alloc_unlock;\n \t}\n@@ -326,7 +337,7 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \n \t/* now, try reserving with size hint */\n \tret = heap_alloc(heap, type, size, flags, align == 0 ? 1 : align,\n-\t\t\tbound);\n+\t\t\tbound, contig);\n \tif (ret != NULL)\n \t\tgoto alloc_unlock;\n \n@@ -338,7 +349,7 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \t\tstruct rte_memseg_list *msl = other_msls[i];\n \n \t\tret = try_expand_heap(heap, msl, type, size, socket, flags,\n-\t\t\t\talign, bound);\n+\t\t\t\talign, bound, contig);\n \t\tif (ret != NULL)\n \t\t\tgoto alloc_unlock;\n \t}\n@@ -349,7 +360,7 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \n void *\n malloc_heap_alloc(const char *type, size_t size, int socket_arg, unsigned flags,\n-\t\tsize_t align, size_t bound) {\n+\t\tsize_t align, size_t bound, bool contig) {\n \tint socket, i;\n \tvoid *ret;\n \n@@ -371,7 +382,8 @@ malloc_heap_alloc(const char *type, size_t size, int socket_arg, unsigned flags,\n \n \t// TODO: add warning for alignments bigger than page size if not VFIO\n \n-\tret = heap_alloc_on_socket(type, size, socket, flags, align, bound);\n+\tret = heap_alloc_on_socket(type, size, socket, flags, align, bound,\n+\t\t\tcontig);\n \tif (ret != NULL || socket_arg != SOCKET_ID_ANY)\n \t\treturn ret;\n \n@@ -380,7 +392,7 @@ malloc_heap_alloc(const char *type, size_t size, int socket_arg, unsigned flags,\n \t\tif (i == socket)\n \t\t\tcontinue;\n \t\tret = heap_alloc_on_socket(type, size, socket, flags,\n-\t\t\t\talign, bound);\n+\t\t\t\talign, bound, contig);\n \t\tif (ret != NULL)\n \t\t\treturn ret;\n \t}\n@@ -455,7 +467,7 @@ malloc_heap_free(struct malloc_elem *elem) {\n }\n \n int\n-malloc_heap_resize(struct malloc_elem *elem, size_t size) {\n+malloc_heap_resize(struct malloc_elem *elem, size_t size, bool contig) {\n \tint ret;\n \n \tif (!malloc_elem_cookies_ok(elem) || elem->state != ELEM_BUSY)\n@@ -463,7 +475,7 @@ malloc_heap_resize(struct malloc_elem *elem, size_t size) {\n \n \trte_spinlock_lock(&(elem->heap->lock));\n \n-\tret = malloc_elem_resize(elem, size);\n+\tret = malloc_elem_resize(elem, size, contig);\n \n \trte_spinlock_unlock(&(elem->heap->lock));\n \ndiff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h\nindex 3fcd14f..e95b526 100644\n--- a/lib/librte_eal/common/malloc_heap.h\n+++ b/lib/librte_eal/common/malloc_heap.h\n@@ -34,6 +34,8 @@\n #ifndef MALLOC_HEAP_H_\n #define MALLOC_HEAP_H_\n \n+#include <stdbool.h>\n+\n #include <rte_malloc.h>\n #include <rte_malloc_heap.h>\n \n@@ -54,13 +56,13 @@ malloc_get_numa_socket(void)\n \n void *\n malloc_heap_alloc(const char *type, size_t size, int socket, unsigned flags,\n-\t\tsize_t align, size_t bound);\n+\t\tsize_t align, size_t bound, bool contig);\n \n int\n malloc_heap_free(struct malloc_elem *elem);\n \n int\n-malloc_heap_resize(struct malloc_elem *elem, size_t size);\n+malloc_heap_resize(struct malloc_elem *elem, size_t size, bool contig);\n \n int\n malloc_heap_get_stats(struct malloc_heap *heap,\ndiff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c\nindex dc3199a..623725e 100644\n--- a/lib/librte_eal/common/rte_malloc.c\n+++ b/lib/librte_eal/common/rte_malloc.c\n@@ -62,12 +62,9 @@ void rte_free(void *addr)\n \t\trte_panic(\"Fatal error: Invalid memory\\n\");\n }\n \n-/*\n- * Allocate memory on specified heap.\n- */\n-void *\n-rte_malloc_socket(const char *type, size_t size, unsigned align, int socket_arg)\n-{\n+static void *\n+malloc_socket(const char *type, size_t size, unsigned align, int socket_arg,\n+\t\tbool contig) {\n \tint socket;\n \n \t/* return NULL if size is 0 or alignment is not power-of-2 */\n@@ -86,8 +83,16 @@ rte_malloc_socket(const char *type, size_t size, unsigned align, int socket_arg)\n \tif (socket >= RTE_MAX_NUMA_NODES)\n \t\treturn NULL;\n \n-\treturn malloc_heap_alloc(type, size, socket_arg, 0,\n-\t\t\talign == 0 ? 1 : align, 0);\n+\treturn malloc_heap_alloc(type, size, socket_arg, 0, align, 0, contig);\n+}\n+\n+/*\n+ * Allocate memory on specified heap.\n+ */\n+void *\n+rte_malloc_socket(const char *type, size_t size, unsigned align, int socket_arg)\n+{\n+\treturn malloc_socket(type, size, align, socket_arg, false);\n }\n \n /*\n@@ -138,8 +143,8 @@ rte_calloc(const char *type, size_t num, size_t size, unsigned align)\n /*\n  * Resize allocated memory.\n  */\n-void *\n-rte_realloc(void *ptr, size_t size, unsigned align)\n+static void *\n+do_realloc(void *ptr, size_t size, unsigned align, bool contig)\n {\n \tif (ptr == NULL)\n \t\treturn rte_malloc(NULL, size, align);\n@@ -151,12 +156,12 @@ rte_realloc(void *ptr, size_t size, unsigned align)\n \tsize = RTE_CACHE_LINE_ROUNDUP(size), align = RTE_CACHE_LINE_ROUNDUP(align);\n \t/* check alignment matches first, and if ok, see if we can resize block */\n \tif (RTE_PTR_ALIGN(ptr,align) == ptr &&\n-\t\t\tmalloc_heap_resize(elem, size) == 0)\n+\t\t\tmalloc_heap_resize(elem, size, contig) == 0)\n \t\treturn ptr;\n \n \t/* either alignment is off, or we have no room to expand,\n \t * so move data. */\n-\tvoid *new_ptr = rte_malloc(NULL, size, align);\n+\tvoid *new_ptr = malloc_socket(NULL, size, align, SOCKET_ID_ANY, contig);\n \tif (new_ptr == NULL)\n \t\treturn NULL;\n \tconst unsigned old_size = elem->size - MALLOC_ELEM_OVERHEAD;\n@@ -166,6 +171,15 @@ rte_realloc(void *ptr, size_t size, unsigned align)\n \treturn new_ptr;\n }\n \n+/*\n+ * Resize allocated memory.\n+ */\n+void *\n+rte_realloc(void *ptr, size_t size, unsigned align)\n+{\n+\treturn do_realloc(ptr, size, align, false);\n+}\n+\n int\n rte_malloc_validate(const void *ptr, size_t *size)\n {\n",
    "prefixes": [
        "dpdk-dev",
        "RFC",
        "v2",
        "17/23"
    ]
}