Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / rlimit.c
blob13521d392a227271a60e9be0c59fda0c2832b95f
1 /* SPDX-License-Identifier: LGPL-2.1 */
3 #include "util/debug.h"
4 #include "util/rlimit.h"
5 #include <sys/time.h>
6 #include <sys/resource.h>
8 /*
9 * Bump the memlock so that we can get bpf maps of a reasonable size,
10 * like the ones used with 'perf trace' and with 'perf test bpf',
11 * improve this to some specific request if needed.
13 void rlimit__bump_memlock(void)
15 struct rlimit rlim;
17 if (getrlimit(RLIMIT_MEMLOCK, &rlim) == 0) {
18 rlim.rlim_cur *= 4;
19 rlim.rlim_max *= 4;
21 if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
22 rlim.rlim_cur /= 2;
23 rlim.rlim_max /= 2;
25 if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0)
26 pr_debug("Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc\n");