From: Johan Almbladh <johan.almbladh@anyfinetworks.com>
Date: Tue, 14 Sep 2021 11:18:30 +0200
Subject: bpf/tests: Reduce memory footprint of test suite
Patch-mainline: v5.16-rc1
Git-commit: 4bc354138d553bc48dc1fb1e184d50a524e6c20f
References: jsc#PED-1377
The test suite used to call any fill_helper callbacks to generate eBPF
program data for all test cases at once. This caused ballooning memory
requirements as more extensive test cases were added. Now the each
fill_helper is called before the test is run and the allocated memory
released afterwards, before the next test case is processed.
Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210914091842.4186267-3-johan.almbladh@anyfinetworks.com
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
lib/test_bpf.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -6717,8 +6717,6 @@ static __init int find_test_index(const
static __init int prepare_bpf_tests(void)
{
- int i;
-
if (test_id >= 0) {
/*
* if a test_id was specified, use test_range to
@@ -6762,23 +6760,11 @@ static __init int prepare_bpf_tests(void
}
}
- for (i = 0; i < ARRAY_SIZE(tests); i++) {
- if (tests[i].fill_helper &&
- tests[i].fill_helper(&tests[i]) < 0)
- return -ENOMEM;
- }
-
return 0;
}
static __init void destroy_bpf_tests(void)
{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(tests); i++) {
- if (tests[i].fill_helper)
- kfree(tests[i].u.ptr.insns);
- }
}
static bool exclude_test(int test_id)
@@ -6983,7 +6969,19 @@ static __init int test_bpf(void)
pr_info("#%d %s ", i, tests[i].descr);
+ if (tests[i].fill_helper &&
+ tests[i].fill_helper(&tests[i]) < 0) {
+ pr_cont("FAIL to prog_fill\n");
+ continue;
+ }
+
fp = generate_filter(i, &err);
+
+ if (tests[i].fill_helper) {
+ kfree(tests[i].u.ptr.insns);
+ tests[i].u.ptr.insns = NULL;
+ }
+
if (fp == NULL) {
if (err == 0) {
pass_cnt++;