linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dennis Zhou <dennis@kernel.org>, Christoph Lameter <cl@linux.com>
Subject: Re: [PATCH 1/2] pcpu_ref: add percpu_ref_tryget_many()
Date: Wed, 18 Dec 2019 08:26:42 -0800	[thread overview]
Message-ID: <20191218162642.GC2914998@devbig004.ftw2.facebook.com> (raw)
In-Reply-To: <fe13d615-0fae-23e3-f133-49b727973d14@kernel.dk>

(cc'ing Dennis and Christoph and quoting whole body)

Pavel, can you please cc percpu maintainers on related changes?

The patch looks fine to me.  Please feel free to add my acked-by.

On Tue, Dec 17, 2019 at 04:42:59PM -0700, Jens Axboe wrote:
> CC Tejun on this one. Looks fine to me, and matches the put path.
> 
> 
> On 12/17/19 3:28 PM, Pavel Begunkov wrote:
> > Add percpu_ref_tryget_many(), which works the same way as
> > percpu_ref_tryget(), but grabs specified number of refs.
> > 
> > Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> > ---
> >  include/linux/percpu-refcount.h | 24 ++++++++++++++++++++----
> >  1 file changed, 20 insertions(+), 4 deletions(-)
> > 
> > diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
> > index 390031e816dc..19079b62ce31 100644
> > --- a/include/linux/percpu-refcount.h
> > +++ b/include/linux/percpu-refcount.h
> > @@ -210,15 +210,17 @@ static inline void percpu_ref_get(struct percpu_ref *ref)
> >  }
> >  
> >  /**
> > - * percpu_ref_tryget - try to increment a percpu refcount
> > + * percpu_ref_tryget_many - try to increment a percpu refcount
> >   * @ref: percpu_ref to try-get
> > + * @nr: number of references to get
> >   *
> >   * Increment a percpu refcount unless its count already reached zero.
> >   * Returns %true on success; %false on failure.
> >   *
> >   * This function is safe to call as long as @ref is between init and exit.
> >   */
> > -static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> > +static inline bool percpu_ref_tryget_many(struct percpu_ref *ref,
> > +					  unsigned long nr)
> >  {
> >  	unsigned long __percpu *percpu_count;
> >  	bool ret;
> > @@ -226,10 +228,10 @@ static inline bool percpu_ref_tryget(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 {
> > -		ret = atomic_long_inc_not_zero(&ref->count);
> > +		ret = atomic_long_add_unless(&ref->count, nr, 0);
> >  	}
> >  
> >  	rcu_read_unlock();
> > @@ -237,6 +239,20 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> >  	return ret;
> >  }
> >  
> > +/**
> > + * percpu_ref_tryget - try to increment a percpu refcount
> > + * @ref: percpu_ref to try-get
> > + *
> > + * Increment a percpu refcount unless its count already reached zero.
> > + * Returns %true on success; %false on failure.
> > + *
> > + * This function is safe to call as long as @ref is between init and exit.
> > + */
> > +static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> > +{
> > +	return percpu_ref_tryget_many(ref, 1);
> > +}
> > +
> >  /**
> >   * percpu_ref_tryget_live - try to increment a live percpu refcount
> >   * @ref: percpu_ref to try-get
> > 
> 
> 
> -- 
> Jens Axboe
> 

-- 
tejun

  reply	other threads:[~2019-12-18 16:26 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17 22:28 [PATCH 0/2] optimise ctx's refs grabbing in io_uring Pavel Begunkov
2019-12-17 22:28 ` [PATCH 1/2] pcpu_ref: add percpu_ref_tryget_many() Pavel Begunkov
2019-12-17 23:42   ` Jens Axboe
2019-12-18 16:26     ` Tejun Heo [this message]
2019-12-18 17:49       ` Dennis Zhou
2019-12-21 15:36         ` Pavel Begunkov
2019-12-17 22:28 ` [PATCH 2/2] io_uring: batch getting pcpu references Pavel Begunkov
2019-12-17 23:21   ` Jens Axboe
2019-12-17 23:31     ` Jens Axboe
2019-12-18  9:25       ` Pavel Begunkov
2019-12-18  9:23     ` Pavel Begunkov
2019-12-18  0:02   ` Jens Axboe
2019-12-18 10:41     ` Pavel Begunkov
2019-12-21 16:15   ` [PATCH v2 0/3] optimise ctx's refs grabbing in io_uring Pavel Begunkov
2019-12-21 16:15     ` [PATCH v2 1/3] pcpu_ref: add percpu_ref_tryget_many() Pavel Begunkov
2019-12-21 16:15     ` [PATCH v2 2/3] io_uring: batch getting pcpu references Pavel Begunkov
2019-12-21 16:15     ` [PATCH RFC v2 3/3] io_uring: batch get(ctx->ref) across submits Pavel Begunkov
2019-12-21 16:20       ` Pavel Begunkov
2019-12-21 16:38         ` Jens Axboe
2019-12-21 16:48           ` Pavel Begunkov
2019-12-21 17:01             ` Jens Axboe
2019-12-21 17:26               ` Pavel Begunkov
2019-12-21 20:12       ` [PATCH v3 0/2] optimise ctx's refs grabbing in io_uring Pavel Begunkov
2019-12-21 20:12         ` [PATCH v3 1/2] pcpu_ref: add percpu_ref_tryget_many() Pavel Begunkov
2019-12-21 20:12         ` [PATCH v3 2/2] io_uring: batch getting pcpu references Pavel Begunkov
2019-12-21 21:56           ` Pavel Begunkov
2019-12-28 11:13         ` [PATCH v4 0/2] optimise ctx's refs grabbing in io_uring Pavel Begunkov
2019-12-28 11:13           ` [PATCH v4 1/2] pcpu_ref: add percpu_ref_tryget_many() Pavel Begunkov
2019-12-28 11:13           ` [PATCH v4 2/2] io_uring: batch getting pcpu references Pavel Begunkov
2019-12-28 11:15             ` Pavel Begunkov
2019-12-28 17:03               ` Jens Axboe
2019-12-28 18:37                 ` Pavel Begunkov
2019-12-30  3:33                   ` Brian Gianforcaro
2019-12-30 18:45                     ` Pavel Begunkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191218162642.GC2914998@devbig004.ftw2.facebook.com \
    --to=tj@kernel.org \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=cl@linux.com \
    --cc=dennis@kernel.org \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).