This is an automated email from the ASF dual-hosted git repository.
spricoder pushed a commit to branch feature/memory_collect
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/feature/memory_collect by this
push:
new 86111989f38 add name of MemoryManager and MemoryBlock
86111989f38 is described below
commit 86111989f38d59854e68495cdf9242ccdf9370b0
Author: spricoder <[email protected]>
AuthorDate: Thu Jan 16 16:19:39 2025 +0800
add name of MemoryManager and MemoryBlock
---
.../apache/iotdb/commons/memory/IMemoryBlock.java | 3 ++
.../apache/iotdb/commons/memory/MemoryBlock.java | 10 ++++--
.../apache/iotdb/commons/memory/MemoryManager.java | 37 ++++++++++++++--------
3 files changed, 34 insertions(+), 16 deletions(-)
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IMemoryBlock.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IMemoryBlock.java
index 92ccd40a772..642580d847b 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IMemoryBlock.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/IMemoryBlock.java
@@ -29,6 +29,9 @@ public abstract class IMemoryBlock implements AutoCloseable {
/** The reentrant lock of memory block */
protected final ReentrantLock lock = new ReentrantLock();
+ /** The name of this memory block */
+ protected String name;
+
/** The type of this memory block */
protected MemoryBlockType memoryBlockType;
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryBlock.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryBlock.java
index 98fe531db5e..2fbf02bec9b 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryBlock.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryBlock.java
@@ -27,16 +27,20 @@ import java.util.concurrent.TimeUnit;
public class MemoryBlock extends IMemoryBlock {
private static final Logger LOGGER =
LoggerFactory.getLogger(MemoryBlock.class);
- public MemoryBlock(final MemoryManager memoryManager, final long
maxMemorySizeInByte) {
+ public MemoryBlock(
+ final String name, final MemoryManager memoryManager, final long
maxMemorySizeInByte) {
+ this.name = name;
this.memoryManager = memoryManager;
this.maxMemorySizeInByte = maxMemorySizeInByte;
this.memoryBlockType = MemoryBlockType.NONE;
}
public MemoryBlock(
+ final String name,
final MemoryManager memoryManager,
final long maxMemorySizeInByte,
final MemoryBlockType memoryBlockType) {
+ this.name = name;
this.memoryManager = memoryManager;
this.maxMemorySizeInByte = maxMemorySizeInByte;
this.memoryBlockType = memoryBlockType;
@@ -50,7 +54,9 @@ public class MemoryBlock extends IMemoryBlock {
@Override
public String toString() {
return "IoTDBMemoryBlock{"
- + "memoryBlockType="
+ + "name="
+ + name
+ + ", memoryBlockType="
+ memoryBlockType
+ ", maxMemorySizeInByte="
+ maxMemorySizeInByte
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
index 86074ef1f70..30c991fe979 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/memory/MemoryManager.java
@@ -42,6 +42,9 @@ public class MemoryManager {
/** Min memory size to allocate */
private static final long MEMORY_ALLOCATE_MIN_SIZE_IN_BYTES = 32;
+ /** Name of memory manager */
+ private final String name;
+
/** Total memory size in byte of memory manager */
private long totalMemorySizeInBytes = 0L;
@@ -57,20 +60,22 @@ public class MemoryManager {
/** Allocated memory blocks of this memory manager */
private final Set<MemoryBlock> allocatedMemoryBlocks = new HashSet<>();
- public MemoryManager(MemoryManager parentMemoryManager, long
totalMemorySizeInBytes) {
+ public MemoryManager(
+ String name, MemoryManager parentMemoryManager, long
totalMemorySizeInBytes) {
+ this.name = name;
this.parentMemoryManager = parentMemoryManager;
this.parentMemoryManager.addChildMemoryManager(this);
this.totalMemorySizeInBytes = totalMemorySizeInBytes;
}
/** Try to force allocate memory block with specified size in bytes. */
- private MemoryBlock forceAllocate(long sizeInBytes, MemoryBlockType type) {
+ private MemoryBlock forceAllocate(String name, long sizeInBytes,
MemoryBlockType type) {
if (!ENABLED) {
- return new MemoryBlock(this, sizeInBytes, type);
+ return new MemoryBlock(name, this, sizeInBytes, type);
}
for (int i = 0; i < MEMORY_ALLOCATE_MAX_RETRIES; i++) {
if (totalMemorySizeInBytes - allocatedMemorySizeInBytes >= sizeInBytes) {
- return registerMemoryBlock(sizeInBytes, type);
+ return registerMemoryBlock(name, sizeInBytes, type);
}
try {
@@ -94,16 +99,17 @@ public class MemoryManager {
}
/** Try to force allocate memory block with specified size in bytes when
memory is sufficient. */
- public synchronized MemoryBlock forceAllocateIfSufficient(long sizeInBytes,
float usedThreshold) {
+ public synchronized MemoryBlock forceAllocateIfSufficient(
+ String name, long sizeInBytes, float usedThreshold) {
if (usedThreshold < 0.0f || usedThreshold > 1.0f) {
return null;
}
if (!ENABLED) {
- return new MemoryBlock(this, sizeInBytes);
+ return new MemoryBlock(name, this, sizeInBytes);
}
if (totalMemorySizeInBytes - allocatedMemorySizeInBytes >= sizeInBytes
&& (float) allocatedMemorySizeInBytes / totalMemorySizeInBytes <
usedThreshold) {
- return forceAllocate(sizeInBytes, MemoryBlockType.NONE);
+ return forceAllocate(name, sizeInBytes, MemoryBlockType.NONE);
} else {
// TODO @spricoder: consider to find more memory in active way
LOGGER.debug(
@@ -121,13 +127,16 @@ public class MemoryManager {
/** Try to allocate memory block with customAllocateStrategy */
public synchronized MemoryBlock tryAllocate(
- long sizeInBytes, LongUnaryOperator customAllocateStrategy,
MemoryBlockType type) {
+ String name,
+ long sizeInBytes,
+ LongUnaryOperator customAllocateStrategy,
+ MemoryBlockType type) {
if (!ENABLED) {
- return new MemoryBlock(this, sizeInBytes);
+ return new MemoryBlock(name, this, sizeInBytes);
}
if (totalMemorySizeInBytes - allocatedMemorySizeInBytes >= sizeInBytes) {
- return registerMemoryBlock(sizeInBytes, type);
+ return registerMemoryBlock(name, sizeInBytes, type);
}
long sizeToAllocateInBytes = sizeInBytes;
@@ -142,7 +151,7 @@ public class MemoryManager {
allocatedMemorySizeInBytes,
sizeInBytes,
sizeToAllocateInBytes);
- return registerMemoryBlock(sizeToAllocateInBytes, type);
+ return registerMemoryBlock(name, sizeToAllocateInBytes, type);
}
sizeToAllocateInBytes =
@@ -159,13 +168,13 @@ public class MemoryManager {
totalMemorySizeInBytes,
allocatedMemorySizeInBytes,
sizeInBytes);
- return registerMemoryBlock(0, type);
+ return registerMemoryBlock(name, 0, type);
}
/** Try to register memory block with specified size in bytes. */
- private MemoryBlock registerMemoryBlock(long sizeInBytes, MemoryBlockType
type) {
+ private MemoryBlock registerMemoryBlock(String name, long sizeInBytes,
MemoryBlockType type) {
allocatedMemorySizeInBytes += sizeInBytes;
- final MemoryBlock memoryBlock = new MemoryBlock(this, sizeInBytes, type);
+ final MemoryBlock memoryBlock = new MemoryBlock(name, this, sizeInBytes,
type);
allocatedMemoryBlocks.add(memoryBlock);
return memoryBlock;
}