From: sashiko-bot@kernel.org
To: "Tianyi Chen" <hi@tychen.cc>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpftool: Use batch lookups for bounded hash map dumps
Date: Sun, 06 Sep 2026 17:20:49 +0000 [thread overview]
Message-ID: <20260906172049.EE1431F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260906170819.1212661-2-hi@tychen.cc>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Multi-line comments do not follow the mandatory BPF subsystem style.
--
commit a1cb333fccdbef3bcdfaf55fc0e0a282326e27a3
Author: Tianyi Chen <hi@tychen.cc>
bpftool: Use batch lookups for bounded hash map dumps
This patch updates bpftool to use BPF_MAP_LOOKUP_BATCH when dumping bounded
hash maps to reduce BPF syscalls. It restricts this optimization to maps
that fit within a 4 MiB memory budget and handles fallbacks.
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 684a8fb724146..1eccdc0d1e963 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
[ ... ]
> @@ -762,10 +757,108 @@ static int dump_map_elem(int fd, void *key, void *value,
[ ... ]
> +/* Return 1 to use individual lookups, but only before batch traversal starts. */
> +static int dump_map_batch(int fd, void *key, void *value,
> + struct bpf_map_info *info, struct btf *btf,
> + json_writer_t *wtr, unsigned int *num_elems)
> +{
> + __u32 capacity, count, batch = 0, next_batch = 0, i;
> + void *keys = NULL, *values = NULL, *buf;
> + bool first = true, can_fallback = true;
> + int err;
> +
> + /* Hash lookup batches must accommodate a whole bucket. Restrict the
> + * optimization to maps whose worst-case bucket fits the memory budget,
> + * so a later ENOSPC never forces a restart after printing some entries.
> + * Division also bounds the allocation multiplications on 32-bit hosts.
> + */
[Severity: Low]
Should the opening /* be on its own line to follow the BPF subsystem
multi-line comment style?
> + if (info->type != BPF_MAP_TYPE_HASH || !info->max_entries ||
> + (__u64)info->key_size + info->value_size >
> + MAP_DUMP_BATCH_MAX_BYTES / info->max_entries)
> + return 1;
[ ... ]
> + while (true) {
> + count = capacity;
> + err = bpf_map_lookup_batch(fd, first ? NULL : &batch,
> + &next_batch, keys, values, &count, NULL);
> + err = err ? errno : 0;
> + /* Older kernels reject the command before updating count. Do not
> + * inspect the buffers on these errors, or fall back after progress.
> + */
[Severity: Low]
Does this comment also need the opening /* on its own line?
> + if (can_fallback && (err == EINVAL || err == EOPNOTSUPP ||
> + err == 524 /* ENOTSUPP */)) {
> + err = 1;
> + goto out;
> + }
[ ... ]
> + for (i = 0; i < count; i++) {
> + /* Keep the alignment provided by individual lookups, including
> + * for BTF types whose map key/value size is not aligned.
> + */
[Severity: Low]
Here is a third instance. Should this opening /* be on its own line as well?
> + memcpy(key, keys + (size_t)i * info->key_size, info->key_size);
> + memcpy(value, values + (size_t)i * info->value_size, info->value_size);
> + print_map_elem(key, value, info, btf, wtr);
> + (*num_elems)++;
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260906170819.1212661-1-hi@tychen.cc?part=1
next prev parent reply other threads:[~2026-09-06 17:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-06 17:08 [PATCH bpf-next 0/2] bpftool: Batch bounded hash map dumps Tianyi Chen
2026-09-06 17:08 ` [PATCH bpf-next 1/2] bpftool: Use batch lookups for " Tianyi Chen
2026-09-06 17:20 ` sashiko-bot [this message]
2026-09-06 18:17 ` bot+bpf-ci
2026-09-06 17:08 ` [PATCH bpf-next 2/2] selftests/bpf: Check bpftool batch map dump contents Tianyi Chen
2026-09-06 17:16 ` sashiko-bot
2026-09-06 18:01 ` bot+bpf-ci
2026-09-07 1:21 ` Tianyi Chen
2026-09-07 1:21 ` [PATCH bpf-next v2 0/2] bpftool: Batch bounded hash map dumps Tianyi Chen
2026-09-07 1:21 ` [PATCH bpf-next v2 1/2] bpftool: Use batch lookups for " Tianyi Chen
2026-09-07 2:21 ` bot+bpf-ci
2026-09-07 5:15 ` Tianyi Chen
2026-09-07 1:21 ` [PATCH bpf-next v2 2/2] selftests/bpf: Check bpftool batch map dump contents Tianyi Chen
2026-09-07 2:21 ` bot+bpf-ci
2026-09-07 5:15 ` Tianyi Chen
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=20260906172049.EE1431F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hi@tychen.cc \
--cc=sashiko-reviews@lists.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