From: Hui Su <sh_def@163.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>, bpf@vger.kernel.org
Cc: Hui Su <sh_def@163.com>,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev, shuah@kernel.org,
yatsenko@meta.com, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf v2 1/2] bpf: bound resizable hash map iteration
Date: Fri, 4 Sep 2026 11:16:37 +0800 [thread overview]
Message-ID: <20260904031637.230595-1-sh_def@163.com> (raw)
In-Reply-To: <7c741628-c259-4ae6-8d67-d92910183526@gmail.com>
On Thu, Sep 3, 2026 at 5:43 PM, Mykyta Yatsenko wrote:
> I'm not sure if this change fixes anything, the main issue of walking
> concurrently modified rhashtable is not changed: you still may miss
> elements or visit same elements multiple times.
>
> In some scenarios this can make things worse: imagine you start
> iterating with small map (visit_budget = 10), then 1000000 elements
> are inserted concurrently with walk, so you'll miss at least
> 1000000 - 10.
>
> To me this is a trade off/taste thing, rather than bug fix. The
> change is compact, though, I'm not against it.
Thanks for the review.
I agree that this change does not, and is not intended to, make
concurrent rhashtable iteration complete or duplicate-free. Missed and
duplicate elements remain part of the existing best-effort semantics.
The narrower issue I am trying to address is that bpf_each_rhash_elem()
currently keeps calling rhashtable_next_key() until it returns NULL.
The rhashtable_next_key() documentation states that a full iteration
may not terminate under adversarial or sustained rehashing, and
recommends that callers bound such walks externally.
The purpose of this change is therefore not to make the iteration
complete, but to provide a finite upper bound on callback invocations
under sustained rehashing.
I agree that taking a snapshot of ht.nelems makes the bound insensitive
to elements inserted after the walk starts. In the example you gave, the
walk could stop after the initial occupancy and miss most newly inserted
elements.
Using map->max_entries would preserve more of the existing behavior
under concurrent growth, at the cost of allowing a much longer walk for
a sparsely populated map.
Would map->max_entries be a more appropriate bound in your view?
Also, if you consider adding such a bound useful but not a bug fix,
would bpf-next be a more appropriate target for this change?
Thanks,
Hui
prev parent reply other threads:[~2026-09-04 3:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 14:01 [PATCH bpf v2 1/2] bpf: bound resizable hash map iteration Hui Su
2026-08-31 14:01 ` [PATCH bpf v2 2/2] selftests/bpf: add RHASH iteration stress test Hui Su
2026-09-03 16:43 ` [PATCH bpf v2 1/2] bpf: bound resizable hash map iteration Mykyta Yatsenko
2026-09-04 3:16 ` Hui Su [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=20260904031637.230595-1-sh_def@163.com \
--to=sh_def@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yatsenko@meta.com \
--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;
as well as URLs for NNTP newsgroup(s).