Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp534732rwb; Thu, 10 Nov 2022 04:24:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7zFPVBa+Y+kCJvSpLSTOR8cDz/eJgQXZmYdMfBePi/mayx4OCsUtmeFU7x1f8Vc5vhpf4E X-Received: by 2002:a17:903:324a:b0:188:8117:7221 with SMTP id ji10-20020a170903324a00b0018881177221mr19803381plb.90.1668083048578; Thu, 10 Nov 2022 04:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668083048; cv=none; d=google.com; s=arc-20160816; b=CVwMc+G0fOHKMol4CL/lSH+z3EucfNlPEC9NxJ1uZ8l3wyGhE4IEKYLSxuJd1vJTdj n79zn3yjrMPEQ9JsUwlfp/fVre5rMc8mpNyzHMV78rRN+uoB+GqYe4CQSJ+myycW+VvE 30XOFgWIiZt9zCQnakEvpR2ntknvjoJyOvV4TppkfvBJH6NjEri6HEmiU8+PUzNHrHGZ 02TgruzSEkU5Y3ayy+imipU/LVhe5Zl5ENfmgzbRM3yJhNuikpGmAGdgkUenDB0gy0in L8zxj7918UJ21RoKC2ID3Up04N5Q9bh5jOfDL5fRpX3sh7Z3FY4z2kVkVHECEq1L7BdL 0QdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=xHmb3oZbqQEN2yJ2OZBtB3fE443Vekbcfy5OMkh4FoU=; b=obm18JEQYGsV+Llgl/glEZE5A1M6tavoOqxb3sx3dJmwCxWyhqILjbfhFuzUDQ8mVK SxL/zsxFek82zVo9lw3XV+sZgSQd5BmRDdN5HbB1y+66lHrtlffF9XhoFLO0TzjMd2KW ypDj7952Tse/4gX8EvVJMiRFmzOVKVY8nbiW8L+68WhqRvj7zFlOATuPJpwhvDslz2vi k4LUcUKRc+WUR8Fa4PLs4tuRiB8L2Fk2xqaN6Y1/PcwMhVOwXCMHVe/Dw3o4xX9OKRlb gxpZ0QIu9KV6QbAge5WfTtR2xGWmnqd6ZZOa6J5BMWcpdzoNdAOp5qxLYYCWh3qbuE4i 2Oyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=faa5aXYu; dkim=neutral (no key) header.i=@suse.cz; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oa8-20020a17090b1bc800b0020da8f11bb3si4829780pjb.14.2022.11.10.04.23.55; Thu, 10 Nov 2022 04:24:08 -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; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=faa5aXYu; dkim=neutral (no key) header.i=@suse.cz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbiKJLQt (ORCPT + 92 others); Thu, 10 Nov 2022 06:16:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbiKJLQl (ORCPT ); Thu, 10 Nov 2022 06:16:41 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A36521E0D; Thu, 10 Nov 2022 03:16:38 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3C1C31F90A; Thu, 10 Nov 2022 11:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1668078997; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xHmb3oZbqQEN2yJ2OZBtB3fE443Vekbcfy5OMkh4FoU=; b=faa5aXYuwYMSFIRpCm0mRYfKg/dMt92rAPxzwNsqqtNEQYdUYTbbEs/fWgbJGxApkqAVVi QqwBbnDWPGk7EOIQ9wGWw8n6PGZvjsgz1ZwoTpvNV7YoOxqX6ergWgJsTaTABwTSCqTDGv QYQ55us6gBk3Y3JrexkeVSCu4cWSU+4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1668078997; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xHmb3oZbqQEN2yJ2OZBtB3fE443Vekbcfy5OMkh4FoU=; b=WbGADlX1QvbVwk2hD1MKzKbt8f7UerQ+VGfdBWDd+6jjfCsO1U56p1159vLpTmPIE9I1Mt fzjOHSxeLcdmSwCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2A7B913B58; Thu, 10 Nov 2022 11:16:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id RlB6CpXdbGOZKwAAMHmgww (envelope-from ); Thu, 10 Nov 2022 11:16:37 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 985C7A0704; Thu, 10 Nov 2022 12:16:36 +0100 (CET) Date: Thu, 10 Nov 2022 12:16:36 +0100 From: Jan Kara To: Yu Kuai Cc: Gabriel Krisman Bertazi , axboe@kernel.dk, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Hugh Dickins , Keith Busch , Liu Song , Jan Kara , "yukuai (C)" Subject: Re: [PATCH] sbitmap: Use single per-bitmap counting to wake up queued tags Message-ID: <20221110111636.ufgyp4tkbzexugk2@quack3> References: <20221105231055.25953-1-krisman@suse.de> <2a445c5c-fd15-c0bf-8655-2fb5bde3fe67@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2a445c5c-fd15-c0bf-8655-2fb5bde3fe67@huaweicloud.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Hi! On Thu 10-11-22 17:42:49, Yu Kuai wrote: > 在 2022/11/06 7:10, Gabriel Krisman Bertazi 写道: > > +void sbitmap_queue_wake_up(struct sbitmap_queue *sbq, int nr) > > { > > - struct sbq_wait_state *ws; > > - unsigned int wake_batch; > > - int wait_cnt, cur, sub; > > - bool ret; > > + unsigned int wake_batch = READ_ONCE(sbq->wake_batch); > > + struct sbq_wait_state *ws = NULL; > > + unsigned int wakeups; > > - if (*nr <= 0) > > - return false; > > + if (!atomic_read(&sbq->ws_active)) > > + return; > > - ws = sbq_wake_ptr(sbq); > > - if (!ws) > > - return false; > > + atomic_add(nr, &sbq->completion_cnt); > > + wakeups = atomic_read(&sbq->wakeup_cnt); > > - cur = atomic_read(&ws->wait_cnt); > > do { > > - /* > > - * For concurrent callers of this, callers should call this > > - * function again to wakeup a new batch on a different 'ws'. > > - */ > > - if (cur == 0) > > - return true; > > - sub = min(*nr, cur); > > - wait_cnt = cur - sub; > > - } while (!atomic_try_cmpxchg(&ws->wait_cnt, &cur, wait_cnt)); > > - > > - /* > > - * If we decremented queue without waiters, retry to avoid lost > > - * wakeups. > > - */ > > - if (wait_cnt > 0) > > - return !waitqueue_active(&ws->wait); > > + if (atomic_read(&sbq->completion_cnt) - wakeups < wake_batch) > > + return; > > Should it be considered that completion_cnt overflow and becomes > negtive? Yes, the counters can (and will) certainly overflow but since we only care about (completion_cnt - wakeups), we should be fine - this number is always sane (and relatively small) and in the kernel we do compile with signed overflows being well defined. Honza -- Jan Kara SUSE Labs, CR