All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] sbitmap: fix permanent io blocking caused by insufficient wakeup times
       [not found] <20220917035831.735-1-hdanton@sina.com>
@ 2022-09-17  9:10 ` Liu Song
  0 siblings, 0 replies; 4+ messages in thread
From: Liu Song @ 2022-09-17  9:10 UTC (permalink / raw)
  To: Hillf Danton; +Cc: axboe, linux-kernel


On 2022/9/17 11:58, Hillf Danton wrote:
> On 17 Sep 2022 10:33:01 +0800 Liu Song <liusong@linux.alibaba.com> wrote:
>> @@ -632,10 +633,14 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
>>   		if (ret == wait_cnt) {
>>   			sbq_index_atomic_inc(&sbq->wake_index);
>>   			wake_up_nr(&ws->wait, wake_batch);
>> -			return false;
>> +			if (!nr || *nr <= 0)
>> +				return false;
>>   		}
>>   
>>   		return true;
>> +	} else if (nr && *nr) {
>> +		(*nr)--;
>> +		goto again;
>>   	}
>>   
>>   	return false;
> Hi Song,
>
> See if advancing wake_index can survive your tests.

Hi

Thanks for your suggestion, this problem not only needs to switch a wait 
queue, but also needs to consume "wait_cnt" correctly.


Thanks


>
> Only for thoughts now.
>
> Hillf
> --- a/lib/sbitmap.c
> +++ b/lib/sbitmap.c
> @@ -611,6 +611,7 @@ static bool __sbq_wake_up(struct sbitmap
>   	if (wait_cnt <= 0) {
>   		int ret;
>   
> +		sbq_index_atomic_inc(&sbq->wake_index);
>   		wake_batch = READ_ONCE(sbq->wake_batch);
>   
>   		/*
> @@ -627,7 +628,6 @@ static bool __sbq_wake_up(struct sbitmap
>   		 */
>   		ret = atomic_cmpxchg(&ws->wait_cnt, wait_cnt, wake_batch);
>   		if (ret == wait_cnt) {
> -			sbq_index_atomic_inc(&sbq->wake_index);
>   			wake_up_nr(&ws->wait, wake_batch);
>   			return false;
>   		}

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

* Re: [PATCH] sbitmap: fix permanent io blocking caused by insufficient wakeup times
  2022-09-17 10:20 ` Yu Kuai
@ 2022-09-17 15:06   ` Liu Song
  0 siblings, 0 replies; 4+ messages in thread
From: Liu Song @ 2022-09-17 15:06 UTC (permalink / raw)
  To: Yu Kuai, axboe; +Cc: linux-kernel, linux-block, yukuai (C)


在 2022/9/17 18:20, Yu Kuai 写道:
> Hi,
>
> 在 2022/09/17 10:33, Liu Song 写道:
>> From: Liu Song <liusong@linux.alibaba.com>
>>
>> In "sbitmap_queue_clear_batch", a batch of completed requests may be
>> processed at once, but "wait_cnt" is only reduced once by
>> "sbitmap_queue_wake_up".
>> In our environment, if "/sys/block/nvme0n1/nr_requests" is adjusted to
>> 32, it is easily because no tag and then enter the waiting situation,
>> if continue change "nr_requests" to 1023 at this time, it will basically
>> fall into the situation of permanent blocking. Because there will be
>> "blk_freeze_queue" in "blk_mq_update_nr_requests", which will prevent
>> any new requests, but due to insufficient wake-up, there are tasks
>> waiting for wake-up, but no new wake-up opportunities will be generated
>> at this time, so this situation needs to be repaired.
>>
>
> It seems Keith already fixed this recently. Can you have a check at his
> patch?
>
Hi

It's a bit embarrassing. My code is 6.0-rc3. Yesterday, there was a 
problem with
the Tsinghua mirror station. The fetched code could not be the latest, 
so I submitted it.
According to your suggestion, I checked and it has been fixed, thank you 
for your suggestion.

Thanks

> Thanks,
> Kuai
>> Signed-off-by: Liu Song <liusong@linux.alibaba.com>
>> ---
>>   include/linux/sbitmap.h |  8 ++++++++
>>   lib/sbitmap.c           | 22 ++++++++++++++++++----
>>   2 files changed, 26 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
>> index 8f5a86e..153382e 100644
>> --- a/include/linux/sbitmap.h
>> +++ b/include/linux/sbitmap.h
>> @@ -579,6 +579,14 @@ static inline struct sbq_wait_state 
>> *sbq_wait_ptr(struct sbitmap_queue *sbq,
>>   void sbitmap_queue_wake_up(struct sbitmap_queue *sbq);
>>     /**
>> + * sbitmap_queue_wake_up_batch() - Attempt to wake up waiters in 
>> batches
>> + * on a &struct sbitmap_queue.
>> + * @sbq: Bitmap queue to wake up.
>> + * @nr: The number of attempts to wake the waiter.
>> + */
>> +void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr);
>> +
>> +/**
>>    * sbitmap_queue_show() - Dump &struct sbitmap_queue information to 
>> a &struct
>>    * seq_file.
>>    * @sbq: Bitmap queue to show.
>> diff --git a/lib/sbitmap.c b/lib/sbitmap.c
>> index 29eb048..f2aa1da 100644
>> --- a/lib/sbitmap.c
>> +++ b/lib/sbitmap.c
>> @@ -600,7 +600,7 @@ static struct sbq_wait_state *sbq_wake_ptr(struct 
>> sbitmap_queue *sbq)
>>       return NULL;
>>   }
>>   -static bool __sbq_wake_up(struct sbitmap_queue *sbq)
>> +static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr)
>>   {
>>       struct sbq_wait_state *ws;
>>       unsigned int wake_batch;
>> @@ -610,6 +610,7 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
>>       if (!ws)
>>           return false;
>>   +again:
>>       wait_cnt = atomic_dec_return(&ws->wait_cnt);
>>       if (wait_cnt <= 0) {
>>           int ret;
>> @@ -632,10 +633,14 @@ static bool __sbq_wake_up(struct sbitmap_queue 
>> *sbq)
>>           if (ret == wait_cnt) {
>>               sbq_index_atomic_inc(&sbq->wake_index);
>>               wake_up_nr(&ws->wait, wake_batch);
>> -            return false;
>> +            if (!nr || *nr <= 0)
>> +                return false;
>>           }
>>             return true;
>> +    } else if (nr && *nr) {
>> +        (*nr)--;
>> +        goto again;
>>       }
>>         return false;
>> @@ -643,11 +648,20 @@ static bool __sbq_wake_up(struct sbitmap_queue 
>> *sbq)
>>     void sbitmap_queue_wake_up(struct sbitmap_queue *sbq)
>>   {
>> -    while (__sbq_wake_up(sbq))
>> +    while (__sbq_wake_up(sbq, NULL))
>>           ;
>>   }
>>   EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up);
>>   +void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr)
>> +{
>> +    int i = SBQ_WAIT_QUEUES;
>> +
>> +    while (__sbq_wake_up(sbq, &nr) && --i)
>> +        ;
>> +}
>> +EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up_batch);
>> +
>>   static inline void sbitmap_update_cpu_hint(struct sbitmap *sb, int 
>> cpu, int tag)
>>   {
>>       if (likely(!sb->round_robin && tag < sb->depth))
>> @@ -683,7 +697,7 @@ void sbitmap_queue_clear_batch(struct 
>> sbitmap_queue *sbq, int offset,
>>           atomic_long_andnot(mask, (atomic_long_t *) addr);
>>         smp_mb__after_atomic();
>> -    sbitmap_queue_wake_up(sbq);
>> +    sbitmap_queue_wake_up_batch(sbq, nr_tags);
>>       sbitmap_update_cpu_hint(&sbq->sb, raw_smp_processor_id(),
>>                       tags[nr_tags - 1] - offset);
>>   }
>>

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

* Re: [PATCH] sbitmap: fix permanent io blocking caused by insufficient wakeup times
  2022-09-17  2:33 Liu Song
@ 2022-09-17 10:20 ` Yu Kuai
  2022-09-17 15:06   ` Liu Song
  0 siblings, 1 reply; 4+ messages in thread
From: Yu Kuai @ 2022-09-17 10:20 UTC (permalink / raw)
  To: Liu Song, axboe; +Cc: linux-kernel, linux-block, yukuai (C)

Hi,

在 2022/09/17 10:33, Liu Song 写道:
> From: Liu Song <liusong@linux.alibaba.com>
> 
> In "sbitmap_queue_clear_batch", a batch of completed requests may be
> processed at once, but "wait_cnt" is only reduced once by
> "sbitmap_queue_wake_up".
> In our environment, if "/sys/block/nvme0n1/nr_requests" is adjusted to
> 32, it is easily because no tag and then enter the waiting situation,
> if continue change "nr_requests" to 1023 at this time, it will basically
> fall into the situation of permanent blocking. Because there will be
> "blk_freeze_queue" in "blk_mq_update_nr_requests", which will prevent
> any new requests, but due to insufficient wake-up, there are tasks
> waiting for wake-up, but no new wake-up opportunities will be generated
> at this time, so this situation needs to be repaired.
> 

It seems Keith already fixed this recently. Can you have a check at his
patch?

Thanks,
Kuai
> Signed-off-by: Liu Song <liusong@linux.alibaba.com>
> ---
>   include/linux/sbitmap.h |  8 ++++++++
>   lib/sbitmap.c           | 22 ++++++++++++++++++----
>   2 files changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
> index 8f5a86e..153382e 100644
> --- a/include/linux/sbitmap.h
> +++ b/include/linux/sbitmap.h
> @@ -579,6 +579,14 @@ static inline struct sbq_wait_state *sbq_wait_ptr(struct sbitmap_queue *sbq,
>   void sbitmap_queue_wake_up(struct sbitmap_queue *sbq);
>   
>   /**
> + * sbitmap_queue_wake_up_batch() - Attempt to wake up waiters in batches
> + * on a &struct sbitmap_queue.
> + * @sbq: Bitmap queue to wake up.
> + * @nr: The number of attempts to wake the waiter.
> + */
> +void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr);
> +
> +/**
>    * sbitmap_queue_show() - Dump &struct sbitmap_queue information to a &struct
>    * seq_file.
>    * @sbq: Bitmap queue to show.
> diff --git a/lib/sbitmap.c b/lib/sbitmap.c
> index 29eb048..f2aa1da 100644
> --- a/lib/sbitmap.c
> +++ b/lib/sbitmap.c
> @@ -600,7 +600,7 @@ static struct sbq_wait_state *sbq_wake_ptr(struct sbitmap_queue *sbq)
>   	return NULL;
>   }
>   
> -static bool __sbq_wake_up(struct sbitmap_queue *sbq)
> +static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr)
>   {
>   	struct sbq_wait_state *ws;
>   	unsigned int wake_batch;
> @@ -610,6 +610,7 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
>   	if (!ws)
>   		return false;
>   
> +again:
>   	wait_cnt = atomic_dec_return(&ws->wait_cnt);
>   	if (wait_cnt <= 0) {
>   		int ret;
> @@ -632,10 +633,14 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
>   		if (ret == wait_cnt) {
>   			sbq_index_atomic_inc(&sbq->wake_index);
>   			wake_up_nr(&ws->wait, wake_batch);
> -			return false;
> +			if (!nr || *nr <= 0)
> +				return false;
>   		}
>   
>   		return true;
> +	} else if (nr && *nr) {
> +		(*nr)--;
> +		goto again;
>   	}
>   
>   	return false;
> @@ -643,11 +648,20 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
>   
>   void sbitmap_queue_wake_up(struct sbitmap_queue *sbq)
>   {
> -	while (__sbq_wake_up(sbq))
> +	while (__sbq_wake_up(sbq, NULL))
>   		;
>   }
>   EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up);
>   
> +void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr)
> +{
> +	int i = SBQ_WAIT_QUEUES;
> +
> +	while (__sbq_wake_up(sbq, &nr) && --i)
> +		;
> +}
> +EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up_batch);
> +
>   static inline void sbitmap_update_cpu_hint(struct sbitmap *sb, int cpu, int tag)
>   {
>   	if (likely(!sb->round_robin && tag < sb->depth))
> @@ -683,7 +697,7 @@ void sbitmap_queue_clear_batch(struct sbitmap_queue *sbq, int offset,
>   		atomic_long_andnot(mask, (atomic_long_t *) addr);
>   
>   	smp_mb__after_atomic();
> -	sbitmap_queue_wake_up(sbq);
> +	sbitmap_queue_wake_up_batch(sbq, nr_tags);
>   	sbitmap_update_cpu_hint(&sbq->sb, raw_smp_processor_id(),
>   					tags[nr_tags - 1] - offset);
>   }
> 


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

* [PATCH] sbitmap: fix permanent io blocking caused by insufficient wakeup times
@ 2022-09-17  2:33 Liu Song
  2022-09-17 10:20 ` Yu Kuai
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Song @ 2022-09-17  2:33 UTC (permalink / raw)
  To: axboe; +Cc: linux-kernel, linux-block

From: Liu Song <liusong@linux.alibaba.com>

In "sbitmap_queue_clear_batch", a batch of completed requests may be
processed at once, but "wait_cnt" is only reduced once by
"sbitmap_queue_wake_up".
In our environment, if "/sys/block/nvme0n1/nr_requests" is adjusted to
32, it is easily because no tag and then enter the waiting situation,
if continue change "nr_requests" to 1023 at this time, it will basically
fall into the situation of permanent blocking. Because there will be
"blk_freeze_queue" in "blk_mq_update_nr_requests", which will prevent
any new requests, but due to insufficient wake-up, there are tasks
waiting for wake-up, but no new wake-up opportunities will be generated
at this time, so this situation needs to be repaired.

Signed-off-by: Liu Song <liusong@linux.alibaba.com>
---
 include/linux/sbitmap.h |  8 ++++++++
 lib/sbitmap.c           | 22 ++++++++++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
index 8f5a86e..153382e 100644
--- a/include/linux/sbitmap.h
+++ b/include/linux/sbitmap.h
@@ -579,6 +579,14 @@ static inline struct sbq_wait_state *sbq_wait_ptr(struct sbitmap_queue *sbq,
 void sbitmap_queue_wake_up(struct sbitmap_queue *sbq);
 
 /**
+ * sbitmap_queue_wake_up_batch() - Attempt to wake up waiters in batches
+ * on a &struct sbitmap_queue.
+ * @sbq: Bitmap queue to wake up.
+ * @nr: The number of attempts to wake the waiter.
+ */
+void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr);
+
+/**
  * sbitmap_queue_show() - Dump &struct sbitmap_queue information to a &struct
  * seq_file.
  * @sbq: Bitmap queue to show.
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 29eb048..f2aa1da 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -600,7 +600,7 @@ static struct sbq_wait_state *sbq_wake_ptr(struct sbitmap_queue *sbq)
 	return NULL;
 }
 
-static bool __sbq_wake_up(struct sbitmap_queue *sbq)
+static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr)
 {
 	struct sbq_wait_state *ws;
 	unsigned int wake_batch;
@@ -610,6 +610,7 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
 	if (!ws)
 		return false;
 
+again:
 	wait_cnt = atomic_dec_return(&ws->wait_cnt);
 	if (wait_cnt <= 0) {
 		int ret;
@@ -632,10 +633,14 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
 		if (ret == wait_cnt) {
 			sbq_index_atomic_inc(&sbq->wake_index);
 			wake_up_nr(&ws->wait, wake_batch);
-			return false;
+			if (!nr || *nr <= 0)
+				return false;
 		}
 
 		return true;
+	} else if (nr && *nr) {
+		(*nr)--;
+		goto again;
 	}
 
 	return false;
@@ -643,11 +648,20 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq)
 
 void sbitmap_queue_wake_up(struct sbitmap_queue *sbq)
 {
-	while (__sbq_wake_up(sbq))
+	while (__sbq_wake_up(sbq, NULL))
 		;
 }
 EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up);
 
+void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr)
+{
+	int i = SBQ_WAIT_QUEUES;
+
+	while (__sbq_wake_up(sbq, &nr) && --i)
+		;
+}
+EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up_batch);
+
 static inline void sbitmap_update_cpu_hint(struct sbitmap *sb, int cpu, int tag)
 {
 	if (likely(!sb->round_robin && tag < sb->depth))
@@ -683,7 +697,7 @@ void sbitmap_queue_clear_batch(struct sbitmap_queue *sbq, int offset,
 		atomic_long_andnot(mask, (atomic_long_t *) addr);
 
 	smp_mb__after_atomic();
-	sbitmap_queue_wake_up(sbq);
+	sbitmap_queue_wake_up_batch(sbq, nr_tags);
 	sbitmap_update_cpu_hint(&sbq->sb, raw_smp_processor_id(),
 					tags[nr_tags - 1] - offset);
 }
-- 
1.8.3.1


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

end of thread, other threads:[~2022-09-17 15:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220917035831.735-1-hdanton@sina.com>
2022-09-17  9:10 ` [PATCH] sbitmap: fix permanent io blocking caused by insufficient wakeup times Liu Song
2022-09-17  2:33 Liu Song
2022-09-17 10:20 ` Yu Kuai
2022-09-17 15:06   ` Liu Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.