]> git.itanic.dy.fi Git - linux-stable/commitdiff
net/mlx5: DR, Allocate icm_chunks from their own slab allocator
authorYevgeny Kliteynik <kliteyn@nvidia.com>
Wed, 25 May 2022 22:44:18 +0000 (01:44 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 27 Oct 2022 14:50:39 +0000 (15:50 +0100)
SW steering allocates/frees lots of icm_chunk structs. To make this more
efficiently, create a separate kmem_cache and allocate these chunks from
this allocator.
By doing this we observe that the alloc/free "hiccups" frequency has
become much lower, which allows for a more steady rule insersion rate.

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_types.h

index 3dc784b2274139121bc84fcbb29bb739c792f360..3fbcb2883a2657ffe5b641cac9dfcb18d14884ad 100644 (file)
@@ -60,10 +60,19 @@ static int dr_domain_init_mem_resources(struct mlx5dr_domain *dmn)
 {
        int ret;
 
+       dmn->chunks_kmem_cache = kmem_cache_create("mlx5_dr_chunks",
+                                                  sizeof(struct mlx5dr_icm_chunk), 0,
+                                                  SLAB_HWCACHE_ALIGN, NULL);
+       if (!dmn->chunks_kmem_cache) {
+               mlx5dr_err(dmn, "Couldn't create chunks kmem_cache\n");
+               return -ENOMEM;
+       }
+
        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");
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto free_chunks_kmem_cache;
        }
 
        dmn->action_icm_pool = mlx5dr_icm_pool_create(dmn, DR_ICM_TYPE_MODIFY_ACTION);
@@ -85,6 +94,9 @@ 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_chunks_kmem_cache:
+       kmem_cache_destroy(dmn->chunks_kmem_cache);
+
        return ret;
 }
 
@@ -93,6 +105,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->chunks_kmem_cache);
 }
 
 static int dr_domain_init_resources(struct mlx5dr_domain *dmn)
index 7ca1ef073f550d2225204d761e4198d7ef943032..be02546a7de061ccbdfaea16e74f75d9ef59002d 100644 (file)
@@ -9,6 +9,8 @@ struct mlx5dr_icm_pool {
        enum mlx5dr_icm_type icm_type;
        enum mlx5dr_icm_chunk_size max_log_chunk_sz;
        struct mlx5dr_domain *dmn;
+       struct kmem_cache *chunks_kmem_cache;
+
        /* memory management */
        struct mutex mutex; /* protect the ICM pool and ICM buddy */
        struct list_head buddy_mem_list;
@@ -193,10 +195,13 @@ static void dr_icm_chunk_ste_init(struct mlx5dr_icm_chunk *chunk, int offset)
 
 static void dr_icm_chunk_destroy(struct mlx5dr_icm_chunk *chunk)
 {
+       struct kmem_cache *chunks_cache =
+               chunk->buddy_mem->pool->chunks_kmem_cache;
+
        chunk->buddy_mem->used_memory -= mlx5dr_icm_pool_get_chunk_byte_size(chunk);
        list_del(&chunk->chunk_list);
 
-       kvfree(chunk);
+       kmem_cache_free(chunks_cache, chunk);
 }
 
 static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy)
@@ -302,10 +307,11 @@ dr_icm_chunk_create(struct mlx5dr_icm_pool *pool,
                    struct mlx5dr_icm_buddy_mem *buddy_mem_pool,
                    unsigned int seg)
 {
+       struct kmem_cache *chunks_cache = buddy_mem_pool->pool->chunks_kmem_cache;
        struct mlx5dr_icm_chunk *chunk;
        int offset;
 
-       chunk = kvzalloc(sizeof(*chunk), GFP_KERNEL);
+       chunk = kmem_cache_alloc(chunks_cache, GFP_KERNEL);
        if (!chunk)
                return NULL;
 
@@ -482,6 +488,7 @@ struct mlx5dr_icm_pool *mlx5dr_icm_pool_create(struct mlx5dr_domain *dmn,
        pool->dmn = dmn;
        pool->icm_type = icm_type;
        pool->max_log_chunk_sz = max_log_chunk_sz;
+       pool->chunks_kmem_cache = dmn->chunks_kmem_cache;
 
        INIT_LIST_HEAD(&pool->buddy_mem_list);
 
index 244685453a279aafb4725456f2ca2b04e1549eed..4f38f0f5b3523b8789041f78bc7d5ae5ce7252be 100644 (file)
@@ -915,6 +915,7 @@ struct mlx5dr_domain {
        struct mlx5dr_icm_pool *action_icm_pool;
        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 mlx5dr_send_ring *send_ring;
        struct mlx5dr_domain_info info;
        struct xarray csum_fts_xa;