DPDK patches and discussions
 help / color / mirror / Atom feed
From: Suanming Mou <suanmingm@mellanox.com>
To: Matan Azrad <matan@mellanox.com>,
	Shahaf Shuler <shahafs@mellanox.com>,
	Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Cc: rasland@mellanox.com, dev@dpdk.org
Subject: [dpdk-dev] [PATCH 03/10] net/mlx5: add trunk release for indexed pool
Date: Mon, 13 Apr 2020 09:11:42 +0800	[thread overview]
Message-ID: <1586740309-449310-4-git-send-email-suanmingm@mellanox.com> (raw)
In-Reply-To: <1586740309-449310-1-git-send-email-suanmingm@mellanox.com>

While entries are fully freed in trunk, it means the trunk is free now.
User may prefer the free trunk memory can be reclaimed.

Add the trunk release memory option for indexed pool in this case.

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5_utils.c | 37 +++++++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_utils.h |  1 +
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_utils.c b/drivers/net/mlx5/mlx5_utils.c
index e63921d..7683167 100644
--- a/drivers/net/mlx5/mlx5_utils.c
+++ b/drivers/net/mlx5/mlx5_utils.c
@@ -254,7 +254,14 @@ struct mlx5_indexed_pool *
 			pool->cfg.free(pool->trunks);
 		pool->n_trunk += n_grow;
 	}
-	idx = pool->n_trunk_valid;
+	if (!pool->cfg.release_mem_en) {
+		idx = pool->n_trunk_valid;
+	} else {
+		/* Find the first available slot in trunk list */
+		for (idx = 0; idx < pool->n_trunk; idx++)
+			if (pool->trunks[idx] == NULL)
+				break;
+	}
 	trunk_size += sizeof(*trunk);
 	data_size = mlx5_trunk_size_get(pool, idx);
 	bmp_size = rte_bitmap_get_memory_footprint(data_size);
@@ -356,7 +363,8 @@ struct mlx5_indexed_pool *
 	idx -= 1;
 	mlx5_ipool_lock(pool);
 	trunk_idx = mlx5_trunk_idx_get(pool, idx);
-	if (trunk_idx >= pool->n_trunk_valid)
+	if ((!pool->cfg.release_mem_en && trunk_idx >= pool->n_trunk_valid) ||
+	    (pool->cfg.release_mem_en && trunk_idx >= pool->n_trunk))
 		goto out;
 	trunk = pool->trunks[trunk_idx];
 	if (!trunk)
@@ -367,7 +375,27 @@ struct mlx5_indexed_pool *
 		goto out;
 	rte_bitmap_set(trunk->bmp, entry_idx);
 	trunk->free++;
-	if (trunk->free == 1) {
+	if (pool->cfg.release_mem_en && trunk->free == mlx5_trunk_size_get
+	   (pool, trunk->idx)) {
+		if (pool->free_list == trunk->idx)
+			pool->free_list = trunk->next;
+		if (trunk->next != TRUNK_INVALID)
+			pool->trunks[trunk->next]->prev = trunk->prev;
+		if (trunk->prev != TRUNK_INVALID)
+			pool->trunks[trunk->prev]->next = trunk->next;
+		pool->cfg.free(trunk);
+		pool->trunks[trunk_idx] = NULL;
+		pool->n_trunk_valid--;
+#ifdef POOL_DEBUG
+		pool->trunk_avail--;
+		pool->trunk_free++;
+#endif
+		if (pool->n_trunk_valid == 0) {
+			pool->cfg.free(pool->trunks);
+			pool->trunks = NULL;
+			pool->n_trunk = 0;
+		}
+	} else if (trunk->free == 1) {
 		/* Put into free trunk list head. */
 		MLX5_ASSERT(pool->free_list != trunk->idx);
 		trunk->next = pool->free_list;
@@ -400,7 +428,8 @@ struct mlx5_indexed_pool *
 	idx -= 1;
 	mlx5_ipool_lock(pool);
 	trunk_idx = mlx5_trunk_idx_get(pool, idx);
-	if (trunk_idx >= pool->n_trunk_valid)
+	if ((!pool->cfg.release_mem_en && trunk_idx >= pool->n_trunk_valid) ||
+	    (pool->cfg.release_mem_en && trunk_idx >= pool->n_trunk))
 		goto out;
 	trunk = pool->trunks[trunk_idx];
 	if (!trunk)
diff --git a/drivers/net/mlx5/mlx5_utils.h b/drivers/net/mlx5/mlx5_utils.h
index af96a87..1051b12 100644
--- a/drivers/net/mlx5/mlx5_utils.h
+++ b/drivers/net/mlx5/mlx5_utils.h
@@ -101,6 +101,7 @@ struct mlx5_indexed_pool_config {
 	 */
 	uint32_t need_lock:1;
 	/* Lock is needed for multiple thread usage. */
+	uint32_t release_mem_en:1; /* Rlease trunk when it is free. */
 	const char *type; /* Memory allocate type name. */
 	void *(*malloc)(const char *type, size_t size, unsigned int align,
 			int socket);
-- 
1.8.3.1


  parent reply	other threads:[~2020-04-13  1:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13  1:11 [dpdk-dev] [PATCH 00/10] net/mlx5: optimize flow resource allocation Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 01/10] net/mlx5: add indexed memory pool Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 02/10] net/mlx5: add trunk dynamic grow for indexed pool Suanming Mou
2020-04-13  1:11 ` Suanming Mou [this message]
2020-04-13  1:11 ` [dpdk-dev] [PATCH 04/10] net/mlx5: convert encap/decap resource to indexed Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 05/10] net/mlx5: convert push VLAN " Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 06/10] net/mlx5: convert tag " Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 07/10] net/mlx5: convert port id action " Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 08/10] net/mlx5: convert jump resource " Suanming Mou
2020-04-13  1:11 ` [dpdk-dev] [PATCH 09/10] net/mlx5: convert hrxq " Suanming Mou
2020-04-16  2:41 ` [dpdk-dev] [PATCH v2 00/10] net/mlx5: optimize flow resource allocation Suanming Mou
2020-04-16  2:41   ` [dpdk-dev] [PATCH v2 01/10] net/mlx5: add indexed memory pool Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 02/10] net/mlx5: add trunk dynamic grow for indexed pool Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 03/10] net/mlx5: add trunk release " Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 04/10] net/mlx5: convert encap/decap resource to indexed Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 05/10] net/mlx5: convert push VLAN " Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 06/10] net/mlx5: convert tag " Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 07/10] net/mlx5: convert port id action " Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 08/10] net/mlx5: convert jump resource " Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 09/10] net/mlx5: convert hrxq " Suanming Mou
2020-04-16  2:42   ` [dpdk-dev] [PATCH v2 10/10] net/mlx5: convert flow dev handle " Suanming Mou
2020-04-16 15:08   ` [dpdk-dev] [PATCH v2 00/10] net/mlx5: optimize flow resource allocation Raslan Darawsheh
2020-04-17 14:58   ` Ferruh Yigit
2020-04-18  1:46     ` Suanming Mou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1586740309-449310-4-git-send-email-suanmingm@mellanox.com \
    --to=suanmingm@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=matan@mellanox.com \
    --cc=rasland@mellanox.com \
    --cc=shahafs@mellanox.com \
    --cc=viacheslavo@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).