Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz committed Sep 20, 2023
1 parent d2c12e0 commit d517208
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ DEFINE_mBool(enable_query_memory_overcommit, "true");

DEFINE_mBool(disable_memory_gc, "false");

DEFINE_mInt64(large_memory_check_bytes, "1073741824");
DEFINE_mInt64(large_memory_check_bytes, "2147483648");

// The maximum time a thread waits for a full GC. Currently only query will wait for full gc.
DEFINE_mInt32(thread_wait_gc_max_milliseconds, "1000");
Expand Down
3 changes: 1 addition & 2 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ DECLARE_mBool(enable_query_memory_overcommit);
// default gc strategy is conservative, if you want to exclude the interference of gc, let it be true
DECLARE_mBool(disable_memory_gc);

// malloc or new large memory larger than large_memory_check_bytes and Doris Allocator is not used,
// malloc or new large memory larger than large_memory_check_bytes, default 2G,
// will print a warning containing the stacktrace, but not prevent memory alloc.
// large memory alloc looking forward to using Allocator.
DECLARE_mInt64(large_memory_check_bytes);

// The maximum time a thread waits for a full GC. Currently only query will wait for full gc.
Expand Down
2 changes: 1 addition & 1 deletion be/src/runtime/memory/mem_tracker_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ std::string MemTrackerLimiter::log_process_usage_str() {
std::vector<MemTracker::Snapshot> snapshots;
MemTrackerLimiter::make_process_snapshots(&snapshots);
MemTrackerLimiter::make_type_snapshots(&snapshots, MemTrackerLimiter::Type::GLOBAL);
MemTrackerLimiter::make_top_consumption_snapshots(&snapshots);
MemTrackerLimiter::make_top_consumption_snapshots(&snapshots, 15);

// Add additional tracker printed when memory exceeds limit.
snapshots.emplace_back(
Expand Down
2 changes: 1 addition & 1 deletion be/src/runtime/memory/mem_tracker_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MemTrackerLimiter final : public MemTracker {
static void make_process_snapshots(std::vector<MemTracker::Snapshot>* snapshots);
static void make_type_snapshots(std::vector<MemTracker::Snapshot>* snapshots, Type type);
static void make_top_consumption_snapshots(std::vector<MemTracker::Snapshot>* snapshots,
int top_num = 15);
int top_num);

static std::string log_usage(MemTracker::Snapshot snapshot);
std::string log_usage() { return log_usage(make_snapshot()); }
Expand Down
16 changes: 10 additions & 6 deletions be/src/runtime/memory/thread_mem_tracker_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "runtime/memory/mem_tracker.h"
#include "runtime/memory/mem_tracker_limiter.h"
#include "util/stack_util.h"
#include "util/uid_util.h"

namespace doris {

Expand Down Expand Up @@ -174,14 +175,17 @@ inline void ThreadMemTrackerMgr::consume(int64_t size, bool large_memory_check)
!_stop_consume) {
flush_untracked_mem();
}
// Large memory alloc should use allocator.h and catch std::bad_alloc
// Direct malloc or new large memory, unable to catch std::bad_alloc, BE may OOM.
if (large_memory_check && size > doris::config::large_memory_check_bytes) {

if (large_memory_check && doris::config::large_memory_check_bytes <= 0 &&
size > doris::config::large_memory_check_bytes) {
_stop_consume = true;
LOG(WARNING) << fmt::format(
"malloc or new large memory: {}, looking forward to using Allocator, this is just "
"a warning, not prevent memory alloc, stacktrace:\n{}",
size, get_stack_trace());
"malloc or new large memory: {}, {}, this is just a warning, not prevent memory "
"alloc, stacktrace:\n{}",
size,
is_attach_query() ? "in query or load: " + print_id(_fragment_instance_id)
: "not in query or load",
get_stack_trace());
_stop_consume = false;
}
}
Expand Down
8 changes: 0 additions & 8 deletions be/src/vec/common/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,13 @@ void Allocator<clear_memory_, mmap_populate, use_mmap>::throw_bad_alloc(

template <bool clear_memory_, bool mmap_populate, bool use_mmap>
void* Allocator<clear_memory_, mmap_populate, use_mmap>::alloc(size_t size, size_t alignment) {
if (doris::enable_thread_catch_bad_alloc) {
doris::thread_context()->large_memory_check = false;
}
DEFER({ doris::thread_context()->large_memory_check = true; });
return alloc_impl(size, alignment);
}

template <bool clear_memory_, bool mmap_populate, bool use_mmap>
void* Allocator<clear_memory_, mmap_populate, use_mmap>::realloc(void* buf, size_t old_size,
size_t new_size,
size_t alignment) {
if (doris::enable_thread_catch_bad_alloc) {
doris::thread_context()->large_memory_check = false;
}
DEFER({ doris::thread_context()->large_memory_check = true; });
return realloc_impl(buf, old_size, new_size, alignment);
}

Expand Down

0 comments on commit d517208

Please sign in to comment.