Skip to contentSkip to conversation

more raid456 thread pool experimentation

RFC PATCH In review Dan Williams 2 participants 6 messages Mar 24, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover more raid456 thread pool experimentation

The current implementation with the async thread pool ends up spreading the work over too many threads. The btrfs workqueue is targeted at high cpu utilization works and has a threshold mechanism to limit thread spawning. Unfortunately it still ends up increasing cpu utilization without a comparable improvement in throughput. Here are the numbers relative to the multicore disabled case:

idle_thresh throughput cycles
4 +0% +102%
64 +4% +63%
128 +1% +45%

This appears to show that something more fundamental needs to happen to take advantage of percpu raid processing. More profiling is needed, but the suspects in my mind are conf->device_lock contention and the fact that all work is serialized through conf->handle_list with no method for encouraging stripe_head to thread affinity.

The idle_thresh parameter translates to the number of stripes that can be in a thread's backlog before new work spills over into a new thread. The current implementation via async is effectively using a threshold of zero which ends up impacting throughput due to excessive cpu utilization and thread creation. I do not think we need any more experimentation before declaring the current implementation broken.

---

Dan Williams (2):
btrq: uplevel the btrfs thread pool for md/raid456 usage md/raid456: switch to btrq for multicore operation

 drivers/md/Kconfig       |    1 
 drivers/md/raid5.c       |   79 +++++++++++++----------
 drivers/md/raid5.h       |   13 ++--
 fs/btrfs/Kconfig         |    1 
 fs/btrfs/Makefile        |    2 -
 fs/btrfs/ctree.h         |   22 +++---
 fs/btrfs/disk-io.c       |  157 +++++++++++++++++++++++-----------------------
 fs/btrfs/extent-tree.c   |    7 +-
 fs/btrfs/inode.c         |   18 +++--
 fs/btrfs/relocation.c    |   22 +++---
 fs/btrfs/volumes.c       |   12 ++--
 fs/btrfs/volumes.h       |    4 +
 include/linux/btrqueue.h |   36 +++++------
 lib/Kconfig              |    6 ++
 lib/Makefile             |    2 +
 lib/btrqueue.c           |  119 ++++++++++++++++++-----------------
 16 files changed, 265 insertions(+), 236 deletions(-)
 rename fs/btrfs/async-thread.h => include/linux/btrqueue.h (76%)
 rename fs/btrfs/async-thread.c => lib/btrqueue.c (82%)
#1 lore raw

RFC PATCH 1/2 btrq: uplevel the btrfs thread pool for md/raid456 usage

The current async thread pool is optimized for extracting subsystem init parallelism. The btrfs workqueue is targetted for load balancing high cpu utilization works and is a better candidate for a raid thread pool.
---

 fs/btrfs/Kconfig         |    1 
 fs/btrfs/Makefile        |    2 -
 fs/btrfs/ctree.h         |   22 +++---
 fs/btrfs/disk-io.c       |  157 +++++++++++++++++++++++-----------------------
 fs/btrfs/extent-tree.c   |    7 +-
 fs/btrfs/inode.c         |   18 +++--
 fs/btrfs/relocation.c    |   22 +++---
 fs/btrfs/volumes.c       |   12 ++--
 fs/btrfs/volumes.h       |    4 +
 include/linux/btrqueue.h |   36 +++++------
 lib/Kconfig              |    6 ++
 lib/Makefile             |    2 +
 lib/btrqueue.c           |  119 ++++++++++++++++++-----------------
 13 files changed, 211 insertions(+), 197 deletions(-)
 rename fs/btrfs/async-thread.h => include/linux/btrqueue.h (76%)
 rename fs/btrfs/async-thread.c => lib/btrqueue.c (82%)
fs/btrfs/Kconfig +1 -0
index 7bb3c02..5d64c17 100644
@@ -4,6 +4,7 @@ config BTRFS_FS
 	select LIBCRC32C
 	select ZLIB_INFLATE
 	select ZLIB_DEFLATE
+	select BTRQ
 	help
 	  Btrfs is a new filesystem with extents, writable snapshotting,
 	  support for multiple devices and many more features.
fs/btrfs/Makefile +1 -1
index a35eb36..96fb502 100644
@@ -5,6 +5,6 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
 	   file-item.o inode-item.o inode-map.o disk-io.o \
 	   transaction.o inode.o file.o tree-defrag.o \
 	   extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
-	   extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
+	   extent_io.o volumes.o ioctl.o locking.o orphan.o \
 	   export.o tree-log.o acl.o free-space-cache.o zlib.o \
 	   compression.o delayed-ref.o relocation.o
fs/btrfs/ctree.h +11 -11
index 444b3e9..5fe630a 100644
@@ -26,10 +26,10 @@
 #include <linux/completion.h>
 #include <linux/backing-dev.h>
 #include <linux/wait.h>
+#include <linux/btrqueue.h>
 #include <asm/kmap_types.h>
 #include "extent_io.h"
 #include "extent_map.h"
-#include "async-thread.h"
 
 struct btrfs_trans_handle;
 struct btrfs_transaction;
@@ -910,21 +910,21 @@ struct btrfs_fs_info {
 	 * A third pool does submit_bio to avoid deadlocking with the other
 	 * two
 	 */
-	struct btrfs_workers generic_worker;
-	struct btrfs_workers workers;
-	struct btrfs_workers delalloc_workers;
-	struct btrfs_workers endio_workers;
-	struct btrfs_workers endio_meta_workers;
-	struct btrfs_workers endio_meta_write_workers;
-	struct btrfs_workers endio_write_workers;
-	struct btrfs_workers submit_workers;
-	struct btrfs_workers enospc_workers;
+	struct btrq_workers generic_worker;
+	struct btrq_workers workers;
+	struct btrq_workers delalloc_workers;
+	struct btrq_workers endio_workers;
+	struct btrq_workers endio_meta_workers;
+	struct btrq_workers endio_meta_write_workers;
+	struct btrq_workers endio_write_workers;
+	struct btrq_workers submit_workers;
+	struct btrq_workers enospc_workers;
 	/*
 	 * fixup workers take dirty pages that didn't properly go through
 	 * the cow mechanism and make them safe to write.  It happens
 	 * for the sys_munmap function call path
 	 */
-	struct btrfs_workers fixup_workers;
+	struct btrq_workers fixup_workers;
 	struct task_struct *transaction_kthread;
 	struct task_struct *cleaner_kthread;
 	int thread_pool_size;
fs/btrfs/disk-io.c +78 -79

266 lines not on this page · raw message

fs/btrfs/extent-tree.c +3 -4
index 94627c4..ece1b59 100644
@@ -2867,10 +2867,10 @@ static void check_force_delalloc(struct btrfs_space_info *meta_sinfo)
 struct async_flush {
 	struct btrfs_root *root;
 	struct btrfs_space_info *info;
-	struct btrfs_work work;
+	struct btrq_work work;
 };
 
-static noinline void flush_delalloc_async(struct btrfs_work *work)
+static noinline void flush_delalloc_async(struct btrq_work *work)
 {
 	struct async_flush *async;
 	struct btrfs_root *root;
@@ -2950,8 +2950,7 @@ static void flush_delalloc(struct btrfs_root *root,
 	async->info = info;
 	async->work.func = flush_delalloc_async;
 
-	btrfs_queue_worker(&root->fs_info->enospc_workers,
-			   &async->work);
+	btrq_queue_worker(&root->fs_info->enospc_workers, &async->work);
 	wait_on_flush(info);
 	return;
 
fs/btrfs/inode.c +9 -9
index b3ad168..541f104 100644
@@ -261,7 +261,7 @@ struct async_cow {
 	u64 start;
 	u64 end;
 	struct list_head extents;
-	struct btrfs_work work;
+	struct btrq_work work;
 };
 
 static noinline int add_async_extent(struct async_cow *cow,
@@ -854,7 +854,7 @@ out:
 /*
  * work queue call back to started compression on a file and pages
  */
-static noinline void async_cow_start(struct btrfs_work *work)
+static noinline void async_cow_start(struct btrq_work *work)
 {
 	struct async_cow *async_cow;
 	int num_added = 0;
@@ -870,7 +870,7 @@ static noinline void async_cow_start(struct btrfs_work *work)
 /*
  * work queue call back to submit previously compressed pages
  */
-static noinline void async_cow_submit(struct btrfs_work *work)
+static noinline void async_cow_submit(struct btrq_work *work)
 {
 	struct async_cow *async_cow;
 	struct btrfs_root *root;
@@ -893,7 +893,7 @@ static noinline void async_cow_submit(struct btrfs_work *work)
 		submit_compressed_extents(async_cow->inode, async_cow);
 }
 
-static noinline void async_cow_free(struct btrfs_work *work)
+static noinline void async_cow_free(struct btrq_work *work)
 {
 	struct async_cow *async_cow;
 	async_cow = container_of(work, struct async_cow, work);
@@ -936,8 +936,8 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
 			PAGE_CACHE_SHIFT;
 		atomic_add(nr_pages, &root->fs_info->async_delalloc_pages);
 
-		btrfs_queue_worker(&root->fs_info->delalloc_workers,
-				   &async_cow->work);
+		btrq_queue_worker(&root->fs_info->delalloc_workers,
+				  &async_cow->work);
 
 		if (atomic_read(&root->fs_info->async_delalloc_pages) > limit) {
 			wait_event(root->fs_info->async_submit_wait,
@@ -1507,10 +1507,10 @@ int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end)
 /* see btrfs_writepage_start_hook for details on why this is required */
 struct btrfs_writepage_fixup {
 	struct page *page;
-	struct btrfs_work work;
+	struct btrq_work work;
 };
 
-static void btrfs_writepage_fixup_worker(struct btrfs_work *work)
+static void btrfs_writepage_fixup_worker(struct btrq_work *work)
 {
 	struct btrfs_writepage_fixup *fixup;
 	struct btrfs_ordered_extent *ordered;
@@ -1588,7 +1588,7 @@ static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end)
 	page_cache_get(page);
 	fixup->work.func = btrfs_writepage_fixup_worker;
 	fixup->page = page;
-	btrfs_queue_worker(&root->fs_info->fixup_workers, &fixup->work);
+	btrq_queue_worker(&root->fs_info->fixup_workers, &fixup->work);
 	return -EAGAIN;
 }
 
fs/btrfs/relocation.c +11 -11
index cfcc93c..3c72366 100644
@@ -21,13 +21,13 @@
 #include <linux/writeback.h>
 #include <linux/blkdev.h>
 #include <linux/rbtree.h>
+#include <linux/btrqueue.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
 #include "volumes.h"
 #include "locking.h"
 #include "btrfs_inode.h"
-#include "async-thread.h"
 
 /*
  * backref_node, mapping_node and tree_block start with this
@@ -137,7 +137,7 @@ struct reloc_control {
 	struct btrfs_root *extent_root;
 	/* inode for moving data */
 	struct inode *data_inode;
-	struct btrfs_workers workers;
+	struct btrq_workers workers;
 	/* tree blocks have been processed */
 	struct extent_io_tree processed_blocks;
 	/* map start of tree root to corresponding reloc tree */
@@ -161,7 +161,7 @@ struct reloc_control {
  * merge reloc tree to corresponding fs tree in worker threads
  */
 struct async_merge {
-	struct btrfs_work work;
+	struct btrq_work work;
 	struct reloc_control *rc;
 	struct btrfs_root *root;
 	struct completion *done;
@@ -1777,7 +1777,7 @@ out:
  * this function merges reloc tree with corresponding fs tree,
  * and then drops the reloc tree.
  */
-static void merge_func(struct btrfs_work *work)
+static void merge_func(struct btrq_work *work)
 {
 	struct btrfs_trans_handle *trans;
 	struct btrfs_root *root;
@@ -1832,7 +1832,7 @@ static int merge_reloc_roots(struct reloc_control *rc)
 		async->done = &done;
 		async->num_pending = &num_pending;
 		atomic_inc(&num_pending);
-		btrfs_queue_worker(&rc->workers, &async->work);
+		btrq_queue_worker(&rc->workers, &async->work);
 	}
 
 	if (!atomic_dec_and_test(&num_pending))
@@ -3517,8 +3517,8 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start)
 	rc->block_group = btrfs_lookup_block_group(fs_info, group_start);
 	BUG_ON(!rc->block_group);
 
-	btrfs_init_workers(&rc->workers, "relocate",
-			   fs_info->thread_pool_size, NULL);
+	btrq_init_workers(&rc->workers, "btrfs-relocate",
+			  fs_info->thread_pool_size, NULL);
 
 	rc->extent_root = extent_root;
 	btrfs_prepare_block_group_relocation(extent_root, rc->block_group);
@@ -3588,7 +3588,7 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start)
 	WARN_ON(btrfs_block_group_used(&rc->block_group->item) > 0);
 out:
 	iput(rc->data_inode);
-	btrfs_stop_workers(&rc->workers);
+	btrq_stop_workers(&rc->workers);
 	btrfs_put_block_group(rc->block_group);
 	kfree(rc);
 	return err;
@@ -3700,8 +3700,8 @@ int btrfs_recover_relocation(struct btrfs_root *root)
 
 	mapping_tree_init(&rc->reloc_root_tree);
 	INIT_LIST_HEAD(&rc->reloc_roots);
-	btrfs_init_workers(&rc->workers, "relocate",
-			   root->fs_info->thread_pool_size, NULL);
+	btrq_init_workers(&rc->workers, "btrfs-relocate",
+			  root->fs_info->thread_pool_size, NULL);
 	rc->extent_root = root->fs_info->extent_root;
 
 	set_reloc_control(rc);
@@ -3736,7 +3736,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
 	btrfs_commit_transaction(trans, rc->extent_root);
 out:
 	if (rc) {
-		btrfs_stop_workers(&rc->workers);
+		btrq_stop_workers(&rc->workers);
 		kfree(rc);
 	}
 	while (!list_empty(&reloc_roots)) {
fs/btrfs/volumes.c +6 -6
index 7eda483..371052c 100644
@@ -21,6 +21,7 @@
 #include <linux/blkdev.h>
 #include <linux/random.h>
 #include <linux/iocontext.h>
+#include <linux/btrqueue.h>
 #include <asm/div64.h>
 #include "compat.h"
 #include "ctree.h"
@@ -29,7 +30,6 @@
 #include "transaction.h"
 #include "print-tree.h"
 #include "volumes.h"
-#include "async-thread.h"
 
 struct map_lookup {
 	u64 type;
@@ -316,7 +316,7 @@ loop_lock:
 			device->running_pending = 1;
 
 			spin_unlock(&device->io_lock);
-			btrfs_requeue_work(&device->work);
+			btrq_requeue_work(&device->work);
 			goto done;
 		}
 	}
@@ -350,7 +350,7 @@ done:
 	return 0;
 }
 
-static void pending_bios_fn(struct btrfs_work *work)
+static void pending_bios_fn(struct btrq_work *work)
 {
 	struct btrfs_device *device;
 
@@ -2907,7 +2907,7 @@ struct async_sched {
 	struct bio *bio;
 	int rw;
 	struct btrfs_fs_info *info;
-	struct btrfs_work work;
+	struct btrq_work work;
 };
 
 /*
@@ -2961,8 +2961,8 @@ static noinline int schedule_bio(struct btrfs_root *root,
 	spin_unlock(&device->io_lock);
 
 	if (should_queue)
-		btrfs_queue_worker(&root->fs_info->submit_workers,
-				   &device->work);
+		btrq_queue_worker(&root->fs_info->submit_workers,
+				  &device->work);
 	return 0;
 }
 
fs/btrfs/volumes.h +2 -2
index 31b0fab..f36e6ec 100644
@@ -20,7 +20,7 @@
 #define __BTRFS_VOLUMES_
 
 #include <linux/bio.h>
-#include "async-thread.h"
+#include <linux/btrqueue.h>
 
 struct buffer_head;
 struct btrfs_pending_bios {
@@ -82,7 +82,7 @@ struct btrfs_device {
 	/* physical drive uuid (or lvm uuid) */
 	u8 uuid[BTRFS_UUID_SIZE];
 
-	struct btrfs_work work;
+	struct btrq_work work;
 };
 
 struct btrfs_fs_devices {
include/linux/btrqueue.h renamed from fs/btrfs/async-thread.h +18 -18
similarity index 76%
rename from fs/btrfs/async-thread.h
rename to include/linux/btrqueue.h
index 5077746..d5093e6 100644
@@ -19,7 +19,7 @@
 #ifndef __BTRFS_ASYNC_THREAD_
 #define __BTRFS_ASYNC_THREAD_
 
-struct btrfs_worker_thread;
+struct btrq_worker_thread;
 
 /*
  * This is similar to a workqueue, but it is meant to spread the operations
@@ -28,14 +28,14 @@ struct btrfs_worker_thread;
  * cut down on context switches.
  *
  * By default threads are added on demand up to 2 * the number of cpus.
- * Changing struct btrfs_workers->max_workers is one way to prevent
+ * Changing struct btrq_workers->max_workers is one way to prevent
  * demand creation of kthreads.
  *
- * the basic model of these worker threads is to embed a btrfs_work
+ * the basic model of these worker threads is to embed a btrq_work
  * structure in your own data struct, and use container_of in a
  * work function to get back to your data struct.
  */
-struct btrfs_work {
+struct btrq_work {
 	/*
 	 * func should be set to the function you want called
 	 * your work struct is passed as the only arg
@@ -44,9 +44,9 @@ struct btrfs_work {
 	 * and it is called to complete a given work item in the same
 	 * order they were sent to the queue.
 	 */
-	void (*func)(struct btrfs_work *work);
-	void (*ordered_func)(struct btrfs_work *work);
-	void (*ordered_free)(struct btrfs_work *work);
+	void (*func)(struct btrq_work *work);
+	void (*ordered_func)(struct btrq_work *work);
+	void (*ordered_free)(struct btrq_work *work);
 
 	/*
 	 * flags should be set to zero.  It is used to make sure the
@@ -55,18 +55,18 @@ struct btrfs_work {
 	unsigned long flags;
 
 	/* don't touch these */
-	struct btrfs_worker_thread *worker;
+	struct btrq_worker_thread *worker;
 	struct list_head list;
 	struct list_head order_list;
 };
 
-struct btrfs_workers {
+struct btrq_workers {
 	/* current number of running workers */
 	int num_workers;
 
 	int num_workers_starting;
 
-	/* max number of workers allowed.  changed by btrfs_start_workers */
+	/* max number of workers allowed.  changed by btrq_start_workers */
 	int max_workers;
 
 	/* once a worker has this many requests or fewer, it is idle */
@@ -83,7 +83,7 @@ struct btrfs_workers {
 	 * to start them at a later time?  If we can't sleep, this indicates
 	 * which queue we need to use to schedule thread creation.
 	 */
-	struct btrfs_workers *atomic_worker_start;
+	struct btrq_workers *atomic_worker_start;
 
 	/* list with all the work threads.  The workers on the idle thread
 	 * may be actively servicing jobs, but they haven't yet hit the
@@ -109,11 +109,11 @@ struct btrfs_workers {
 	char *name;
 };
 
-int btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work);
-int btrfs_start_workers(struct btrfs_workers *workers, int num_workers);
-int btrfs_stop_workers(struct btrfs_workers *workers);
-void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max,
-			struct btrfs_workers *async_starter);
-int btrfs_requeue_work(struct btrfs_work *work);
-void btrfs_set_work_high_prio(struct btrfs_work *work);
+int btrq_queue_worker(struct btrq_workers *workers, struct btrq_work *work);
+int btrq_start_workers(struct btrq_workers *workers, int num_workers);
+int btrq_stop_workers(struct btrq_workers *workers);
+void btrq_init_workers(struct btrq_workers *workers, char *name, int max,
+		       struct btrq_workers *async_starter);
+int btrq_requeue_work(struct btrq_work *work);
+void btrq_set_work_high_prio(struct btrq_work *work);
 #endif
lib/Kconfig +6 -0
index 8d75d35..181d100 100644
@@ -118,6 +118,12 @@ config DECOMPRESS_LZMA
 	tristate
 
 #
+# "Butter" workqueue for load balanced work
+#
+config BTRQ
+	tristate
+
+#
 # Generic allocator support is selected if needed
 #
 config GENERIC_ALLOCATOR
lib/Makefile +2 -0
index 012506f..29bdca1 100644
@@ -70,6 +70,8 @@ lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o
 lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
 lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
 
+obj-$(CONFIG_BTRQ) += btrqueue.o
+
 obj-$(CONFIG_TEXTSEARCH) += textsearch.o
 obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o
 obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o
lib/btrqueue.c renamed from fs/btrfs/async-thread.c +63 -56

353 lines not on this page · raw message

#2 lore raw

RFC PATCH 2/2 md/raid456: switch to btrq for multicore operation

In reply to Dan Williams

The btrfs workqueue is designed for load balancing cpu intensive operations. Reuse it in md/raid456 for distributing stripe processing across multiple cores.
---

 drivers/md/Kconfig |    1 +
 drivers/md/raid5.c |   79 ++++++++++++++++++++++++++++++----------------------
 drivers/md/raid5.h |   13 +++++----
 3 files changed, 54 insertions(+), 39 deletions(-)
drivers/md/Kconfig +1 -0
index 922c36c..09ade02 100644
@@ -129,6 +129,7 @@ config MD_RAID456
 	select ASYNC_PQ
 	select ASYNC_RAID6_RECOV
 	select BLK_BBU if MD_RAID456_BBU
+	select BTRQ if MULTICORE_RAID456
 	---help---
 	  A RAID-5 set of N drives with a capacity of C MB per drive provides
 	  the capacity of C * (N - 1) MB, and protects against a failure
drivers/md/raid5.c +45 -34

128 lines not on this page · raw message

drivers/md/raid5.h +8 -5
index dd70835..81c027b 100644
@@ -3,6 +3,7 @@
 
 #include <linux/raid/xor.h>
 #include <linux/dmaengine.h>
+#include <linux/btrqueue.h>
 
 /*
  *
@@ -214,6 +215,9 @@ struct stripe_head {
 	int			disks;		/* disks in stripe */
 	enum check_states	check_state;
 	enum reconstruct_states reconstruct_state;
+#ifdef CONFIG_MULTICORE_RAID456
+	struct btrq_work	work;
+#endif
 	/**
 	 * struct stripe_operations
 	 * @target - STRIPE_OP_COMPUTE_BLK target
@@ -224,10 +228,6 @@ struct stripe_head {
 	struct stripe_operations {
 		int 		     target, target2;
 		enum sum_check_flags zero_sum_result;
-		#ifdef CONFIG_MULTICORE_RAID456
-		unsigned long	     request;
-		wait_queue_head_t    wait_for_ops;
-		#endif
 	} ops;
 	struct r5dev {
 		struct bio	req;
@@ -302,7 +302,6 @@ struct r6_state {
 #define	STRIPE_FULL_WRITE	13 /* all blocks are set to be overwritten */
 #define	STRIPE_BIOFILL_RUN	14
 #define	STRIPE_COMPUTE_RUN	15
-#define	STRIPE_OPS_REQ_PENDING	16
 
 /*
  * Operation request flags
@@ -382,6 +381,10 @@ struct raid5_private_data {
 	int			bypass_count; /* bypassed prereads */
 	int			bypass_threshold; /* preread nice */
 	struct list_head	*last_hold; /* detect hold_list promotions */
+#ifdef CONFIG_MULTICORE_RAID456
+	struct btrq_workers	workqueue;
+	char			queue_name[20];
+#endif
 
 	atomic_t		reshape_stripes; /* stripes with pending writes for reshape */
 	/* unfortunately we need two cache names as we temporarily have
#3 lore raw
In reply to Dan Williams
Quoted 11 lines · Dan Williams

The current implementation with the async thread pool ends up spreading the work over too many threads. The btrfs workqueue is targeted at high cpu utilization works and has a threshold mechanism to limit thread spawning. Unfortunately it still ends up increasing cpu utilization without a comparable improvement in throughput. Here are the numbers relative to the multicore disabled case:

idle_thresh throughput cycles
4 +0% +102%
64 +4% +63%
128 +1% +45%

Interesting, do the btrfs workqueues improve things? Or do you think they are just a better base for more tuning?

I had always hoped to find more users for the work queues and tried to keep btrfs specific features out of them. The place I didn't entirely succeed was in the spin locks, the ordered queues take regular spin locks to avoid turning off irqs where btrfs always does things outside of interrupt time. Doesn't look like raid needs the ordered queues so this should work pretty well.

Quoted 6 lines

This appears to show that something more fundamental needs to happen to take advantage of percpu raid processing. More profiling is needed, but the suspects in my mind are conf->device_lock contention and the fact that all work is serialized through conf->handle_list with no method for encouraging stripe_head to thread affinity.

The big place I'd suggest to look inside the btrfs async-thread.c for optimization is the worker_loop(). For work that tends to be bursty and relatively short, we can have worker threads finish their work fairly quickly and go to sleep, only to be woken up very quickly again with another big batch of work. The worker_loop code tries to wait around for a while, but the tuning here was btrfs specific.

It might also help to tune the find_worker and next_worker code to prefer giving work to threads that are running but almost done with their queue. Maybe they can be put onto a special hot list as they get near the end of their queue.

There's a rule somewhere that patches renaming things must have replies questioning the new name. The first reply isn't actually allowed to suggest a better name, which is good because I'm not very good at that kind of thing.

Really though, btr_queue is fine by me, but don't feel obligated to keep some variation of btrfs in the name ;)

-chris

#4 lore raw

On Wed, Mar 24, 2010 at 8:51 AM, Chris Mason <[email protected]> w= rote:

Quoted 2 lines · Dan Williams
Quoted 1 line

The current implementation with the async thread pool ends up spread=

ing

Quoted 1 line
Quoted 1 line

the work over too many threads. =A0The btrfs workqueue is targeted a=

t high

Quoted 2 lines
Quoted 2 lines

cpu utilization works and has a threshold mechanism to limit thread spawning. =A0Unfortunately it still ends up increasing cpu utilizati=

on

Quoted 1 line
Quoted 1 line

without a comparable improvement in throughput. =A0Here are the numb=

ers

Quoted 8 lines
Quoted 6 lines

relative to the multicore disabled case:

idle_thresh =A0 throughput =A0 =A0 =A0cycles
4 =A0 =A0 =A0 =A0 =A0 =A0 +0% =A0 =A0 =A0 =A0 =A0 =A0 +102% 64 =A0 =A0 =A0 =A0 =A0 =A0+4% =A0 =A0 =A0 =A0 =A0 =A0 +63% 128 =A0 =A0 =A0 =A0 =A0 +1% =A0 =A0 =A0 =A0 =A0 =A0 +45%

Interesting, do the btrfs workqueues improve things? =A0Or do you thi=

nk they are

Quoted 1 line

just a better base for more tuning?

Both, throughput falls off a cliff with the async thread pool, and there are more knobs to turn in this implementation.

Quoted 1 line

I had always hoped to find more users for the work queues and tried t=

o

Quoted 1 line

keep btrfs specific features out of them. =A0The place I didn't entir=

ely

Quoted 2 lines

succeed was in the spin locks, the ordered queues take regular spin locks to avoid turning off irqs where btrfs always does things outsid=

e

Quoted 1 line

of interrupt time. =A0Doesn't look like raid needs the ordered queues=

so

Quoted 4 lines

this should work pretty well.

Quoted 2 lines

This appears to show that something more fundamental needs to happen=

to

Quoted 1 line
Quoted 1 line

take advantage of percpu raid processing. =A0More profiling is neede=

d, but

Quoted 1 line
Quoted 1 line

the suspects in my mind are conf->device_lock contention and the fac=

t

Quoted 1 line
Quoted 1 line

that all work is serialized through conf->handle_list with no method=

for

Quoted 4 lines
Quoted 1 line

encouraging stripe_head to thread affinity.

The big place I'd suggest to look inside the btrfs async-thread.c for optimization is the worker_loop(). =A0For work that tends to be burst=

y and

Quoted 3 lines

relatively short, we can have worker threads finish their work fairly quickly and go to sleep, only to be woken up very quickly again with another big batch of work. =A0The worker_loop code tries to wait arou=

nd

Quoted 3 lines

for a while, but the tuning here was btrfs specific.

It might also help to tune the find_worker and next_worker code to pr=

efer

Quoted 2 lines

giving work to threads that are running but almost done with their queue. =A0Maybe they can be put onto a special hot list as they get n=

ear

Quoted 2 lines

the end of their queue.

Thanks I'll take a look at these suggestions. For these optimizations to have a chance I think we need stripes to maintain affinity with the first core that picks up the work. Currently all stripes take a trip through the single-threaded raid5d when their reference count drops to zero, only to be immediately reissued to the thread pool potentially on a different core (but I need to back this assumption up with more profiling).

Quoted 1 line

There's a rule somewhere that patches renaming things must have repli=

es

Quoted 1 line

questioning the new name. =A0The first reply isn't actually allowed t=

o

Quoted 4 lines

suggest a better name, which is good because I'm not very good at that kind of thing.

Really though, btr_queue is fine by me, but don't feel obligated to k=

eep

Quoted 1 line

some variation of btrfs in the name ;)

btr_queue seemed to make sense since it's spreading work like "butter" = :-).

--
Dan
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" i= n
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 1 line · Dan Williams

On Wed, Mar 24, 2010 at 8:51 AM, Chris Mason <[email protected]>=

Quoted 2 lines · wrote:
Quoted 2 lines · Dan Williams
Quoted 1 line

The current implementation with the async thread pool ends up spre=

ading

Quoted 1 line
Quoted 1 line
Quoted 1 line

the work over too many threads. =A0The btrfs workqueue is targeted=

at high

Quoted 1 line
Quoted 1 line
Quoted 1 line

cpu utilization works and has a threshold mechanism to limit threa=

d

Quoted 1 line
Quoted 1 line
Quoted 1 line

spawning. =A0Unfortunately it still ends up increasing cpu utiliza=

tion

Quoted 1 line
Quoted 1 line
Quoted 1 line

without a comparable improvement in throughput. =A0Here are the nu=

mbers

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

relative to the multicore disabled case:

idle_thresh =A0 throughput =A0 =A0 =A0cycles
4 =A0 =A0 =A0 =A0 =A0 =A0 +0% =A0 =A0 =A0 =A0 =A0 =A0 +102% 64 =A0 =A0 =A0 =A0 =A0 =A0+4% =A0 =A0 =A0 =A0 =A0 =A0 +63% 128 =A0 =A0 =A0 =A0 =A0 +1% =A0 =A0 =A0 =A0 =A0 =A0 +45%

Interesting, do the btrfs workqueues improve things? =A0Or do you t=

hink they are

Quoted 4 lines
Quoted 1 line

just a better base for more tuning?

=20
Both, throughput falls off a cliff with the async thread pool, and there are more knobs to turn in this implementation.

Ok, it's really interesting that we're only getting you 4% faster tput, at 63% more cycles. That looks like something more than just cache affinity, but at least for btrfs I always had bigger problems than affinity, so I haven't dug into that part yet.

Quoted 2 lines

=20

Quoted 1 line

I had always hoped to find more users for the work queues and tried=

to

Quoted 1 line
Quoted 1 line

keep btrfs specific features out of them. =A0The place I didn't ent=

irely

Quoted 2 lines
Quoted 2 lines

succeed was in the spin locks, the ordered queues take regular spin locks to avoid turning off irqs where btrfs always does things outs=

ide

Quoted 1 line
Quoted 1 line

of interrupt time. =A0Doesn't look like raid needs the ordered queu=

es so

Quoted 4 lines
Quoted 4 lines

this should work pretty well.

Quoted 2 lines

This appears to show that something more fundamental needs to happ=

en to

Quoted 1 line
Quoted 1 line
Quoted 1 line

take advantage of percpu raid processing. =A0More profiling is nee=

ded, but

Quoted 1 line
Quoted 1 line
Quoted 1 line

the suspects in my mind are conf->device_lock contention and the f=

act

Quoted 1 line
Quoted 1 line
Quoted 1 line

that all work is serialized through conf->handle_list with no meth=

od for

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

encouraging stripe_head to thread affinity.

The big place I'd suggest to look inside the btrfs async-thread.c f=

or

Quoted 1 line
Quoted 1 line

optimization is the worker_loop(). =A0For work that tends to be bur=

sty and

Quoted 1 line
Quoted 1 line

relatively short, we can have worker threads finish their work fair=

ly

Quoted 1 line
Quoted 1 line

quickly and go to sleep, only to be woken up very quickly again wit=

h

Quoted 1 line
Quoted 1 line

another big batch of work. =A0The worker_loop code tries to wait ar=

ound

Quoted 3 lines
Quoted 3 lines

for a while, but the tuning here was btrfs specific.

It might also help to tune the find_worker and next_worker code to =

prefer

Quoted 2 lines
Quoted 2 lines

giving work to threads that are running but almost done with their queue. =A0Maybe they can be put onto a special hot list as they get=

near

Quoted 4 lines
Quoted 2 lines

the end of their queue.

=20
Thanks I'll take a look at these suggestions. For these optimization=

s

Quoted 1 line

to have a chance I think we need stripes to maintain affinity with th=

e

Quoted 2 lines

first core that picks up the work. Currently all stripes take a trip through the single-threaded raid5d when their reference count drops t=

o

Quoted 3 lines

zero, only to be immediately reissued to the thread pool potentially on a different core (but I need to back this assumption up with more profiling).

Well, I'd definitely say the pool is going to give you a random core.

Quoted 2 lines

=20

Quoted 1 line

There's a rule somewhere that patches renaming things must have rep=

lies

Quoted 1 line
Quoted 1 line

questioning the new name. =A0The first reply isn't actually allowed=

to

Quoted 4 lines
Quoted 4 lines

suggest a better name, which is good because I'm not very good at that kind of thing.

Really though, btr_queue is fine by me, but don't feel obligated to=

keep

Quoted 3 lines
Quoted 1 line

some variation of btrfs in the name ;)

=20
btr_queue seemed to make sense since it's spreading work like "butter=

" :-).

Grin, it doesn't take many butter jokes to sell me. Careful though, yo= u
can't have just one buttery thread pool. Just wait, you'll think of good reasons to add another real soon.

Speaking of which, you want to use the atomic thread starting helper. Basically kthread_run does GFP allocations that can wait on disk, and if you're the disk it is waiting on things can go badly in a hurry.

We should probably integrate a single kthread run helper thread into th= e
pools instead of forcing people to make their own. I'll take a look.

-chris

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" i= n
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html