-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
server/status: read current process's cgroup to determine available memory #43137
server/status: read current process's cgroup to determine available memory #43137
Conversation
to save future headaches, is it possible to support reading both cgroup v1 file or v2 file? in Kubernetes, we are starting to work toward cgroup v2 enablement so adding support for memory.max in addition to what is checked here would help prevent future revisions. |
@bdarnell I didn't know about #32067 when I typed this. Do we prefer that patch? It adds a dependency on runc just to read the Relates to #31750. |
My thinking is that if it's just the small amount of code in this PR, I'd rather parse the file ourselves and not have the dependency. But given the "TODO: support v2" comments, it seems useful to take on a dependency and get (hopefully) more complete and future-proof support for it. ( |
I buy that. I went fishing around for a better library than the one in If I read your comment correctly, I should take a stab at adopting a dependency to achieve the goals and only if I have a bad time should we revisit this more manual approach. |
Yeah, I'd try with the dependency first. |
4fca024
to
0b6c605
Compare
I ran in to trouble with the dependencies. I decided to just support v2. I wrote tests and tried it out in a variety of settings on VMs. It seems to work. @vladdy would you be willing to give this a review? |
I suspect the code needs more of a gate on the OS, perhaps by consulting runtime.GOOS at runtime or by using compilation directives. Otherwise it is RFAL. |
fd295e5
to
07fd8f3
Compare
Prior to this commit we would consult the system memory and the root cgroup to determine the available memory. This is problematic because almost always when systems use cgroups they use a hierarchy to create limits for specific sets of processes. After this change we'll now determine the deepest child hierarchy which contains this process and examine all of the relevant limits to determine the memory limit. This commit adds a `util/cgroups` package which contains logic to examine the cgroup hierarchy for the current process. Release note (bug fix): On linux machines we now respect the available memory limit as dictated by the cgroup limits which apply to the cockroach process.
07fd8f3
to
a1f18d0
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.
Reviewed 4 of 4 files at r1.
Reviewable status:complete! 0 of 0 LGTMs obtained
TFTR! bors r=vladdy |
43137: server/status: read current process's cgroup to determine available memory r=vladdy a=ajwerner Prior to this commit we would consult the system memory and the root cgroup to determine the available memory. This is problematic because almost always when systems use cgroups they use a hierarchy to create limits for specific sets of processes. After this change we'll now determine the deepest child hierarchy which contains this process and examine all of the relevant limits to determine the memory limit. Release note (bug fix): On linux machines we now respect the available memory limit as dictated by the cgroup limits which apply to the cockroach process. Co-authored-by: Andrew Werner <ajwerner@cockroachlabs.com>
Build succeeded |
Prior to this commit we would consult the system memory and the root cgroup
to determine the available memory. This is problematic because almost always
when systems use cgroups they use a hierarchy to create limits for specific
sets of processes. After this change we'll now determine the deepest child
hierarchy which contains this process and examine all of the relevant
limits to determine the memory limit.
Release note (bug fix): On linux machines we now respect the available memory
limit as dictated by the cgroup limits which apply to the cockroach process.