From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Shuah Khan <shuah@kernel.org>,
Willem de Bruijn <willemb@google.com>
Cc: linux-kernel@vger.kernel.org,
Eva Kurchatova <eva.kurchatova@virtuozzo.com>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next v2 1/1] selftests: bpf: size the map in test_lru_sanity3 to whole refills
Date: Fri, 25 Sep 2026 18:38:13 +0300 [thread overview]
Message-ID: <20260925154029.3673513-2-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20260925154029.3673513-1-eva.kurchatova@virtuozzo.com>
test_lru_sanity3 fills a map of tgt_free * 2 elements, and then reads
back all but the last few. Whether that passes depends on the cpu
count alone; on a machine with six it does not:
test_lru_sanity3 (map_type:9 map_flags:0x0): test_lru_map.c:463:
test_lru_sanity3: Assertion `!bpf_map_lookup_elem_with_ref_bit(
lru_map_fd, key, value)' failed.
The kernel hands elements out in refills of lru->target_free, which is
clamp((size / nr_cpus) / 2, 1, LOCAL_FREE_TARGET), that is 128 / nr_cpus
rounded down. A refill the global free list cannot satisfy in full
calls __bpf_lru_list_shrink() for the remainder, and that evicts live
elements. Filling the map therefore evicts nothing only when computed
128 / nr_cpus is a power of two. Any other nr_cpus variation fails.
batch_size is already __tgt_size(tgt_free), the refill size of a map
is __map_size(batch_size) elements, so size the map that way and the
fill consumes whole refills. Start the keys of the last insert at
map_size + 1, just past the new size.
Above 128 cpus __tgt_size(tgt_free) is 0 and there is no size to build
on. Skip the test there.
Fixes: 5e9388f7984a ("selftests/bpf: adapt one more case in test_lru_map to the new target_free")
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/testing/selftests/bpf/test_lru_map.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_lru_map.c b/tools/testing/selftests/bpf/test_lru_map.c
index 0921939532c6..84e9a930471a 100644
--- a/tools/testing/selftests/bpf/test_lru_map.c
+++ b/tools/testing/selftests/bpf/test_lru_map.c
@@ -441,8 +441,15 @@ static void test_lru_sanity3(int map_type, int map_flags, unsigned int tgt_free)
assert(sched_next_online(0, &next_cpu) != -1);
batch_size = __tgt_size(tgt_free);
+ if (!batch_size) {
+ /* More cpus than this tgt_free gives a refill for */
+ printf("Skip\n");
+ return;
+ }
+
+ /* A partial refill shrinks the LRU and evicts live elements */
+ map_size = __map_size(batch_size);
- map_size = tgt_free * 2;
lru_map_fd = create_map(map_type, map_flags, map_size);
assert(lru_map_fd != -1);
@@ -466,7 +473,7 @@ static void test_lru_sanity3(int map_type, int map_flags, unsigned int tgt_free)
}
/* Insert new batch_size: replaces the non-referenced elements */
- key = 2 * tgt_free + 1;
+ key = 1 + map_size;
end_key = key + batch_size;
for (; key < end_key; key++) {
assert(!bpf_map_update_elem(lru_map_fd, &key, value,
--
2.55.0
next prev parent reply other threads:[~2026-09-25 15:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 15:38 [PATCH bpf-next v2 0/1] selftests: bpf: fix test_lru_sanity3 Eva Kurchatova
2026-09-25 15:38 ` Eva Kurchatova [this message]
2026-09-25 16:42 ` [PATCH bpf-next v2 1/1] selftests: bpf: size the map in test_lru_sanity3 to whole refills bot+bpf-ci
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=20260925154029.3673513-2-eva.kurchatova@virtuozzo.com \
--to=eva.kurchatova@virtuozzo.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=shuah@kernel.org \
--cc=song@kernel.org \
--cc=willemb@google.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
all inboxes | Powered by JetHome®