diff mbox series

[bpf-next] tools/bpf: adjust rlimit RLIMIT_MEMLOCK for test_tcpbpf_user

Message ID 20180213183505.3994994-1-yhs@fb.com
State Accepted, archived
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] tools/bpf: adjust rlimit RLIMIT_MEMLOCK for test_tcpbpf_user | expand

Commit Message

Yonghong Song Feb. 13, 2018, 6:35 p.m. UTC
The default rlimit RLIMIT_MEMLOCK is 64KB. In certain cases,
e.g. in a test machine mimicking our production system, this test may
fail due to unable to charge the required memory for map creation:
   # ./test_tcpbpf_user
   libbpf: failed to create map (name: 'global_map'): Operation not permitted
   libbpf: failed to load object 'test_tcpbpf_kern.o'
   FAILED: load_bpf_file failed for: test_tcpbpf_kern.o

Changing the default rlimit RLIMIT_MEMLOCK to unlimited makes
the test always pass.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/testing/selftests/bpf/test_tcpbpf_user.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Alexei Starovoitov Feb. 14, 2018, 2:04 a.m. UTC | #1
On Tue, Feb 13, 2018 at 10:35:05AM -0800, Yonghong Song wrote:
> The default rlimit RLIMIT_MEMLOCK is 64KB. In certain cases,
> e.g. in a test machine mimicking our production system, this test may
> fail due to unable to charge the required memory for map creation:
>    # ./test_tcpbpf_user
>    libbpf: failed to create map (name: 'global_map'): Operation not permitted
>    libbpf: failed to load object 'test_tcpbpf_kern.o'
>    FAILED: load_bpf_file failed for: test_tcpbpf_kern.o
> 
> Changing the default rlimit RLIMIT_MEMLOCK to unlimited makes
> the test always pass.
> 
> Signed-off-by: Yonghong Song <yhs@fb.com>

Applied to bpf-next, Thanks Yonghong.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_tcpbpf_user.c b/tools/testing/selftests/bpf/test_tcpbpf_user.c
index 95a370f..5d73db4 100644
--- a/tools/testing/selftests/bpf/test_tcpbpf_user.c
+++ b/tools/testing/selftests/bpf/test_tcpbpf_user.c
@@ -11,6 +11,8 @@ 
 #include <linux/ptrace.h>
 #include <linux/bpf.h>
 #include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -42,6 +44,7 @@  static int bpf_find_map(const char *test, struct bpf_object *obj,
 
 int main(int argc, char **argv)
 {
+	struct rlimit limit  = { RLIM_INFINITY, RLIM_INFINITY };
 	const char *file = "test_tcpbpf_kern.o";
 	struct tcpbpf_globals g = {0};
 	int cg_fd, prog_fd, map_fd;
@@ -54,6 +57,9 @@  int main(int argc, char **argv)
 	int pid;
 	int rv;
 
+	if (setrlimit(RLIMIT_MEMLOCK, &limit) < 0)
+		perror("Unable to lift memlock rlimit");
+
 	if (argc > 1 && strcmp(argv[1], "-d") == 0)
 		debug_flag = true;