@@ -67,9 +67,6 @@ ABSL_FLAG(double, eviction_memory_budget_threshold, 0.1,
67
67
" Eviction starts when the free memory (including RSS memory) drops below "
68
68
" eviction_memory_budget_threshold * max_memory_limit." );
69
69
70
- ABSL_FLAG (uint64_t , force_decommit_threshold, 8_MB,
71
- " The threshold of memory to force decommit when memory is under pressure." );
72
-
73
70
ABSL_DECLARE_FLAG (uint32_t , max_eviction_per_heartbeat);
74
71
75
72
namespace dfly {
@@ -325,41 +322,55 @@ bool EngineShard::DefragTaskState::CheckRequired() {
325
322
return false ;
326
323
}
327
324
328
- std::optional<ShardMemUsage> shard_mem_usage;
329
-
330
- if (GetFlag (FLAGS_enable_heartbeat_eviction)) {
331
- shard_mem_usage = ReadShardMemUsage (GetFlag (FLAGS_mem_defrag_page_utilization_threshold));
332
- const static double eviction_waste_threshold = 0.05 ;
333
- if (shard_mem_usage->wasted_mem >
334
- (uint64_t (shard_mem_usage->commited * eviction_waste_threshold))) {
335
- VLOG (1 ) << " memory issue found for memory " << shard_mem_usage.value ();
336
- return true ;
337
- }
338
- }
339
-
340
- const std::size_t global_threshold = max_memory_limit * GetFlag (FLAGS_mem_defrag_threshold);
325
+ /*
326
+ If the eviction is enabled, we want to run the defrag task more frequently and more aggressively.
327
+ For global threshold rss we use the rss memory minus the eviction budget threshold and minus 3%
328
+ - For example if rss_deny_oom_ratio is 0.8 and eviction_memory_budget_threshold is 0.1,
329
+ we will start eviction when rss memory is above 0.8 - 0.1 = 0.7. And defragmentation
330
+ should still working if used rss memory is above 0.7 - 0.03 = 0.67.
331
+ For defrag interval we use the EvictionTaskState::kMemDefragCheckSecInterval
332
+ For waste threshold we use the EvictionTaskState::kEvictionWasteThreshold
333
+ */
334
+ const bool is_eviction_enabled = GetFlag (FLAGS_enable_heartbeat_eviction);
335
+
336
+ const double mem_defrag_threshold_flag = GetFlag (FLAGS_mem_defrag_threshold);
337
+ const double defrag_threshold =
338
+ !is_eviction_enabled ? mem_defrag_threshold_flag
339
+ : std::min (mem_defrag_threshold_flag,
340
+ ServerState::tlocal ()->rss_oom_deny_ratio -
341
+ GetFlag (FLAGS_eviction_memory_budget_threshold) -
342
+ EvictionTaskState::kDefragRssMemoryDelta );
343
+
344
+ const std::size_t global_threshold = max_memory_limit * defrag_threshold;
341
345
if (global_threshold > rss_mem_current.load (memory_order_relaxed)) {
342
346
return false ;
343
347
}
344
348
345
349
const auto now = time (nullptr );
346
350
const auto seconds_from_prev_check = now - last_check_time;
347
- const auto mem_defrag_interval = GetFlag (FLAGS_mem_defrag_check_sec_interval);
351
+
352
+ const uint32_t check_sec_interval_flag = GetFlag (FLAGS_mem_defrag_check_sec_interval);
353
+ const auto mem_defrag_interval =
354
+ !is_eviction_enabled
355
+ ? check_sec_interval_flag
356
+ : std::min (check_sec_interval_flag, EvictionTaskState::kDefragCheckSecInterval );
348
357
349
358
if (seconds_from_prev_check < mem_defrag_interval) {
350
359
return false ;
351
360
}
352
- last_check_time = now;
353
361
354
- if (!shard_mem_usage) {
355
- shard_mem_usage = ReadShardMemUsage (GetFlag (FLAGS_mem_defrag_page_utilization_threshold));
356
- }
362
+ last_check_time = now;
357
363
358
- DCHECK (shard_mem_usage.has_value ());
364
+ ShardMemUsage shard_mem_usage =
365
+ ReadShardMemUsage (GetFlag (FLAGS_mem_defrag_page_utilization_threshold));
359
366
360
- const double waste_threshold = GetFlag (FLAGS_mem_defrag_waste_threshold);
361
- if (shard_mem_usage->wasted_mem > (uint64_t (shard_mem_usage->commited * waste_threshold))) {
362
- VLOG (1 ) << " memory issue found for memory " << shard_mem_usage.value ();
367
+ const float waste_threshold_flag = GetFlag (FLAGS_mem_defrag_waste_threshold);
368
+ const double waste_threshold =
369
+ !is_eviction_enabled
370
+ ? waste_threshold_flag
371
+ : std::min (waste_threshold_flag, EvictionTaskState::kDefragWasteThreshold );
372
+ if (shard_mem_usage.wasted_mem > (uint64_t (shard_mem_usage.commited * waste_threshold))) {
373
+ VLOG (1 ) << " memory issue found for memory " << shard_mem_usage;
363
374
return true ;
364
375
}
365
376
@@ -858,7 +869,7 @@ size_t EngineShard::CalculateEvictionBytes() {
858
869
size_t goal_bytes = CalculateHowManyBytesToEvictOnShard (max_memory_limit, global_used_memory,
859
870
shard_memory_budget_threshold);
860
871
861
- LOG_IF_EVERY_N (INFO , goal_bytes > 0 , 50 )
872
+ VLOG_IF_EVERY_N ( 1 , goal_bytes > 0 , 50 )
862
873
<< " Memory goal bytes: " << goal_bytes << " , used memory: " << global_used_memory
863
874
<< " , memory limit: " << max_memory_limit;
864
875
@@ -889,7 +900,7 @@ size_t EngineShard::CalculateEvictionBytes() {
889
900
max_rss_memory, global_used_rss_memory - deleted_bytes_before_rss_update * shards_count,
890
901
shard_rss_memory_budget_threshold);
891
902
892
- LOG_IF_EVERY_N (INFO , rss_goal_bytes > 0 , 50 )
903
+ VLOG_IF_EVERY_N ( 1 , rss_goal_bytes > 0 , 50 )
893
904
<< " Rss memory goal bytes: " << rss_goal_bytes
894
905
<< " , rss used memory: " << global_used_rss_memory
895
906
<< " , rss memory limit: " << max_rss_memory
0 commit comments