Skip to content

Commit 98c1b0e

Browse files
committed
mpt/internal/span: fallback to MADV_DONTNEED if MADV_FREE is unavailable
1 parent 000e70e commit 98c1b0e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

mpt/internal/span/span_unix.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ func (s *Span) Release() error {
6363
if err := unix.Mprotect(s.mem[:s.alloc], unix.PROT_NONE); err != nil {
6464
return fmt.Errorf("span.Release: mprotect: %w", err)
6565
}
66-
if err := unix.Madvise(s.mem[:s.alloc], unix.MADV_FREE); err != nil {
66+
err := unix.Madvise(s.mem[:s.alloc], unix.MADV_FREE)
67+
if err == unix.EINVAL {
68+
// MADV_FREE is missing before Linux 4.5 and in gVisor.
69+
err = unix.Madvise(s.mem[:s.alloc], unix.MADV_DONTNEED)
70+
}
71+
if err != nil {
6772
return fmt.Errorf("span.Release: madvise: %w", err)
6873
}
6974
}

0 commit comments

Comments
 (0)