]> git.itanic.dy.fi Git - linux-stable/commitdiff
net/mlx5: DR, Allocate htbl from its own slab allocator
authorYevgeny Kliteynik <kliteyn@nvidia.com>
Wed, 25 May 2022 23:32:49 +0000 (02:32 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 27 Oct 2022 14:50:39 +0000 (15:50 +0100)
SW steering allocates/frees lots of htbl structs. Create a
separate kmem_cache and allocate htbls from this allocator.

Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Alex Vesker <valex@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_domain.c
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_icm_pool.c
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_ste.c
drivers/net/ethernet/mellanox/mlx5/core/steering/dr_types.h

index 3fbcb2883a2657ffe5b641cac9dfcb18d14884ad..9a9836218c8e88bb155291c3c18255eacdca1258 100644 (file)
@@ -68,11 +68,20 @@ static int dr_domain_init_mem_resources(struct mlx5dr_domain *dmn)
                return -ENOMEM;
        }
 
+       dmn->htbls_kmem_cache = kmem_cache_create("mlx5_dr_htbls",
+                                                 sizeof(struct mlx5dr_ste_htbl), 0,
+                                                 SLAB_HWCACHE_ALIGN, NULL);
+       if (!dmn->htbls_kmem_cache) {
+               mlx5dr_err(dmn, "Couldn't create hash tables kmem_cache\n");
+               ret = -ENOMEM;
+               goto free_chunks_kmem_cache;
+       }
+
        dmn->ste_icm_pool = mlx5dr_icm_pool_create(dmn, DR_ICM_TYPE_STE);
        if (!dmn->ste_icm_pool) {
                mlx5dr_err(dmn, "Couldn't get icm memory\n");
                ret = -ENOMEM;
-               goto free_chunks_kmem_cache;
+               goto free_htbls_kmem_cache;
        }
 
        dmn->action_icm_pool = mlx5dr_icm_pool_create(dmn, DR_ICM_TYPE_MODIFY_ACTION);
@@ -94,6 +103,8 @@ static int dr_domain_init_mem_resources(struct mlx5dr_domain *dmn)
        mlx5dr_icm_pool_destroy(dmn->action_icm_pool);
 free_ste_icm_pool:
        mlx5dr_icm_pool_destroy(dmn->ste_icm_pool);
+free_htbls_kmem_cache:
+       kmem_cache_destroy(dmn->htbls_kmem_cache);
 free_chunks_kmem_cache:
        kmem_cache_destroy(dmn->chunks_kmem_cache);
 
@@ -105,6 +116,7 @@ static void dr_domain_uninit_mem_resources(struct mlx5dr_domain *dmn)
        mlx5dr_send_info_pool_destroy(dmn);
        mlx5dr_icm_pool_destroy(dmn->action_icm_pool);
        mlx5dr_icm_pool_destroy(dmn->ste_icm_pool);
+       kmem_cache_destroy(dmn->htbls_kmem_cache);
        kmem_cache_destroy(dmn->chunks_kmem_cache);
 }
 
index be02546a7de061ccbdfaea16e74f75d9ef59002d..ca91a0211a5cb7ed3edeb9960daac8cc641033c9 100644 (file)
@@ -470,6 +470,16 @@ void mlx5dr_icm_free_chunk(struct mlx5dr_icm_chunk *chunk)
        mutex_unlock(&pool->mutex);
 }
 
+struct mlx5dr_ste_htbl *mlx5dr_icm_pool_alloc_htbl(struct mlx5dr_icm_pool *pool)
+{
+       return kmem_cache_alloc(pool->dmn->htbls_kmem_cache, GFP_KERNEL);
+}
+
+void mlx5dr_icm_pool_free_htbl(struct mlx5dr_icm_pool *pool, struct mlx5dr_ste_htbl *htbl)
+{
+       kmem_cache_free(pool->dmn->htbls_kmem_cache, htbl);
+}
+
 struct mlx5dr_icm_pool *mlx5dr_icm_pool_create(struct mlx5dr_domain *dmn,
                                               enum mlx5dr_icm_type icm_type)
 {
index 09ebd3088857b4ff120fbd2953b470cf07ab22a8..9e19a8dc9022525d817302bcfe94543000fbab92 100644 (file)
@@ -491,7 +491,7 @@ struct mlx5dr_ste_htbl *mlx5dr_ste_htbl_alloc(struct mlx5dr_icm_pool *pool,
        u32 num_entries;
        int i;
 
-       htbl = kzalloc(sizeof(*htbl), GFP_KERNEL);
+       htbl = mlx5dr_icm_pool_alloc_htbl(pool);
        if (!htbl)
                return NULL;
 
@@ -503,6 +503,9 @@ struct mlx5dr_ste_htbl *mlx5dr_ste_htbl_alloc(struct mlx5dr_icm_pool *pool,
        htbl->lu_type = lu_type;
        htbl->byte_mask = byte_mask;
        htbl->refcount = 0;
+       htbl->pointing_ste = NULL;
+       htbl->ctrl.num_of_valid_entries = 0;
+       htbl->ctrl.num_of_collisions = 0;
        num_entries = mlx5dr_icm_pool_get_chunk_num_of_entries(chunk);
 
        for (i = 0; i < num_entries; i++) {
@@ -517,17 +520,20 @@ struct mlx5dr_ste_htbl *mlx5dr_ste_htbl_alloc(struct mlx5dr_icm_pool *pool,
        return htbl;
 
 out_free_htbl:
-       kfree(htbl);
+       mlx5dr_icm_pool_free_htbl(pool, htbl);
        return NULL;
 }
 
 int mlx5dr_ste_htbl_free(struct mlx5dr_ste_htbl *htbl)
 {
+       struct mlx5dr_icm_pool *pool = htbl->chunk->buddy_mem->pool;
+
        if (htbl->refcount)
                return -EBUSY;
 
        mlx5dr_icm_free_chunk(htbl->chunk);
-       kfree(htbl);
+       mlx5dr_icm_pool_free_htbl(pool, htbl);
+
        return 0;
 }
 
index 4f38f0f5b3523b8789041f78bc7d5ae5ce7252be..b645c0ab9a72825e29a14f5454ca8a9399d79077 100644 (file)
@@ -916,6 +916,7 @@ struct mlx5dr_domain {
        struct mlx5dr_send_info_pool *send_info_pool_rx;
        struct mlx5dr_send_info_pool *send_info_pool_tx;
        struct kmem_cache *chunks_kmem_cache;
+       struct kmem_cache *htbls_kmem_cache;
        struct mlx5dr_send_ring *send_ring;
        struct mlx5dr_domain_info info;
        struct xarray csum_fts_xa;
@@ -1162,6 +1163,9 @@ u32 mlx5dr_icm_pool_get_chunk_num_of_entries(struct mlx5dr_icm_chunk *chunk);
 u32 mlx5dr_icm_pool_get_chunk_byte_size(struct mlx5dr_icm_chunk *chunk);
 u8 *mlx5dr_ste_get_hw_ste(struct mlx5dr_ste *ste);
 
+struct mlx5dr_ste_htbl *mlx5dr_icm_pool_alloc_htbl(struct mlx5dr_icm_pool *pool);
+void mlx5dr_icm_pool_free_htbl(struct mlx5dr_icm_pool *pool, struct mlx5dr_ste_htbl *htbl);
+
 static inline int
 mlx5dr_icm_pool_dm_type_to_entry_size(enum mlx5dr_icm_type icm_type)
 {