Add I/O priority

Signed-off-by: utam0k <k0ma@utam0k.jp>
This commit is contained in:
utam0k
2023-03-24 12:22:25 +00:00
parent a1acca9acb
commit bfbd0305ba
10 changed files with 124 additions and 1 deletions
+25
View File
@@ -124,6 +124,13 @@ func (p *setnsProcess) signal(sig os.Signal) error {
func (p *setnsProcess) start() (retErr error) {
defer p.comm.closeParent()
if p.process.IOPriority != nil {
if err := setIOPriority(p.process.IOPriority); err != nil {
return err
}
}
// get the "before" value of oom kill count
oom, _ := p.manager.OOMKillCount()
err := p.cmd.Start()
@@ -972,3 +979,21 @@ func initWaiter(r io.Reader) chan error {
return ch
}
func setIOPriority(ioprio *configs.IOPriority) error {
const ioprioWhoPgrp = 1
class, ok := configs.IOPrioClassMapping[ioprio.Class]
if !ok {
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)
}
// Combine class and priority into a single value
// https://github.com/torvalds/linux/blob/v5.18/include/uapi/linux/ioprio.h#L5-L17
iop := (class << 13) | ioprio.Priority
_, _, errno := unix.RawSyscall(unix.SYS_IOPRIO_SET, ioprioWhoPgrp, 0, uintptr(iop))
if errno != 0 {
return fmt.Errorf("failed to set io priority: %w", errno)
}
return nil
}