Fix physical memory monitoring in constrained Linux docker containers#23944
Conversation
Signed-off-by: chinrank <thrillpool1@gmail.com>
Signed-off-by: chinrank <thrillpool1@gmail.com>
|
@bot-gradle test this |
|
I've triggered the following builds for you: |
|
@Thrillpool I'd like to add you as a contributor in the release notes for 8.1. We typically use author's actual names for this with a link to their Github profile (for example, see the opening section of https://docs.gradle.org/current/release-notes.html). However, your Github profile doesn't list your name. Would you like to provide it or would you rather just use your Github handle? |
|
|
||
| public class CGroupMemoryInfo implements OsMemoryInfo { | ||
| private static final String CGROUP_MEM_USAGE_FILE = "/sys/fs/cgroup/memory/memory.usage_in_bytes"; | ||
| private static final String CGROUP_MEM_TOTAL_FILE = "/sys/fs/cgroup/memory/memory.limit_in_bytes"; |
There was a problem hiding this comment.
I've been working on my own version of this, and there is a few of problems with this approach:
- This only works for cgroups v1. In cgroups v2, there is a "unified hierarchy" where it lives at
/sys/fs/cgroup/memory.max/memory.current. - When there is no limit, the number in
memory.limit_in_bytes(cgroups v1) is a huge number9223372036854771712. Formemory.max(cgroups v2) it is the stringmax. In this case, you can't use these values - you need to read from/proc/meminfoto get the total actual system memory. - Not sure how much this appears in practice, but it's possible to mount the cgroup filesystems in a different directory to
/sys/fs/cgroup. The best way to handle this would be:
i. Read/etc/mtaband look forcgroup2orcgroup .... memoryentries
ii. If these exist, use them
iii. If they don't exist, try the default/sys/fs/cgrouppath
There was a problem hiding this comment.
I can make a PR with the code I have (although might have to wait until Monday, as it's getting late here in London).
There was a problem hiding this comment.
Thanks for the insight here. 1 and 3 are good points, but also items I think that could be addressed as follow up work (i.e. we could deliver cgroup1 support at the default location in this PR and then add support for cgroup2 later). I think item 2 is not an issue because when the cgroup1 value is a huge number, we always select the smaller of the cgroup value or the meminfo value. Assuming we also support cgroups v2 in the future, when it's "max" we would just drop out and not consider the cgroup value (i.e. non-numeric value), defaulting to meminfo.
There was a problem hiding this comment.
More than happy for this to be merged in as is, it should fix our issues in CI at least. My code unfortunately targets Java 8, rather than 6, so can't immediately get it working when pasted into this repo, but here it is for posterity.
There was a problem hiding this comment.
@ghale is there by any chance any ticket for supporting cgroup2 also?
| import java.io.IOException; | ||
| import java.nio.charset.Charset; | ||
|
|
||
| public class CGroupMemoryInfo implements OsMemoryInfo { |
There was a problem hiding this comment.
Would it also be possible to backport this to Gradle 7? We've started migrating to Gradle 8, but we have over 100 plugins written over 10 years and 1000s of repos, so it takes us a good long while. Without the backport I'm going to have continue to build my plugin that swaps out the OsMemoryInfo service using reflection as a stopgap for Gradle 7, which would be a real pain (we're acutely feeling the pain of this issue atm).
There was a problem hiding this comment.
It's definitely possible. I'll see what we can do.
There was a problem hiding this comment.
Sorry to resurrect an old thread but was this ever backported? I can't find it in the release notes for 7.6.2 but just want to confirm.
There was a problem hiding this comment.
Unfortunately, this got lost in the noise and didn't get included in 7.6.2. I've made sure it's on the list to be included in 7.6.3.
That's very nice of you! I don't like to have my name on the internet so please list me as Thrillpool. |
|
@bot-gradle test and merge |
|
I've triggered a build for you. |
Supersedes #17628