Allocate mark copy resource from indexed pool helps rte flow saves the 4
bytes index instead of 8 bytes pointer. For mark copy resource itself, it
helps save MALLOC_ELEM_OVERHEAD bytes from rte_malloc().

Signed-off-by: Suanming Mou <suanmi...@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viachesl...@mellanox.com>
---
 drivers/net/mlx5/mlx5.c      | 11 +++++++++++
 drivers/net/mlx5/mlx5.h      |  1 +
 drivers/net/mlx5/mlx5_flow.c | 40 ++++++++++++++++++++++++++++------------
 drivers/net/mlx5/mlx5_flow.h |  5 +++--
 4 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index ac9391b..1bb464d 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -268,6 +268,17 @@ struct mlx5_dev_spawn_data {
                .type = "mlx5_meter_ipool",
        },
        {
+               .size = sizeof(struct mlx5_flow_meter),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_mcp_ipool",
+       },
+       {
                .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
                .trunk_size = 64,
                .grow_trunk = 3,
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 009c1da..faf65f3 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -53,6 +53,7 @@ enum mlx5_ipool_index {
        MLX5_IPOOL_JUMP, /* Pool for jump resource. */
 #endif
        MLX5_IPOOL_MTR, /* Pool for meter resource. */
+       MLX5_IPOOL_MCP, /* Pool for metadata resource. */
        MLX5_IPOOL_HRXQ, /* Pool for hrxq resource. */
        MLX5_IPOOL_MLX5_FLOW, /* Pool for mlx5 flow handle. */
        MLX5_IPOOL_MAX,
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 4205f23..eaf3d8d 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -2962,6 +2962,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
                [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
        };
        struct mlx5_flow_mreg_copy_resource *mcp_res;
+       uint32_t idx = 0;
        int ret;
 
        /* Fill the register fileds in the flow. */
@@ -3030,11 +3031,12 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
                };
        }
        /* Build a new entry. */
-       mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
+       mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
        if (!mcp_res) {
                rte_errno = ENOMEM;
                return NULL;
        }
+       mcp_res->idx = idx;
        /*
         * The copy Flows are not included in any list. There
         * ones are referenced from other Flows and can not
@@ -3056,7 +3058,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
 error:
        if (mcp_res->flow)
                flow_list_destroy(dev, NULL, mcp_res->flow);
-       rte_free(mcp_res);
+       mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
        return NULL;
 }
 
@@ -3072,9 +3074,13 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
                          struct rte_flow *flow)
 {
-       struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
+       struct mlx5_flow_mreg_copy_resource *mcp_res;
        struct mlx5_priv *priv = dev->data->dev_private;
 
+       if (!flow->rix_mreg_copy)
+               return;
+       mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
+                                flow->rix_mreg_copy);
        if (!mcp_res || !priv->mreg_cp_tbl)
                return;
        if (flow->copy_applied) {
@@ -3093,8 +3099,8 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
        MLX5_ASSERT(mcp_res->flow);
        flow_list_destroy(dev, NULL, mcp_res->flow);
        mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
-       rte_free(mcp_res);
-       flow->mreg_copy = NULL;
+       mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
+       flow->rix_mreg_copy = 0;
 }
 
 /**
@@ -3112,10 +3118,15 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
                            struct rte_flow *flow)
 {
-       struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
+       struct mlx5_flow_mreg_copy_resource *mcp_res;
+       struct mlx5_priv *priv = dev->data->dev_private;
        int ret;
 
-       if (!mcp_res || flow->copy_applied)
+       if (!flow->rix_mreg_copy || flow->copy_applied)
+               return 0;
+       mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
+                                flow->rix_mreg_copy);
+       if (!mcp_res)
                return 0;
        if (!mcp_res->appcnt) {
                ret = flow_drv_apply(dev, mcp_res->flow, NULL);
@@ -3139,9 +3150,14 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
                           struct rte_flow *flow)
 {
-       struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
+       struct mlx5_flow_mreg_copy_resource *mcp_res;
+       struct mlx5_priv *priv = dev->data->dev_private;
 
-       if (!mcp_res || !flow->copy_applied)
+       if (!flow->rix_mreg_copy || !flow->copy_applied)
+               return;
+       mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
+                                flow->rix_mreg_copy);
+       if (!mcp_res)
                return;
        MLX5_ASSERT(mcp_res->appcnt);
        --mcp_res->appcnt;
@@ -3172,7 +3188,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
        MLX5_ASSERT(mcp_res->flow);
        flow_list_destroy(dev, NULL, mcp_res->flow);
        mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
-       rte_free(mcp_res);
+       mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
 }
 
 /**
@@ -3264,7 +3280,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
                                (dev, MLX5_FLOW_MARK_DEFAULT, error);
                        if (!mcp_res)
                                return -rte_errno;
-                       flow->mreg_copy = mcp_res;
+                       flow->rix_mreg_copy = mcp_res->idx;
                        if (dev->data->dev_started) {
                                mcp_res->appcnt++;
                                flow->copy_applied = 1;
@@ -3277,7 +3293,7 @@ uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev 
*dev, int32_t priority,
                                flow_mreg_add_copy_action(dev, mark->id, error);
                        if (!mcp_res)
                                return -rte_errno;
-                       flow->mreg_copy = mcp_res;
+                       flow->rix_mreg_copy = mcp_res->idx;
                        if (dev->data->dev_started) {
                                mcp_res->appcnt++;
                                flow->copy_applied = 1;
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index b508299..c9b357d 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -460,6 +460,7 @@ struct mlx5_flow_mreg_copy_resource {
        /* List entry for device flows. */
        uint32_t refcnt; /* Reference counter. */
        uint32_t appcnt; /* Apply/Remove counter. */
+       uint32_t idx;
        struct rte_flow *flow; /* Built flow for copy. */
 };
 
@@ -756,8 +757,8 @@ struct rte_flow {
        enum mlx5_flow_drv_type drv_type; /**< Driver type. */
        struct mlx5_flow_rss rss; /**< RSS context. */
        uint32_t counter; /**< Holds flow counter. */
-       struct mlx5_flow_mreg_copy_resource *mreg_copy;
-       /**< pointer to metadata register copy table resource. */
+       uint32_t rix_mreg_copy;
+       /**< Index to metadata register copy table resource. */
        uint16_t meter; /**< Holds flow meter id. */
        uint32_t dev_handles;
        /**< Device flow handles that are part of the flow. */
-- 
1.8.3.1

Reply via email to