linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: quwenruo@cn.fujitsu.com
Subject: [PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct
Date: Thu, 7 Nov 2013 13:51:53 +0800	[thread overview]
Message-ID: <1383803527-23736-4-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1383803527-23736-1-git-send-email-quwenruo@cn.fujitsu.com>

Add high priority workqueue, which added a new workqueue to
btrfs_workqueue_struct.

Whether using the high priority workqueue must be decided at
initialization.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
Changelog:
v1->v2:
  None
v2->v3:
  None
---
 fs/btrfs/async-thread.c | 25 ++++++++++++++++++++++++-
 fs/btrfs/async-thread.h |  8 ++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 00b4913..925aa6d 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -731,6 +731,7 @@ void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
 
 struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
 						     char *ordered_name,
+						     char *high_name,
 						     int flags,
 						     int max_active)
 {
@@ -753,6 +754,19 @@ struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
 		}
 	}
 
+	if (high_name) {
+		ret->high_wq = alloc_workqueue(high_name,
+					       flags | WQ_HIGHPRI,
+					       max_active);
+		if (unlikely(!ret->high_wq)) {
+			destroy_workqueue(ret->normal_wq);
+			if (ret->ordered_wq)
+				destroy_workqueue(ret->ordered_wq);
+			kfree(ret);
+			return NULL;
+		}
+	}
+
 	spin_lock_init(&ret->insert_lock);
 	return ret;
 }
@@ -793,8 +807,13 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq,
 		      struct btrfs_work_struct *work)
 {
 	unsigned long flags;
+	struct workqueue_struct *dest_wq;
+	if (work->high && wq->high_wq)
+		dest_wq = wq->high_wq;
+	else
+		dest_wq = wq->normal_wq;
 	spin_lock_irqsave(&wq->insert_lock, flags);
-	queue_work(wq->normal_wq, &work->normal_work);
+	queue_work(dest_wq, &work->normal_work);
 	if (wq->ordered_wq && work->ordered_func)
 		queue_work(wq->ordered_wq, &work->ordered_work);
 	spin_unlock_irqrestore(&wq->insert_lock, flags);
@@ -804,10 +823,14 @@ void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq)
 {
 	if (wq->ordered_wq)
 		destroy_workqueue(wq->ordered_wq);
+	if (wq->high_wq)
+		destroy_workqueue(wq->high_wq);
 	destroy_workqueue(wq->normal_wq);
 }
 
 void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max)
 {
 	workqueue_set_max_active(wq->normal_wq, max);
+	if (wq->high_wq)
+		workqueue_set_max_active(wq->high_wq, max);
 }
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index eee6709..4863c38 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -123,6 +123,7 @@ void btrfs_set_work_high_prio(struct btrfs_work *work);
 struct btrfs_workqueue_struct {
 	struct workqueue_struct *normal_wq;
 	struct workqueue_struct *ordered_wq;
+	struct workqueue_struct *high_wq;
 
 	/*
 	 * Spinlock to ensure that both ordered and normal work can
@@ -141,17 +142,20 @@ struct btrfs_work_struct {
 	struct work_struct normal_work;
 	struct work_struct ordered_work;
 	struct completion normal_completion;
+	int high;
 };
 
 /*
  * ordered_name is optional. If not given(NULL), the ordered
  * workqueue will not be allocated and the ordered excution will not
  * be available. The behavior will not be changed after init.
+ * The same rule is applied to high_name.
  *
  * flags will use the WQ_ flags, ORed with WQ_UNBOUND.
  * */
 struct btrfs_workqueue_struct *btrfs_alloc_workqueue(char *name,
 						     char *ordered_name,
+						     char *high_name,
 						     int flags,
 						     int max_active);
 void btrfs_init_work(struct btrfs_work_struct *work,
@@ -162,4 +166,8 @@ void btrfs_queue_work(struct btrfs_workqueue_struct *wq,
 		      struct btrfs_work_struct *work);
 void btrfs_destroy_workqueue(struct btrfs_workqueue_struct *wq);
 void btrfs_workqueue_set_max(struct btrfs_workqueue_struct *wq, int max);
+static inline void btrfs_set_work_high_priority(struct btrfs_work_struct *work)
+{
+	work->high = 1;
+}
 #endif
-- 
1.8.4.2


  parent reply	other threads:[~2013-11-07  5:51 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-07  5:51 [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 01/17] btrfs: Cleanup the unused struct async_sched Qu Wenruo
2013-11-07 17:24   ` Josef Bacik
2013-11-07  5:51 ` [PATCH v3 02/17] btrfs: Added btrfs_workqueue_struct implemented ordered execution based on kernel workqueue Qu Wenruo
2013-11-07  9:33   ` Stefan Behrens
2013-11-07 16:05     ` David Sterba
2013-11-08  0:32       ` Qu Wenruo
2013-11-07 18:08   ` Josef Bacik
2013-11-07 18:09     ` Josef Bacik
2013-11-08  0:58       ` Qu Wenruo
2013-11-07  5:51 ` Qu Wenruo [this message]
2013-11-07 16:41   ` [PATCH v3 03/17] btrfs: Add high priority workqueue support for btrfs_workqueue_struct David Sterba
2013-11-08  0:53     ` Qu Wenruo
2013-11-12 16:59       ` David Sterba
2013-11-13  0:53         ` Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 04/17] btrfs: Add threshold workqueue based on kernel workqueue Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 05/17] btrfs: Replace fs_info->workers with btrfs_workqueue Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 06/17] btrfs: Replace fs_info->delalloc_workers " Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 07/17] btrfs: Replace fs_info->submit_workers " Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 08/17] btrfs: Replace fs_info->flush_workers " Qu Wenruo
2013-11-07  5:51 ` [PATCH v3 09/17] btrfs: Replace fs_info->endio_* workqueue " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 10/17] btrfs: Replace fs_info->rmw_workers " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 11/17] btrfs: Replace fs_info->cache_workers " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 12/17] btrfs: Replace fs_info->readahead_workers " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 13/17] btrfs: Replace fs_info->fixup_workers " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 14/17] btrfs: Replace fs_info->delayed_workers " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 15/17] btrfs: Replace fs_info->qgroup_rescan_worker " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 16/17] btrfs: Replace fs_info->scrub_* " Qu Wenruo
2013-11-07  5:52 ` [PATCH v3 17/17] btrfs: Cleanup the old btrfs_worker Qu Wenruo
2013-11-07 17:52 ` [PATCH v3 00/17] Replace btrfs_workers with kernel workqueue based btrfs_workqueue_struct David Sterba
2013-11-08  0:55   ` Qu Wenruo
2013-11-07 17:54 ` Chris Mason
2013-11-08  0:56   ` Qu Wenruo
2013-11-26  1:39   ` Qu Wenruo
2013-11-26  7:31     ` Liu Bo
2013-11-26  8:33       ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383803527-23736-4-git-send-email-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).