From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BD27C433B4 for ; Thu, 15 Apr 2021 10:34:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BC666137D for ; Thu, 15 Apr 2021 10:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230526AbhDOKef (ORCPT ); Thu, 15 Apr 2021 06:34:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46046 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbhDOKef (ORCPT ); Thu, 15 Apr 2021 06:34:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618482852; 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=oi3Sd0OUrlMjtsLbv2z+fg1JsicP7YegqK4bHsIStuc=; b=H4tO6I2Vu4eo83GWA1oi3FjNP4BBR6ggC/6kV6hrT71357AhWFpv3hFmoH1dOqkmb+h2S+ 7htscYhmSeP21Cm0dTlHNte4bVoyn17uyvsPtTDQWgBfQcbg1owD8CSROvK71qqp1WYoOr pKjw3Kef9geKjb7kG8GtAvmazQbLQ+w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-560-5aR0btvYN7qUSfkf0icajg-1; Thu, 15 Apr 2021 06:34:08 -0400 X-MC-Unique: 5aR0btvYN7qUSfkf0icajg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BE4A6D582; Thu, 15 Apr 2021 10:34:07 +0000 (UTC) Received: from localhost (ovpn-13-200.pek2.redhat.com [10.72.13.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3101262462; Thu, 15 Apr 2021 10:33:56 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Jeffle Xu , Mike Snitzer , dm-devel@redhat.com, linux-raid@vger.kernel.org, Song Liu , linux-nvme@lists.infradead.org, Ming Lei , Tejun Heo , Christoph Hellwig , Bart Van Assche Subject: [RFC PATCH 1/2] percpu_ref: add percpu_ref_tryget_many_live Date: Thu, 15 Apr 2021 18:33:09 +0800 Message-Id: <20210415103310.1513841-2-ming.lei@redhat.com> In-Reply-To: <20210415103310.1513841-1-ming.lei@redhat.com> References: <20210415103310.1513841-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Prepare for support freezing bio based request queues. Cc: Tejun Heo Cc: Christoph Hellwig Cc: Bart Van Assche Signed-off-by: Ming Lei --- include/linux/percpu-refcount.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index 16c35a728b4c..9061c7e3113d 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -267,8 +267,9 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) } /** - * percpu_ref_tryget_live - try to increment a live percpu refcount + * percpu_ref_tryget_many_live - try to increment a live percpu refcount * @ref: percpu_ref to try-get + * @nr: number of references to get * * Increment a percpu refcount unless it has already been killed. Returns * %true on success; %false on failure. @@ -281,7 +282,8 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) * * This function is safe to call as long as @ref is between init and exit. */ -static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) +static inline bool percpu_ref_tryget_many_live(struct percpu_ref *ref, + unsigned long nr) { unsigned long __percpu *percpu_count; bool ret = false; @@ -289,10 +291,10 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) rcu_read_lock(); if (__ref_is_percpu(ref, &percpu_count)) { - this_cpu_inc(*percpu_count); + this_cpu_add(*percpu_count, nr); ret = true; } else if (!(ref->percpu_count_ptr & __PERCPU_REF_DEAD)) { - ret = atomic_long_inc_not_zero(&ref->data->count); + ret = atomic_long_add_unless(&ref->data->count, nr, 0); } rcu_read_unlock(); @@ -300,6 +302,26 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) return ret; } +/** + * percpu_ref_tryget_live - try to increment a live percpu refcount + * @ref: percpu_ref to try-get + * + * Increment a percpu refcount unless it has already been killed. Returns + * %true on success; %false on failure. + * + * Completion of percpu_ref_kill() in itself doesn't guarantee that this + * function will fail. For such guarantee, percpu_ref_kill_and_confirm() + * should be used. After the confirm_kill callback is invoked, it's + * guaranteed that no new reference will be given out by + * percpu_ref_tryget_live(). + * + * This function is safe to call as long as @ref is between init and exit. + */ +static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) +{ + return percpu_ref_tryget_many_live(ref, 1); +} + /** * percpu_ref_put_many - decrement a percpu refcount * @ref: percpu_ref to put -- 2.29.2