aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2016-01-07 05:38:48 -0500
committerDavid Sterba <dsterba@suse.com>2016-02-18 04:27:23 -0500
commit2fefd5583f8b86171c898f90cadac7c09ccf9d73 (patch)
tree6f5c406bc2dc0ba63c36f3fb19e2462c9f42739c
parent895a11b868347ca8e287f152f7816862ad4b179d (diff)
btrfs: reada: limit max works count
Reada creates 2 works for each level of tree recursively. In case of a tree having many levels, the number of created works is 2^level_of_tree. Actually we don't need so many works in parallel, this patch limits max works to BTRFS_MAX_MIRRORS * 2. The per-fs works_counter will be also used for btrfs_reada_wait() to check is there are background workers. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/ctree.h3
-rw-r--r--fs/btrfs/disk-io.c1
-rw-r--r--fs/btrfs/reada.c9
3 files changed, 12 insertions, 1 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e557e05d2318..e43d987e1c99 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1822,6 +1822,9 @@ struct btrfs_fs_info {
1822 spinlock_t reada_lock; 1822 spinlock_t reada_lock;
1823 struct radix_tree_root reada_tree; 1823 struct radix_tree_root reada_tree;
1824 1824
1825 /* readahead works cnt */
1826 atomic_t reada_works_cnt;
1827
1825 /* Extent buffer radix tree */ 1828 /* Extent buffer radix tree */
1826 spinlock_t buffer_lock; 1829 spinlock_t buffer_lock;
1827 struct radix_tree_root buffer_radix; 1830 struct radix_tree_root buffer_radix;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 498156ede32c..5e3ec1fc0ac3 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2603,6 +2603,7 @@ int open_ctree(struct super_block *sb,
2603 atomic_set(&fs_info->nr_async_bios, 0); 2603 atomic_set(&fs_info->nr_async_bios, 0);
2604 atomic_set(&fs_info->defrag_running, 0); 2604 atomic_set(&fs_info->defrag_running, 0);
2605 atomic_set(&fs_info->qgroup_op_seq, 0); 2605 atomic_set(&fs_info->qgroup_op_seq, 0);
2606 atomic_set(&fs_info->reada_works_cnt, 0);
2606 atomic64_set(&fs_info->tree_mod_seq, 0); 2607 atomic64_set(&fs_info->tree_mod_seq, 0);
2607 fs_info->sb = sb; 2608 fs_info->sb = sb;
2608 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE; 2609 fs_info->max_inline = BTRFS_DEFAULT_MAX_INLINE;
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index 9157d789ae86..e97bc8eb01e2 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -748,6 +748,8 @@ static void reada_start_machine_worker(struct btrfs_work *work)
748 set_task_ioprio(current, BTRFS_IOPRIO_READA); 748 set_task_ioprio(current, BTRFS_IOPRIO_READA);
749 __reada_start_machine(fs_info); 749 __reada_start_machine(fs_info);
750 set_task_ioprio(current, old_ioprio); 750 set_task_ioprio(current, old_ioprio);
751
752 atomic_dec(&fs_info->reada_works_cnt);
751} 753}
752 754
753static void __reada_start_machine(struct btrfs_fs_info *fs_info) 755static void __reada_start_machine(struct btrfs_fs_info *fs_info)
@@ -779,8 +781,12 @@ static void __reada_start_machine(struct btrfs_fs_info *fs_info)
779 * enqueue to workers to finish it. This will distribute the load to 781 * enqueue to workers to finish it. This will distribute the load to
780 * the cores. 782 * the cores.
781 */ 783 */
782 for (i = 0; i < 2; ++i) 784 for (i = 0; i < 2; ++i) {
783 reada_start_machine(fs_info); 785 reada_start_machine(fs_info);
786 if (atomic_read(&fs_info->reada_works_cnt) >
787 BTRFS_MAX_MIRRORS * 2)
788 break;
789 }
784} 790}
785 791
786static void reada_start_machine(struct btrfs_fs_info *fs_info) 792static void reada_start_machine(struct btrfs_fs_info *fs_info)
@@ -797,6 +803,7 @@ static void reada_start_machine(struct btrfs_fs_info *fs_info)
797 rmw->fs_info = fs_info; 803 rmw->fs_info = fs_info;
798 804
799 btrfs_queue_work(fs_info->readahead_workers, &rmw->work); 805 btrfs_queue_work(fs_info->readahead_workers, &rmw->work);
806 atomic_inc(&fs_info->reada_works_cnt);
800} 807}
801 808
802#ifdef DEBUG 809#ifdef DEBUG