Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9975886rwp; Thu, 20 Jul 2023 12:34:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlHpsYmHD6g24nxGPVFXSLgRakVocJSmPwASFgZ5Cgb+T7W/GqsUWkeCS3Eahxm4/ZCk3hR9 X-Received: by 2002:a17:902:d4cf:b0:1ac:6d4c:c24b with SMTP id o15-20020a170902d4cf00b001ac6d4cc24bmr386827plg.3.1689881684830; Thu, 20 Jul 2023 12:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689881684; cv=none; d=google.com; s=arc-20160816; b=tIyWW6aNtnegHjzPhebHyQZ2rux2h/gMDav69cNXwOaLcjhWEL25XQep8Jg8hJjWjN 2hWmbV0LOL8xrTq1crBu6HRLfkQdXvsFz2wGoYTEoS4vafRcCLC4nnJv2aycEsR0m4g4 lrKAEurPB45Vs7DkD4h0YeEprJI8OVzT0IviGHPdjyykebOl2WTJaLkxoh3g5Fr06RU+ J85yZx4uSAbbsLInjC+4BjAka8RhTNIidNZ/lPVVMYLujwrgtf983s5OGM42wlgg6A2h TSeIif2aUfi8tppjfFRW1J9j0COZeU792fW8XEg1YW5RihX6mAT9/Dz4F2hl1pv+JrBl aRfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:organization:subject:cc:to:from:dkim-signature :dkim-signature; bh=mQnVQG0q9VVm8UuQ6nnXG9ncuTRurJ8jeV6JO3bPO7w=; fh=v9Ug8PATbSNc8t0vP87ye583wRZhNDMMNgvalbjlJKs=; b=Fu+aOmfZ+GZslNWxeUyUL33y0wFMXq7hb68Dsqh/OMjs223TupKoZ3Pi51xEPC8hFJ QLDZpzwPqZS0c3JXKi1aMXwbA5DO2anBCTY7eRln9HxmWKsGS1M3hRcLRCypQ8cnAgyQ 6/Y2USY3ozGRkDeB+klYLRFQRsjy8YOoTglvUmm20SngC/QSbxp4EXTOE+HsZrNbZ7SX YE5HkrXNswfSkB3luXMGVMl0/35WG4Xzt0CUYyBr4FMO7fmSZ7YxDpo49ZUR9X6YLQpR OCPtJEWGWowTnBMSPHFIsmAVaoJPbaeOD3ERTRO7GcuFzJ34Ghi4lo4zWT7glmC0WJ4f Estg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=dHn9dnqz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="Xpyr/kcb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170903028300b001b87bd2f7b0si1442364plr.402.2023.07.20.12.34.31; Thu, 20 Jul 2023 12:34:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=dHn9dnqz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="Xpyr/kcb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjGTTHI (ORCPT + 99 others); Thu, 20 Jul 2023 15:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230082AbjGTTHH (ORCPT ); Thu, 20 Jul 2023 15:07:07 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0D622719; Thu, 20 Jul 2023 12:07:02 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6C54C22C8B; Thu, 20 Jul 2023 19:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689880021; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mQnVQG0q9VVm8UuQ6nnXG9ncuTRurJ8jeV6JO3bPO7w=; b=dHn9dnqz9JSek/gmyfpDHzzdj8FbSMF6ZOoM0sYdkS70bTwWMfsCiPtasUYVerbZOJCwuw 3GyOAHI6RsM3MdMiQ13FO3v0ny1LnG10HYosfOo5fFlo9aFxoT4OgQlN9zL3RjtQ2o3iHK bH2UFCrvlf9VUwSI8SdZu6Jz3yiZCO4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689880021; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mQnVQG0q9VVm8UuQ6nnXG9ncuTRurJ8jeV6JO3bPO7w=; b=Xpyr/kcbASNlPiEYokGoGexQCErIE4MJIDylmSIM/14CJerJOjby3Pj/hvaYeGJvV0bzsn D+azY3e/AudeRIDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 336A1138EC; Thu, 20 Jul 2023 19:07:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +DLjBtWFuWRmfAAAMHmgww (envelope-from ); Thu, 20 Jul 2023 19:07:01 +0000 From: Gabriel Krisman Bertazi To: chengming.zhou@linux.dev Cc: axboe@kernel.dk, osandov@fb.com, ming.lei@redhat.com, kbusch@kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, zhouchengming@bytedance.com Subject: Re: [PATCH 1/6] sbitmap: fix hint wrap in the failure case Organization: SUSE References: <20230720094555.1397621-1-chengming.zhou@linux.dev> <20230720094555.1397621-2-chengming.zhou@linux.dev> Date: Thu, 20 Jul 2023 15:06:58 -0400 In-Reply-To: <20230720094555.1397621-2-chengming.zhou@linux.dev> (chengming zhou's message of "Thu, 20 Jul 2023 17:45:50 +0800") Message-ID: <87r0p24d2l.fsf@suse.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org chengming.zhou@linux.dev writes: > From: Chengming Zhou > > ``` > hint = nr + 1; > if (hint >= depth - 1) > hint = 0; > ``` > > Now we wrap the hint to 0 in the failure case, but: > 1. hint == depth - 1, is actually an available offset hint, which > we shouldn't wrap hint to 0. > 2. In the strict round_robin non-wrap case, we shouldn't wrap at all. > > ``` > wrap = wrap && hint; > ``` > > We only need to check wrap based on the original hint ( > 0), don't need > to recheck the new hint which maybe updated in the failure case. > Also delete the mismatched comments by the way. > > Signed-off-by: Chengming Zhou > --- > lib/sbitmap.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/lib/sbitmap.c b/lib/sbitmap.c > index eff4e42c425a..5ed6c2adf58e 100644 > --- a/lib/sbitmap.c > +++ b/lib/sbitmap.c > @@ -144,12 +144,7 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth, > while (1) { > nr = find_next_zero_bit(word, depth, hint); > if (unlikely(nr >= depth)) { > - /* > - * We started with an offset, and we didn't reset the > - * offset to 0 in a failure case, so start from 0 to > - * exhaust the map. > - */ > - if (hint && wrap) { > + if (wrap) { > hint = 0; > continue; I think this is wrong. If you start with an offset in the wrap case and the bitmap is completely full this will become busy wait until a bit is available. The hint check is what make you break out of the loop early, after wrapping, re-walking the entire bitmap and failing to find any available space. > @@ -160,8 +155,13 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth, > break; > > hint = nr + 1; > - if (hint >= depth - 1) > - hint = 0; > + if (hint >= depth) { > + if (wrap) { > + hint = 0; > + continue; > + } > + return -1; > + } > } > > return nr; -- Gabriel Krisman Bertazi