Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2907877rdb; Mon, 4 Dec 2023 10:41:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcFIK0xOo8WM3seQTDseAV+8nDbnlJsrtk/7Pe2qjjBEqPpT78kfYunEat+53WoUsxDy5T X-Received: by 2002:a05:6a20:2444:b0:18b:902f:88fe with SMTP id t4-20020a056a20244400b0018b902f88femr5478607pzc.9.1701715271470; Mon, 04 Dec 2023 10:41:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701715271; cv=none; d=google.com; s=arc-20160816; b=PZGw7eS2yCmVbY2Axw7jbGSbAS0cHM/FMCCEyMMvhiFgsp1cUjVyPkOX7Z7lFqLirF DuqfWUV018pBQRzi9GNFRd8nUb4KTVui6/5hfmQLqglwYvNW0dmLhLGvHW8W0hTj2nww zoBKV/c5PKrc0u1VbPlXQK0QApKTyBWniYHfOg7MQpKqsK4qWm5NAGWtFjQM/aFSxc40 GJVM88h6Izid0wPj4LD5SHVD+dd8EsCQyX+IUviqaGCxiDvU5z5JouY5plnn3ERFhLUb s4fkcD/QjrzWEgsaAjxDhN8djYk0biA9VsSAK26+BlhJRbXLQHEb4SPXYSGpvFICsdTz u1XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=8nF/2go7Oh+X36EEMP+OJQ3WMJQXuy7RxDAu7l6pxwI=; fh=6S0UKWOHhk3OrkWAxQXWClKVCHsEocZjIURoS1Md4gY=; b=GE8xM+0yPv9b561YDaOKe0/4XMWpycgd+DQGK8pnCFkWBdpfxqOgRo3UGT8Mg+eHK0 VsR3+o+QGvRBJPrPtLLwQfkf0HQ2jdSS4AjI8UBhQRIVZmuV+eSRXmx85CUszaP4eVhB CwnaQJI2jlMDRiEnEgTN8uw7VBrfx2FXh8RQ+mTk3ZJuU7u4ByMGD5BHyVbdNAO/OIMC sHl6z8UByud4SQPcZo2mruKSfQkaNIWcTq/6IUejaMalbYHn13sMd0O4b+570C95e+ng l01Pa+IZZISl7mv1+apD8quDbiixDcIhELNE2jHVMkj/YXsGo/tdxHRDXEe6QEsECAkZ iAnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=RW4NtGgg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a7-20020a656047000000b005a1d88169casi8364307pgp.189.2023.12.04.10.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:41:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=RW4NtGgg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EAD04804C609; Mon, 4 Dec 2023 10:41:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbjLDSk5 (ORCPT + 99 others); Mon, 4 Dec 2023 13:40:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjLDSk4 (ORCPT ); Mon, 4 Dec 2023 13:40:56 -0500 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21EC8113 for ; Mon, 4 Dec 2023 10:41:02 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-35d626e4f79so1822195ab.0 for ; Mon, 04 Dec 2023 10:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1701715261; x=1702320061; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8nF/2go7Oh+X36EEMP+OJQ3WMJQXuy7RxDAu7l6pxwI=; b=RW4NtGggQhTrYZK1Qmc1d7zjjg5dEmVgaCD4soCV4Mvw7euO4WY6i6Qk+4dKfK2Rxy z/hn93scfymepBPSqhCTdv38L9X1m46DxWENw51nUTf7eJdL85kZZUoK+34aT34MIkRl vok1BDPx/c1Mx4VeDoNMSG/EMgfMikG7RFLNW7NWOMB6Q+Egcys6R9/4em9kUTbplSkv LsDZYabo8pR6Q4RatjhBsuOiyi8zJ5R64tnmMXhVpUxGCkBIE0RzpTGXEf77FXSiB2sf HxNkl3hIPRKUvIIETKcxebNYhsxmzve9jTMpL69LCiA+O26NxRMmw/kZIFgZ5uRelEen oY3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701715261; x=1702320061; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8nF/2go7Oh+X36EEMP+OJQ3WMJQXuy7RxDAu7l6pxwI=; b=idlKqnrpQ+rJJyC4pewLMQ1rNZ90cuvcho9FhML91jQCgPmVYTAwE1ejV5uOP7FAQ2 n87sUTB29IX5+P6PUJNok7arN0RtIiiwUA8p2X3o5BdV2NQnijDvyqDSvoGioIwlTuCy j/p6X0AHrGZmtCpWFQfmB5iFYMMUgCfVmqcATaWi6y0+QewEsgzKLETfdHfgDXeGNNbR CofG8mQgfo5sDT5I9H4N6ex+U6ZJK8dYjBwNa0tXPwbhJnMRf1Ouj7MNYqd3r4WegxZx DLdfM8X6mW7hhwVoqIlmWyrxkAEBujKYzh73BgT+mqDCxg1aqub53O72+SCZlqccLti4 Df1A== X-Gm-Message-State: AOJu0YxuDGcrPrv+G6DA5yMtfdEPaFgb3w/OVwXSQ+4k1Bf95ZTfFn5s ryguOTRhRb/EqTjsTWOaOT73/w== X-Received: by 2002:a6b:660f:0:b0:7b3:58c4:b894 with SMTP id a15-20020a6b660f000000b007b358c4b894mr30267653ioc.1.1701715261426; Mon, 04 Dec 2023 10:41:01 -0800 (PST) Received: from [192.168.1.116] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id fn20-20020a056638641400b0045812e7b8bbsm2621977jab.25.2023.12.04.10.41.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Dec 2023 10:41:00 -0800 (PST) Message-ID: Date: Mon, 4 Dec 2023 11:40:59 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 03/35] lib/sbitmap; make __sbitmap_get_word() using find_and_set_bit() Content-Language: en-US To: Yury Norov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov , Bart Van Assche , Sergey Shtylyov References: <20231203192422.539300-1-yury.norov@gmail.com> <20231203193307.542794-1-yury.norov@gmail.com> <20231203193307.542794-2-yury.norov@gmail.com> From: Jens Axboe In-Reply-To: <20231203193307.542794-2-yury.norov@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 10:41:10 -0800 (PST) On 12/3/23 12:32 PM, Yury Norov wrote: > diff --git a/lib/sbitmap.c b/lib/sbitmap.c > index d0a5081dfd12..b21aebd07fd6 100644 > --- a/lib/sbitmap.c > +++ b/lib/sbitmap.c > @@ -133,38 +133,11 @@ 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, > +static inline int __sbitmap_get_word(unsigned long *word, unsigned long depth, > unsigned int hint, bool wrap) > { > - 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)) { > - /* > - * 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) { > - hint = 0; > - continue; > - } > - return -1; > - } > - > - if (!test_and_set_bit_lock(nr, word)) > - break; > - > - hint = nr + 1; > - if (hint >= depth - 1) > - hint = 0; > - } > - > - return nr; > + return wrap ? find_and_set_bit_wrap_lock(word, depth, hint) : > + find_and_set_next_bit_lock(word, depth, hint); > } Please make this: if (wrap) return find_and_set_bit_wrap_lock(word, depth, hint) : return find_and_set_next_bit_lock(word, depth, hint); so this is a lot more readable. -- Jens Axboe