-
Notifications
You must be signed in to change notification settings - Fork 3.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
HBASE-27445 fix the result of DirectMemoryUtils#getDirectMemorySize #4846
Conversation
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
@@ -85,7 +85,8 @@ public static long getDirectMemorySize() { | |||
RuntimeMXBean runtimemxBean = ManagementFactory.getRuntimeMXBean(); | |||
List<String> arguments = runtimemxBean.getInputArguments(); | |||
long multiplier = 1; // for the byte case. | |||
for (String s : arguments) { | |||
for (int i = arguments.size() - 1; i >= 0; i--) { |
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 method guarantee the order of the returned arguments?
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.
Thanks for reviewing Duo.
From what I see, the result is in order.
https://github.com/Tencent/TencentKona-8/blob/master/hotspot/src/share/vm/services/management.cpp#L545
💔 -1 overall
This message was automatically generated. |
I mean if there is a standard on this? The code of a specific jvm implementation is not stable, maybe other implementations will have different orders... If not, let's at least check the order for at least several commonly used jvm implementations, and also add comments in code to say that this is just our observation, not a standard. |
Really sorry for missing your reply here Duo. I didn't find related information in the jvm specification in https://docs.oracle.com/javase/specs/jvms/se8/html/ , so I guess there isn't ? I'll do the check and add some comments. Thanks for your reply Duo. |
Hi Duo I found that netty did some work about this. I did a simple test, it works for jdk8, jdk11 and jdk17. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
Hi, Duo, mind taking a look ? @Apache9 |
+1 since we have shaded netty. |
return retValue * multiplier; | ||
} | ||
try { | ||
Field directMemoryLimit = PlatformDependent.class.getDeclaredField("MAX_DIRECT_MEMORY"); |
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.
PlatformDependent.maxDirectMemory is enough?
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.
Thanks for reviewing Duo @Apache9
I think maybe we cannot. Here is the reason:
-
in the master branch, the hbase-thirdparty version is 4.1.2
https://github.com/apache/hbase/blob/master/pom.xml#L870 -
the the hbase-thirdparty 4.1.2, the netty version is 4.1.82.Final
https://github.com/apache/hbase-thirdparty/blob/230e5ebc432c2004b4ab744dca6627697f9f2a76/pom.xml#L135 -
in the netty 4.1.82.Final, the return value is DIRECT_MEMORY_LIMIT
https://github.com/netty/netty/blob/47799635143d7a11b56c4a4e9a1e65ca221d28ca/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L407
however, the value can be overrided if org.apache.hbase.thirdparty.io.netty.maxDirectMemory is set.
https://github.com/netty/netty/blob/47799635143d7a11b56c4a4e9a1e65ca221d28ca/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L179
So I think this API is not stable enough. That's the reason why I give up this.
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.
OK, on branch 4.1 it returns the netty limit. Should we provide a fallback way if netty one is avaiable?
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.
In both version , the meaning of MAX_DIRECT_MEMORY is the same, It represents the direct memory size that the JVM process can obtain. So I think the value of MAX_DIRECT_MEMORY is fine. Maybe there's no need to fallback ?
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.
We use reflection to get this field so it will not trigger a compilation error if netty changes this field in the future, so we can not find it when upgrading netty.
The estimateMaxDirectMemory method is public, so maybe we could just call it and store the return value by our own?
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.
Oh, in the old version, this method is private. Didn't notice it has been public now. Thanks for point it out.
You are right,this is better than reflection. I'll fix this. Thanks Duo.@Apache9
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
* @return the setting of -XX:MaxDirectMemorySize as a long. Returns 0 if -XX:MaxDirectMemorySize | ||
* is not set. | ||
*/ | ||
/** Returns the direct memory limit of the current progress */ | ||
public static long getDirectMemorySize() { |
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.
Will this method be called by multiple threads? Let's initialize it while loading the class?
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.
Currently not likely, so I make this lazily.
But I think you are right, it's better to evaluate it first. Pushed a new commit to address this. Thanks Duo. @Apache9
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
…pache#4846) Co-authored-by: huiruan <huiruan@tencent.com> Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 2f4758e) (cherry picked from commit a3ac3c5) Change-Id: Ic0711a7076e3bfad7fb35d40f33aaf82b22c77a2
…rySize (apache#4846)" This reverts commit bf84f6a. Change-Id: Ice546e5c31cb937cf9410f9c466ae2d7ad383810
…pache#4846) Co-authored-by: huiruan <huiruan@tencent.com> Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 2f4758e) (cherry picked from commit a3ac3c5) Change-Id: Ibe0d43401f3745d4ae6d399620ec55002f5effe7
No description provided.