Skip to content

Commit

Permalink
libct: unify IOPriority setting
Browse files Browse the repository at this point in the history
For some reason, io priority is set in different places between runc
start/run and runc exec (it is done much earlier for the latter).

Let's unify the code flow of start/run and exec.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Jul 1, 2024
1 parent 5d90543 commit 135ebae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
21 changes: 21 additions & 0 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,27 @@ func setupScheduler(config *configs.Config) error {
return nil
}

func setIOPriority(ioprio *configs.IOPriority) error {
const ioprioWhoPgrp = 1

if ioprio == nil {
return nil
}
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
}

func setupPersonality(config *configs.Config) error {
return system.SetLinuxPersonality(config.Personality.Domain)
}
Expand Down
25 changes: 0 additions & 25 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ func (p *setnsProcess) signal(sig os.Signal) error {
func (p *setnsProcess) start() (retErr error) {
defer p.comm.closeParent()

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()
Expand Down Expand Up @@ -986,24 +982,3 @@ func initWaiter(r io.Reader) chan error {

return ch
}

func setIOPriority(ioprio *configs.IOPriority) error {
const ioprioWhoPgrp = 1

if ioprio == nil {
return nil
}
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
}
3 changes: 3 additions & 0 deletions libcontainer/setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (l *linuxSetnsInit) Init() error {
return err
}

if err := setIOPriority(l.config.Config.IOPriority); err != nil {
return err
}
// Tell our parent that we're ready to exec. This must be done before the
// Seccomp rules have been applied, because we need to be able to read and
// write to a socket.
Expand Down

0 comments on commit 135ebae

Please sign in to comment.