dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: San Mehat <san@google.com>
To: dm-devel@redhat.com
Cc: San Mehat <san@google.com>, Brian Swetland <swetland@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christophe Saout <christophe@saout.de>,
	Milan Broz <mbroz@redhat.com>
Subject: [PATCH] md: dm-crypt: Add option to re-use a new global work-queue.
Date: Thu, 22 Apr 2010 10:48:58 -0700	[thread overview]
Message-ID: <1271958538-11193-1-git-send-email-san@google.com> (raw)

Typically, dm-crypt instances each have their own set of kcrypt/kcrypt_io
work-queues. This patch adds an option which will create one set of
work-queues on init, and re-uses them for all dm-crypt target instances.

Cc: Milan Broz <mbroz@redhat.com>
Cc: Brian Swetland <swetland@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Christophe Saout <christophe@saout.de>
Signed-off-by: San Mehat <san@google.com>
---
 drivers/md/Kconfig    |   10 ++++++++++
 drivers/md/dm-crypt.c |   42 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 2158377..8d82dfc 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -244,6 +244,16 @@ config DM_CRYPT
 
 	  If unsure, say N.
 
+config DM_CRYPT_GLOBAL_WORKQUEUES
+	boolean "Use global instead of per-device work-queues"
+	depends on DM_CRYPT
+	---help---
+	  Normally 2 kernel work-queue threads are created for every
+	  dm-crypt target. This option creates only 1 set of work-queues
+	  on init, and re-uses them.
+
+	  If unsure, say N.
+
 config DM_SNAPSHOT
        tristate "Snapshot target"
        depends on BLK_DEV_DM
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 959d6d1..875ad9a 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -104,8 +104,10 @@ struct crypt_config {
 	mempool_t *page_pool;
 	struct bio_set *bs;
 
+#ifndef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
 	struct workqueue_struct *io_queue;
 	struct workqueue_struct *crypt_queue;
+#endif
 
 	/*
 	 * crypto related data
@@ -148,6 +150,10 @@ struct crypt_config {
 #define MIN_BIO_PAGES  8
 
 static struct kmem_cache *_crypt_io_pool;
+#ifdef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
+static struct workqueue_struct *_io_queue;
+static struct workqueue_struct *_crypt_queue;
+#endif
 
 static void clone_init(struct dm_crypt_io *, struct bio *);
 static void kcryptd_queue_crypt(struct dm_crypt_io *io);
@@ -730,7 +736,11 @@ static void kcryptd_queue_io(struct dm_crypt_io *io)
 	struct crypt_config *cc = io->target->private;
 
 	INIT_WORK(&io->work, kcryptd_io);
+#ifdef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
+	queue_work(_io_queue, &io->work);
+#else
 	queue_work(cc->io_queue, &io->work);
+#endif
 }
 
 static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io,
@@ -914,7 +924,11 @@ static void kcryptd_queue_crypt(struct dm_crypt_io *io)
 	struct crypt_config *cc = io->target->private;
 
 	INIT_WORK(&io->work, kcryptd_crypt);
+#ifdef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
+	queue_work(_crypt_queue, &io->work);
+#else
 	queue_work(cc->crypt_queue, &io->work);
+#endif
 }
 
 /*
@@ -1165,6 +1179,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	} else
 		cc->iv_mode = NULL;
 
+#ifndef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
 	cc->io_queue = create_singlethread_workqueue("kcryptd_io");
 	if (!cc->io_queue) {
 		ti->error = "Couldn't create kcryptd io queue";
@@ -1174,15 +1189,15 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	cc->crypt_queue = create_singlethread_workqueue("kcryptd");
 	if (!cc->crypt_queue) {
 		ti->error = "Couldn't create kcryptd queue";
-		goto bad_crypt_queue;
+		destroy_workqueue(cc->io_queue);
+		goto bad_io_queue;
 	}
+#endif
 
 	ti->num_flush_requests = 1;
 	ti->private = cc;
 	return 0;
 
-bad_crypt_queue:
-	destroy_workqueue(cc->io_queue);
 bad_io_queue:
 	kfree(cc->iv_mode);
 bad_ivmode_string:
@@ -1210,8 +1225,10 @@ static void crypt_dtr(struct dm_target *ti)
 {
 	struct crypt_config *cc = (struct crypt_config *) ti->private;
 
+#ifndef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
 	destroy_workqueue(cc->io_queue);
 	destroy_workqueue(cc->crypt_queue);
+#endif
 
 	if (cc->req)
 		mempool_free(cc->req, cc->req_pool);
@@ -1399,6 +1416,21 @@ static int __init dm_crypt_init(void)
 {
 	int r;
 
+#ifdef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
+	_io_queue = create_singlethread_workqueue("kcryptd_io");
+	if (!_io_queue) {
+		DMERR("couldn't create kcryptd io queue");
+		return -ENOMEM;
+	}
+
+	_crypt_queue = create_singlethread_workqueue("kcryptd");
+	if (!_crypt_queue) {
+		DMERR("couldn't create kcryptd queue");
+		destroy_workqueue(_io_queue);
+		return -ENOMEM;
+	}
+#endif
+
 	_crypt_io_pool = KMEM_CACHE(dm_crypt_io, 0);
 	if (!_crypt_io_pool)
 		return -ENOMEM;
@@ -1416,6 +1448,10 @@ static void __exit dm_crypt_exit(void)
 {
 	dm_unregister_target(&crypt_target);
 	kmem_cache_destroy(_crypt_io_pool);
+#ifdef CONFIG_DM_CRYPT_GLOBAL_WORKQUEUES
+	destroy_workqueue(_io_queue);
+	destroy_workqueue(_crypt_queue);
+#endif
 }
 
 module_init(dm_crypt_init);
-- 
1.7.0.1

             reply	other threads:[~2010-04-22 17:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-22 17:48 San Mehat [this message]
2010-04-22 18:03 ` [PATCH] md: dm-crypt: Add option to re-use a new global work-queue Milan Broz
2010-04-22 18:08   ` San Mehat
2010-04-22 18:47     ` Milan Broz
2010-04-22 19:42       ` San Mehat
2010-04-23 14:01         ` Heinz Mauelshagen
2010-04-27 20:58         ` San Mehat
2010-11-02 22:02           ` cmwq and dm-crypt devices? (was: Re: md: dm-crypt: Add option to re-use a new global work-queue.) Mike Snitzer
2010-11-03  9:46             ` cmwq and dm-crypt devices? Tejun Heo
2010-11-03 11:51               ` Andi Kleen
2010-11-03 11:56                 ` Milan Broz
2010-11-03 12:33                   ` Andi Kleen
2010-11-03 13:02                     ` Milan Broz
2010-11-03 13:18                     ` Alasdair G Kergon
2010-11-03 16:13                       ` Andi Kleen
2010-11-03 16:17                         ` Tejun Heo
2010-11-03 16:22                           ` Milan Broz
2010-11-04  9:55                             ` Andi Kleen

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=1271958538-11193-1-git-send-email-san@google.com \
    --to=san@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=christophe@saout.de \
    --cc=dm-devel@redhat.com \
    --cc=mbroz@redhat.com \
    --cc=swetland@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).