btrfs_compress_op[idx]->free_workspace(workspace);
        atomic_dec(total_ws);
 wake:
-       /*
-        * Make sure counter is updated before we wake up waiters.
-        */
-       smp_mb();
-       if (waitqueue_active(ws_wait))
-               wake_up(ws_wait);
+       cond_wake_up(ws_wait);
 }
 
 static void free_workspace(int type, struct list_head *ws)
 
 {
        int seq = atomic_inc_return(&delayed_root->items_seq);
 
-       /*
-        * atomic_dec_return implies a barrier for waitqueue_active
-        */
+       /* atomic_dec_return implies a barrier */
        if ((atomic_dec_return(&delayed_root->items) <
-           BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
-           waitqueue_active(&delayed_root->wait))
-               wake_up(&delayed_root->wait);
+           BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0))
+               cond_wake_up_nomb(&delayed_root->wait);
 }
 
 static void __btrfs_remove_delayed_item(struct btrfs_delayed_item *delayed_item)
 
        ASSERT(atomic_read(&dev_replace->read_locks) > 0);
        ASSERT(atomic_read(&dev_replace->blocking_readers) > 0);
        read_lock(&dev_replace->lock);
-       if (atomic_dec_and_test(&dev_replace->blocking_readers) &&
-           waitqueue_active(&dev_replace->read_lock_wq))
-               wake_up(&dev_replace->read_lock_wq);
+       /* Barrier implied by atomic_dec_and_test */
+       if (atomic_dec_and_test(&dev_replace->blocking_readers))
+               cond_wake_up_nomb(&dev_replace->read_lock_wq);
 }
 
 void btrfs_bio_counter_inc_noblocked(struct btrfs_fs_info *fs_info)
 void btrfs_bio_counter_sub(struct btrfs_fs_info *fs_info, s64 amount)
 {
        percpu_counter_sub(&fs_info->bio_counter, amount);
-
-       if (waitqueue_active(&fs_info->replace_wait))
-               wake_up(&fs_info->replace_wait);
+       cond_wake_up_nomb(&fs_info->replace_wait);
 }
 
 void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info)
 
 void btrfs_end_write_no_snapshotting(struct btrfs_root *root)
 {
        percpu_counter_dec(&root->subv_writers->counter);
-       /*
-        * Make sure counter is updated before we wake up waiters.
-        */
-       smp_mb();
-       if (waitqueue_active(&root->subv_writers->wait))
-               wake_up(&root->subv_writers->wait);
+       cond_wake_up(&root->subv_writers->wait);
 }
 
 int btrfs_start_write_no_snapshotting(struct btrfs_root *root)
 
        nr_pages = (async_cow->end - async_cow->start + PAGE_SIZE) >>
                PAGE_SHIFT;
 
-       /*
-        * atomic_sub_return implies a barrier for waitqueue_active
-        */
+       /* atomic_sub_return implies a barrier */
        if (atomic_sub_return(nr_pages, &fs_info->async_delalloc_pages) <
-           5 * SZ_1M &&
-           waitqueue_active(&fs_info->async_submit_wait))
-               wake_up(&fs_info->async_submit_wait);
+           5 * SZ_1M)
+               cond_wake_up_nomb(&fs_info->async_submit_wait);
 
        if (async_cow->inode)
                submit_compressed_extents(async_cow->inode, async_cow);
 
                write_lock(&eb->lock);
                WARN_ON(atomic_read(&eb->spinning_writers));
                atomic_inc(&eb->spinning_writers);
-               /*
-                * atomic_dec_and_test implies a barrier for waitqueue_active
-                */
-               if (atomic_dec_and_test(&eb->blocking_writers) &&
-                   waitqueue_active(&eb->write_lock_wq))
-                       wake_up(&eb->write_lock_wq);
+               /* atomic_dec_and_test implies a barrier */
+               if (atomic_dec_and_test(&eb->blocking_writers))
+                       cond_wake_up_nomb(&eb->write_lock_wq);
        } else if (rw == BTRFS_READ_LOCK_BLOCKING) {
                BUG_ON(atomic_read(&eb->blocking_readers) == 0);
                read_lock(&eb->lock);
                atomic_inc(&eb->spinning_readers);
-               /*
-                * atomic_dec_and_test implies a barrier for waitqueue_active
-                */
-               if (atomic_dec_and_test(&eb->blocking_readers) &&
-                   waitqueue_active(&eb->read_lock_wq))
-                       wake_up(&eb->read_lock_wq);
+               /* atomic_dec_and_test implies a barrier */
+               if (atomic_dec_and_test(&eb->blocking_readers))
+                       cond_wake_up_nomb(&eb->read_lock_wq);
        }
 }
 
        }
        btrfs_assert_tree_read_locked(eb);
        WARN_ON(atomic_read(&eb->blocking_readers) == 0);
-       /*
-        * atomic_dec_and_test implies a barrier for waitqueue_active
-        */
-       if (atomic_dec_and_test(&eb->blocking_readers) &&
-           waitqueue_active(&eb->read_lock_wq))
-               wake_up(&eb->read_lock_wq);
+       /* atomic_dec_and_test implies a barrier */
+       if (atomic_dec_and_test(&eb->blocking_readers))
+               cond_wake_up_nomb(&eb->read_lock_wq);
        atomic_dec(&eb->read_locks);
 }
 
        if (blockers) {
                WARN_ON(atomic_read(&eb->spinning_writers));
                atomic_dec(&eb->blocking_writers);
-               /*
-                * Make sure counter is updated before we wake up waiters.
-                */
+               /* Use the lighter barrier after atomic */
                smp_mb__after_atomic();
-               if (waitqueue_active(&eb->write_lock_wq))
-                       wake_up(&eb->write_lock_wq);
+               cond_wake_up_nomb(&eb->write_lock_wq);
        } else {
                WARN_ON(atomic_read(&eb->spinning_writers) != 1);
                atomic_dec(&eb->spinning_writers);
 
 
        if (entry->bytes_left == 0) {
                ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
-               /*
-                * Implicit memory barrier after test_and_set_bit
-                */
-               if (waitqueue_active(&entry->wait))
-                       wake_up(&entry->wait);
+               /* test_and_set_bit implies a barrier */
+               cond_wake_up_nomb(&entry->wait);
        } else {
                ret = 1;
        }
 
        if (entry->bytes_left == 0) {
                ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
-               /*
-                * Implicit memory barrier after test_and_set_bit
-                */
-               if (waitqueue_active(&entry->wait))
-                       wake_up(&entry->wait);
+               /* test_and_set_bit implies a barrier */
+               cond_wake_up_nomb(&entry->wait);
        } else {
                ret = 1;
        }
 
        atomic_dec(&cur_trans->num_writers);
        extwriter_counter_dec(cur_trans, trans->type);
 
-       /*
-        * Make sure counter is updated before we wake up waiters.
-        */
-       smp_mb();
-       if (waitqueue_active(&cur_trans->writer_wait))
-               wake_up(&cur_trans->writer_wait);
+       cond_wake_up(&cur_trans->writer_wait);
        btrfs_put_transaction(cur_trans);
 
        if (current->journal_info == trans)
 
 void btrfs_end_log_trans(struct btrfs_root *root)
 {
        if (atomic_dec_and_test(&root->log_writers)) {
-               /*
-                * Implicit memory barrier after atomic_dec_and_test
-                */
-               if (waitqueue_active(&root->log_writer_wait))
-                       wake_up(&root->log_writer_wait);
+               /* atomic_dec_and_test implies a barrier */
+               cond_wake_up_nomb(&root->log_writer_wait);
        }
 }
 
 
        mutex_lock(&log_root_tree->log_mutex);
        if (atomic_dec_and_test(&log_root_tree->log_writers)) {
-               /*
-                * Implicit memory barrier after atomic_dec_and_test
-                */
-               if (waitqueue_active(&log_root_tree->log_writer_wait))
-                       wake_up(&log_root_tree->log_writer_wait);
+               /* atomic_dec_and_test implies a barrier */
+               cond_wake_up_nomb(&log_root_tree->log_writer_wait);
        }
 
        if (ret) {
        mutex_unlock(&log_root_tree->log_mutex);
 
        /*
-        * The barrier before waitqueue_active is needed so all the updates
-        * above are seen by the woken threads. It might not be necessary, but
-        * proving that seems to be hard.
+        * The barrier before waitqueue_active (in cond_wake_up) is needed so
+        * all the updates above are seen by the woken threads. It might not be
+        * necessary, but proving that seems to be hard.
         */
-       smp_mb();
-       if (waitqueue_active(&log_root_tree->log_commit_wait[index2]))
-               wake_up(&log_root_tree->log_commit_wait[index2]);
+       cond_wake_up(&log_root_tree->log_commit_wait[index2]);
 out:
        mutex_lock(&root->log_mutex);
        btrfs_remove_all_log_ctxs(root, index1, ret);
        mutex_unlock(&root->log_mutex);
 
        /*
-        * The barrier before waitqueue_active is needed so all the updates
-        * above are seen by the woken threads. It might not be necessary, but
-        * proving that seems to be hard.
+        * The barrier before waitqueue_active (in cond_wake_up) is needed so
+        * all the updates above are seen by the woken threads. It might not be
+        * necessary, but proving that seems to be hard.
         */
-       smp_mb();
-       if (waitqueue_active(&root->log_commit_wait[index1]))
-               wake_up(&root->log_commit_wait[index1]);
+       cond_wake_up(&root->log_commit_wait[index1]);
        return ret;
 }