BPF List
 help / color / mirror / Atom feed
From: Matt Bobrowski <mattbobrowski@google.com>
To: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Yonghong Song <yonghong.song@linux.dev>,
	ohn Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: retry bpf_map_update_elem() when E2BIG is returned
Date: Thu, 13 Nov 2025 08:23:15 +0000	[thread overview]
Message-ID: <aRWVc1tne5vNffqU@google.com> (raw)
In-Reply-To: <CAHzjS_s=+qgkt0RRFqvVORhWBt8jsFS8RDy4Kq1Vwr8fPRzfag@mail.gmail.com>

On Wed, Nov 12, 2025 at 05:00:50PM -0800, Song Liu wrote:
> On Wed, Nov 12, 2025 at 12:32 AM Matt Bobrowski
> <mattbobrowski@google.com> wrote:
> >
> > Executing the test_maps binary on platforms with extremely high core
> > counts may cause intermittent assertion failures in
> > test_update_delete() (called via test_map_parallel()). This can occur
> > because bpf_map_update_elem() under some circumstances (specifically
> > in this case while performing bpf_map_update_elem() with BPF_NOEXIST
> > on a BPF_MAP_TYPE_HASH with its map_flags set to BPF_F_NO_PREALLOC)
> > can return an E2BIG error code i.e.
> >
> > error -7 7
> > tools/testing/selftests/bpf/test_maps.c:#: void test_update_delete(unsigned int, void *): Assertion `err == 0' failed.
> > tools/testing/selftests/bpf/test_maps.c:#: void
> > __run_parallel(unsigned int, void (*)(unsigned int, void *), void *): Assertion `status == 0' failed.
> >
> > As it turns out, is_map_full() which is called from alloc_htab_elem()
> > can take on a conservative approach when htab->use_percpu_counter is
> > true (which is the case here because the percpu_counter is used when a
> > BPF_MAP_TYPE_HASH is created with its map_flags set to
> > BPF_F_NO_PREALLOC). This conservative approach approach prioritizes
> 
> s/approach approach/approach
> 
> AFAICT checkpatch.pl also warns double "approach", as well as line exceed
> 75 character above.

ACK. Will respin with nits addressed at some point today.

> > preventing over-allocation and potential issues that could arise from
> > possibly exceeding htab->map.max_entries in highly concurrent
> > environments, even if it means slightly under-utilizing the htab map's
> > capacity.
> >
> > Given that bpf_map_update_elem() from test_update_delete() can return
> > E2BIG, update can_retry() such that it also accounts for the E2BIG
> > error code (specifically only when running with map_flags being set to
> > BPF_F_NO_PREALLOC). The retry loop will allow the global count
> > belonging to the percpu_counter to become synchronized and better
> > reflect the current htab map's capacity.
> >
> > Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
> 
> Other than the nitpick above, this looks good to me.
> 
> Acked-by: Song Liu <song@kernel.org>
> 
> 
> > ---
> >  tools/testing/selftests/bpf/test_maps.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
> > index 3fae9ce46ca9..ccc5acd55ff9 100644
> > --- a/tools/testing/selftests/bpf/test_maps.c
> > +++ b/tools/testing/selftests/bpf/test_maps.c
> > @@ -1399,7 +1399,8 @@ static void test_map_stress(void)
> >  static bool can_retry(int err)
> >  {
> >         return (err == EAGAIN || err == EBUSY ||
> > -               (err == ENOMEM && map_opts.map_flags == BPF_F_NO_PREALLOC));
> > +               ((err == ENOMEM || err == E2BIG) &&
> > +                map_opts.map_flags == BPF_F_NO_PREALLOC));
> >  }
> >
> >  int map_update_retriable(int map_fd, const void *key, const void *value, int flags, int attempts,
> > --
> > 2.51.2.1041.gc1ab5b90ca-goog
> >

      reply	other threads:[~2025-11-13  8:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12  8:31 [PATCH bpf-next] selftests/bpf: retry bpf_map_update_elem() when E2BIG is returned Matt Bobrowski
2025-11-13  1:00 ` Song Liu
2025-11-13  8:23   ` Matt Bobrowski [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=aRWVc1tne5vNffqU@google.com \
    --to=mattbobrowski@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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