Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions be/src/common/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,21 @@ void Daemon::block_spill_gc_thread() {
}
}

void Daemon::je_purge_dirty_pages_thread() const {
do {
std::unique_lock<std::mutex> l(doris::MemInfo::je_purge_dirty_pages_lock);
while (_stop_background_threads_latch.count() != 0 &&
!doris::MemInfo::je_purge_dirty_pages_notify.load(std::memory_order_relaxed)) {
doris::MemInfo::je_purge_dirty_pages_cv.wait_for(l, std::chrono::seconds(1));
}
if (_stop_background_threads_latch.count() == 0) {
break;
}
doris::MemInfo::je_purge_all_arena_dirty_pages();
doris::MemInfo::je_purge_dirty_pages_notify.store(false, std::memory_order_relaxed);
} while (true);
}

void Daemon::start() {
Status st;
st = Thread::create(
Expand Down Expand Up @@ -381,6 +396,9 @@ void Daemon::start() {
st = Thread::create(
"Daemon", "block_spill_gc_thread", [this]() { this->block_spill_gc_thread(); },
&_threads.emplace_back());
st = Thread::create(
"Daemon", "je_purge_dirty_pages_thread",
[this]() { this->je_purge_dirty_pages_thread(); }, &_threads.emplace_back());
CHECK(st.ok()) << st;
}

Expand Down
1 change: 1 addition & 0 deletions be/src/common/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Daemon {
void memtable_memory_limiter_tracker_refresh_thread();
void calculate_metrics_thread();
void block_spill_gc_thread();
void je_purge_dirty_pages_thread() const;

CountDownLatch _stop_background_threads_latch;
std::vector<scoped_refptr<Thread>> _threads;
Expand Down
11 changes: 7 additions & 4 deletions be/src/util/mem_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int64_t MemInfo::_s_sys_mem_available_low_water_mark = -1;
int64_t MemInfo::_s_sys_mem_available_warning_water_mark = -1;
int64_t MemInfo::_s_process_minor_gc_size = -1;
int64_t MemInfo::_s_process_full_gc_size = -1;
std::mutex MemInfo::je_purge_dirty_pages_lock;
std::condition_variable MemInfo::je_purge_dirty_pages_cv;
std::atomic<bool> MemInfo::je_purge_dirty_pages_notify {false};

void MemInfo::refresh_allocator_mem() {
#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || defined(THREAD_SANITIZER)
Expand Down Expand Up @@ -129,7 +132,7 @@ bool MemInfo::process_minor_gc() {
std::string pre_sys_mem_available = MemInfo::sys_mem_available_str();

Defer defer {[&]() {
je_purge_all_arena_dirty_pages();
notify_je_purge_dirty_pages();
std::stringstream ss;
profile->pretty_print(&ss);
LOG(INFO) << fmt::format(
Expand All @@ -139,7 +142,7 @@ bool MemInfo::process_minor_gc() {
}};

freed_mem += CacheManager::instance()->for_each_cache_prune_stale(profile.get());
je_purge_all_arena_dirty_pages();
notify_je_purge_dirty_pages();
if (freed_mem > _s_process_minor_gc_size) {
return true;
}
Expand Down Expand Up @@ -180,7 +183,7 @@ bool MemInfo::process_full_gc() {
std::string pre_sys_mem_available = MemInfo::sys_mem_available_str();

Defer defer {[&]() {
je_purge_all_arena_dirty_pages();
notify_je_purge_dirty_pages();
std::stringstream ss;
profile->pretty_print(&ss);
LOG(INFO) << fmt::format(
Expand All @@ -190,7 +193,7 @@ bool MemInfo::process_full_gc() {
}};

freed_mem += CacheManager::instance()->for_each_cache_prune_all(profile.get());
je_purge_all_arena_dirty_pages();
notify_je_purge_dirty_pages();
if (freed_mem > _s_process_full_gc_size) {
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions be/src/util/mem_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdint.h>

#include <atomic>
#include <condition_variable>
#include <string>

#if !defined(__APPLE__) || !defined(_POSIX_C_SOURCE)
Expand Down Expand Up @@ -127,6 +128,14 @@ class MemInfo {
#endif
}

static std::mutex je_purge_dirty_pages_lock;
static std::condition_variable je_purge_dirty_pages_cv;
static std::atomic<bool> je_purge_dirty_pages_notify;
static void notify_je_purge_dirty_pages() {
je_purge_dirty_pages_notify.store(true, std::memory_order_relaxed);
je_purge_dirty_pages_cv.notify_all();
}

static inline size_t allocator_virtual_mem() {
return _s_virtual_memory_used.load(std::memory_order_relaxed);
}
Expand Down