<html>
    <head>
      <base href="https://bugs.dpdk.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8" class="bz_new_table">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - rte_mempool_avail_count : returns bigger than mempool size"
   href="https://bugs.dpdk.org/show_bug.cgi?id=1229">1229</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>rte_mempool_avail_count : returns bigger than mempool size
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>DPDK
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>22.11
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>x86
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>minor
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>core
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dev@dpdk.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yasinncaner@gmail.com
          </td>
        </tr>

        <tr>
          <th>Target Milestone</th>
          <td>---
          </td>
        </tr></table>
      <p>
        <div class="bz_comment_block">
          <pre class="bz_comment_text">Hello,

Sometimes rte_mempool_avail_count function returns bigger than mempool size
that cause mis-calculation/overflow/negative of in-use count  (
rte_mempool_in_use_count)


11:51:48 NOTI [UseCount_mpool:00000065][avail_mpool:00010334]
11:51:48 NOTI [UseCount_mpool:4294967135][avail_mpool:00010560]


After adding a condition, it is fixed.

/* Return the number of entries in the mempool */
unsigned int
rte_mempool_avail_count(const struct rte_mempool *mp)
{
        unsigned count;
        unsigned lcore_id;

        count = rte_mempool_ops_get_count(mp);

        if (mp->cache_size == 0){
                if (count > mp->size){
                        return mp->size;
                }
                return count;
        }
        for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
                count += mp->local_cache[lcore_id].len;

        /*
         * due to race condition (access to len is not locked), the
         * total can be greater than size... so fix the result
         */
        if (count > mp->size){
                return mp->size;
        }
        return count;
}
          </pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
      <div itemscope itemtype="http://schema.org/EmailMessage">
        <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
          
          <link itemprop="url" href="https://bugs.dpdk.org/show_bug.cgi?id=1229">
          <meta itemprop="name" content="View bug">
        </div>
        <meta itemprop="description" content="Bugzilla bug update notification">
      </div>
    </body>
</html>