Show a patch.

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

{
    "id": 44234,
    "url": "http://patches.dpdk.org/api/patches/44234/",
    "web_url": "http://patches.dpdk.org/patch/44234/",
    "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": "<5e2898fe0a413c04960359cc9a2d30e1a297a562.1536064999.git.anatoly.burakov@intel.com>",
    "date": "2018-09-04T13:11:38",
    "name": "[03/16] malloc: index heaps using heap ID rather than NUMA node",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "8d80c4447ebaca170fdc3ab8582343846842b357",
    "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/44234/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/44234/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/44234/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 C11625F27;\n\tTue,  4 Sep 2018 15:12:22 +0200 (CEST)",
            "from mga18.intel.com (mga18.intel.com [134.134.136.126])\n\tby dpdk.org (Postfix) with ESMTP id 77D2A4CC0\n\tfor <dev@dpdk.org>; Tue,  4 Sep 2018 15:12:19 +0200 (CEST)",
            "from orsmga003.jf.intel.com ([10.7.209.27])\n\tby orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t04 Sep 2018 06:12:18 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga003.jf.intel.com with ESMTP; 04 Sep 2018 06:11:53 -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\tw84DBqlH023353; Tue, 4 Sep 2018 14:11:52 +0100",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id w84DBq06024340;\n\tTue, 4 Sep 2018 14:11:52 +0100",
            "(from aburakov@localhost)\n\tby sivswdev01.ir.intel.com with LOCAL id w84DBqZK024325;\n\tTue, 4 Sep 2018 14:11:52 +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": "<5e2898fe0a413c04960359cc9a2d30e1a297a562.1536064999.git.anatoly.burakov@intel.com>",
        "X-IronPort-AV": "E=Sophos;i=\"5.53,329,1531810800\"; d=\"scan'208\";a=\"80749933\"",
        "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:38 +0100",
        "Cc": "Thomas Monjalon <thomas@monjalon.net>,\n\tBruce Richardson <bruce.richardson@intel.com>,\n\tlaszlo.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",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "Subject": "[dpdk-dev] [PATCH 03/16] malloc: index heaps using heap ID rather\n\tthan NUMA node"
    },
    "content": "Switch over all parts of EAL to use heap ID instead of NUMA node\nID to identify heaps. Heap ID for DPDK-internal heaps is NUMA\nnode's index within the detected NUMA node list. Heap ID for\nexternal heaps will be order of their creation.\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n config/common_base                            |  1 +\n config/rte_config.h                           |  1 +\n .../common/include/rte_eal_memconfig.h        |  4 +-\n .../common/include/rte_malloc_heap.h          |  1 +\n lib/librte_eal/common/malloc_heap.c           | 85 +++++++++++++------\n lib/librte_eal/common/malloc_heap.h           |  3 +\n lib/librte_eal/common/rte_malloc.c            | 41 ++++++---\n 7 files changed, 94 insertions(+), 42 deletions(-)",
    "diff": "diff --git a/config/common_base b/config/common_base\nindex 4bcbaf923..e96c52054 100644\n--- a/config/common_base\n+++ b/config/common_base\n@@ -61,6 +61,7 @@ CONFIG_RTE_CACHE_LINE_SIZE=64\n CONFIG_RTE_LIBRTE_EAL=y\n CONFIG_RTE_MAX_LCORE=128\n CONFIG_RTE_MAX_NUMA_NODES=8\n+CONFIG_RTE_MAX_HEAPS=32\n CONFIG_RTE_MAX_MEMSEG_LISTS=64\n # each memseg list will be limited to either RTE_MAX_MEMSEG_PER_LIST pages\n # or RTE_MAX_MEM_MB_PER_LIST megabytes worth of memory, whichever is smaller\ndiff --git a/config/rte_config.h b/config/rte_config.h\nindex a8e479774..1f330c24e 100644\n--- a/config/rte_config.h\n+++ b/config/rte_config.h\n@@ -21,6 +21,7 @@\n /****** library defines ********/\n \n /* EAL defines */\n+#define RTE_MAX_HEAPS 32\n #define RTE_MAX_MEMSEG_LISTS 128\n #define RTE_MAX_MEMSEG_PER_LIST 8192\n #define RTE_MAX_MEM_MB_PER_LIST 32768\ndiff --git a/lib/librte_eal/common/include/rte_eal_memconfig.h b/lib/librte_eal/common/include/rte_eal_memconfig.h\nindex 76faf9a4a..5c6bd4bc3 100644\n--- a/lib/librte_eal/common/include/rte_eal_memconfig.h\n+++ b/lib/librte_eal/common/include/rte_eal_memconfig.h\n@@ -72,8 +72,8 @@ struct rte_mem_config {\n \n \tstruct rte_tailq_head tailq_head[RTE_MAX_TAILQ]; /**< Tailqs for objects */\n \n-\t/* Heaps of Malloc per socket */\n-\tstruct malloc_heap malloc_heaps[RTE_MAX_NUMA_NODES];\n+\t/* Heaps of Malloc */\n+\tstruct malloc_heap malloc_heaps[RTE_MAX_HEAPS];\n \n \t/* address of mem_config in primary process. used to map shared config into\n \t * exact same address the primary process maps it.\ndiff --git a/lib/librte_eal/common/include/rte_malloc_heap.h b/lib/librte_eal/common/include/rte_malloc_heap.h\nindex d43fa9097..e7ac32d42 100644\n--- a/lib/librte_eal/common/include/rte_malloc_heap.h\n+++ b/lib/librte_eal/common/include/rte_malloc_heap.h\n@@ -27,6 +27,7 @@ struct malloc_heap {\n \n \tunsigned alloc_count;\n \tsize_t total_size;\n+\tunsigned int socket_id;\n } __rte_cache_aligned;\n \n #endif /* _RTE_MALLOC_HEAP_H_ */\ndiff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c\nindex 8c37b9d7c..0a868f61d 100644\n--- a/lib/librte_eal/common/malloc_heap.c\n+++ b/lib/librte_eal/common/malloc_heap.c\n@@ -66,6 +66,21 @@ check_hugepage_sz(unsigned flags, uint64_t hugepage_sz)\n \treturn check_flag & flags;\n }\n \n+int\n+malloc_socket_to_heap_id(unsigned int socket_id)\n+{\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tint i;\n+\n+\tfor (i = 0; i < RTE_MAX_HEAPS; i++) {\n+\t\tstruct malloc_heap *heap = &mcfg->malloc_heaps[i];\n+\n+\t\tif (heap->socket_id == socket_id)\n+\t\t\treturn i;\n+\t}\n+\treturn -1;\n+}\n+\n /*\n  * Expand the heap with a memory area.\n  */\n@@ -93,12 +108,13 @@ malloc_add_seg(const struct rte_memseg_list *msl,\n \tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n \tstruct rte_memseg_list *found_msl;\n \tstruct malloc_heap *heap;\n-\tint msl_idx;\n+\tint msl_idx, heap_idx;\n \n \tif (msl->external)\n \t\treturn 0;\n \n-\theap = &mcfg->malloc_heaps[msl->socket_id];\n+\theap_idx = malloc_socket_to_heap_id(msl->socket_id);\n+\theap = &mcfg->malloc_heaps[heap_idx];\n \n \t/* msl is const, so find it */\n \tmsl_idx = msl - mcfg->memsegs;\n@@ -111,6 +127,7 @@ malloc_add_seg(const struct rte_memseg_list *msl,\n \tmalloc_heap_add_memory(heap, found_msl, ms->addr, len);\n \n \theap->total_size += len;\n+\theap->socket_id = msl->socket_id;\n \n \tRTE_LOG(DEBUG, EAL, \"Added %zuM to heap on socket %i\\n\", len >> 20,\n \t\t\tmsl->socket_id);\n@@ -563,12 +580,14 @@ alloc_more_mem_on_socket(struct malloc_heap *heap, size_t size, int socket,\n \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 int flags, size_t align, size_t bound, bool contig)\n+malloc_heap_alloc_on_heap_id(const char *type, size_t size,\n+\t\tunsigned int heap_id, unsigned int flags, size_t align,\n+\t\tsize_t bound, bool contig)\n {\n \tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n-\tstruct malloc_heap *heap = &mcfg->malloc_heaps[socket];\n+\tstruct malloc_heap *heap = &mcfg->malloc_heaps[heap_id];\n \tunsigned int size_flags = flags & ~RTE_MEMZONE_SIZE_HINT_ONLY;\n+\tint socket_id;\n \tvoid *ret;\n \n \trte_spinlock_lock(&(heap->lock));\n@@ -590,8 +609,13 @@ heap_alloc_on_socket(const char *type, size_t size, int socket,\n \tif (ret != NULL)\n \t\tgoto alloc_unlock;\n \n-\tif (!alloc_more_mem_on_socket(heap, size, socket, flags, align, bound,\n-\t\t\tcontig)) {\n+\tsocket_id = rte_socket_id_by_idx(heap_id);\n+\t/* if socket ID is invalid, this is an external heap */\n+\tif (socket_id < 0)\n+\t\tgoto alloc_unlock;\n+\n+\tif (!alloc_more_mem_on_socket(heap, size, socket_id, flags, align,\n+\t\t\tbound, contig)) {\n \t\tret = heap_alloc(heap, type, size, flags, align, bound, contig);\n \n \t\t/* this should have succeeded */\n@@ -607,7 +631,7 @@ void *\n malloc_heap_alloc(const char *type, size_t size, int socket_arg,\n \t\tunsigned int flags, size_t align, size_t bound, bool contig)\n {\n-\tint socket, i, cur_socket;\n+\tint socket, heap_id, i;\n \tvoid *ret;\n \n \t/* return NULL if size is 0 or alignment is not power-of-2 */\n@@ -622,22 +646,25 @@ malloc_heap_alloc(const char *type, size_t size, int socket_arg,\n \telse\n \t\tsocket = socket_arg;\n \n-\t/* Check socket parameter */\n-\tif (socket >= RTE_MAX_NUMA_NODES)\n+\t/* turn socket ID into heap ID */\n+\theap_id = malloc_socket_to_heap_id(socket);\n+\t/* if heap id is negative, socket ID was invalid */\n+\tif (heap_id < 0)\n \t\treturn NULL;\n \n-\tret = heap_alloc_on_socket(type, size, socket, flags, align, bound,\n-\t\t\tcontig);\n+\tret = malloc_heap_alloc_on_heap_id(type, size, heap_id, flags, align,\n+\t\t\tbound, contig);\n \tif (ret != NULL || socket_arg != SOCKET_ID_ANY)\n \t\treturn ret;\n \n-\t/* try other heaps */\n+\t/* try other heaps. we are only iterating through native DPDK sockets,\n+\t * so external heaps won't be included.\n+\t */\n \tfor (i = 0; i < (int) rte_socket_count(); i++) {\n-\t\tcur_socket = rte_socket_id_by_idx(i);\n-\t\tif (cur_socket == socket)\n+\t\tif (i == heap_id)\n \t\t\tcontinue;\n-\t\tret = heap_alloc_on_socket(type, size, cur_socket, flags,\n-\t\t\t\talign, bound, contig);\n+\t\tret = malloc_heap_alloc_on_heap_id(type, size, i, flags, align,\n+\t\t\t\tbound, contig);\n \t\tif (ret != NULL)\n \t\t\treturn ret;\n \t}\n@@ -645,11 +672,11 @@ malloc_heap_alloc(const char *type, size_t size, int socket_arg,\n }\n \n static void *\n-heap_alloc_biggest_on_socket(const char *type, int socket, unsigned int flags,\n-\t\tsize_t align, bool contig)\n+heap_alloc_biggest_on_heap_id(const char *type, unsigned int heap_id,\n+\t\tunsigned int flags, size_t align, bool contig)\n {\n \tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n-\tstruct malloc_heap *heap = &mcfg->malloc_heaps[socket];\n+\tstruct malloc_heap *heap = &mcfg->malloc_heaps[heap_id];\n \tvoid *ret;\n \n \trte_spinlock_lock(&(heap->lock));\n@@ -667,7 +694,7 @@ void *\n malloc_heap_alloc_biggest(const char *type, int socket_arg, unsigned int flags,\n \t\tsize_t align, bool contig)\n {\n-\tint socket, i, cur_socket;\n+\tint socket, i, cur_socket, heap_id;\n \tvoid *ret;\n \n \t/* return NULL if align is not power-of-2 */\n@@ -682,11 +709,13 @@ malloc_heap_alloc_biggest(const char *type, int socket_arg, unsigned int flags,\n \telse\n \t\tsocket = socket_arg;\n \n-\t/* Check socket parameter */\n-\tif (socket >= RTE_MAX_NUMA_NODES)\n+\t/* turn socket ID into heap ID */\n+\theap_id = malloc_socket_to_heap_id(socket);\n+\t/* if heap id is negative, socket ID was invalid */\n+\tif (heap_id < 0)\n \t\treturn NULL;\n \n-\tret = heap_alloc_biggest_on_socket(type, socket, flags, align,\n+\tret = heap_alloc_biggest_on_heap_id(type, heap_id, flags, align,\n \t\t\tcontig);\n \tif (ret != NULL || socket_arg != SOCKET_ID_ANY)\n \t\treturn ret;\n@@ -696,8 +725,8 @@ malloc_heap_alloc_biggest(const char *type, int socket_arg, unsigned int flags,\n \t\tcur_socket = rte_socket_id_by_idx(i);\n \t\tif (cur_socket == socket)\n \t\t\tcontinue;\n-\t\tret = heap_alloc_biggest_on_socket(type, cur_socket, flags,\n-\t\t\t\talign, contig);\n+\t\tret = heap_alloc_biggest_on_heap_id(type, i, flags, align,\n+\t\t\t\tcontig);\n \t\tif (ret != NULL)\n \t\t\treturn ret;\n \t}\n@@ -919,7 +948,7 @@ malloc_heap_resize(struct malloc_elem *elem, size_t size)\n }\n \n /*\n- * Function to retrieve data for heap on given socket\n+ * Function to retrieve data for a given heap\n  */\n int\n malloc_heap_get_stats(struct malloc_heap *heap,\n@@ -957,7 +986,7 @@ malloc_heap_get_stats(struct malloc_heap *heap,\n }\n \n /*\n- * Function to retrieve data for heap on given socket\n+ * Function to retrieve data for a given heap\n  */\n void\n malloc_heap_dump(struct malloc_heap *heap, FILE *f)\ndiff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h\nindex f52cb5559..61b844b6f 100644\n--- a/lib/librte_eal/common/malloc_heap.h\n+++ b/lib/librte_eal/common/malloc_heap.h\n@@ -46,6 +46,9 @@ malloc_heap_get_stats(struct malloc_heap *heap,\n void\n malloc_heap_dump(struct malloc_heap *heap, FILE *f);\n \n+int\n+malloc_socket_to_heap_id(unsigned int socket_id);\n+\n int\n rte_eal_malloc_heap_init(void);\n \ndiff --git a/lib/librte_eal/common/rte_malloc.c b/lib/librte_eal/common/rte_malloc.c\nindex b51a6d111..dfcdf380a 100644\n--- a/lib/librte_eal/common/rte_malloc.c\n+++ b/lib/librte_eal/common/rte_malloc.c\n@@ -152,11 +152,20 @@ rte_malloc_get_socket_stats(int socket,\n \t\tstruct rte_malloc_socket_stats *socket_stats)\n {\n \tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tint heap_idx, ret = -1;\n \n-\tif (socket >= RTE_MAX_NUMA_NODES || socket < 0)\n-\t\treturn -1;\n+\trte_rwlock_read_lock(&mcfg->memory_hotplug_lock);\n \n-\treturn malloc_heap_get_stats(&mcfg->malloc_heaps[socket], socket_stats);\n+\theap_idx = malloc_socket_to_heap_id(socket);\n+\tif (heap_idx < 0)\n+\t\tgoto unlock;\n+\n+\tret = malloc_heap_get_stats(&mcfg->malloc_heaps[heap_idx],\n+\t\t\tsocket_stats);\n+unlock:\n+\trte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);\n+\n+\treturn ret;\n }\n \n /*\n@@ -168,12 +177,14 @@ rte_malloc_dump_heaps(FILE *f)\n \tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n \tunsigned int idx;\n \n-\tfor (idx = 0; idx < rte_socket_count(); idx++) {\n-\t\tunsigned int socket = rte_socket_id_by_idx(idx);\n-\t\tfprintf(f, \"Heap on socket %i:\\n\", socket);\n-\t\tmalloc_heap_dump(&mcfg->malloc_heaps[socket], f);\n+\trte_rwlock_read_lock(&mcfg->memory_hotplug_lock);\n+\n+\tfor (idx = 0; idx < RTE_MAX_HEAPS; idx++) {\n+\t\tfprintf(f, \"Heap id: %u\\n\", idx);\n+\t\tmalloc_heap_dump(&mcfg->malloc_heaps[idx], f);\n \t}\n \n+\trte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);\n }\n \n /*\n@@ -182,14 +193,19 @@ rte_malloc_dump_heaps(FILE *f)\n void\n rte_malloc_dump_stats(FILE *f, __rte_unused const char *type)\n {\n-\tunsigned int socket;\n+\tstruct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;\n+\tunsigned int heap_id;\n \tstruct rte_malloc_socket_stats sock_stats;\n+\n+\trte_rwlock_read_lock(&mcfg->memory_hotplug_lock);\n+\n \t/* Iterate through all initialised heaps */\n-\tfor (socket=0; socket< RTE_MAX_NUMA_NODES; socket++) {\n-\t\tif ((rte_malloc_get_socket_stats(socket, &sock_stats) < 0))\n-\t\t\tcontinue;\n+\tfor (heap_id = 0; heap_id < RTE_MAX_HEAPS; heap_id++) {\n+\t\tstruct malloc_heap *heap = &mcfg->malloc_heaps[heap_id];\n \n-\t\tfprintf(f, \"Socket:%u\\n\", socket);\n+\t\tmalloc_heap_get_stats(heap, &sock_stats);\n+\n+\t\tfprintf(f, \"Heap id:%u\\n\", heap_id);\n \t\tfprintf(f, \"\\tHeap_size:%zu,\\n\", sock_stats.heap_totalsz_bytes);\n \t\tfprintf(f, \"\\tFree_size:%zu,\\n\", sock_stats.heap_freesz_bytes);\n \t\tfprintf(f, \"\\tAlloc_size:%zu,\\n\", sock_stats.heap_allocsz_bytes);\n@@ -198,6 +214,7 @@ rte_malloc_dump_stats(FILE *f, __rte_unused const char *type)\n \t\tfprintf(f, \"\\tAlloc_count:%u,\\n\",sock_stats.alloc_count);\n \t\tfprintf(f, \"\\tFree_count:%u,\\n\", sock_stats.free_count);\n \t}\n+\trte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);\n \treturn;\n }\n \n",
    "prefixes": [
        "03/16"
    ]
}