Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9306239rwp; Thu, 20 Jul 2023 02:56:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGT1Pzxl1arWFgC9bF9vZzinZxgNeXGQ33/+pok56ygBuU9JPznCzldC6b8gNc7UpAd/Z5f X-Received: by 2002:a50:ed94:0:b0:521:6305:82e7 with SMTP id h20-20020a50ed94000000b00521630582e7mr4923074edr.30.1689847007465; Thu, 20 Jul 2023 02:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689847007; cv=none; d=google.com; s=arc-20160816; b=Mh+WCDq3lE8/Uq5N7tSTCxloH+zqiNQ/nuEVqw0tDMOROPsV5J8e50UlknHjD5oXDZ 6pAI8GfyQdo3EsKPnjbAW2h9w2Cpev04iRGHKVD/OhLNHz4LRTduuYV0hM8GzJbAs3Ot kWfPO4yNt1Gmns3hvdjMhlGCunqgd0zBTULjwEaEV7PwpI2JI9okZjhB8AQGXQQGud3U Q0Q1Dm/BIkmILxrLzS9G1timk9Snw6Qn0qkMoJZ96mJqlYCYzFwilRABH31NcQpsIRKK hAfvWoIYZMkauc5JFE8KePJhtcRtLF2e7wLwhFBgiaPG9E6H6Sp90LRSeKgOlUEjnDiH F6bg== 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=CHTcss6l/Dml/Uch+o0A/n+25yQoOIqj7dE4TlbyHH4=; fh=hjJkBnU2szufEu6iYNeHw5+ILtjbq+a6zNGIo+CbvPw=; b=OTZjAZoqLMrjrcHrIBKOcBdtBp0Spc4YYAxseW31oazrezje5Ps9iiqB9F9bUouWF4 klL1chLCaBFC4rdnBpQe4tavIMlwPdLeJjAHXgAoY15cnU3zCKNrkXB/pAw1no8nXLVf x6f23547djl5AQtdCymzVm2uTzfrWVixGjV2NslzdRhCjYqd2rmkWg9gnkmQiZfIzTcM qVgKIXn2tp0jDK+rT5JnVQhx74yVLuSNJAX07IiBIneoa1+vW5HwR6bYp2E+y/tha3ay oF2Qlv60g9vbgvv4fiQuEYclVZ+FiYo9iXyKuO8fShSc2g+S86tS8rp1eclS17xgwUHs W69Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ai++OZMU; 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 dy25-20020a05640231f900b0051e26617526si560587edb.347.2023.07.20.02.56.23; Thu, 20 Jul 2023 02:56:47 -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=Ai++OZMU; 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 S230517AbjGTJtc (ORCPT + 99 others); Thu, 20 Jul 2023 05:49:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjGTJs2 (ORCPT ); Thu, 20 Jul 2023 05:48:28 -0400 Received: from out-18.mta0.migadu.com (out-18.mta0.migadu.com [IPv6:2001:41d0:1004:224b::12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 678DB26A5 for ; Thu, 20 Jul 2023 02:47:32 -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=1689846450; 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=CHTcss6l/Dml/Uch+o0A/n+25yQoOIqj7dE4TlbyHH4=; b=Ai++OZMUjHmw2983yCNBjVkPFxFeR1arX5zXXbaGjA90hfi5mvTPK+xbJURrXi/u+0CWWN RkZhb6KGm+bKwEOt2ud4UlHdP4VWFqqslwKhjxgk4nP6y8kd6taike6pQ5cLKPz4EMMIpE 7N58wZ4pmp7tHfkumvcPMa3P5e/aYD4= 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 4/6] sbitmap: remove offset wrap logic when finding bit in word Date: Thu, 20 Jul 2023 17:45:53 +0800 Message-ID: <20230720094555.1397621-5-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,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 From: Chengming Zhou We actually don't need the offset hint wrap logic in word: 1. Strict round-robin mode: just search from that offset hint, we will recheck that word at last if offset hint > 0. 2. No round-robin mode: we use offset hint == 0, so don't need to wrap offset hint too. We remove offset wrap logic and simplify the code. Signed-off-by: Chengming Zhou --- lib/sbitmap.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 0f3943bd3940..50bdf3a31947 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -134,34 +134,21 @@ void sbitmap_resize(struct sbitmap *sb, unsigned int depth) EXPORT_SYMBOL_GPL(sbitmap_resize); static int __sbitmap_get_word(unsigned long *word, unsigned long depth, - unsigned int hint, bool wrap) + unsigned int hint) { int nr; - /* don't wrap if starting from 0 */ - wrap = wrap && hint; - while (1) { nr = find_next_zero_bit(word, depth, hint); - if (unlikely(nr >= depth)) { - if (wrap) { - hint = 0; - continue; - } + if (unlikely(nr >= depth)) return -1; - } if (!test_and_set_bit_lock(nr, word)) break; hint = nr + 1; - if (hint >= depth) { - if (wrap) { - hint = 0; - continue; - } + if (hint >= depth) return -1; - } } return nr; @@ -169,14 +156,13 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth, static int sbitmap_find_bit_in_word(struct sbitmap_word *map, unsigned int depth, - unsigned int alloc_hint, - bool wrap) + unsigned int alloc_hint) { int nr; do { nr = __sbitmap_get_word(&map->word, depth, - alloc_hint, wrap); + alloc_hint); if (nr != -1) break; if (!sbitmap_deferred_clear(map)) @@ -189,8 +175,7 @@ static int sbitmap_find_bit_in_word(struct sbitmap_word *map, static int sbitmap_find_bit(struct sbitmap *sb, unsigned int depth, unsigned int index, - unsigned int alloc_hint, - bool wrap) + unsigned int alloc_hint) { unsigned int map_nr = sb->map_nr; unsigned int i; @@ -200,7 +185,7 @@ static int sbitmap_find_bit(struct sbitmap *sb, * If we have alloc_hint > 0 and don't wrap, we need to * recheck sb->map[index] with hint == 0 to exhaust the map. */ - if (alloc_hint && !wrap) + if (alloc_hint) map_nr += 1; for (i = 0; i < map_nr; i++) { @@ -208,7 +193,7 @@ static int sbitmap_find_bit(struct sbitmap *sb, min_t(unsigned int, __map_depth(sb, index), depth), - alloc_hint, wrap); + alloc_hint); if (nr != -1) { nr += index << sb->shift; @@ -240,8 +225,7 @@ static int __sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint) else alloc_hint = 0; - return sbitmap_find_bit(sb, UINT_MAX, index, alloc_hint, - !sb->round_robin); + return sbitmap_find_bit(sb, UINT_MAX, index, alloc_hint); } int sbitmap_get(struct sbitmap *sb) @@ -272,7 +256,7 @@ static int __sbitmap_get_shallow(struct sbitmap *sb, /* 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); + return sbitmap_find_bit(sb, shallow_depth, index, alloc_hint); } int sbitmap_get_shallow(struct sbitmap *sb, unsigned long shallow_depth) -- 2.41.0