All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: dm-devel@redhat.com
Cc: Mikulas Patocka <mpatocka@redhat.com>
Subject: [PATCH 06/20] dm-crypt: Introduce an option that sets the number of threads.
Date: Tue, 21 Aug 2012 11:09:17 +0200	[thread overview]
Message-ID: <d05353ef83d887f765924a045681d69be3ec50e2.1345477953.git.mbroz@redhat.com> (raw)
In-Reply-To: <520994e0c87d38ca6abb8dd60760aef993842a32.1345477953.git.mbroz@redhat.com>
In-Reply-To: <cover.1345477953.git.mbroz@redhat.com>

Introduce an option "num_cpus". It allows the user to set the number of
threads used for encryption. The value "0" means a default.

The default is the number of CPUs in the system, but at most 3.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
---
 drivers/md/dm-crypt.c |   96 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 76 insertions(+), 20 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index b251e15..fd2909d 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -34,6 +34,8 @@
 #define DMREQ_PULL_BATCH			16
 #define DMREQ_PUSH_BATCH			16
 
+#define DM_CRYPT_DEFAULT_CPUS			3
+
 /*
  * context holding the current state of a multi-part conversion
  */
@@ -127,6 +129,7 @@ struct crypt_config {
 	struct workqueue_struct *io_queue;
 	struct workqueue_struct *crypt_queue;
 	unsigned crypt_threads_size;
+	int num_threads_value;	/* the value entered in the arguments */
 	struct task_struct **crypt_threads;
 
 	wait_queue_head_t crypt_thread_wait;
@@ -1630,9 +1633,14 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	struct dm_arg_set as;
 	const char *opt_string;
 	char dummy;
+	int num_threads = -1;
 
 	static struct dm_arg _args[] = {
-		{0, 1, "Invalid number of feature args"},
+		{0, INT_MAX, "Invalid number of feature args"},
+	};
+
+	static struct dm_arg num_cpu_arg[] = {
+		{0, 65536, "Number of CPUs"},
 	};
 
 	if (argc < 5) {
@@ -1716,18 +1724,31 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		if (ret)
 			goto bad;
 
-		opt_string = dm_shift_arg(&as);
-
-		if (opt_params == 1 && opt_string &&
-		    !strcasecmp(opt_string, "allow_discards"))
-			ti->num_discard_requests = 1;
-		else if (opt_params) {
-			ret = -EINVAL;
-			ti->error = "Invalid feature arguments";
-			goto bad;
+		for (i = 0; i < opt_params; i++) {
+			opt_string = dm_shift_arg(&as);
+			if (!strcasecmp(opt_string, "allow_discards")) {
+				ti->num_discard_requests = 1;
+			} else if (!strcasecmp(opt_string, "num_cpus") && i + 1 < opt_params) {
+				ret = dm_read_arg(num_cpu_arg, &as, &num_threads, &ti->error);
+				if (ret)
+					goto bad;
+				i++;
+			} else {
+				ret = -EINVAL;
+				ti->error = "Invalid feature arguments";
+				goto bad;
+			}
 		}
 	}
 
+	cc->num_threads_value = num_threads;
+
+	if (num_threads <= 0) {
+		num_threads = num_online_cpus();
+		if (num_threads > DM_CRYPT_DEFAULT_CPUS)
+			num_threads = DM_CRYPT_DEFAULT_CPUS;
+	}
+
 	ret = -ENOMEM;
 	cc->io_queue = alloc_workqueue("kcryptd_io",
 				       WQ_NON_REENTRANT|
@@ -1747,9 +1768,15 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		goto bad;
 	}
 
-	for (i = 0; i < NR_CPUS; i++)
-		if (cpu_online(i))
-			cc->crypt_threads_size = i + 1;
+	if (num_threads == num_online_cpus()) {
+		for (i = 0; i < NR_CPUS; i++)
+			if (cpu_online(i))
+				cc->crypt_threads_size = i + 1;
+	} else {
+		if (num_threads > INT_MAX / sizeof(struct task_struct *))
+			num_threads = INT_MAX / sizeof(struct task_struct *);
+		cc->crypt_threads_size = num_threads;
+	}
 
 	init_waitqueue_head(&cc->crypt_thread_wait);
 	INIT_LIST_HEAD(&cc->crypt_thread_list);
@@ -1761,18 +1788,31 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		goto bad;
 	}
 
-	for (i = 0; i < cc->crypt_threads_size; i++) {
-		if (cpu_online(i)) {
-			cc->crypt_threads[i] = kthread_create_on_node(
-				dmcrypt_thread, cc, cpu_to_node(i),
-				"dmcryptd/%d", i);
+	if (num_threads == num_online_cpus())
+		for (i = 0; i < cc->crypt_threads_size; i++) {
+			if (cpu_online(i)) {
+				cc->crypt_threads[i] = kthread_create_on_node(
+					dmcrypt_thread, cc, cpu_to_node(i),
+					"dmcryptd/%d", i);
+				if (IS_ERR(cc->crypt_threads[i])) {
+					ret = PTR_ERR(cc->crypt_threads[i]);
+					cc->crypt_threads[i] = NULL;
+					ti->error = "Couldn't spawn thread";
+					goto bad;
+				}
+				kthread_bind(cc->crypt_threads[i], i);
+				wake_up_process(cc->crypt_threads[i]);
+			}
+	} else {
+		for (i = 0; i < cc->crypt_threads_size; i++) {
+			cc->crypt_threads[i] = kthread_create(
+				dmcrypt_thread, cc, "dmcryptd/%d", i);
 			if (IS_ERR(cc->crypt_threads[i])) {
 				ret = PTR_ERR(cc->crypt_threads[i]);
 				cc->crypt_threads[i] = NULL;
 				ti->error = "Couldn't spawn thread";
 				goto bad;
 			}
-			kthread_bind(cc->crypt_threads[i], i);
 			wake_up_process(cc->crypt_threads[i]);
 		}
 	}
@@ -1821,6 +1861,7 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
 {
 	struct crypt_config *cc = ti->private;
 	unsigned int sz = 0;
+	unsigned int num_args;
 
 	switch (type) {
 	case STATUSTYPE_INFO:
@@ -1845,8 +1886,23 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
 		DMEMIT(" %llu %s %llu", (unsigned long long)cc->iv_offset,
 				cc->dev->name, (unsigned long long)cc->start);
 
+		num_args = 0;
+		if (ti->num_discard_requests)
+			num_args++;
+
+		if (cc->num_threads_value >= 0)
+			num_args += 2;
+
+		if (!num_args)
+			break;
+
+		DMEMIT(" %u", num_args);
+
 		if (ti->num_discard_requests)
-			DMEMIT(" 1 allow_discards");
+			DMEMIT(" allow_discards");
+
+		if (cc->num_threads_value >= 0)
+			DMEMIT(" num_cpus %d", cc->num_threads_value);
 
 		break;
 	}
-- 
1.7.10.4

  parent reply	other threads:[~2012-08-21  9:09 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21  9:08 [RFC PATCH 00/20] dm-crypt: parallel processing Milan Broz
2012-08-21  9:09 ` [PATCH 01/20] dm-crypt: remove per-cpu structure Mikulas Patocka
2012-08-21  9:09   ` [PATCH 02/20] dm-crypt: use unbound workqueue for request processing Mikulas Patocka
2012-08-21  9:09   ` [PATCH 03/20] dm-crypt: remove completion restart Mikulas Patocka
2012-08-21  9:09   ` [PATCH 04/20] dm-crypt: use encryption threads Mikulas Patocka
2012-08-21  9:09   ` [PATCH 05/20] dm-crypt: Unify spinlock Mikulas Patocka
2012-08-21  9:09   ` Mikulas Patocka [this message]
2012-08-21  9:09   ` [PATCH 07/20] dm-crypt: don't use write queue Mikulas Patocka
2012-08-21  9:09   ` [PATCH 08/20] dm-crypt: simplify io queue Mikulas Patocka
2012-08-21  9:09   ` [PATCH 09/20] dm-crypt: unify io_queue and crypt_queue Mikulas Patocka
2012-08-21  9:09   ` [PATCH 10/20] dm-crypt: don't allocate pages for a partial request Mikulas Patocka
2012-08-21  9:09   ` [PATCH 11/20] dm-crypt: avoid deadlock in mempools Mikulas Patocka
2012-08-21  9:09   ` [PATCH 12/20] dm-crypt: simplify cc_pending Mikulas Patocka
2012-08-21  9:09   ` [PATCH 13/20] dm-crypt merge convert_context and dm_crypt_io Mikulas Patocka
2012-08-21  9:09   ` [PATCH 14/20] dm-crypt: move error handling to crypt_convert Mikulas Patocka
2012-08-21  9:09   ` [PATCH 15/20] dm-crypt: remove io_pending field Mikulas Patocka
2012-08-21  9:09   ` [PATCH 16/20] dm-crypt: small changes Mikulas Patocka
2012-08-21  9:09   ` [PATCH 17/20] dm-crypt: move temporary values to stack Mikulas Patocka
2012-08-21  9:09   ` [PATCH 18/20] dm-crypt: offload writes to thread Mikulas Patocka
2012-08-21  9:09   ` [PATCH 19/20] dm-crypt: retain write ordering Mikulas Patocka
2012-08-21  9:09   ` [PATCH 20/20] dm-crypt: sort writes Mikulas Patocka
2012-08-21 10:57     ` Alasdair G Kergon
2012-08-21 13:39       ` Mikulas Patocka
2012-08-21  9:37 ` [RFC PATCH 00/20] dm-crypt: parallel processing Milan Broz
2012-08-21 18:23   ` Tejun Heo
2012-08-21 19:26     ` Vivek Goyal
2012-08-22 10:28     ` Milan Broz
2012-08-23 20:15       ` Tejun Heo
2012-08-21 13:32 ` Mike Snitzer

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=d05353ef83d887f765924a045681d69be3ec50e2.1345477953.git.mbroz@redhat.com \
    --to=mpatocka@redhat.com \
    --cc=dm-devel@redhat.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 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.