mempool: fix allocation in memzone during retry
authorZhike Wang <wangzhike@jd.com>
Tue, 14 Jul 2020 07:26:05 +0000 (15:26 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 21 Jul 2020 23:27:10 +0000 (01:27 +0200)
If allocation is successful on the first attempt, typically
there is no problem since we allocated everything required and
we'll terminate the loop (if memory chunk is really sufficient
to populate required number of mempool elements).

If the first attempt fails, we try to allocate half
of mem_size and it succeed, we'll have one more iteration of
the for-loop to allocate memory for remaining elements and
should not try the next time with quarter of the mem_size.

It is wrong that max_alloc_size is divided by 2 in the
case of successful allocation as well, or invalid memory
can be allocated, and leads to population failure, then errno
other than ENOMEM may be returned.

Fixes: 3a3d0c75b43e ("mempool: fix slow allocation of large pools")
Cc: stable@dpdk.org
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Signed-off-by: Zhike Wang <wangzhike@jd.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/librte_mempool/rte_mempool.c

index a2bd249..7774f0c 100644 (file)
@@ -635,7 +635,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
                                RTE_MIN((size_t)mem_size, max_alloc_size),
                                mp->socket_id, mz_flags, align);
 
-                       if (mz == NULL && rte_errno != ENOMEM)
+                       if (mz != NULL || rte_errno != ENOMEM)
                                break;
 
                        max_alloc_size = RTE_MIN(max_alloc_size,