Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9340460rwp; Thu, 20 Jul 2023 03:32:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSlg8odsp0V7GbY1K0aozSMFVqz/eou9t3qO5jhKfN0hBmXM4vB8MFYgaEApQBK8LMwjrk X-Received: by 2002:a17:907:1c26:b0:98d:4b97:acc8 with SMTP id nc38-20020a1709071c2600b0098d4b97acc8mr4832555ejc.25.1689849130785; Thu, 20 Jul 2023 03:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689849130; cv=none; d=google.com; s=arc-20160816; b=I8UDal82F2yoJDCDlFQtLdMhHmF5o5ZNgieuTXrlOgWZSkfl+1qxezYKxHrp+4VK8/ FSJhXsoSLI7kX55uXOc5T6i8j5iNYSZFsk4RkNB8ARqjtlP2t6BDQCiD98Yma4UNWJAn xjTwMIWpRA+A4SB34eT1k5+WgTPesHdmfHqWHFf0+KZ1B45NFjNRRclkhydNIXvXXyhg 2fY1S6huxF0LmLsx11ep3MirP70Dpqaba2GbRrlBTgQKTkb3oO5u2umivpzA0M9ohqJY nLFoCeH21XuyJ3Q7Rk3nNnaJEqRKeAh7iQHigOaN7ZbBpEmXKTVsp9LRR6WKTAxiERnO Z0Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TQ3vuI5C6djnpQbCi1PW59Gj+FCebISZRVuxTvWKvqo=; fh=hjJkBnU2szufEu6iYNeHw5+ILtjbq+a6zNGIo+CbvPw=; b=RQ+mEIM441/DadtZahwgxea6jWV+xSZ3coM49aODmt1h8vAyOUkXD8S6T1ZHjAodV/ NteRteT5ykL7+zWtYv/dgGZ/vlDt+Ln5XfVqEktJHUk2QFlHHS6d1byT6EYGgcJNkh8W kGvA1f+kHXneJRFay7BHSq6oo/7MhJAzPCsXT/5/CsXFbwdDooh8zjRk1bwqeRAIfflw XvT06FArWY/SESlX7FoBWrV/7kxW4PcjAvYuyOA1cMP1B3sNRivu3537dotMetCFtM7P FMXrnvBgt5W2eUVoPNAkuBzS/0vNAgFuuitldPEMa8SvbKF/Ggy7k10HYC8D8ZQ7uF/P sTmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=w4MmY0D5; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u19-20020aa7d893000000b005219817ce6asi725742edq.676.2023.07.20.03.31.43; Thu, 20 Jul 2023 03:32:10 -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=@linux.dev header.s=key1 header.b=w4MmY0D5; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231215AbjGTJtT (ORCPT + 99 others); Thu, 20 Jul 2023 05:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbjGTJsT (ORCPT ); Thu, 20 Jul 2023 05:48:19 -0400 Received: from out-48.mta0.migadu.com (out-48.mta0.migadu.com [IPv6:2001:41d0:1004:224b::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12DA110A for ; Thu, 20 Jul 2023 02:47:27 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689846446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TQ3vuI5C6djnpQbCi1PW59Gj+FCebISZRVuxTvWKvqo=; b=w4MmY0D51B5mbGeKCwtzsoKhqXXNdLV/Jh+Z8f4ocFu4r2lgNM2FMx5joP6MZg61eMRcPe SWTBP0I8vkvNLPEK871eybgV69GeQS2Ltb1S/JfKkNAgDSRsA3dseXHhNnlHdXo/ewd8zK JY+lUtfuC2q3a1WZ9PWsuyHaW+deVy0= From: chengming.zhou@linux.dev To: axboe@kernel.dk, osandov@fb.com, ming.lei@redhat.com, kbusch@kernel.org, krisman@suse.de Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, zhouchengming@bytedance.com Subject: [PATCH 3/6] sbitmap: don't loop twice in find_next_zero_bit() Date: Thu, 20 Jul 2023 17:45:52 +0800 Message-ID: <20230720094555.1397621-4-chengming.zhou@linux.dev> In-Reply-To: <20230720094555.1397621-1-chengming.zhou@linux.dev> References: <20230720094555.1397621-1-chengming.zhou@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Chengming Zhou __sbitmap_get_shallow() try to allocate a free bit with a limited depth, which always wrap when finding a free bit in the word, even in the round-robin case. So it seems we don't need strict round-robin here. This way will loop twice in find_next_zero_bit() in the word, no point in looping twice in find_next_zero_bit() if we don't want strict round-robin for this case. Signed-off-by: Chengming Zhou --- lib/sbitmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index ccb96d1f92ba..0f3943bd3940 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -268,7 +268,9 @@ static int __sbitmap_get_shallow(struct sbitmap *sb, unsigned int index; index = SB_NR_TO_INDEX(sb, alloc_hint); - alloc_hint = SB_NR_TO_BIT(sb, alloc_hint); + + /* No point in looping twice in find_next_zero_bit() for this case. */ + alloc_hint = 0; return sbitmap_find_bit(sb, shallow_depth, index, alloc_hint, true); } -- 2.41.0