This is an automated email from the ASF dual-hosted git repository.

zouxinyi pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
     new 6b89d47477 [fix](memtracker) Fix mem limit exceed return wrong format 
(#12139)
6b89d47477 is described below

commit 6b89d474773321372d3c5a4bc165099ef67f9cd1
Author: Xinyi Zou <[email protected]>
AuthorDate: Mon Aug 29 21:07:02 2022 +0800

    [fix](memtracker) Fix mem limit exceed return wrong format (#12139)
---
 be/src/runtime/memory/mem_tracker_limiter.cpp | 27 ++++++++++++---------------
 be/src/runtime/memory/mem_tracker_limiter.h   | 12 +++++-------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/be/src/runtime/memory/mem_tracker_limiter.cpp 
b/be/src/runtime/memory/mem_tracker_limiter.cpp
index 4078564041..1eb6166b9f 100644
--- a/be/src/runtime/memory/mem_tracker_limiter.cpp
+++ b/be/src/runtime/memory/mem_tracker_limiter.cpp
@@ -49,7 +49,8 @@ MemTrackerLimiter::MemTrackerLimiter(int64_t byte_limit, 
const std::string& labe
     MemTrackerLimiter* tracker = this;
     while (tracker != nullptr) {
         _all_ancestors.push_back(tracker);
-        if (tracker->has_limit()) _limited_ancestors.push_back(tracker);
+        if (tracker->has_limit() && tracker->label() != "Process")
+            _limited_ancestors.push_back(tracker);
         tracker = tracker->_parent.get();
     }
     DCHECK_GT(_all_ancestors.size(), 0);
@@ -149,7 +150,7 @@ bool MemTrackerLimiter::gc_memory(int64_t max_consumption) {
 Status MemTrackerLimiter::try_gc_memory(int64_t bytes) {
     if (UNLIKELY(gc_memory(_limit - bytes))) {
         return Status::MemoryLimitExceeded(fmt::format(
-                "failed_alloc_size={}Bytes, exceeded_tracker={}, limit={}B, 
peak_used={}B, "
+                "failed_alloc_size={}B, exceeded_tracker={}, limit={}B, 
peak_used={}B, "
                 "current_used={}B",
                 bytes, label(), _limit, _consumption->value(), 
_consumption->current_value()));
     }
@@ -255,17 +256,12 @@ void MemTrackerLimiter::print_log_usage(const 
std::string& msg) {
 Status MemTrackerLimiter::mem_limit_exceeded(const std::string& msg,
                                              int64_t failed_allocation_size) {
     STOP_CHECK_THREAD_MEM_TRACKER_LIMIT();
-    DCHECK(!_limited_ancestors.empty());
-    std::string detail = fmt::format("Memory limit exceeded, 
<consuming_tracker={}, ", _label);
-    if (failed_allocation_size != 0)
-        detail += fmt::format("failed_alloc_size={}Bytes, ",
-                              PrettyPrinter::print(failed_allocation_size, 
TUnit::BYTES));
+    std::string detail = fmt::format("Memory limit 
exceeded:<consuming_tracker={}, ", _label);
     MemTrackerLimiter* exceeded_tracker = nullptr;
     MemTrackerLimiter* max_consumption_tracker = nullptr;
     int64_t free_size = INT64_MAX;
     // Find the tracker that exceed limit and has the least free.
     for (const auto& tracker : _limited_ancestors) {
-        if (tracker->label() == "Process") continue;
         int64_t max_consumption = tracker->peak_consumption() > 
tracker->consumption()
                                           ? tracker->peak_consumption()
                                           : tracker->consumption();
@@ -283,19 +279,20 @@ Status MemTrackerLimiter::mem_limit_exceeded(const 
std::string& msg,
     MemTrackerLimiter* print_log_usage_tracker = nullptr;
     if (exceeded_tracker != nullptr) {
         detail += fmt::format(
-                "exceeded_tracker={}, limit={}B, peak_used={}B, 
current_used={}B>, "
-                "executing_msg:<{}>",
+                "failed_alloc_size={}B, exceeded_tracker={}, limit={}B, 
peak_used={}B, "
+                "current_used={}B>, executing_msg:<{}>",
+                PrettyPrinter::print(failed_allocation_size, TUnit::BYTES),
                 exceeded_tracker->label(), exceeded_tracker->limit(),
                 exceeded_tracker->peak_consumption(), 
exceeded_tracker->consumption(), msg);
         print_log_usage_tracker = exceeded_tracker;
     } else if (!sys_exceed_st) {
-        detail = fmt::format("Memory limit exceeded, {}, executing_msg:<{}>",
-                             sys_exceed_st.get_error_msg(), msg);
+        detail += fmt::format("{}>, executing_msg:<{}>", 
sys_exceed_st.get_error_msg(), msg);
     } else if (max_consumption_tracker != nullptr) {
         // must after check_sys_mem_info false
         detail += fmt::format(
-                "max_consumption_tracker={}, limit={}B, peak_used={}B, 
current_used={}B>, "
-                "executing_msg:<{}>",
+                "failed_alloc_size={}B, max_consumption_tracker={}, limit={}B, 
peak_used={}B, "
+                "current_used={}B>, executing_msg:<{}>",
+                PrettyPrinter::print(failed_allocation_size, TUnit::BYTES),
                 max_consumption_tracker->label(), 
max_consumption_tracker->limit(),
                 max_consumption_tracker->peak_consumption(), 
max_consumption_tracker->consumption(),
                 msg);
@@ -317,7 +314,7 @@ Status MemTrackerLimiter::mem_limit_exceeded(const 
std::string& msg,
                                              Status failed_try_consume_st) {
     STOP_CHECK_THREAD_MEM_TRACKER_LIMIT();
     std::string detail =
-            fmt::format("memory limit exceeded:<consuming_tracker={}, {}>, 
executing_msg:<{}>",
+            fmt::format("Memory limit exceeded:<consuming_tracker={}, {}>, 
executing_msg:<{}>",
                         _label, failed_try_consume_st.get_error_msg(), msg);
     auto st = MemTrackerLimiter::mem_limit_exceeded_construct(detail);
     failed_tracker->print_log_usage(st.get_error_msg());
diff --git a/be/src/runtime/memory/mem_tracker_limiter.h 
b/be/src/runtime/memory/mem_tracker_limiter.h
index 1933a15fc5..275e52375e 100644
--- a/be/src/runtime/memory/mem_tracker_limiter.h
+++ b/be/src/runtime/memory/mem_tracker_limiter.h
@@ -64,16 +64,15 @@ public:
                        size_t upper_level) const;
 
 public:
-    Status check_sys_mem_info(int64_t bytes) {
+    static Status check_sys_mem_info(int64_t bytes) {
         // Limit process memory usage using the actual physical memory of the 
process in `/proc/self/status`.
         // This is independent of the consumption value of the mem tracker, 
which counts the virtual memory
         // of the process malloc.
         // for fast, expect MemInfo::initialized() to be true.
         if (PerfCounters::get_vm_rss() + bytes >= MemInfo::mem_limit()) {
             auto st = Status::MemoryLimitExceeded(
-                    fmt::format("Memory limit exceeded, process memory used {} 
exceed limit {}, "
-                    "consuming_tracker={}, failed_alloc_size={}",
-                    PerfCounters::get_vm_rss(), MemInfo::mem_limit(), _label, 
bytes));
+                    fmt::format("process memory used {} exceed limit {}, 
failed_alloc_size={}",
+                    PerfCounters::get_vm_rss(), MemInfo::mem_limit(), bytes));
             
ExecEnv::GetInstance()->new_process_mem_tracker()->print_log_usage(st.get_error_msg());
             return st;
         }
@@ -212,7 +211,7 @@ private:
 
     // this tracker limiter plus all of its ancestors
     std::vector<MemTrackerLimiter*> _all_ancestors;
-    // _all_ancestors with valid limits
+    // _all_ancestors with valid limits, except process tracker
     std::vector<MemTrackerLimiter*> _limited_ancestors;
 
     // Consume size smaller than mem_tracker_consume_min_size_bytes will 
continue to accumulate
@@ -284,7 +283,7 @@ inline Status MemTrackerLimiter::try_consume(int64_t bytes) 
{
         MemTrackerLimiter* tracker = _all_ancestors[i];
         // Process tracker does not participate in the process memory limit, 
process tracker consumption is virtual memory,
         // and there is a diff between the real physical memory value of the 
process. It is replaced by check_sys_mem_info.
-        if (tracker->limit() < 0 || _label == "Process") {
+        if (tracker->limit() < 0 || tracker->label() == "Process") {
             tracker->_consumption->add(bytes); // No limit at this tracker.
         } else {
             // If TryConsume fails, we can try to GC, but we may need to try 
several times if
@@ -317,7 +316,6 @@ inline Status MemTrackerLimiter::check_limit(int64_t bytes) 
{
         MemTrackerLimiter* tracker = _limited_ancestors[i];
         // Process tracker does not participate in the process memory limit, 
process tracker consumption is virtual memory,
         // and there is a diff between the real physical memory value of the 
process. It is replaced by check_sys_mem_info.
-        if (tracker->label() == "Process") continue;
         while (true) {
             if (LIKELY(tracker->_consumption->current_value() + bytes < 
tracker->limit())) break;
             RETURN_IF_ERROR(tracker->try_gc_memory(bytes));


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

Reply via email to