• Paolo Valente's avatar
    block, bfq: fix decrement of num_active_groups · ba7aeae5
    Paolo Valente authored
    Since commit '2d29c9f8 ("block, bfq: improve asymmetric scenarios
    detection")', if there are process groups with I/O requests waiting for
    completion, then BFQ tags the scenario as 'asymmetric'. This detection
    is needed for preserving service guarantees (for details, see comments
    on the computation * of the variable asymmetric_scenario in the
    function bfq_better_to_idle).
    
    Unfortunately, commit '2d29c9f8 ("block, bfq: improve asymmetric
    scenarios detection")' contains an error exactly in the updating of
    the number of groups with I/O requests waiting for completion: if a
    group has more than one descendant process, then the above number of
    groups, which is renamed from num_active_groups to a more appropriate
    num_groups_with_pending_reqs by this commit, may happen to be wrongly
    decremented multiple times, namely every time one of the descendant
    processes gets all its pending I/O requests completed.
    
    A correct, complete solution should work as follows. Consider a group
    that is inactive, i.e., that has no descendant process with pending
    I/O inside BFQ queues. Then suppose that num_groups_with_pending_reqs
    is still accounting for this group, because the group still has some
    descendant process with some I/O request still in
    flight. num_groups_with_pending_reqs should be decremented when the
    in-flight request of the last descendant process is finally completed
    (assuming that nothing else has changed for the group in the meantime,
    in terms of composition of the group and active/inactive state of
    child groups and processes). To accomplish this, an additional
    pending-request counter must be added to entities, and must be
    updated correctly.
    
    To avoid this additional field and operations, this commit resorts to
    the following tradeoff between simplicity and accuracy: for an
    inactive group that is still counted in num_groups_with_pending_reqs,
    this commit decrements num_groups_with_pending_reqs when the first
    descendant process of the group remains with no request waiting for
    completion.
    
    This simplified scheme provides a fix to the unbalanced decrements
    introduced by 2d29c9f8. Since this error was also caused by lack
    of comments on this non-trivial issue, this commit also adds related
    comments.
    
    Fixes: 2d29c9f8 ("block, bfq: improve asymmetric scenarios detection")
    Reported-by: 's avatarSteven Barrett <steven@liquorix.net>
    Tested-by: 's avatarSteven Barrett <steven@liquorix.net>
    Tested-by: 's avatarLucjan Lucjanov <lucjan.lucjanov@gmail.com>
    Reviewed-by: 's avatarFederico Motta <federico@willer.it>
    Signed-off-by: 's avatarPaolo Valente <paolo.valente@linaro.org>
    Signed-off-by: 's avatarJens Axboe <axboe@kernel.dk>
    ba7aeae5