This commit is contained in:
Antonio Andelic 2024-07-25 08:45:08 +02:00
parent e2e4c8ee0f
commit f449c2fea0
4 changed files with 11 additions and 7 deletions

View File

@ -120,6 +120,11 @@ public:
return amount.load(std::memory_order_relaxed);
}
Int64 getRSS() const
{
return rss.load(std::memory_order_relaxed);
}
// Merges and mutations may pass memory ownership to other threads thus in the end of execution
// MemoryTracker for background task may have a non-zero counter.
// This method is intended to fix the counter inside of background_memory_tracker.

View File

@ -312,7 +312,7 @@ uint64_t MemoryWorker::getMemoryUsage()
void MemoryWorker::backgroundThread()
{
std::chrono::milliseconds chrono_period_ms{period_ms};
bool first_run = true;
[[maybe_unused]] bool first_run = true;
std::unique_lock lock(mutex);
while (true)
{
@ -340,17 +340,15 @@ void MemoryWorker::backgroundThread()
}
#endif
#if USE_JEMALLOC
if (unlikely(first_run || total_memory_tracker.get() < 0))
{
#if USE_JEMALLOC
if (source != MemoryUsageSource::Jemalloc)
epoch_mib.setValue(0);
MemoryTracker::updateAllocated(allocated_mib.getValue());
#elif defined(OS_LINUX)
MemoryTracker::updateAllocated(resident);
#endif
}
#endif
ProfileEvents::increment(ProfileEvents::MemoryWorkerRun);
ProfileEvents::increment(ProfileEvents::MemoryWorkerRunElapsedMicroseconds, total_watch.elapsedMicroseconds());

View File

@ -150,10 +150,11 @@ void KeeperDispatcher::requestThread()
{
LOG_WARNING(
log,
"Processing requests refused because of max_memory_usage_soft_limit {}, the total used memory is {}, request type "
"Processing requests refused because of max_memory_usage_soft_limit {}, the total allocated memory is {}, RSS is {}, request type "
"is {}",
ReadableSize(mem_soft_limit),
ReadableSize(total_memory_tracker.get()),
ReadableSize(total_memory_tracker.getRSS()),
request.request->getOpNum());
addErrorResponses({request}, Coordination::Error::ZCONNECTIONLOSS);
continue;

View File

@ -599,7 +599,7 @@ bool KeeperServer::isLeaderAlive() const
bool KeeperServer::isExceedingMemorySoftLimit() const
{
Int64 mem_soft_limit = keeper_context->getKeeperMemorySoftLimit();
return mem_soft_limit > 0 && total_memory_tracker.get() >= mem_soft_limit;
return mem_soft_limit > 0 && std::max(total_memory_tracker.get(), total_memory_tracker.getRSS()) >= mem_soft_limit;
}
/// TODO test whether taking failed peer in count