Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp39631rwb; Wed, 30 Nov 2022 21:39:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf6uH5Y5hovdK1FT3mobgV8LSRWzmeeCUdOhyi3kYatyznqCNlwdHz2itZubnsxZSJSBzd/Q X-Received: by 2002:a65:6c0d:0:b0:470:7886:e200 with SMTP id y13-20020a656c0d000000b004707886e200mr46401658pgu.111.1669873161903; Wed, 30 Nov 2022 21:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669873161; cv=none; d=google.com; s=arc-20160816; b=ORVUeRQWcQouZ5A4CvilxVns2+nRmMcEBKrJgXmK+oL7mLOt0xRKOhMgCV7g7EzN4Z 0UA49O40fPQAZmZrE2JN9bS4Pdfc+CfKcdhioWPoesxDMBOdaW6P9E52LUvTm3Z+Zuiz PH8Vx92f+TtDhfTXXIe/t94YTyo2v/+DQZqYlXZTv9jnJKVmUPmpAcFLHklmpKedUw1T QDX5kGILjy9ET2MEKdR4S/o3UIINbxSVS6BcNs3fEwZftoGLMEzXuT4tCqZDn1TPpxBj BSe+/gw/pvZj6u7kZIN9awyFC4IdCxPcl4a4O8TzCLnBxf0CE8rQMu6CVYfEVXjY+6DS CmWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+qYHcydYynGpb5+uiW7pbsJZIAgZUgq1sTrJtP5PI+A=; b=T6mJRfLrrb7J+vpXu4FFxRBGzouycm2vL37/I/s4PA0bTfRBaolGcwyaKjdHgh7/Vp brRbXb/0LnS2zx0tFl/Mx8xFHr2Z62IcPQw9qu4avsKZ4hIvlLWl0R6fdlsVDYbwF11Z Rs+bxwejl4USsGfzzzObyYE2pBqJKuyTeoDWtpVDJWcEEvE5GlxS1c08QtoUuiGrWCYx dptRMy5gfiZwnB5T7Q+2flylW9tx8pRdFtQ9bKhhEk3TXQGhFEzebZCPCyE/ilLFUNPC 7lzcrMVLJaXSQsvQsq750JyXhs1OpqSIOCnlysUJgE0Jmsv7pJxQAHZV/5nabElBoYXw BNlg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020a631c03000000b00476d0c7b644si3541266pgc.290.2022.11.30.21.39.11; Wed, 30 Nov 2022 21:39:21 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiLAEzI (ORCPT + 83 others); Wed, 30 Nov 2022 23:55:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiLAEy5 (ORCPT ); Wed, 30 Nov 2022 23:54:57 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B065F9FEC7; Wed, 30 Nov 2022 20:54:56 -0800 (PST) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NN3ch0VwhzHwN9; Thu, 1 Dec 2022 12:53:40 +0800 (CST) Received: from huawei.com (10.174.178.129) by kwepemi500016.china.huawei.com (7.221.188.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 1 Dec 2022 12:54:11 +0800 From: Kemeng Shi To: CC: , , , , Subject: [PATCH 3/5] sbitmap: remove redundant check in __sbitmap_queue_get_batch Date: Thu, 1 Dec 2022 12:54:06 +0800 Message-ID: <20221201045408.21908-4-shikemeng@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20221201045408.21908-1-shikemeng@huawei.com> References: <20221201045408.21908-1-shikemeng@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.178.129] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500016.china.huawei.com (7.221.188.220) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 Commit fbb564a557809 ("lib/sbitmap: Fix invalid loop in __sbitmap_queue_get_batch()") mentioned that "Checking free bits when setting the target bits. Otherwise, it may reuse the busying bits." This commit add check to make sure all masked bits in word before cmpxchg is zero. Then the existing check after cmpxchg to check any zero bit is existing in masked bits in word is redundant. Actually, old value of word before cmpxchg is stored in val and we will filter out busy bits in val by "(get_mask & ~val)" after cmpxchg. So we will not reuse busy bits methioned in commit fbb564a557809 ("lib/sbitmap: Fix invalid loop in __sbitmap_queue_get_batch()"). Revert new-added check to remove redundant check. Signed-off-by: Kemeng Shi --- lib/sbitmap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/sbitmap.c b/lib/sbitmap.c index 791edf5ea4ca..70b62b1e40a1 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -534,11 +534,9 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags, get_mask = ((1UL << nr_tags) - 1) << nr; val = READ_ONCE(map->word); - do { - if ((val & ~get_mask) != val) - goto next; - } while (!atomic_long_try_cmpxchg(ptr, &val, - get_mask | val)); + while (!atomic_long_try_cmpxchg(ptr, &val, + get_mask | val)) + ; get_mask = (get_mask & ~val) >> nr; if (get_mask) { *offset = nr + (index << sb->shift); -- 2.30.0