• Yu Kuai's avatar
    block, bfq: fix procress reference leakage for bfqq in merge chain · 73aeab37
    Yu Kuai authored
    Original state:
    
            Process 1       Process 2       Process 3       Process 4
             (BIC1)          (BIC2)          (BIC3)          (BIC4)
              Λ                |               |               |
               \--------------\ \-------------\ \-------------\|
                               V               V               V
              bfqq1--------->bfqq2---------->bfqq3----------->bfqq4
        ref    0               1               2               4
    
    After commit 0e456dba ("block, bfq: choose the last bfqq from merge
    chain in bfq_setup_cooperator()"), if P1 issues a new IO:
    
    Without the patch:
    
            Process 1       Process 2       Process 3       Process 4
             (BIC1)          (BIC2)          (BIC3)          (BIC4)
              Λ                |               |               |
               \------------------------------\ \-------------\|
                                               V               V
              bfqq1--------->bfqq2---------->bfqq3----------->bfqq4
        ref    0               0               2               4
    
    bfqq3 will be used to handle IO from P1, this is not expected, IO
    should be redirected to bfqq4;
    
    With the patch:
    
              -------------------------------------------
              |                                         |
            Process 1       Process 2       Process 3   |   Process 4
             (BIC1)          (BIC2)          (BIC3)     |    (BIC4)
                               |               |        |      |
                                \-------------\ \-------------\|
                                               V               V
              bfqq1--------->bfqq2---------->bfqq3----------->bfqq4
        ref    0               0               2               4
    
    IO is redirected to bfqq4, however, procress reference of bfqq3 is still
    2, while there is only P2 using it.
    
    Fix the problem by calling bfq_merge_bfqqs() for each bfqq in the merge
    chain. Also change bfqq_merge_bfqqs() to return new_bfqq to simplify
    code.
    
    Fixes: 0e456dba ("block, bfq: choose the last bfqq from merge chain in bfq_setup_cooperator()")
    Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
    Link: https://lore.kernel.org/r/20240909134154.954924-3-yukuai1@huaweicloud.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
    73aeab37
bfq-iosched.c 265 KB