Skip to content

8380103: Perfdata shared memory file flock failures#30537

Open
caspernorrbin wants to merge 2 commits intoopenjdk:masterfrom
caspernorrbin:perfdata-flock-race
Open

8380103: Perfdata shared memory file flock failures#30537
caspernorrbin wants to merge 2 commits intoopenjdk:masterfrom
caspernorrbin:perfdata-flock-race

Conversation

@caspernorrbin
Copy link
Copy Markdown
Member

@caspernorrbin caspernorrbin commented Apr 1, 2026

Hi everyone,

The existing posix hsperfdata logic has a potential race between stale-file cleanup and new file creation. During startup, a JVM first scans the hsperfdata directory and cleans up old files before creating its own file. While one JVM is scanning the directory and probing pid files to decide whether they are stale, another JVM may already have created its own file but not yet acquired the flock on it. Because ownership is established with an open followed by a flock, the cleanup path can briefly win that race on a freshly created file and cause the creating JVM to fail its own flock. The same locking protocol is also used to distinguish stale files from live JVMs in other pid namespaces when multiple containers share the same /tmp.

To reduce this race window, I have made the cleanup path more conservative with file removals, and the startup path more tolerant of collisions. The cleanup sweep now checks file modification time and avoids touching files that were recently modified, so we do not try to flock and remove files that are likely still in use or have just been created. In addition, if create_sharedmem_file() loses the initial flock with EWOULDBLOCK, it now retries a small number of times with a short delay before giving up, which gives a concurrent cleanup JVM time to release the lock.

Together these changes make the race much less likely to affect startup. Files that were just created are left out of the cleanup sweep, and even if they were to get probed, the creating JVM would still eventually get to flock it. If a stale file that should have been removed isn't, it is still going to get cleaned up eventually with the next JVM start. I also updated the ShareTmpDir.java test, as with these changes we do not try and remove the file, which results in a different log output.

Testing:

  • Oracle tiers 1-5
  • Multiple Oracle tiers 1-5 on linux with extra asserts added to ensure we can always create and flock the hsperfdata file

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8380103: Perfdata shared memory file flock failures (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30537/head:pull/30537
$ git checkout pull/30537

Update a local copy of the PR:
$ git checkout pull/30537
$ git pull https://git.openjdk.org/jdk.git pull/30537/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30537

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30537.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 1, 2026

👋 Welcome back cnorrbin! 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
Copy link
Copy Markdown

openjdk bot commented Apr 1, 2026

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

8380103: Perfdata shared memory file flock failures

Reviewed-by: dholmes, aartemov

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

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 changed the title 8380103 8380103: Perfdata shared memory file flock failures Apr 1, 2026
@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Apr 1, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 1, 2026

@caspernorrbin 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 rfr Pull request is ready for review label Apr 1, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 1, 2026

Webrevs

Copy link
Copy Markdown
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.

This seems quite reasonable to me. Thanks for fixing this nuisance issue.

One minor suggestion below, and one issue in the test.

Comment on lines +141 to +142
out2.getStdout().contains(s2) ||
out2.getStdout().contains(s2));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should one of those be out1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes it definitely should! Fixed now. The reason it worked is because out2 is from the second process which is almost always the one that contains the output.

// still be starting up and are therefore not candidates for stale-file
// cleanup. This avoids racing a concurrent JVM startup while scanning the
// hsperfdata directory.
static const time_t cleanup_grace_period_seconds = 5;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A drive-by comment, how did you determine this value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Very arbitrarily. It could probably be a bit lower, but I wanted to give a bit of a buffer in case some weird behaviour happens when we start a lot of VMs concurrently.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand that, so by the log message if needed we'll be able to tell if it sufficient in most cases. If nothing pops up, then yes.

Copy link
Copy Markdown
Contributor

@toxaart toxaart left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
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.

Thanks for the updates.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 2, 2026
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 ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants