Skip to content

Commit

Permalink
fix: re-introduce memory bumping (#265)
Browse files Browse the repository at this point in the history
make libbpfgo to bump rlimits instead of relying in libbpf to do so.
  • Loading branch information
rafaeldtinoco committed Oct 25, 2022
1 parent 57b6f6d commit 9ba4e04
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libbpfgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ func (b LibbpfStrictMode) String() (str string) {
return str
}

// NOTE: libbpf has started raising limits by default but, unfortunately, that
// seems to be failing in current libbpf version. The memory limit bump might be
// removed once this is sorted out.
func bumpMemlockRlimit() error {
var rLimit syscall.Rlimit
rLimit.Max = 512 << 20 /* 512 MBs */
rLimit.Cur = 512 << 20 /* 512 MBs */
err := syscall.Setrlimit(C.RLIMIT_MEMLOCK, &rLimit)
if err != nil {
return fmt.Errorf("error setting rlimit: %v", err)
}
return nil
}

func SetStrictMode(mode LibbpfStrictMode) {
C.libbpf_set_strict_mode(uint32(mode))
}
Expand All @@ -307,6 +321,11 @@ func NewModuleFromFileArgs(args NewModuleArgs) (*Module, error) {
}
C.set_print_fn()

// TODO: remove this once libbpf memory limit bump issue is solved
if err := bumpMemlockRlimit(); err != nil {
return nil, err
}

opts := C.struct_bpf_object_open_opts{}
opts.sz = C.sizeof_struct_bpf_object_open_opts

Expand Down Expand Up @@ -353,6 +372,11 @@ func NewModuleFromBufferArgs(args NewModuleArgs) (*Module, error) {
}
C.set_print_fn()

// TODO: remove this once libbpf memory limit bump issue is solved
if err := bumpMemlockRlimit(); err != nil {
return nil, err
}

if args.BTFObjPath == "" {
args.BTFObjPath = "/sys/kernel/btf/vmlinux"
}
Expand Down

0 comments on commit 9ba4e04

Please sign in to comment.