Skip to content

Commit ffa9baf

Browse files
committed
libct: unify IOPriority setting
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 <kolyshkin@gmail.com>
1 parent cc91030 commit ffa9baf

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

libcontainer/init_linux.go

+21
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,27 @@ func setupScheduler(config *configs.Config) error {
692692
return nil
693693
}
694694

695+
func setIOPriority(ioprio *configs.IOPriority) error {
696+
const ioprioWhoPgrp = 1
697+
698+
if ioprio == nil {
699+
return nil
700+
}
701+
class, ok := configs.IOPrioClassMapping[ioprio.Class]
702+
if !ok {
703+
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)
704+
}
705+
706+
// Combine class and priority into a single value
707+
// https://github.com/torvalds/linux/blob/v5.18/include/uapi/linux/ioprio.h#L5-L17
708+
iop := (class << 13) | ioprio.Priority
709+
_, _, errno := unix.RawSyscall(unix.SYS_IOPRIO_SET, ioprioWhoPgrp, 0, uintptr(iop))
710+
if errno != 0 {
711+
return fmt.Errorf("failed to set io priority: %w", errno)
712+
}
713+
return nil
714+
}
715+
695716
func setupPersonality(config *configs.Config) error {
696717
return system.SetLinuxPersonality(config.Personality.Domain)
697718
}

libcontainer/process_linux.go

-25
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ func (p *setnsProcess) signal(sig os.Signal) error {
125125
func (p *setnsProcess) start() (retErr error) {
126126
defer p.comm.closeParent()
127127

128-
if err := setIOPriority(p.process.IOPriority); err != nil {
129-
return err
130-
}
131-
132128
// get the "before" value of oom kill count
133129
oom, _ := p.manager.OOMKillCount()
134130
err := p.cmd.Start()
@@ -986,24 +982,3 @@ func initWaiter(r io.Reader) chan error {
986982

987983
return ch
988984
}
989-
990-
func setIOPriority(ioprio *configs.IOPriority) error {
991-
const ioprioWhoPgrp = 1
992-
993-
if ioprio == nil {
994-
return nil
995-
}
996-
class, ok := configs.IOPrioClassMapping[ioprio.Class]
997-
if !ok {
998-
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)
999-
}
1000-
1001-
// Combine class and priority into a single value
1002-
// https://github.com/torvalds/linux/blob/v5.18/include/uapi/linux/ioprio.h#L5-L17
1003-
iop := (class << 13) | ioprio.Priority
1004-
_, _, errno := unix.RawSyscall(unix.SYS_IOPRIO_SET, ioprioWhoPgrp, 0, uintptr(iop))
1005-
if errno != 0 {
1006-
return fmt.Errorf("failed to set io priority: %w", errno)
1007-
}
1008-
return nil
1009-
}

libcontainer/setns_init_linux.go

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func (l *linuxSetnsInit) Init() error {
7676
return err
7777
}
7878

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

0 commit comments

Comments
 (0)