Commit 8b5536bb authored by Eric Dumazet's avatar Eric Dumazet Committed by Greg Kroah-Hartman

[PATCH] kref: avoid an atomic operation in kref_put()

Avoid an atomic operation in kref_put() when the last reference is
dropped. On most platforms, atomic_read() is a plan read of the counter
and involves no atomic at all.
Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 48944738
...@@ -52,7 +52,12 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref)) ...@@ -52,7 +52,12 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
WARN_ON(release == NULL); WARN_ON(release == NULL);
WARN_ON(release == (void (*)(struct kref *))kfree); 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); release(kref);
return 1; return 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment