Skip to content
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

JDK-8281274: deal with ActiveProcessorCount in os::Linux::print_container_info #7354

Closed
wants to merge 5 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Feb 4, 2022

The function os::Linux::print_container_info outputs memory- and cpu-related container information (when running in a containerized environment).
However in the case of active processor count , it currently just outputs the info from OSContainer::active_processor_count without looking at ActiveProcessorCount that can be set to overwrite the OSContainer::active_processor_count() - information. This should be improved.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8281274: deal with ActiveProcessorCount in os::Linux::print_container_info

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7354/head:pull/7354
$ git checkout pull/7354

Update a local copy of the PR:
$ git checkout pull/7354
$ git pull https://git.openjdk.java.net/jdk pull/7354/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7354

View PR using the GUI difftool:
$ git pr show -t 7354

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7354.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 4, 2022

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 4, 2022
@openjdk
Copy link

openjdk bot commented Feb 4, 2022

@MBaesken The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Feb 4, 2022
@mlbridge
Copy link

mlbridge bot commented Feb 4, 2022

Webrevs

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine.

While looking at this I found that the default for ActiveProcessorCount is -1. The VM only reacts to this flag if it is >0. So, what is 0? The java man page is not saying. Maybe the default should just be 0 to be consistent.

@openjdk
Copy link

openjdk bot commented Feb 4, 2022

@MBaesken 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:

8281274: deal with ActiveProcessorCount in os::Linux::print_container_info

Reviewed-by: stuefe, sgehwolf, dholmes, iklam

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 39 new commits pushed to the master branch:

  • f924e50: 8281440: AWT: Conversion from string literal loses const qualifier
  • 072e7b4: 8272807: Permit use of memory concurrent with pretouch
  • cb2f8ca: 8281338: NSAccessibilityPressAction action for tree node and NSAccessibilityShowMenuAcgtion action not working
  • fc77217: 8281168: Micro-optimize VarForm.getMemberName for interpreter
  • bce5dd1: 8280438: Improve BufferNode::Allocator::release to avoid walking pending list
  • 13f739d: 8280830: Change NonblockingQueue::try_pop variable named "result"
  • 2f46af0: 8280132: Incorrect comparator com.sun.beans.introspect.MethodInfo.MethodOrder
  • fb17a8e: 8278947: Support for array constants in constant table
  • d658d94: 8280828: Improve invariants in NonblockingQueue::append
  • 5fb56db: 8281476: ProblemList tools/jar/CreateMissingParentDirectories.java
  • ... and 29 more: https://git.openjdk.java.net/jdk/compare/66b2c3b66e253ac3d8718c0c6d7c7551dbe04001...master

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 4, 2022
@@ -2174,7 +2174,12 @@ bool os::Linux::print_container_info(outputStream* st) {
int i = OSContainer::active_processor_count();
st->print("active_processor_count: ");
if (i > 0) {
st->print_cr("%d", i);
if (ActiveProcessorCount > 0) {
st->print_cr("%d, but overwritten by flag ActiveProcessorCount: %d",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will print the same number (processor count) twice. I'd suggest to only add a blurb like " overridden by -XX:ActiveProcessorCount" in case the flag is set and not print the blurb otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserting the new output in the jtreg test would be good to have too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format is fine me with me. You want to see both the container processor count and the actual count being used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Severin , I adjusted the output following your suggestion (David, in case ActiveProcessorCount is set on the command line it is printed as well , see Arguments::print_summary_on , probably that's why Severin does not want it here.
Regarding , whether other info we present can be overridden by flags, I think not in the container area (not sure about the whole hs_err output).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was wrong. I misread int i = OSContainer::active_processor_count(); for int i = os::active_processor_count(); which would then return the same value. As @dholmes-ora said, the original format was fine. Please add this in the test, though. Could be akin to test/hotspot/jtreg/containers/docker/TestMisc.testPrintContainerInfo(). I.e. set some CPU quota and also ActiveProcessorCount and assert the message in log output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was wrong. I misread int i = OSContainer::active_processor_count(); for int i = os::active_processor_count(); which would then return the same value. As @dholmes-ora said, the original format was fine. Please add this in the test, though. Could be akin to test/hotspot/jtreg/containers/docker/TestMisc.testPrintContainerInfo(). I.e. set some CPU quota and also ActiveProcessorCount and assert the message in log output.

Hi Severin, I adjusted the output again; also adjusted the jtreg test containers/docker/TestMisc .

Best regards, Matthias

Copy link
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure why it recorded my comment as "approval".

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me.

Does make me wonder whether other info we present can be overridden by flags.

Thanks,
David

@@ -2174,7 +2174,12 @@ bool os::Linux::print_container_info(outputStream* st) {
int i = OSContainer::active_processor_count();
st->print("active_processor_count: ");
if (i > 0) {
st->print_cr("%d", i);
if (ActiveProcessorCount > 0) {
st->print_cr("%d, but overwritten by flag ActiveProcessorCount: %d",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format is fine me with me. You want to see both the container processor count and the actual count being used.

@MBaesken
Copy link
Member Author

MBaesken commented Feb 7, 2022

Looks fine.

While looking at this I found that the default for ActiveProcessorCount is -1. The VM only reacts to this flag if it is >0. So, what is 0? The java man page is not saying. Maybe the default should just be 0 to be consistent.

Thanks for the review. Indeed only ActiveProcessorCount > 0 results in special handling, so 0 and -1 are both leading to the same runtime behavior.

@@ -86,7 +86,7 @@ private static void testIsContainerized() throws Exception {
private static void testPrintContainerInfo() throws Exception {
Common.logNewTestCase("Test print_container_info()");

DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");
DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo", "-XX:ActiveProcessorCount=2");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to separate this specific test. More like this:
jerboaa@3911ef8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this version of the test better. I'd rather separate concerns. The changes to Common aren't really needed, as Common.newOpts(imageName, "PrintContainerInfo").addJavaOpts("-XX:ActiveProcessorCount=2"); can be used instead. Similarly, the changes to checkContainerInfo() make the test harder to read. It's once called with a null argument and checks similar things, but one additional assert. Rather than that, I'd just do the assert directly in the new test as suggested. This saves the reader having to look up call-sites to know what the test is actually asserting. This also more closely matches what's likely to happen in real scenarios (override the container detection heuristics with -XX:ActiveProcessorCount).

@@ -71,6 +71,14 @@ public static DockerRunOptions newOpts(String imageNameAndTag, String testClass)
return opts;
}

public static DockerRunOptions newOpts(String imageNameAndTag, String testClass, String addJavaOpts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to avoid code duplication and just e.g. have the no-arg newOpts pass null for addJavaOpts.

@MBaesken
Copy link
Member Author

MBaesken commented Feb 8, 2022

Hi David and Severin, I added a separate test to TestMisc. Additionally I adjusted Common.java to avoid code duplication.
Thanks, Matthias

@@ -86,7 +86,7 @@ private static void testIsContainerized() throws Exception {
private static void testPrintContainerInfo() throws Exception {
Common.logNewTestCase("Test print_container_info()");

DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");
DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo", "-XX:ActiveProcessorCount=2");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this version of the test better. I'd rather separate concerns. The changes to Common aren't really needed, as Common.newOpts(imageName, "PrintContainerInfo").addJavaOpts("-XX:ActiveProcessorCount=2"); can be used instead. Similarly, the changes to checkContainerInfo() make the test harder to read. It's once called with a null argument and checks similar things, but one additional assert. Rather than that, I'd just do the assert directly in the new test as suggested. This saves the reader having to look up call-sites to know what the test is actually asserting. This also more closely matches what's likely to happen in real scenarios (override the container detection heuristics with -XX:ActiveProcessorCount).

Copy link
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MBaesken
Copy link
Member Author

MBaesken commented Feb 9, 2022

Hi Severin, indeed we can live without changing Common.java; adjusted the test.
Best regards, Matthias

@MBaesken
Copy link
Member Author

MBaesken commented Feb 9, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Feb 9, 2022

Going to push as commit bb2e10c.
Since your change was applied there have been 41 commits pushed to the master branch:

  • 69e390a: 8262721: Add Tests to verify single iteration loops are properly optimized
  • f092bab: 8281195: Mistakenly used logging causes significant overhead in interpreter
  • f924e50: 8281440: AWT: Conversion from string literal loses const qualifier
  • 072e7b4: 8272807: Permit use of memory concurrent with pretouch
  • cb2f8ca: 8281338: NSAccessibilityPressAction action for tree node and NSAccessibilityShowMenuAcgtion action not working
  • fc77217: 8281168: Micro-optimize VarForm.getMemberName for interpreter
  • bce5dd1: 8280438: Improve BufferNode::Allocator::release to avoid walking pending list
  • 13f739d: 8280830: Change NonblockingQueue::try_pop variable named "result"
  • 2f46af0: 8280132: Incorrect comparator com.sun.beans.introspect.MethodInfo.MethodOrder
  • fb17a8e: 8278947: Support for array constants in constant table
  • ... and 31 more: https://git.openjdk.java.net/jdk/compare/66b2c3b66e253ac3d8718c0c6d7c7551dbe04001...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 9, 2022
@openjdk openjdk bot closed this Feb 9, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 9, 2022
@openjdk
Copy link

openjdk bot commented Feb 9, 2022

@MBaesken Pushed as commit bb2e10c.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a single reviewer approved the final version of these changes so it may have been prudent to seek a least one additional re-review. I had it on my to-do list. :)

The updated test looks much cleaner and simpler.

Thanks,
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants