DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Zhike Wang <wangzhike@jd.com>, dev@dpdk.org
Cc: olivier.matz@6wind.com, arybchenko@solarflare.com
Subject: Re: [dpdk-dev] [PATCH] mempool: fix memory allocation in memzones during retry.
Date: Mon, 13 Jul 2020 12:17:35 +0100	[thread overview]
Message-ID: <cde3f7cf-ce57-806f-58a8-e85c3cd260b7@intel.com> (raw)
In-Reply-To: <1594611634-7730-1-git-send-email-wangzhike@jd.com>

On 13-Jul-20 4:40 AM, Zhike Wang wrote:
> 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.
> 
> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
> Signed-off-by: Zhike Wang <wangzhike@jd.com>
> ---
>   lib/librte_mempool/rte_mempool.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
> index a2bd249..b8f2629 100644
> --- a/lib/librte_mempool/rte_mempool.c
> +++ b/lib/librte_mempool/rte_mempool.c
> @@ -635,7 +635,7 @@ struct pagesz_walk_arg {
>   				RTE_MIN((size_t)mem_size, max_alloc_size),
>   				mp->socket_id, mz_flags, align);
>   
> -			if (mz == NULL && rte_errno != ENOMEM)
> +			if ((mz != NULL) || (mz == NULL && rte_errno != ENOMEM))

I think checking mz == NULL for the second time is redundant, as if 
we're hitting the second branch, we've already failed the "mz != NULL" 
test and can therefore assume that mz == NULL.

That said, i'm struggling to think of circumstances where this would 
matter. Could you please provide an example?

>   				break;
>   
>   			max_alloc_size = RTE_MIN(max_alloc_size,
> 

This should have a Fixes: tag.

-- 
Thanks,
Anatoly

  parent reply	other threads:[~2020-07-13 11:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13  3:40 Zhike Wang
2020-07-13 10:32 ` Andrew Rybchenko
2020-07-13 11:17 ` Burakov, Anatoly [this message]
2020-07-13 11:29   ` Andrew Rybchenko
2020-07-13 14:52     ` Burakov, Anatoly
2020-07-14  7:36       ` 王志克
2020-07-14  7:26 ` [dpdk-dev] [PATCH v2] " Zhike Wang
2020-07-14  9:32   ` Burakov, Anatoly
2020-07-21 23:27     ` Thomas Monjalon

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=cde3f7cf-ce57-806f-58a8-e85c3cd260b7@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=arybchenko@solarflare.com \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.com \
    --cc=wangzhike@jd.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).