Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/44931/?format=api
http://patches.dpdk.org/api/patches/44931/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/9f2c7bdd775175ae6b2de4762207ddbe7d6fd0b2.1537363687.git.anatoly.burakov@intel.com/", "project": { "id": 1, "url": "http://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": "<9f2c7bdd775175ae6b2de4762207ddbe7d6fd0b2.1537363687.git.anatoly.burakov@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/9f2c7bdd775175ae6b2de4762207ddbe7d6fd0b2.1537363687.git.anatoly.burakov@intel.com", "date": "2018-09-19T13:56:38", "name": "[v2,14/20] malloc: allow attaching to external memory chunks", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "aaaf40baf6aaeaef89048a81ebc9ea89494ce7c0", "submitter": { "id": 4, "url": "http://patches.dpdk.org/api/people/4/?format=api", "name": "Anatoly Burakov", "email": "anatoly.burakov@intel.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/9f2c7bdd775175ae6b2de4762207ddbe7d6fd0b2.1537363687.git.anatoly.burakov@intel.com/mbox/", "series": [ { "id": 1391, "url": "http://patches.dpdk.org/api/series/1391/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1391", "date": "2018-09-19T13:56:25", "name": "Support externally allocated memory in DPDK", "version": 2, "mbox": "http://patches.dpdk.org/series/1391/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/44931/comments/", "check": "success", "checks": "http://patches.dpdk.org/api/patches/44931/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 0148A5F28;\n\tWed, 19 Sep 2018 15:57:41 +0200 (CEST)", "from mga07.intel.com (mga07.intel.com [134.134.136.100])\n\tby dpdk.org (Postfix) with ESMTP id 60DA54C95\n\tfor <dev@dpdk.org>; Wed, 19 Sep 2018 15:56:52 +0200 (CEST)", "from orsmga006.jf.intel.com ([10.7.209.51])\n\tby orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t19 Sep 2018 06:56:50 -0700", "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga006.jf.intel.com with ESMTP; 19 Sep 2018 06:56:47 -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\tw8JDukvv005016; Wed, 19 Sep 2018 14:56:46 +0100", "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id w8JDukgS023511;\n\tWed, 19 Sep 2018 14:56:46 +0100", "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with LOCAL id w8JDukAb023507;\n\tWed, 19 Sep 2018 14:56:46 +0100" ], "X-Amp-Result": "SKIPPED(no attachment in message)", "X-Amp-File-Uploaded": "False", "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.53,394,1531810800\"; d=\"scan'208\";a=\"75600736\"", "From": "Anatoly Burakov <anatoly.burakov@intel.com>", "To": "dev@dpdk.org", "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\tgeza.koblo@ericsson.com, srinath.mannam@broadcom.com,\n\tscott.branden@broadcom.com, ajit.khaparde@broadcom.com,\n\tkeith.wiles@intel.com, bruce.richardson@intel.com, thomas@monjalon.net,\n\tshreyansh.jain@nxp.com, shahafs@mellanox.com", "Date": "Wed, 19 Sep 2018 14:56:38 +0100", "Message-Id": "<9f2c7bdd775175ae6b2de4762207ddbe7d6fd0b2.1537363687.git.anatoly.burakov@intel.com>", "X-Mailer": "git-send-email 1.7.0.7", "In-Reply-To": [ "<cover.1537363686.git.anatoly.burakov@intel.com>", "<cover.1537363686.git.anatoly.burakov@intel.com>" ], "References": [ "<cover.1537363686.git.anatoly.burakov@intel.com>", "<cover.1536064999.git.anatoly.burakov@intel.com>\n\t<cover.1537363686.git.anatoly.burakov@intel.com>" ], "Subject": "[dpdk-dev] [PATCH v2 14/20] malloc: allow attaching to external\n\tmemory chunks", "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://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "In order to use external memory in multiple processes, we need to\nattach to primary process's memseg lists, so add a new API to do\nthat. It is the responsibility of the user to ensure that memory\nis accessible and that it has been previously added to the malloc\nheap by another process.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_eal/common/include/rte_malloc.h | 48 +++++++++--\n lib/librte_eal/common/rte_malloc.c | 93 ++++++++++++++++++++++\n lib/librte_eal/rte_eal_version.map | 1 +\n 3 files changed, 135 insertions(+), 7 deletions(-)", "diff": "diff --git a/lib/librte_eal/common/include/rte_malloc.h b/lib/librte_eal/common/include/rte_malloc.h\nindex 9bbe8e3af..440496cd9 100644\n--- a/lib/librte_eal/common/include/rte_malloc.h\n+++ b/lib/librte_eal/common/include/rte_malloc.h\n@@ -268,6 +268,10 @@ rte_malloc_get_socket_stats(int socket,\n *\n * @note Multiple memory chunks can be added to the same heap\n *\n+ * @note Before accessing this memory in other processes, it needs to be\n+ * attached in each of those processes by calling\n+ * ``rte_malloc_heap_memory_attach`` in each other process.\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@@ -329,21 +333,48 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,\n int __rte_experimental\n rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len);\n \n+/**\n+ * Attach to an already existing chunk of external memory in another process.\n+ *\n+ * @note This function must be called before any attempt is made to use an\n+ * already existing external memory chunk. This function does *not* need to\n+ * be called if a call to ``rte_malloc_heap_memory_add`` was made in the\n+ * current process.\n+ *\n+ * @param heap_name\n+ * Heap name to which this chunk of memory belongs\n+ * @param va_addr\n+ * Start address of memory chunk to attach to\n+ * @param len\n+ * Length of memory chunk to attach to\n+ * @return\n+ * 0 on successful attach\n+ * -1 on unsuccessful attach, with rte_errno set to indicate cause for error:\n+ * EINVAL - one of the parameters was invalid\n+ * EPERM - attempted to attach memory to a reserved heap\n+ * ENOENT - heap or memory chunk was not found\n+ */\n+int __rte_experimental\n+rte_malloc_heap_memory_attach(const char *heap_name, void *va_addr, size_t len);\n+\n /**\n * Creates a new empty malloc heap with a specified name.\n *\n * @note Heaps created via this call will automatically get assigned a unique\n * socket ID, which can be found using ``rte_malloc_heap_get_socket()``\n *\n+ * @note This function can only be called in primary process.\n+ *\n * @param heap_name\n * Name of the heap to create.\n *\n * @return\n * - 0 on successful creation\n * - -1 in case of error, with rte_errno set to one of the following:\n- * EINVAL - ``heap_name`` was NULL, empty or too long\n- * EEXIST - heap by name of ``heap_name`` already exists\n- * ENOSPC - no more space in internal config to store a new heap\n+ * EINVAL - ``heap_name`` was NULL, empty or too long\n+ * EEXIST - heap by name of ``heap_name`` already exists\n+ * ENOSPC - no more space in internal config to store a new heap\n+ * E_RTE_SECONDARY - attempted to create a heap in secondary process\n */\n int __rte_experimental\n rte_malloc_heap_create(const char *heap_name);\n@@ -357,16 +388,19 @@ rte_malloc_heap_create(const char *heap_name);\n * @note This function will return a failure result if not all memory segments\n * were removed from the heap prior to its destruction\n *\n+ * @note This function can only be called in primary process.\n+ *\n * @param heap_name\n * Name of the heap to create.\n *\n * @return\n * - 0 on success\n * - -1 in case of error, with rte_errno set to one of the following:\n- * EINVAL - ``heap_name`` was NULL, empty or too long\n- * ENOENT - heap by the name of ``heap_name`` was not found\n- * EPERM - attempting to destroy reserved heap\n- * EBUSY - heap still contains data\n+ * EINVAL - ``heap_name`` was NULL, empty or too long\n+ * ENOENT - heap by the name of ``heap_name`` was not found\n+ * EPERM - attempting to destroy reserved heap\n+ * EBUSY - heap still contains data\n+ * E_RTE_SECONDARY - attempted to destroy a heap in secondary process\n */\n int __rte_experimental\n rte_malloc_heap_destroy(const char *heap_name);\ndiff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c\nindex aed066882..bc22d21e4 100644\n--- a/lib/librte_eal/common/rte_malloc.c\n+++ b/lib/librte_eal/common/rte_malloc.c\n@@ -393,6 +393,89 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)\n \treturn ret;\n }\n \n+struct sync_mem_walk_arg {\n+\tvoid *va_addr;\n+\tsize_t len;\n+\tint result;\n+};\n+\n+static int\n+attach_mem_walk(const struct rte_memseg_list *msl, void *arg)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tstruct sync_mem_walk_arg *wa = arg;\n+\tsize_t len = msl->page_sz * msl->memseg_arr.len;\n+\n+\tif (msl->base_va == wa->va_addr &&\n+\t\t\tlen == wa->len) {\n+\t\tstruct rte_memseg_list *found_msl;\n+\t\tint msl_idx, ret;\n+\n+\t\t/* msl is const */\n+\t\tmsl_idx = msl - mcfg->memsegs;\n+\t\tfound_msl = &mcfg->memsegs[msl_idx];\n+\n+\t\tret = rte_fbarray_attach(&found_msl->memseg_arr);\n+\n+\t\tif (ret < 0)\n+\t\t\twa->result = -rte_errno;\n+\t\telse\n+\t\t\twa->result = 0;\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+int\n+rte_malloc_heap_memory_attach(const char *heap_name, void *va_addr, size_t len)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tstruct malloc_heap *heap = NULL;\n+\tstruct sync_mem_walk_arg wa;\n+\tint ret;\n+\n+\tif (heap_name == NULL || va_addr == NULL || len == 0 ||\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\treturn -1;\n+\t}\n+\trte_rwlock_read_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+\t/* we shouldn't be able to attach to internal heaps */\n+\tif (heap->socket_id < RTE_MAX_NUMA_NODES) {\n+\t\trte_errno = EPERM;\n+\t\tret = -1;\n+\t\tgoto unlock;\n+\t}\n+\n+\t/* find corresponding memseg list to attach to */\n+\twa.va_addr = va_addr;\n+\twa.len = len;\n+\twa.result = -ENOENT; /* fail unless explicitly told to succeed */\n+\n+\t/* we're already holding a read lock */\n+\trte_memseg_list_walk_thread_unsafe(attach_mem_walk, &wa);\n+\n+\tif (wa.result < 0) {\n+\t\trte_errno = -wa.result;\n+\t\tret = -1;\n+\t} else {\n+\t\tret = 0;\n+\t}\n+unlock:\n+\trte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);\n+\treturn ret;\n+}\n+\n int\n rte_malloc_heap_create(const char *heap_name)\n {\n@@ -400,6 +483,11 @@ rte_malloc_heap_create(const char *heap_name)\n \tstruct malloc_heap *heap = NULL;\n \tint i, ret;\n \n+\tif (rte_eal_process_type() != RTE_PROC_PRIMARY) {\n+\t\trte_errno = E_RTE_SECONDARY;\n+\t\treturn -1;\n+\t}\n+\n \tif (heap_name == NULL ||\n \t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) == 0 ||\n \t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) ==\n@@ -451,6 +539,11 @@ rte_malloc_heap_destroy(const char *heap_name)\n \tstruct malloc_heap *heap = NULL;\n \tint ret;\n \n+\tif (rte_eal_process_type() != RTE_PROC_PRIMARY) {\n+\t\trte_errno = E_RTE_SECONDARY;\n+\t\treturn -1;\n+\t}\n+\n \tif (heap_name == NULL ||\n \t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) == 0 ||\n \t\t\tstrnlen(heap_name, RTE_HEAP_NAME_MAX_LEN) ==\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex f10c34130..822c5693a 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -315,6 +315,7 @@ EXPERIMENTAL {\n \trte_malloc_heap_destroy;\n \trte_malloc_heap_get_socket;\n \trte_malloc_heap_memory_add;\n+\trte_malloc_heap_memory_attach;\n \trte_malloc_heap_memory_remove;\n \trte_mem_alloc_validator_register;\n \trte_mem_alloc_validator_unregister;\n", "prefixes": [ "v2", "14/20" ] }{ "id": 44931, "url": "