hongzhi-gao commented on code in PR #18848:
URL: https://github.com/apache/iotdb/pull/18848#discussion_r4290368146
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/memory/PrimitiveArrayManager.java:
##########
@@ -268,12 +283,45 @@ public static void release(Object array) {
ArrayDeque<Object> arrays = POOLED_ARRAYS[order];
if (arrays.size() < LIMITS[order]) {
arrays.add(array);
+ POOLED_ARRAY_BYTES[order] += arraySize(array);
} else {
StorageEngineMemoryMetrics.getInstance().incPamReleaseFailure();
}
}
}
+ public static IMemoryBlock getMemoryBlock() {
+ return POOLED_ARRAYS_MEMORY_BLOCK;
+ }
+
+ private static long getPooledArrayMemoryInBytes(int order) {
+ if (order == POOLED_ARRAYS.length) {
+ return 0;
+ }
+ // Hold every queue lock in ascending order for a linearizable total.
Borrow/return paths
+ // hold only one queue lock and never call this method or the memory
manager.
+ synchronized (POOLED_ARRAYS[order]) {
+ return POOLED_ARRAY_BYTES[order] + getPooledArrayMemoryInBytes(order +
1);
+ }
+ }
+
+ private static long arraySize(Object array) {
+ // Use typed array lengths on this hot path instead of reflective
shallowSizeOf(Object).
+ if (array instanceof long[]) {
+ return RamUsageEstimator.sizeOf((long[]) array);
+ } else if (array instanceof int[]) {
+ return RamUsageEstimator.sizeOf((int[]) array);
+ } else if (array instanceof boolean[]) {
+ return RamUsageEstimator.sizeOf((boolean[]) array);
+ } else if (array instanceof float[]) {
+ return RamUsageEstimator.sizeOf((float[]) array);
+ } else if (array instanceof double[]) {
+ return RamUsageEstimator.sizeOf((double[]) array);
+ }
+ // Binary[] entries have been cleared; only the shallow reference array
belongs to the pool.
+ return RamUsageEstimator.shallowSizeOf((Binary[]) array);
+ }
Review Comment:
Added cached typed size calculators indexed by TSDataType.serialize(),
matching POOLED_ARRAYS. Borrow/return now use the calculator for the selected
pool instead of repeating the instanceof chain to calculate its size. The
calculators still use the actual array length, and Binary[] accounting remains
shallow after clearing its elements. Added coverage for the supported types and
their primitive/Binary pool aliases; existing variable-length and concurrent
pool-accounting regressions also pass.
Implemented in
[f1945e5201](https://github.com/apache/iotdb/pull/18848/commits/f1945e52015f4d3b99ffc036b9c903592feb3f82).
--
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]