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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAA0BC433FE for ; Thu, 21 Oct 2021 14:01:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 479346112D for ; Thu, 21 Oct 2021 14:01:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 479346112D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A66FB6B0071; Thu, 21 Oct 2021 10:01:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A16A76B0072; Thu, 21 Oct 2021 10:01:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 905046B0073; Thu, 21 Oct 2021 10:01:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 7FA6C6B0071 for ; Thu, 21 Oct 2021 10:01:30 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 472E282499B9 for ; Thu, 21 Oct 2021 14:01:30 +0000 (UTC) X-FDA: 78720607140.37.094BBA7 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf07.hostedemail.com (Postfix) with ESMTP id 23B5D10004D2 for ; Thu, 21 Oct 2021 14:01:32 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id o20so463647qvk.7 for ; Thu, 21 Oct 2021 07:01:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0U+RWvmwzZQnDHkZFAiKquq3sy5BuzvtMKBzB6NsKtY=; b=5WoIkoSR35Jn9Y+ngWxKx6m9lbyMXaFbM0e1she5mbmjwdVb9Jf40yhjlfs2c2ANAd WRVe5PDypupe8VuR/4qROzepDYkWtPxsJfxoimy3EK/HGCKYLpATe9JBjNRVkljS84Ub 481q7t/Mmyd7QhG52//0N9nnw2M6gZTp8+tRHLP8e+bVoE4giBJU3XtpQKEoalwADo8M 4Im4PQQ15tCICGvkM9HBoa9hG5NlZ9yl34Gp98smHciB+HjpAUxll8BTXZeIxdylE2ZR vKBOV2bTeiYUMP1EIorRVJv23GfEq15G4aLUib7+zLY5RBcRNksTUOv8p0U1sRSeaOma gQbw== X-Gm-Message-State: AOAM530CopCQwui+dLCAZzmpN0SwdiV4ClESLz5CmF2uMbzSdKGOonvJ owX+4TWzndQpCfuKBB4w1ew= X-Google-Smtp-Source: ABdhPJw2uX2rarXlJXea4IjdYD5evpOPewmF56bfTV7aJEvMs0lg3dzF+7TzoFHZy8QqOXi5pg+JFw== X-Received: by 2002:a05:6214:144c:: with SMTP id b12mr5514294qvy.56.1634824887011; Thu, 21 Oct 2021 07:01:27 -0700 (PDT) Received: from fedora (pool-173-68-57-129.nycmny.fios.verizon.net. [173.68.57.129]) by smtp.gmail.com with ESMTPSA id b2sm2446805qtg.88.2021.10.21.07.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 07:01:26 -0700 (PDT) Date: Thu, 21 Oct 2021 10:01:24 -0400 From: Dennis Zhou To: Pavel Begunkov Cc: linux-block@vger.kernel.org, Jens Axboe , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Lameter , Tejun Heo Subject: Re: [PATCH v2 1/2] percpu_ref: percpu_ref_tryget_live() version holding RCU Message-ID: References: <3066500d7a6eb3e03f10adf98b87fdb3b1c49db8.1634822969.git.asml.silence@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3066500d7a6eb3e03f10adf98b87fdb3b1c49db8.1634822969.git.asml.silence@gmail.com> X-Stat-Signature: 6k6bsb15e8m1x6cmq969ebkciuwgsio5 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 23B5D10004D2 Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf07.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.219.53 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com X-HE-Tag: 1634824892-33873 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello, On Thu, Oct 21, 2021 at 02:30:51PM +0100, Pavel Begunkov wrote: > Add percpu_ref_tryget_live_rcu(), which is a version of > percpu_ref_tryget_live() but the user is responsible for enclosing it in > a RCU read lock section. > > Signed-off-by: Pavel Begunkov > --- > include/linux/percpu-refcount.h | 33 +++++++++++++++++++++++---------- > 1 file changed, 23 insertions(+), 10 deletions(-) > > diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h > index ae16a9856305..b31d3f3312ce 100644 > --- a/include/linux/percpu-refcount.h > +++ b/include/linux/percpu-refcount.h > @@ -266,6 +266,28 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) > return percpu_ref_tryget_many(ref, 1); > } > > +/** > + * percpu_ref_tryget_live_rcu - same as percpu_ref_tryget_live() but the > + * caller is responsible for taking RCU. > + * > + * This function is safe to call as long as @ref is between init and exit. > + */ > +static inline bool percpu_ref_tryget_live_rcu(struct percpu_ref *ref) > +{ > + unsigned long __percpu *percpu_count; > + bool ret = false; > + > + WARN_ON_ONCE(!rcu_read_lock_held()); > + > + if (likely(__ref_is_percpu(ref, &percpu_count))) { > + this_cpu_inc(*percpu_count); > + ret = true; > + } else if (!(ref->percpu_count_ptr & __PERCPU_REF_DEAD)) { > + ret = atomic_long_inc_not_zero(&ref->data->count); > + } > + return ret; > +} > + > /** > * percpu_ref_tryget_live - try to increment a live percpu refcount > * @ref: percpu_ref to try-get Nit: it's dumb convention at this point, but do you mind copying this guy up. I like consistency. > @@ -283,20 +305,11 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) > */ > static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) > { > - unsigned long __percpu *percpu_count; > bool ret = false; > > rcu_read_lock(); > - > - if (__ref_is_percpu(ref, &percpu_count)) { > - this_cpu_inc(*percpu_count); > - ret = true; > - } else if (!(ref->percpu_count_ptr & __PERCPU_REF_DEAD)) { > - ret = atomic_long_inc_not_zero(&ref->data->count); > - } > - > + ret = percpu_ref_tryget_live_rcu(ref); > rcu_read_unlock(); > - > return ret; > } > > -- > 2.33.1 > Currently I'm not carrying anything and I don't expect any percpu_ref work to come in. Jens, feel free to pick this up. Acked-by: Dennis Zhou Thanks, Dennis