BPF List
 help / color / mirror / Atom feed
From: "wuqiang.matt" <wuqiang.matt@bytedance.com>
To: Viktor Malik <vmalik@redhat.com>, linux-trace-kernel@vger.kernel.org
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	bpf@vger.kernel.org
Subject: Re: [PATCH] objpool: fix choosing allocation for percpu slots
Date: Fri, 23 Aug 2024 11:44:29 +0800	[thread overview]
Message-ID: <95ef23f0-1215-4882-9b20-85bbfa1fdff1@bytedance.com> (raw)
In-Reply-To: <20240822082519.216070-1-vmalik@redhat.com>

On 2024/8/22 16:25, Viktor Malik wrote:
> objpool intends to use vmalloc for default (non-atomic) allocations of
> percpu slots and objects. However, the condition checking if GFP flags
> are equal to GFP_ATOMIC is wrong and causes kmalloc to be used in most
> cases (even if GFP_KERNEL is requested). Since kmalloc cannot allocate
> large amounts of memory, this may lead to unexpected OOM errors.

Sure, good catch. Don't notice that GFP_ATOMIC is not atomic. My original
intention is using kmalloc only if GFP_ATOMIC is specified and other flags
should go with vmalloc, but (pool->gfp == GFP_ATOMIC) is not accurate.

Masami, please help review and include this patch into your patch set if
it's appropriate to you. Thanks.

Reviewed-by: Matt Wu <wuqiang.matt@bytedance.com>

> For instance, objpool is used by fprobe rethook which in turn is used by
> BPF kretprobe.multi and kprobe.session probe types. Trying to attach
> these to all kernel functions with libbpf using
> 
>      SEC("kprobe.session/*")
>      int kprobe(struct pt_regs *ctx)
>      {
>          [...]
>      }
> 
> fails on objpool slot allocation with ENOMEM.
> 
> Fix the condition to truly use vmalloc by default.
> 
> Fixes: b4edb8d2d464 ("lib: objpool added: ring-array based lockless MPMC")
> Signed-off-by: Viktor Malik <vmalik@redhat.com>
> ---
>   lib/objpool.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/objpool.c b/lib/objpool.c
> index 234f9d0bd081..fd108fe0d095 100644
> --- a/lib/objpool.c
> +++ b/lib/objpool.c
> @@ -76,7 +76,7 @@ objpool_init_percpu_slots(struct objpool_head *pool, int nr_objs,
>   		 * mimimal size of vmalloc is one page since vmalloc would
>   		 * always align the requested size to page size
>   		 */
> -		if (pool->gfp & GFP_ATOMIC)
> +		if ((pool->gfp & GFP_ATOMIC) == GFP_ATOMIC)
>   			slot = kmalloc_node(size, pool->gfp, cpu_to_node(i));
>   		else
>   			slot = __vmalloc_node(size, sizeof(void *), pool->gfp,

      parent reply	other threads:[~2024-08-23  3:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22  8:25 [PATCH] objpool: fix choosing allocation for percpu slots Viktor Malik
2024-08-22 21:30 ` Andrii Nakryiko
2024-08-26  5:43   ` Viktor Malik
2024-08-23  3:44 ` wuqiang.matt [this message]

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=95ef23f0-1215-4882-9b20-85bbfa1fdff1@bytedance.com \
    --to=wuqiang.matt@bytedance.com \
    --cc=bpf@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=vmalik@redhat.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