rlimit.c 730 B

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