diff --git a/src/bees-roots.cc b/src/bees-roots.cc index 0c2dfb0..76a3357 100644 --- a/src/bees-roots.cc +++ b/src/bees-roots.cc @@ -538,8 +538,9 @@ should_throttle() // If there's not too many entries in the queue, restart the scan task const auto instance_count = Task::instance_count(); const auto instance_limit = BEES_MAX_EXTENT_REF_COUNT; - const bool queue_empty = s_throttled && instance_count < instance_limit; - const bool queue_full = !s_throttled && instance_count > instance_limit; + // Add some hysteresis so that we aren't constantly flipping throttle on and off + const bool queue_empty = s_throttled && instance_count < instance_limit * .90; + const bool queue_full = !s_throttled && instance_count > instance_limit * .99; if (queue_full) { BEESLOGDEBUG("Throttling crawl at " << instance_count << " tasks"); s_throttled = true; @@ -761,8 +762,6 @@ BeesScanModeExtent::scan() { BEESTRACE("bsm scan"); - if (should_throttle()) return; - unique_lock lock(m_mutex); const auto task_map_copy = m_task_map; lock.unlock(); @@ -778,8 +777,6 @@ BeesScanModeExtent::map_next_extent(uint64_t const subvol) { BEESTRACE("map_next_extent " << subvol); - if (should_throttle()) return; - size_t discard_count = 0; size_t gen_low_count = 0; size_t gen_high_count = 0; @@ -902,8 +899,10 @@ BeesScanModeExtent::map_next_extent(uint64_t const subvol) << " time " << crawl_time << " subvol " << subvol); } - // We did something! Get in line to run again - Task::current_task().idle(); + // We did something! Get in line to run again...unless we're throttled + if (!should_throttle()) { + Task::current_task().idle(); + } return; }