From: "Jörn Engel" <joern@logfs.org>
To: Roland Dreier <roland@purestorage.com>
Cc: "Nicholas A. Bellinger" <nab@linux-iscsi.org>,
target-devel@vger.kernel.org, Arun Easi <arun.easi@qlogic.com>,
linux-scsi <linux-scsi@vger.kernel.org>,
Steve Hodgson <steve@purestorage.com>
Subject: Re: [PATCH] qla_target: Check refcount in find_sess_by_*
Date: Thu, 17 May 2012 17:10:56 -0400 [thread overview]
Message-ID: <20120517211055.GF18067@logfs.org> (raw)
In-Reply-To: <20120517210521.GE18067@logfs.org>
And below is a patch that allows speeding up the fast path a bit.
The code in tcm_qla2xxx_put_session() would turn into this:
local_irq_save(flags);
if (kref_put_and_lock(&se_sess->sess_kref, &ha->hardware_lock,
target_release_session))
spin_unlock(&ha->hardware_lock);
local_irq_restore(flags);
I don't propose we do this yet, correct code is more important than
fast code at this point. But we should be able to reclaim most of the
performance impact - if it is actually measureable.
Jörn
--
The grand essentials of happiness are: something to do, something to
love, and something to hope for.
-- Allan K. Chalmers
[PATCH] kref: add kref_put_and_lock()
Similar to kref_put(), but will only take a lock (and a performance hit)
if the refcount drops to zero.
Signed-off-by: Joern Engel <joern@logfs.org>
---
include/linux/kref.h | 3 +++
lib/kref.c | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/include/linux/kref.h b/include/linux/kref.h
index d4a62ab..9581493 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -16,6 +16,7 @@
#define _KREF_H_
#include <linux/types.h>
+#include <linux/spinlock.h>
struct kref {
atomic_t refcount;
@@ -24,6 +25,8 @@ struct kref {
void kref_init(struct kref *kref);
void kref_get(struct kref *kref);
int kref_put(struct kref *kref, void (*release) (struct kref *kref));
+int kref_put_and_lock(struct kref *kref, spinlock_t *lock,
+ void (*release)(struct kref *kref));
int kref_sub(struct kref *kref, unsigned int count,
void (*release) (struct kref *kref));
diff --git a/lib/kref.c b/lib/kref.c
index 3efb882..07a82f3 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -62,6 +62,29 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
return 0;
}
+/**
+ * kref_put_and_lock - decrement refcount for object with locking
+ * @kref: object
+ * @lock: the lock to acquire when dropping the last refcount
+ * @release: pointer to the function that will clean up the object when the
+ * last reference to the object is released.
+ *
+ * Same as kref_put(), except that it will acquire the lock before dropping the
+ * last refcount. If the last refcount is dropped, the lock will be held on
+ * return and the return value will be 1.
+ */
+int kref_put_and_lock(struct kref *kref, spinlock_t *lock,
+ void (*release)(struct kref *kref))
+{
+ WARN_ON(release == NULL);
+ WARN_ON(release == (void (*)(struct kref *))kfree);
+
+ if (atomic_dec_and_lock(&kref->refcount, lock)) {
+ release(kref);
+ return 1;
+ }
+ return 0;
+}
/**
* kref_sub - subtract a number of refcounts for object.
--
1.7.10
next prev parent reply other threads:[~2012-05-17 21:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20120511143341.GA18753@logfs.org>
[not found] ` <20120517162600.GA18067@logfs.org>
2012-05-17 19:46 ` [PATCH] qla_target: Check refcount in find_sess_by_* Nicholas A. Bellinger
2012-05-17 20:49 ` Roland Dreier
2012-05-17 19:28 ` Jörn Engel
2012-05-17 21:05 ` Jörn Engel
2012-05-17 21:10 ` Jörn Engel [this message]
2012-05-18 2:02 ` Nicholas A. Bellinger
2012-05-18 1:15 ` Jörn Engel
2012-05-18 6:09 ` Nicholas A. Bellinger
2012-05-18 22:49 ` Jörn Engel
2012-05-19 1:26 ` Nicholas A. Bellinger
2012-05-21 22:18 ` Nicholas A. Bellinger
2012-05-17 21:24 ` Nicholas A. Bellinger
2012-05-17 19:56 ` Jörn Engel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120517211055.GF18067@logfs.org \
--to=joern@logfs.org \
--cc=arun.easi@qlogic.com \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@linux-iscsi.org \
--cc=roland@purestorage.com \
--cc=steve@purestorage.com \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.