Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262171AbVERLH4 (ORCPT ); Wed, 18 May 2005 07:07:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262169AbVERLH4 (ORCPT ); Wed, 18 May 2005 07:07:56 -0400 Received: from pat.uio.no ([129.240.130.16]:14843 "EHLO pat.uio.no") by vger.kernel.org with ESMTP id S262170AbVERLHh (ORCPT ); Wed, 18 May 2005 07:07:37 -0400 Subject: Re: [PATCH] fix race in mark_mounts_for_expiry() From: Trond Myklebust To: Miklos Szeredi Cc: dhowells@redhat.com, linuxram@us.ibm.com, jamie@shareable.org, viro@parcelfarce.linux.theplanet.co.uk, akpm@osdl.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org In-Reply-To: References: <1116005355.6248.372.camel@localhost> <1116012287.6248.410.camel@localhost> <1116013840.6248.429.camel@localhost> <1116256279.4154.41.camel@localhost> <20050516111408.GA21145@mail.shareable.org> <1116301843.4154.88.camel@localhost> <20050517012854.GC32226@mail.shareable.org> <1116360352.24560.85.camel@localhost> <1116399887.24560.116.camel@localhost> <1116400118.24560.119.camel@localhost> <6865.1116412354@redhat.com> <7230.1116413175@redhat.com> Content-Type: text/plain Date: Wed, 18 May 2005 07:07:09 -0400 Message-Id: <1116414429.10773.57.camel@lade.trondhjem.org> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-UiO-Spam-info: not spam, SpamAssassin (score=-4.95, required 12, autolearn=disabled, FORGED_RCVD_HELO 0.05, UIO_MAIL_IS_INTERNAL -5.00) Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1334 Lines: 41 on den 18.05.2005 Klokka 12:53 (+0200) skreiv Miklos Szeredi: > > Yes you can. cmpxchg() is atomic. Several archs implement atomic_inc() and co > > with cmpxchg() or similar. > > > > Something like: > > > > static inline struct namespace *grab_namespace(struct namespace *n) > > { > > int old = atomic_read(&n->count); > > > > while (old > 0) { > > /* attempt to increment the counter */ > > old = cmpxchg(&n->count, old, old + 1); > > } > > > > return old > 0 ? n : NULL; > > } > > > > Ahh OK :) > > There's still the problem of cmpxchg meddling in the internals of an > atomic_t. Is that OK? Will that work on all archs? Some archs already have an atomic_dec_if_positive() (see for instance the PPC). It won't take much work to convert that to an atomic_inc_if_positive(). For those arches that don't have that sort of thing, then writing a generic atomic_inc_if_positive() using cmpxchg() will often be possible, but there are exceptions (for instance the original 386 does not have a cmpxchg, so there you will have to use something else). Cheers, Trond - 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/