BTRFS_INODE_IN_DELALLOC_LIST,
        BTRFS_INODE_READDIO_NEED_LOCK,
        BTRFS_INODE_HAS_PROPS,
+       BTRFS_INODE_SNAPSHOT_FLUSH,
 };
 
 /* in memory btrfs inode */
 
                               struct inode *inode, u64 new_size,
                               u32 min_type);
 
-int btrfs_start_delalloc_inodes(struct btrfs_root *root);
+int btrfs_start_delalloc_snapshot(struct btrfs_root *root);
 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int nr);
 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
                              unsigned int extra_bits,
 
                        range_whole = 1;
                scanned = 1;
        }
-       if (wbc->sync_mode == WB_SYNC_ALL)
+
+       /*
+        * We do the tagged writepage as long as the snapshot flush bit is set
+        * and we are the first one who do the filemap_flush() on this inode.
+        *
+        * The nr_to_write == LONG_MAX is needed to make sure other flushers do
+        * not race in and drop the bit.
+        */
+       if (range_whole && wbc->nr_to_write == LONG_MAX &&
+           test_and_clear_bit(BTRFS_INODE_SNAPSHOT_FLUSH,
+                              &BTRFS_I(inode)->runtime_flags))
+               wbc->tagged_writepages = 1;
+
+       if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
                tag = PAGECACHE_TAG_TOWRITE;
        else
                tag = PAGECACHE_TAG_DIRTY;
 retry:
-       if (wbc->sync_mode == WB_SYNC_ALL)
+       if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
                tag_pages_for_writeback(mapping, index, end);
        done_index = index;
        while (!done && !nr_to_write_done && (index <= end) &&
 
  * some fairly slow code that needs optimization. This walks the list
  * of all the inodes with pending delalloc and forces them to disk.
  */
-static int start_delalloc_inodes(struct btrfs_root *root, int nr)
+static int start_delalloc_inodes(struct btrfs_root *root, int nr, bool snapshot)
 {
        struct btrfs_inode *binode;
        struct inode *inode;
                }
                spin_unlock(&root->delalloc_lock);
 
+               if (snapshot)
+                       set_bit(BTRFS_INODE_SNAPSHOT_FLUSH,
+                               &binode->runtime_flags);
                work = btrfs_alloc_delalloc_work(inode);
                if (!work) {
                        iput(inode);
        return ret;
 }
 
-int btrfs_start_delalloc_inodes(struct btrfs_root *root)
+int btrfs_start_delalloc_snapshot(struct btrfs_root *root)
 {
        struct btrfs_fs_info *fs_info = root->fs_info;
        int ret;
        if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
                return -EROFS;
 
-       ret = start_delalloc_inodes(root, -1);
+       ret = start_delalloc_inodes(root, -1, true);
        if (ret > 0)
                ret = 0;
        return ret;
                               &fs_info->delalloc_roots);
                spin_unlock(&fs_info->delalloc_root_lock);
 
-               ret = start_delalloc_inodes(root, nr);
+               ret = start_delalloc_inodes(root, nr, false);
                btrfs_put_fs_root(root);
                if (ret < 0)
                        goto out;
 
        wait_event(root->subv_writers->wait,
                   percpu_counter_sum(&root->subv_writers->counter) == 0);
 
-       ret = btrfs_start_delalloc_inodes(root);
+       ret = btrfs_start_delalloc_snapshot(root);
        if (ret)
                goto dec_and_free;