-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Carry 3962] Support process.scheduler
#4025
[Carry 3962] Support process.scheduler
#4025
Conversation
ecd3e1a
to
8d1145b
Compare
libcontainer/process_linux.go
Outdated
@@ -81,6 +81,7 @@ func (p *setnsProcess) signal(sig os.Signal) error { | |||
|
|||
func (p *setnsProcess) start() (retErr error) { | |||
defer p.messageSockPair.parent.Close() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated; please remove
libcontainer/setns_init_linux.go
Outdated
if errors.Is(err, unix.EPERM) { | ||
return fmt.Errorf("error setting scheduler(please check you have appropriate privileges or valid cpus config): %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do want to distinguish between the two cases for EPERM, maybe it makes sense to check if we have cpus
set first.
Also, maybe move this code into a separate function (setupScheduler), as we have the same 8 lines of code in both setns_init_linux.go and standard_init_linux.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it makes sense to check if we have
cpus
set first.
I also considered it when writing the code, but there is another corner case is that if the cpus
value includes all cpus in the machine, it will be no error. So I don't want to check cpus value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lifubang thanks for the carry! Left some comments, mostly minor.
3087839
to
dc3aa07
Compare
Thanks, there are all resolved, PTAL. |
return nil | ||
} | ||
if s.Policy == "" { | ||
return fmt.Errorf("scheduler policy is required") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: errors.New
.
niceValue := s.Nice | ||
if niceValue < -20 || niceValue > 19 { | ||
return fmt.Errorf("invalid scheduler.nice: %d", niceValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use s.Nice
directly (drop the intermediate variable) here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original author used an intermediate variable because repeating config.Scheduler.Nice
three times was too much.
But, just in case an intermediate variable is preferred, it is better to limit its scope:
if n := s.Nice; n < -20 || n > 19 {
return fmt.Errorf("invalid scheduler.nice: %d", n)
}
libcontainer/init_linux.go
Outdated
if config.Cgroups.CpusetCpus == "" { | ||
return errors.New("please check you have appropriate privileges to set process scheduler") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe don't make this a special case.
I.e. something like
if err := unix.SchedSetAttr(0, attr, 0); err != nil {
if errors.Is(err, unix.EPERM) && config.Cgroups.CpusetCpus != "" {
return errors.New("process scheduler can not be used together with AllowedCPUs")
}
return fmt.Errorf("error setting scheduler: %w", err)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some nits.
Also, you can add Co-authored-by: ...
footer.
eded31e
to
25b3d41
Compare
fd43bb2
to
cf74bfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Spec: opencontainers/runtime-spec#1188 Fix: opencontainers#3895 Co-authored-by: lifubang <[email protected]> Signed-off-by: utam0k <[email protected]> Signed-off-by: lifubang <[email protected]>
cf74bfc
to
770728e
Compare
(this is a carry of #3962)
Spec: opencontainers/runtime-spec#1188
Close: #3895 #3962