Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754939AbcKUPtf (ORCPT ); Mon, 21 Nov 2016 10:49:35 -0500 Received: from merlin.infradead.org ([205.233.59.134]:52244 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754918AbcKUPte (ORCPT ); Mon, 21 Nov 2016 10:49:34 -0500 Date: Mon, 21 Nov 2016 16:49:15 +0100 From: Peter Zijlstra To: "Reshetova, Elena" Cc: David Windsor , Alexei Starovoitov , Kees Cook , Greg KH , Will Deacon , Arnd Bergmann , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , LKML , Daniel Borkmann Subject: Re: [RFC][PATCH 2/7] kref: Add kref_read() Message-ID: <20161121154915.GB3124@twins.programming.kicks-ass.net> References: <20161117085342.GB3142@twins.programming.kicks-ass.net> <20161117161937.GA46515@ast-mbp.thefacebook.com> <2236FBA76BA1254E88B949DDB74E612B41C14BB4@IRSMSX102.ger.corp.intel.com> <2236FBA76BA1254E88B949DDB74E612B41C15583@IRSMSX102.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2236FBA76BA1254E88B949DDB74E612B41C15583@IRSMSX102.ger.corp.intel.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 941 Lines: 25 On Mon, Nov 21, 2016 at 03:39:19PM +0000, Reshetova, Elena wrote: > > By the way, there are several sites where the use of > > atomic_t/atomic_wrap_t as a counter ventures beyond the standard (inc, > > dec, add, sub, read, set) operations we're planning on implementing > > for both refcount_t and stats_t. > > Speaking of non-fitting patterns. This one is quite common in > networking code for refcounters: > > if (atomic_cmpxchg(&cur->refcnt, 1, 0) == 1) {} This is from > net/netfilter/nfnetlink_acct.c, but there are similar ones in other > places. Cute, but weird it doesn't actually decrement if not 1. > Also, simple atomic_dec() is used pretty much everywhere for counters, > which we don’t have a straight match in refcount_t API. WARN_ON(refcount_dec_and_test(refs)); And seeing how I've implememented refcount_inc() in similar terms: WARN_ON(!refcount_inc_not_zero(refs)); It might make sense to actually provide that.