Show a patch.

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

{
    "id": 44228,
    "url": "http://patches.dpdk.org/api/patches/44228/",
    "web_url": "http://patches.dpdk.org/patch/44228/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<d0f9f66818709f637a58045a252592c530070661.1536064999.git.anatoly.burakov@intel.com>",
    "date": "2018-09-04T13:11:47",
    "name": "[12/16] malloc: allow adding memory to named heaps",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "c9c47a374e118a99393e39c313203f1b929d74ca",
    "submitter": {
        "id": 4,
        "url": "http://patches.dpdk.org/api/people/4/",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/patch/44228/mbox/",
    "series": [
        {
            "id": 1170,
            "url": "http://patches.dpdk.org/api/series/1170/",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1170",
            "date": "2018-09-04T13:11:35",
            "name": "Support externally allocated memory in DPDK",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/1170/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/44228/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/44228/checks/",
    "tags": {},
    "headers": {
        "X-Mailman-Version": "2.1.15",
        "X-ExtLoop1": "1",
        "Errors-To": "dev-bounces@dpdk.org",
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Mailer": "git-send-email 1.7.0.7",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 49CF45398;\n\tTue,  4 Sep 2018 15:12:08 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id 6C1162C02\n\tfor <dev@dpdk.org>; Tue,  4 Sep 2018 15:12:00 +0200 (CEST)",
            "from fmsmga005.fm.intel.com ([10.253.24.32])\n\tby orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t04 Sep 2018 06:11:58 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga005.fm.intel.com with ESMTP; 04 Sep 2018 06:11:55 -0700",
            "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\tw84DBsu2023381; Tue, 4 Sep 2018 14:11:54 +0100",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id w84DBsYs024744;\n\tTue, 4 Sep 2018 14:11:54 +0100",
            "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with LOCAL id w84DBsI2024730;\n\tTue, 4 Sep 2018 14:11:54 +0100"
        ],
        "References": [
            "<cover.1536064999.git.anatoly.burakov@intel.com>",
            "<cover.1536064999.git.anatoly.burakov@intel.com>"
        ],
        "X-Amp-File-Uploaded": "False",
        "X-BeenThere": "dev@dpdk.org",
        "Message-Id": "<d0f9f66818709f637a58045a252592c530070661.1536064999.git.anatoly.burakov@intel.com>",
        "X-IronPort-AV": "E=Sophos;i=\"5.53,329,1531810800\"; d=\"scan'208\";a=\"259703428\"",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "Precedence": "list",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "X-Original-To": "patchwork@dpdk.org",
        "List-Post": "<mailto:dev@dpdk.org>",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "In-Reply-To": [
            "<cover.1536064999.git.anatoly.burakov@intel.com>",
            "<cover.1536064999.git.anatoly.burakov@intel.com>"
        ],
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "To": "dev@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "Date": "Tue,  4 Sep 2018 14:11:47 +0100",
        "Cc": "laszlo.madarassy@ericsson.com, laszlo.vadkerti@ericsson.com,\n\tandras.kovacs@ericsson.com, winnie.tian@ericsson.com,\n\tdaniel.andrasi@ericsson.com, janos.kobor@ericsson.com,\n\tsrinath.mannam@broadcom.com, scott.branden@broadcom.com,\n\tajit.khaparde@broadcom.com, keith.wiles@intel.com,\n\tbruce.richardson@intel.com, thomas@monjalon.net",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "Subject": "[dpdk-dev] [PATCH 12/16] malloc: allow adding memory to named heaps"
    },
    "content": "Add an API to add externally allocated memory to malloc heap. The\nmemory will be stored in memseg lists like regular DPDK memory.\nMultiple segments are allowed within a heap. If IOVA table is\nnot provided, IOVA addresses are filled in with RTE_BAD_IOVA.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_eal/common/include/rte_malloc.h | 39 ++++++++++++\n lib/librte_eal/common/malloc_heap.c        | 74 ++++++++++++++++++++++\n lib/librte_eal/common/malloc_heap.h        |  4 ++\n lib/librte_eal/common/rte_malloc.c         | 51 +++++++++++++++\n lib/librte_eal/rte_eal_version.map         |  1 +\n 5 files changed, 169 insertions(+)",
    "diff": "diff --git a/lib/librte_eal/common/include/rte_malloc.h b/lib/librte_eal/common/include/rte_malloc.h\nindex 8a8cc1e6d..47f867a05 100644\n--- a/lib/librte_eal/common/include/rte_malloc.h\n+++ b/lib/librte_eal/common/include/rte_malloc.h\n@@ -263,6 +263,45 @@ int\n rte_malloc_get_socket_stats(int socket,\n \t\tstruct rte_malloc_socket_stats *socket_stats);\n \n+/**\n+ * Add memory chunk to a heap with specified name.\n+ *\n+ * @note Multiple memory chunks can be added to the same heap\n+ *\n+ * @note Memory must be previously allocated for DPDK to be able to use it as a\n+ *   malloc heap. Failing to do so will result in undefined behavior, up to and\n+ *   including segmentation faults.\n+ *\n+ * @note Calling this function will erase any contents already present at the\n+ *   supplied memory address.\n+ *\n+ * @param heap_name\n+ *   Name of the heap to add memory chunk to\n+ * @param va_addr\n+ *   Start of virtual area to add to the heap\n+ * @param len\n+ *   Length of virtual area to add to the heap\n+ * @param iova_addrs\n+ *   Array of page IOVA addresses corresponding to each page in this memory\n+ *   area. Can be NULL, in which case page IOVA addresses will be set to\n+ *   RTE_BAD_IOVA.\n+ * @param n_pages\n+ *   Number of elements in the iova_addrs array. Ignored if  ``iova_addrs``\n+ *   is NULL.\n+ * @param page_sz\n+ *   Page size of the underlying memory\n+ *\n+ * @return\n+ *   - 0 on success\n+ *   - -1 in case of error, with rte_errno set to one of the following:\n+ *     EINVAL - one of the parameters was invalid\n+ *     EPERM  - attempted to add memory to a reserved heap\n+ *     ENOSPC - no more space in internal config to store a new memory chunk\n+ */\n+int __rte_experimental\n+rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz);\n+\n /**\n  * Creates a new empty malloc heap with a specified name.\n  *\ndiff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c\nindex 471094cd1..af2476504 100644\n--- a/lib/librte_eal/common/malloc_heap.c\n+++ b/lib/librte_eal/common/malloc_heap.c\n@@ -1010,6 +1010,80 @@ malloc_heap_dump(struct malloc_heap *heap, FILE *f)\n \trte_spinlock_unlock(&heap->lock);\n }\n \n+int\n+malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tchar fbarray_name[RTE_FBARRAY_NAME_LEN];\n+\tstruct rte_memseg_list *msl = NULL;\n+\tstruct rte_fbarray *arr;\n+\tsize_t seg_len = n_pages * page_sz;\n+\tunsigned int i;\n+\n+\t/* first, find a free memseg list */\n+\tfor (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {\n+\t\tstruct rte_memseg_list *tmp = &mcfg->memsegs[i];\n+\t\tif (tmp->base_va == NULL) {\n+\t\t\tmsl = tmp;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (msl == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Couldn't find empty memseg list\\n\");\n+\t\trte_errno = ENOSPC;\n+\t\treturn -1;\n+\t}\n+\n+\tsnprintf(fbarray_name, sizeof(fbarray_name) - 1, \"%s_%p\",\n+\t\t\theap->name, va_addr);\n+\n+\t/* create the backing fbarray */\n+\tif (rte_fbarray_init(&msl->memseg_arr, fbarray_name, n_pages,\n+\t\t\tsizeof(struct rte_memseg)) < 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Couldn't create fbarray backing the memseg list\\n\");\n+\t\treturn -1;\n+\t}\n+\tarr = &msl->memseg_arr;\n+\n+\t/* fbarray created, fill it up */\n+\tfor (i = 0; i < n_pages; i++) {\n+\t\tstruct rte_memseg *ms;\n+\n+\t\trte_fbarray_set_used(arr, i);\n+\t\tms = rte_fbarray_get(arr, i);\n+\t\tms->addr = RTE_PTR_ADD(va_addr, n_pages * page_sz);\n+\t\tms->iova = iova_addrs == NULL ? RTE_BAD_IOVA : iova_addrs[i];\n+\t\tms->hugepage_sz = page_sz;\n+\t\tms->len = page_sz;\n+\t\tms->nchannel = rte_memory_get_nchannel();\n+\t\tms->nrank = rte_memory_get_nrank();\n+\t\tms->socket_id = heap->socket_id;\n+\t}\n+\n+\t/* set up the memseg list */\n+\tmsl->base_va = va_addr;\n+\tmsl->page_sz = page_sz;\n+\tmsl->socket_id = heap->socket_id;\n+\tmsl->len = seg_len;\n+\tmsl->version = 0;\n+\tmsl->external = true;\n+\n+\t/* erase contents of new memory */\n+\tmemset(va_addr, 0, seg_len);\n+\n+\t/* now, add newly minted memory to the malloc heap */\n+\tmalloc_heap_add_memory(heap, msl, va_addr, seg_len);\n+\n+\theap->total_size += seg_len;\n+\n+\t/* all done! */\n+\tRTE_LOG(DEBUG, EAL, \"Added segment for heap %s starting at %p\\n\",\n+\t\t\theap->name, va_addr);\n+\n+\treturn 0;\n+}\n+\n int\n malloc_heap_create(struct malloc_heap *heap, const char *heap_name)\n {\ndiff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h\nindex 75278da3c..237ce9dc2 100644\n--- a/lib/librte_eal/common/malloc_heap.h\n+++ b/lib/librte_eal/common/malloc_heap.h\n@@ -39,6 +39,10 @@ malloc_heap_create(struct malloc_heap *heap, const char *heap_name);\n int\n malloc_heap_destroy(struct malloc_heap *heap);\n \n+int\n+malloc_heap_add_external_memory(struct malloc_heap *heap, void *va_addr,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz);\n+\n int\n malloc_heap_free(struct malloc_elem *elem);\n \ndiff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c\nindex d135f9730..329524ac9 100644\n--- a/lib/librte_eal/common/rte_malloc.c\n+++ b/lib/librte_eal/common/rte_malloc.c\n@@ -303,6 +303,57 @@ find_named_heap(const char *name)\n \treturn NULL;\n }\n \n+int\n+rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,\n+\t\trte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tstruct malloc_heap *heap = NULL;\n+\tunsigned int n;\n+\tint ret;\n+\n+\tif (heap_name == NULL || va_addr == NULL ||\n+\t\t\tpage_sz == 0 || !rte_is_power_of_2(page_sz) ||\n+\t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) == 0 ||\n+\t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) ==\n+\t\t\t\tRTE_HEAP_NAME_MAX_LEN) {\n+\t\trte_errno = EINVAL;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\trte_rwlock_write_lock(&mcfg->memory_hotplug_lock);\n+\n+\t/* find our heap */\n+\theap = find_named_heap(heap_name);\n+\tif (heap == NULL) {\n+\t\trte_errno = ENOENT;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\tif (heap->socket_id < RTE_MAX_NUMA_NODES) {\n+\t\t/* cannot add memory to internal heaps */\n+\t\trte_errno = EPERM;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\tn = len / page_sz;\n+\tif (n != n_pages && iova_addrs != NULL) {\n+\t\trte_errno = EINVAL;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\n+\trte_spinlock_lock(&heap->lock);\n+\tret = malloc_heap_add_external_memory(heap, va_addr, iova_addrs, n,\n+\t\t\tpage_sz);\n+\trte_spinlock_unlock(&heap->lock);\n+\n+unlock:\n+\trte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);\n+\n+\treturn ret;\n+}\n+\n int\n rte_malloc_heap_create(const char *heap_name)\n {\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex 1d3ca0716..0d052d20a 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -314,6 +314,7 @@ EXPERIMENTAL {\n \trte_malloc_heap_create;\n \trte_malloc_heap_destroy;\n \trte_malloc_heap_get_socket;\n+\trte_malloc_heap_memory_add;\n \trte_mem_alloc_validator_register;\n \trte_mem_alloc_validator_unregister;\n \trte_mem_event_callback_register;\n",
    "prefixes": [
        "12/16"
    ]
}