get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 117357,
    "url": "http://patches.dpdk.org/api/patches/117357/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/tencent_FEE531AF1F40D6FD8FB249B7DE9B04E7E408@qq.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": "<tencent_FEE531AF1F40D6FD8FB249B7DE9B04E7E408@qq.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/tencent_FEE531AF1F40D6FD8FB249B7DE9B04E7E408@qq.com",
    "date": "2022-10-05T04:09:43",
    "name": "[v5,01/10] memarea: introduce memarea library",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "1a9d1ec99d85313e3306d218992b79f53027d7e7",
    "submitter": {
        "id": 2867,
        "url": "http://patches.dpdk.org/api/people/2867/?format=api",
        "name": "datshan",
        "email": "datshan@qq.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/tencent_FEE531AF1F40D6FD8FB249B7DE9B04E7E408@qq.com/mbox/",
    "series": [
        {
            "id": 24981,
            "url": "http://patches.dpdk.org/api/series/24981/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=24981",
            "date": "2022-10-05T04:09:43",
            "name": "[v5,01/10] memarea: introduce memarea library",
            "version": 5,
            "mbox": "http://patches.dpdk.org/series/24981/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/117357/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/117357/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id CCF1DA0542;\n\tWed,  5 Oct 2022 06:10:06 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 837AE40E5A;\n\tWed,  5 Oct 2022 06:10:01 +0200 (CEST)",
            "from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com\n [203.205.221.233])\n by mails.dpdk.org (Postfix) with ESMTP id E0A9240694\n for <dev@dpdk.org>; Wed,  5 Oct 2022 06:09:58 +0200 (CEST)",
            "from qq.com ([120.229.93.179])\n by newxmesmtplogicsvrsza31.qq.com (NewEsmtp) with SMTP\n id 27598E97; Wed, 05 Oct 2022 12:09:53 +0800"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512;\n t=1664942997; bh=kufC0W6a+WsfiQHlRf1PNDEhWzmcZjrhRL9NkE+WX7o=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References;\n b=gs3Dh65DkZMv9E23/b0H/KYJ/rPtVecjlaHGKrOcwqaB3yMYqAcgSbmQnAdnGNdNS\n KyqxK1T9/OSuhoi/UhmZGjcFWbSz7aiONx2lulpndRX+Nj7t8Ox1otFnAg2/Cz492S\n UqYlUXcM+othX/6ZGTNwRxbotk0KsNxMpJRHhL1Q=",
        "X-QQ-mid": "xmsmtpt1664942995ta761kmvq",
        "Message-ID": "<tencent_FEE531AF1F40D6FD8FB249B7DE9B04E7E408@qq.com>",
        "X-QQ-XMAILINFO": "OKKHiI6c9SH3x1lldSLzqkdwHFgwxerIsD1wlY69i9twTJd3rbwOaS8NDCyDJ4\n 4iNAKtnvy1v2+yamfQ3v2ssqzYmkZV7VKpcIn/Wmsa3TZSObtwJMBtAZx0DuXq16YpLfh3cZKYpm\n 5BPrMueESUOWQ1+xdv2aqqQAE61yFw/H4yba740gLHVJwLLX+jbrKu0pQYk+3jXE6ApKJQW3Em+0\n P0jCGQs2nO/hrnQlHuMmZUkDfsYyo6IVD/Xc33RMkr1c2QXVE4qjjwMOhhpOxAwkOYDD/Bpc41yH\n q7tQqQvG/vwhK72kUoyf40qmFBam2efeKzsZnkKBFUGCjArF25sJLyDtsbKqCOkJIp0gz2Agj9Xo\n 8Ie2gD6+GgsWZMWel/iV/qU8rWyZtWdbidTcPJMOwEeV34PzMQo+eDzf2VSgueHHNlsWLNpNGDKS\n jEqaT1VaXX+LM0YvEQDmWme1QZj61DRtE6fRNpUEp0uKR1H2RlffX2H5AdRYOUfBmTWMBiLbgpeF\n 00+AkgTVMnngUdJES/WMbPURLcy9fOep/2Vxf3XMfACauEAUyEX/qByD+rqLe95KhvHU5xv89Wit\n f5LM8t8X6QpPk9XzanA41nIr3kU+LqmXPpOWOJqP5Eky9+D31in2fEpI/lpgSucfzIh5+BLgDQD9\n Vn7zW+VQf3dQQzQPXdfUWcKrfKNpIYX/80Y4C+HxyshDd595AV3SgeQNVZpoHeqo9VTvCd9wbO/g\n MZi1Lhc2OmhQi7ijAmtmI5f1DH4YvcfLR2nBYpiS3D4oGz6TtUHQKPZwdjsCzTd3MJhXI6XVp8JO\n /8k1ZX6OSFSTjVZie+5RXLN3o/e/W2OIDGlBlgRhXu8ZQCfQ+9mtJkLq6ZgESSph5sgnooGv2Kad\n onovT2TI2WbQC3ka/y41g/Qg9wkRhZQ9DlysuraYCWRZ365EtGfG7UyWKLo+Hh1/+f6w0yVihxG0\n 8Pz/IfFy/vH24CYnylBMvPr601gR/TwxX36/wkBeFq6HnlEGED273WhboOjkFEJoqPJSkkLIP44G\n nhSQ7zNmKd3sbnx82mDJsWI5pYkJxyk50hN44I/A==",
        "From": "datshan <datshan@qq.com>",
        "To": "david.marchand@redhat.com, mb@smartsharesystems.com,\n anatoly.burakov@intel.com, dmitry.kozliuk@gmail.com, jerinjacobk@gmail.com",
        "Cc": "thomas@monjalon.net, dev@dpdk.org, Chengwen Feng <fengchengwen@huawei.com>",
        "Subject": "[PATCH v5 01/10] memarea: introduce memarea library",
        "Date": "Wed,  5 Oct 2022 12:09:43 +0800",
        "X-OQ-MSGID": "<20221005040952.8166-2-datshan@qq.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20221005040952.8166-1-datshan@qq.com>",
        "References": "<20220721044648.6817-1-fengchengwen@huawei.com>\n <20221005040952.8166-1-datshan@qq.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <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 <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "From: Chengwen Feng <fengchengwen@huawei.com>\n\nThe memarea library is an allocator of variable-size object which based\non a memory region.\n\nThis patch provides create/destroy API.\n\nSigned-off-by: Chengwen Feng <fengchengwen@huawei.com>\n---\n MAINTAINERS                            |   5 +\n doc/api/doxy-api-index.md              |   3 +-\n doc/api/doxy-api.conf.in               |   1 +\n doc/guides/prog_guide/index.rst        |   1 +\n doc/guides/prog_guide/memarea_lib.rst  |  39 ++++++\n doc/guides/rel_notes/release_22_11.rst |   6 +\n lib/eal/common/eal_common_log.c        |   1 +\n lib/eal/include/rte_log.h              |   1 +\n lib/memarea/memarea_private.h          |  30 +++++\n lib/memarea/meson.build                |  16 +++\n lib/memarea/rte_memarea.c              | 157 +++++++++++++++++++++++++\n lib/memarea/rte_memarea.h              | 145 +++++++++++++++++++++++\n lib/memarea/version.map                |  12 ++\n lib/meson.build                        |   1 +\n 14 files changed, 417 insertions(+), 1 deletion(-)\n create mode 100644 doc/guides/prog_guide/memarea_lib.rst\n create mode 100644 lib/memarea/memarea_private.h\n create mode 100644 lib/memarea/meson.build\n create mode 100644 lib/memarea/rte_memarea.c\n create mode 100644 lib/memarea/rte_memarea.h\n create mode 100644 lib/memarea/version.map",
    "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex a55b379d73..b9c638221d 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -1550,6 +1550,11 @@ F: app/test/test_lpm*\n F: app/test/test_func_reentrancy.c\n F: app/test/test_xmmt_ops.h\n \n+Memarea - EXPERIMENTAL\n+M: Chengwen Feng <fengchengwen@huawei.com>\n+F: lib/memarea\n+F: doc/guides/prog_guide/memarea_lib.rst\n+\n Membership - EXPERIMENTAL\n M: Yipeng Wang <yipeng1.wang@intel.com>\n M: Sameh Gobriel <sameh.gobriel@intel.com>\ndiff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md\nindex de488c7abf..24456604f8 100644\n--- a/doc/api/doxy-api-index.md\n+++ b/doc/api/doxy-api-index.md\n@@ -62,7 +62,8 @@ The public API headers are grouped by topics:\n   [memzone](@ref rte_memzone.h),\n   [mempool](@ref rte_mempool.h),\n   [malloc](@ref rte_malloc.h),\n-  [memcpy](@ref rte_memcpy.h)\n+  [memcpy](@ref rte_memcpy.h),\n+  [memarea](@ref rte_memarea.h)\n \n - **timers**:\n   [cycles](@ref rte_cycles.h),\ndiff --git a/doc/api/doxy-api.conf.in b/doc/api/doxy-api.conf.in\nindex f0886c3bd1..8334ebcbd6 100644\n--- a/doc/api/doxy-api.conf.in\n+++ b/doc/api/doxy-api.conf.in\n@@ -53,6 +53,7 @@ INPUT                   = @TOPDIR@/doc/api/doxy-api-index.md \\\n                           @TOPDIR@/lib/latencystats \\\n                           @TOPDIR@/lib/lpm \\\n                           @TOPDIR@/lib/mbuf \\\n+                          @TOPDIR@/lib/memarea \\\n                           @TOPDIR@/lib/member \\\n                           @TOPDIR@/lib/mempool \\\n                           @TOPDIR@/lib/meter \\\ndiff --git a/doc/guides/prog_guide/index.rst b/doc/guides/prog_guide/index.rst\nindex 8564883018..e9015d65e3 100644\n--- a/doc/guides/prog_guide/index.rst\n+++ b/doc/guides/prog_guide/index.rst\n@@ -37,6 +37,7 @@ Programmer's Guide\n     hash_lib\n     toeplitz_hash_lib\n     efd_lib\n+    memarea_lib\n     member_lib\n     lpm_lib\n     lpm6_lib\ndiff --git a/doc/guides/prog_guide/memarea_lib.rst b/doc/guides/prog_guide/memarea_lib.rst\nnew file mode 100644\nindex 0000000000..b96dad15f6\n--- /dev/null\n+++ b/doc/guides/prog_guide/memarea_lib.rst\n@@ -0,0 +1,39 @@\n+..  SPDX-License-Identifier: BSD-3-Clause\n+    Copyright(c) 2022 HiSilicon Limited\n+\n+Memarea Library\n+===============\n+\n+Introduction\n+------------\n+\n+The memarea library provides an allocator of variable-size objects, it is\n+oriented towards the application layer, which could provides 'region-based\n+memory management' function [1].\n+\n+The main features are as follows:\n+\n+* The default aligement size is ``RTE_CACHE_LINE_SIZE``.\n+\n+* The memory region can be initialized from the following memory sources:\n+  a) RTE memory: e.g. invoke ``rte_malloc_socket`` to obtain. b) System API:\n+  e.g. invoke posix_memalign to obtain. c) User provided address: it can be from\n+  extendedd memory as long as it is available. d) User provided memarea: it can\n+  be from another memarea.\n+\n+* It provides refcnt feature which could be useful in multi-reader scenario.\n+\n+* It supports MT-safe as long as it's specified at creation time.\n+\n+Library API Overview\n+--------------------\n+\n+The ``rte_memarea_create()`` function is used to create a memarea, the function\n+returns the pointer to the created memarea or ``NULL`` if the creation failed.\n+\n+The ``rte_memarea_destroy()`` function is used to destroy a memarea.\n+\n+Reference\n+---------\n+\n+[1] https://en.wikipedia.org/wiki/Region-based_memory_management\ndiff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst\nindex 5d8ef669b8..4c1f760b98 100644\n--- a/doc/guides/rel_notes/release_22_11.rst\n+++ b/doc/guides/rel_notes/release_22_11.rst\n@@ -55,6 +55,12 @@ New Features\n      Also, make sure to start the actual text at the margin.\n      =======================================================\n \n+* **Added memarea library.**\n+\n+  The memarea library is an allocator of variable-size objects, it is oriented\n+  towards the application layer, which could provides 'region-based memory\n+  management' function.\n+\n * **Added configuration for asynchronous flow connection tracking.**\n \n   Added connection tracking action number hint to ``rte_flow_configure``\ndiff --git a/lib/eal/common/eal_common_log.c b/lib/eal/common/eal_common_log.c\nindex bd7b188ceb..3d62af59c6 100644\n--- a/lib/eal/common/eal_common_log.c\n+++ b/lib/eal/common/eal_common_log.c\n@@ -369,6 +369,7 @@ static const struct logtype logtype_strings[] = {\n \t{RTE_LOGTYPE_EFD,        \"lib.efd\"},\n \t{RTE_LOGTYPE_EVENTDEV,   \"lib.eventdev\"},\n \t{RTE_LOGTYPE_GSO,        \"lib.gso\"},\n+\t{RTE_LOGTYPE_MEMAREA,    \"lib.memarea\"},\n \t{RTE_LOGTYPE_USER1,      \"user1\"},\n \t{RTE_LOGTYPE_USER2,      \"user2\"},\n \t{RTE_LOGTYPE_USER3,      \"user3\"},\ndiff --git a/lib/eal/include/rte_log.h b/lib/eal/include/rte_log.h\nindex 25ce42cdfc..708f3a39dd 100644\n--- a/lib/eal/include/rte_log.h\n+++ b/lib/eal/include/rte_log.h\n@@ -48,6 +48,7 @@ extern \"C\" {\n #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */\n #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */\n #define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */\n+#define RTE_LOGTYPE_MEMAREA   21 /**< Log related to memarea. */\n \n /* these log types can be used in an application */\n #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */\ndiff --git a/lib/memarea/memarea_private.h b/lib/memarea/memarea_private.h\nnew file mode 100644\nindex 0000000000..c76392d3e6\n--- /dev/null\n+++ b/lib/memarea/memarea_private.h\n@@ -0,0 +1,30 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2022 HiSilicon Limited\n+ */\n+\n+#ifndef MEMAREA_PRIVATE_H\n+#define MEMAREA_PRIVATE_H\n+\n+#include <rte_memarea.h>\n+\n+#define MEMAREA_FREE_ELEM_COOKIE\t0xFFFFFFFF\n+\n+struct memarea_elem {\n+\tsize_t   size;\n+\tuint32_t cookie;\n+\tint32_t  refcnt; /* Non-zero indicates that it has been allocated */\n+\tTAILQ_ENTRY(memarea_elem) elem_node;\n+\tTAILQ_ENTRY(memarea_elem) free_node;\n+} __rte_cache_aligned;\n+\n+TAILQ_HEAD(memarea_elem_list, memarea_elem);\n+\n+struct rte_memarea {\n+\tstruct rte_memarea_param init;\n+\trte_spinlock_t           lock;\n+\tvoid                    *area_addr;\n+\tstruct memarea_elem_list elem_list;\n+\tstruct memarea_elem_list free_list;\n+} __rte_cache_aligned;\n+\n+#endif /* MEMAREA_PRIVATE_H */\ndiff --git a/lib/memarea/meson.build b/lib/memarea/meson.build\nnew file mode 100644\nindex 0000000000..0a74fb4cd1\n--- /dev/null\n+++ b/lib/memarea/meson.build\n@@ -0,0 +1,16 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright(c) 2022 HiSilicon Limited\n+\n+if is_windows\n+    build = false\n+    reason = 'not supported on Windows'\n+    subdir_done()\n+endif\n+\n+sources = files(\n+        'rte_memarea.c',\n+)\n+headers = files(\n+        'rte_memarea.h',\n+)\n+deps += []\ndiff --git a/lib/memarea/rte_memarea.c b/lib/memarea/rte_memarea.c\nnew file mode 100644\nindex 0000000000..868da7661d\n--- /dev/null\n+++ b/lib/memarea/rte_memarea.c\n@@ -0,0 +1,157 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2022 HiSilicon Limited\n+ */\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+\n+#include <rte_common.h>\n+#include <rte_log.h>\n+#include <rte_malloc.h>\n+#include <rte_spinlock.h>\n+\n+#include \"rte_memarea.h\"\n+#include \"memarea_private.h\"\n+\n+static int\n+memarea_check_param(const struct rte_memarea_param *init)\n+{\n+\tsize_t len;\n+\n+\tif (init == NULL) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea init param is NULL!\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tlen = strnlen(init->name, RTE_MEMAREA_NAMESIZE);\n+\tif (len == 0 || len >= RTE_MEMAREA_NAMESIZE) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea name size %zu invalid!\\n\", len);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (init->source != RTE_MEMAREA_SOURCE_RTE_MEMORY &&\n+\t    init->source != RTE_MEMAREA_SOURCE_SYSTEM_API &&\n+\t    init->source != RTE_MEMAREA_SOURCE_USER_ADDR &&\n+\t    init->source != RTE_MEMAREA_SOURCE_USER_MEMAREA) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s source: %d not supported!\\n\",\n+\t\t\tinit->name, init->source);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (init->total_sz <= sizeof(struct memarea_elem)) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s total-size: %zu too small!\\n\",\n+\t\t\tinit->name, init->total_sz);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (init->source == RTE_MEMAREA_SOURCE_USER_ADDR && init->user_addr == NULL) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s user provided addr is NULL!\\n\", init->name);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (init->source == RTE_MEMAREA_SOURCE_USER_ADDR &&\n+\t    ((uintptr_t)init->user_addr & (RTE_CACHE_LINE_SIZE - 1))) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s user provided addr should align: %d!\\n\",\n+\t\t\tinit->name, RTE_CACHE_LINE_SIZE);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (init->source == RTE_MEMAREA_SOURCE_USER_MEMAREA && init->user_memarea == NULL) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s user provided memarea is NULL!\\n\", init->name);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (init->alg != RTE_MEMAREA_ALG_DEFAULT) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s alg: %d not supported!\\n\",\n+\t\t\tinit->name, init->alg);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void *\n+memarea_alloc_from_system_api(size_t size)\n+{\n+\tvoid *ptr = NULL;\n+\tint ret;\n+\n+\tret = posix_memalign(&ptr, RTE_CACHE_LINE_SIZE, size);\n+\tif (ret)\n+\t\treturn NULL;\n+\treturn ptr;\n+}\n+\n+static void *\n+memarea_alloc_area(const struct rte_memarea_param *init)\n+{\n+\tvoid *ptr = NULL;\n+\n+\tif (init->source == RTE_MEMAREA_SOURCE_RTE_MEMORY)\n+\t\tptr = rte_malloc_socket(NULL, init->total_sz, RTE_CACHE_LINE_SIZE,\n+\t\t\t\t\tinit->numa_socket);\n+\telse if (init->source == RTE_MEMAREA_SOURCE_SYSTEM_API)\n+\t\tptr = memarea_alloc_from_system_api(init->total_sz);\n+\telse if (init->source == RTE_MEMAREA_SOURCE_USER_ADDR)\n+\t\tptr = init->user_addr;\n+\n+\tif (ptr == NULL)\n+\t\tRTE_LOG(ERR, MEMAREA, \"memarea: %s alloc memory area fail!\\n\", init->name);\n+\n+\treturn ptr;\n+}\n+\n+struct rte_memarea *\n+rte_memarea_create(const struct rte_memarea_param *init)\n+{\n+\tstruct memarea_elem *elem;\n+\tstruct rte_memarea *ma;\n+\tvoid *addr;\n+\tint ret;\n+\n+\tret = memarea_check_param(init);\n+\tif (ret)\n+\t\treturn NULL;\n+\n+\taddr = memarea_alloc_area(init);\n+\tif (addr == NULL)\n+\t\treturn NULL;\n+\n+\tma = rte_zmalloc(NULL, sizeof(struct rte_memarea), RTE_CACHE_LINE_SIZE);\n+\tif (ma == NULL) {\n+\t\tRTE_LOG(ERR, MEMAREA, \"malloc memarea: %s management obj fail!\\n\", init->name);\n+\t\treturn NULL;\n+\t}\n+\n+\tma->init = *init;\n+\trte_spinlock_init(&ma->lock);\n+\tTAILQ_INIT(&ma->elem_list);\n+\tTAILQ_INIT(&ma->free_list);\n+\tma->area_addr = addr;\n+\telem = addr;\n+\telem->size = init->total_sz - sizeof(struct memarea_elem);\n+\telem->cookie = MEMAREA_FREE_ELEM_COOKIE;\n+\telem->refcnt = 0;\n+\tTAILQ_INSERT_TAIL(&ma->elem_list, elem, elem_node);\n+\tTAILQ_INSERT_TAIL(&ma->free_list, elem, free_node);\n+\n+\treturn ma;\n+}\n+\n+static void\n+memarea_free_area(struct rte_memarea *ma)\n+{\n+\tif (ma->init.source == RTE_MEMAREA_SOURCE_RTE_MEMORY)\n+\t\trte_free(ma->area_addr);\n+\telse if (ma->init.source == RTE_MEMAREA_SOURCE_SYSTEM_API)\n+\t\tfree(ma->area_addr);\n+}\n+\n+void\n+rte_memarea_destroy(struct rte_memarea *ma)\n+{\n+\tif (ma == NULL)\n+\t\treturn;\n+\tmemarea_free_area(ma);\n+\trte_free(ma);\n+}\ndiff --git a/lib/memarea/rte_memarea.h b/lib/memarea/rte_memarea.h\nnew file mode 100644\nindex 0000000000..543cda4cac\n--- /dev/null\n+++ b/lib/memarea/rte_memarea.h\n@@ -0,0 +1,145 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2022 HiSilicon Limited\n+ */\n+\n+#ifndef RTE_MEMAREA_H\n+#define RTE_MEMAREA_H\n+\n+/**\n+ * @file\n+ * RTE Memarea.\n+ *\n+ * The memarea is an allocator of variable-size object which based on a memory\n+ * region. It has the following features:\n+ *\n+ * - The default alignment size is RTE_CACHE_LINE_SIZE.\n+ * - The memory region can be initialized from the following memory sources:\n+ *   1. RTE memory: e.g. invoke rte_malloc_socket to obtain.\n+ *   2. System API: e.g. invoke posix_memalign to obtain.\n+ *   3. User provided address: it can be from extended memory as long as it is\n+ *      available. The address must be aligned to RTE_CACHE_LINE_SIZE.\n+ *   4) User provided memarea: it can be from another memarea. So we can build\n+ *      the following memory management structure:\n+ *         \\code{.unparsed}\n+ *                           -------------\n+ *                           | memarea-1 |\n+ *                           -------------\n+ *                                 |\n+ *                                 v\n+ *                  -------------------------------\n+ *                  |               |             |\n+ *                  v               v             v\n+ *            -------------   -------------   ----------\n+ *            | memarea-2 |   | memarea-3 |   | object |\n+ *            -------------   -------------   ----------\n+ *         \\endcode\n+ *      As shown above, the memarea-2/3 both create from memarea-1's memory.\n+ * - It provides refcnt feature which could be useful in multi-reader scenario.\n+ * - It supports MT-safe as long as it's specified at creation time. If not\n+ *   specified, all the functions of the memarea API are lock-free, and assume\n+ *   to not be invoked in parallel on different logical cores to work on the\n+ *   same memarea.\n+ */\n+\n+#include <stdbool.h>\n+#include <stdint.h>\n+#include <stdio.h>\n+\n+#include <rte_compat.h>\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+#define RTE_MEMAREA_NAMESIZE\t64\n+\n+/**\n+ * Memarea memory source.\n+ */\n+enum rte_memarea_source {\n+\t/** Memory source comes from rte memory. */\n+\tRTE_MEMAREA_SOURCE_RTE_MEMORY,\n+\t/** Memory source comes from system API. */\n+\tRTE_MEMAREA_SOURCE_SYSTEM_API,\n+\t/** Memory source comes from user-provided address. */\n+\tRTE_MEMAREA_SOURCE_USER_ADDR,\n+\t/** Memory source comes from user-provided memarea. */\n+\tRTE_MEMAREA_SOURCE_USER_MEMAREA,\n+};\n+\n+/**\n+ * Memarea memory management algorithm.\n+ */\n+enum rte_memarea_alg {\n+\t/* The default management algorithm is a variant of the next fit\n+\t * algorithm. It uses a free-list to apply for memory and uses an\n+\t * element-list in ascending order of address to support merging\n+\t * upon free.\n+\t */\n+\tRTE_MEMAREA_ALG_DEFAULT,\n+};\n+\n+struct rte_memarea;\n+\n+struct rte_memarea_param {\n+\tchar name[RTE_MEMAREA_NAMESIZE]; /**< Name of memarea. */\n+\tenum rte_memarea_source source;  /**< Memory source of memarea. */\n+\tenum rte_memarea_alg alg;        /**< Memory management algorithm. */\n+\tsize_t total_sz;                 /**< total size (bytes) of memarea. */\n+\t/** Indicates whether the memarea API should be MT-safe. */\n+\tuint32_t mt_safe : 1;\n+\tunion {\n+\t\t/** Numa socket from which to apply for memarea's memory, this\n+\t\t * field is valid only when the source is set to be\n+\t\t * RTE_MEMAREA_SOURCE_RTE_MEMORY.\n+\t\t */\n+\t\tint numa_socket;\n+\t\t/** User provided address, this field is valid only when the\n+\t\t * source is set to be RTE_MEMAREA_SOURCE_USER_ADDR.\n+\t\t * Note: the provided address must align at least\n+\t\t * RTE_CACHE_LINE_SIZE.\n+\t\t */\n+\t\tvoid *user_addr;\n+\t\t/** User provided memarea, this field is valid only when the\n+\t\t * source is set to be RTE_MEMAREA_SOURCE_USER_MEMAREA.\n+\t\t */\n+\t\tstruct rte_memarea *user_memarea;\n+\t};\n+};\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change without prior notice.\n+ *\n+ * Create memarea.\n+ *\n+ * Create one new memarea.\n+ *\n+ * @param init\n+ *   The init parameter of memarea.\n+ *\n+ * @return\n+ *   Non-NULL on success. Otherwise NULL is returned.\n+ */\n+__rte_experimental\n+struct rte_memarea *rte_memarea_create(const struct rte_memarea_param *init);\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change without prior notice.\n+ *\n+ * Destroy memarea.\n+ *\n+ * Destroy the memarea.\n+ *\n+ * @param ma\n+ *   The pointer of memarea.\n+ */\n+__rte_experimental\n+void rte_memarea_destroy(struct rte_memarea *ma);\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+#endif /* RTE_MEMAREA_H */\ndiff --git a/lib/memarea/version.map b/lib/memarea/version.map\nnew file mode 100644\nindex 0000000000..f36a04d7cf\n--- /dev/null\n+++ b/lib/memarea/version.map\n@@ -0,0 +1,12 @@\n+EXPERIMENTAL {\n+\tglobal:\n+\n+\trte_memarea_create;\n+\trte_memarea_destroy;\n+\n+\tlocal: *;\n+};\n+\n+INTERNAL {\n+\tlocal: *;\n+};\ndiff --git a/lib/meson.build b/lib/meson.build\nindex c648f7d800..521a25d6c0 100644\n--- a/lib/meson.build\n+++ b/lib/meson.build\n@@ -42,6 +42,7 @@ libraries = [\n         'kni',\n         'latencystats',\n         'lpm',\n+        'memarea',\n         'member',\n         'pcapng',\n         'power',\n",
    "prefixes": [
        "v5",
        "01/10"
    ]
}