-
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
Remove kmem Initialization check while setting memory configuration #962
Conversation
a5e95f8
to
1a323f1
Compare
Are we happy for it to fail if joining an existing cgroup with a limit already sets? On this PR, the error message is not very explicit from a user perspective as it will just be:
I think adding a more explanatory message to the returned error on WDYT? |
Yeah, that's what I concerned in #841 (comment) |
1a323f1
to
5106b56
Compare
@mlaventure @hqhq Please have a look at my comment here: #841 (comment) |
// We have to set kernel memory here, as we can't change it once | ||
// processes have been attached to the cgroup. | ||
if err := s.SetKernelMemory(path, d.config); err != nil { | ||
// We have to limit the kernel memory here as it won't be accounted at all |
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.
Check if memory.kmem.limit_in_bytes
file is there?
On Mon, Jul 25, 2016 at 11:46 AM, Buddha Prakash [email protected]
wrote:
In libcontainer/cgroups/fs/memory.go
#962 (comment):@@ -34,9 +32,15 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
return err
}
}
// We have to set kernel memory here, as we can't change it once
// processes have been attached to the cgroup.
if err := s.SetKernelMemory(path, d.config); err != nil {
// We have to limit the kernel memory here as it won't be accounted at all
We need to have a check here for determining if kmem is enabled on the
system.
@hqhq https://github.com/hqhq @vishh https://github.com/vishh
Suggestions on how to check for the same?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/opencontainers/runc/pull/962/files/5106b565da1c9af39f279edb0235eb1da06d703d#r72121173,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGvIKEIF-LQ6vcR1xObXWdqCQ_kmAS4aks5qZQSdgaJpZM4JTOyV
.
Alternative of opencontainers#962 Fixes: opencontainers#841 Signed-off-by: Qiang Huang <[email protected]>
5106b56
to
b2fe403
Compare
Updated the patch to add a more specific error message when kernel memory limit write fails with an EBUSY. |
LGTM (IANAM). |
return err | ||
|
||
// Check if kernel memory is enabled | ||
if _, err := os.Stat(filepath.Join(path, cgroupKernelMemoryLimit)); err == nil { |
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 use cgroups.PathExists(...)
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.
Why not move this check to SetKernelMemory(...)
method?
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.
The idea was we SetKernelMemory() only if kernel memory is enabled. So have the check and then call the method.
But having the check inside the method would be more cleaner. I will make that change.
b2fe403
to
bb706f9
Compare
if pathErr, ok := err.(*os.PathError); ok { | ||
if errNo, ok := pathErr.Err.(syscall.Errno); ok { | ||
if errNo == syscall.EBUSY { | ||
return fmt.Errorf("Cannot set %s after tasks have joined this cgroup", cgroupKernelMemoryLimit) |
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.
EBUSY could also be returned if there are child cgroups, we need to change error message a bit to cover that.
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.
Don't forget to change the above comments.
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.
And error messages start with lower case in runc.
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.
Right! Thanks
e742564
to
91825b2
Compare
@cyphar @hqhq @mrunalp @mlaventure I have updated the logic in systemd to be same as that of cgroup fs. @mrunalp @derekwaynecarr Can you please have a look and maybe test it on a systemd system. |
if pathErr, ok := err.(*os.PathError); ok { | ||
if errNo, ok := pathErr.Err.(syscall.Errno); ok { | ||
if errNo == syscall.EBUSY { | ||
return fmt.Errorf("failed to set %s, because either tasks have already joined this cgroupe or it has chilren", cgroupKernelMemoryLimit) |
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.
s/cgroupe/cgroup
s/chilren/children
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.
Thanks! I will make the change!
Signed-off-by: Buddha Prakash <[email protected]>
91825b2
to
fcd966f
Compare
@cyphar @mrunalp @mlaventure friendly ping! |
This LGTM. Thanks for the cleanup @dubstack !! @opencontainers/runc-maintainers Can we get a quick review on this? This PR is important. |
Testing this with systemd. |
@hmeng-19 Could you test this PR on RHEL 7? |
@hmeng-19 Thanks for testing. |
@mrunalp , no problem. First, I created a basic config.json:
Then add kernel memory limit into config.json:
Finally, start the container and check the kernel memory limit:
|
Follow up: opencontainers#962 Signed-off-by: Qiang Huang <[email protected]>
I suggest that we modify the logic for setting the kmem.limit_on_bytes to be more deterministic and
remove the kmemInitialized check.
If kernel memory is enabled we limit the cgroup during cgroup creation ie. in apply(). This will enable kernel memory accounting on the cgroup ( http://lxr.free-electrons.com/source/Documentation/cgroups/memory.txt?v=3.9#L284 ).
We limit the cgroup by writing some arbitrary limiting value(say 1) so that the kernel memory is accounted, and then we remove the limitation by writing -1.
Once accounting is enabled we should be able to set the kernel memory limit to configuration value in the Set method.
The only scenario in which this would fail is if someone straight out calls Set() on a cgroup which was not created by libcontainer, in which case, if there are already process attached to the cgroup setting kernel memory limit would return an Ebusy signal and we can error out.
cc @mrunalp @derekwaynecarr @cyphar @vishh @hqhq PTAL