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

8261023: Document why memory pretouch must be a store #2373

Closed
wants to merge 2 commits into from

Conversation

tschatzl
Copy link
Contributor

@tschatzl tschatzl commented Feb 3, 2021

Hi all,

may I have reviews for this additional comment that explains why os::pretouch_memory needs to use a store and must not use a read which would be more convenient?

Basically on some (all?) OSes memory pages are only actually backed with physical memory on a store to that page. Before that a common "zero page" may be used to satisfy reads. This is not what is intended here.

A previous comment (that has been removed long ago) seems to have been a bit confused about the actual issue:

-      // since the value read was unused, the optimizer removed the read.
-      // If we ever have a concurrent touchahead thread, we'll want to use
-      // a read, to avoid the potential of overwriting data (if a mutator
-      // thread beats the touchahead thread to a page).  There are various
-      // ways of making sure this read is not optimized away: for example,
-      // generating the code for a read procedure at runtime.

It indicates that the reason for using a store has been that the compiler would optimize away the reads (which begs the question why a volatile read has not been used).

Maybe these zero page optimizations came later than that original implementation though.

Testing: local compilation - it's adding a comment only, really.

Thanks,
Thomas


Progress

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

Issue

  • JDK-8261023: Document why memory pretouch must be a store

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2373/head:pull/2373
$ git checkout pull/2373

@tschatzl
Copy link
Contributor Author

tschatzl commented Feb 3, 2021

/label hotspot-gc

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 3, 2021

👋 Welcome back tschatzl! 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.

@tschatzl tschatzl marked this pull request as ready for review February 3, 2021 09:48
@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Feb 3, 2021
@openjdk
Copy link

openjdk bot commented Feb 3, 2021

@tschatzl
The hotspot-gc label was successfully added.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 3, 2021
@mlbridge
Copy link

mlbridge bot commented Feb 3, 2021

Webrevs

Copy link
Member

@shipilev shipilev 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. Bikeshedding suggestions below.

Comment on lines 1816 to 1819
// This must be a store due to OS optimizations like e.g. the Linux zero page
// optimization where only writes trigger actual backing of memory. Reads
// access a single shared zero page at first and so will not achieve the
// desired effect.
Copy link
Member

@shipilev shipilev Feb 3, 2021

Choose a reason for hiding this comment

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

Consider:

Note: this must be a store, not a load. On many OSes loads from the fresh memory would be
satisfied from a single mapped zero page. We need to store something to each page to get
them backed by their own memory, which is what we want as the effect here.

@openjdk
Copy link

openjdk bot commented Feb 3, 2021

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

8261023: Document why memory pretouch must be a store

Reviewed-by: shade, iwalulya

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

  • ae2c5f0: 8260581: IGV: enhance node search
  • 9037615: 8222850: jshell tool: Misleading cascade compiler error in switch expression with undefined vars
  • 91e6c75: 8260928: InitArrayShortSize constraint func should print a helpful error message
  • cb127a4: 8198343: Test java/awt/print/PrinterJob/TestPgfmtSetMPA.java may fail w/o printer
  • c008410: 8197825: [Test] Intermittent timeout with javax/swing JColorChooser Test
  • b9d4211: 8260193: Remove JVM_GetInterfaceVersion() and JVM_DTraceXXX
  • 98a7692: 8076313: GraphicsEnvironment does not detect changes in count of monitors on Linux OS
  • a47befc: 8260878: com/sun/jdi/JdbOptions.java fails without jfr
  • d423d36: 8258508: Merge G1RedirtyCardsQueue into qset
  • bec6043: 8259570: (macos) tools/jpackage tests fails with 'hdiutil: couldn't eject "disk2" - Resource busy'
  • ... and 11 more: https://git.openjdk.java.net/jdk/compare/288a4fed3f495e5bb83839564eda7d0c78751d21...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 3, 2021
Copy link
Member

@walulyai walulyai left a comment

Choose a reason for hiding this comment

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

lgtm!

@tschatzl tschatzl changed the title 8261023: Add comment why memory pretouch must be a store 8261023: Document why memory pretouch must be a store Feb 3, 2021
@tschatzl
Copy link
Contributor Author

tschatzl commented Feb 4, 2021

Thanks @shipilev @walulyai for your reviews.

/integrate

@openjdk openjdk bot closed this Feb 4, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 4, 2021
@openjdk
Copy link

openjdk bot commented Feb 4, 2021

@tschatzl Since your change was applied there have been 50 commits pushed to the master branch:

  • 83357b1: 8261030: Avoid loading GenerateJLIClassesHelper at runtime
  • 992b500: 8261036: Reduce classes loaded by CleanerFactory initialization
  • e8ad8b3: 8259956: jdk.jfr.internal.ChunkInputStream#available should return the sum of remaining available bytes
  • 06b33a0: 8261107: ArrayIndexOutOfBoundsException in the ICC_Profile.getInstance(InputStream)
  • 60f440d: 6436374: Graphics.setColor(null) is not documented
  • 82028e7: 8260012: Reduce inclusion of collectedHeap.hpp and heapInspection.hpp
  • 9b7a8f1: Merge
  • 1a7040e: 8259794: Remove EA from JDK 16 version string starting with Initial RC promotion on Feb 04, 2021(B35)
  • afd5eef: 8260704: ParallelGC: oldgen expansion needs release-store for _end
  • 081fa3e: 8260927: StringBuilder::insert is incorrect without Compact Strings
  • ... and 40 more: https://git.openjdk.java.net/jdk/compare/288a4fed3f495e5bb83839564eda7d0c78751d21...master

Your commit was automatically rebased without conflicts.

Pushed as commit be772ff.

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

@tschatzl tschatzl deleted the 8261023-comment-pretouch branch February 12, 2021 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated
3 participants