btrfs: use correct compare function of dirty_metadata_bytes
authorEthan Lien <ethanlien@synology.com>
Mon, 2 Jul 2018 07:44:58 +0000 (15:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Sep 2018 07:26:33 +0000 (09:26 +0200)
commit d814a49198eafa6163698bdd93961302f3a877a4 upstream.

We use customized, nodesize batch value to update dirty_metadata_bytes.
We should also use batch version of compare function or we will easily
goto fast path and get false result from percpu_counter_compare().

Fixes: e2d845211eda ("Btrfs: use percpu counter for dirty metadata count")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Ethan Lien <ethanlien@synology.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/disk-io.c

index b475d1ebbbbf02117a45fc26f5652e907538e7d6..5cf1bbe9754cfed6eb6b5a9e246859b8d30d0204 100644 (file)
@@ -1098,8 +1098,9 @@ static int btree_writepages(struct address_space *mapping,
 
                fs_info = BTRFS_I(mapping->host)->root->fs_info;
                /* this is a bit racy, but that's ok */
-               ret = percpu_counter_compare(&fs_info->dirty_metadata_bytes,
-                                            BTRFS_DIRTY_METADATA_THRESH);
+               ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes,
+                                            BTRFS_DIRTY_METADATA_THRESH,
+                                            fs_info->dirty_metadata_batch);
                if (ret < 0)
                        return 0;
        }
@@ -4030,8 +4031,9 @@ static void __btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info,
        if (flush_delayed)
                btrfs_balance_delayed_items(fs_info);
 
-       ret = percpu_counter_compare(&fs_info->dirty_metadata_bytes,
-                                    BTRFS_DIRTY_METADATA_THRESH);
+       ret = __percpu_counter_compare(&fs_info->dirty_metadata_bytes,
+                                    BTRFS_DIRTY_METADATA_THRESH,
+                                    fs_info->dirty_metadata_batch);
        if (ret > 0) {
                balance_dirty_pages_ratelimited(fs_info->btree_inode->i_mapping);
        }