Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752614Ab3FEHi3 (ORCPT ); Wed, 5 Jun 2013 03:38:29 -0400 Received: from ozlabs.org ([203.10.76.45]:52297 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079Ab3FEHi1 (ORCPT ); Wed, 5 Jun 2013 03:38:27 -0400 From: Rusty Russell To: Kent Overstreet , linux-kernel@vger.kernel.org Cc: Kent Overstreet , Zach Brown , Felipe Balbi , Greg Kroah-Hartman , Mark Fasheh , Joel Becker , Jens Axboe , Asai Thambi S P , Selvan Mani , Sam Bradshaw , Jeff Moyer , Al Viro , Benjamin LaHaise , Tejun Heo , Oleg Nesterov , Christoph Lameter , Ingo Molnar , Andrew Morton , "Paul McKenney" Subject: Re: [PATCH] Generic percpu refcounting In-Reply-To: <1370039205-14071-1-git-send-email-koverstreet@google.com> References: <1370039205-14071-1-git-send-email-koverstreet@google.com> User-Agent: Notmuch/0.15.2+81~gd2c8818 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Wed, 05 Jun 2013 17:05:09 +0930 Message-ID: <87d2s1rowi.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1536 Lines: 44 Kent Overstreet writes: > This implements a refcount with similar semantics to > atomic_get()/atomic_dec_and_test() - but percpu. > > It also implements two stage shutdown, as we need it to tear down the > percpu counts. Before dropping the initial refcount, you must call > percpu_ref_kill(); this puts the refcount in "shutting down mode" and > switches back to a single atomic refcount with the appropriate barriers > (synchronize_rcu()). > > It's also legal to call percpu_ref_kill() multiple times - it only returns > true once, so callers don't have to reimplement shutdown synchronization. > +static inline void percpu_ref_get(struct percpu_ref *ref) > +{ > + unsigned __percpu *pcpu_count; > + > + preempt_disable(); > + > + pcpu_count = ACCESS_ONCE(ref->pcpu_count); > + > + if (likely(REF_STATUS(pcpu_count) == PCPU_REF_PTR)) > + __this_cpu_inc(*pcpu_count); > + else > + atomic_inc(&ref->count); > + > + preempt_enable(); > +} I think this should be rcu_read_lock(), which is currently equivalent but theoretically different. Does your percpu_ref_kill() *really* need to be nonblocking? (I'd have to read your other patches which use this to be sure). Otherwise, just use synchronize_rcu(), and get rid of the release function... Cheers, Rusty. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/