Skip to content

Commit c4eb7f4

Browse files
netoptimizerdavem330
authored andcommitted
samples/bpf: xdp_monitor increase memory rlimit
Other concurrent running programs, like perf or the XDP program what needed to be monitored, might take up part of the max locked memory limit. Thus, the xdp_monitor tool have to set the RLIMIT_MEMLOCK to RLIM_INFINITY, as it cannot determine a more sane limit. Using the man exit(3) specified EXIT_FAILURE return exit code, and correct other users too. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 280b058 commit c4eb7f4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

samples/bpf/xdp_monitor_user.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static const char *__doc_err_only__=
2020
#include <unistd.h>
2121
#include <locale.h>
2222

23+
#include <sys/resource.h>
2324
#include <getopt.h>
2425
#include <net/if.h>
2526
#include <time.h>
@@ -295,6 +296,7 @@ static void print_bpf_prog_info(void)
295296

296297
int main(int argc, char **argv)
297298
{
299+
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
298300
int longindex = 0, opt;
299301
int ret = EXIT_SUCCESS;
300302
char bpf_obj_file[256];
@@ -325,13 +327,18 @@ int main(int argc, char **argv)
325327
}
326328
}
327329

330+
if (setrlimit(RLIMIT_MEMLOCK, &r)) {
331+
perror("setrlimit(RLIMIT_MEMLOCK)");
332+
return EXIT_FAILURE;
333+
}
334+
328335
if (load_bpf_file(bpf_obj_file)) {
329336
printf("ERROR - bpf_log_buf: %s", bpf_log_buf);
330-
return 1;
337+
return EXIT_FAILURE;
331338
}
332339
if (!prog_fd[0]) {
333340
printf("ERROR - load_bpf_file: %s\n", strerror(errno));
334-
return 1;
341+
return EXIT_FAILURE;
335342
}
336343

337344
if (debug) {

0 commit comments

Comments
 (0)