diff --git a/packages/orchestrator/internal/sandbox/uffd/serve.go b/packages/orchestrator/internal/sandbox/uffd/serve.go index a10afa50b6..afffe11688 100644 --- a/packages/orchestrator/internal/sandbox/uffd/serve.go +++ b/packages/orchestrator/internal/sandbox/uffd/serve.go @@ -3,6 +3,7 @@ package uffd import ( "errors" "fmt" + "sync/atomic" "syscall" "unsafe" @@ -41,6 +42,17 @@ func Serve( missingPagesBeingHandled := map[int64]struct{}{} + var readEagainCount atomic.Int64 + + logEagainCount := func(message string) { + eagainOccurences := readEagainCount.Swap(0) + if eagainOccurences > 0 { + logger.Debug(message, zap.Any("occurences", eagainOccurences)) + } + } + + defer logEagainCount("uffd: closing with accumulated read EAGAIN occurences") + outerLoop: for { if _, err := unix.Poll( @@ -54,7 +66,7 @@ outerLoop: } if err == unix.EAGAIN { - logger.Debug("uffd: eagain during polling, going back to polling") + logger.Debug("uffd: eagain fd polling, going back to polling") continue } @@ -95,7 +107,7 @@ outerLoop: buf := make([]byte, unsafe.Sizeof(userfaultfd.UffdMsg{})) for { - n, err := syscall.Read(uffd, buf) + _, err := syscall.Read(uffd, buf) if err == syscall.EINTR { logger.Debug("uffd: interrupted read, reading again") @@ -108,7 +120,7 @@ outerLoop: } if err == syscall.EAGAIN { - logger.Debug("uffd: eagain error, going back to polling", zap.Error(err), zap.Int("read_bytes", n)) + readEagainCount.Add(1) // Continue polling the fd. continue outerLoop @@ -151,6 +163,8 @@ outerLoop: } }() + defer logEagainCount("uffd: serving with accumulated read eagain occurences") + b, err := src.Slice(offset, pagesize) if err != nil {