--- a/lib/kref.c 2006-01-30 06:11:04.000000000 +0100 +++ b/lib/kref.c 2006-01-30 06:13:32.000000000 +0100 @@ -52,7 +52,12 @@ WARN_ON(release == NULL); WARN_ON(release == (void (*)(struct kref *))kfree); - if (atomic_dec_and_test(&kref->refcount)) { + /* + * 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; }