mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-22 07:56:32 -05:00
Clamp set_threads to autoscale bounds
set_threads did not enforce ScalingConfig::min_threads / max_threads, so a caller could push the pool outside the range that the monitor thread and idle self-exit logic expect. For example, set_threads(1) with min_threads=2 would be rejected by _remove_thread_scaling_locked partway through, leaving the pool in a partially-shrunk state. Growing above max_threads had no guard at all. Clamp the requested count to [min_threads, max_threads] when autoscaling is enabled, mirroring the constructor's clamping logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8f41b40692
commit
78d320a64c
1 changed files with 13 additions and 2 deletions
|
|
@ -777,6 +777,17 @@ ThreadPool::set_threads(const std::size_t count_)
|
|||
if(count_ == 0)
|
||||
return -EINVAL;
|
||||
|
||||
// Clamp to autoscale bounds so external callers can't push the
|
||||
// pool outside the range the monitor and idle-exit logic expect.
|
||||
std::size_t count = count_;
|
||||
if(_autoscale_enabled)
|
||||
{
|
||||
if(count < _scaling_config.min_threads)
|
||||
count = _scaling_config.min_threads;
|
||||
if(count > _scaling_config.max_threads)
|
||||
count = _scaling_config.max_threads;
|
||||
}
|
||||
|
||||
std::size_t current;
|
||||
|
||||
{
|
||||
|
|
@ -786,14 +797,14 @@ ThreadPool::set_threads(const std::size_t count_)
|
|||
|
||||
int rv = 0;
|
||||
|
||||
for(std::size_t i = current; i < count_; ++i)
|
||||
for(std::size_t i = current; i < count; ++i)
|
||||
{
|
||||
rv = _add_thread_scaling_locked({});
|
||||
if(rv != 0)
|
||||
return rv;
|
||||
}
|
||||
|
||||
for(std::size_t i = count_; i < current; ++i)
|
||||
for(std::size_t i = count; i < current; ++i)
|
||||
{
|
||||
rv = _remove_thread_scaling_locked();
|
||||
if(rv != 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue