Unify spinlock Remove "crypt_thread_spinlock" and use wait queue spinlock "crypt_thread_wait.spinlock" instead. This saves few atomic operations in the encryption thread. Signed-off-by: Mikulas Patocka --- drivers/md/dm-crypt.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) Index: linux-3.2-fast/drivers/md/dm-crypt.c =================================================================== --- linux-3.2-fast.orig/drivers/md/dm-crypt.c 2012-01-31 02:29:58.000000000 +0100 +++ linux-3.2-fast/drivers/md/dm-crypt.c 2012-01-31 02:30:30.000000000 +0100 @@ -130,7 +130,6 @@ struct crypt_config { struct task_struct **crypt_threads; wait_queue_head_t crypt_thread_wait; - spinlock_t crypt_thread_spinlock; struct list_head crypt_thread_list; char *cipher; @@ -681,15 +680,16 @@ static int dmcrypt_thread(void *data) DECLARE_WAITQUEUE(wait, current); - spin_lock(&cc->crypt_thread_spinlock); + spin_lock_irq(&cc->crypt_thread_wait.lock); +continue_locked: if (!list_empty(&cc->crypt_thread_list)) goto pop_from_list; __set_current_state(TASK_INTERRUPTIBLE); - add_wait_queue(&cc->crypt_thread_wait, &wait); + __add_wait_queue(&cc->crypt_thread_wait, &wait); - spin_unlock(&cc->crypt_thread_spinlock); + spin_unlock_irq(&cc->crypt_thread_wait.lock); if (unlikely(kthread_should_stop())) { set_task_state(current, TASK_RUNNING); @@ -700,8 +700,9 @@ static int dmcrypt_thread(void *data) schedule(); set_task_state(current, TASK_RUNNING); - remove_wait_queue(&cc->crypt_thread_wait, &wait); - continue; + spin_lock_irq(&cc->crypt_thread_wait.lock); + __remove_wait_queue(&cc->crypt_thread_wait, &wait); + goto continue_locked; pop_from_list: n_dmreqs = 0; @@ -713,7 +714,8 @@ pop_from_list: dmreqs[n_dmreqs++] = dmreq; } while (n_dmreqs < DMREQ_PULL_BATCH && !list_empty(&cc->crypt_thread_list)); - spin_unlock(&cc->crypt_thread_spinlock); + + spin_unlock_irq(&cc->crypt_thread_wait.lock); i = 0; do { @@ -806,10 +808,10 @@ static struct ablkcipher_request *crypt_ static void crypt_flush_batch(struct crypt_config *cc, struct list_head *batch) { - spin_lock(&cc->crypt_thread_spinlock); + spin_lock_irq(&cc->crypt_thread_wait.lock); list_splice_tail(batch, &cc->crypt_thread_list); - spin_unlock(&cc->crypt_thread_spinlock); - wake_up_all(&cc->crypt_thread_wait); + wake_up_locked(&cc->crypt_thread_wait); + spin_unlock_irq(&cc->crypt_thread_wait.lock); INIT_LIST_HEAD(batch); } @@ -1754,7 +1756,6 @@ static int crypt_ctr(struct dm_target *t cc->crypt_threads_size = i + 1; init_waitqueue_head(&cc->crypt_thread_wait); - spin_lock_init(&cc->crypt_thread_spinlock); INIT_LIST_HEAD(&cc->crypt_thread_list); cc->crypt_threads = kzalloc(cc->crypt_threads_size *