Skip to content

Commit 0d2450a

Browse files
Sergei TrofimovichJosef Bacik
authored andcommitted
btrfs: allow changing 'thread_pool' size at remount time
Changing 'mount -oremount,thread_pool=2 /' didn't make any effect: maximum amount of worker threads is specified in 2 places: - in 'strict btrfs_fs_info::thread_pool_size' - in each worker struct: 'struct btrfs_workers::max_workers' 'mount -oremount' updated only 'btrfs_fs_info::thread_pool_size'. Fix it by pushing new maximum value to all created worker structures as well. Cc: Josef Bacik <josef@redhat.com> Cc: Chris Mason <chris.mason@oracle.com> Reviewed-by: Josef Bacik <josef@redhat.com> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
1 parent 0885ef5 commit 0d2450a

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

fs/btrfs/super.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,8 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
435435
case Opt_thread_pool:
436436
intarg = 0;
437437
match_int(&args[0], &intarg);
438-
if (intarg) {
438+
if (intarg)
439439
info->thread_pool_size = intarg;
440-
printk(KERN_INFO "btrfs: thread pool %d\n",
441-
info->thread_pool_size);
442-
}
443440
break;
444441
case Opt_max_inline:
445442
num = match_strdup(&args[0]);
@@ -1118,6 +1115,40 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
11181115
return ERR_PTR(error);
11191116
}
11201117

1118+
static void btrfs_set_max_workers(struct btrfs_workers *workers, int new_limit)
1119+
{
1120+
spin_lock_irq(&workers->lock);
1121+
workers->max_workers = new_limit;
1122+
spin_unlock_irq(&workers->lock);
1123+
}
1124+
1125+
static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
1126+
int new_pool_size, int old_pool_size)
1127+
{
1128+
if (new_pool_size == old_pool_size)
1129+
return;
1130+
1131+
fs_info->thread_pool_size = new_pool_size;
1132+
1133+
printk(KERN_INFO "btrfs: resize thread pool %d -> %d\n",
1134+
old_pool_size, new_pool_size);
1135+
1136+
btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size);
1137+
btrfs_set_max_workers(&fs_info->workers, new_pool_size);
1138+
btrfs_set_max_workers(&fs_info->delalloc_workers, new_pool_size);
1139+
btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size);
1140+
btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size);
1141+
btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size);
1142+
btrfs_set_max_workers(&fs_info->endio_workers, new_pool_size);
1143+
btrfs_set_max_workers(&fs_info->endio_meta_workers, new_pool_size);
1144+
btrfs_set_max_workers(&fs_info->endio_meta_write_workers, new_pool_size);
1145+
btrfs_set_max_workers(&fs_info->endio_write_workers, new_pool_size);
1146+
btrfs_set_max_workers(&fs_info->endio_freespace_worker, new_pool_size);
1147+
btrfs_set_max_workers(&fs_info->delayed_workers, new_pool_size);
1148+
btrfs_set_max_workers(&fs_info->readahead_workers, new_pool_size);
1149+
btrfs_set_max_workers(&fs_info->scrub_workers, new_pool_size);
1150+
}
1151+
11211152
static int btrfs_remount(struct super_block *sb, int *flags, char *data)
11221153
{
11231154
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
@@ -1137,6 +1168,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
11371168
goto restore;
11381169
}
11391170

1171+
btrfs_resize_thread_pool(fs_info,
1172+
fs_info->thread_pool_size, old_thread_pool_size);
1173+
11401174
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
11411175
return 0;
11421176

@@ -1180,7 +1214,8 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
11801214
fs_info->compress_type = old_compress_type;
11811215
fs_info->max_inline = old_max_inline;
11821216
fs_info->alloc_start = old_alloc_start;
1183-
fs_info->thread_pool_size = old_thread_pool_size;
1217+
btrfs_resize_thread_pool(fs_info,
1218+
old_thread_pool_size, fs_info->thread_pool_size);
11841219
fs_info->metadata_ratio = old_metadata_ratio;
11851220
return ret;
11861221
}

0 commit comments

Comments
 (0)