From nobody Fri Apr 3 02:29:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC8DEECAAD8 for ; Sat, 17 Sep 2022 02:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbiIQCdd (ORCPT ); Fri, 16 Sep 2022 22:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiIQCdb (ORCPT ); Fri, 16 Sep 2022 22:33:31 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E68399B77; Fri, 16 Sep 2022 19:33:29 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=liusong@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VPzHIFq_1663381981; Received: from localhost(mailfrom:liusong@linux.alibaba.com fp:SMTPD_---0VPzHIFq_1663381981) by smtp.aliyun-inc.com; Sat, 17 Sep 2022 10:33:27 +0800 From: Liu Song To: axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH] sbitmap: fix permanent io blocking caused by insufficient wakeup times Date: Sat, 17 Sep 2022 10:33:01 +0800 Message-Id: <1663381981-6413-1-git-send-email-liusong@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Liu Song 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 --- 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(stru= ct sbitmap_queue *sbq, void sbitmap_queue_wake_up(struct sbitmap_queue *sbq); =20 /** + * 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 &str= uct * 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 sbitm= ap_queue *sbq) return NULL; } =20 -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; =20 +again: wait_cnt =3D atomic_dec_return(&ws->wait_cnt); if (wait_cnt <=3D 0) { int ret; @@ -632,10 +633,14 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq) if (ret =3D=3D wait_cnt) { sbq_index_atomic_inc(&sbq->wake_index); wake_up_nr(&ws->wait, wake_batch); - return false; + if (!nr || *nr <=3D 0) + return false; } =20 return true; + } else if (nr && *nr) { + (*nr)--; + goto again; } =20 return false; @@ -643,11 +648,20 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq) =20 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); =20 +void sbitmap_queue_wake_up_batch(struct sbitmap_queue *sbq, int nr) +{ + int i =3D 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, in= t tag) { if (likely(!sb->round_robin && tag < sb->depth)) @@ -683,7 +697,7 @@ void sbitmap_queue_clear_batch(struct sbitmap_queue *sb= q, int offset, atomic_long_andnot(mask, (atomic_long_t *) addr); =20 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); } --=20 1.8.3.1