Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 
0003 #include "util/debug.h"
0004 #include "util/rlimit.h"
0005 #include <sys/time.h>
0006 #include <sys/resource.h>
0007 
0008 /*
0009  * Bump the memlock so that we can get bpf maps of a reasonable size,
0010  * like the ones used with 'perf trace' and with 'perf test bpf',
0011  * improve this to some specific request if needed.
0012  */
0013 void rlimit__bump_memlock(void)
0014 {
0015     struct rlimit rlim;
0016 
0017     if (getrlimit(RLIMIT_MEMLOCK, &rlim) == 0) {
0018         rlim.rlim_cur *= 4;
0019         rlim.rlim_max *= 4;
0020 
0021         if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
0022             rlim.rlim_cur /= 2;
0023             rlim.rlim_max /= 2;
0024 
0025             if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0)
0026                 pr_debug("Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc\n");
0027         }
0028     }
0029 }