From: Paolo Valente <hidden> Date: 2021-01-22 18:44:16
Hi,
about nine months ago, Jan (Kara, SUSE) reported a throughput
regression with BFQ. That was the beginning of a fruitful dev&testing
collaboration, which led to 18 new commits. Part are fixes, part are
actual performance improvements.
Jia Cheng Hu (1):
block, bfq: set next_rq to waker_bfqq->next_rq in waker injection
Paolo Valente (5):
block, bfq: use half slice_idle as a threshold to check short ttime
block, bfq: increase time window for waker detection
block, bfq: do not raise non-default weights
block, bfq: avoid spurious switches to soft_rt of interactive queues
block, bfq: do not expire a queue when it is the only busy one
block/bfq-iosched.c | 100 +++++++++++++++++++++++++++++++-------------
1 file changed, 70 insertions(+), 30 deletions(-)
--
2.20.1
From: Paolo Valente <hidden> Date: 2021-01-22 18:31:14
Il giorno 22 gen 2021, alle ore 19:19, Paolo Valente [off-list ref] ha scritto:
Hi,
about nine months ago, Jan (Kara, SUSE) reported a throughput
regression with BFQ. That was the beginning of a fruitful dev&testing
collaboration, which led to 18 new commits. Part are fixes, part are
actual performance improvements.
The cover letter was not complete, sorry. Here is the missing piece:
Given the high number of commits, and the size of a few of them, I've
opted for splitting their submission into three batches. This is the
first batch.
Thanks,
Paolo
Jia Cheng Hu (1):
block, bfq: set next_rq to waker_bfqq->next_rq in waker injection
Paolo Valente (5):
block, bfq: use half slice_idle as a threshold to check short ttime
block, bfq: increase time window for waker detection
block, bfq: do not raise non-default weights
block, bfq: avoid spurious switches to soft_rt of interactive queues
block, bfq: do not expire a queue when it is the only busy one
block/bfq-iosched.c | 100 +++++++++++++++++++++++++++++++-------------
1 file changed, 70 insertions(+), 30 deletions(-)
--
2.20.1
From: Paolo Valente <hidden> Date: 2021-01-22 18:31:55
This commits preserves I/O-dispatch plugging for a special symmetric
case that may suddenly turn into asymmetric: the case where only one
bfq_queue, say bfqq, is busy. In this case, not expiring bfqq does not
cause any harm to any other queues in terms of service guarantees. In
contrast, it avoids the following unlucky sequence of events: (1) bfqq
is expired, (2) a new queue with a lower weight than bfqq becomes busy
(or more queues), (3) the new queue is served until a new request
arrives for bfqq, (4) when bfqq is finally served, there are so many
requests of the new queue in the drive that the pending requests for
bfqq take a lot of time to be served. In particular, event (2) may
case even already dispatched requests of bfqq to be delayed, inside
the drive. So, to avoid this series of events, the scenario is
preventively declared as asymmetric also if bfqq is the only busy
queues. By doing so, I/O-dispatch plugging is performed for bfqq.
Tested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <redacted>
---
block/bfq-iosched.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
@@ -3464,20 +3464,38 @@ static void bfq_dispatch_remove(struct request_queue *q, struct request *rq)*orderuntilalltherequestsalreadyqueuedinthedevicehavebeen*served.Thelastsub-conditioncommentedabovesomewhatmitigates*thisproblemforweight-raisedqueues.+*+*However,asanadditionalmitigationforthisproblem,wepreserve+*pluggingforaspecialsymmetriccasethatmaysuddenlyturninto+*asymmetric:thecasewhereonlybfqqisbusy.Inthiscase,not+*expiringbfqqdoesnotcauseanyharmtoanyotherqueuesinterms+*ofserviceguarantees.Incontrast,itavoidsthefollowingunlucky+*sequenceofevents:(1)bfqqisexpired,(2)anewqueuewitha+*lowerweightthanbfqqbecomesbusy(ormorequeues),(3)thenew+*queueisserveduntilanewrequestarrivesforbfqq,(4)whenbfqq+*isfinallyserved,therearesomanyrequestsofthenewqueuein+*thedrivethatthependingrequestsforbfqqtakealotoftimeto+*beserved.Inparticular,event(2)maycaseevenalready+*dispatchedrequestsofbfqqtobedelayed,insidethedrive.So,to+*avoidthisseriesofevents,thescenarioispreventivelydeclared+*asasymmetricalsoifbfqqistheonlybusyqueues*/staticboolidling_needed_for_service_guarantees(structbfq_data*bfqd,structbfq_queue*bfqq){+inttot_busy_queues=bfq_tot_busy_queues(bfqd);+/* No point in idling for bfqq if it won't get requests any longer */if(unlikely(!bfqq_process_refs(bfqq)))returnfalse;return(bfqq->wr_coeff>1&&(bfqd->wr_busy_queues<-bfq_tot_busy_queues(bfqd)||+tot_busy_queues||bfqd->rq_in_driver>=bfqq->dispatched+4))||-bfq_asymmetric_scenario(bfqd,bfqq);+bfq_asymmetric_scenario(bfqd,bfqq)||+tot_busy_queues==1;}staticbool__bfq_bfqq_expire(structbfq_data*bfqd,structbfq_queue*bfqq,
From: Paolo Valente <hidden> Date: 2021-01-22 18:32:55
BFQ tags some bfq_queues as interactive or soft_rt if it deems that
these bfq_queues contain the I/O of, respectively, interactive or soft
real-time applications. BFQ privileges both these special types of
bfq_queues over normal bfq_queues. To privilege a bfq_queue, BFQ
mainly raises the weight of the bfq_queue. In particular, soft_rt
bfq_queues get a higher weight than interactive bfq_queues.
A bfq_queue may turn from interactive to soft_rt. And this leads to a
tricky issue. Soft real-time applications usually start with an
I/O-bound, interactive phase, in which they load themselves into main
memory. BFQ correctly detects this phase, and keeps the bfq_queues
associated with the application in interactive mode for a
while. Problems arise when the I/O pattern of the application finally
switches to soft real-time. One of the conditions for a bfq_queue to
be deemed as soft_rt is that the bfq_queue does not consume too much
bandwidth. But the bfq_queues associated with a soft real-time
application consume as much bandwidth as they can in the loading phase
of the application. So, after the application becomes truly soft
real-time, a lot of time should pass before the average bandwidth
consumed by its bfq_queues finally drops to a value acceptable for
soft_rt bfq_queues. As a consequence, there might be a time gap during
which the application is not privileged at all, because its bfq_queues
are not interactive any longer, but cannot be deemed as soft_rt yet.
To avoid this problem, BFQ pretends that an interactive bfq_queue
consumes zero bandwidth, and allows an interactive bfq_queue to switch
to soft_rt. Yet, this fake zero-bandwidth consumption easily causes
the bfq_queue to often switch to soft_rt deceptively, during its
loading phase. As in soft_rt mode, the bfq_queue gets its bandwidth
correctly computed, and therefore soon switches back to
interactive. Then it switches again to soft_rt, and so on. These
spurious fluctuations usually cause losses of throughput, because they
deceive BFQ's mechanisms for boosting throughput (injection,
I/O-plugging avoidance, ...).
This commit addresses this issue as follows:
1) It does compute actual bandwidth consumption also for interactive
bfq_queues. This avoids the above false positives.
2) When a bfq_queue switches from interactive to normal mode, the
consumed bandwidth is reset (forgotten). This allows the
bfq_queue to enjoy soft_rt very quickly. In particular, two
alternatives are possible in this switch:
- the bfq_queue still has backlog, and therefore there is a budget
already scheduled to serve the bfq_queue; in this case, the
scheduling of the current budget of the bfq_queue is not
hindered, because only the scheduling of the next budget will
be affected by the weight drop. After that, if the bfq_queue is
actually in a soft_rt phase, and becomes empty during the
service of its current budget, which is the natural behavior of
a soft_rt bfq_queue, then the bfq_queue will be considered as
soft_rt when its next I/O arrives. If, in contrast, the
bfq_queue remains constantly non-empty, then its next budget
will be scheduled with a low weight, which is the natural
treatment for an I/O-bound (non soft_rt) bfq_queue.
- the bfq_queue is empty; in this case, the bfq_queue may be
considered unjustly soft_rt when its new I/O arrives. Yet
the problem is now much smaller than before, because it is
unlikely that more than one spurious fluctuation occurs.
Tested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <redacted>
---
block/bfq-iosched.c | 57 +++++++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 20 deletions(-)
@@ -2356,6 +2356,24 @@ static void bfq_requests_merged(struct request_queue *q, struct request *rq,/* Must be called with bfqq != NULL */staticvoidbfq_bfqq_end_wr(structbfq_queue*bfqq){+/*+*Ifbfqqhasbeenenjoyinginteractiveweight-raising,then+*resetsoft_rt_next_start.Wedoitforthefollowing+*reason.bfqqmayhavebeenconveyingtheI/Oneededtoload+*asoftreal-timeapplication.Suchanapplicationactually+*exhibitsasoftreal-timeI/Opatternafteritfinishes+*loading,andfinallystartsdoingitsjob.But,ifbfqqhas+*beenreceivingalotofbandwidthsofar(likelytohappen+*onafastdevice),thensoft_rt_next_startnowcontainsa+*highvaluethat.So,withoutthisreset,bfqqwouldbe+*preventedfrombeingpossiblyconsideredassoft_rtfora+*verylongtime.+*/++if(bfqq->wr_cur_max_time!=+bfqq->bfqd->bfq_wr_rt_max_time)+bfqq->soft_rt_next_start=jiffies;+if(bfq_bfqq_busy(bfqq))bfqq->bfqd->wr_busy_queues--;bfqq->wr_coeff=1;
From: Paolo Valente <hidden> Date: 2021-01-22 18:33:20
BFQ heuristics try to detect interactive I/O, and raise the weight of
the queues containing such an I/O. Yet, if also the user changes the
weight of a queue (i.e., the user changes the ioprio of the process
associated with that queue), then it is most likely better to prevent
BFQ heuristics from silently changing the same weight.
Tested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <redacted>
---
block/bfq-iosched.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
From: Paolo Valente <hidden> Date: 2021-01-22 19:17:37
The value of the I/O plugging (idling) timeout is used also as the
think-time threshold to decide whether a process has a short think
time. In this respect, a good value of this timeout for rotational
drives is un the order of several ms. Yet, this is often too long a
time interval to be effective as a think-time threshold. This commit
mitigates this problem (by a lot, according to tests), by halving the
threshold.
Tested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <redacted>
---
block/bfq-iosched.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
@@ -5238,12 +5238,13 @@ static void bfq_update_has_short_ttime(struct bfq_data *bfqd,return;/* Think time is infinite if no process is linked to-*bfqq.Otherwisecheckaveragethinktimeto-*decidewhethertomarkashas_short_ttime+*bfqq.Otherwisecheckaveragethinktimetodecidewhether+*tomarkashas_short_ttime.Tothisgoal,compareaverage+*thinktimewithhalftheI/O-pluggingtimeout.*/if(atomic_read(&bic->icq.ioc->active_ref)==0||(bfq_sample_valid(bfqq->ttime.ttime_samples)&&-bfqq->ttime.ttime_mean>bfqd->bfq_slice_idle))+bfqq->ttime.ttime_mean>bfqd->bfq_slice_idle>>1))has_short_ttime=false;state_changed=has_short_ttime!=bfq_bfqq_has_short_ttime(bfqq);
From: Paolo Valente <hidden> Date: 2021-01-22 19:17:38
From: Jia Cheng Hu <redacted>
Since commit c5089591c3ba ("block, bfq: detect wakers and
unconditionally inject their I/O"), when the in-service bfq_queue, say
Q, is temporarily empty, BFQ checks whether there are I/O requests to
inject (also) from the waker bfq_queue for Q. To this goal, the value
pointed by bfqq->waker_bfqq->next_rq must be controlled. However, the
current implementation mistakenly looks at bfqq->next_rq, which
instead points to the next request of the currently served queue.
This mistake evidently causes losses of throughput in scenarios with
waker bfq_queues.
This commit corrects this mistake.
Fixes: c5089591c3ba ("block, bfq: detect wakers and unconditionally inject their I/O")
Signed-off-by: Jia Cheng Hu <redacted>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <redacted>
---
block/bfq-iosched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Paolo Valente <hidden> Date: 2021-01-22 19:17:39
Tests on slower machines showed current window to be way too
small. This commit increases it.
Tested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <redacted>
---
block/bfq-iosched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Hi,
about nine months ago, Jan (Kara, SUSE) reported a throughput
regression with BFQ. That was the beginning of a fruitful dev&testing
collaboration, which led to 18 new commits. Part are fixes, part are
actual performance improvements.