-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add support for adjusting OOM score adjustment. #94
Conversation
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.
Thank's for the PR @zxj874478410 ! I have a few nits, but otherwise it looks good to me.
Thanks for the review @klihub . I've fixed these faults. |
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
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.
wondering if we should be able to nil out the oooscoreadj
func (g *Generator) AdjustOomScoreAdj(score *nri.OptionalInt) { | ||
if score != nil { | ||
g.SetProcessOOMScoreAdj(int(score.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.
Thanks for the suggestion! After we set OomScoreAdj to nil, We can handle the nil here.
I try to call the func g.initConfigProcess() by calling func g.SetProcessOOMScoreAdj(0), and then set g.Config.Process.OOMScoreAdj to nil. Will it work? @mikebrow
} | |
} else { | |
g.SetProcessOOMScoreAdj(0) | |
g.Config.Process.OOMScoreAdj = 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.
sgtm let's try it / test it out
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.
We tested it with the following code
oomScoreAdj:= 555
adjustment.SetLinuxOomScoreAdj(&oomScoreAdj)
adjustment.SetLinuxOomScoreAdj(nil)
The second set unset the oomscoreadj with the api. Finally, the oom_score_adj is set to 996 by kubelet.
cat /proc/2213925/oom_score_adj
996
This is work! @mikebrow
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.
nod.. while I think it's a valid path to unset given 0 / 999 etc.. is not unset.. we need to ensure we are not accidentally unsetting a valid oom from kubelet. @klihub FYI
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.
manual:
Sets the adjustment value for the Linux kernel's
Out-Of-Memory (OOM) killer score for executed processes.
Takes an integer between -1000 (to disable OOM killing of
processes of this unit) and 1000 (to make killing of
processes of this unit under memory pressure very likely).
See The /proc Filesystem[6] for details. If not specified
defaults to the OOM score adjustment level of the service
manager itself, which is normally at 0.
note behavior normally 0 when unset, but is configurable making unset a unique state
94de1db
to
f3f0bd7
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.
LGTM
1712c1a
to
83f6ab0
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.
LGTM
Signed-off-by: Xiaojin Zhang <874478410@qq.com>
|
@zxj874478410 This fix is not sufficient in it's current form as it breaks replacing a mount with another one to the same destination. I think we'd need a bit of additional code to prevent that from happening. Maybe something like this, where 8f509e7 is an updated version of your commit, and 7ea0a47 adds a new test case for mount removal. |
@zxj874478410 PTAL at the latest review comments and the suggested fixes/improvements.
Thanks for the detailed instructions, but does this problem refer to another pr #87 ? This one refers to OOM score adjustment. |
Argh... Sorry about that. Yes, you are absolutely right, it is about PR #87. Time to renew my glasses or get a brain transplant... |
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
The OomScoreAdj field is added to the LinuxContainerAdjustment structure of the NRI plugin. This field records the value of oom_score_adj that needs to be adjusted during CreateContainer. Added the appropriate set method and the method to write back to the NRI response.
Fix #92
TEST METHOD:
We build a NRI plugin with CreateContainer function like this:
Then run this NRI plugin with containerd. Create a k8s pod of apache.
Run the docker inspect command to query the process ID of the Apache container is 3445531.
At last, query the oom_score_adj of this pid. It has been set to 121 successfully.