Skip to content

Commit 2d52c58

Browse files
Algodev-githubaxboe
authored andcommitted
block, bfq: honor already-setup queue merges
The function bfq_setup_merge prepares the merging between two bfq_queues, say bfqq and new_bfqq. To this goal, it assigns bfqq->new_bfqq = new_bfqq. Then, each time some I/O for bfqq arrives, the process that generated that I/O is disassociated from bfqq and associated with new_bfqq (merging is actually a redirection). In this respect, bfq_setup_merge increases new_bfqq->ref in advance, adding the number of processes that are expected to be associated with new_bfqq. Unfortunately, the stable-merging mechanism interferes with this setup. After bfqq->new_bfqq has been set by bfq_setup_merge, and before all the expected processes have been associated with bfqq->new_bfqq, bfqq may happen to be stably merged with a different queue than the current bfqq->new_bfqq. In this case, bfqq->new_bfqq gets changed. So, some of the processes that have been already accounted for in the ref counter of the previous new_bfqq will not be associated with that queue. This creates an unbalance, because those references will never be decremented. This commit fixes this issue by reestablishing the previous, natural behaviour: once bfqq->new_bfqq has been set, it will not be changed until all expected redirections have occurred. Signed-off-by: Davide Zini <[email protected]> Signed-off-by: Paolo Valente <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 55a51ea commit 2d52c58

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

block/bfq-iosched.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,15 @@ bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)
26622662
* are likely to increase the throughput.
26632663
*/
26642664
bfqq->new_bfqq = new_bfqq;
2665+
/*
2666+
* The above assignment schedules the following redirections:
2667+
* each time some I/O for bfqq arrives, the process that
2668+
* generated that I/O is disassociated from bfqq and
2669+
* associated with new_bfqq. Here we increases new_bfqq->ref
2670+
* in advance, adding the number of processes that are
2671+
* expected to be associated with new_bfqq as they happen to
2672+
* issue I/O.
2673+
*/
26652674
new_bfqq->ref += process_refs;
26662675
return new_bfqq;
26672676
}
@@ -2724,6 +2733,10 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq,
27242733
{
27252734
struct bfq_queue *in_service_bfqq, *new_bfqq;
27262735

2736+
/* if a merge has already been setup, then proceed with that first */
2737+
if (bfqq->new_bfqq)
2738+
return bfqq->new_bfqq;
2739+
27272740
/*
27282741
* Check delayed stable merge for rotational or non-queueing
27292742
* devs. For this branch to be executed, bfqq must not be
@@ -2825,9 +2838,6 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq,
28252838
if (bfq_too_late_for_merging(bfqq))
28262839
return NULL;
28272840

2828-
if (bfqq->new_bfqq)
2829-
return bfqq->new_bfqq;
2830-
28312841
if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq))
28322842
return NULL;
28332843

0 commit comments

Comments
 (0)