@@ -296,6 +296,20 @@ func (b LibbpfStrictMode) String() (str string) {
296296 return str
297297}
298298
299+ // NOTE: libbpf has started raising limits by default but, unfortunately, that
300+ // seems to be failing in current libbpf version. The memory limit bump might be
301+ // removed once this is sorted out.
302+ func bumpMemlockRlimit () error {
303+ var rLimit syscall.Rlimit
304+ rLimit .Max = 512 << 20 /* 512 MBs */
305+ rLimit .Cur = 512 << 20 /* 512 MBs */
306+ err := syscall .Setrlimit (C .RLIMIT_MEMLOCK , & rLimit )
307+ if err != nil {
308+ return fmt .Errorf ("error setting rlimit: %v" , err )
309+ }
310+ return nil
311+ }
312+
299313func SetStrictMode (mode LibbpfStrictMode ) {
300314 C .libbpf_set_strict_mode (uint32 (mode ))
301315}
@@ -307,6 +321,11 @@ func NewModuleFromFileArgs(args NewModuleArgs) (*Module, error) {
307321 }
308322 C .set_print_fn ()
309323
324+ // TODO: remove this once libbpf memory limit bump issue is solved
325+ if err := bumpMemlockRlimit (); err != nil {
326+ return nil , err
327+ }
328+
310329 opts := C.struct_bpf_object_open_opts {}
311330 opts .sz = C .sizeof_struct_bpf_object_open_opts
312331
@@ -353,6 +372,11 @@ func NewModuleFromBufferArgs(args NewModuleArgs) (*Module, error) {
353372 }
354373 C .set_print_fn ()
355374
375+ // TODO: remove this once libbpf memory limit bump issue is solved
376+ if err := bumpMemlockRlimit (); err != nil {
377+ return nil , err
378+ }
379+
356380 if args .BTFObjPath == "" {
357381 args .BTFObjPath = "/sys/kernel/btf/vmlinux"
358382 }
0 commit comments