1*4882a593Smuzhiyun /* SPDX-License-Identifier: LGPL-2.1 */ 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun #include "util/debug.h" 4*4882a593Smuzhiyun #include "util/rlimit.h" 5*4882a593Smuzhiyun #include <sys/time.h> 6*4882a593Smuzhiyun #include <sys/resource.h> 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun /* 9*4882a593Smuzhiyun * Bump the memlock so that we can get bpf maps of a reasonable size, 10*4882a593Smuzhiyun * like the ones used with 'perf trace' and with 'perf test bpf', 11*4882a593Smuzhiyun * improve this to some specific request if needed. 12*4882a593Smuzhiyun */ rlimit__bump_memlock(void)13*4882a593Smuzhiyunvoid rlimit__bump_memlock(void) 14*4882a593Smuzhiyun { 15*4882a593Smuzhiyun struct rlimit rlim; 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun if (getrlimit(RLIMIT_MEMLOCK, &rlim) == 0) { 18*4882a593Smuzhiyun rlim.rlim_cur *= 4; 19*4882a593Smuzhiyun rlim.rlim_max *= 4; 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) { 22*4882a593Smuzhiyun rlim.rlim_cur /= 2; 23*4882a593Smuzhiyun rlim.rlim_max /= 2; 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) 26*4882a593Smuzhiyun pr_debug("Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc\n"); 27*4882a593Smuzhiyun } 28*4882a593Smuzhiyun } 29*4882a593Smuzhiyun } 30