lkml.org 
[lkml]   [2006]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: kref refcnt and false positives
On Wed, 13 Dec 2006 16:12:46 -0800
Greg KH <gregkh@suse.de> wrote:

> > Original comment seemed to indicate that this conditional thing was
> > performance related. Is it really? If not, we should consider the below patch.
>
> Yes, it's a performance gain and I don't see how this patch would change
> the above warning.

I suspect it's a false optimisation.

int kref_put(struct kref *kref, void (*release)(struct kref *kref))
{
WARN_ON(release == NULL);
WARN_ON(release == (void (*)(struct kref *))kfree);

/*
* if current count is one, we are the last user and can release object
* right now, avoiding an atomic operation on 'refcount'
*/
if ((atomic_read(&kref->refcount) == 1) ||
(atomic_dec_and_test(&kref->refcount))) {
release(kref);
return 1;
}
return 0;
}

The only time we avoid the atomic_dec_and_test() is when the object is
about to be freed. ie: once in its entire lifetime. And freeing the
object is part of an expensive (and rare) operation anyway.

otoh, we've gone and added a test-n-branch to the common case: those cases
where the object will not be freed.

-
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/

\
 
 \ /
  Last update: 2006-12-14 01:45    [W:0.057 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site