-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
8284950: CgroupV1 detection code should consider memory.swappiness #8285
Conversation
👋 Welcome back xpbob! A progress list of the required criteria for merging this PR into |
Webrevs
|
return retval > 0; | ||
long memswBytes = getLongValue(controller, "memory.memsw.limit_in_bytes"); | ||
long swappiness = getLongValue(controller, "memory.swappiness"); | ||
return (memswBytes > 0 && swappiness > 0); |
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.
Does this also need to be changed in the test?
jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java
Lines 291 to 296 in c63fabe
oldVal = metrics.getMemoryAndSwapLimit(); | |
newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes"); | |
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; | |
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { | |
fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal); | |
} |
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's also corresponding code in HotSpot:
jdk/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp
Lines 129 to 150 in c63fabe
jlong CgroupV1Subsystem::memory_and_swap_limit_in_bytes() { | |
GET_CONTAINER_INFO(julong, _memory->controller(), "/memory.memsw.limit_in_bytes", | |
"Memory and Swap Limit is: " JULONG_FORMAT, JULONG_FORMAT, memswlimit); | |
if (memswlimit >= _unlimited_memory) { | |
log_trace(os, container)("Non-Hierarchical Memory and Swap Limit is: Unlimited"); | |
CgroupV1MemoryController* mem_controller = reinterpret_cast<CgroupV1MemoryController*>(_memory->controller()); | |
if (mem_controller->is_hierarchical()) { | |
const char* matchline = "hierarchical_memsw_limit"; | |
const char* format = "%s " JULONG_FORMAT; | |
GET_CONTAINER_INFO_LINE(julong, _memory->controller(), "/memory.stat", matchline, | |
"Hierarchical Memory and Swap Limit is : " JULONG_FORMAT, format, hier_memlimit) | |
if (hier_memlimit >= _unlimited_memory) { | |
log_trace(os, container)("Hierarchical Memory and Swap Limit is: Unlimited"); | |
} else { | |
return (jlong)hier_memlimit; | |
} | |
} | |
return (jlong)-1; | |
} else { | |
return (jlong)memswlimit; | |
} | |
} |
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.
Does this also need to be changed in the test?
jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java
Lines 291 to 296 in c63fabe
oldVal = metrics.getMemoryAndSwapLimit(); newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes"); newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal); }
This condition returns false,The following code is skipped
if (metrics.getMemoryAndSwapLimit() > metrics.getMemoryLimit()) { |
Both the PR and the bug report are not clear about exactly what the problem is. Could you provide a test case that demonstrates the relationship between Ultimately we should add a new jtreg test case.
Related to your other PR (#8256), I think |
I changed the JBS issue summary to "CgroupV1 detection code should consider memory.swappiness" |
opts.addDockerOpts("--memory-swappiness", "0"); | ||
} else { | ||
opts.addDockerOpts("--memory-swappiness", "60"); |
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.
Unfortunately this breaks on a cgroups v2 system as --memory-swappiness
is not supported there. I'd prefer if this wouldn't piggy back on the existing test, but actually assert that swap is properly reported as the same as the memory limit if --memory-swappiness=0
. Also, this test only verifies the Java (core-libs) change, not the hotspot change. That would have to be done via some TestMisc
variant which uses print_container_info()
.
I refer to the content of this test
|
@@ -57,6 +57,7 @@ public static void main(String[] args) throws Exception { | |||
testIsContainerized(); | |||
testPrintContainerInfo(); | |||
testPrintContainerInfoActiveProcessorCount(); | |||
testPrintContainerMemoryInfo("100M", "150M"); |
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.
Again. This test runs unconditionally. --memory-swappiness
is not supported in cgroups v2. Thus, the test will fail on a cgroups v2 system. You need to only run this test on a cgroups v1 system. Have a look at test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java
how could could detect this and only run on cgroupv1
providers.
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.
On my cgroups v2 system (i.e. it's using 200m memory + 200m swap):
$ sudo docker run --rm -ti --memory-swappiness=0 --memory=200m fedora:35
WARNING: Your kernel does not support memory swappiness capabilities or the cgroup is not mounted. Memory swappiness discarded.
[root@fb3182c8e23c /]# cat /sys/fs/cgroup/memory.max
209715200
[root@fb3182c8e23c /]# cat /sys/fs/cgroup/memory.swap.max
209715200
Thanks for review. |
Thanks for review. |
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.
This looks much better. Thanks!
Common.addWhiteBoxOpts(opts); | ||
|
||
OutputAnalyzer out = Common.run(opts); | ||
System.out.println(out.getOutput()); |
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.
This looks like debug output?
System.out.println("TEST PASSED!!!"); | ||
return; | ||
} | ||
if ("cgroupv1".equals(metrics.getProvider())) { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Thanks for review. |
GET_CONTAINER_INFO(julong, _memory->controller(), "/memory.swappiness", | ||
"Swappiness is: " JULONG_FORMAT, JULONG_FORMAT, swappiness); | ||
if (swappiness == 0) { | ||
jlong memlimit = read_memory_limit_in_bytes(); | ||
log_trace(os, container)("Memory and Swap Limit has been reset to " JULONG_FORMAT " because swappiness is 0", memlimit); | ||
return memlimit; | ||
} |
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.
It now occurs to me that we'd need the same treatment of this on line 143
. Perhaps extract a function and call it in both places?
Thanks for review. |
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.
This looks good. I think the only thing missing is a test for the JDK side. Perhaps write one using the OperatingSystemMXBean
's getTotalSwapSpaceSize()
method within a container with --memory=200m --memory-swap=250m
and using --memory-swappiness=0
. You could use test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java
and CheckOperatingSystemMXBean.java
as a model. Again a cgroupsv1 specific test.
Thanks for review. |
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. Consider a better name for the test :)
.shouldContain("Memory & Swap Limit: " + expectedLimit); | ||
} | ||
|
||
private static void testOperatingSystemMXBeanAwareness(String memoryAllocation, String swapAllocation, |
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.
Please use a more telling name for this. Perhaps this? testOSBeanSwappinessMemory
.
@xpbob This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 414 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jerboaa, @iklam) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Thanks for review. |
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.
@iklam , are you also fine with the latest change? Thanks. |
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
/integrate |
/sponsor |
Going to push as commit 46d208f.
Your commit was automatically rebased without conflicts. |
@DamonFool @xpbob Pushed as commit 46d208f. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
set memory.swappiness to 0,swap space will not be used
determine the value of memory.swappiness
https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
=>
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8285/head:pull/8285
$ git checkout pull/8285
Update a local copy of the PR:
$ git checkout pull/8285
$ git pull https://git.openjdk.java.net/jdk pull/8285/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 8285
View PR using the GUI difftool:
$ git pr show -t 8285
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8285.diff