@@ -14,7 +14,7 @@ import (
14
14
"github.com/cilium/ebpf/asm"
15
15
"github.com/cilium/ebpf/btf"
16
16
"github.com/cilium/ebpf/features"
17
- "golang.org/x/sys/unix "
17
+ "github.com/cilium/ebpf/rlimit "
18
18
)
19
19
20
20
// FunctionExcluder - An interface for types that can be used for `AdditionalExcludedFunctionCollector`
@@ -104,9 +104,9 @@ type Options struct {
104
104
// ProbeRetryDelay - Defines the delay to wait before a probe should retry to attach / detach on error.
105
105
DefaultProbeRetryDelay time.Duration
106
106
107
- // RLimit - The maps & programs provided to the manager might exceed the maximum allowed memory lock.
107
+ // RemoveRlimit - The maps & programs provided to the manager might exceed the maximum allowed memory lock.
108
108
// `RLIMIT_MEMLOCK` If a limit is provided here it will be applied when the manager is initialized.
109
- RLimit * unix. Rlimit
109
+ RemoveRlimit bool
110
110
111
111
// KeepKernelBTF - Defines if the kernel types defined in VerifierOptions.Programs.KernelTypes and KernelModuleTypes should be cleaned up
112
112
// once the manager is done using them. By default, the manager will clean them up to save up space. DISCLAIMER: if
@@ -487,9 +487,11 @@ func (m *Manager) InitWithOptions(elf io.ReaderAt, options Options) error {
487
487
}
488
488
489
489
// set resource limit if requested
490
- if m .options .RLimit != nil {
491
- err := unix .Setrlimit (unix .RLIMIT_MEMLOCK , m .options .RLimit )
492
- if err != nil {
490
+ if m .options .RemoveRlimit {
491
+ // rlimit.RemoveMemlock automatically detects if rlimit based accounting
492
+ // is used for eBPF maps. Only in this case is the rlimit removed.
493
+ // If cgroup based accounting is in effect, then rlimit is not removed.
494
+ if err := rlimit .RemoveMemlock (); err != nil {
493
495
m .stateLock .Unlock ()
494
496
return fmt .Errorf ("couldn't adjust RLIMIT_MEMLOCK: %w" , err )
495
497
}
0 commit comments