99#include < Common/ProfileEvents.h>
1010#include < Common/formatReadable.h>
1111#include < Common/logger_useful.h>
12+ #include < Common/setThreadName.h>
1213
1314#include < fmt/ranges.h>
1415
@@ -303,6 +304,7 @@ uint64_t MemoryWorker::getMemoryUsage()
303304 return cgroups_reader != nullptr ? cgroups_reader->readMemoryUsage () : 0 ;
304305 case MemoryUsageSource::Jemalloc:
305306#if USE_JEMALLOC
307+ epoch_mib.setValue (0 );
306308 return resident_mib.getValue ();
307309#else
308310 return 0 ;
@@ -314,6 +316,8 @@ uint64_t MemoryWorker::getMemoryUsage()
314316
315317void MemoryWorker::backgroundThread ()
316318{
319+ setThreadName (" MemoryWorker" );
320+
317321 std::chrono::milliseconds chrono_period_ms{period_ms};
318322 [[maybe_unused]] bool first_run = true ;
319323 std::unique_lock lock (mutex);
@@ -325,11 +329,6 @@ void MemoryWorker::backgroundThread()
325329
326330 Stopwatch total_watch;
327331
328- #if USE_JEMALLOC
329- if (source == MemoryUsageSource::Jemalloc)
330- epoch_mib.setValue (0 );
331- #endif
332-
333332 Int64 resident = getMemoryUsage ();
334333 MemoryTracker::updateRSS (resident);
335334
@@ -350,19 +349,9 @@ void MemoryWorker::backgroundThread()
350349 // / - MemoryTracker stores a negative value
351350 // / - `correct_tracker` is set to true
352351 if (unlikely (first_run || total_memory_tracker.get () < 0 ))
353- {
354- if (source != MemoryUsageSource::Jemalloc)
355- epoch_mib.setValue (0 );
356-
357- MemoryTracker::updateAllocated (allocated_mib.getValue (), /* log_change=*/ true );
358- }
352+ MemoryTracker::updateAllocated (resident, /* log_change=*/ true );
359353 else if (correct_tracker)
360- {
361- if (source != MemoryUsageSource::Jemalloc)
362- epoch_mib.setValue (0 );
363-
364- MemoryTracker::updateAllocated (allocated_mib.getValue (), /* log_change=*/ false );
365- }
354+ MemoryTracker::updateAllocated (resident, /* log_change=*/ false );
366355#else
367356 // / we don't update in the first run if we don't have jemalloc
368357 // / because we can only use resident memory information
@@ -371,7 +360,6 @@ void MemoryWorker::backgroundThread()
371360 // / before MemoryTracker initialization
372361 if (unlikely (total_memory_tracker.get () < 0 ) || correct_tracker)
373362 MemoryTracker::updateAllocated (resident, /* log_change=*/ false );
374-
375363#endif
376364
377365 ProfileEvents::increment (ProfileEvents::MemoryWorkerRun);
0 commit comments