linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs: reada: limit max works count
@ 2016-01-12  7:46 Zhao Lei
  2016-01-12  7:46 ` [PATCH 2/2] btrfs: reada: simplify dev->reada_in_flight processing Zhao Lei
  2016-01-20 15:16 ` [PATCH 1/2] btrfs: reada: limit max works count Chris Mason
  0 siblings, 2 replies; 12+ messages in thread
From: Zhao Lei @ 2016-01-12  7:46 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Zhao Lei

reada create 2 works for each level of tree in recursion.

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 limit
max works to BTRFS_MAX_MIRRORS * 2.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 fs/btrfs/reada.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index 53ee7b1..7b150b2 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -103,6 +103,9 @@ static void __reada_start_machine(struct btrfs_fs_info *fs_info);
 static int reada_add_block(struct reada_control *rc, u64 logical,
 			   struct btrfs_key *top, u64 generation);
 
+/* To limit max reada works */
+static atomic_t works_cnt = ATOMIC_INIT(0);
+
 /* recurses */
 /* in case of err, eb might be NULL */
 static void __readahead_hook(struct btrfs_fs_info *fs_info,
@@ -759,6 +762,8 @@ static void reada_start_machine_worker(struct btrfs_work *work)
 	set_task_ioprio(current, BTRFS_IOPRIO_READA);
 	__reada_start_machine(fs_info);
 	set_task_ioprio(current, old_ioprio);
+
+	atomic_dec(&works_cnt);
 }
 
 static void __reada_start_machine(struct btrfs_fs_info *fs_info)
@@ -790,8 +795,11 @@ static void __reada_start_machine(struct btrfs_fs_info *fs_info)
 	 * enqueue to workers to finish it. This will distribute the load to
 	 * the cores.
 	 */
-	for (i = 0; i < 2; ++i)
+	for (i = 0; i < 2; ++i) {
 		reada_start_machine(fs_info);
+		if (atomic_read(&works_cnt) > BTRFS_MAX_MIRRORS * 2)
+			break;
+	}
 }
 
 static void reada_start_machine(struct btrfs_fs_info *fs_info)
@@ -808,6 +816,7 @@ static void reada_start_machine(struct btrfs_fs_info *fs_info)
 	rmw->fs_info = fs_info;
 
 	btrfs_queue_work(fs_info->readahead_workers, &rmw->work);
+	atomic_inc(&works_cnt);
 }
 
 #ifdef DEBUG
-- 
1.8.5.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-01-28 13:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-12  7:46 [PATCH 1/2] btrfs: reada: limit max works count Zhao Lei
2016-01-12  7:46 ` [PATCH 2/2] btrfs: reada: simplify dev->reada_in_flight processing Zhao Lei
2016-01-20 15:16 ` [PATCH 1/2] btrfs: reada: limit max works count Chris Mason
2016-01-20 17:48   ` Chris Mason
2016-01-21  3:36     ` Zhao Lei
2016-01-21 10:06     ` Zhao Lei
2016-01-21 14:14       ` Chris Mason
2016-01-22 12:25         ` Zhao Lei
2016-01-22 14:19           ` Chris Mason
2016-01-26  9:08             ` Zhao Lei
2016-01-28  7:49             ` Zhao Lei
2016-01-28 13:30               ` Chris Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).