SpriCoder commented on code in PR #14710:
URL: https://github.com/apache/iotdb/pull/14710#discussion_r1981326247
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java:
##########
@@ -471,6 +487,121 @@ public long getUsedMemorySizeInBytes() {
return memorySize;
}
+ /** Get static allocated memory size in bytes of memory manager */
+ public long getStaticAllocatedMemorySizeInBytes() {
+ long memorySize = staticAllocatedMemorySizeInBytes;
+ for (MemoryManager child : children.values()) {
+ memorySize += child.getStaticAllocatedMemorySizeInBytes();
+ }
+ return memorySize;
+ }
+
+ /** Get used memory ratio */
+ public double getUsedMemoryRatio() {
+ return (double) getUsedMemorySizeInBytes() / totalMemorySizeInBytes;
+ }
+
+ // endregion
+
+ // region auto adapt memory
+ /**
+ * Whether this memory manager is available to shrink
+ *
+ * @return true if available to shrink, otherwise false
+ */
+ public boolean isAvailableToShrink() {
+ return totalAllocatedMemorySizeInBytes - totalMemorySizeInBytes
+ < totalAllocatedMemorySizeInBytes / 10
+ && totalMemorySizeInBytes != allocatedMemorySizeInBytes;
+ }
+
+ /**
+ * Try to shrink this memory manager
+ *
+ * @return actual shrink size
+ */
+ public synchronized long shrink() {
+ long shrinkSize =
+ Math.min(
+ getAvailableMemorySizeInBytes() / 10,
+ totalMemorySizeInBytes - totalAllocatedMemorySizeInBytes * 9 / 10);
+ totalMemorySizeInBytes -= shrinkSize;
+ return shrinkSize;
+ }
+
+ /**
+ * Whether this memory manager is available to expand. If there are one
child memory manager or
+ * memory block available to expand, return true.
+ *
+ * @return true if available to expand, otherwise false
+ */
+ public boolean isAvailableToExpand() {
+ for (MemoryManager memoryManager : children.values()) {
+ if (memoryManager.isAvailableToExpand()) {
+ return true;
+ }
+ }
+ for (IMemoryBlock memoryBlock : allocatedMemoryBlocks.values()) {
+ if (memoryBlock.getMemoryBlockType() != MemoryBlockType.STATIC) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public double getScore() {
+ return getUsedMemoryRatio();
+ }
Review Comment:
Sorry, it's my mistake and this method is not for this pr
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]