-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Workaround for JDK bug with total mem on Debian8 #68542
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,6 +254,71 @@ public void testCgroupProbeWithMissingMemory() { | |
assertNull(cgroup); | ||
} | ||
|
||
public void testGetTotalMemFromProcMeminfo() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add a test that does not stub out /proc/meminfo and verify that it gives us something > 0? It should run on debian 8 only. |
||
// missing MemTotal line | ||
var meminfoLines = Arrays.asList( | ||
"MemFree: 8467692 kB", | ||
"MemAvailable: 39646240 kB", | ||
"Buffers: 4699504 kB", | ||
"Cached: 23290380 kB", | ||
"SwapCached: 0 kB", | ||
"Active: 43637908 kB", | ||
"Inactive: 8130280 kB" | ||
); | ||
OsProbe probe = buildStubOsProbe(true, "", List.of(), meminfoLines); | ||
assertThat(probe.getTotalMemFromProcMeminfo(), equalTo(0L)); | ||
|
||
// MemTotal line with invalid value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us for completeness also add a case of having wrong unit. |
||
meminfoLines = Arrays.asList( | ||
"MemTotal: invalid kB", | ||
"MemFree: 8467692 kB", | ||
"MemAvailable: 39646240 kB", | ||
"Buffers: 4699504 kB", | ||
"Cached: 23290380 kB", | ||
"SwapCached: 0 kB", | ||
"Active: 43637908 kB", | ||
"Inactive: 8130280 kB" | ||
); | ||
probe = buildStubOsProbe(true, "", List.of(), meminfoLines); | ||
assertThat(probe.getTotalMemFromProcMeminfo(), equalTo(0L)); | ||
|
||
// MemTotal line with invalid unit | ||
meminfoLines = Arrays.asList( | ||
"MemTotal: 39646240 MB", | ||
"MemFree: 8467692 kB", | ||
"MemAvailable: 39646240 kB", | ||
"Buffers: 4699504 kB", | ||
"Cached: 23290380 kB", | ||
"SwapCached: 0 kB", | ||
"Active: 43637908 kB", | ||
"Inactive: 8130280 kB" | ||
); | ||
probe = buildStubOsProbe(true, "", List.of(), meminfoLines); | ||
assertThat(probe.getTotalMemFromProcMeminfo(), equalTo(0L)); | ||
|
||
// MemTotal line with random valid value | ||
long memTotalInKb = randomLongBetween(1, Long.MAX_VALUE / 1024L); | ||
meminfoLines = Arrays.asList( | ||
"MemTotal: " + memTotalInKb + " kB", | ||
"MemFree: 8467692 kB", | ||
"MemAvailable: 39646240 kB", | ||
"Buffers: 4699504 kB", | ||
"Cached: 23290380 kB", | ||
"SwapCached: 0 kB", | ||
"Active: 43637908 kB", | ||
"Inactive: 8130280 kB" | ||
); | ||
probe = buildStubOsProbe(true, "", List.of(), meminfoLines); | ||
assertThat(probe.getTotalMemFromProcMeminfo(), equalTo(memTotalInKb * 1024L)); | ||
} | ||
|
||
public void testGetTotalMemoryOnDebian8() throws Exception { | ||
// tests the workaround for JDK bug on debian8: https://github.com/elastic/elasticsearch/issues/67089#issuecomment-756114654 | ||
final OsProbe osProbe = new OsProbe(); | ||
assumeTrue("runs only on Debian 8", osProbe.isDebian8()); | ||
assertThat(osProbe.getTotalPhysicalMemorySize(), greaterThan(0L)); | ||
} | ||
|
||
private static List<String> getProcSelfGroupLines(String hierarchy) { | ||
return Arrays.asList( | ||
"10:freezer:/", | ||
|
@@ -282,12 +347,14 @@ private static OsProbe buildStubOsProbe(final boolean areCgroupStatsAvailable, f | |
* @param areCgroupStatsAvailable whether or not cgroup data is available. Normally OsProbe establishes this for itself. | ||
* @param hierarchy a mock value used to generate a cgroup hierarchy. | ||
* @param procSelfCgroupLines the lines that will be used as the content of <code>/proc/self/cgroup</code> | ||
* @param procMeminfoLines lines that will be used as the content of <code>/proc/meminfo</code> | ||
* @return a test instance | ||
*/ | ||
private static OsProbe buildStubOsProbe( | ||
final boolean areCgroupStatsAvailable, | ||
final String hierarchy, | ||
List<String> procSelfCgroupLines | ||
List<String> procSelfCgroupLines, | ||
List<String> procMeminfoLines | ||
) { | ||
return new OsProbe() { | ||
@Override | ||
|
@@ -338,6 +405,20 @@ String readSysFsCgroupMemoryUsageInBytes(String controlGroup) { | |
boolean areCgroupStatsAvailable() { | ||
return areCgroupStatsAvailable; | ||
} | ||
|
||
@Override | ||
List<String> readProcMeminfo() throws IOException { | ||
return procMeminfoLines; | ||
} | ||
}; | ||
} | ||
|
||
private static OsProbe buildStubOsProbe( | ||
final boolean areCgroupStatsAvailable, | ||
final String hierarchy, | ||
List<String> procSelfCgroupLines | ||
) { | ||
return buildStubOsProbe(areCgroupStatsAvailable, hierarchy, procSelfCgroupLines, List.of()); | ||
} | ||
|
||
} |
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'm not thrilled by everything that happens here, but by default, the value is cached so that this method shouldn't be called more than once per second and probably less frequently on systems with appropriate monitoring intervals.