xinyiZzz commented on code in PR #52553:
URL: https://github.com/apache/doris/pull/52553#discussion_r2176361079


##########
be/src/vec/common/pod_array.h:
##########
@@ -174,15 +177,26 @@ class PODArrayBase : private boost::noncopyable,
         static_assert(!TAllocator::need_check_and_tracking_memory(),
                       "TAllocator should specify 
`NoTrackingDefaultMemoryAllocator`");
         if (UNLIKELY(c_end_new - c_res_mem > 0)) {
+            // 1. if (capacity_size / PRE_GROWTH_RATIO) <= PRE_MIN_GROWTH_SIZE:
             // - allocated_bytes = c_end_of_storage - c_start = 4 MB;
             // - used_bytes = c_end_new - c_start = 2.1 MB;
             // - last tracking_res_memory = c_res_mem - c_start = 1 MB;
-            // - res_mem_growth = min(allocated_bytes, 
integerRoundUp(used_bytes)) - last_tracking_res_memory = 3 - 1 = 2 MB;
+            // - res_mem_growth = min(allocated_bytes, 
integerRoundUp(used_bytes, 1M)) - last_tracking_res_memory = 3 - 1 = 2 MB;
             // - update tracking_res_memory = 1 + 2 = 3 MB;
             // so after each reset_resident_memory, tracking_res_memory >= 
used_bytes;
+            //
+            // 2. if (capacity_size / PRE_GROWTH_RATIO) > PRE_MIN_GROWTH_SIZE:
+            // - allocated_bytes = c_end_of_storage - c_start = 1024 MB;
+            // - used_bytes = c_end_new - c_start = 210 MB;
+            // - last tracking_res_memory = c_res_mem - c_start = 102 MB;
+            // - res_mem_growth = min(allocated_bytes, 
integerRoundUp(used_bytes, 102M)) - last_tracking_res_memory = 306 - 102 = 204 
MB;
+            // - update tracking_res_memory = 102 + 204 = 306 MB;
+
+            auto capacity_size = static_cast<size_t>(c_end_of_storage - 
c_start);
+            auto min_growth_size = std::max(static_cast<size_t>(capacity_size 
/ PRE_GROWTH_RATIO),
+                                            PRE_MIN_GROWTH_SIZE);
             int64_t res_mem_growth =
-                    std::min(static_cast<size_t>(c_end_of_storage - c_start),
-                             integerRoundUp(c_end_new - c_start, 
PRE_GROWTH_SIZE)) -
+                    std::min(capacity_size, integerRoundUp(c_end_new - 
c_start, min_growth_size)) -

Review Comment:
   向上取整到 min_growth_size 的整数倍,min_growth_size = max(1M, capacity / 10)
   
   比如 used 了 10K,实际会 tracking 1M,那么接下来若干次 use 都不会再次 tracking,直到 used 超过 1M 后再 
tracking 到 2M,所以 tracking 会一直比实际 used 大一点。
   
   这个 pr 改动后会再次降低 tracking 频率



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to