linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge
@ 2021-05-12  9:43 Paolo Valente
  2021-05-12  9:43 ` [PATCH BUGFIX 1/1] block, bfq: avoid circular stable merges Paolo Valente
  2021-05-12 13:39 ` [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Valente @ 2021-05-12  9:43 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-kernel, yi.zhang, Paolo Valente

Hi,
this patch fixes a bug I've found while debugging a failure reported
by Yi Zhang [1].

This patch seems to make that failure disappear [1]. Yet it was tested
only together with other debug patches (which add logs and invariant
checks), so I don't know whether the other patches influenced the
outcome as well. At any rate, this patch does fix a bug.

Thanks,
Paolo

[1] https://www.spinics.net/lists/linux-block/msg67840.html


Paolo Valente (1):
  block, bfq: avoid circular stable merges

 block/bfq-iosched.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

--
2.20.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH BUGFIX 1/1] block, bfq: avoid circular stable merges
  2021-05-12  9:43 [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge Paolo Valente
@ 2021-05-12  9:43 ` Paolo Valente
  2021-05-12 13:39 ` [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Valente @ 2021-05-12  9:43 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, linux-kernel, yi.zhang, Paolo Valente, Pietro Pedroni

BFQ may merge a new bfq_queue, stably, with the last bfq_queue
created. In particular, BFQ first waits a little bit for some I/O to
flow inside the new queue, say Q2, if this is needed to understand
whether it is better or worse to merge Q2 with the last queue created,
say Q1. This delayed stable merge is performed by assigning
bic->stable_merge_bfqq = Q1, for the bic associated with Q1.

Yet, while waiting for some I/O to flow in Q2, a non-stable queue
merge of Q2 with Q1 may happen, causing the bic previously associated
with Q2 to be associated with exactly Q1 (bic->bfqq = Q1). After that,
Q2 and Q1 may happen to be split, and, in the split, Q1 may happen to
be recycled as a non-shared bfq_queue. In that case, Q1 may then
happen to undergo a stable merge with the bfq_queue pointed by
bic->stable_merge_bfqq. Yet bic->stable_merge_bfqq still points to
Q1. So Q1 would be merged with itself.

This commit fixes this error by intercepting this situation, and
canceling the schedule of the stable merge.

Fixes: 430a67f9d616 ("block, bfq: merge bursts of newly-created queues")
Signed-off-by: Pietro Pedroni <pedroni.pietro.96@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
---
 block/bfq-iosched.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 0270cd7ca165..4c3dcf43b0e2 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -372,9 +372,38 @@ struct bfq_queue *bic_to_bfqq(struct bfq_io_cq *bic, bool is_sync)
 	return bic->bfqq[is_sync];
 }
 
+static void bfq_put_stable_ref(struct bfq_queue *bfqq);
+
 void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync)
 {
+	/*
+	 * If bfqq != NULL, then a non-stable queue merge between
+	 * bic->bfqq and bfqq is happening here. This causes troubles
+	 * in the following case: bic->bfqq has also been scheduled
+	 * for a possible stable merge with bic->stable_merge_bfqq,
+	 * and bic->stable_merge_bfqq == bfqq happens to
+	 * hold. Troubles occur because bfqq may then undergo a split,
+	 * thereby becoming eligible for a stable merge. Yet, if
+	 * bic->stable_merge_bfqq points exactly to bfqq, then bfqq
+	 * would be stably merged with itself. To avoid this anomaly,
+	 * we cancel the stable merge if
+	 * bic->stable_merge_bfqq == bfqq.
+	 */
 	bic->bfqq[is_sync] = bfqq;
+
+	if (bfqq && bic->stable_merge_bfqq == bfqq) {
+		/*
+		 * Actually, these same instructions are executed also
+		 * in bfq_setup_cooperator, in case of abort or actual
+		 * execution of a stable merge. We could avoid
+		 * repeating these instructions there too, but if we
+		 * did so, we would nest even more complexity in this
+		 * function.
+		 */
+		bfq_put_stable_ref(bic->stable_merge_bfqq);
+
+		bic->stable_merge_bfqq = NULL;
+	}
 }
 
 struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic)
@@ -2631,8 +2660,6 @@ static bool bfq_may_be_close_cooperator(struct bfq_queue *bfqq,
 static bool idling_boosts_thr_without_issues(struct bfq_data *bfqd,
 					     struct bfq_queue *bfqq);
 
-static void bfq_put_stable_ref(struct bfq_queue *bfqq);
-
 /*
  * Attempt to schedule a merge of bfqq with the currently in-service
  * queue or with a close queue among the scheduled queues.  Return
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge
  2021-05-12  9:43 [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge Paolo Valente
  2021-05-12  9:43 ` [PATCH BUGFIX 1/1] block, bfq: avoid circular stable merges Paolo Valente
@ 2021-05-12 13:39 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-05-12 13:39 UTC (permalink / raw)
  To: Paolo Valente; +Cc: linux-block, linux-kernel, yi.zhang

On 5/12/21 3:43 AM, Paolo Valente wrote:
> Hi,
> this patch fixes a bug I've found while debugging a failure reported
> by Yi Zhang [1].
> 
> This patch seems to make that failure disappear [1]. Yet it was tested
> only together with other debug patches (which add logs and invariant
> checks), so I don't know whether the other patches influenced the
> outcome as well. At any rate, this patch does fix a bug.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-12 13:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12  9:43 [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge Paolo Valente
2021-05-12  9:43 ` [PATCH BUGFIX 1/1] block, bfq: avoid circular stable merges Paolo Valente
2021-05-12 13:39 ` [PATCH BUGFIX 0/1] block, bfq: a bugfix for stable merge Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).