Add mount option "priority_alloc=%s", now %s only supports "usage" and
"off". The latter is used for remount.
"priority_alloc=usage" will active priority aware allocator.
This mount option changes the way of find_free_extent to search
block groups and may cost more time.

Signed-off-by: Su Yue <suy.f...@cn.fujitsu.com>
---
 fs/btrfs/super.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index cbc9d0d2c12d..4a6ccd4c29fd 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -326,6 +326,7 @@ enum {
        Opt_treelog, Opt_notreelog,
        Opt_usebackuproot,
        Opt_user_subvol_rm_allowed,
+       Opt_priority_allocator,
 
        /* Deprecated options */
        Opt_alloc_start,
@@ -393,6 +394,7 @@ static const match_table_t tokens = {
        {Opt_notreelog, "notreelog"},
        {Opt_usebackuproot, "usebackuproot"},
        {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
+       {Opt_priority_allocator, "priority_alloc=%s"},
 
        /* Deprecated options */
        {Opt_alloc_start, "alloc_start=%s"},
@@ -765,6 +767,18 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char 
*options,
                case Opt_skip_balance:
                        btrfs_set_opt(info->mount_opt, SKIP_BALANCE);
                        break;
+               case Opt_priority_allocator:
+                       if (strcmp(args[0].from, "usage") == 0) {
+                               btrfs_set_and_info(info, PRIORITY_USAGE,
+                                  "using priority usage-aware allocator");
+                       } else if (strcmp(args[0].from, "off") == 0) {
+                               btrfs_clear_and_info(info, PRIORITY_USAGE,
+                                  "priority awareallocator disabled");
+                       } else {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       break;
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
                case Opt_check_integrity_including_extent_data:
                        btrfs_info(info,
@@ -1337,6 +1351,10 @@ static int btrfs_show_options(struct seq_file *seq, 
struct dentry *dentry)
                seq_puts(seq, ",inode_cache");
        if (btrfs_test_opt(info, SKIP_BALANCE))
                seq_puts(seq, ",skip_balance");
+       if (btrfs_test_opt(info, PRIORITY_USAGE))
+               seq_puts(seq, ",priority_alloc=usage");
+       else
+               seq_puts(seq, ",priority_alloc=off");
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
        if (btrfs_test_opt(info, CHECK_INTEGRITY_INCLUDING_EXTENT_DATA))
                seq_puts(seq, ",check_int_data");
-- 
2.19.1



Reply via email to