Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9306705rwp; Thu, 20 Jul 2023 02:57:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlGkh+jjHdT+r1uF9T4Wm0XXBBliKbf6ZXWG8by49Ou29JYsziacN0t48NZ3zjz6gfO0qa3T X-Received: by 2002:a17:906:64d7:b0:993:f127:2391 with SMTP id p23-20020a17090664d700b00993f1272391mr5471109ejn.32.1689847038657; Thu, 20 Jul 2023 02:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689847038; cv=none; d=google.com; s=arc-20160816; b=VX316LIl+2jNj4fWV43i71zEnCobzaDj2ZEnN5cmh1j8JlYLKRGUPZXZu3a1J8Y6/t d0DjCaIVi4P8zLKErGFxYcwvH403yKOOj3tG+WZCi+HMKLg3sQlO0+uEVYvJwxamKCRA mVg8U9R9ZBCDuoT1ktx2g7uRgsl4G+OK2KfcmvRisGKUweu/9qijIDebz9ZtY136dkqs ZAqh+UlFMWsulvo4fgmlNgsLgcFuvxjzlV3/yqSowLlUXGd5V58BOFWNDX8v3Izb66HD LGfww0noyCY5HYVnN2z3+U/OIZWALgVts3tl393qhsn+zFwYtgrYKps3PDNe1oeIcnOH sB8w== 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=p34J6xnRb86eKyDcpXgSq81rjV9gO+WCulIJcSmybAc=; fh=hjJkBnU2szufEu6iYNeHw5+ILtjbq+a6zNGIo+CbvPw=; b=wiVvnHkPRTe+f1NgrwNGNu906GUgpkTvyiz6kLp/t0hyzVOL4BZXkQAay1tMid3QWL pMbRXujynxAmCoO2C0pUGduyq+VbttKLTKzTAMHShWEnBd2uuOJrVXMnDqCf7FvCblyU GT19iUXijzQB0zaSNiuGiN9fhXNxq5NtMTQdKvcu01B8e97cJg2A4Kbd/DhaeAFf4RNw AxF/FJwBt01TdCe7YNwIBkVn0+nV2KZocLS/STFft6SrG+4ZpJvRl/bSFfhg5gPWwkgi NJIgnxe2sAumqTU4a+547X2Qi0AMo+13Qr00GYUjkuoblQ+CRG4ZxnFTnnG3c8fzZk6C LLxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=FO6tJlnK; 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 kd10-20020a17090798ca00b00992f3097ed4si424010ejc.871.2023.07.20.02.56.54; Thu, 20 Jul 2023 02:57:18 -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=FO6tJlnK; 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 S231279AbjGTJtk (ORCPT + 99 others); Thu, 20 Jul 2023 05:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjGTJsf (ORCPT ); Thu, 20 Jul 2023 05:48:35 -0400 Received: from out-42.mta0.migadu.com (out-42.mta0.migadu.com [91.218.175.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 844623AA8 for ; Thu, 20 Jul 2023 02:47:36 -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=1689846454; 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=p34J6xnRb86eKyDcpXgSq81rjV9gO+WCulIJcSmybAc=; b=FO6tJlnKG0PcTyIP5O724vhJaUPzs5PqLkd247BAIxAFGdYM4v7WurTFDGaN1YoOreq4c4 b/h8BL7Yc08WxbDl3yG4Uw0l/8qSIJEuH5EsaTErtlXjMS1BEQPE+uV6BtlyiezOPVg7ob IdnA189BksTiUPxZouFvEL2EiJX56tI= 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 5/6] sbitmap: wake_index doesn't need to be atomic_t Date: Thu, 20 Jul 2023 17:45:54 +0800 Message-ID: <20230720094555.1397621-6-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=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 use wake_index to remember from which to wake up next time, which doesn't need to be atomic_t since we only read it once before wakeups, and write it once after wakeups. Signed-off-by: Chengming Zhou --- include/linux/sbitmap.h | 2 +- lib/sbitmap.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h index d662cf136021..bdbe478ba4dc 100644 --- a/include/linux/sbitmap.h +++ b/include/linux/sbitmap.h @@ -116,7 +116,7 @@ struct sbitmap_queue { /** * @wake_index: Next wait queue in @ws to wake up. */ - atomic_t wake_index; + unsigned int wake_index; /** * @ws: Wait queues. diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 50bdf3a31947..6778ab3fc6a5 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -419,7 +419,7 @@ int sbitmap_queue_init_node(struct sbitmap_queue *sbq, unsigned int depth, sbq->min_shallow_depth = UINT_MAX; sbq->wake_batch = sbq_calc_wake_batch(sbq, depth); - atomic_set(&sbq->wake_index, 0); + sbq->wake_index = 0; atomic_set(&sbq->ws_active, 0); atomic_set(&sbq->completion_cnt, 0); atomic_set(&sbq->wakeup_cnt, 0); @@ -549,7 +549,7 @@ static void __sbitmap_queue_wake_up(struct sbitmap_queue *sbq, int nr) if (!atomic_read(&sbq->ws_active)) return; - wake_index = atomic_read(&sbq->wake_index); + wake_index = READ_ONCE(sbq->wake_index); for (i = 0; i < SBQ_WAIT_QUEUES; i++) { struct sbq_wait_state *ws = &sbq->ws[wake_index]; @@ -570,8 +570,8 @@ static void __sbitmap_queue_wake_up(struct sbitmap_queue *sbq, int nr) break; } - if (wake_index != atomic_read(&sbq->wake_index)) - atomic_set(&sbq->wake_index, wake_index); + if (wake_index != READ_ONCE(sbq->wake_index)) + WRITE_ONCE(sbq->wake_index, wake_index); } void sbitmap_queue_wake_up(struct sbitmap_queue *sbq, int nr) @@ -672,7 +672,7 @@ void sbitmap_queue_wake_all(struct sbitmap_queue *sbq) * sbitmap_queue_wake_up(). */ smp_mb(); - wake_index = atomic_read(&sbq->wake_index); + wake_index = READ_ONCE(sbq->wake_index); for (i = 0; i < SBQ_WAIT_QUEUES; i++) { struct sbq_wait_state *ws = &sbq->ws[wake_index]; @@ -702,7 +702,7 @@ void sbitmap_queue_show(struct sbitmap_queue *sbq, struct seq_file *m) seq_puts(m, "}\n"); seq_printf(m, "wake_batch=%u\n", sbq->wake_batch); - seq_printf(m, "wake_index=%d\n", atomic_read(&sbq->wake_index)); + seq_printf(m, "wake_index=%d\n", READ_ONCE(sbq->wake_index)); seq_printf(m, "ws_active=%d\n", atomic_read(&sbq->ws_active)); seq_puts(m, "ws={\n"); -- 2.41.0