|
|
745326 |
From 0290582355c4c7f1a30c80b206f62d7ddaa2de05 Mon Sep 17 00:00:00 2001
|
|
|
745326 |
From: Erez Shitrit <erezsh@mellanox.com>
|
|
|
745326 |
Date: Thu, 20 Feb 2020 15:27:30 +0200
|
|
|
745326 |
Subject: [PATCH 2/8] mlx5: Allocate accurate aligned DM memory size
|
|
|
745326 |
|
|
|
745326 |
[ Upstream commit 96bd5476194106deb4c9edaf405e92646623465a ]
|
|
|
745326 |
|
|
|
745326 |
Allocate the exact memory size and only when failed to allocate an aligned
|
|
|
745326 |
memory size fallback to allocate double size of DM memory.
|
|
|
745326 |
|
|
|
745326 |
Fixes: 6235899cdf7a ("mlx5: ICM pool memory allocator")
|
|
|
745326 |
Signed-off-by: Erez Shitrit <erezsh@mellanox.com>
|
|
|
745326 |
Reviewed-by: Alex Vesker <valex@mellanox.com>
|
|
|
745326 |
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
|
|
|
745326 |
Signed-off-by: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com>
|
|
|
745326 |
---
|
|
|
745326 |
providers/mlx5/dr_icm_pool.c | 103 ++++++++++++++++++++++-------------
|
|
|
745326 |
1 file changed, 64 insertions(+), 39 deletions(-)
|
|
|
745326 |
|
|
|
745326 |
diff --git a/providers/mlx5/dr_icm_pool.c b/providers/mlx5/dr_icm_pool.c
|
|
|
745326 |
index 1e2853959b37..469e52552ccd 100644
|
|
|
745326 |
--- a/providers/mlx5/dr_icm_pool.c
|
|
|
745326 |
+++ b/providers/mlx5/dr_icm_pool.c
|
|
|
745326 |
@@ -89,16 +89,72 @@ struct dr_icm_mr {
|
|
|
745326 |
struct list_node mr_list;
|
|
|
745326 |
};
|
|
|
745326 |
|
|
|
745326 |
-static struct dr_icm_mr *
|
|
|
745326 |
-dr_icm_pool_mr_create(struct dr_icm_pool *pool,
|
|
|
745326 |
- enum mlx5_ib_uapi_dm_type dm_type,
|
|
|
745326 |
- size_t align_base)
|
|
|
745326 |
+static int
|
|
|
745326 |
+dr_icm_allocate_aligned_dm(struct dr_icm_pool *pool,
|
|
|
745326 |
+ struct dr_icm_mr *icm_mr,
|
|
|
745326 |
+ struct ibv_alloc_dm_attr *dm_attr)
|
|
|
745326 |
{
|
|
|
745326 |
struct mlx5dv_alloc_dm_attr mlx5_dm_attr = {};
|
|
|
745326 |
+ size_t log_align_base = 0;
|
|
|
745326 |
+ bool fallback = false;
|
|
|
745326 |
+ struct mlx5_dm *dm;
|
|
|
745326 |
+ size_t size;
|
|
|
745326 |
+
|
|
|
745326 |
+ /* create dm/mr for this pool */
|
|
|
745326 |
+ size = dr_icm_pool_chunk_size_to_byte(pool->max_log_chunk_sz,
|
|
|
745326 |
+ pool->icm_type);
|
|
|
745326 |
+
|
|
|
745326 |
+ if (pool->icm_type == DR_ICM_TYPE_STE) {
|
|
|
745326 |
+ mlx5_dm_attr.type = MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM;
|
|
|
745326 |
+ /* Align base is the biggest chunk size */
|
|
|
745326 |
+ log_align_base = ilog32(size - 1);
|
|
|
745326 |
+ } else if (pool->icm_type == DR_ICM_TYPE_MODIFY_ACTION) {
|
|
|
745326 |
+ mlx5_dm_attr.type = MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM;
|
|
|
745326 |
+ /* Align base is 64B */
|
|
|
745326 |
+ log_align_base = ilog32(DR_ICM_MODIFY_HDR_ALIGN_BASE - 1);
|
|
|
745326 |
+ }
|
|
|
745326 |
+
|
|
|
745326 |
+ dm_attr->length = size;
|
|
|
745326 |
+
|
|
|
745326 |
+alloc_dm:
|
|
|
745326 |
+ icm_mr->dm = mlx5dv_alloc_dm(pool->dmn->ctx, dm_attr, &mlx5_dm_attr);
|
|
|
745326 |
+ if (!icm_mr->dm) {
|
|
|
745326 |
+ dr_dbg(pool->dmn, "Failed allocating DM\n");
|
|
|
745326 |
+ return errno;
|
|
|
745326 |
+ }
|
|
|
745326 |
+
|
|
|
745326 |
+ dm = to_mdm(icm_mr->dm);
|
|
|
745326 |
+ icm_mr->icm_start_addr = dm->remote_va;
|
|
|
745326 |
+
|
|
|
745326 |
+ if (icm_mr->icm_start_addr & ((1UL << log_align_base) - 1)) {
|
|
|
745326 |
+ uint64_t align_base;
|
|
|
745326 |
+ uint64_t align_diff;
|
|
|
745326 |
+
|
|
|
745326 |
+ /* Fallback to previous implementation, ask for double size */
|
|
|
745326 |
+ dr_dbg(pool->dmn, "Got not aligned memory: %zu last_try: %d\n",
|
|
|
745326 |
+ log_align_base, fallback);
|
|
|
745326 |
+ if (fallback) {
|
|
|
745326 |
+ align_base = 1UL << log_align_base;
|
|
|
745326 |
+ align_diff = icm_mr->icm_start_addr % align_base;
|
|
|
745326 |
+ icm_mr->used_length = align_base - align_diff;
|
|
|
745326 |
+ return 0;
|
|
|
745326 |
+ }
|
|
|
745326 |
+
|
|
|
745326 |
+ mlx5_free_dm(icm_mr->dm);
|
|
|
745326 |
+ /* retry to allocate, now double the size */
|
|
|
745326 |
+ dm_attr->length = size * 2;
|
|
|
745326 |
+ fallback = true;
|
|
|
745326 |
+ goto alloc_dm;
|
|
|
745326 |
+ }
|
|
|
745326 |
+
|
|
|
745326 |
+ return 0;
|
|
|
745326 |
+}
|
|
|
745326 |
+
|
|
|
745326 |
+static struct dr_icm_mr *
|
|
|
745326 |
+dr_icm_pool_mr_create(struct dr_icm_pool *pool)
|
|
|
745326 |
+{
|
|
|
745326 |
struct ibv_alloc_dm_attr dm_attr = {};
|
|
|
745326 |
struct dr_icm_mr *icm_mr;
|
|
|
745326 |
- struct mlx5_dm *dm;
|
|
|
745326 |
- size_t align_diff;
|
|
|
745326 |
|
|
|
745326 |
icm_mr = calloc(1, sizeof(struct dr_icm_mr));
|
|
|
745326 |
if (!icm_mr) {
|
|
|
745326 |
@@ -106,20 +162,8 @@ dr_icm_pool_mr_create(struct dr_icm_pool *pool,
|
|
|
745326 |
return NULL;
|
|
|
745326 |
}
|
|
|
745326 |
|
|
|
745326 |
- icm_mr->pool = pool;
|
|
|
745326 |
- list_node_init(&icm_mr->mr_list);
|
|
|
745326 |
-
|
|
|
745326 |
- mlx5_dm_attr.type = dm_type;
|
|
|
745326 |
-
|
|
|
745326 |
- /* 2^log_biggest_table * entry-size * double-for-alignment */
|
|
|
745326 |
- dm_attr.length = dr_icm_pool_chunk_size_to_byte(pool->max_log_chunk_sz,
|
|
|
745326 |
- pool->icm_type) * 2;
|
|
|
745326 |
-
|
|
|
745326 |
- icm_mr->dm = mlx5dv_alloc_dm(pool->dmn->ctx, &dm_attr, &mlx5_dm_attr);
|
|
|
745326 |
- if (!icm_mr->dm) {
|
|
|
745326 |
- dr_dbg(pool->dmn, "Failed allocating DM\n");
|
|
|
745326 |
+ if (dr_icm_allocate_aligned_dm(pool, icm_mr, &dm_attr))
|
|
|
745326 |
goto free_icm_mr;
|
|
|
745326 |
- }
|
|
|
745326 |
|
|
|
745326 |
/* Register device memory */
|
|
|
745326 |
icm_mr->mr = ibv_reg_dm_mr(pool->dmn->pd, icm_mr->dm, 0,
|
|
|
745326 |
@@ -133,13 +177,6 @@ dr_icm_pool_mr_create(struct dr_icm_pool *pool,
|
|
|
745326 |
goto free_dm;
|
|
|
745326 |
}
|
|
|
745326 |
|
|
|
745326 |
- dm = to_mdm(icm_mr->dm);
|
|
|
745326 |
- icm_mr->icm_start_addr = dm->remote_va;
|
|
|
745326 |
-
|
|
|
745326 |
- align_diff = icm_mr->icm_start_addr % align_base;
|
|
|
745326 |
- if (align_diff)
|
|
|
745326 |
- icm_mr->used_length = align_base - align_diff;
|
|
|
745326 |
-
|
|
|
745326 |
list_add_tail(&pool->icm_mr_list, &icm_mr->mr_list);
|
|
|
745326 |
|
|
|
745326 |
return icm_mr;
|
|
|
745326 |
@@ -199,33 +236,21 @@ static int dr_icm_chunks_create(struct dr_icm_bucket *bucket)
|
|
|
745326 |
{
|
|
|
745326 |
size_t mr_free_size, mr_req_size, mr_row_size;
|
|
|
745326 |
struct dr_icm_pool *pool = bucket->pool;
|
|
|
745326 |
- enum mlx5_ib_uapi_dm_type dm_type;
|
|
|
745326 |
struct dr_icm_chunk *chunk;
|
|
|
745326 |
struct dr_icm_mr *icm_mr;
|
|
|
745326 |
- size_t align_base;
|
|
|
745326 |
int i;
|
|
|
745326 |
|
|
|
745326 |
mr_req_size = bucket->num_of_entries * bucket->entry_size;
|
|
|
745326 |
mr_row_size = dr_icm_pool_chunk_size_to_byte(pool->max_log_chunk_sz,
|
|
|
745326 |
pool->icm_type);
|
|
|
745326 |
|
|
|
745326 |
- if (pool->icm_type == DR_ICM_TYPE_STE) {
|
|
|
745326 |
- dm_type = MLX5_IB_UAPI_DM_TYPE_STEERING_SW_ICM;
|
|
|
745326 |
- /* Align base is the biggest chunk size / row size */
|
|
|
745326 |
- align_base = mr_row_size;
|
|
|
745326 |
- } else {
|
|
|
745326 |
- dm_type = MLX5_IB_UAPI_DM_TYPE_HEADER_MODIFY_SW_ICM;
|
|
|
745326 |
- /* Align base is 64B */
|
|
|
745326 |
- align_base = DR_ICM_MODIFY_HDR_ALIGN_BASE;
|
|
|
745326 |
- }
|
|
|
745326 |
-
|
|
|
745326 |
pthread_mutex_lock(&pool->mr_mutex);
|
|
|
745326 |
icm_mr = list_tail(&pool->icm_mr_list, struct dr_icm_mr, mr_list);
|
|
|
745326 |
if (icm_mr)
|
|
|
745326 |
mr_free_size = icm_mr->mr->length - icm_mr->used_length;
|
|
|
745326 |
|
|
|
745326 |
if (!icm_mr || mr_free_size < mr_row_size) {
|
|
|
745326 |
- icm_mr = dr_icm_pool_mr_create(pool, dm_type, align_base);
|
|
|
745326 |
+ icm_mr = dr_icm_pool_mr_create(pool);
|
|
|
745326 |
if (!icm_mr)
|
|
|
745326 |
goto out_err;
|
|
|
745326 |
}
|
|
|
745326 |
--
|
|
|
745326 |
2.25.4
|
|
|
745326 |
|