[PATCH] lib/mempool : rte_mempool_avail_count, fixing return bigger than mempool size
Stephen Hemminger
stephen at networkplumber.org
Tue May 16 17:23:49 CEST 2023
On Tue, 16 May 2023 13:41:46 +0000
Yasin CANER <yasinncaner at gmail.com> wrote:
> From: Yasin CANER <yasin.caner at ulakhaberlesme.com.tr>
>
> after a while working rte_mempool_avail_count function returns bigger
> than mempool size that cause miscalculation rte_mempool_in_use_count.
>
> it helps to avoid miscalculation rte_mempool_in_use_count.
>
> Bugzilla ID: 1229
>
> Signed-off-by: Yasin CANER <yasin.caner at ulakhaberlesme.com.tr>
An alternative that avoids some code duplication.
diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index cf5dea2304a7..2406b112e7b0 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -1010,7 +1010,7 @@ rte_mempool_avail_count(const struct rte_mempool *mp)
count = rte_mempool_ops_get_count(mp);
if (mp->cache_size == 0)
- return count;
+ goto exit;
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
count += mp->local_cache[lcore_id].len;
@@ -1019,6 +1019,7 @@ rte_mempool_avail_count(const struct rte_mempool *mp)
* due to race condition (access to len is not locked), the
* total can be greater than size... so fix the result
*/
+exit:
if (count > mp->size)
return mp->size;
return count;
More information about the dev
mailing list