Skip to content

8292989: Avoid dynamic memory in AsyncLogWriter #1630

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

Closed
wants to merge 2 commits into from

Conversation

navyxliu
Copy link
Member

@navyxliu navyxliu commented Jul 28, 2023

This patch is NOT a clean backport. The logic part is exactly the same, but I have to adjust code in the following parts:

  1. change from KVHashtable to ResourceHashtable because we want to use resourceArea instead of C_HEAP.
  2. rewrite lambda expression using Functor.

Testing:
jdk-test1 tests including gtest.
Manually check there's no malloc/free in runtime.


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
  • JDK-8292989 needs maintainer approval

Issue

  • JDK-8292989: Avoid dynamic memory in AsyncLogWriter (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk17u-dev.git pull/1630/head:pull/1630
$ git checkout pull/1630

Update a local copy of the PR:
$ git checkout pull/1630
$ git pull https://git.openjdk.org/jdk17u-dev.git pull/1630/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1630

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk17u-dev/pull/1630.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 28, 2023

👋 Welcome back xliu! 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 changed the title Backport bf79f99c0c61fc36b80cd8550e5c70e158338ef4 8292989: Avoid dynamic memory in AsyncLogWriter Jul 28, 2023
@openjdk
Copy link

openjdk bot commented Jul 28, 2023

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk bot added backport rfr Pull request is ready for review labels Jul 28, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 28, 2023

Webrevs

@openjdk
Copy link

openjdk bot commented Jul 28, 2023

@navyxliu This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 28, 2023
@phohensee
Copy link
Member

windows-aarch64 build failure running adlc appears unrelated.

@shipilev
Copy link
Member

shipilev commented Aug 1, 2023

Before I review the change, should https://bugs.openjdk.org/browse/JDK-8294075 be backported as well? Is JDK-8294075 caused by this change?

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.

Looked through the code, I have comments.

Comment on lines 61 to 63
using AsyncLogMap = ResourceHashtable<LogFileStreamOutput*, uint32_t, primitive_hash<LogFileStreamOutput*>,
primitive_equals<LogFileStreamOutput*>, 17,
ResourceObj::C_HEAP, mtLogging>;
Copy link
Member

Choose a reason for hiding this comment

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

These arguments should be on the new lines each, I think? This would match the upstream code better.

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, @shipilev
Do we have linter rules for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -184,11 +184,20 @@ class ResourceHashtable : public ResourceObj {
// the iteration is cancelled.
template<class ITER>
void iterate(ITER* iter) const {
auto function = [&] (K& k, V& v) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid doing this by making a named struct implementing do_entry for every use? I realize that would deviate the uses from the upstream, but we would not be changing the shared code, which would be safer for generic code that does not use any of async logging and uses older toolchains.

This hunk effectively backports https://bugs.openjdk.org/browse/JDK-8276789, which seems to imply the need to check this works well with different toolchains.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I can rewrite lambdas using old-style functor.

to backport JDK-8276789, we also need to backport bucket_at(), table()/table_size() beforehand. I take your advice. my approach skips more verification and it's not good. I will use functor.

@navyxliu
Copy link
Member Author

navyxliu commented Aug 1, 2023

Before I review the change, should https://bugs.openjdk.org/browse/JDK-8294075 be backported as well? Is JDK-8294075 caused by this change?

we found that it doesn't work. we still have intermittent failure.
https://bugs.openjdk.org/browse/JDK-8309067

@tstuefe
Copy link
Member

tstuefe commented Aug 5, 2023

Is it necessary to downport this patch? On its own, it does not sound that important, especially if we downport the glibc autotrimmer.

@navyxliu
Copy link
Member Author

navyxliu commented Aug 7, 2023

Hi, Thomas,

Thanks you for the comments. I was told that it is better reducing memory footprint of UL in jdk17u, a LTS Java. May I learn more about glibc autotrim? Is it a glibc feature or a new feature of hotspot?

I found JDK-8268893 on JBS. It itself is a very useful feature! It is not an automatic trimmer, is it?

@tstuefe
Copy link
Member

tstuefe commented Aug 7, 2023

Hi Xin :)

Hi, Thomas,

Thanks you for the comments. I was told that it is better reducing memory footprint of UL in jdk17u, a LTS Java.

Interesting, I'm curious about the effectiveness of your patch. Do you see good results? I would have thought that a lot of these interleaving memory requests are just taken from and handed back into fastbins or tcache, and therefore don't make the arena grow. Also, the glibc attempts to reclaim memory automatically are quite limited (see PR description openjdk/jdk#14781 (comment))

May I learn more about glibc autotrim? Is it a glibc feature or a new feature of hotspot?

I found JDK-8268893 on JBS. It itself is a very useful feature! It is not an automatic trimmer, is it?

Its https://bugs.openjdk.org/browse/JDK-8293114. You have to manually enable it, it is still marked as experimental. Also not in 17 yet, but Aleksey is preparing things to get it down quickly once it has baked in head a bit.

Essentially, what the trimmer does is run periodically a malloc_trim() operation. malloc_trim() will reclaim memory that has been free'd and that is in page granularity (so, it will also reclaim memory in the middle of an arena).

Cheers, Thomas

@shipilev
Copy link
Member

shipilev commented Aug 7, 2023

Is it necessary to downport this patch? On its own, it does not sound that important, especially if we downport the glibc autotrimmer.

I think that autotrimmer is a mitigation strategy for oversubscription, rather than a fix. it also does not resolve fragmentation issues, if there are surviving mallocs between temporarly async logging mallocs. In other words, it is more compelling to avoid the issue instead of relying on auto-trimmer. We use a lot of -Xlog:async in production, and this would give us additional safety against memory fragmentation/oversubscription at least with glibc.

@navyxliu
Copy link
Member Author

navyxliu commented Aug 9, 2023

hi, @tstuefe,

I think we need both of them. This patch refrains from using any malloc/free in the first place. It also helps avoid the fragmentation issue. Autotrimmer is a general solution for glibc overprovision.

Should we still consider to include this patch in jdk17u?

@tstuefe
Copy link
Member

tstuefe commented Aug 10, 2023

hi, @tstuefe,

I think we need both of them. This patch refrains from using any malloc/free in the first place. It also helps avoid the fragmentation issue. Autotrimmer is a general solution for glibc overprovision.

Should we still consider to include this patch in jdk17u?

I don't want to block this patch, so sure. I just would have liked to know what the strategy brings in terms of RSS. Plain curiousity.

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.

OK, this looks good, but I think we should fix/backport these two before backporting this one to 17u:
https://bugs.openjdk.org/browse/JDK-8297302 (fixed, should be backported)
https://bugs.openjdk.org/browse/JDK-8309067 (not fixed, should be dealt with first)

@navyxliu
Copy link
Member Author

https://bugs.openjdk.org/browse/JDK-8309067 (not fixed, should be dealt with first)

okay. I will work on JDK-8309067

@openjdk
Copy link

openjdk bot commented Sep 21, 2023

⚠️ @navyxliu This change is now ready for you to apply for maintainer approval. This can be done directly in each associated issue or by using the /approval command.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 21, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 19, 2023

@navyxliu This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 16, 2023

@navyxliu This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

4 participants