storj/storagenode/iopriority/low_ioprio_linux.go
Clement Sam f076238748 storagenode: run used-space filewalker as a low IO subprocess
As part of fixing the IO priority of filewalker related
processes such as the garbage collection and used-space
calculation, this  change allows the initial used-space
calculation to run as a separate subprocess with lower
IO priority.

This can be enabled with the `--storage2.enable-lazy-filewalker`
config item. It falls back to the old behaviour when the
subprocess fails.

Updates https://github.com/storj/storj/issues/5349

Change-Id: Ia6ee98ce912de3e89fc5ca670cf4a30be73b36a6
2023-04-14 04:16:14 +00:00

30 lines
806 B
Go

// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package iopriority
import (
"syscall"
)
// These constants come from the definitions in linux's ioprio.h.
// See https://github.com/torvalds/linux/blob/master/include/uapi/linux/ioprio.h
const (
ioprioClassShift = uint32(13)
ioprioPrioMask = (uint32(1) << ioprioClassShift) - 1
ioprioWhoProcess = 1
ioprioClassIdle = 3
)
// SetLowIOPriority lowers the process I/O priority.
func SetLowIOPriority() error {
// from the definition for the IOPRIO_PRIO_VALUE macro in Linux's ioprio.h
ioprioPrioValue := ioprioClassIdle<<ioprioClassShift | (0 & ioprioPrioMask)
_, _, err := syscall.Syscall(syscall.SYS_IOPRIO_SET, uintptr(ioprioWhoProcess), 0, uintptr(ioprioPrioValue))
if err != 0 {
return err
}
return nil
}