2020-07-27 19:22:03

by Roman Gushchin

[permalink] [raw]
Subject: [PATCH bpf-next v2 33/35] bpf: selftests: don't touch RLIMIT_MEMLOCK

Since bpf is not using memlock rlimit for memory accounting,
there are no more reasons to bump the limit.

Signed-off-by: Roman Gushchin <[email protected]>
---
tools/testing/selftests/bpf/bench.c | 16 ---------------
.../selftests/bpf/progs/bpf_iter_bpf_map.c | 5 ++---
tools/testing/selftests/bpf/xdping.c | 6 ------
tools/testing/selftests/net/reuseport_bpf.c | 20 -------------------
4 files changed, 2 insertions(+), 45 deletions(-)

diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
index 944ad4721c83..f66610541c8a 100644
--- a/tools/testing/selftests/bpf/bench.c
+++ b/tools/testing/selftests/bpf/bench.c
@@ -29,25 +29,9 @@ static int libbpf_print_fn(enum libbpf_print_level level,
return vfprintf(stderr, format, args);
}

-static int bump_memlock_rlimit(void)
-{
- struct rlimit rlim_new = {
- .rlim_cur = RLIM_INFINITY,
- .rlim_max = RLIM_INFINITY,
- };
-
- return setrlimit(RLIMIT_MEMLOCK, &rlim_new);
-}
-
void setup_libbpf()
{
- int err;
-
libbpf_set_print(libbpf_print_fn);
-
- err = bump_memlock_rlimit();
- if (err)
- fprintf(stderr, "failed to increase RLIMIT_MEMLOCK: %d", err);
}

void hits_drops_report_progress(int iter, struct bench_res *res, long delta_ns)
diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c b/tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c
index 08651b23edba..5fe76df58dd4 100644
--- a/tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c
+++ b/tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c
@@ -19,10 +19,9 @@ int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
}

if (seq_num == 0)
- BPF_SEQ_PRINTF(seq, " id refcnt usercnt locked_vm\n");
+ BPF_SEQ_PRINTF(seq, " id refcnt usercnt\n");

BPF_SEQ_PRINTF(seq, "%8u %8ld %8ld %10lu\n", map->id, map->refcnt.counter,
- map->usercnt.counter,
- map->memory.user->locked_vm.counter);
+ map->usercnt.counter);
return 0;
}
diff --git a/tools/testing/selftests/bpf/xdping.c b/tools/testing/selftests/bpf/xdping.c
index 842d9155d36c..488021169171 100644
--- a/tools/testing/selftests/bpf/xdping.c
+++ b/tools/testing/selftests/bpf/xdping.c
@@ -88,7 +88,6 @@ int main(int argc, char **argv)
{
__u32 mode_flags = XDP_FLAGS_DRV_MODE | XDP_FLAGS_SKB_MODE;
struct addrinfo *a, hints = { .ai_family = AF_INET };
- struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
__u16 count = XDPING_DEFAULT_COUNT;
struct pinginfo pinginfo = { 0 };
const char *optstr = "c:I:NsS";
@@ -166,11 +165,6 @@ int main(int argc, char **argv)
freeaddrinfo(a);
}

- if (setrlimit(RLIMIT_MEMLOCK, &r)) {
- perror("setrlimit(RLIMIT_MEMLOCK)");
- return 1;
- }
-
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);

if (bpf_prog_load(filename, BPF_PROG_TYPE_XDP, &obj, &prog_fd)) {
diff --git a/tools/testing/selftests/net/reuseport_bpf.c b/tools/testing/selftests/net/reuseport_bpf.c
index b5277106df1f..88709898bae5 100644
--- a/tools/testing/selftests/net/reuseport_bpf.c
+++ b/tools/testing/selftests/net/reuseport_bpf.c
@@ -437,26 +437,6 @@ void enable_fastopen(void)
}
}

-static struct rlimit rlim_old;
-
-static __attribute__((constructor)) void main_ctor(void)
-{
- getrlimit(RLIMIT_MEMLOCK, &rlim_old);
-
- if (rlim_old.rlim_cur != RLIM_INFINITY) {
- struct rlimit rlim_new;
-
- rlim_new.rlim_cur = rlim_old.rlim_cur + (1UL << 20);
- rlim_new.rlim_max = rlim_old.rlim_max + (1UL << 20);
- setrlimit(RLIMIT_MEMLOCK, &rlim_new);
- }
-}
-
-static __attribute__((destructor)) void main_dtor(void)
-{
- setrlimit(RLIMIT_MEMLOCK, &rlim_old);
-}
-
int main(void)
{
fprintf(stderr, "---- IPv4 UDP ----\n");
--
2.26.2


2020-07-28 06:11:15

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH bpf-next v2 33/35] bpf: selftests: don't touch RLIMIT_MEMLOCK

On Mon, Jul 27, 2020 at 12:21 PM Roman Gushchin <[email protected]> wrote:
>
> Since bpf is not using memlock rlimit for memory accounting,
> there are no more reasons to bump the limit.
>
> Signed-off-by: Roman Gushchin <[email protected]>
> ---

Similarly for bench, it's a tool that's not coupled with the latest
kernel version, it will be a big step down if the tool doesn't bump
rlimit on its own on slightly older kernels. Let's just keep it for
now.

> tools/testing/selftests/bpf/bench.c | 16 ---------------
> .../selftests/bpf/progs/bpf_iter_bpf_map.c | 5 ++---
> tools/testing/selftests/bpf/xdping.c | 6 ------
> tools/testing/selftests/net/reuseport_bpf.c | 20 -------------------
> 4 files changed, 2 insertions(+), 45 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
> index 944ad4721c83..f66610541c8a 100644
> --- a/tools/testing/selftests/bpf/bench.c
> +++ b/tools/testing/selftests/bpf/bench.c
> @@ -29,25 +29,9 @@ static int libbpf_print_fn(enum libbpf_print_level level,
> return vfprintf(stderr, format, args);
> }
>
> -static int bump_memlock_rlimit(void)
> -{
> - struct rlimit rlim_new = {
> - .rlim_cur = RLIM_INFINITY,
> - .rlim_max = RLIM_INFINITY,
> - };
> -
> - return setrlimit(RLIMIT_MEMLOCK, &rlim_new);
> -}
> -
> void setup_libbpf()
> {
> - int err;
> -
> libbpf_set_print(libbpf_print_fn);
> -
> - err = bump_memlock_rlimit();
> - if (err)
> - fprintf(stderr, "failed to increase RLIMIT_MEMLOCK: %d", err);
> }
>

[...]