[RESEND,v2,03/10] block, bfq: initialize bfqq->decrease_time_jif correctly

Message ID 20221222191641.1643117-4-shikemeng@huaweicloud.com
State New
Headers
Series A few bugfix and cleancode patch for bfq |

Commit Message

Kemeng Shi Dec. 22, 2022, 7:16 p.m. UTC
  Inject limit is updated or reset when time_is_before_eq_jiffies(
decrease_time_jif + several msecs) or think-time state changes.
decrease_time_jif is initialized to 0 and will be set to current jiffies
when inject limit is updated or reset. If the jiffies is slightly greater
than LONG_MAX, time_is_after_eq_jiffies(0) will keep for a long time, so as
time_is_after_eq_jiffies(decrease_time_jif + several msecs). If the
think-time state never chages, then the injection will not work as expected
for long time.

To be more specific:
Function bfq_update_inject_limit maybe triggered when jiffies pasts
decrease_time_jif + msecs_to_jiffies(10) in bfq_add_request by setting
bfqd->wait_dispatch to true.
Function bfq_reset_inject_limit are called in two conditions:
1. jiffies pasts bfqq->decrease_time_jif + msecs_to_jiffies(1000) in
function bfq_add_request.
2. jiffies pasts bfqq->decrease_time_jif + msecs_to_jiffies(100) or
bfq think-time state change from short to long.

Fix this by initializing bfqq->decrease_time_jif to current jiffies
to trigger service injection soon when service injection conditions
are met.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Jan Kara Jan. 2, 2023, 3:30 p.m. UTC | #1
On Fri 23-12-22 03:16:34, Kemeng Shi wrote:
> Inject limit is updated or reset when time_is_before_eq_jiffies(
> decrease_time_jif + several msecs) or think-time state changes.
> decrease_time_jif is initialized to 0 and will be set to current jiffies
> when inject limit is updated or reset. If the jiffies is slightly greater
> than LONG_MAX, time_is_after_eq_jiffies(0) will keep for a long time, so as
> time_is_after_eq_jiffies(decrease_time_jif + several msecs). If the
> think-time state never chages, then the injection will not work as expected
> for long time.
> 
> To be more specific:
> Function bfq_update_inject_limit maybe triggered when jiffies pasts
> decrease_time_jif + msecs_to_jiffies(10) in bfq_add_request by setting
> bfqd->wait_dispatch to true.
> Function bfq_reset_inject_limit are called in two conditions:
> 1. jiffies pasts bfqq->decrease_time_jif + msecs_to_jiffies(1000) in
> function bfq_add_request.
> 2. jiffies pasts bfqq->decrease_time_jif + msecs_to_jiffies(100) or
> bfq think-time state change from short to long.
> 
> Fix this by initializing bfqq->decrease_time_jif to current jiffies
> to trigger service injection soon when service injection conditions
> are met.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>

I agree that initializing jiffies timer to 0 is just a bad practice and
current time is much saner choice. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/bfq-iosched.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
> index 5a6d9e8c329d..9441fc98961a 100644
> --- a/block/bfq-iosched.c
> +++ b/block/bfq-iosched.c
> @@ -5491,6 +5491,8 @@ static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
>  
>  	/* first request is almost certainly seeky */
>  	bfqq->seek_history = 1;
> +
> +	bfqq->decrease_time_jif = jiffies;
>  }
>  
>  static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd,
> -- 
> 2.30.0
>
  

Patch

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 5a6d9e8c329d..9441fc98961a 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5491,6 +5491,8 @@  static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
 
 	/* first request is almost certainly seeky */
 	bfqq->seek_history = 1;
+
+	bfqq->decrease_time_jif = jiffies;
 }
 
 static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd,