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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


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

commit 09b8d32421c2dc5b899d020fdc7c670b370c569c
Author: Xinyi Zou <zouxiny...@gmail.com>
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 | 29 ++++++++++++---------------
 be/src/runtime/memory/mem_tracker_limiter.h   | 12 +++++------
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/be/src/runtime/memory/mem_tracker_limiter.cpp 
b/be/src/runtime/memory/mem_tracker_limiter.cpp
index 87a49eedce..13e888959a 100644
--- a/be/src/runtime/memory/mem_tracker_limiter.cpp
+++ b/be/src/runtime/memory/mem_tracker_limiter.cpp
@@ -50,7 +50,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);
@@ -150,7 +151,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()));
     }
@@ -227,7 +228,7 @@ std::string MemTrackerLimiter::log_usage(int 
max_recursive_depth,
 
 Status MemTrackerLimiter::mem_limit_exceeded_construct(const std::string& msg) 
{
     std::string detail = fmt::format(
-            "{}, backend {} process memory used {}Bytes, process limit {}B. If 
is query, can "
+            "{}, backend {} process memory used {}, process limit {}. If is 
query, can "
             "change the limit "
             "by `set exec_mem_limit=xxx`, details mem usage see be.INFO.",
             msg, BackendOptions::get_localhost(),
@@ -257,17 +258,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();
@@ -285,19 +281,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);
@@ -319,7 +316,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 3aaa9d973f..65506964a8 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(
-                    "Memory limit exceeded, process memory used {}Bytes exceed 
limit {}B, "
-                    "consuming_tracker={}, failed_alloc_size={}",
-                    PerfCounters::get_vm_rss(), MemInfo::mem_limit(), _label, 
bytes);
+                    "process memory used {} exceed limit {}, 
failed_alloc_size={}",
+                    PerfCounters::get_vm_rss(), MemInfo::mem_limit(), bytes);
             
ExecEnv::GetInstance()->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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to