aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2018-07-11 12:10:51 -0400
committerMike Snitzer <snitzer@redhat.com>2018-07-27 15:24:28 -0400
commitc7329eff72aa237d6bedef6dc57c93dc048d2a16 (patch)
tree67593673bda0423578c806c0cda8c51a58b39ae0
parenta3fcf7253139609bf9ff901fbf955fba047e75dd (diff)
dm crypt: use wake_up_process() instead of a wait queue
This is a small simplification of dm-crypt - use wake_up_process() instead of a wait queue in a case where only one process may be waiting. dm-writecache uses a similar pattern. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r--drivers/md/dm-crypt.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index b61b069c33af..c406767cb9b7 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -144,7 +144,7 @@ struct crypt_config {
144 struct workqueue_struct *io_queue; 144 struct workqueue_struct *io_queue;
145 struct workqueue_struct *crypt_queue; 145 struct workqueue_struct *crypt_queue;
146 146
147 wait_queue_head_t write_thread_wait; 147 spinlock_t write_thread_lock;
148 struct task_struct *write_thread; 148 struct task_struct *write_thread;
149 struct rb_root write_tree; 149 struct rb_root write_tree;
150 150
@@ -1620,36 +1620,31 @@ static int dmcrypt_write(void *data)
1620 struct rb_root write_tree; 1620 struct rb_root write_tree;
1621 struct blk_plug plug; 1621 struct blk_plug plug;
1622 1622
1623 DECLARE_WAITQUEUE(wait, current); 1623 spin_lock_irq(&cc->write_thread_lock);
1624
1625 spin_lock_irq(&cc->write_thread_wait.lock);
1626continue_locked: 1624continue_locked:
1627 1625
1628 if (!RB_EMPTY_ROOT(&cc->write_tree)) 1626 if (!RB_EMPTY_ROOT(&cc->write_tree))
1629 goto pop_from_list; 1627 goto pop_from_list;
1630 1628
1631 set_current_state(TASK_INTERRUPTIBLE); 1629 set_current_state(TASK_INTERRUPTIBLE);
1632 __add_wait_queue(&cc->write_thread_wait, &wait);
1633 1630
1634 spin_unlock_irq(&cc->write_thread_wait.lock); 1631 spin_unlock_irq(&cc->write_thread_lock);
1635 1632
1636 if (unlikely(kthread_should_stop())) { 1633 if (unlikely(kthread_should_stop())) {
1637 set_current_state(TASK_RUNNING); 1634 set_current_state(TASK_RUNNING);
1638 remove_wait_queue(&cc->write_thread_wait, &wait);
1639 break; 1635 break;
1640 } 1636 }
1641 1637
1642 schedule(); 1638 schedule();
1643 1639
1644 set_current_state(TASK_RUNNING); 1640 set_current_state(TASK_RUNNING);
1645 spin_lock_irq(&cc->write_thread_wait.lock); 1641 spin_lock_irq(&cc->write_thread_lock);
1646 __remove_wait_queue(&cc->write_thread_wait, &wait);
1647 goto continue_locked; 1642 goto continue_locked;
1648 1643
1649pop_from_list: 1644pop_from_list:
1650 write_tree = cc->write_tree; 1645 write_tree = cc->write_tree;
1651 cc->write_tree = RB_ROOT; 1646 cc->write_tree = RB_ROOT;
1652 spin_unlock_irq(&cc->write_thread_wait.lock); 1647 spin_unlock_irq(&cc->write_thread_lock);
1653 1648
1654 BUG_ON(rb_parent(write_tree.rb_node)); 1649 BUG_ON(rb_parent(write_tree.rb_node));
1655 1650
@@ -1693,7 +1688,9 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)
1693 return; 1688 return;
1694 } 1689 }
1695 1690
1696 spin_lock_irqsave(&cc->write_thread_wait.lock, flags); 1691 spin_lock_irqsave(&cc->write_thread_lock, flags);
1692 if (RB_EMPTY_ROOT(&cc->write_tree))
1693 wake_up_process(cc->write_thread);
1697 rbp = &cc->write_tree.rb_node; 1694 rbp = &cc->write_tree.rb_node;
1698 parent = NULL; 1695 parent = NULL;
1699 sector = io->sector; 1696 sector = io->sector;
@@ -1706,9 +1703,7 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)
1706 } 1703 }
1707 rb_link_node(&io->rb_node, parent, rbp); 1704 rb_link_node(&io->rb_node, parent, rbp);
1708 rb_insert_color(&io->rb_node, &cc->write_tree); 1705 rb_insert_color(&io->rb_node, &cc->write_tree);
1709 1706 spin_unlock_irqrestore(&cc->write_thread_lock, flags);
1710 wake_up_locked(&cc->write_thread_wait);
1711 spin_unlock_irqrestore(&cc->write_thread_wait.lock, flags);
1712} 1707}
1713 1708
1714static void kcryptd_crypt_write_convert(struct dm_crypt_io *io) 1709static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
@@ -2831,7 +2826,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
2831 goto bad; 2826 goto bad;
2832 } 2827 }
2833 2828
2834 init_waitqueue_head(&cc->write_thread_wait); 2829 spin_lock_init(&cc->write_thread_lock);
2835 cc->write_tree = RB_ROOT; 2830 cc->write_tree = RB_ROOT;
2836 2831
2837 cc->write_thread = kthread_create(dmcrypt_write, cc, "dmcrypt_write"); 2832 cc->write_thread = kthread_create(dmcrypt_write, cc, "dmcrypt_write");