From mboxrd@z Thu Jan 1 00:00:00 1970 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 BA3E7C04A95 for ; Fri, 23 Sep 2022 19:07:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232347AbiIWTH2 (ORCPT ); Fri, 23 Sep 2022 15:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbiIWTHY (ORCPT ); Fri, 23 Sep 2022 15:07:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94E23124C1C; Fri, 23 Sep 2022 12:07:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 19DE86114C; Fri, 23 Sep 2022 19:07:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0662C433D6; Fri, 23 Sep 2022 19:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663960042; bh=7H8VpOjF/PEX4j/BXyfxiFyc4XiKNHwJzvMMej31jZo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mLJi8NGQanMCvftUQWlJfbezIx1RXhCBo4SDMmstuxEfaSe0WcUnZswts/34rZjDe zmtTVPtr8/uhzhqfBvwxuc2uvLI0E/FWfJRWuLcnggK1in+YUM/CPEUAkQV0nb2lph K31FuPDzG98rboZ6Gndt1Dxr/sGNupEZInWBn7H0NjtmiPk3F04VhEnJpI6XXwR9mz W+fJPFgmPVfOuPVHtUKjqLVA2xlcI7U/fl4gosyfHhrmPX7Q/N9EBKXqlDYgF8mfKn PvfbPtjj28UPPOs+OKdiw9gKa8TrxhS4ctxKuxLJbjFH1iwUTuJZzU2qaDrF4AaEug mi2s552EfTMbA== Date: Fri, 23 Sep 2022 13:07:19 -0600 From: Keith Busch To: Hugh Dickins Cc: Jan Kara , Jens Axboe , Yu Kuai , Liu Song , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH next] sbitmap: fix lockup while swapping Message-ID: References: <20220921164012.s7lvklp2qk6occcg@quack3> <20220923144303.fywkmgnkg6eken4x@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Does the following fix the observation? Rational being that there's no reason to spin on the current wait state that is already under handling; let subsequent clearings proceed to the next inevitable wait state immediately. --- diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 624fa7f118d1..47bf7882210b 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -634,6 +634,13 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr) *nr -= sub; + /* + * Increase wake_index before updating wait_cnt, otherwise concurrent + * callers can see valid wait_cnt in old waitqueue, which can cause + * invalid wakeup on the old waitqueue. + */ + sbq_index_atomic_inc(&sbq->wake_index); + /* * When wait_cnt == 0, we have to be particularly careful as we are * responsible to reset wait_cnt regardless whether we've actually @@ -660,13 +667,6 @@ static bool __sbq_wake_up(struct sbitmap_queue *sbq, int *nr) * of atomic_set(). */ smp_mb__before_atomic(); - - /* - * Increase wake_index before updating wait_cnt, otherwise concurrent - * callers can see valid wait_cnt in old waitqueue, which can cause - * invalid wakeup on the old waitqueue. - */ - sbq_index_atomic_inc(&sbq->wake_index); atomic_set(&ws->wait_cnt, wake_batch); return ret || *nr; --